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


Python canvas.saveState方法代码示例

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


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

示例1: resetTransforms

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def resetTransforms(self):
        """I want to draw something (eg, string underlines) w.r.t. the default user space.
           Reset the matrix! This should be used usually as follows::
           
              canv.saveState()
              canv.resetTransforms()
              #...draw some stuff in default space coords...
              canv.restoreState() # go back!
        """
        # we have to adjoin the inverse, since reset is not a basic operation (without save/restore)
        (selfa, selfb, selfc, selfd, selfe, selff) = self._currentMatrix
        det = selfa*selfd - selfc*selfb
        resulta = selfd/det
        resultc = -selfc/det
        resulte = (selfc*selff - selfd*selfe)/det
        resultd = selfa/det
        resultb = -selfb/det
        resultf = (selfe*selfb - selff*selfa)/det
        self.transform(resulta, resultb, resultc, resultd, resulte, resultf) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:canvas.py

示例2: restoreState

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def restoreState(self):
        """restore the graphics state to the matching saved state (see saveState)."""
        self._code.append('Q')
        self.pop_state_stack()

        ###############################################################
        #
        #   Drawing methods.  These draw things directly without
        #   fiddling around with Path objects.  We can add any geometry
        #   methods we wish as long as their meaning is precise and
        #   they are of general use.
        #
        #   In general there are two patterns.  Closed shapes
        #   have the pattern shape(self, args, stroke=1, fill=0);
        #   by default they draw an outline only. Line segments come
        #   in three flavours: line, bezier, arc (which is a segment
        #   of an elliptical arc, approximated by up to four bezier
        #   curves, one for each quadrant.
        #
        #   In the case of lines, we provide a 'plural' to unroll
        #   the inner loop; it is useful for drawing big grids
        ################################################################

        #--------first the line drawing methods----------------------- 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:canvas.py

示例3: test2

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def test2(canv,testpara):
    #print test_program; return
    from reportlab.lib.units import inch
    from reportlab.lib.styles import ParagraphStyle
    from reportlab.lib import rparsexml
    parsedpara = rparsexml.parsexmlSimple(testpara,entityReplacer=None)
    S = ParagraphStyle("Normal", None)
    P = Para(S, parsedpara)
    (w, h) = P.wrap(5*inch, 10*inch)
    print("wrapped as", (h,w))
    canv.saveState()
    canv.translate(1*inch, 1*inch)
    canv.rect(0,0,5*inch,10*inch, fill=0, stroke=1)
    P.canv = canv
    canv.saveState()
    P.draw()
    canv.restoreState()
    canv.setStrokeColorRGB(1, 0, 0)
    #canv.translate(0, 3*inch)
    canv.rect(0,0,w,h, fill=0, stroke=1)
    canv.restoreState()
    canv.showPage() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:para.py

示例4: test2

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def test2(canv,testpara):
    #print test_program; return
    from reportlab.lib.units import inch
    from reportlab.lib.styles import ParagraphStyle
    from reportlab.lib import rparsexml
    parsedpara = rparsexml.parsexmlSimple(testpara,entityReplacer=None)
    S = ParagraphStyle("Normal", None)
    P = Para(S, parsedpara)
    (w, h) = P.wrap(5*inch, 10*inch)
    print "wrapped as", (h,w)
    canv.saveState()
    canv.translate(1*inch, 1*inch)
    canv.rect(0,0,5*inch,10*inch, fill=0, stroke=1)
    P.canv = canv
    canv.saveState()
    P.draw()
    canv.restoreState()
    canv.setStrokeColorRGB(1, 0, 0)
    #canv.translate(0, 3*inch)
    canv.rect(0,0,w,h, fill=0, stroke=1)
    canv.restoreState()
    canv.showPage() 
开发者ID:gltn,项目名称:stdm,代码行数:24,代码来源:para.py

示例5: header_footer

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def header_footer(self, canvas, doc):
        canvas.saveState()
        height_adjust = self.add_banner(canvas, doc)

        # Document Header
        if self.pdf_components.get('hdr_image', None) and self.firstPage:
            header = Image(self.pdf_components.get('hdr_image'), height=25 * mm, width=191 * mm)
            header.drawOn(canvas, doc.rightMargin, doc.height + doc.topMargin - 15 * mm)
            self.firstPage = False
        elif self.firstPage:
            header = Paragraph(self.pdf_components.get('hdr_html', ''), self.style['centered'])
            w, h = header.wrap(doc.width, doc.topMargin)
            header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - height_adjust * h)

        # Document Footer
        if self.pdf_components.get('ftr_image', None):
            footer = Image(self.pdf_components.get('ftr_image'), 8.5 * inch, 1.8 * inch)
            footer.drawOn(canvas, 0, 0)
        else:
            footer = Paragraph(self.pdf_components.get('ftr_html', ''), self.style['centered'])
            w, h = footer.wrap(doc.width, doc.bottomMargin)
            footer.drawOn(canvas, doc.leftMargin, height_adjust * h)

        # Release the Canvas
        canvas.restoreState() 
