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


Python Canvas.roundRect方法代码示例

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


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

示例1: generateEntrancePDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]
    def generateEntrancePDF(self,response):
        #Attach name.pdf file to responses content disposition
        response['Content-Disposition'] = 'attachment; filename=entrance.pdf'
        
        #Create empty pdf document, hook pdf with response
        pdf = Canvas(response)



        pdf.setFillColor(colors.black) #sets Line/Rectangle Colors
        pdf.roundRect(10, 755, 575, 75, 10, 1, 0)
        pdf.setFont("Helvetica-Bold", 40)
        pdf.setStrokeColorRGB(0, 0, 0) #sets Line/Rectangle Colors
        pdf.drawCentredString(300, 790, "GroupFinder")
        pdf.setFont("Helvetica-Bold", 20)
        pdf.drawString(15, 765, "The following spaces are reserved during scheduled hours")

        
        pdf.drawCentredString(300,725, datetime.datetime.now().strftime("%A, %B %d, %Y"))

        #Get Todays Events
        brains = sorted(util.gatherTodaysEvents(self), key=attrgetter('start','Title')) 
       
        index = 700
        i = 0
        for brain in brains:
            pdf.rect(45, index-30, 510, 42, stroke=1, fill=0) #Schedule List Rectangles
            if util.isPublic(self,brain.id):
                title = brain.Title
            else:
                title = "Private Group"
                
            pdf.setFont("Helvetica-Bold", 17)
            pdf.drawString(50, index-5, DateTime(brain.start).strftime("%I:%M %p").lower() +
                                        " - " + DateTime(brain.end).strftime("%I:%M %p").lower() +
                                        " : " + title)
            pdf.setFont("Helvetica", 17)
            l = self.locationLookup(brain.location)
            pdf.drawString(50, index-25, "Location: " + l['Name'] + " - " + l['DirectionsShort'])
            
            index -= 42
            i += 1
            if i == 13:
                pdf.setFont("Helvetica", 17)
                pdf.drawCentredString(300, index-5, "See Website For More Study Groups!")
                break
        
        pdf.setFont("Helvetica-Bold", 28)
        pdf.drawCentredString(300, 90, "Use GroupFinder to Reserve a Study Space.")
        pdf.setFont("Helvetica", 24)
        pdf.drawCentredString(300, 60, "http://www.uwosh.edu/library/groupfinder")
        
        pdf = self.tableFooter(pdf)
        
        pdf.showPage() #next page, finalize last page.
        pdf.save() #save the pdf content
        return response #return response with hooked pdf.
开发者ID:uwosh,项目名称:uwosh.librarygroupfinder,代码行数:59,代码来源:print.py

示例2: rect

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]
def rect(path, width, height, radius=None, margin=0.1*inch):
    canvas = Canvas(path, pagesize=(width + 2*margin, height + 2*margin))
    set_vector_cut(canvas)

    if radius:
        canvas.roundRect(margin, margin, width, height, radius)
    else:
        canvas.rect(margin, margin, width, height)

    canvas.showPage()
    canvas.save()
开发者ID:chase-ok,项目名称:hollow-books-render,代码行数:13,代码来源:rect.py

示例3: PDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]

