fix: Use new fonts for PDFization (#5688)

This commit is contained in:
Lars Eggert 2023-05-25 17:43:15 +03:00 committed by GitHub
parent 66f1ba3088
commit 5f4dfb87b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ from pathlib import Path
from lxml import etree
from typing import Optional, TYPE_CHECKING
from weasyprint import HTML as wpHTML
from weasyprint.text.fonts import FontConfiguration
from django.db import models
from django.core import checks
@ -626,6 +627,7 @@ class DocumentInfo(models.Model):
stylesheets.append(finders.find("ietf/css/document_html_txt.css"))
else:
text = self.htmlized()
stylesheets.append("https://static.ietf.org/fonts/noto-sans-mono/import.css")
cache = caches["pdfized"]
cache_key = name.split(".")[0]
@ -635,10 +637,12 @@ class DocumentInfo(models.Model):
pdf = None
if not pdf:
try:
font_config = FontConfiguration()
pdf = wpHTML(
string=text, base_url=settings.IDTRACKER_BASE_URL
).write_pdf(
stylesheets=stylesheets,
font_config=font_config,
presentational_hints=True,
optimize_size=("fonts", "images"),
)