From 71e9e257ccc7780f3c4e04893b11210bd06ad626 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 21 Oct 2022 22:26:11 +0200 Subject: [PATCH] Always set font size when font is changed in line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In setting the font size also sets the font family, and that’s useful when we have different fonts in the same text block. It happens for example when characters are missing from a font and are replaced by a fallback font’s character. Fix #1748. --- tests/draw/test_text.py | 24 ++++++++++++++++++++++++ weasyprint/draw.py | 4 +--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/draw/test_text.py b/tests/draw/test_text.py index 760f712dd8..93f49bc702 100644 --- a/tests/draw/test_text.py +++ b/tests/draw/test_text.py @@ -827,6 +827,30 @@ def test_font_size_very_small(assert_pixels): ''') +def test_missing_glyph_fallback(assert_pixels): + # The apostrophe is not included in weasyprint.otf + assert_pixels(''' + zzzzzzzzzzzzzzzzz___ + zzzzzzzzzzzzzzzzzRR_ + zzzzzzzzzzzzzzzzzRR_ + zzzzzzzzzzzzzzzzz___ + ''', ''' + 'a''') + + def test_tabulation_character(assert_pixels): # Test regression: https://github.com/Kozea/WeasyPrint/issues/1515 assert_pixels(''' diff --git a/weasyprint/draw.py b/weasyprint/draw.py index d7a87830ae..71cb8d0f97 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -1135,9 +1135,7 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y, if string: stream.show_text(string) string = '' - if last_font is None or font.bitmap != last_font.bitmap: - stream.set_font_size( - font.hash, 1 if font.bitmap else font_size) + stream.set_font_size(font.hash, 1 if font.bitmap else font_size) last_font = font string += '<' for i in range(num_glyphs):