add local fonts all at once

workspace
Brendan Howell 5 years ago
parent a0977f28b9
commit 93b8b92683

@ -354,19 +354,18 @@ 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))
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)

Loading…
Cancel
Save