当前位置: 首页>>代码示例>>Python>>正文


Python Image.draw方法代码示例

本文整理汇总了Python中reportlab.platypus.flowables.Image.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Image.draw方法的具体用法?Python Image.draw怎么用?Python Image.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.platypus.flowables.Image的用法示例。


在下文中一共展示了Image.draw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Figure

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import draw [as 别名]
class Figure(Flowable):

    def __init__(self, imgFile, captionTxt, captionStyle, imgWidth=None, imgHeight=None, margin=(0, 0, 0, 0),
                 padding=(0, 0, 0, 0), align=None, borderColor=(0.75, 0.75, 0.75), no_mask=False, url=None):

        imgFile = imgFile
        self.imgPath = imgFile
        # workaround for http://code.pediapress.com/wiki/ticket/324
        # see http://two.pairlist.net/pipermail/reportlab-users/2008-October/007526.html
        if no_mask:
            self.i = Image(imgFile, width=imgWidth, height=imgHeight, mask=None)
        else:
            self.i = Image(imgFile, width=imgWidth, height=imgHeight)
        self.imgWidth = imgWidth
        self.imgHeight = imgHeight
        self.c = Paragraph(captionTxt, style=captionStyle)
        self.margin = margin  # 4-tuple. margins in order: top, right, bottom, left
        self.padding = padding  # same as above
        self.borderColor = borderColor
        self.align = align
        self.cs = captionStyle
        self.captionTxt = captionTxt
        self.availWidth = None
        self.availHeight = None
        self.url = url

    def draw(self):
        canv = self.canv
        if self.align == "center":
            canv.translate((self.availWidth - self.width) / 2, 0)
        canv.saveState()
        canv.setStrokeColor(Color(self.borderColor[0], self.borderColor[1], self.borderColor[2]))
        canv.rect(self.margin[3], self.margin[2], self.boxWidth, self.boxHeight)
        canv.restoreState()
        canv.translate(self.margin[3] + self.padding[3], self.margin[2] + self.padding[2] - 2)
        self.c.canv = canv
        self.c.draw()
        canv.translate((self.boxWidth - self.padding[1] - self.padding[3] - self.i.drawWidth) / 2, self.captionHeight + 2)
        self.i.canv = canv
        self.i.draw()
        if self.url:
            frags = urlparse.urlsplit(self.url.encode('utf-8'))
            clean_url = urlparse.urlunsplit((frags.scheme,
                                             frags.netloc,
                                             urllib.quote(frags.path, safe='/'),
                                             urllib.quote(frags.query, safe='=&'),
                                             frags.fragment,)).decode('utf-8')
            canv.linkURL(clean_url, (0, 0, self.imgWidth, self.imgHeight), relative=1, thickness=0)

    def wrap(self, availWidth, availHeight):
        self.availWidth = availWidth
        self.availHeight = availHeight
        contentWidth = max(self.i.drawWidth, self.c.wrap(self.i.drawWidth, availHeight)[0])
        self.boxWidth = contentWidth + self.padding[1] + self.padding[3]
        (self.captionWidth, self.captionHeight) = self.c.wrap(contentWidth, availHeight)
        self.captionHeight += self.cs.spaceBefore + self.cs.spaceAfter
        self.boxHeight = self.i.drawHeight + self.captionHeight + self.padding[0] + self.padding[2]
        self.width = self.boxWidth + self.margin[1] + self.margin[3]
        self.height = self.boxHeight + self.margin[0] + self.margin[2]
        return (self.width, self.height)
开发者ID:tosher,项目名称:mwlib.rl,代码行数:62,代码来源:customflowables.py

示例2: draw

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import draw [as 别名]
 def draw(self):
     self.canv.rotate(90)
     Image.draw(self)
开发者ID:swasher,项目名称:pdfupload,代码行数:5,代码来源:reporting_platypus_example.py


注:本文中的reportlab.platypus.flowables.Image.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。