Next / Previous / Contents / Shipman's homepage

20.9. InputFile.__addChunk(): Add one chunk of lines to the column structure

listext2
# - - -   I n p u t F i l e . _ _ a d d C h u n k

    def __addChunk(self, count, first, last):
        '''Add one chunk of lines to the column structure.

          [ (count is the number of lines already in
            the current column and is in the interval
            [1,self.bodyLayout.linesPerCol]) and
            (first is the index in self.__blockList of a line
            that is marked for a break) and
            (last is the index in self.__blockList of the next
            line after (first) that is marked, or len(self.__blockList),
            whichever is smaller) ->
              self.__blockList  :=  self.__blockList with
                  breaks marked in the region starting at
                  (first) such that no region bracketed by
                  marks contains more than self.bodyLayout.linesPerCol
                  lines
              return the number of lines left in the last column ]
        '''

If the new chunk will fit entirely within the column, all we have to do is add the size to count and we are done. The abbreviation “CAPY” is a standard abbreviation for “capacity.”

listext2
        #-- 1
        chunkSize = last - first
        capy = self.bodyLayout.linesPerCol

        #-- 2
        if count + chunkSize <= capy:
            return count + chunkSize

The new chunk will not fit entirely within the current column. So, except for the very first time (when count is zero), mark the first line of the chunk for a column break.

listext2
        #-- 3
        if count > 0:
            self.__blockList[first].setBreak()

If the chunk is bigger than an entire column, chop it into column-sized pieces, and return the size of the last piece.

listext2
        #-- 4
        # [ first  :=  index in self.__blockList of a line such that
        #       (last-(that index)) <= capy
        #   self.__blockList  :=  self.__blockList with every
        #       (capy)th line marked for a break ]
        while (last - first) > capy:
            #-- 3 body
            # [ self.__blockList[first+capy]  :=  that block
            #       marked for a break
            #   first  :=  first + capy ]
            first += capy
            self.__blockList[first].setBreak()

The size of the last column is the size of the slice [first:last].

listext2
        #-- 5
        return last - first