reportlab/platypus/tables.py
 changeset 2879 0ba5481218bd parent 2878 a7af19b6f9fb child 2880 70c6ad230fea
equal inserted replaced
2878:a7af19b6f9fb 2879:0ba5481218bd
`   201     try:`
`   201     try:`
`   202         return obj.endswith(s)`
`   202         return obj.endswith(s)`
`   203     except:`
`   203     except:`
`   204         return 0`
`   204         return 0`
`   205 `
`   205 `
`   206 def _spanConsCmp(a,b):`
`   206 def spanFixDim(V0,V,spanCons,FUZZ=rl_config._FUZZ):`
`   207     r = cmp(b[1]-b[0],a[1]-a[0])`
`   207     print 'V0=',V0`
`   208     if not r:`
`   208     print 'V=',V`
`   209         r = cmp(a,b)`
`   209     print 'spanCons=',spanCons`
`   210     return r`
`   210     #assign required space to variable rows equally to existing calculated values`
`       `
`   211     M = {}`
`       `
`   212     for (x0,x1),v in spanCons.iteritems():`
`       `
`   213         t = sum([V[x]+M.get(x,0) for x in xrange(x0,x1+1)])`
`       `
`   214         if t>=v-FUZZ: continue      #already good enough`
`       `
`   215         X = [x for x in xrange(x0,x1+1) if V0[x] is None]   #variable candidates`
`       `
`   216         if not X: continue          #something wrong here mate`
`       `
`   217         v -= t`
`       `
`   218         v /= float(len(X))`
`       `
`   219         for x in X:`
`       `
`   220             M[x] = max(M.get(x,v),v)`
`       `
`   221     for x,v in M.iteritems():`
`       `
`   222         V[x] += v`
`       `
`   223     print 'V-->',V`
`   211 `
`   224 `
`   212 class Table(Flowable):`
`   225 class Table(Flowable):`
`   213     def __init__(self, data, colWidths=None, rowHeights=None, style=None,`
`   226     def __init__(self, data, colWidths=None, rowHeights=None, style=None,`
`   214                 repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None, ident=None,`
`   227                 repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None, ident=None,`
`   215                 hAlign=None,vAlign=None):`
`   228                 hAlign=None,vAlign=None):`
`   382                 spanRanges = self._spanRanges`
`   395                 spanRanges = self._spanRanges`
`   383             else:`
`   396             else:`
`   384                 colSpanCells = ()`
`   397                 colSpanCells = ()`
`   385                 spanRanges = {}`
`   398                 spanRanges = {}`
`   386             spanCons = {}`
`   399             spanCons = {}`
`   388             if W is self._argW:`
`   400             if W is self._argW:`
`   389                 W0 = W`
`   401                 W0 = W`
`   390                 W = W[:]`
`   402                 W = W[:]`
`   391             else:`
`   403             else:`
`   392                 W0 = W[:]`
`   404                 W0 = W[:]`
`   419                     i += 1`
`   431                     i += 1`
`   420 `
`   432 `
`   421                 W[j] = w`
`   433                 W[j] = w`
`   422 `
`   434 `
`   423             if spanCons:`
`   435             if spanCons:`
`   424                 spanConsX = spanCons.keys()     #try to ensure span constraints are satisfied`
`   436                 spanFixDim(W0,W,spanCons)`
`   425                 spanConsX.sort(_spanConsCmp)    #assign required space to variable rows`
`       `
`   426                 for c0,c1 in spanConsX:         #equally to existing calculated values`
`       `
`   427                     w = spanCons[c0,c1]`
`       `
`   428                     t = sum(W[c0:c1+1])`
`       `
`   429                     if t>=w-FUZZ: continue      #already good enough`
`       `
`   430                     X = [x for x in xrange(c0,c1+1) if W0[x] is None]   #variable candidates`
`       `
`   431                     if not X: continue          #something wrong here mate`
`       `
`   432                     w -= t`
`       `
`   433                     w /= float(len(X))`
`       `
`   434                     for x in X:`
`       `
`   435                         W[x] += w`
`       `
`   436 `
`   437 `
`   437         self._colWidths = W`
`   438         self._colWidths = W`
`   438         width = 0`
`   439         width = 0`
`   439         self._colpositions = [0]        #index -1 is right side boundary; we skip when processing cells`
`   440         self._colpositions = [0]        #index -1 is right side boundary; we skip when processing cells`
`   440         for w in W:`
`   441         for w in W:`
`   539                     if t>h: h = t   #record a new maximum`
`   540                     if t>h: h = t   #record a new maximum`
`   540                 H[i] = h`
`   541                 H[i] = h`
`   541             if None not in H: hmax = lim`
`   542             if None not in H: hmax = lim`
`   542 `
`   543 `
`   543             if spanCons:`
`   544             if spanCons:`
`   544                 spanConsX = spanCons.keys()     #try to ensure span constraints are satisfied`
`   545                 spanFixDim(H0,H,spanCons)`
`   545                 spanConsX.sort(_spanConsCmp)    #assign required space to variable rows`
`       `
`   546                 for r0,r1 in spanConsX:         #equally to existing calculated values`
`       `
`   547                     h = spanCons[r0,r1]`
`       `
`   548                     t = sum(H[r0:r1+1])`
`       `
`   549                     if t>=h-FUZZ: continue      #already good enough`
`       `
`   550                     X = [x for x in xrange(r0,r1+1) if H0[x] is None]   #variable candidates`
`       `
`   551                     if not X: continue          #something wrong here mate`
`       `
`   552                     h -= t`
`       `
`   553                     h /= float(len(X))`
`       `
`   554                     for x in X:`
`       `
`   555                         H[x] += h`
`       `
`   556 `
`   546 `
`   557         height = self._height = reduce(operator.add, H[:hmax], 0)`
`   547         height = self._height = reduce(operator.add, H[:hmax], 0)`
`   558         self._rowpositions = [height]    # index 0 is actually topline; we skip when processing cells`
`   548         self._rowpositions = [height]    # index 0 is actually topline; we skip when processing cells`
`   559         for h in H[:hmax]:`
`   549         for h in H[:hmax]:`
`   560             height = height - h`
`   550             height = height - h`