def _listWrapOn(F, availWidth, canv, mergeSpace=1, obj=None, dims=None): '''return max width, required height for a list of flowables F''' doct = getattr(canv, '_doctemplate', None) cframe = getattr(doct, 'frame', None) if cframe: from reportlab.platypus.doctemplate import _addGeneratedContent, Indenter doct_frame = cframe from copy import deepcopy cframe = doct.frame = deepcopy(doct_frame) cframe._generated_content = None del cframe._generated_content try: W = 0 H = 0 pS = 0 atTop = 1 F = F[:] while F: f = F.pop(0) if hasattr(f, 'frameAction'): from reportlab.platypus.doctemplate import Indenter if isinstance(f, Indenter): availWidth -= f.left + f.right continue w, h = f.wrapOn(canv, availWidth, 0xfffffff) if dims is not None: dims.append((w, h)) if cframe: _addGeneratedContent(F, cframe) if w <= fl._FUZZ or h <= fl._FUZZ: continue # # THE HACK # # W = max(W,min(availWidth, w)) W = max(W, w) H += h if not atTop: h = f.getSpaceBefore() if mergeSpace: if getattr(f, '_SPACETRANSFER', False): h = pS h = max(h - pS, 0) H += h else: if obj is not None: obj._spaceBefore = f.getSpaceBefore() atTop = 0 s = f.getSpaceAfter() if getattr(f, '_SPACETRANSFER', False): s = pS pS = s H += pS if obj is not None: obj._spaceAfter = pS return W, H - pS finally: if cframe: doct.frame = doct_frame
def _listWrapOn(F, availWidth, canv, mergeSpace=1, obj=None, dims=None): '''return max width, required height for a list of flowables F''' doct = getattr(canv, '_doctemplate', None) cframe = getattr(doct, 'frame', None) if cframe: from reportlab.platypus.doctemplate import _addGeneratedContent, Indenter doct_frame = cframe from copy import deepcopy cframe = doct.frame = deepcopy(doct_frame) cframe._generated_content = None del cframe._generated_content try: W = 0 H = 0 pS = 0 atTop = 1 F = F[:] while F: f = F.pop(0) if hasattr(f, 'frameAction'): from reportlab.platypus.doctemplate import Indenter if isinstance(f, Indenter): availWidth -= f.left + f.right continue w, h = f.wrapOn(canv, availWidth, 0xfffffff) if dims is not None: dims.append((w, h)) if cframe: _addGeneratedContent(F, cframe) if w <= fl._FUZZ or h <= fl._FUZZ: continue # # THE HACK # # W = max(W,min(availWidth, w)) W = max(W, w) H += h if not atTop: h = f.getSpaceBefore() if mergeSpace: if getattr(f, '_SPACETRANSFER', False): h = pS h = max(h - pS, 0) H += h else: if obj is not None: obj._spaceBefore = f.getSpaceBefore() atTop = 0 s = f.getSpaceAfter() if getattr(f, '_SPACETRANSFER', False): s = pS pS = s H += pS if obj is not None: obj._spaceAfter = pS return W, H - pS finally: if cframe: doct.frame = doct_frame
def _listWrapOn(F, availWidth, canv, mergeSpace=1, obj=None, dims=None): '''return max width, required height for a list of flowables F''' doct = getattr(canv, '_doctemplate', None) if doct: from reportlab.platypus.doctemplate import _addGeneratedContent doct_frame = doct.frame cframe = doct.frame = deepcopy(doct_frame) cframe._generated_content = None del cframe._generated_content else: cframe = None try: W = 0 H = 0 pS = 0 atTop = 1 F = F[:] while F: f = F.pop(0) if hasattr(f, 'frameAction'): continue w, h = f.wrapOn(canv, availWidth, 0xfffffff) if dims is not None: dims.append((w, h)) if cframe: _addGeneratedContent(F, cframe) if w <= _FUZZ or h <= _FUZZ: continue W = max(W, w) H += h if not atTop: h = f.getSpaceBefore() if mergeSpace: h = max(h - pS, 0) H += h else: if obj is not None: obj._spaceBefore = f.getSpaceBefore() atTop = 0 pS = f.getSpaceAfter() H += pS if obj is not None: obj._spaceAfter = pS return W, H - pS finally: if doct: doct.frame = doct_frame
def _listWrapOn(F,availWidth,canv,mergeSpace=1,obj=None,dims=None): '''return max width, required height for a list of flowables F''' doct = getattr(canv,'_doctemplate',None) if doct: from reportlab.platypus.doctemplate import _addGeneratedContent doct_frame = doct.frame cframe = doct.frame = deepcopy(doct_frame) cframe._generated_content = None del cframe._generated_content else: cframe = None try: W = 0 H = 0 pS = 0 atTop = 1 F = F[:] while F: f = F.pop(0) if hasattr(f,'frameAction'): continue w,h = f.wrapOn(canv,availWidth,0xfffffff) if dims is not None: dims.append((w,h)) if cframe: _addGeneratedContent(F,cframe) if w<=_FUZZ or h<=_FUZZ: continue W = max(W,w) H += h if not atTop: h = f.getSpaceBefore() if mergeSpace: h = max(h-pS,0) H += h else: if obj is not None: obj._spaceBefore = f.getSpaceBefore() atTop = 0 pS = f.getSpaceAfter() H += pS if obj is not None: obj._spaceAfter = pS return W, H-pS finally: if doct: doct.frame = doct_frame
def handle_flowable(self, flowables): """ overriding base method!!! try to handle one flowable from the front of list flowables. added a dirty workaround to scale images if their boundingBox exceeds the borders of the frame. """ #allow document a chance to look at, modify or ignore #the object(s) about to be processed self.filterFlowables(flowables) self.handle_breakBefore(flowables) self.handle_keepWithNext(flowables) f = flowables[0] del flowables[0] if f is None: return if isinstance(f, PageBreak): npt = f.nextTemplate if npt and not self._samePT(npt): npt = NextPageTemplate(npt) npt.apply(self) self.afterFlowable(npt) if isinstance(f, SlowPageBreak): self.handle_pageBreak(slow=1) else: #print( f.__class__.__name__, self.frame.id ) self.handle_pageBreak() self.afterFlowable(f) elif isinstance(f, ActionFlowable): f.apply(self) self.afterFlowable(f) else: frame = self.frame canv = self.canv if self.debug: frame.drawBoundary(canv) #handle scaling to fit a PdfImage on self.frame if isinstance(f, Table): pass # controls default behaviour for Table typed flowables #f.setStyle([("GRID", (0, 0), (-1, -1), 0.5, colors.black)]) elif isinstance(f, Spacer): pass if isinstance(f, ap.PdfImage): #print("height of image:",f.drawHeight) #print("height of frame:",frame._aH) xfactor = getattr(f, "_userScaleFactor", None) factor = 1. if xfactor is not None: #print( "applying scale", xfactor) factor = xfactor f = self._scaleApply(f, factor) setattr(f, "_userScaleFactor", None) #resizing image if drawWidth is exceeding the available frame Width _aW if f.drawWidth > frame._aW: factor = frame._aW / f.drawWidth f = self._scaleApply(f, factor) if self.debug: print("PdfImage exceeds available width on frame:", frame.id, frame._aW / cm, frame._aH / cm, f.drawWidth / cm, f.drawHeight / cm, "rescaling to fit frame geometry.") #resizing image if drawHeight is exceeding the available frame Width _aH if f.drawHeight > frame._aH: #print("PdfImage height exceeds height of available space on frame:", # frame.id, # "rescaling to fit frame geometry..." ) factor = frame._aH / f.drawHeight f = self._scaleApply(f, factor) #print("spaceBelow:",frame._aH-f.drawHeight ) #print("spaceBesides:",frame._aW-f.drawWidth ) #print(f.drawHeight) #try to fit it then draw it if frame.add(f, canv, trySplit=self.allowSplitting): if not isinstance(f, FrameActionFlowable): self._curPageFlowableCount += 1 self.afterFlowable(f) _addGeneratedContent(flowables, frame) else: if self.allowSplitting: # see if this is a splittable thing S = frame.split(f, canv) n = len(S) else: n = 0 if n: if not isinstance(S[0], (PageBreak, SlowPageBreak, ActionFlowable, DDIndenter)): if not frame.add(S[0], canv, trySplit=0): ident = "Splitting error(n==%d) on page %d in\n%s\nS[0]=%s" % \ (n, self.page, self._fIdent(f, 60, frame), self._fIdent(S[0], 60, frame)) #leave to keep apart from the raise raise LayoutError(ident) self._curPageFlowableCount += 1 self.afterFlowable(S[0]) flowables[0:0] = S[ 1:] # put rest of splitted flowables back on the list _addGeneratedContent(flowables, frame) else: flowables[ 0:0] = S # put splitted flowables back on the list else: if hasattr(f, '_postponed'): pass #print( f.__class__.__name__, self.frame.id, f.drawWidth, f.drawHeight, ) # ident = "Flowable %s%s too large on page %d in frame %r%s of template %r" % \ # (self._fIdent(f, 60, frame), # _fSizeString(f), # self.page, # self.frame.id, # self.frame._aSpaceString(), # self.pageTemplate.id) # #leave to keep apart from the raise # raise LayoutError(ident) # this ought to be cleared when they are finally drawn! f._postponed = 1 mbe = getattr(self, '_multiBuildEdits', None) if mbe: mbe((delattr, f, '_postponed')) # put the flowable back flowables.insert(0, f) self.handle_frameEnd()