add local fonts all at once

workspace
Brendan Howell 5 years ago
parent a0977f28b9
commit 93b8b92683

@ -354,20 +354,19 @@ class Bureau(object):
# TODO: make paper size a config variable
pdfpath = tempfile.mkstemp(".pdf")[1]
self.log.debug("rendering to: " + pdfpath)
# manually add local fonts
fontconfig = FontConfiguration()
fontsdir = os.path.join(self.mdir, "fonts")
self.log.debug(fontsdir)
fontlist = []
for font in glob.glob(fontsdir + "/*.otf"):
fdict = {}
fdict["src"] = ("local", "file://" + font)
fontlist.append(("local", "file://" + font))
self.log.debug("adding font " + str(fdict))
fontconfig.add_font_face(fdict,
weasyprint.default_url_fetcher)
for font in glob.glob(fontsdir + "/*.ttf"):
fdict = {}
fdict["src"] = ("local", "file://" + font)
fontlist.append(("local", "file://" + font))
self.log.debug("adding font " + str(fdict))
fontconfig.add_font_face(fdict,
fdict["src"] = fontlist
fontconfig.add_font_face(fdict,
weasyprint.default_url_fetcher)
weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath, font_config=fontconfig)
subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + pdfpath, shell=True)

Loading…
Cancel
Save