mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
496 lines
18 KiB
Python
496 lines
18 KiB
Python
# coding: utf8
|
||
|
||
# WeasyPrint converts web documents (HTML, CSS, ...) to PDF.
|
||
# Copyright (C) 2011 Simon Sapin
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
# it under the terms of the GNU Affero General Public License as
|
||
# published by the Free Software Foundation, either version 3 of the
|
||
# License, or (at your option) any later version.
|
||
#
|
||
# This program is distributed in the hope that it will be useful,
|
||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
# GNU Affero General Public License for more details.
|
||
#
|
||
# You should have received a copy of the GNU Affero General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
||
|
||
import os.path
|
||
from array import array
|
||
|
||
import png
|
||
from attest import Tests, assert_hook
|
||
|
||
from . import resource_filename
|
||
from ..document import PNGDocument
|
||
|
||
|
||
_ = array('B', [255, 255, 255]) # white
|
||
r = array('B', [255, 0, 0]) # red
|
||
B = array('B', [0, 0, 255]) # blue
|
||
|
||
suite = Tests()
|
||
|
||
|
||
def make_filename(dirname, basename):
|
||
return os.path.join(os.path.dirname(__file__), dirname, basename + '.png')
|
||
|
||
|
||
def format_pixel(lines, x, y):
|
||
pixel = lines[y][3 * x:3 * (x + 1)]
|
||
return ('#' + 3 * '%02x') % tuple(pixel)
|
||
|
||
|
||
def test_pixels(name, expected_width, expected_height, expected_lines, html):
|
||
assert len(expected_lines) == expected_height, name
|
||
assert len(expected_lines[0]) == 3 * expected_width, name
|
||
|
||
writer = png.Writer(width=expected_width, height=expected_height)
|
||
with open(make_filename('expected_results', name), 'wb') as fd:
|
||
writer.write(fd, expected_lines)
|
||
|
||
document = PNGDocument.from_string(html)
|
||
# Dummy filename, but in the right directory.
|
||
document.base_url = resource_filename('<test>')
|
||
filename = make_filename('test_results', name)
|
||
document.write_to(filename)
|
||
assert len(document.pages) == 1
|
||
|
||
reader = png.Reader(filename=filename)
|
||
width, height, lines, meta = reader.read()
|
||
lines = list(lines)
|
||
|
||
assert width == expected_width, name
|
||
assert height == expected_height, name
|
||
assert meta['greyscale'] == False, name
|
||
assert meta['alpha'] == False, name
|
||
assert meta['bitdepth'] == 8, name
|
||
assert len(lines) == height, name
|
||
assert len(lines[0]) == width * 3, name
|
||
if lines != expected_lines:
|
||
for y in xrange(height):
|
||
for x in xrange(width):
|
||
pixel = format_pixel(lines, x, y)
|
||
expected_pixel = format_pixel(expected_lines, x, y)
|
||
assert pixel == expected_pixel, \
|
||
'Pixel (%i, %i) does not match in %s' % (x, y, name)
|
||
|
||
@suite.test
|
||
def test_canvas_background():
|
||
test_pixels('all_blue', 10, 10, (10 * [10 * B]), '''
|
||
<style>
|
||
@page { size: 10px }
|
||
/* body’s background propagates to the whole canvas */
|
||
body { margin: 2px; background: #00f; height: 5px }
|
||
</style>
|
||
<body>
|
||
''')
|
||
|
||
test_pixels('blocks', 10, 10, [
|
||
r+r+r+r+r+r+r+r+r+r,
|
||
r+r+r+r+r+r+r+r+r+r,
|
||
r+r+B+B+B+B+B+B+r+r,
|
||
r+r+B+B+B+B+B+B+r+r,
|
||
r+r+B+B+B+B+B+B+r+r,
|
||
r+r+B+B+B+B+B+B+r+r,
|
||
r+r+B+B+B+B+B+B+r+r,
|
||
r+r+r+r+r+r+r+r+r+r,
|
||
r+r+r+r+r+r+r+r+r+r,
|
||
r+r+r+r+r+r+r+r+r+r,
|
||
], '''
|
||
<style>
|
||
@page { size: 10px }
|
||
/* html’s background propagates to the whole canvas */
|
||
html { margin: 1px; background: #f00 }
|
||
/* html has a background, so body’s does not propagate */
|
||
body { margin: 1px; background: #00f; height: 5px }
|
||
</style>
|
||
<body>
|
||
''')
|
||
|
||
|
||
@suite.test
|
||
def test_background_image():
|
||
# pattern.png looks like this:
|
||
|
||
# r+B+B+B,
|
||
# B+B+B+B,
|
||
# B+B+B+B,
|
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,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
]),
|
||
('fixed_right', 'no-repeat fixed right 3px', [
|
||
#######
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+r+B+_+_, #
|
||
_+_+_+_+_+_+_+_+_+_+B+B+_+_, #
|
||
_+_+_+_+_+_+_+_+_+_+B+B+_+_, #
|
||
_+_+_+_+_+_+_+_+_+_+B+B+_+_, #
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
|
||
]),
|
||
]:
|
||
test_pixels('background_' + name, 14, 16, pixels, '''
|
||
<style>
|
||
@page { size: 14px 16px }
|
||
html { background: #fff }
|
||
body { margin: 2px; height: 10px;
|
||
background: url(pattern.png) %s }
|
||
</style>
|
||
<body>
|
||
''' % (css,))
|
||
|
||
|
||
@suite.test
|
||
def test_list_style_image():
|
||
for position, pixels in [
|
||
('outside', [
|
||
# ++++++++++++++ ++++ <li> horizontal margins: 7px 2px
|
||
# ###### <li> width: 12 - 7 - 2 = 3px
|
||
# -- list marker margin: 0.5em = 2px
|
||
# ******** list marker image is 4px wide
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+r+B+B+B+_+_+_+_+_+_,
|
||
_+_+B+B+B+B+_+_+_+_+_+_,
|
||
_+_+B+B+B+B+_+_+_+_+_+_,
|
||
_+_+B+B+B+B+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
]),
|
||
('inside', [
|
||
# ++++++++++++++ ++++ <li> horizontal margins: 7px 2px
|
||
# ###### <li> width: 12 - 7 - 2 = 3px
|
||
# ******** list marker image is 4px wide, it overflows
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+r+B+B+B+_,
|
||
_+_+_+_+_+_+_+B+B+B+B+_,
|
||
_+_+_+_+_+_+_+B+B+B+B+_,
|
||
_+_+_+_+_+_+_+B+B+B+B+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_+_+_,
|
||
])
|
||
]:
|
||
test_pixels('list_style_image_' + position, 12, 10, pixels, '''
|
||
<style>
|
||
@page { size: 12px 10px }
|
||
body { margin: 0; background: white }
|
||
ul { margin: 2px 2px 0 7px; list-style: url(pattern.png) %s;
|
||
font-size: 2px }
|
||
</style>
|
||
<ul><li></li></ul>
|
||
''' % (position,))
|
||
|
||
test_pixels('list_style_none', 10, 10, [
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
_+_+_+_+_+_+_+_+_+_,
|
||
], '''
|
||
<style>
|
||
@page { size: 10px }
|
||
body { margin: 0; background: white }
|
||
ul { margin: 0 0 0 5px; list-style: none; font-size: 2px; }
|
||
</style>
|
||
<ul><li>
|
||
''')
|