#.........这里部分代码省略.........
                else:  # texto com formatação
                    componentes = (
                        componentes[0],
                        Paragraph("".join([linhas[0].words[i].text for i in range(len(linhas[0].words))]), estilo),
                    )
        for componente in componentes:
            larg, alt = componente.wrapOn(self.canvas, largura_texto, altura_texto)
            altura_total += alt
            altura_texto -= alt
            renderizados.append((altura_total, componente, larg))
        altura_total -= ajuste_inferior
        if altura_total < altura - espacamento:
            altura_total = altura - espacamento
        if posicao:
            x, y = posicao
            y = self.canvas._pagesize[1] - y
        else:
            pi = self.ponto_insercao(largura, altura_total + espacamento)
            if pi:
                x, y = pi
            else:
                print (
                    'Um objeto de %i cm x %i cm não coube na página do PDF "%s" e será apresentado'
                    "no canto inferior direito desta página" % (largura / cm, altura_total / cm, self.titulo)
                )
                x = self.canvas._pagesize[0] - largura - espessura / 2
                y = altura_total + espacamento + espessura / 2
        # print "Posição:", x/mm, y/mm
        for renderizado in renderizados:
            self.canvas.setLineWidth(espessura)
            # renderizado[1].drawOn(self.canvas, x + espacamento / 2, y - renderizado[0] - espacamento / 2)
            renderizado[1].drawOn(self.canvas, x + (largura - renderizado[2]) / 2, y - renderizado[0] - espacamento / 2)
        if borda:
            self.canvas.roundRect(
                x, y - altura_total - espacamento, largura, altura_total + espacamento, arredondamento
            )
        return (x, y, largura, altura_total + espacamento)

    def altura(
        self,
        largura,
        altura,
        titulo,
        dados,
        borda=True,
        arredondamento=0.5 * mm,
        ajuste_inferior=0 * mm,
        espacamento=None,
        posicao=None,
        espessura=None,
        alinhamento="justa",
        multilinha=None,
    ):
        if espessura == None:
            espessura = self.espessura
        if not espacamento:
            espacamento = self.espacamento * 2
        else:
            espacamento *= 2
        if alinhamento.lower() == "esquerda":
            estilo = normal_esquerda
        elif alinhamento.lower() == "direita":
            estilo = normal_direita
        elif alinhamento.lower() == "centro":
            estilo = normal_centro
        else:
开发者ID:rodrigorodriguescosta,项目名称:pole,代码行数:70,代码来源:PolePDF.py

示例4: Report

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]
class Report(object):
    render = {'table': render.TableRender,
              'pie':   render.PieRender,
              'histo': render.HistoRender,
              'line':  render.LineRender,
              'gantt': render.GanttRender,
             }

    margin = 30
    big_title_height = 40
    title_height = 50
    frame_margin = 5
    frag_title_height = 20
    frag_margin = 9
    edenwall_height = 60

    def __init__(self, title, enterprise, interval, logo):
        self.title = title
        self.enterprise = enterprise
        self.interval = interval
        self.logo = logo
        self.width, self.height = A4
        self.buf = StringIO()
        self.canvas = Canvas(self.buf, pagesize=A4)

        self.page_title = ''
        self.page_rows = []
        self.page_frags = 0
        self.page_num = 1

        # Build story.
        self.canvas.saveState()
        self.canvas.setStrokeColor(colors.RED)
        self.canvas.setLineWidth(2)
        self.canvas.roundRect(self.margin, self.edenwall_height + self.margin, self.width, self.height, 20, stroke=1, fill=0)

        self.canvas.setFillColor(colors.GREEN2)
        self.canvas.setStrokeColor(colors.GREEN1)
        self.canvas.roundRect(- self.margin, - self.margin, self.width - self.margin, self.edenwall_height + self.margin,
                              20, stroke=1, fill=1)
        # TODO do not hardcode this values.
        img = Image('/var/lib/ufwi_rpcd/edenwall.png', 1209 / (300/(self.edenwall_height-self.margin/2)), self.edenwall_height-self.margin/2)
        img.drawOn(self.canvas, self.margin, self.margin/4)

        self.canvas.restoreState()

        if self.logo:
            img = Image(StringIO(self.logo))
            img._setup_inner()
            img.drawOn(self.canvas, (self.width - self.margin)/2 - img.drawWidth/2, 2*self.height/3)

        offset = 40

        self.canvas.setFillColor(black)
        self.canvas.setFont("Helvetica-Bold", self.big_title_height)
        self.canvas.drawCentredString((self.width-self.margin)/2, self.height/3, title)
        self.canvas.setFont("Helvetica-Bold", self.frag_title_height)
        self.canvas.drawString(offset, self.height - offset, enterprise)

    def __getstate__(self):
        d = self.__dict__.copy()
        del d['canvas']
        return d

    def __setstate__(self, d):
        self.__dict__ = d
        self.canvas = Canvas(self.buf, pagesize=A4)

    def build(self):
        self.canvas.showPage()
        self.canvas.save()
        return self.buf

    def addGraph(self, title, columns, table, render):
        frags = self.page_frags
        for row, cols in enumerate(self.page_rows):
            frags -= cols
            if frags < 0:
                break

        if frags >= 0:
            self.addPage(self.page_title, self.page_rows)
            col = 0
            row = 0
            cols = self.page_rows[0]
        else:
            col = - frags - 1

        # You can read that? Not me.
        x = self.margin + self.frame_margin + (col+1) * self.frag_margin + \
            col * (self.width - 2*self.margin - 2*self.frame_margin - (col+1)*self.frag_margin) / cols
        y = self.margin + self.frame_margin + (row+1) * self.frag_margin + \
            row * (self.height - 2*self.margin - 2*self.frame_margin - self.title_height - 2*self.frag_margin) / len(self.page_rows)
        width = (self.width - 2*self.margin - 2*self.frame_margin - 2*cols*self.frag_margin) / cols
        height = (self.height - 2*self.margin - 2*self.frame_margin - self.title_height - 2*len(self.page_rows)*self.frag_margin) / len(self.page_rows)

        self.canvas.setFillColor(colors.GREEN1)
        self.canvas.roundRect(x, y, width, height, 7, stroke=0, fill=1)
        self.canvas.setFillColor(white)
        x += 1
