2022-03-25 13:47:27 +03:00
|
|
|
"""Test various unicode texts and filenames."""
|
2018-03-20 01:35:56 +03:00
|
|
|
|
2020-12-06 22:19:59 +03:00
|
|
|
from weasyprint.urls import ensure_url
|
|
|
|
|
2022-05-24 00:09:32 +03:00
|
|
|
from .draw import document_to_pixels, html_to_pixels
|
2024-01-04 12:47:34 +03:00
|
|
|
from .testing_utils import FakeHTML, assert_no_logs, resource_path
|
2018-03-20 01:35:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
@assert_no_logs
|
2024-01-04 12:47:34 +03:00
|
|
|
def test_unicode(assert_pixels_equal, tmp_path):
|
2018-03-20 01:35:56 +03:00
|
|
|
text = 'I løvë Unicode'
|
|
|
|
style = '''
|
2022-04-17 10:32:15 +03:00
|
|
|
@page { size: 200px 50px }
|
2018-03-20 01:35:56 +03:00
|
|
|
p { color: blue }
|
|
|
|
'''
|
2024-01-05 00:24:33 +03:00
|
|
|
expected_width, expected_height, expected_lines = html_to_pixels(f'''
|
|
|
|
<style>{style}</style>
|
|
|
|
<p><img src="pattern.png"> {text}</p>
|
|
|
|
''')
|
2018-03-20 01:35:56 +03:00
|
|
|
|
2024-01-04 12:47:34 +03:00
|
|
|
stylesheet = tmp_path / 'style.css'
|
|
|
|
image = tmp_path / 'pattern.png'
|
|
|
|
html = tmp_path / 'doc.html'
|
2024-01-04 13:44:51 +03:00
|
|
|
stylesheet.write_text(style, 'utf-8')
|
2024-01-04 12:47:34 +03:00
|
|
|
image.write_bytes(resource_path('pattern.png').read_bytes())
|
|
|
|
html_content = f'''
|
|
|
|
<link rel=stylesheet href="{ensure_url(str(stylesheet))}">
|
|
|
|
<p><img src="{ensure_url(str(image))}"> {text}</p>
|
|
|
|
'''
|
2024-01-04 13:59:35 +03:00
|
|
|
html.write_text(html_content, 'utf-8')
|
2018-03-20 01:35:56 +03:00
|
|
|
|
2024-01-04 12:47:34 +03:00
|
|
|
document = FakeHTML(html, encoding='utf-8')
|
|
|
|
width, height, lines = document_to_pixels(document)
|
|
|
|
assert (expected_width, expected_height) == (width, height)
|
|
|
|
assert_pixels_equal(width, height, lines, expected_lines)
|