当前位置: 首页>>代码示例>>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;未经允许,请勿转载。