#.........这里部分代码省略.........
开发者ID:maximerobin,项目名称:Ufwi,代码行数:103,代码来源:report.py

示例5: PDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]

#.........这里部分代码省略.........
        if titulo == '':
            componentes = (Paragraph(dados, estilo),)
        elif titulo:
            componentes = (Paragraph(titulo, pequena_esquerda), Paragraph(dados, estilo))
        else:
            componentes = dados
        altura_total = 0
        altura_texto = altura - espacamento + ajuste_inferior
        largura_texto = largura - espacamento
        renderizados = []
        if not multilinha and titulo and dados != '&nbsp;':
            componentes[1].wrapOn(self.canvas, largura_texto, altura_texto)
            linhas = componentes[1].breakLines(largura_texto).lines
            if len(linhas) > 0:
                if isinstance(linhas[0], tuple): # texto comum
                    componentes = (componentes[0], Paragraph(' '.join(linhas[0][1]), estilo))
                else: # texto com formatação
                    componentes = (componentes[0], Paragraph(''.join([linhas[0].words[i].text for i in range(len(linhas[0].words))]), estilo))
        for componente in componentes:
            larg, alt = componente.wrapOn(self.canvas, largura_texto, altura_texto)
            altura_total += alt
            altura_texto -= alt
            renderizados.append((altura_total, componente, larg))
        altura_total -= ajuste_inferior
        if altura_total < altura - espacamento:
            altura_total = altura - espacamento
        if posicao:
            x, y = posicao
            y = self.canvas._pagesize[1] - y
        else:
            pi = self.ponto_insercao(largura, altura_total + espacamento)
            if pi:
                x, y = pi
            else:
                print ('Um objeto de %i cm x %i cm não coube na página do PDF "%s" e será apresentado'
                       'no canto inferior direito desta página' % (largura / cm, altura_total / cm, self.titulo))
                x = self.canvas._pagesize[0] - largura - espessura / 2
                y = altura_total + espacamento + espessura / 2
        #print "Posição:", x/mm, y/mm
        for renderizado in renderizados:
            self.canvas.setLineWidth(espessura)
            #renderizado[1].drawOn(self.canvas, x + espacamento / 2, y - renderizado[0] - espacamento / 2)
            renderizado[1].drawOn(self.canvas, x + (largura - renderizado[2]) / 2, y - renderizado[0] - espacamento / 2)
        if borda:
            self.canvas.roundRect(x, y - altura_total - espacamento, largura, altura_total + espacamento, arredondamento)
        return (x, y, largura, altura_total + espacamento)

    def altura(self, largura, altura, titulo, dados, borda = True, arredondamento = 0.5 * mm, ajuste_inferior = 0 * mm, espacamento = None, posicao = None, espessura = None, alinhamento = 'justa', multilinha = None):
        if espessura == None:
            espessura = self.espessura
        if not espacamento:
            espacamento = self.espacamento * 2
        else:
            espacamento *= 2
        if alinhamento.lower() == 'esquerda':
            estilo = normal_esquerda
        elif alinhamento.lower() == 'direita':
            estilo = normal_direita
        elif alinhamento.lower() == 'centro':
            estilo = normal_centro
        else:
            estilo = normal_justa
        if titulo == '':
            componentes = (Paragraph(dados, estilo),)
        elif titulo:
            componentes = (Paragraph(titulo, pequena_esquerda), Paragraph(dados, estilo))
        else:
            componentes = dados
        altura_total = 0
        altura_texto = altura - espacamento + ajuste_inferior
        largura_texto = largura - espacamento
        renderizados = []
        if not multilinha and titulo and dados != '&nbsp;':
            componentes[1].wrapOn(self.canvas, largura_texto, altura_texto)
            linhas = componentes[1].breakLines(largura_texto).lines
            if len(linhas) > 0:
                if isinstance(linhas[0], tuple): # texto comum
                    componentes = (componentes[0], Paragraph(' '.join(linhas[0][1]), estilo))
                else: # texto com formatação
                    componentes = (componentes[0], Paragraph(''.join([linhas[0].words[i].text for i in range(len(linhas[0].words))]), estilo))
        for componente in componentes:
            larg, alt = componente.wrapOn(self.canvas, largura_texto, altura_texto)
            altura_total += alt
            altura_texto -= alt
            renderizados.append((altura_total, componente, larg))
        altura_total -= ajuste_inferior
        if altura_total < altura - espacamento:
            altura_total = altura - espacamento
        return altura_total + espacamento

    def salvar(self):
        self.canvas.save()

    def mostrar(self, programa = 'evince'):
        self.canvas.save()
        subprocess.Popen([programa, self.nome_do_arquivo])

    def nova_pagina(self):
        self.canvas.showPage()
        self.retangulos = [(0, 0, self.canvas._pagesize[0] - 2 * self.margem, self.canvas._pagesize[1] - 2 * self.margem)]
