Skip to content

Commit

Permalink
Sync fix with master
Browse files Browse the repository at this point in the history
  • Loading branch information
kygoh committed Sep 3, 2023
2 parents af141ba + 7d45356 commit b18bbb3
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 156 deletions.
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
'collapse_navigation': False,
}

# Favicon URL
html_favicon = 'https://www.courtbouillon.org/static/images/favicon.png'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
Expand Down
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
2 changes: 1 addition & 1 deletion docs/first_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ WeasyPrint in a `virtual environment`_ using `pip`_::
python3 -m pip install weasyprint
python3 -m weasyprint --info

.. _Microsoft Store: https://www.microsoft.com/en-us/search?q=python
.. _Microsoft Store: https://apps.microsoft.com/store/search/python
.. _GTK3 installer: https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases


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
136 changes: 136 additions & 0 deletions tests/draw/test_leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,139 @@ def test_leader_absolute(assert_pixels):
</style>
<div>aa<article>bb</article>aa</div>
''')


@assert_no_logs
def test_leader_padding(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div {
padding-left: 2px;
}
</style>
<div>a</div>
<div>b</div>
''')


@assert_no_logs
def test_leader_inline_padding(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div span {
padding-left: 2px;
}
</style>
<div><span>a</span></div>
<div><span>b</span></div>
''')


@assert_no_logs
def test_leader_margin(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div {
margin-left: 2px;
}
</style>
<div>a</div>
<div>b</div>
''')


@assert_no_logs
def test_leader_inline_margin(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div span {
margin-left: 2px;
}
</style>
<div><span>a</span></div>
<div><span>b</span></div>
''')
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
Loading

0 comments on commit b18bbb3

Please sign in to comment.