Skip to content

Commit

Permalink
Only apply text-indent to lineboxes
Browse files Browse the repository at this point in the history
Fix #1000.
  • Loading branch information
liZe committed Mar 16, 2020
1 parent 2218740 commit aeb00c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
14 changes: 9 additions & 5 deletions weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,16 @@ def table_cell_max_content_width(context, box, outer):

def inline_line_widths(context, box, outer, is_line_start, minimum,
skip_stack=None, first_line=False):
if box.style['text_indent'].unit == '%':
# TODO: this is wrong, text-indent percentages should be resolved
# before calling this function.
text_indent = 0
if isinstance(box, boxes.LineBox):
if box.style['text_indent'].unit == '%':
# TODO: this is wrong, text-indent percentages should be resolved
# before calling this function.
text_indent = 0
else:
text_indent = box.style['text_indent'].value
else:
text_indent = box.style['text_indent'].value
text_indent = 0

current_line = 0
if skip_stack is None:
skip = 0
Expand Down
17 changes: 17 additions & 0 deletions weasyprint/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,23 @@ def test_text_indent(indent):
assert text_3.position_x == 10 # No indent


@assert_no_logs
def test_text_indent_inline():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1000
page, = render_pages('''
<style>
@font-face { src: url(AHEM____.TTF); font-family: ahem }
p { display: inline-block; text-indent: 1em; font-family: ahem }
</style>
<p><span>text
''')
html, = page.children
body, = html.children
paragraph, = body.children
line, = paragraph.children
assert line.width == (4 + 1) * 16


@pytest.mark.parametrize('indent', ('12px', '6%'))
@assert_no_logs
def test_text_indent_multipage(indent):
Expand Down

0 comments on commit aeb00c5

Please sign in to comment.