开发者ID:paulom,项目名称:pole,代码行数:104,代码来源:PolePDF.py

示例6: bid_sheets

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]
def bid_sheets ( pieces, output ):

    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    pdfmetrics.registerFont(TTFont(*settings.ARTSHOW_BARCODE_FONT))

    c = Canvas(output,pagesize=letter)

    pdf = PdfReader ( settings.ARTSHOW_BLANK_BID_SHEET )
    xobj = pagexobj ( pdf.pages[0] )
    rlobj = makerl ( c, xobj )
    
    nfs_pdf = PdfReader ( settings.ARTSHOW_BLANK_NFS_SHEET )
    nfs_xobj = pagexobj ( nfs_pdf.pages[0] )
    nfs_rlobj = makerl ( c, nfs_xobj )

    sheet_offsets = [
        (0,5.5),
        (4.25,5.5),
        (0,0),
        (4.25,0),
        ]

    sheets_per_page = len(sheet_offsets)
    sheet_num = 0
    pieceiter = iter(pieces)
    if artshow_settings.ARTSHOW_BID_SHEET_PRECOLLATION:
        pieceiter = precollate_pieces(pieceiter)
    last_artist = None
    
    try:
        piece = pieceiter.next ()
        while True:
            try:
                for sheet_num in range(sheets_per_page):
                    if artshow_settings.ARTSHOW_BID_SHEET_PRECOLLATION:
                        if piece is None:
                            piece = pieceiter.next()
                            continue
                    else:
                        if piece.artist != last_artist and sheet_num != 0:
                            continue
                    c.saveState ()
                    c.translate ( sheet_offsets[sheet_num][0]*inch, sheet_offsets[sheet_num][1]*inch )
                    if piece.not_for_sale:
                        c.doForm ( nfs_rlobj )
                    else:
                        c.doForm ( rlobj )
                    c.saveState ()
                    c.setLineWidth ( 4 )
                    c.setFillColorRGB ( 1, 1, 1 )
                    c.setStrokeColorRGB ( 1, 1, 1 )
                    c.roundRect ( 1.1875*inch, 4.4375*inch, 1.75*inch, 0.5*inch, 0.0675*inch, stroke=True, fill=True )
                    c.restoreState ()
                    text_into_box ( c, u"*A"+unicode(piece.artist.artistid)+u"P"+unicode(piece.pieceid)+u"*", 1.3125, 4.6, 2.8125, 4.875, fontSize=13, style=barcode_style )
                    text_into_box ( c, "Artist "+unicode(piece.artist.artistid), 1.25, 4.4375, 2.0, 4.625 )
                    text_into_box ( c, "Piece "+unicode(piece.pieceid), 2.125, 4.4375, 2.875, 4.625 )
                    text_into_box ( c, piece.artist.artistname(), 1.125, 4.125, 3.875, 4.375 )
                    text_into_box ( c, piece.name, 0.75, 3.8125, 3.875, 4.0625 )
                    if piece.not_for_sale:
                        text_into_box ( c, piece.media, 0.875, 3.5, 2.375, 3.75 )
                    else:
                        text_into_box ( c, piece.media, 0.875, 3.5, 3.875, 3.75 )
                        text_into_box ( c, piece.not_for_sale and "NFS" or unicode(piece.min_bid), 3.25, 2.625, 3.75, 3.0 )
                        text_into_box ( c, piece.buy_now and unicode(piece.buy_now) or "N/A", 3.25, 1.9375, 3.75, 2.3125 )
                        text_into_box ( c, "X", 3.375, 0.375, 3.5625, 0.675, style=left_align_style, fontSize=16 )      
                    c.restoreState ()
                    last_artist = piece.artist
                    piece = pieceiter.next ()
            finally:
                c.showPage ()
    except StopIteration:
        pass

    c.save ()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:77,代码来源:preprint.py

