math_flowable.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:deviation-manual 作者: DeviationTX 项目源码 文件源码
def drawOn(self, canv, x, y, _sW=0):
        if _sW and hasattr(self,'hAlign'):
            from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY
            a = self.hAlign
            if a in ('CENTER','CENTRE', TA_CENTER):
                x = x + 0.5*_sW
            elif a in ('RIGHT',TA_RIGHT):
                x = x + _sW
            elif a not in ('LEFT',TA_LEFT):
                raise ValueError, "Bad hAlign value "+str(a)
        height = 0
        if HAS_MATPLOTLIB:
            global fonts
            canv.saveState()
            canv.translate(x, y)
            try:
                width, height, descent, glyphs, \
                rects, used_characters = self.parser.parse(
                    enclose(self.s), 72, prop=FontProperties(size=self.fontsize))
                for ox, oy, fontname, fontsize, num, symbol_name in glyphs:
                    if not fontname in fonts:
                        fonts[fontname] = fontname
                        pdfmetrics.registerFont(TTFont(fontname, fontname))
                    canv.setFont(fontname, fontsize)
                    col_conv=ColorConverter()
                    rgb_color=col_conv.to_rgb(self.color)
                    canv.setFillColorRGB(rgb_color[0],rgb_color[1],rgb_color[2])
                    canv.drawString(ox, oy, unichr(num))

                canv.setLineWidth(0)
                canv.setDash([])
                for ox, oy, width, height in rects:
                    canv.rect(ox, oy+2*height, width, height, fill=1)
            except:
                # FIXME: report error
                col_conv=ColorConverter()
                rgb_color=col_conv.to_rgb(self.color)
                canv.setFillColorRGB(rgb_color[0],rgb_color[1],rgb_color[2])
                canv.drawString(0,0,self.s)
            canv.restoreState()
        else:
            canv.saveState()
            canv.drawString(x, y, self.s)
            canv.restoreState()
        if self.label:
            log.info('Drawing equation-%s'%self.label)
            canv.bookmarkHorizontal('equation-%s'%self.label,0,height)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号