Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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