示例7: PDFGenerator

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import roundRect [as 别名]
class PDFGenerator(ReportGenerator):
    """This is a generator to output a PDF using ReportLab library with
    preference by its Platypus API"""
    filename = None

    _is_first_page = True
    _is_latest_page = True
    _current_top_position = 0
    _current_page_number = 0
    _current_object = None

    def __init__(self, report, filename):
        super(PDFGenerator, self).__init__(report)

        self.filename = filename

    def execute(self):
        """Generate a PDF file using ReportLab pdfgen package."""

        # Initializes the PDF canvas
        self.start_pdf(self.filename)

        self.generate_pages()

        # Finalizes the canvas
        self.canvas.save()

    def start_pdf(self, filename):
        """Initializes the PDF document with some properties and methods"""
        # Sets the PDF canvas
        self.canvas = Canvas(filename=filename, pagesize=self.report.page_size)

        # Set PDF properties
        self.canvas.setTitle(self.report.title)
        self.canvas.setAuthor(self.report.author)

        self._is_first_page = True

    def generate_band(self, band, top_position=None):
        """Generate a band having the current top position or informed as its
        top coordinate"""

        # Coordinates and dimensions
        temp_top = top_position = top_position or self.get_top_pos()
        band_rect = {
                'left': self.report.margin_left,
                'top': top_position,
                'right': self.report.page_size[0] - self.report.margin_right,
                'bottom': top_position - band.height,
                }
        # This should be done by a metaclass in Report domain TODO
        band.width = self.report.page_size[0] - self.report.margin_left - self.report.margin_right

        # Loop at band widgets
        for element in band.elements:
            # Widget element
            if isinstance(element, Widget):
                widget = element

                # Set element colors
                self.set_fill_color(self.report.default_font_color)

                # Set widget basic attributes
                widget.instance = self._current_object
                widget.generator = self
                widget.report = self.report # This should be done by a metaclass in Band domain TODO
                widget.band = band # This should be done by a metaclass in Band domain TODO

                if isinstance(widget, Label):
                    para = Paragraph(widget.text, ParagraphStyle(name='Normal', **widget.style))
                    para.wrapOn(self.canvas, widget.width, widget.height)
                    para.drawOn(self.canvas, self.report.margin_left + widget.left, temp_top - widget.top - para.height)

            # Graphic element
            elif isinstance(element, Graphic):
                graphic = element

                # Set element colors
                self.set_fill_color(graphic.fill_color or self.report.default_fill_color)
                self.set_stroke_color(graphic.stroke_color or self.report.default_stroke_color)
                self.set_stroke_width(graphic.stroke_width)

                if isinstance(element, RoundRect):
                    self.canvas.roundRect(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top - graphic.height,
                            graphic.width,
                            graphic.height,
                            graphic.radius,
                            graphic.stroke,
                            graphic.fill,
                            )
                elif isinstance(element, Rect):
                    self.canvas.rect(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top - graphic.height,
                            graphic.width,
                            graphic.height,
                            graphic.stroke,
                            graphic.fill,
#.........这里部分代码省略.........
开发者ID:macndesign,项目名称:django-geraldo,代码行数:103,代码来源:pdf.py


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