Skip to content

Commit

Permalink
Fix multiple text decorations drawing
Browse files Browse the repository at this point in the history
Fix #1621.
  • Loading branch information
liZe committed Apr 12, 2022
1 parent 6ba031e commit 20c91dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tests/draw/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ def test_text_line_through():
<div>abc</div>''')


def test_text_multiple_text_decoration():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1621
assert_pixels('text_multiple_text_decoration', 13, 7, '''
_____________
_zzzzzzzzzzz_
_zRRRRRRRRRz_
_zBBBBBBBBBz_
_zBBBBBBBBBz_
_zzzzzzzzzzz_
_____________
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 13px 7px;
background: white;
margin: 2px;
}
body {
color: red;
font-family: weasyprint;
font-size: 3px;
text-decoration: underline line-through blue;
}
</style>
<div>abc</div>''')


def test_zero_width_character():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1508
assert_pixels('zero_width_character', 6, 4, '''
Expand Down
5 changes: 4 additions & 1 deletion weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,16 +1000,19 @@ def draw_text(stream, textbox, offset_x, text_overflow, block_ellipsis):
thickness = textbox.pango_layout.underline_thickness
offset_y = (
textbox.baseline - textbox.pango_layout.ascent + thickness / 2)
draw_text_decoration(
stream, textbox, offset_x, offset_y, thickness, color)
if 'underline' in values:
thickness = textbox.pango_layout.underline_thickness
offset_y = (
textbox.baseline - textbox.pango_layout.underline_position +
thickness / 2)
draw_text_decoration(
stream, textbox, offset_x, offset_y, thickness, color)
if 'line-through' in values:
thickness = textbox.pango_layout.strikethrough_thickness
offset_y = (
textbox.baseline - textbox.pango_layout.strikethrough_position)
if values != 'none':
draw_text_decoration(
stream, textbox, offset_x, offset_y, thickness, color)

Expand Down

0 comments on commit 20c91dc

Please sign in to comment.