Skip to content

Commit

Permalink
feat: Update weasyprint to 55.0
Browse files Browse the repository at this point in the history
This changes PDF generation from cairo to pydyf.
  • Loading branch information
kesara committed Jun 28, 2022
1 parent edcdc15 commit 005b007
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 45 deletions.
2 changes: 0 additions & 2 deletions configtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import sys
import warnings

warnings.filterwarnings("ignore", message='There are known rendering problems and missing features with cairo < 1.15.4')

errors = 0

sys.stderr.write("Checking installation of test and development packages:\n")
for (pname, mname) in [
('decorator', 'decorator'),
('dict2xml', 'dict2xml'),
('pycairo', 'cairo'),
('PyPDF2', 'PyPDF2'),
]:
try:
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def norm(t):
self.assertIn(t, text)

def test_included_fonts(self):
if xml2rfc.HAVE_WEASYPRINT and xml2rfc.HAVE_PYCAIRO and xml2rfc.HAVE_CAIRO and xml2rfc.HAVE_PANGO:
if xml2rfc.HAVE_WEASYPRINT and xml2rfc.HAVE_PANGO:
font_families = set([ f.text for f in self.pdfxml.xpath('.//FontFamily') ])
for script in self.root.get('scripts').split(','):
family = xml2rfc.util.fonts.get_noto_serif_family_for_script(script)
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ deps =
-rrequirements.txt
decorator
dict2xml==1.7
pycairo<1.20
pypdf2<1.27.0
weasyprint<53
weasyprint==55.0
15 changes: 1 addition & 14 deletions xml2rfc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,7 @@
weasyprint = False
HAVE_WEASYPRINT = False
try:
import cairo
HAVE_PYCAIRO = True
except (ImportError, OSError):
cairo = False
HAVE_PYCAIRO = False
try:
from weasyprint.text import cairo
HAVE_CAIRO = True
CAIRO_VERSION = cairo.cairo_version()
except (ImportError, OSError):
HAVE_CAIRO = False
CAIRO_VERSION = None
try:
from weasyprint.text import pango
from weasyprint.text.ffi import pango
HAVE_PANGO = True
PANGO_VERSION = pango.pango_version
except (ImportError, OSError, AttributeError):
Expand Down
29 changes: 5 additions & 24 deletions xml2rfc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def get_missing_pdf_libs():
missing = ""
if not xml2rfc.HAVE_WEASYPRINT:
missing += "\nCould not import weasyprint"
if not xml2rfc.HAVE_PYCAIRO:
missing += "\nCould not import pycairo"
if not xml2rfc.HAVE_CAIRO:
missing += "\nCould not find the cairo lib"
if not xml2rfc.HAVE_PANGO:
missing += "\nCould not find the pango lib"
return missing
Expand Down Expand Up @@ -84,29 +80,14 @@ def get_pdf_help(missing_libs=""):
In order to generate PDFs, xml2rfc uses the WeasyPrint library, which
depends on external libaries that must be installed as native packages.
1. First, install the Cairo, Pango, and GDK-PixBuf library files on your
1. First, install the Pango, and other required libraries on your
system. See installation instructions on the WeasyPrint Docs:
https://weasyprint.readthedocs.io/en/stable/install.html
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html
(Python 3 is not needed if your system Python is 2.7, though).
2. Next, install weasyprint python modules using pip.
2. Next, install the pycairo and weasyprint python modules using pip.
Depending on your system, you may need to use 'sudo' or install in
user-specific directories, using the --user switch. On OS X in
particular, you may also need to install a newer version of setuptools
using --user before weasyprint can be installed. If you install with
the --user switch, you may need to also set PYTHONPATH, e.g.,
PYTHONPATH=/Users/username/Library/Python/2.7/lib/python/site-packages
for Python 2.7.
The basic pip commands (modify as needed according to the text above)
are:
pip install 'pycairo>=1.18' 'weasyprint<=0.42.3'
pip install 'weasyprint==55.0'
3. Finally, install the full Noto Font and Roboto Mono packages:
Expand Down Expand Up @@ -212,7 +193,7 @@ def main():
help='outputs formatted HTML to file')
formatgroup.add_argument('--nroff', action='store_true',
help='outputs formatted nroff to file (only v2 input)')
if xml2rfc.HAVE_CAIRO and xml2rfc.HAVE_PANGO:
if xml2rfc.HAVE_PANGO:
formatgroup.add_argument('--pdf', action='store_true',
help='outputs formatted PDF to file')
else:
Expand Down
13 changes: 11 additions & 2 deletions xml2rfc/writers/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import warnings

warnings.filterwarnings("ignore", message='There are known rendering problems with Cairo <= 1.14.0')
warnings.filterwarnings("ignore", message='There are known rendering problems and missing features with cairo < 1.15.4')
warnings.filterwarnings("ignore", message='@font-face support needs Pango >= 1.38')

try:
Expand Down Expand Up @@ -44,6 +42,8 @@ def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
return

logging.basicConfig(level=logging.INFO)

# Weasyprint logger
wplogger = logging.getLogger('weasyprint')
if self.options.quiet:
wplogger.setLevel(logging.CRITICAL)
Expand All @@ -52,6 +52,15 @@ def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
else:
wplogger.setLevel(logging.ERROR)

# fontTools logger
ftlogger = logging.getLogger('fontTools')
if self.options.quiet:
ftlogger.setLevel(logging.CRITICAL)
elif self.options.verbose:
ftlogger.setLevel(logging.WARNING)
else:
ftlogger.setLevel(logging.ERROR)

def pdf(self):
if not weasyprint:
return None
Expand Down

0 comments on commit 005b007

Please sign in to comment.