Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into efficient-style-sto…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
ssjkamei committed Aug 31, 2023
2 parents 33e5bbc + 3fdd3c5 commit 539161c
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 87 deletions.
5 changes: 4 additions & 1 deletion docs/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install WeasyPrint dependencies.
git clone https://github.com/Kozea/WeasyPrint.git
cd WeasyPrint
python -m venv venv
venv/bin/pip install -e .[doc,test]
venv/bin/pip install -e '.[doc,test]'
You can then launch Python to test your changes.

Expand Down Expand Up @@ -44,6 +44,8 @@ Tests
Tests are stored in the ``tests`` folder at the top of the repository. They use
the pytest_ library.

Tests require Ghostscript_ to be installed and available on the local path.

You can launch tests using the following command::

venv/bin/python -m pytest
Expand All @@ -55,6 +57,7 @@ style::
venv/bin/python -m flake8

.. _pytest: https://docs.pytest.org/
.. _Ghostscript: https://www.ghostscript.com/
.. _isort: https://pycqa.github.io/isort/
.. _flake8: https://flake8.pycqa.org/

Expand Down
70 changes: 70 additions & 0 deletions tests/draw/svg/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,73 @@ def test_text_rotate(assert_pixels):
rotate="180" letter-spacing="2">abc</text>
</svg>
''')


@assert_no_logs
def test_text_text_length(assert_pixels):
assert_pixels('''
__RRRRRR____________
__RRRRRR____________
__BB__BB__BB________
__BB__BB__BB________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 20px 4px }
svg { display: block }
</style>
<svg width="20px" height="4px" xmlns="http://www.w3.org/2000/svg">
<text x="2" y="1.5" font-family="weasyprint" font-size="2" fill="red">
abc
</text>
<text x="2" y="3.5" font-family="weasyprint" font-size="2" fill="blue"
textLength="10">abc</text>
</svg>
''')


@assert_no_logs
def test_text_length_adjust_glyphs_only(assert_pixels):
assert_pixels('''
__RRRRRR____________
__RRRRRR____________
__BBBBBBBBBBBB______
__BBBBBBBBBBBB______
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 20px 4px }
svg { display: block }
</style>
<svg width="20px" height="4px" xmlns="http://www.w3.org/2000/svg">
<text x="2" y="1.5" font-family="weasyprint" font-size="2" fill="red">
abc
</text>
<text x="2" y="3.5" font-family="weasyprint" font-size="2" fill="blue"
textLength="12" lengthAdjust="spacingAndGlyphs">abc</text>
</svg>
''')


@assert_no_logs
def test_text_length_adjust_spacing_and_glyphs(assert_pixels):
assert_pixels('''
__RR_RR_RR__________
__RR_RR_RR__________
__BBBB__BBBB__BBBB__
__BBBB__BBBB__BBBB__
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 20px 4px }
svg { display: block }
</style>
<svg width="20px" height="4px" xmlns="http://www.w3.org/2000/svg">
<text x="2" y="1.5" font-family="weasyprint" font-size="2" fill="red"
letter-spacing="1">abc</text>
<text x="2" y="3.5" font-family="weasyprint" font-size="2" fill="blue"
letter-spacing="1" textLength="16" lengthAdjust="spacingAndGlyphs">
abc
</text>
</svg>
''')
13 changes: 7 additions & 6 deletions tests/draw/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,13 +1054,14 @@ def test_background_size_clip(assert_pixels):

@assert_no_logs
def test_bleed_background_size_clip(assert_pixels):
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1943
assert_pixels('''
RRRRRR
RBBBBR
RBRBBR
RBBBBR
RBBBBR
RRRRRR
BBBBBB
BBBBBB
BBRBBB
BBBBBB
BBBBBB
BBBBBB
''', '''
<style>
@page { size: 4px; bleed: 1px; margin: 1px;
Expand Down
26 changes: 26 additions & 0 deletions tests/layout/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,32 @@ def test_overflow_auto():
assert article.height == 50 + 10 + 10


def test_overflow_hidden_in_flow_layout():
page, = render_pages('''
<div style="overflow: hidden; height: 3px;">
<div>abc</div>
<div style="height: 100px; margin: 50px;">def</div>
</div>
''')
html, = page.children
body, = html.children
parent_div, = body.children
assert parent_div.height == 3


def test_overflow_hidden_out_of_flow_layout():
page, = render_pages('''
<div style="overflow: hidden; height: 3px;">
<div style="float: left;">abc</div>
<div style="float: right; height: 100px; margin: 50px;">def</div>
</div>
''')
html, = page.children
body, = html.children
parent_div, = body.children
assert parent_div.height == 3


@assert_no_logs
def test_box_margin_top_repagination():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/943
Expand Down
32 changes: 32 additions & 0 deletions tests/layout/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,38 @@ def ghi
assert column3.children[0].children[0].children[0].text == 'ghi'


@assert_no_logs
def test_column_span_balance():
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { margin: 0; size: 8px 5px }
body { font-family: weasyprint; font-size: 1px }
div { columns: 2; column-gap: 0; line-height: 1; column-fill: auto }
section { column-span: all }
</style>
<div>
abc def
<section>line1</section>
ghi jkl
</div>
''')
html, = page.children
body, = html.children
div, = body.children
column1, column2, section, column3 = div.children
assert (column1.position_x, column1.position_y) == (0, 0)
assert (column2.position_x, column2.position_y) == (4, 0)
assert (section.position_x, section.position_y) == (0, 1)
assert (column3.position_x, column3.position_y) == (0, 2)

assert column1.children[0].children[0].children[0].text == 'abc'
assert column2.children[0].children[0].children[0].text == 'def'
assert section.children[0].children[0].text == 'line1'
assert column3.children[0].children[0].children[0].text == 'ghi'
assert column3.children[0].children[1].children[0].text == 'jkl'


@assert_no_logs
def test_columns_multipage():
page1, page2 = render_pages('''
Expand Down
36 changes: 36 additions & 0 deletions tests/layout/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,42 @@ def test_page_names_9():
assert article.element_tag == 'article'


@assert_no_logs
def test_page_names_10():
pages = render_pages('''
<style>
#running { position: running(running); }
#fixed { position: fixed; }
@page { size: 200px 200px; @top-center { content: element(header); }}
section { page: small; }
@page small { size: 100px 100px; }
.pagebreak { break-after: page; }
</style>
<div id="running">running</div>
<div id="fixed">fixed</div>
<section>
<h1>text</h1>
<div class="pagebreak"></div>
<article>text</article>
</section>
''')
page1, page2 = pages

assert (page1.width, page1.height) == (100, 100)
html, runing = page1.children
body, = html.children
fixed, section, = body.children
h1, pagebreak = section.children
assert h1.element_tag == 'h1'

assert (page2.width, page2.height) == (100, 100)
html, running = page2.children
fixed, body = html.children
section, = body.children
article, = section.children
assert article.element_tag == 'article'


@assert_no_logs
@pytest.mark.parametrize('style, line_counts', (
('orphans: 2; widows: 2', [4, 3]),
Expand Down
61 changes: 61 additions & 0 deletions tests/layout/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2912,3 +2912,64 @@ def test_table_different_display():
</td>
</table>
''')


@assert_no_logs
def test_min_width_with_overflow():
# issue 1383
page, = render_pages('''
<head>
<style>
table td { border: 1px solid black; }
table.key-val tr td:nth-child(1) { min-width: 13em; }
</style>
</head>
<body>
<table class="key-val">
<tbody>
<tr>
<td>Normal Key 1</td>
<td>Normal Value 1</td>
</tr>
<tr>
<td>Normal Key 2</td>
<td>Normal Value 2</td>
</tr>
</tbody>
</table>
<table class="key-val">
<tbody>
<tr>
<td>Short value</td>
<td>Works as expected</td>
</tr>
<tr>
<td>Long Value</td>
<td>Annoyingly breaks my table layout: Sed ut perspiciatis
unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam,
eaque ipsa quae ab illo inventore veritatis et quasi
architecto beatae vitae dicta sunt explicabo.
</td>
</tr>
</tbody>
</table>
</body>
''')
html, = page.children
body, = html.children
table_wrapper_1, table_wrapper_2 = body.children

table1, = table_wrapper_1.children
tbody1, = table1.children
tr1, tr2 = tbody1.children
table1_td1, table1_td2 = tr1.children

table2, = table_wrapper_2.children
tbody2, = table2.children
tr1, tr2 = tbody2.children
table2_td1, table2_td2 = tr1.children

assert table1_td1.min_width == table2_td1.min_width
assert table1_td1.width == table2_td1.width
Loading

0 comments on commit 539161c

Please sign in to comment.