示例#1
0
 def process(self):
     args = dict(self.getAttributeValues(attrMapping=self.attrMapping))
     if 'encoding' in args:
         font = cidfonts.CIDFont(**args)
     else:
         font = cidfonts.UnicodeCIDFont(**args)
     pdfmetrics.registerFont(font)
示例#2
0
def hBoxText(msg, canvas, x, y, fontName):
    """Helper for stringwidth tests on Asian fonts.

    Registers font if needed.  Then draws the string,
    and a box around it derived from the stringWidth function"""
    canvas.saveState()
    try:
        font = pdfmetrics.getFont(fontName)
    except KeyError:
        font = cidfonts.UnicodeCIDFont(fontName)
        pdfmetrics.registerFont(font)

    canvas.setFillGray(0.8)
    canvas.rect(x,y,pdfmetrics.stringWidth(msg, fontName, 16),16,stroke=0,fill=1)
    canvas.setFillGray(0)
    canvas.setFont(fontName, 16,16)
    canvas.drawString(x,y,msg)
    canvas.restoreState()
示例#3
0
    def __init__(self):
        self.width, self.height = page_sizes["A4"]
        reportlab.lib.fonts.ps2tt = lambda psfn: ('STSong-Light', 0, 0)
        reportlab.lib.fonts.tt2ps = lambda fn, b, i: 'STSong-Light'
        reportlab.lib.styles.ParagraphStyle.defaults['wordWrap'] = "CJK"
        self.page_tail = None
        self.grid_head_height = 30
        self.row_height = 15
        self.style_grid = TableStyle([
            ('GRID', (0, 0), (-1, -1), 0.25, colors.gray),
            ('BOX', (0, 0), (-1, -1), 0.5, colors.black),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, -1), 'STSong-Light'),
            ('FONTSIZE', (0, 0), (-1, -1), 8),
            ('LEFTPADDING', (0, 0), (-1, -1), 1),
            ('RIGHTPADDING', (0, 0), (-1, -1), -5),
        ])
        self.style_table = TableStyle([
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, -1), 'STSong-Light'),
            ('FONTSIZE', (0, 0), (-1, -1), 8),
            ('LEFTPADDING', (0, 0), (-1, -1), 5),
            ('RIGHTPADDING', (0, 0), (-1, -1), 20),
        ])
        self.styleSheet = getSampleStyleSheet()
        self.styNormal = self.styleSheet['Normal']
        self.styNormal.spaceBefore = 6
        self.styNormal.spaceAfter = 6
        font = cidfonts.UnicodeCIDFont('STSong-Light')
        pdfmetrics.registerFont(font)

        self.style_head_text = ParagraphStyle(
            name="base",
            fontName="STSong-Light",
            leading=10,
            leftIndent=0,
            firstLineIndent=-10,
            spaceBefore=-10,
            spaceAfter=1,
            fontSize=8,
            wordWrap='CJK',
        )
        self.style_grid_head = ParagraphStyle(
            name="base",
            fontName="STSong-Light",
            leading=10,
            leftIndent=0,
            firstLineIndent=0,
            spaceBefore=1,
            fontSize=8,
            align="CENTER",
            wordWrap='CJK',
        )
        self.style_title = ParagraphStyle(
            name='normal',
            fontName='STSong-Light',
            fontSize=13,
            leading=30,  #1.2*12,
            spaceBefore=1,
            spaceAfter=1,
            parent=self.styleSheet['Heading1'],
            alignment=TA_CENTER,
            wordWrap='CJK',
        )
示例#4
0
 def process(self):
     args = self.getAttributeValues(valuesOnly=True)
     font = cidfonts.UnicodeCIDFont(*args)
     pdfmetrics.registerFont(font)