Fix some pytest failures on Windows #599
There are more than 60 snippets using
The Pango crash itself is invisible/suppressed in the pytest; test_api.test_bookmark passes, no problem.
Parsing the snippet on its own produces the following bewildering messages:
What? What is Windows trying to tell?
BTW: 'DejaVu Serif Bold 0' can't be ugly because it is invisible.
The induced crashing cairocffi.context.Context produces about 1000 to 2000 log lines per failing test. Dont think that the backtraces are very helpful. Nevertheless, if you want me to, I'll try to make an extract of maybe relevant lines.
I suspect it's another missing DLL, will investigate
Managed to capture useful error log by parsing the following snippet:
<div> prepare crash </div> <div style="font-size: 0; break-before:always"> crash with font-size 0 on page 2 </div> <div style="break-before:always"> page 3 </div>
The "prepare crash" is important. Without it -- no problems. Page breaks for proof of speculations.
Until now: everything is ok/as expected.
On Page 2 the div with font-size 0 hits Cairo/Pango:
The offending code seems to be located in the function
In any case: No reason to stop or crash -- not yet.
The Zero-Font-Size crashes Cairo -- not Pango! -- when we actually try to draw on a surface.
That's the short version of the backtrace. Unshortened there are lots of "During handling of the above exception, another exception occurred" only repeating that the
Will undo the last commit in this PR.
Thank you really much, that's an impressive report.
I've had bad times reporting Cairo bugs for corner cases, we should try to find a workaround in WeasyPrint in my opinion.
I don't exactly remember what's been done to avoid text with
I think that the font metrics are requested when layouts are created. Maybe we should try to prevent the creation of these layouts (they're useless by the way). I'll try to find a quick fix if possible.
Here's a patch that may help:
2 files changed, 12 insertions(+) weasyprint/css/computed_values.py | 2 ++ weasyprint/text.py | 10 ++++++++++ modified weasyprint/css/computed_values.py @@ -304,6 +304,8 @@ def length(computer, name, value, font_size=None, pixels_only=False): result = value.value * font_size * ex_ratio(computer.computed) elif unit == 'ch': # TODO: cache + if font_size == 0: + return 0 layout = text.Layout( context=None, font_size=font_size, style=computer.computed) modified weasyprint/text.py @@ -626,6 +626,9 @@ def first_line_metrics(first_line, text, layout, resume_at, space_collapse, class Layout(object): """Object holding PangoLayout-related cdata pointers.""" def __init__(self, context, font_size, style): + # Cairo crashes with font-size: 0 + assert font_size + self.context = context hinting = context.enable_hinting if context else False self.layout = ffi.gc( @@ -690,6 +693,8 @@ class Layout(object): def set_tabs(self, style): if isinstance(style['tab_size'], int): + if style['font_size'] == 0: + width = 0 layout = Layout( context=self.context, font_size=style['font_size'], style=style) @@ -838,6 +843,11 @@ def create_layout(text, style, context, max_width, justification_spacing): or ``None`` for unlimited width. """ + if style['font_size'] == 0: + # Cairo crashes with font-size: 0 + # See https://github.com/Kozea/WeasyPrint/pull/599 + return Layout(context, 1, style) + text_wrap = style['white_space'] in ('normal', 'pre-wrap', 'pre-line') if not text_wrap: max_width = None
Youre right, the assertion in draw.draw_text comes too late. Respectively it doesn't help. When the given snippet hits
Why assert something when we can prevent it?
# weasyprint/text.py, line 626 ff class Layout(object): """Object holding PangoLayout-related cdata pointers.""" def __init__(self, context, font_size, style): # Cairo crashes with font-size: 0 # See https://github.com/Kozea/WeasyPrint/pull/599 if font_size == 0: font_size = 1
No need to alter other source files. One location to catch them all.
Works for the above test case (hitting text.create_layout).
I'm not as familiar with the code base as you, maybe there are reasons not to do it like I propose?
If you set font-size to 1 and don't catch
You're right, was an error in reasoning.
No, this doesn't make me happy. Feels like makeshift.
Considering that this error only happens on Windows when Pango/Cairo switch to Win32 API.
Considering that, I think
Anyway, will implement and test the
You're right, let's forget about this for now.
(I like the third point
Uninstalled my Ahem font.
pytest with working fontconfig/FreeType -- no errors.
Didnt yet check how many tests fail because of unsupported
Version 43 ---------- Released on 2018-11-09. Bug fixes: * `#726 <https://github.com/Kozea/WeasyPrint/issues/726>`_: Make empty strings clear previous values of named strings * `#729 <https://github.com/Kozea/WeasyPrint/issues/729>`_: Include tools in packaging This version also includes the changes from unstable rc1 and rc2 versions listed below. Version 43rc2 ------------- Released on 2018-11-02. **This version is experimental, don't use it in production. If you find bugs, please report them!** Bug fixes: * `#706 <https://github.com/Kozea/WeasyPrint/issues/706>`_: Fix text-indent at the beginning of a page * `#687 <https://github.com/Kozea/WeasyPrint/issues/687>`_: Allow query strings in file:// URIs * `#720 <https://github.com/Kozea/WeasyPrint/issues/720>`_: Optimize minimum size calculation of long inline elements * `#717 <https://github.com/Kozea/WeasyPrint/issues/717>`_: Display <details> tags as blocks * `#691 <https://github.com/Kozea/WeasyPrint/issues/691>`_: Don't recalculate max content widths when distributing extra space for tables * `#722 <https://github.com/Kozea/WeasyPrint/issues/722>`_: Fix bookmarks and strings set on images * `#723 <https://github.com/Kozea/WeasyPrint/issues/723>`_: Warn users when string() is not used in page margin Version 43rc1 ------------- Released on 2018-10-15. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * Python 3.4+ is now needed, Python 2.x is not supported anymore * Cairo 1.15.4+ is now needed, but 1.10+ should work with missing features (such as links, outlines and metadata) * Pdfrw is not needed anymore New features: * `Beautiful website <https://weasyprint.org>`_ * `#579 <https://github.com/Kozea/WeasyPrint/issues/579>`_: Initial support of flexbox * `#592 <https://github.com/Kozea/WeasyPrint/pull/592>`_: Support @font-face on Windows * `#306 <https://github.com/Kozea/WeasyPrint/issues/306>`_: Add a timeout parameter to the URL fetcher functions * `#594 <https://github.com/Kozea/WeasyPrint/pull/594>`_: Split tests using modern pytest features * `#599 <https://github.com/Kozea/WeasyPrint/pull/599>`_: Make tests pass on Windows * `#604 <https://github.com/Kozea/WeasyPrint/pull/604>`_: Handle target counters and target texts * `#631 <https://github.com/Kozea/WeasyPrint/pull/631>`_: Enable counter-increment and counter-reset in page context * `#622 <https://github.com/Kozea/WeasyPrint/issues/622>`_: Allow pathlib.Path objects for HTML, CSS and Attachment classes * `#674 <https://github.com/Kozea/WeasyPrint/issues/674>`_: Add extensive installation instructions for Windows Bug fixes: * `#558 <https://github.com/Kozea/WeasyPrint/issues/558>`_: Fix attachments * `#565 <https://github.com/Kozea/WeasyPrint/issues/565>`_, `#596 <https://github.com/Kozea/WeasyPrint/issues/596>`_, `#539 <https://github.com/Kozea/WeasyPrint/issues/539>`_: Fix many PDF rendering, printing and compatibility problems * `#614 <https://github.com/Kozea/WeasyPrint/issues/614>`_: Avoid crashes and endless loops caused by a Pango bug * `#662 <https://github.com/Kozea/WeasyPrint/pull/662>`_: Fix warnings and errors when generating documentation * `#666 <https://github.com/Kozea/WeasyPrint/issues/666>`_, `#685 <https://github.com/Kozea/WeasyPrint/issues/685>`_: Fix many table layout rendering problems * `#680 <https://github.com/Kozea/WeasyPrint/pull/680>`_: Don't crash when there's no font available * `#662 <https://github.com/Kozea/WeasyPrint/pull/662>`_: Fix support of some align values in tables