當前位置: 首頁>>代碼示例>>Python>>正文


Python PmlImage.drawWidth方法代碼示例

本文整理匯總了Python中xhtml2pdf.xhtml2pdf_reportlab.PmlImage.drawWidth方法的典型用法代碼示例。如果您正苦於以下問題:Python PmlImage.drawWidth方法的具體用法?Python PmlImage.drawWidth怎麽用?Python PmlImage.drawWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xhtml2pdf.xhtml2pdf_reportlab.PmlImage的用法示例。


在下文中一共展示了PmlImage.drawWidth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: from xhtml2pdf.xhtml2pdf_reportlab import PmlImage [as 別名]
# 或者: from xhtml2pdf.xhtml2pdf_reportlab.PmlImage import drawWidth [as 別名]
    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!"))
開發者ID:4c656554,項目名稱:xhtml2pdf,代碼行數:96,代碼來源:tags.py


注:本文中的xhtml2pdf.xhtml2pdf_reportlab.PmlImage.drawWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。