开发者ID:mitre,项目名称:multiscanner,代码行数:27,代码来源:generic_pdf.py

示例6: _header_footer

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def _header_footer(self, canvas, doc):
        # Save the state of our canvas so we can draw on it
        canvas.saveState()
        
        style_right = ParagraphStyle(name='right', parent=self.bodystyle, fontName='arialuni',
                fontSize=10, alignment=TA_RIGHT)
        
        fieldsight_logo = Image('http://' + self.base_url +'/static/images/fs1.jpg')
        fieldsight_logo._restrictSize(1.5 * inch, 1.5 * inch)
        

        # headerleft = Paragraph("FieldSight", self.bodystyle)
        headerright = Paragraph(self.project_name, style_right)

        # w1, h1 = headerleft.wrap(doc.width, doc.topMargin)
        w2, h2 = headerright.wrap(doc.width, doc.topMargin)

        textWidth = stringWidth(self.project_name, fontName='arialuni',
                fontSize=10) 
        
        fieldsight_logo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 12)
        headerright.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 20)
        try:
            project_logo = Image(self.project_logo)
            project_logo._restrictSize(0.4 * inch, 0.4 * inch)
            project_logo.drawOn(canvas, headerright.width + doc.leftMargin -0.5 * inch - textWidth, doc.height + doc.topMargin + 10)
        except:
            pass        
        # header.drawOn(canvas, doc.leftMargin + doc.width, doc.height + doc.topMargin +20)
        
        # Footer
        footer = Paragraph('Page no. '+str(canvas._pageNumber), style_right)
        w, h = footer.wrap(doc.width, doc.bottomMargin)
        footer.drawOn(canvas, doc.leftMargin, h + 40)
 
        # Release the canvas
        canvas.restoreState() 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:39,代码来源:generatereport.py

示例7: saveState

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def saveState(self):
        """Save the current graphics state to be restored later by restoreState.

        For example:
            canvas.setFont("Helvetica", 20)
            canvas.saveState()
            ...
            canvas.setFont("Courier", 9)
            ...
            canvas.restoreState()
            # if the save/restore pairs match then font is Helvetica 20 again.
        """
        self.push_state_stack()
        self._code.append('q') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:canvas.py

示例8: end_at

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def end_at(self, x, y, para, canvas, textobject):
        offset = para.fontSize/8.0
        canvas.saveState()
        color = self.color
        if self.color is None:
            color = para.fontColor
        canvas.setStrokeColor(color)
        canvas.line(self.xStart, self.yStart-offset, x,y-offset)
        canvas.restoreState() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:para.py

示例9: myLaterPages

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def myLaterPages(canvas, doc):
        from reportlab.lib.colors import red
        PAGE_HEIGHT = canvas._pagesize[1]
        canvas.saveState()
        canvas.setStrokeColor(red)
        canvas.setLineWidth(5)
        canvas.line(66,72,66,PAGE_HEIGHT-72)
        canvas.setFont(_baseFontName,12)
        canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
        canvas.restoreState() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:doctemplate.py

示例10: get_header_footer

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def get_header_footer(self, recipient):
        def func(canvas, doc):
            width, height = letter
            margin = 0.66 * 72
            canvas.saveState()
            canvas.setFillColor("gray")
            canvas.drawString(margin, height - margin, "CONFIDENTIAL")
            canvas.drawRightString(width - margin, height - margin, str(timezone.now()))
            canvas.restoreState()

        return func 
开发者ID:project-callisto,项目名称:callisto-core,代码行数:13,代码来源:report_delivery.py

示例11: draw_vertical_text

# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import saveState [as 别名]
def draw_vertical_text(canvas, font_name, font_size, xto, ymid, text):
    tw = stringWidth(text, font_name, font_size);
    canvas.setFont(font_name, font_size);
    canvas.saveState();
    canvas.translate(xto, ymid - tw/2);
    canvas.rotate(90);
    canvas.drawString(0, 0, text);
    canvas.restoreState(); 
开发者ID:lucivpav,项目名称:cwg,代码行数:10,代码来源:draw.py


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