本文整理汇总了Python中reportlab.pdfbase.pdfmetrics.registerTypeFace函数的典型用法代码示例。如果您正苦于以下问题:Python registerTypeFace函数的具体用法?Python registerTypeFace怎么用?Python registerTypeFace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerTypeFace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register_font
def register_font(font_name, family=""):
try:
return _registered_font_names[font_name]
except KeyError:
pass
found = ff.getFontsWithAttributes(name=font_name)
if not found:
# print '%(font_name)s not found, loading default for rl_config %(res)s' % locals()
res = rl_config.defaultGraphicsFontName
else:
descr = found[0]
if descr.typeCode == "ttf":
font = TTFont(descr.name, descr.fileName)
else:
face = pdfmetrics.EmbeddedType1Face(descr.metricsFileName, descr.fileName)
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(font_name, font_name, rl_config.defaultEncoding)
pdfmetrics.registerFont(font)
res = font_name
if 10:
from reportlab.lib.fonts import addMapping
bold = int("Bold" in font_name)
italic = int("Italic" in font_name)
addMapping(family or font_name, bold, italic, font_name)
_registered_font_names[font_name] = res
return res
开发者ID:svilendobrev,项目名称:rl2wx,代码行数:28,代码来源:fonts.py
示例2: __init__
def __init__(self, path, margin_x=48, margin_y=60, file_name='Untitled.pdf',
file_name_S3='Untitled.pdf', is_landscape=False, author=None, title=None):
self.path = path
self.margin_x = self.origin_x = margin_x
self.margin_y = self.origin_y = margin_y
self.file_name = file_name
self.is_landscape = is_landscape
self.author = author
self.title = title
# embeds "Hand of Sean" font:
afmFile = os.path.join(settings.FONT_ROOT, 'HandOfSean.afm')
pfbFile = os.path.join(settings.FONT_ROOT, 'HandOfSean.pfb')
ttfFile = os.path.join(settings.FONT_ROOT, 'handsean.ttf')
justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile) #embeds font
faceName = 'HandOfSean' # pulled from AFM file
pdfmetrics.registerTypeFace(justFace)
justFont = pdfmetrics.Font('HandSean', faceName, 'WinAnsiEncoding')
pdfmetrics.registerFont(justFont)
pdfmetrics.registerFont(TTFont('HandSean', ttfFile))
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename=' + self.file_name
self.set_orientation(self.is_landscape)
self.canvas = canvas.Canvas(self.path + '/' + self.file_name,
pagesize=(self.page_width, self.page_height))
if self.author is not None:
self.canvas.setAuthor(self.author)
if self.title is not None:
self.canvas.setTitle(self.title)
开发者ID:LocalGround,项目名称:localground,代码行数:32,代码来源:reports.py
示例3: __makeParaStyles
def __makeParaStyles(self):
psn = '_%s__paraStyles' % self.__class__.__name__
if not hasattr(self.__class__,psn):
from reportlab.pdfbase import pdfmetrics
fontDir = self.getFontDir()
if fontDir is None:
fontName = 'Helvetica-Bold'
else:
face = pdfmetrics.EmbeddedType1Face(os.path.join(fontDir,'eurosbe2.afm'),os.path.join(fontDir,'eurosbe2.pfb'))
pdfmetrics.registerTypeFace(face)
fontName = "Eurostile-BoldExtendedTwo"
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY
from reportlab.lib.colors import white, PCMYKColor
from reportlab.lib import colors
colors.fidblue = fidblue = PCMYKColor(60,40,0,20,spotName='FidelityBlue',density=100)
colors.fidlightblue = PCMYKColor(12.1568,8.2353,0,3.9216,spotName='FidelityLightBlue',density=100)
S = []
a = S.append
normal = getSampleStyleSheet()['Normal']
a(ParagraphStyle('ct0',normal, fontName=fontName, fontSize=12,leading=14.4, spaceAfter=6, spacebefore=6,textColor=fidblue))
a(ParagraphStyle('ct1',normal, alignment=TA_CENTER, fontName="Helvetica-Bold", fontSize=7, textColor=white, leading=1.2*7))
a(ParagraphStyle('ct2',normal, alignment=TA_CENTER, fontName="Helvetica", fontSize=6, leading=8))
a(ParagraphStyle('ct3',normal, alignment=TA_JUSTIFY, fontName="Helvetica", fontSize=5.5, leading=6))
a(ParagraphStyle('ct4',normal, fontName="Helvetica-Bold", fontSize=7, textColor=white,leading=7*1.2))
a(ParagraphStyle('ct5',normal, alignment=TA_LEFT, fontName="Helvetica", fontSize=5, leading=5.5))
a(ParagraphStyle('ct6',normal, alignment=TA_RIGHT, fontName="Helvetica", fontSize=5, leading=5.5))
a(ParagraphStyle('ct7',normal, alignment=TA_CENTER, fontName="Helvetica", fontSize=5, leading=5.5))
a(ParagraphStyle('ct8',normal, alignment=TA_JUSTIFY, fontName="Helvetica", fontSize=5.5, leading=6.0))
a(ParagraphStyle('ct9',normal, alignment=TA_CENTER, fontName="Helvetica-Bold", fontSize=6, leading=1.2*6))
setattr(self.__class__,psn,S)
开发者ID:AndyKovv,项目名称:hostel,代码行数:30,代码来源:chargestable.py
示例4: _register_fonts
def _register_fonts(self):
afmfile, pfbfile, fontname = self.TITLE_FONT
registerTypeFace(EmbeddedType1Face(afmfile, pfbfile))
registerFont(Font(fontname, fontname, 'WinAnsiEncoding'))
for suffix in ['', '-Bold', '-Oblique', '-BoldOblique']:
registerFont(TTFont(self.MONO_FONT[0].format(suffix),
self.MONO_FONT[1].format(suffix)))
registerFontFamily('Mono', normal='Mono', bold='Mono-Bold',
italic='Mono-Oblique', boldItalic='Mono-BoldOblique')
开发者ID:dolvany,项目名称:dtrace-stap-book,代码行数:10,代码来源:pdf.py
示例5: embed_font
def embed_font(self, path, face_name):
"""
Register a font face with ReportLab an (if used) embed in the target PDF.
"""
## Based on snippet from http://www.reportlab.org/devfaq.html
afm = os.path.join(path, face_name + '.afm')
pfb = os.path.join(path, face_name + '.pfb')
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(face_name, face_name, 'WinAnsiEncoding')
pdfmetrics.registerFont(font)
开发者ID:Troush,项目名称:django-jobs-system,代码行数:11,代码来源:font.py
示例6: reg_font_afm
def reg_font_afm(head,root):
afmFile = os.path.join(head,root+".afm")
pfbFile = os.path.join(head,root+".pfb")
(topLevel, glyphData) = pdfmetrics.parseAFMFile(afmFile)
faceName=topLevel['FontName']
justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
pdfmetrics.registerTypeFace(justFace)
justFont = pdfmetrics.Font(faceName, faceName, 'WinAnsiEncoding')
pdfmetrics.registerFont(justFont)
return
开发者ID:reingart,项目名称:web2conf,代码行数:12,代码来源:RD.py
示例7: font_start
def font_start(self, name, ttf=None, afm=None, pfb=None):
# True Type Fonts
if ttf:
font_path = os.path.join(self.font_dir, ttf)
pdfmetrics.registerFont(TTFont(name, font_path))
return
# Type 1
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(name, name, 'WinAnsiEncoding')
pdfmetrics.registerFont(font)
开发者ID:Cuahutli,项目名称:pypdfml,代码行数:13,代码来源:pypdfml.py
示例8: registerFont0
def registerFont0(sourceFile, name, path):
"Register Type-1 font for future use, simple version."
rl_config.warnOnMissingFontGlyphs = 0
p = os.path.join(os.path.dirname(sourceFile), path)
afmFiles = glob.glob(p + ".[aA][fF][mM]")
pfbFiles = glob.glob(p + ".[pP][fF][bB]")
assert len(afmFiles) == len(pfbFiles) == 1, FontFilesNotFoundError
T1face = pdfmetrics.EmbeddedType1Face(afmFiles[0], pfbFiles[0])
T1faceName = name
pdfmetrics.registerTypeFace(T1face)
T1font = pdfmetrics.Font(name, T1faceName, "WinAnsiEncoding")
pdfmetrics.registerFont(T1font)
开发者ID:radical-software,项目名称:radicalspam,代码行数:15,代码来源:pythonpoint.py
示例9: import_pdf_font
def import_pdf_font(self, base_name, face_name):
if self.fonts.get(face_name, None) is None:
afm = find(base_name + '.afm')
pfb = find(base_name + '.pfb')
try:
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(face_name, face_name, 'WinAnsiEncoding')
pdfmetrics.registerFont(font)
except:
pass
else:
self.fonts[face_name] = True
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:15,代码来源:parser.py
示例10: import_pdf_font
def import_pdf_font(self, base_name, face_name):
import os
import reportlab
from reportlab.pdfbase import pdfmetrics
if self.fonts.get(face_name, None) is None:
afm = os.path.join(settings.MEDIA_ROOT, base_name + '.afm')
pfb = os.path.join(settings.MEDIA_ROOT, base_name + '.pfb')
try:
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(face_name, face_name, 'WinAnsiEncoding')
pdfmetrics.registerFont(font)
except:
pass
else:
self.fonts[face_name] = True
开发者ID:gvangool,项目名称:django-pdfgen,代码行数:19,代码来源:parser.py
示例11: get
def get(self):
text = self.request.get('t')
if text:
pdfmetrics.registerTypeFace(pdfmetrics.EmbeddedType1Face(
os.path.join(folderFonts, 'DarkGardenMK.afm'),
os.path.join(folderFonts, 'DarkGardenMK.pfb')))
pdfmetrics.registerFont(pdfmetrics.Font(
'DarkGardenMK', 'DarkGardenMK', 'WinAnsiEncoding'))
p = canvas.Canvas(self.response.out)
p.drawImage('dog.jpg', 150, 400)
p.drawString(50, 700, 'The text you entered: ' + text)
p.setFont('DarkGardenMK', 16)
p.drawString(50, 600, 'DarkGarden font loaded from reportlab.zip')
p.showPage()
self.response.headers['Content-Type'] = 'application/pdf'
self.response.headers['Content-Disposition'] = 'filename=testpdf.pdf'
p.save()
else:
self.response.out.write(template.render('testpdf.html', {}))
开发者ID:prcek,项目名称:VitalMenuTracker,代码行数:22,代码来源:testpdf.py
示例12: _setup_font
def _setup_font(self, fontname, locale):
registerTypeFace(TypeFace('Times-Roman'))
if fontname != '(auto)':
if fontname not in self._stdfonts \
and fontname not in self._cidfonts:
fontname = '(auto)'
if fontname == '(auto)':
lang = None
if locale:
lang = str(locale).split('_', 1)[0]
fontname = {'ja': 'HeiseiKakuGo-W5',
'ko': 'HYGothic-Medium',
'zh': 'STSong-Light'}.get(lang, 'Helvetica')
if fontname in self._stdfonts:
font = TypeFace(fontname)
registerTypeFace(font)
elif fontname in self._cidfonts:
font = UnicodeCIDFont(fontname)
registerFont(font)
return fontname
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:24,代码来源:pdf.py
示例13: loadFont
def loadFont(self, names, src, encoding="WinAnsiEncoding", bold=0, italic=0):
# XXX Just works for local filenames!
if names and src: # and src.local:
file = src
src = file.uri
log.debug("Load font %r", src)
if type(names) is types.ListType:
fontAlias = names
else:
fontAlias = [x.lower().strip() for x in names.split(",") if x]
# XXX Problems with unicode here
fontAlias = [str(x) for x in fontAlias]
fontName = fontAlias[0]
parts = src.split(".")
baseName, suffix = ".".join(parts[: - 1]), parts[ - 1]
suffix = suffix.lower()
try:
if suffix == "ttf":
# determine full font name according to weight and style
fullFontName = "%s_%d%d" % (fontName, bold, italic)
# check if font has already been registered
if fullFontName in self.fontList:
log.warn(self.warning("Repeated font embed for %s, skip new embed ", fullFontName))
else:
# Register TTF font and special name
filename = file.getNamedFile()
pdfmetrics.registerFont(TTFont(fullFontName, filename))
# Add or replace missing styles
for bold in (0, 1):
for italic in (0, 1):
if ("%s_%d%d" % (fontName, bold, italic)) not in self.fontList:
addMapping(fontName, bold, italic, fullFontName)
# Register "normal" name and the place holder for style
self.registerFont(fontName, fontAlias + [fullFontName])
elif suffix in ("afm", "pfb"):
if suffix == "afm":
afm = file.getNamedFile()
tfile = pisaFileObject(baseName + ".pfb")
pfb = tfile.getNamedFile()
else:
pfb = file.getNamedFile()
tfile = pisaFileObject(baseName + ".afm")
afm = tfile.getNamedFile()
#afm = baseName + ".afm"
#pfb = baseName + ".pfb"
# determine full font name according to weight and style
fullFontName = "%s_%d%d" % (fontName, bold, italic)
#fontNameOriginal = ""
#for line in open(afm).readlines()[:-1]:
# if line[:16] == 'StartCharMetrics':
# self.error("Font name not found")
# if line[:8] == 'FontName':
# fontNameOriginal = line[9:].strip()
# break
# check if font has already been registered
if fullFontName in self.fontList:
log.warn(self.warning("Repeated font embed for %s, skip new embed", fontName))
else:
# Include font
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
fontNameOriginal = face.name
pdfmetrics.registerTypeFace(face)
# print fontName, fontNameOriginal, fullFontName
justFont = pdfmetrics.Font(fullFontName, fontNameOriginal, encoding)
pdfmetrics.registerFont(justFont)
# Add or replace missing styles
for bold in (0, 1):
for italic in (0, 1):
if ("%s_%d%d" % (fontName, bold, italic)) not in self.fontList:
addMapping(fontName, bold, italic, fontNameOriginal)
# Register "normal" name and the place holder for style
self.registerFont(fontName, fontAlias + [fullFontName, fontNameOriginal])
#import pprint
#pprint.pprint(self.fontList)
else:
log.warning(self.warning("wrong attributes for <pdf:font>"))
#.........这里部分代码省略.........
开发者ID:onia,项目名称:django-project-management,代码行数:101,代码来源:pisa_context.py
示例14: getJustFontPaths
fontSize=36))
d.add(String(150, 160, 'Hello World',
fontName='DarkGardenMK',
fontSize=36))
"""
)
from reportlab.pdfbase import pdfmetrics
from reportlab import rl_config
rl_config.warnOnMissingFontGlyphs = 0
afmFile, pfbFile = getJustFontPaths()
T1face = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
T1faceName = "DarkGardenMK"
pdfmetrics.registerTypeFace(T1face)
T1font = pdfmetrics.Font(T1faceName, T1faceName, "WinAnsiEncoding")
pdfmetrics.registerFont(T1font)
d = Drawing(400, 200)
for size in range(12, 36, 4):
d.add(String(10 + size * 2, 10 + size * 2, "Hello World", fontName="Times-Roman", fontSize=size))
d.add(String(130, 120, "Hello World", fontName="Courier", fontSize=36))
d.add(String(150, 160, "Hello World", fontName="DarkGardenMK", fontSize=36))
draw(d, "fancy font example")
heading3("""Paths""")
开发者ID:jbacou,项目名称:myReportLab_installPackage,代码行数:31,代码来源:graph_shapes.py
示例15: test0
def test0(self):
"""Make documents with embedded fonts.
Just vam Rossum has kindly donated a font which we may use
for testing purposes. You need to contact him at [email protected]
if you want to use it for real."""
#LettError fonts should always be there. The others are voluntary.
ok = 1
c = Canvas(outputfile('test_pdfbase_fontembed.pdf'))
c.setPageCompression(0)
c.setFont('Helvetica', 12)
c.drawString(100, 700, 'This is Helvetica. The text below should be different fonts...')
if os.path.isfile('GDB_____.AFM') and os.path.isfile('GDB_____.PFB'):
# a normal text font
garaFace = pdfmetrics.EmbeddedType1Face('GDB_____.AFM','GDB_____.PFB')
faceName = 'AGaramond-Bold' # pulled from AFM file
pdfmetrics.registerTypeFace(garaFace)
garaFont = pdfmetrics.Font('MyGaramondBold', faceName, 'WinAnsiEncoding')
pdfmetrics.registerFont(garaFont)
c.setFont('AGaramond-Bold', 12)
c.drawString(100, 650, 'This should be in AGaramond-Bold')
if os.path.isfile('CR______.AFM') and os.path.isfile('CR______.PFB'):
# one with a custom encoding
cartaFace = pdfmetrics.EmbeddedType1Face('CR______.AFM','CR______.PFB')
faceName = 'Carta' # pulled from AFM file
pdfmetrics.registerTypeFace(cartaFace)
cartaFont = pdfmetrics.Font('Carta', 'Carta', 'CartaEncoding')
pdfmetrics.registerFont(cartaFont)
text = 'This should be in Carta, a map symbol font:'
c.setFont('Helvetica', 12)
c.drawString(100, 600, text)
w = c.stringWidth(text, 'Helvetica', 12)
c.setFont('Carta', 12)
c.drawString(100+w, 600, ' Hello World')
# LettError sample - creates on demand, we hope
y = 550
## justFace = pdfmetrics.EmbeddedType1Face('LeERC___.AFM','LeERC___.PFB')
##
## faceName = 'LettErrorRobot-Chrome' # pulled from AFM file
## pdfmetrics.registerTypeFace(justFace)
##
## justFont = pdfmetrics.Font('LettErrorRobot-Chrome', faceName, 'WinAnsiEncoding')
## pdfmetrics.registerFont(justFont)
c.setFont('LettErrorRobot-Chrome', 12)
c.drawString(100, y, 'This should be in LettErrorRobot-Chrome')
def testNamedFont(canv, fontName):
canv.showPage()
makeWidthTestForAllGlyphs(canv, fontName, outlining=0)
testNamedFont(c, 'LettErrorRobot-Chrome')
c.save()
开发者ID:ShaulBarkan,项目名称:PRION,代码行数:66,代码来源:test_pdfbase_fontembed.py
示例16: autoEmbed
def autoEmbed(fname):
"""Given a font name, does a best-effort of embedding
said font and its variants.
Returns a list of the font names it registered with ReportLab.
"""
log.info('Trying to embed %s'%fname)
fontList = []
variants=[]
f = findFont(fname)
if f : # We have this font located
if f[0].lower()[-4:]=='.afm': #Type 1 font
family = families[f[2]]
# Register the whole family of faces
faces = [pdfmetrics.EmbeddedType1Face(*fonts[fn.lower()][:2]) for fn in family]
for face in faces:
pdfmetrics.registerTypeFace(face)
for face, name in zip(faces, family):
fontList.append(name)
font = pdfmetrics.Font(face, name, "WinAnsiEncoding")
log.info('Registering font: %s from %s'%\
(face,name))
pdfmetrics.registerFont(font)
# Map the variants
regular, italic, bold, bolditalic = family
addMapping(fname, 0, 0, regular)
addMapping(fname, 0, 1, italic)
addMapping(fname, 1, 0, bold)
addMapping(fname, 1, 1, bolditalic)
addMapping(regular, 0, 0, regular)
addMapping(regular, 0, 1, italic)
addMapping(regular, 1, 0, bold)
addMapping(regular, 1, 1, bolditalic)
log.info('Embedding as %s'%fontList)
return fontList
else: # A TTF font
variants = [fonts[f.lower()][0] for f in families[f[2]]]
if not variants: # Try fc-match
variants = findTTFont(fname)
# It is a TT Font and we found it using fc-match (or found *something*)
if variants:
for variant in variants:
vname = os.path.basename(variant)[:-4]
try:
if vname not in pdfmetrics._fonts:
_font=TTFont(vname, variant)
log.info('Registering font: %s from %s'%\
(vname,variant))
pdfmetrics.registerFont(_font)
except TTFError:
log.error('Error registering font: %s from %s'%(vname,variant))
else:
fontList.append(vname)
regular, bold, italic, bolditalic = [
os.path.basename(variant)[:-4] for variant in variants]
addMapping(regular, 0, 0, regular)
addMapping(regular, 0, 1, italic)
addMapping(regular, 1, 0, bold)
addMapping(regular, 1, 1, bolditalic)
log.info('Embedding via findTTFont as %s'%fontList)
return fontList
开发者ID:123667,项目名称:deviation-manual,代码行数:65,代码来源:findfonts.py
示例17: range
'afii10074', 'afii10075', 'afii10076', 'afii10077', 'afii10078',
'afii10079', 'afii10080', 'afii10081', 'afii10082', 'afii10083',
'afii10084', 'afii10085', 'afii10086', 'afii10087', 'afii10088',
'afii10089', 'afii10090', 'afii10091', 'afii10092', 'afii10093',
'afii10094', 'afii10095', 'afii10096', 'afii10097'
)
# Replace glyphs from code 128 to code 256 with cp1251 values
for i in range(128,256):
cyrenc[i] = cp1251[i-128]
# Register newly created encoding
pdfmetrics.registerEncoding(cyrenc)
# Register type face
pdfmetrics.registerTypeFace(cyrFace)
# Register the font with adding '1251' to its name
pdfmetrics.registerFont(pdfmetrics.Font(faceName+'1251', faceName, 'CP1251'))
# Use this font and set font size
c.setFont(faceName+'1251', 90)
# hello - 'Hello!' in Ukrainian. If you have Cyrillic keyboard layout and
# cp1251 system encoding just type Cyrillic text instead of its hexadecimal
# equivalent
hello = '\xcf\xf0\xe8\xe2\xb3\xf2!'
# Draw this text at last
c.drawString(125, 700, hello)
开发者ID:xtopherbrandt,项目名称:pivotalpdf,代码行数:30,代码来源:LoadCyrllicFont.py
示例18: process
def process(self):
args = self.getAttributeValues(valuesOnly=True)
face = pdfmetrics.EmbeddedType1Face(*args)
pdfmetrics.registerTypeFace(face)
开发者ID:contracode,项目名称:z3c.rml,代码行数:4,代码来源:document.py
示例19: loadFont
def loadFont(self, names, src, encoding="WinAnsiEncoding", bold=0, italic=0):
if names and src:
if type(names) is types.ListType:
fontAlias = names
else:
fontAlias = [x.lower().strip() for x in names.split(",") if x]
# XXX Problems with unicode here
fontAlias = [str(x) for x in fontAlias]
src = str(src)
fontName = fontAlias[0]
baseName, suffix = src.rsplit(".", 1)
suffix = suffix.lower()
try:
if suffix == "ttf":
# determine full font name according to weight and style
fullFontName = "%s_%d%d" % (fontName, bold, italic)
# check if font has already been registered
if fullFontName in self.fontList:
self.warning("Repeated font embed for %s, skip new embed " % fullFontName)
else:
# Register TTF font and special name
pdfmetrics.registerFont(TTFont(fullFontName, src))
# Add or replace missing styles
for bold in (0, 1):
for italic in (0, 1):
if ("%s_%d%d" % (fontName, bold, italic)) not in self.fontList:
addMapping(fontName, bold, italic, fullFontName)
# Register "normal" name and the place holder for style
self.registerFont(fontName, fontAlias + [fullFontName])
elif suffix in ("afm", "pfb"):
afm = baseName + ".afm"
pfb = baseName + ".pfb"
# determine full font name according to weight and style
fullFontName = "%s_%d%d" % (fontName, bold, italic)
# fontNameOriginal = ""
# for line in open(afm).readlines()[:-1]:
# if line[:16] == 'StartCharMetrics':
# self.error("Font name not found")
# if line[:8] == 'FontName':
# fontNameOriginal = line[9:].strip()
# break
# check if font has already been registered
if fullFontName in self.fontList:
self.warning("Repeated font embed for %s, skip new embed" % fontName)
else:
# Include font
face = pdfmetrics.EmbeddedType1Face(afm, pfb)
fontNameOriginal = face.name
pdfmetrics.registerTypeFace(face)
# print fontName, fontNameOriginal, fullFontName
justFont = pdfmetrics.Font(fullFontName, fontNameOriginal, encoding)
pdfmetrics.registerFont(justFont)
# Add or replace missing styles
for bold in (0, 1):
for italic in (0, 1):
if ("%s_%d%d" % (fontName, bold, italic)) not in self.fontList:
addMapping(fontName, bold, italic, fontNameOriginal)
# Register "normal" name and the place holder for style
self.registerFont(fontName, fontAlias + [fullFontName, fontNameOriginal])
# import pprint
# pprint.pprint(self.fontList)
else:
self.error("wrong attributes for <pdf:font>")
except Exception, e:
self.warning(ErrorMsg())
开发者ID:ahmedsalman,项目名称:django-project,代码行数:86,代码来源:pisa_context.py
示例20: getExamples
#.........这里部分代码省略.........
story.append(FrameBreak())
#######################################################################
# Examples Page 3
#######################################################################
story.append(Paragraph(
"Here are some examples of the remaining objects above.",
styleSheet['Italic']))
story.append(Paragraph("This is a bullet point", styleSheet['Bullet'], bulletText='O'))
story.append(Paragraph("Another bullet point", styleSheet['Bullet'], bulletText='O'))
story.append(Paragraph("""Here is a Table, which takes all kinds of formatting options...""",
styleSheet['Italic']))
story.append(platypus.Spacer(0, 12))
g = platypus.Table(
(('','North','South','East','West'),
('Quarter 1',100,200,300,400),
('Quarter 2',100,200,300,400),
('Total',200,400,600,800)),
(72,36,36,36,36),
(24, 16,16,18)
)
style = platypus.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'),
('ALIGN', (0,0), (-1,0), 'CENTRE'),
('GRID', (0,0), (-1,-1), 0.25, colors.black),
('LINEBELOW', (0,0), (-1,0), 2, colors.black),
('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)),
('TEXTCOLOR', (0,1), (0,-1), colors.black),
('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))
])
g.setStyle(style)
story.append(g)
story.append(FrameBreak())
#######################################################################
# Examples Page 4 - custom fonts
#######################################################################
# custom font with LettError-Robot font
import reportlab.rl_config
reportlab.rl_config.warnOnMissingFontGlyphs = 0
from reportlab.pdfbase import pdfmetrics
fontDir = os.path.join(os.path.dirname(reportlab.__file__),'fonts')
face = pdfmetrics.EmbeddedType1Face(os.path.join(fontDir,'LeERC___.AFM'),os.path.join(fontDir,'LeERC___.PFB'))
faceName = face.name # should be 'LettErrorRobot-Chrome'
pdfmetrics.registerTypeFace(face)
font = pdfmetrics.Font(faceName, faceName, 'WinAnsiEncoding')
pdfmetrics.registerFont(font)
# put it inside a paragraph.
story.append(Paragraph(
"""This is an ordinary paragraph, which happens to contain
text in an embedded font:
<font name="LettErrorRobot-Chrome">LettErrorRobot-Chrome</font>.
Now for the real challenge...""", styleSheet['Normal']))
styRobot = ParagraphStyle('Robot', styleSheet['Normal'])
styRobot.fontSize = 16
styRobot.leading = 20
styRobot.fontName = 'LettErrorRobot-Chrome'
story.append(Paragraph(
"This whole paragraph is 16-point Letterror-Robot-Chrome.",
styRobot))
story.append(FrameBreak())
if _GIF:
story.append(Paragraph("Here is an Image flowable obtained from a string filename.",styleSheet['Italic']))
story.append(platypus.Image(_GIF))
story.append(Paragraph( "Here is an Image flowable obtained from a utf8 filename.", styleSheet['Italic']))
story.append(platypus.Image(_GIF.encode('utf8')))
story.append(Paragraph("Here is an Image flowable obtained from a string file url.",styleSheet['Italic']))
story.append(platypus.Image(getFurl(_GIF)))
story.append(Paragraph("Here is an Image flowable obtained from an open file.",styleSheet['Italic']))
story.append(platypus.Image(open_for_read(_GIF,'b')))
story.append(FrameBreak())
try:
img = platypus.Image('http://www.reportlab.com/rsrc/encryption.gif')
story.append(Paragraph("Here is an Image flowable obtained from a string http url.",styleSheet['Italic']))
story.append(img)
except:
story.append(Paragraph("The image could not be obtained from a string http url.",styleSheet['Italic']))
story.append(FrameBreak())
if _JPG:
img = platypus.Image(_JPG)
story.append(Paragraph("Here is an JPEG Image flowable obtained from a filename.",styleSheet['Italic']))
story.append(img)
story.append(Paragraph("Here is an JPEG Image flowable obtained from an open file.",styleSheet['Italic']))
img = platypus.Image(open_for_read(_JPG,'b'))
story.append(img)
story.append(FrameBreak())
return story
开发者ID:roytest001,项目名称:PythonCode,代码行数:101,代码来源:test_platypus_general.py
注:本文中的reportlab.pdfbase.pdfmetrics.registerTypeFace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论