Skip to content

Commit

Permalink
Always set font size when font is changed in line
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
liZe committed Oct 21, 2022
1 parent 2b05137 commit 71e9e25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 24 additions & 0 deletions tests/draw/test_text.py
Expand Up @@ -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___
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 20px 4px;
}
body {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 0;
margin: 2px 1px;
text-align: right;
}
</style>'a''')


def test_tabulation_character(assert_pixels):
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1515
assert_pixels('''
Expand Down
4 changes: 1 addition & 3 deletions weasyprint/draw.py
Expand Up @@ -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):
Expand Down

0 comments on commit 71e9e25

Please sign in to comment.