def start(self, c): attr = self.attr codeName = attr.type or "Code128" codeName = pisaTagPDFBARCODE._codeName[codeName.upper().replace("-", "")] humanReadable = int(attr.humanreadable) vertical = int(attr.vertical) checksum = int(attr.checksum) barWidth = attr.barwidth or 0.01 * inch barHeight = attr.barheight or 0.5 * inch fontName = c.getFontName("OCRB10,OCR-B,OCR B,OCRB") # or "Helvetica" fontSize = attr.fontsize or 2.75 * mm # Assure minimal size. if codeName in ("EAN13", "EAN8"): barWidth = max(barWidth, 0.264 * mm) fontSize = max(fontSize, 2.75 * mm) # with QR codes barWidth is used for width of the whole box elif codeName == 'QR': barWidth = max(barWidth, 15*mm) else: # Code39 etc. barWidth = max(barWidth, 0.0075 * inch) barcode = pisaTagPDFBARCODE._barcodeWrapper( codeName=codeName, value=attr.value, barWidth=barWidth, barHeight=barHeight, humanReadable=humanReadable, vertical=vertical, checksum=checksum, fontName=fontName, fontSize=fontSize, ) width, height = barcode.wrap(c.frag.width, c.frag.height) c.force = True valign = attr.align or c.frag.vAlign or "baseline" if valign in ["texttop"]: valign = "top" elif valign in ["absmiddle"]: valign = "middle" elif valign in ["absbottom", "baseline"]: valign = "bottom" afrag = c.frag.clone() afrag.text = "" afrag.fontName = fontName afrag.cbDefn = ABag( kind="barcode", barcode=barcode, width=width, height=height, valign=valign, ) c.fragList.append(afrag)
def start(self, c): attr = self.attr codeName = attr.type or "Code128" codeName = pisaTagPDFBARCODE._codeName[codeName.upper().replace( "-", "")] humanReadable = bool(attr.humanreadable) barWidth = attr.barwidth or 0.01 * inch barHeight = attr.barheight or 0.5 * inch fontName = c.getFontName("OCRB10,OCR-B,OCR B,OCRB") # or "Helvetica" fontSize = 2.75 * mm # Assure minimal size. if codeName in ("EAN13", "EAN8"): barWidth = max(barWidth, 0.264 * mm) fontSize = max(fontSize, 2.75 * mm) else: # Code39 etc. barWidth = max(barWidth, 0.0075 * inch) #barHeight = max(barHeight, 25.93*mm) barcode = pisaTagPDFBARCODE._barcodeWrapper( codeName=codeName, value=attr.value, barWidth=barWidth, barHeight=barHeight, humanReadable=humanReadable, fontName=fontName, fontSize=fontSize, ) width, height = barcode.wrap(c.frag.width, c.frag.height) #barcode.spaceBefore = c.frag.spaceBefore #barcode.spaceAfter = c.frag.spaceAfter c.force = True valign = attr.align or c.frag.vAlign or "baseline" if valign in ["texttop"]: valign = "top" elif valign in ["absmiddle"]: valign = "middle" elif valign in ["absbottom", "baseline"]: valign = "bottom" afrag = c.frag.clone() afrag.text = "" afrag.fontName = fontName afrag.cbDefn = ABag( kind="barcode", barcode=barcode, width=width, height=height, valign=valign, ) c.fragList.append(afrag)
def start(self, c): attr = self.attr # XXX Also support attr.id ? if attr.name: # Important! Make sure that cbDefn is not inherited by other # fragments because of a bug in Reportlab! afrag = c.frag.clone() afrag.cbDefn = ABag(kind="anchor", name=attr.name, label="anchor") c.fragAnchor.append(afrag) c.anchorName.append(attr.name) if attr.href and self.rxLink.match(attr.href): c.frag.link = attr.href
def start(self, c): attr = self.attr if attr.name: afrag = c.newFrag(cbDefn = ABag( kind = "anchor", name = attr.name, label = "anchor" )) c.fragAnchor.append(afrag) c.anchorName.append(attr.name) if attr.href and self.rxLink.match(attr.href): c.frag.link = attr.href
def start(self, c): attr = self.attr # XXX Also support attr.id ? if attr.name: # Important! Make sure that cbDefn is not inherited by other # fragments because of a bug in Reportlab! afrag = c.frag.clone() # These 3 lines are needed to fix an error with non internal fonts afrag.fontName = "Helvetica" afrag.bold = 0 afrag.italic = 0 afrag.cbDefn = ABag(kind="anchor", name=attr.name, label="anchor") c.fragAnchor.append(afrag) c.anchorName.append(attr.name) if attr.href and self.rxLink.match(attr.href): c.frag.link = attr.href
def start(self, c): attr = self.attr if attr.src and (not attr.src.notFound()): try: align = attr.align or c.frag.vAlign or "baseline" width = c.frag.width height = c.frag.height if attr.width: width = attr.width * dpi96 if attr.height: height = attr.height * dpi96 img = PmlImage( attr.src.getData(), width=None, height=None) img.pisaZoom = c.frag.zoom img.drawHeight *= dpi96 img.drawWidth *= dpi96 if (width is None) and (height is not None): factor = getSize(height) / img.drawHeight img.drawWidth *= factor img.drawHeight = getSize(height) elif (height is None) and (width is not None): factor = getSize(width) / img.drawWidth img.drawHeight *= factor img.drawWidth = getSize(width) elif (width is not None) and (height is not None): img.drawWidth = getSize(width) img.drawHeight = getSize(height) img.drawWidth *= img.pisaZoom img.drawHeight *= img.pisaZoom img.spaceBefore = c.frag.spaceBefore img.spaceAfter = c.frag.spaceAfter # print "image", id(img), img.drawWidth, img.drawHeight ''' TODO: - Apply styles - vspace etc. - Borders - Test inside tables ''' c.force = True if align in ["left", "right"]: c.image = img c.imageData = dict( align=align ) else: # Important! Make sure that cbDefn is not inherited by other # fragments because of a bug in Reportlab! # afrag = c.frag.clone() valign = align if valign in ["texttop"]: valign = "top" elif valign in ["absmiddle"]: valign = "middle" elif valign in ["absbottom", "baseline"]: valign = "bottom" afrag = c.frag.clone() afrag.text = "" afrag.fontName = "Helvetica" # Fix for a nasty bug!!! afrag.cbDefn = ABag( kind="img", image=img, # .getImage(), # XXX Inline? valign=valign, fontName="Helvetica", fontSize=img.drawHeight, width=img.drawWidth, height=img.drawHeight) c.fragList.append(afrag) c.fontSize = img.drawHeight except Exception: # TODO: Kill catch-all log.warn(c.warning("Error in handling image"), exc_info=1) else: log.warn(c.warning("Need a valid file name!"))