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


Python pdfmetrics.registerFont函数代码示例

本文整理汇总了Python中reportlab.pdfbase.pdfmetrics.registerFont函数的典型用法代码示例。如果您正苦于以下问题:Python registerFont函数的具体用法?Python registerFont怎么用?Python registerFont使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get_paragraph_styles

    def get_paragraph_styles():
        from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
        from reportlab.lib.enums import TA_JUSTIFY, TA_RIGHT, TA_CENTER
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont

        pdfmetrics.registerFont(TTFont('Persian', 'Bahij-Nazanin-Regular.ttf'))
        pdfmetrics.registerFont(TTFont('Persian-Bold', 'Bahij-Nazanin-Bold.ttf'))
        styles = getSampleStyleSheet()
        styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY, fontName='Persian', fontSize=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Justify-Bold', alignment=TA_JUSTIFY, fontName='Persian-Bold', fontSize=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Right-indented', alignment=TA_RIGHT, fontName='Persian', fontSize=10,
                                  rightIndent=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Right', alignment=TA_RIGHT, fontName='Persian', fontSize=10,
                                  rightIndent=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Right-with-space', alignment=TA_RIGHT, fontName='Persian', fontSize=10,
                                  rightIndent=10, wordWrap='CJK', spaceBefore=12, spaceAfter=12, bulletAnchor='end',
                                  bulletIndent=5))
        styles.add(ParagraphStyle(name='Right-Bold', alignment=TA_RIGHT, fontName='Persian-Bold', fontSize=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Right-Bold-Titr', alignment=TA_RIGHT, fontName='Persian-Bold', fontSize=12,
                                  textColor=colors.cornflowerblue, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Right-small', alignment=TA_RIGHT, fontName='Persian', fontSize=8,
                                  rightIndent=20,
                                  wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Centre', alignment=TA_CENTER, fontName='Persian', fontSize=10, wordWrap='CJK'))
        styles.add(ParagraphStyle(name='Centre-Bold', alignment=TA_CENTER, fontName='Persian-Bold', fontSize=10, wordWrap='CJK'))
        return styles
开发者ID:RahyabGroup,项目名称:PyCore,代码行数:27,代码来源:farsi_styles.py

示例2: __init__

    def __init__(self, regFont='Anonymous Pro', pdfDir=gettempdir()):
        self.pdfDir = pdfDir
        for root, dirs, files in os.walk(os.getcwd()):  #to find Fonts directory regardless of how we're invoked
            if 'BPmono.ttf' in files:
                fontDir = root 
        
        self.regFont = regFont
        self.boldFont = regFont + ' Bold'

        self.fontSize = self.fontDict[regFont][2]
        fileNameReg = fontDir + os.sep + self.fontDict[regFont][0]
        fileNameBold = fontDir + os.sep + self.fontDict[regFont][1]
        pdfmetrics.registerFont(TTFont(self.regFont, fileNameReg))
        pdfmetrics.registerFont(TTFont(self.boldFont, fileNameBold))

        tmpCanv = canvas.Canvas('tmp.pdf')
        # cW - because 'charWidth' is too damn long
        self.cW = tmpCanv.stringWidth('W', fontName=regFont, fontSize=self.fontSize)
        del tmpCanv
        #---Table styles and widths
        self.styles = {}
        for tmpStyle in ['codes', 'clmHeader', 'clmLine', 'clmFooter1', 'clmFooter2', 'rptFooter']:
            self.styles[tmpStyle] = TableStyle([('VALIGN', (0,0), (-1,-1), 'TOP'),
                                                ('ALIGN', (0,0), (-1,-1), 'LEFT'),
                                                ('FONT', (0,0), (-1,-1), regFont, self.fontSize),
                                                ("BOTTOMPADDING",(0,0),(-1,-1),self.pad),
                                                ("TOPPADDING", (0,0),(-1,-1),self.pad),
                                                ("RIGHTPADDING", (0,0),(-1,-1),self.pad),
                                                ("LEFTPADDING", (0,0),(-1,-1),self.pad)])
开发者ID:fsrtechnologies,项目名称:fsrPy,代码行数:29,代码来源:GenPDFSet.py

示例3: docinit

    def docinit(self, els):
        from reportlab.lib.fonts import addMapping
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont

        for node in els:

            for font in node.findall('registerFont'):
                name = font.get('fontName').encode('ascii')
                fname = font.get('fontFile').encode('ascii')
                if name not in pdfmetrics._fonts:
                    pdfmetrics.registerFont(TTFont(name, fname))
                #by default, we map the fontName to each style (bold, italic, bold and italic), so that 
                #if there isn't any font defined for one of these style (via a font family), the system
                #will fallback on the normal font.
                addMapping(name, 0, 0, name)    #normal
                addMapping(name, 0, 1, name)    #italic
                addMapping(name, 1, 0, name)    #bold
                addMapping(name, 1, 1, name)    #italic and bold

            #if registerFontFamily is defined, we register the mapping of the fontName to use for each style.
            for font_family in node.findall('registerFontFamily'):
                family_name = font_family.get('normal').encode('ascii')
                if font_family.get('italic'):
                    addMapping(family_name, 0, 1, font_family.get('italic').encode('ascii'))
                if font_family.get('bold'):
                    addMapping(family_name, 1, 0, font_family.get('bold').encode('ascii'))
                if font_family.get('boldItalic'):
                    addMapping(family_name, 1, 1, font_family.get('boldItalic').encode('ascii'))
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:29,代码来源:trml2pdf.py

示例4: print_rep

def print_rep(uid):
    registerFont(TTFont('DroidSans', 'DroidSans.ttf'))

    pdf = StringIO()

    doc = SimpleDocTemplate(pdf, pagesize=A4)
    elements = []
    style = getSampleStyleSheet()
    style.add(ParagraphStyle(name='Header', alignment=TA_LEFT,
                             fontName='DroidSans',
                             fontSize=14, leading=16))
    style.add(ParagraphStyle(name='Left', alignment=TA_LEFT,
                             fontName='DroidSans',
                             fontSize=12))
    style.add(ParagraphStyle(name='Right', alignment=TA_RIGHT,
                             fontName='DroidSans',
                             fontSize=12))
    if uid == 0:
        elements.append(Paragraph(u'<u>Users List</u>', style['Header']))
        u = User.query.all()     
        for i, o in enumerate(u):
            elements.append(Paragraph(u'%s. %s %s %s' % (i+1, o.name, o.email, o.progress), style['Left']))
    else:
        u = User.query.get(uid)
        elements.append(Paragraph(u'%s %s %s' % (u.name, u.email, u.progress), style['Header']))

    doc.build(elements)
    pdf_file = pdf.getvalue()
    pdf.close()
    response = make_response(pdf_file)

    response.headers['Content-Disposition'] = "attachment; filename='pdf_user.pdf"
    response.mimetype = 'application/pdf'
    return response
开发者ID:nisiotis,项目名称:flask_app_2,代码行数:34,代码来源:__init__.py

示例5: pdftest

def pdftest(text=None):
    logging.info('pdftest')
    output = StringIO.StringIO()
   # pdfmetrics.registerTypeFace(pdfmetrics.EmbeddedType1Face(
   #         os.path.join(folderFonts, 'DarkGardenMK.afm'),
   #         os.path.join(folderFonts, 'DarkGardenMK.pfb')))
   # pdfmetrics.registerFont(pdfmetrics.Font(
   #         'DarkGardenMK', 'DarkGardenMK', 'WinAnsiEncoding'))

   # pdfmetrics.registerFont(TTFont('Vera', os.path.join(folderFonts,'Vera.ttf')))
    pdfmetrics.registerFont(TTFont('DejaVuSansMono', os.path.join(folderFonts,'DejaVuSansMono.ttf')))


    c = canvas.Canvas(output)    
    #c.setFont('DarkGardenMK', 16)
    c.setFont('DejaVuSansMono', 16)
    if text:
        c.drawString(100,100,text)
    else:
        c.drawString(100,100,'pdftest')

    c.showPage()
    c.save()
    logging.info('ok')    
    return output.getvalue() 
开发者ID:prcek,项目名称:VitalMenuTracker,代码行数:25,代码来源:pdf.py

示例6: add_font

def add_font(fontname, path=None):
    fontname = fontname.upper()
    if fontname not in fontnames:
        if path is None:
            def addit(args, d, names):
                for fn in names:
                    FN = fn.upper()
                    if FN[:-4] == fontname and FN[-4:] == '.TTF':
                        pdfmetrics.registerFont(TTFont(FN[:-4], os.path.join(d, fn)))
                        fontnames.append(fontname)
                        if not os.path.exists(os.path.join('./fonts/', fn)):
                            source = open(os.path.join(d, fn), 'rb')
                            dest = open(os.path.join('./fonts/', fn), 'wb')
                            dest.write(source.read())
                            dest.close()
                        break
            for fontdir in fontpath:
                os.path.walk(fontdir, addit, ())
                if fontname in fontnames:
                    break
        else:
            path = '%s/%s.ttf' % (path, fontname)
            pdfmetrics.registerFont(TTFont(fontname, path))
            fontnames.append(fontname)
    return fontname in fontnames
开发者ID:wyolum,项目名称:ClockFOUR,代码行数:25,代码来源:create_ClockFOUR_v1.py

示例7: _setup

def _setup():
    from reportlab.pdfbase import pdfmetrics, ttfonts
    pdfmetrics.registerFont(ttfonts.TTFont("Vera", "Vera.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBd", "VeraBd.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraIt", "VeraIt.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBI", "VeraBI.ttf"))
    F = ['Times-Roman','Courier','Helvetica','Vera', 'VeraBd', 'VeraIt', 'VeraBI']
    if sys.platform=='win32':
        for name, ttf in [
            ('Adventurer Light SF','Advlit.ttf'),('ArialMS','ARIAL.TTF'),
            ('Arial Unicode MS', 'ARIALUNI.TTF'),
            ('Book Antiqua','BKANT.TTF'),
            ('Century Gothic','GOTHIC.TTF'),
            ('Comic Sans MS', 'COMIC.TTF'),
            ('Elementary Heavy SF Bold','Vwagh.ttf'),
            ('Firenze SF','flot.ttf'),
            ('Garamond','GARA.TTF'),
            ('Jagger','Rols.ttf'),
            ('Monotype Corsiva','MTCORSVA.TTF'),
            ('Seabird SF','seag.ttf'),
            ('Tahoma','TAHOMA.TTF'),
            ('VerdanaMS','VERDANA.TTF'),
            ]:
            for D in ('c:\WINNT','c:\Windows'):
                fn = os.path.join(D,'Fonts',ttf)
                if os.path.isfile(fn):
                    try:
                        f = ttfonts.TTFont(name, fn)
                        pdfmetrics.registerFont(f)
                        F.append(name)
                    except:
                        pass
    return F
开发者ID:7o9,项目名称:stdm-plugin,代码行数:33,代码来源:testshapes.py

示例8: process

 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)
开发者ID:contracode,项目名称:z3c.rml,代码行数:7,代码来源:document.py

示例9: docinit

    def docinit(self, els):
        from reportlab.lib.fonts import addMapping
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont

        for node in els:
            for font in node.getElementsByTagName('registerFont'):
                name = font.getAttribute('fontName').encode('ascii')
                fname = font.getAttribute('fontFile').encode('ascii')
                pdfmetrics.registerFont(TTFont(name, fname))
                addMapping(name, 0, 0, name)    #normal
                addMapping(name, 0, 1, name)    #italic
                addMapping(name, 1, 0, name)    #bold
                addMapping(name, 1, 1, name)    #italic and bold
            for font in node.getElementsByTagName('registerTTFont'):
                name = font.getAttribute('faceName').encode('ascii')
                fname = font.getAttribute('fileName').encode('ascii')
                pdfmetrics.registerFont(TTFont(name, fname))	# , subfontIndex=subfontIndex
            for font in node.getElementsByTagName('registerFontFamily'):
                pdfmetrics.registerFontFamily(
                        font.getAttribute('normal').encode('ascii'),
                        normal = font.getAttribute('normal').encode('ascii'),
                        bold = font.getAttribute('bold').encode('ascii'),
                        italic = font.getAttribute('italic').encode('ascii'),
                        boldItalic = font.getAttribute('boldItalic').encode('ascii')
                )
开发者ID:tieugene,项目名称:rml2pdf,代码行数:26,代码来源:trml2pdf.py

示例10: ___test2_all

    def ___test2_all(self):
        """Dumps out ALl GLYPHS in a CID font.

        Reach for your microscope :-)"""
        try:
            from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile
            findCMapFile('90ms-RKSJ-H')
            findCMapFile('Identity-H')
        except:
            #don't have the font pack.  return silently
            return

        pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','Identity-H'))

        c = Canvas('test_japanese_2.pdf')
        c.setFont('Helvetica', 30)
        c.drawString(100,800, 'All Glyphs in Adobe-Japan-1-2 collection!')

        # the two typefaces
        c.setFont('HeiseiMin-W3-Identity-H', 2)

        x0 = 50
        y0 = 700
        dx = 2
        dy = 2
        for row in range(256):
            for cell in range(256):
                s = chr(row) + chr(cell)
                x = x0 + cell*dx
                y = y0 - row*dy
                c.drawString(x,y,s)

        c.save()
        if VERBOSE:
            print('saved '+outputfile('test_multibyte_jpn.pdf'))
开发者ID:Distrotech,项目名称:reportlab,代码行数:35,代码来源:test_multibyte_jpn.py

示例11: set_cyrillic_font

 def set_cyrillic_font(self):
     pdfmetrics.registerFont(TTFont('DejaVuSans', _self_path + u'/' 'DejaVuSans.ttf'))
     self.pdf.setFont('DejaVuSans', 10) # default font
     if self.debug:
         self.pdf.setFillColor(red)
     else:
         self.pdf.setFillColor(black)
开发者ID:vovkd,项目名称:russian-post-receipts,代码行数:7,代码来源:base_pdf.py

示例12: docinit

    def docinit(self, els):
        from reportlab.lib.fonts import addMapping
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.cidfonts import UnicodeCIDFont
        from reportlab.pdfbase.ttfonts import TTFont

        for node in els:
            # register CID fonts
            for subnode in node.getElementsByTagName('registerCidFont'):
                params = dict(
                    faceName=subnode.getAttribute('faceName').encode('utf-8'))
                font = self.font_resolver('UnicodeCIDFont', params)
                if font:
                    pdfmetrics.registerFont(font)
            # register TrueType fonts
            for subnode in node.getElementsByTagName('registerTTFont'):
                faceName = subnode.getAttribute('faceName').encode('utf-8')
                fileName = subnode.getAttribute('fileName').encode('utf-8')
                subfontIndex = subnode.getAttribute('subfontIndex')
                if subfontIndex:
                    subfontIndex = int(subfontIndex)
                else:
                    subfontIndex = 0
                params = dict(faceName=faceName,
                              fileName=fileName,
                              subfontIndex=subfontIndex)
                # Resolvers are recommended to implement cache.
                font = self.font_resolver('TTFont', params)
                if font:
                    pdfmetrics.registerFont(font)
开发者ID:clsdaniel,项目名称:template2pdf,代码行数:30,代码来源:trml2pdf.py

示例13: test_instanceStringWidth

 def test_instanceStringWidth(self):
     from reportlab.pdfbase.pdfmetrics import registerFont, getFont, _fonts, unicode2T1
     from reportlab.pdfbase.ttfonts import TTFont
     ttfn = 'Vera'
     t1fn = 'Times-Roman'
     registerFont(TTFont(ttfn, "Vera.ttf"))
     ttf = getFont(ttfn)
     t1f = getFont(t1fn)
     testCp1252 = 'copyright %s trademark %s registered %s ReportLab! Ol%s!' % (chr(169), chr(153),chr(174), chr(0xe9))
     enc='cp1252'
     senc = 'utf8'
     ts = 'ABCDEF\xce\x91\xce\xb2G'
     utext = 'ABCDEF\xce\x91\xce\xb2G'.decode(senc)
     fontSize = 12
     defns="ttfn t1fn ttf t1f testCp1252 enc senc ts utext fontSize ttf.face ttf.face.charWidths ttf.face.defaultWidth t1f.widths t1f.encName t1f.substitutionFonts _fonts"
     rcv = getrc(defns)
     def tfunc(f,ts,fontSize,enc):
         w1 = f.stringWidth(ts,fontSize,enc)
         w2 = f._py_stringWidth(ts,fontSize,enc)
         assert abs(w1-w2)<1e-10,"f(%r).stringWidthU(%r,%s,%r)-->%r != f._py_stringWidth(...)-->%r" % (f,ts,fontSize,enc,w1,w2)
     tfunc(t1f,testCp1252,fontSize,enc)
     tfunc(t1f,ts,fontSize,senc)
     tfunc(t1f,utext,fontSize,senc)
     tfunc(ttf,ts,fontSize,senc)
     tfunc(ttf,testCp1252,fontSize,enc)
     tfunc(ttf,utext,fontSize,senc)
     rcc = checkrc(defns,rcv)
     assert not rcc, "rc diffs (%s)" % rcc
开发者ID:Jbaumotte,项目名称:web2py,代码行数:28,代码来源:test_rl_accel.py

示例14: Text

	def Text(self, o):

		print(C.CTFontCreateWithName)


		attrString = Q.CFAttributedStringCreate(Q.kCFAllocatorDefault, o.text, {})
		line = Q.CTLineCreateWithAttributedString(attrString)
		Q.CGContextSetTextPosition(self.context, self.X(o.x), self.Y(o.y))
		Q.CTLineDraw(line, self.context)

		
		return ['']

		from reportlab.pdfbase import pdfmetrics
		from reportlab.pdfbase.ttfonts import TTFont
		if not os.path.basename(o.font) in self.registeredFonts:
			pdfmetrics.registerFont(TTFont(os.path.basename(o.font), o.font))
			self.registeredFonts.append(os.path.basename(o.font))

		if o.fillcolor:
			self.setFillColor(o.fillcolor)
		if o.strokecolor:
			self.setStrokeColor(o.strokecolor)

		self.reportlabcanvas.setFont(os.path.basename(o.font), o.fontsize)
		if o.align == 'left':
			self.reportlabcanvas.drawString(self.X(o.x), self.Y(o.y) - o.fontsize + .17*o.fontsize, o.text)
		elif o.align == 'center':
			self.reportlabcanvas.drawCentredString(self.X(o.x), self.Y(o.y) - o.fontsize + .17*o.fontsize, o.text)
		elif o.align == 'right':
			self.reportlabcanvas.drawRightString(self.X(o.x), self.Y(o.y) - o.fontsize + .17*o.fontsize, o.text)


		return ['']
开发者ID:yanone,项目名称:ynglib,代码行数:34,代码来源:QuartzPDF.py

示例15: make_cd_pdf

def make_cd_pdf(item_list):
    """Create CD label pdf"""

    # Filter non-CD items, copied items, split item bases, compilation items after the first for each CD
    cd_label_list = [each_item for each_item in item_list if \
        each_item.compilation_cd_item_counter <= 1 and 'cd' in each_item.format and \
        not (each_item.copies > 1 and not each_item.copy_counter) and \
        not (each_item.long and not each_item.side)]

    if not cd_label_list:
        logging.warning('No CD labels to print.')
        return
    logging.info('cd_label_list: ({0}): {1}'.format(len(cd_label_list), [item.name for item in cd_label_list]))

    # Draw CD labels
    c = canvas.Canvas(os.path.join(pdf_folder, 'cd-labels.pdf'), pagesize=(150 * mm, 320 * mm))
    width, height = (150 * mm, 320 * mm)
    pdfmetrics.registerFont(TTFont('Garamond', font_path))
    for item in cd_label_list:
        # Clipping
        path = c.beginPath()
        path.circle(81 * mm, 113 * mm, 60 * mm)
        path.circle(81 * mm, 113 * mm, 11 * mm)
        c.clipPath(path, stroke = 1, fill = 0)
        # Draw CD image
        if not item.counter_image_path:
            item.counter_image_path = make_cover_image(item)
        c.drawImage(item.counter_image_path, 20 * mm, 52 * mm, width=120 * mm, height=120 * mm)
        c.showPage()
    c.save()
开发者ID:broxeph,项目名称:ameryn,代码行数:30,代码来源:print_labels.py


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