Permalink
Browse files

Unprefix paged media, transforms, and SVG properties

The image-rendering, transform, transform-origin and size
properties are now unprefixed.

The prefixed form (eg. -weasy-size) is ignored but gives
a specific warning.
  • Loading branch information...
1 parent 1cdb625 commit 279386b850c2c84c1718839e043dea115c01450e @SimonSapin SimonSapin committed Jul 4, 2012
View
43 weasyprint/css/validation.py
@@ -61,7 +61,7 @@
EXPANDERS = {}
PREFIXED = set()
-# The same replacement was done on property names:
+UNPREFIXED = set()
PREFIX = '-weasy-'
@@ -71,14 +71,28 @@ class InvalidValues(ValueError):
# Validators
-def validator(property_name=None, prefixed=False, wants_base_url=False):
+def validator(property_name=None, prefixed=False, unprefixed=False,
+ wants_base_url=False):
"""Decorator adding a function to the ``VALIDATORS``.
The name of the property covered by the decorated function is set to
``property_name`` if given, or is inferred from the function name
(replacing underscores by hyphens).
+ :param prefixed:
+ Vendor-specific (non-standard) and experimental properties are
+ prefixed: stylesheets need to use eg. ``-weasy-bookmark-level: 2``
+ instead of ``bookmark-level: 2``.
+ See http://wiki.csswg.org/spec/vendor-prefixes
+ :param unprefixed:
+ Mark properties that used to be prefixed. When used with the prefix,
+ they will be ignored be give a specific warning.
+ :param wants_base_url:
+ The function takes the stylesheet’s base URL as an additional
+ parameter.
+
"""
+ assert not (prefixed and unprefixed)
def decorator(function):
"""Add ``function`` to the ``VALIDATORS``."""
if property_name is None:
@@ -92,6 +106,8 @@ def decorator(function):
VALIDATORS[name] = function
if prefixed:
PREFIXED.add(name)
+ if unprefixed:
+ UNPREFIXED.add(name)
return function
return decorator
@@ -202,7 +218,7 @@ def image(token, base_url):
return safe_urljoin(base_url, token.value)
-@validator('transform-origin', prefixed=True) # Not in CR yet
+@validator('transform-origin', unprefixed=True)
@validator()
def background_position(tokens):
"""``background-position`` property validation.
@@ -791,14 +807,14 @@ def white_space(keyword):
return keyword in ('normal', 'pre', 'nowrap', 'pre-wrap', 'pre-line')
-@validator(prefixed=True) # Taken from SVG
+@validator(unprefixed=True)
@single_keyword
def image_rendering(keyword):
"""Validation for ``image-rendering``."""
return keyword in ('auto', 'optimizespeed', 'optimizequality')
-@validator(prefixed=True) # Not in CR yet
+@validator(unprefixed=True)
def size(tokens):
"""``size`` property validation.
@@ -838,7 +854,7 @@ def size(tokens):
return width, height
-@validator(prefixed=True) # Proprietary
+@validator(prefixed=True) # Non-standard
@single_token
def anchor(token):
"""Validation for ``anchor``."""
@@ -853,7 +869,7 @@ def anchor(token):
return (name, args[0])
-@validator(prefixed=True, wants_base_url=True) # Proprietary
+@validator(prefixed=True, wants_base_url=True) # Non-standard
@single_token
def link(token, base_url):
"""Validation for ``link``."""
@@ -873,7 +889,7 @@ def link(token, base_url):
return (name, args[0])
-@validator(prefixed=True) # CSS3 GCPM
+@validator(prefixed=True) # CSS3 GCPM, experimental
@single_token
def bookmark_label(token):
"""Validation for ``bookmark-label``."""
@@ -885,7 +901,7 @@ def bookmark_label(token):
return ('string', token.value)
-@validator(prefixed=True) # CSS3 GCPM
+@validator(prefixed=True) # CSS3 GCPM, experimental
@single_token
def bookmark_level(token):
"""Validation for ``bookmark-level``."""
@@ -897,7 +913,7 @@ def bookmark_level(token):
return 'none'
-@validator(prefixed=True) # Not in CR yet
+@validator(unprefixed=True)
def transform(tokens):
if get_single_keyword(tokens) == 'none':
return []
@@ -1268,7 +1284,8 @@ def validation_error(level, reason):
if name in PREFIXED and not name.startswith(PREFIX):
validation_error('warn',
- 'the property is experimental, use ' + PREFIX + name)
+ 'the property is experimental or non-standard, use '
+ + PREFIX + name)
continue
if name in NOT_PRINT_MEDIA:
@@ -1278,6 +1295,10 @@ def validation_error(level, reason):
if name.startswith(PREFIX):
unprefixed_name = name[len(PREFIX):]
+ if unprefixed_name in UNPREFIXED:
+ validation_error('warn',
+ 'the property was unprefixed, use ' + unprefixed_name)
+ continue
if unprefixed_name in PREFIXED:
name = unprefixed_name
View
8 weasyprint/tests/test_api.py
@@ -200,9 +200,9 @@ def test_python_render():
html = TestHTML(string='<body><img src=pattern.png>',
base_url=resource_filename('dummy.html'))
css = CSS(string='''
- @page { margin: 2px; -weasy-size: 8px; background: #fff }
+ @page { margin: 2px; size: 8px; background: #fff }
body { margin: 0; font-size: 0 }
- img { -weasy-image-rendering: optimizeSpeed }
+ img { image-rendering: optimizeSpeed }
''')
png_bytes = html.write_png(stylesheets=[css])
@@ -257,7 +257,7 @@ def getvalue(self):
def test_command_line_render():
"""Test rendering with the command-line API."""
css = b'''
- @page { margin: 2px; -weasy-size: 8px; background: #fff }
+ @page { margin: 2px; size: 8px; background: #fff }
body { margin: 0; font-size: 0 }
'''
html = b'<body><img src=pattern.png>'
@@ -337,7 +337,7 @@ def test_unicode_filenames():
# Replicate pattern.png in CSS so that base_url does not matter.
html = b'''
<style>
- @page { margin: 2px; -weasy-size: 8px; background: #fff }
+ @page { margin: 2px; size: 8px; background: #fff }
html { background: #00f; }
body { background: #f00; width: 1px; height: 1px; }
</style>
View
4 weasyprint/tests/test_boxes.py
@@ -1183,7 +1183,7 @@ def test_margin_boxes():
@page {
/* Make the page content area only 10px high and wide,
so every word in <p> end up on a page of its own. */
- -weasy-size: 30px;
+ size: 30px;
margin: 10px;
@top-center { content: "Title" }
}
@@ -1218,7 +1218,7 @@ def test_page_counters():
@page {
/* Make the page content area only 10px high and wide,
so every word in <p> end up on a page of its own. */
- -weasy-size: 30px;
+ size: 30px;
margin: 10px;
@bottom-center {
content: "Page " counter(page) " of " counter(pages) ".";
View
52 weasyprint/tests/test_css_validation.py
@@ -99,52 +99,52 @@ def test_decoration():
@assert_no_logs
def test_size():
- assert expand_to_dict('-weasy-size: 200px') == {
+ assert expand_to_dict('size: 200px') == {
'size': ((200, 'px'), (200, 'px'))}
- assert expand_to_dict('-weasy-size: 200px 300pt') == {
+ assert expand_to_dict('size: 200px 300pt') == {
'size': ((200, 'px'), (300, 'pt'))}
- assert expand_to_dict('-weasy-size: auto') == {
+ assert expand_to_dict('size: auto') == {
'size': ((210, 'mm'), (297, 'mm'))}
- assert expand_to_dict('-weasy-size: portrait') == {
+ assert expand_to_dict('size: portrait') == {
'size': ((210, 'mm'), (297, 'mm'))}
- assert expand_to_dict('-weasy-size: landscape') == {
+ assert expand_to_dict('size: landscape') == {
'size': ((297, 'mm'), (210, 'mm'))}
- assert expand_to_dict('-weasy-size: A3 portrait') == {
+ assert expand_to_dict('size: A3 portrait') == {
'size': ((297, 'mm'), (420, 'mm'))}
- assert expand_to_dict('-weasy-size: A3 landscape') == {
+ assert expand_to_dict('size: A3 landscape') == {
'size': ((420, 'mm'), (297, 'mm'))}
- assert expand_to_dict('-weasy-size: portrait A3') == {
+ assert expand_to_dict('size: portrait A3') == {
'size': ((297, 'mm'), (420, 'mm'))}
- assert expand_to_dict('-weasy-size: landscape A3') == {
+ assert expand_to_dict('size: landscape A3') == {
'size': ((420, 'mm'), (297, 'mm'))}
- assert expand_to_dict('-weasy-size: A3 landscape A3', 'invalid') == {}
- assert expand_to_dict('-weasy-size: A9', 'invalid') == {}
- assert expand_to_dict('-weasy-size: foo', 'invalid') == {}
- assert expand_to_dict('-weasy-size: foo bar', 'invalid') == {}
- assert expand_to_dict('-weasy-size: 20%', 'invalid') == {}
+ assert expand_to_dict('size: A3 landscape A3', 'invalid') == {}
+ assert expand_to_dict('size: A9', 'invalid') == {}
+ assert expand_to_dict('size: foo', 'invalid') == {}
+ assert expand_to_dict('size: foo bar', 'invalid') == {}
+ assert expand_to_dict('size: 20%', 'invalid') == {}
@assert_no_logs
def test_transforms():
- assert expand_to_dict('-weasy-transform: none') == {
+ assert expand_to_dict('transform: none') == {
'transform': []}
- assert expand_to_dict('-weasy-transform: translate(6px) rotate(90deg)'
+ assert expand_to_dict('transform: translate(6px) rotate(90deg)'
) == {'transform': [('translate', ((6, 'px'), (0, 'px'))),
('rotate', (90, 'deg'))]}
- assert expand_to_dict('-weasy-transform: translate(-4px, 0)'
+ assert expand_to_dict('transform: translate(-4px, 0)'
) == {'transform': [('translate', ((-4, 'px'), (0, None)))]}
- assert expand_to_dict('-weasy-transform: translate(6px, 20%)'
+ assert expand_to_dict('transform: translate(6px, 20%)'
) == {'transform': [('translate', ((6, 'px'), (20, '%')))]}
- assert expand_to_dict('-weasy-transform: scale(2)'
+ assert expand_to_dict('transform: scale(2)'
) == {'transform': [('scale', (2, 2))]}
- assert expand_to_dict('-weasy-transform: translate(6px 20%)',
+ assert expand_to_dict('transform: translate(6px 20%)',
'invalid') == {} # missing comma
- assert expand_to_dict('-weasy-transform: lipsumize(6px)', 'invalid') == {}
- assert expand_to_dict('-weasy-transform: foo', 'invalid') == {}
- assert expand_to_dict('-weasy-transform: scale(2) foo', 'invalid') == {}
- assert expand_to_dict('-weasy-transform: 6px', 'invalid') == {}
- assert expand_to_dict('transform: none',
- 'the property is experimental, use -weasy-transform') == {}
+ assert expand_to_dict('transform: lipsumize(6px)', 'invalid') == {}
+ assert expand_to_dict('transform: foo', 'invalid') == {}
+ assert expand_to_dict('transform: scale(2) foo', 'invalid') == {}
+ assert expand_to_dict('transform: 6px', 'invalid') == {}
+ assert expand_to_dict('-weasy-transform: none',
+ 'the property was unprefixed, use transform') == {}
@assert_no_logs
View
146 weasyprint/tests/test_draw.py
@@ -167,7 +167,7 @@ def test_canvas_background():
"""Test the background applied on ``<html>`` and/or ``<body>`` tags."""
assert_pixels('all_blue', 10, 10, (10 * [10 * B]), '''
<style>
- @page { -weasy-size: 10px }
+ @page { size: 10px }
/* body’s background propagates to the whole canvas */
body { margin: 2px; background: #00f; height: 5px }
</style>
@@ -187,7 +187,7 @@ def test_canvas_background():
r+r+r+r+r+r+r+r+r+r,
], '''
<style>
- @page { -weasy-size: 10px }
+ @page { size: 10px }
/* html’s background propagates to the whole canvas */
html { padding: 1px; background: #f00 }
/* html has a background, so body’s does not propagate */
@@ -560,7 +560,7 @@ def test_background_image():
]:
assert_pixels('background_' + name, 14, 16, pixels, '''
<style>
- @page { -weasy-size: 14px 16px }
+ @page { size: 14px 16px }
html { background: #fff }
body { margin: 2px; height: 10px;
background: url(pattern.png) %s }
@@ -577,7 +577,7 @@ def test_background_origin():
def test_value(value, pixels, css=None):
assert_pixels('background_origin_' + value, 12, 12, pixels, '''
<style>
- @page { -weasy-size: 12px }
+ @page { size: 12px }
html { background: #fff }
body { margin: 1px; padding: 1px; height: 6px;
border: 1px solid transparent;
@@ -653,7 +653,7 @@ def test_background_clip():
def test_value(value, pixels):
assert_pixels('background_clip_' + value, 8, 8, pixels, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
html { background: #fff }
body { margin: 1px; padding: 1px; height: 2px;
border: 1px solid transparent;
@@ -712,11 +712,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 12px }
+ @page { size: 12px }
html { background: #fff }
body { margin: 1px; height: 10px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) bottom right no-repeat;
background-size: 8px }
</style>
@@ -738,11 +738,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 12px }
+ @page { size: 12px }
html { background: #fff }
body { margin: 1px; height: 10px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) bottom right no-repeat;
background-size: auto }
</style>
@@ -762,11 +762,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 14px 10px }
+ @page { size: 14px 10px }
html { background: #fff }
body { margin: 1px; height: 8px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) no-repeat;
background-size: contain }
</style>
@@ -786,11 +786,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 14px 10px }
+ @page { size: 14px 10px }
html { background: #fff }
body { margin: 1px; height: 8px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) no-repeat;
background-size: auto 8px;
clip: auto; /* no-op to cover more validation */ }
@@ -811,11 +811,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 14px 10px }
+ @page { size: 14px 10px }
html { background: #fff }
body { margin: 1px; height: 8px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) no-repeat;
background-size: 8px 4px;
clip: auto; /* no-op to cover more validation */ }
@@ -836,11 +836,11 @@ def test_background_size():
_+_+_+_+_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 14px 10px }
+ @page { size: 14px 10px }
html { background: #fff }
body { margin: 1px; height: 8px;
/* Use nearest neighbor algorithm for image resizing: */
- -weasy-image-rendering: optimizeSpeed;
+ image-rendering: optimizeSpeed;
background: url(pattern.png) no-repeat;
background-size: cover }
</style>
@@ -886,7 +886,7 @@ def test_list_style_image():
]:
assert_pixels('list_style_image_' + position, 12, 10, pixels, '''
<style>
- @page { -weasy-size: 12px 10px }
+ @page { size: 12px 10px }
body { margin: 0; background: white; font-family: %s }
ul { margin: 2px 2px 0 7px; list-style: url(pattern.png) %s;
font-size: 2px }
@@ -907,7 +907,7 @@ def test_list_style_image():
_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 10px }
+ @page { size: 10px }
body { margin: 0; background: white; font-family: %s }
ul { margin: 0 0 0 5px; list-style: none; font-size: 2px; }
</style>
@@ -958,14 +958,14 @@ def test_images():
('blue.jpg', blue_image)]:
assert_pixels('inline_image_' + filename, 8, 8, image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px 0 0 2px; background: #fff; font-size: 0 }
</style>
<div><img src="%s"></div>
''' % filename)
assert_pixels('block_image', 8, 8, centered_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 0; background: #fff; font-size: 0 }
img { display: block; margin: 2px auto 0 }
</style>
@@ -974,7 +974,7 @@ def test_images():
with capture_logs() as logs:
assert_pixels('image_not_found', 8, 8, no_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 0; background: #fff; font-size: 0 }
img { display: block; margin: 2px auto 0 }
</style>
@@ -985,7 +985,7 @@ def test_images():
assert 'inexistent1.png' in logs[0]
assert_pixels('image_no_src', 8, 8, no_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 0; background: #fff; font-size: 0 }
img { display: block; margin: 2px auto 0 }
</style>
@@ -995,7 +995,7 @@ def test_images():
assert_same_rendering(200, 30, [
(name, '''
<style>
- @page { -weasy-size: 200px 30px }
+ @page { size: 200px 30px }
body { margin: 0; background: #fff; font-size: 0 }
</style>
<div>%s</div>
@@ -1019,23 +1019,23 @@ def test_images():
assert_pixels('image_0x1', 8, 8, no_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px; background: #fff; font-size: 0 }
</style>
<div><img src="pattern.png" alt="not shown"
style="width: 0; height: 1px"></div>
''')
assert_pixels('image_1x0', 8, 8, no_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px; background: #fff; font-size: 0 }
</style>
<div><img src="pattern.png" alt="not shown"
style="width: 1px; height: 0"></div>
''')
assert_pixels('image_0x0', 8, 8, no_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px; background: #fff; font-size: 0 }
</style>
<div><img src="pattern.png" alt="not shown"
@@ -1073,7 +1073,7 @@ def test_images():
]
assert_pixels('image_page_break', 8, 3 * 8, page_break, '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff }
+ @page { size: 8px; margin: 2px; background: #fff }
body { font-size: 0 }
</style>
<div><img src="pattern.png"></div>
@@ -1083,7 +1083,7 @@ def test_images():
# Regression test: padding used to be ignored on images
assert_pixels('image_with_padding', 8, 8, centered_image, '''
<style>
- @page { -weasy-size: 8px; background: #fff }
+ @page { size: 8px; background: #fff }
body { font-size: 0 }
</style>
<div style="line-height: 1px">
@@ -1094,7 +1094,7 @@ def test_images():
# Regression test: this used to cause an exception
assert_pixels('image_in_inline_block', 8, 8, centered_image, '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px 0 0 2px; background: #fff; font-size: 0 }
</style>
<div style="display: inline-block">
@@ -1108,7 +1108,7 @@ def test_images():
def test_visibility():
source = '''
<style>
- @page { -weasy-size: 12px 7px }
+ @page { size: 12px 7px }
body { background: #fff; font: 1px/1 serif }
img { margin: 1px 0 0 1px; }
%(extra_css)s
@@ -1154,7 +1154,7 @@ def test_visibility():
def test_tables():
source = '''
<style>
- @page { -weasy-size: 28px }
+ @page { size: 28px }
html { background: #fff; }
table { margin: 1px; padding: 1px; border-spacing: 1px;
border: 1px solid transparent }
@@ -1335,15 +1335,15 @@ def test_before_after():
assert_same_rendering(300, 30, [
('pseudo_before', '''
<style>
- @page { -weasy-size: 300px 30px }
+ @page { size: 300px 30px }
body { margin: 0; background: #fff }
a[href]:before { content: '[' '' attr(href) '] ' }
</style>
<p><a href="some url">some content</p>
'''),
('pseudo_before_reference', '''
<style>
- @page { -weasy-size: 300px 30px }
+ @page { size: 300px 30px }
body { margin: 0; background: #fff }
</style>
<p><a href="another url">[some url] some content</p>
@@ -1353,7 +1353,7 @@ def test_before_after():
assert_same_rendering(500, 30, [
('pseudo_quotes', '''
<style>
- @page { -weasy-size: 500px 30px }
+ @page { size: 500px 30px }
body { margin: 0; background: #fff; quotes: '«' '»' '“' '”' }
q:before { content: open-quote ' '}
q:after { content: ' ' close-quote }
@@ -1362,7 +1362,7 @@ def test_before_after():
'''),
('pseudo_quotes_reference', '''
<style>
- @page { -weasy-size: 500px 30px }
+ @page { size: 500px 30px }
body { margin: 0; background: #fff }
</style>
<p>« Lorem ipsum “ dolor ” sit amet »</p>
@@ -1372,15 +1372,15 @@ def test_before_after():
assert_same_rendering(100, 30, [
('pseudo_url', '''
<style>
- @page { -weasy-size: 100px 30px }
+ @page { size: 100px 30px }
body { margin: 0; background: #fff; }
p:before { content: 'a' url(pattern.png) 'b'}
</style>
<p>c</p>
'''),
('pseudo_url_reference', '''
<style>
- @page { -weasy-size: 100px 30px }
+ @page { size: 100px 30px }
body { margin: 0; background: #fff }
</style>
<p>a<img src="pattern.png" alt="Missing image">bc</p>
@@ -1393,7 +1393,7 @@ def test_borders():
"""Test the rendering of borders"""
source = '''
<style>
- @page { -weasy-size: 140px 110px }
+ @page { size: 140px 110px }
html { background: #fff }
body { margin: 10px; width: 100px; height: 70px;
border: 10px %(border_style)s blue }
@@ -1463,7 +1463,7 @@ def test_margin_boxes():
html { height: 100% }
body { background: #f00; height: 100% }
@page {
- -weasy-size: 15px;
+ size: 15px;
margin: 4px 6px 7px 5px;
background: white;
@@ -1499,7 +1499,7 @@ def test_unicode():
text = 'I løvë Unicode'
style = '''
@page {
- -weasy-size: 200px 50px;
+ size: 200px 50px;
}
p { color: blue }
'''
@@ -1551,7 +1551,7 @@ def test_overflow():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px }
+ @page { size: 8px }
body { margin: 2px 0 0 2px; background: #fff; font-size:0 }
div { height: 2px; overflow: hidden }
</style>
@@ -1571,7 +1571,7 @@ def test_overflow():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; background: #fff;
+ @page { size: 8px; background: #fff;
margin: 2px;
padding-bottom: 2px;
border-bottom: 1px transparent solid; }
@@ -1590,7 +1590,7 @@ def clip(css, pixels):
name = 'background_repeat_clipped_%s' % num[0]
assert_pixels(name, 14, 16, pixels, '''
<style>
- @page { -weasy-size: 14px 16px; background: #fff }
+ @page { size: 14px 16px; background: #fff }
div { margin: 1px; height: 10px;
border: 1px green solid;
background: url(pattern.png);
@@ -1687,7 +1687,7 @@ def test_opacity():
"""Test the opacity property."""
template = '''
<style>
- @page { -weasy-size: 200px 60px }
+ @page { size: 200px 60px }
body { margin: 0; background: #fff }
</style>
%s
@@ -1740,8 +1740,8 @@ def test_2d_transform():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: rotate(90deg); font-size: 0 }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: rotate(90deg); font-size: 0 }
</style>
<div><img src="pattern.png"></div>
''')
@@ -1757,8 +1757,8 @@ def test_2d_transform():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: matrix(-1, 0, 0, 1, 0, 0); font-size: 0 }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: matrix(-1, 0, 0, 1, 0, 0); font-size: 0 }
</style>
<div><img src="pattern.png"></div>
''')
@@ -1774,8 +1774,8 @@ def test_2d_transform():
_+_+_+B+B+B+B+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: translate(1px, 2px); font-size: 0 }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: translate(1px, 2px); font-size: 0 }
</style>
<div><img src="pattern.png"></div>
''')
@@ -1791,8 +1791,8 @@ def test_2d_transform():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: translate(25%, 0); font-size: 0 }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: translate(25%, 0); font-size: 0 }
</style>
<div><img src="pattern.png"></div>
''')
@@ -1808,8 +1808,8 @@ def test_2d_transform():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: translateX(0.25em); font-size: 12px }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: translateX(0.25em); font-size: 12px }
div div { font-size: 0 }
</style>
<div><div><img src="pattern.png"></div></div>
@@ -1826,8 +1826,8 @@ def test_2d_transform():
_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 8px; margin: 2px; background: #fff; }
- div { -weasy-transform: translateY(-1px); font-size: 0 }
+ @page { size: 8px; margin: 2px; background: #fff; }
+ div { transform: translateY(-1px); font-size: 0 }
</style>
<div><img src="pattern.png"></div>
''')
@@ -1845,10 +1845,10 @@ def test_2d_transform():
_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 10px; margin: 2px; background: #fff; }
- div { -weasy-transform: scale(2, 2);
- -weasy-transform-origin: 1px 1px;
- -weasy-image-rendering: optimizeSpeed;
+ @page { size: 10px; margin: 2px; background: #fff; }
+ div { transform: scale(2, 2);
+ transform-origin: 1px 1px;
+ image-rendering: optimizeSpeed;
font-size: 0 }
</style>
<div><img src="pattern.png"></div>
@@ -1867,10 +1867,10 @@ def test_2d_transform():
_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 10px; margin: 2px; background: #fff; }
- div { -weasy-transform: scale(1, 2);
- -weasy-transform-origin: 1px 1px;
- -weasy-image-rendering: optimizeSpeed;
+ @page { size: 10px; margin: 2px; background: #fff; }
+ div { transform: scale(1, 2);
+ transform-origin: 1px 1px;
+ image-rendering: optimizeSpeed;
font-size: 0 }
</style>
<div><img src="pattern.png"></div>
@@ -1889,10 +1889,10 @@ def test_2d_transform():
_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 10px; margin: 2px; background: #fff; }
- div { -weasy-transform: scaleY(2);
- -weasy-transform-origin: 1px 1px;
- -weasy-image-rendering: optimizeSpeed;
+ @page { size: 10px; margin: 2px; background: #fff; }
+ div { transform: scaleY(2);
+ transform-origin: 1px 1px;
+ image-rendering: optimizeSpeed;
font-size: 0 }
</style>
<div><img src="pattern.png"></div>
@@ -1911,10 +1911,10 @@ def test_2d_transform():
_+_+_+_+_+_+_+_+_+_,
], '''
<style>
- @page { -weasy-size: 10px; margin: 2px; background: #fff; }
- div { -weasy-transform: scaleX(2);
- -weasy-transform-origin: 1px 1px;
- -weasy-image-rendering: optimizeSpeed;
+ @page { size: 10px; margin: 2px; background: #fff; }
+ div { transform: scaleX(2);
+ transform-origin: 1px 1px;
+ image-rendering: optimizeSpeed;
font-size: 0 }
</style>
<div><img src="pattern.png"></div>
View
96 weasyprint/tests/test_layout.py
@@ -61,36 +61,36 @@ def test_page_size():
assert int(page.margin_width()) == 793 # A4: 210 mm in pixels
assert int(page.margin_height()) == 1122 # A4: 297 mm in pixels
- page, = parse('<style>@page { -weasy-size: 2in 10in; }</style>')
+ page, = parse('<style>@page { size: 2in 10in; }</style>')
assert page.margin_width() == 192
assert page.margin_height() == 960
- page, = parse('<style>@page { -weasy-size: 242px; }</style>')
+ page, = parse('<style>@page { size: 242px; }</style>')
assert page.margin_width() == 242
assert page.margin_height() == 242
- page, = parse('<style>@page { -weasy-size: letter; }</style>')
+ page, = parse('<style>@page { size: letter; }</style>')
assert page.margin_width() == 816 # 8.5in
assert page.margin_height() == 1056 # 11in
- page, = parse('<style>@page { -weasy-size: letter portrait; }</style>')
+ page, = parse('<style>@page { size: letter portrait; }</style>')
assert page.margin_width() == 816 # 8.5in
assert page.margin_height() == 1056 # 11in
- page, = parse('<style>@page { -weasy-size: letter landscape; }</style>')
+ page, = parse('<style>@page { size: letter landscape; }</style>')
assert page.margin_width() == 1056 # 11in
assert page.margin_height() == 816 # 8.5in
- page, = parse('<style>@page { -weasy-size: portrait; }</style>')
+ page, = parse('<style>@page { size: portrait; }</style>')
assert int(page.margin_width()) == 793 # A4: 210 mm
assert int(page.margin_height()) == 1122 # A4: 297 mm
- page, = parse('<style>@page { -weasy-size: landscape; }</style>')
+ page, = parse('<style>@page { size: landscape; }</style>')
assert int(page.margin_width()) == 1122 # A4: 297 mm
assert int(page.margin_height()) == 793 # A4: 210 mm
page, = parse('''
- <style>@page { -weasy-size: 200px 300px; margin: 10px 10% 20% 1in }
+ <style>@page { size: 200px 300px; margin: 10px 10% 20% 1in }
body { margin: 8px }
</style>
<p style="margin: 0">
@@ -127,7 +127,7 @@ def test_page_size():
page, = parse('''
<style>
- @page { -weasy-size: 100px; margin: 1px 2px; padding: 4px 8px;
+ @page { size: 100px; margin: 1px 2px; padding: 4px 8px;
border-width: 16px 32px; border-style: solid }
</style>
<body>
@@ -140,7 +140,7 @@ def test_page_size():
assert html.position_y == 21 # 1 + 4 + 16
page, = parse('''<style>@page {
- -weasy-size: 106px 206px; width: 80px; height: 170px;
+ size: 106px 206px; width: 80px; height: 170px;
padding: 1px; border: 2px solid; margin: auto;
}</style>''')
assert page.margin_top == 15 # (206 - 2*1 - 2*2 - 170) / 2
@@ -149,7 +149,7 @@ def test_page_size():
assert page.margin_left == 10 # (106 - 2*1 - 2*2 - 80) / 2
page, = parse('''<style>@page {
- -weasy-size: 106px 206px; width: 80px; height: 170px;
+ size: 106px 206px; width: 80px; height: 170px;
padding: 1px; border: 2px solid; margin: 5px 5px auto auto;
}</style>''')
assert page.margin_top == 5
@@ -159,21 +159,21 @@ def test_page_size():
# Over-constrained: the containing block is resized
page, = parse('''<style>@page {
- -weasy-size: 4px 10000px; width: 100px; height: 100px;
+ size: 4px 10000px; width: 100px; height: 100px;
padding: 1px; border: 2px solid; margin: 3px;
}</style>''')
assert page.margin_width() == 112 # 100 + 2*1 + 2*2 + 2*3
assert page.margin_height() == 112
page, = parse('''<style>@page {
- -weasy-size: 1000px; margin: 100px;
+ size: 1000px; margin: 100px;
max-width: 500px; min-height: 1500px;
}</style>''')
assert page.margin_width() == 700
assert page.margin_height() == 1700
page, = parse('''<style>@page {
- -weasy-size: 1000px; margin: 100px;
+ size: 1000px; margin: 100px;
min-width: 1500px; max-height: 500px;
}</style>''')
assert page.margin_width() == 1700
@@ -185,7 +185,7 @@ def test_block_widths():
"""Test the blocks widths."""
page, = parse('''
<style>
- @page { margin: 0; -weasy-size: 120px 2000px }
+ @page { margin: 0; size: 120px 2000px }
body { margin: 0 }
div { margin: 10px }
p { padding: 2px; border-width: 1px; border-style: solid }
@@ -323,7 +323,7 @@ def test_block_heights():
"""Test the blocks heights."""
page, = parse('''
<style>
- @page { margin: 0; -weasy-size: 100px 20000px }
+ @page { margin: 0; size: 100px 20000px }
html, body { margin: 0 }
div { margin: 4px; border-width: 2px; border-style: solid;
padding: 4px }
@@ -452,7 +452,7 @@ def test_inline_block_sizes():
"""Test the inline-block elements sizes."""
page, = parse('''
<style>
- @page { margin: 0; -weasy-size: 200px 2000px }
+ @page { margin: 0; size: 200px 2000px }
body { margin: 0 }
div { display: inline-block; }
</style>
@@ -832,7 +832,7 @@ def test_auto_layout_table():
page, = parse('''
<style>
- @page { -weasy-size: 100px 1000px; }
+ @page { size: 100px 1000px; }
</style>
<table style="border-spacing: 1px; margin-right: 79px; font-size: 0">
<tr>
@@ -1332,7 +1332,7 @@ def test_page_breaks():
"""Test the page breaks."""
pages = parse('''
<style>
- @page { -weasy-size: 100px; margin: 10px }
+ @page { size: 100px; margin: 10px }
body { margin: 0 }
div { height: 30px; font-size: 20px; }
</style>
@@ -1356,7 +1356,7 @@ def test_page_breaks():
# TODO: This currently gives no page break. Should it?
# pages = parse('''
# <style>
-# @page { -weasy-size: 100px; margin: 10px }
+# @page { size: 100px; margin: 10px }
# body { margin: 0 }
# div { height: 30px }
# </style>
@@ -1374,7 +1374,7 @@ def test_page_breaks():
pages = parse('''
<style>
- @page { -weasy-size: 100px; margin: 10px }
+ @page { size: 100px; margin: 10px }
img { height: 30px; display: block }
</style>
<body>
@@ -1454,7 +1454,7 @@ def test_page_breaks():
# Without any 'avoid', this breaks after the <div>
page_1, page_2 = parse('''
<style>
- @page { -weasy-size: 140px; margin: 0 }
+ @page { size: 140px; margin: 0 }
img { height: 25px; vertical-align: top }
p { orphans: 1; widows: 1 }
</style>
@@ -1484,7 +1484,7 @@ def test_page_breaks():
# before the <div>
page_1, page_2 = parse('''
<style>
- @page { -weasy-size: 140px; margin: 0 }
+ @page { size: 140px; margin: 0 }
img { height: 25px; vertical-align: top }
p { orphans: 1; widows: 1 }
</style>
@@ -1515,7 +1515,7 @@ def test_page_breaks():
page_1, page_2 = parse('''
<style>
- @page { -weasy-size: 140px; margin: 0 }
+ @page { size: 140px; margin: 0 }
img { height: 25px; vertical-align: top }
p { orphans: 1; widows: 1 }
</style>
@@ -1550,7 +1550,7 @@ def test_page_breaks():
# Reference for the next test
page_1, page_2, page_3 = parse('''
<style>
- @page { -weasy-size: 100px; margin: 0 }
+ @page { size: 100px; margin: 0 }
img { height: 30px; display: block; }
p { orphans: 1; widows: 1 }
</style>
@@ -1581,7 +1581,7 @@ def test_page_breaks():
page_1, page_2, page_3 = parse('''
<style>
- @page { -weasy-size: 100px; margin: 0 }
+ @page { size: 100px; margin: 0 }
img { height: 30px; display: block; }
p { orphans: 1; widows: 1 }
</style>
@@ -1624,7 +1624,7 @@ def test_orphans_widows_avoid():
def line_distribution(css):
pages = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
h1 { height: 120px }
p { line-height: 20px;
width: 1px; /* line break at each word */
@@ -1700,7 +1700,7 @@ def run(html):
rows_per_page, rows_position_y = run('''
<style>
- @page { -weasy-size: 120px }
+ @page { size: 120px }
table { table-layout: fixed; width: 100% }
h1 { height: 30px }
td { height: 40px }
@@ -1725,7 +1725,7 @@ def run(html):
rows_per_page, rows_position_y = run('''
<style>
- @page { -weasy-size: 120px }
+ @page { size: 120px }
h1 { height: 30px}
td { height: 40px }
table { table-layout: fixed; width: 100%;
@@ -1745,7 +1745,7 @@ def run(html):
rows_per_page, rows_position_y = run('''
<style>
- @page { -weasy-size: 120px }
+ @page { size: 120px }
h1 { height: 30px}
td { height: 40px }
table { table-layout: fixed; width: 100%;
@@ -1767,7 +1767,7 @@ def run(html):
rows_per_page, rows_position_y = run('''
<style>
- @page { -weasy-size: 120px }
+ @page { size: 120px }
h1 { height: 30px}
td { height: 40px }
table { table-layout: fixed; width: 100% }
@@ -1787,7 +1787,7 @@ def run(html):
pages = parse('''
<style>
- @page { -weasy-size: 100px }
+ @page { size: 100px }
</style>
<h1 style="margin: 0; height: 30px">Lipsum</h1>
<!-- Leave 70px on the first page: enough for the header or row1
@@ -1996,7 +1996,7 @@ def test_page_and_linebox_breaking():
pages = parse('''
<style>
div { font-family:%(fonts)s; font-size:22px}
- @page { -weasy-size: 100px; margin:2px; border:1px solid }
+ @page { size: 100px; margin:2px; border:1px solid }
body { margin: 0 }
</style>
<div><span/>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15</div>
@@ -2153,7 +2153,7 @@ def get_img(html):
# Block-level image:
page, = parse('''
<style>
- @page { -weasy-size: 100px }
+ @page { size: 100px }
img { width: 40px; margin: 10px auto; display: block }
</style>
<body>
@@ -2170,7 +2170,7 @@ def get_img(html):
page, = parse('''
<style>
- @page { -weasy-size: 100px }
+ @page { size: 100px }
img { min-width: 40%; margin: 10px auto; display: block }
</style>
<body>
@@ -2473,7 +2473,7 @@ def test_text_align_left():
"""
page, = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
</style>
<body>
<img src="pattern.png" style="width: 40px">
@@ -2505,7 +2505,7 @@ def test_text_align_right():
"""
page, = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
body { text-align: right }
</style>
<body>
@@ -2537,7 +2537,7 @@ def test_text_align_center():
"""
page, = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
body { text-align: center }
</style>
<body>
@@ -2557,7 +2557,7 @@ def test_text_align_justify():
"""Test justified text."""
page, = parse('''
<style>
- @page { -weasy-size: 300px 1000px }
+ @page { size: 300px 1000px }
body { text-align: justify }
</style>
<p><img src="pattern.png" style="width: 40px"> &#20;
@@ -2663,7 +2663,7 @@ def test_text_indent():
for indent in ['12px', '6%']: # 6% of 200px is 12px
page, = parse('''
<style>
- @page { -weasy-size: 220px }
+ @page { size: 220px }
body { margin: 10px; text-indent: %(indent)s }
</style>
<p>Some text that is long enough that it take at least three line,
@@ -2686,7 +2686,7 @@ def test_inline_replaced_auto_margins():
"""Test that auto margins are ignored for inline replaced boxes."""
page, = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
img { display: inline; margin: auto; width: 50px }
</style>
<body>
@@ -2707,7 +2707,7 @@ def test_empty_inline_auto_margins():
"""Test that horizontal auto margins are ignored for empty inline boxes."""
page, = parse('''
<style>
- @page { -weasy-size: 200px }
+ @page { size: 200px }
span { margin: auto }
</style>
<body><span></span>
@@ -2731,7 +2731,7 @@ def test_box_sizing():
"""
page, = parse('''
<style>
- @page { -weasy-size: 100000px }
+ @page { size: 100000px }
body { width: 10000px; margin: 0 }
div { width: 10%; height: 1000px;
margin: 100px; padding: 10px; border: 1px solid }
@@ -3033,7 +3033,7 @@ def test_table_row_height():
def test_table_wrapper():
page, = parse('''
<style>
- @page { -weasy-size: 1000px }
+ @page { size: 1000px }
table { width: 600px; height: 500px; table-layout: fixed;
padding: 1px; border: 10px solid; margin: 100px; }
</style>
@@ -3083,7 +3083,7 @@ def test_margin_boxes_fixed_dimension():
padding: 10px;
}
- -weasy-size: 1000px;
+ size: 1000px;
margin-top: 10%;
margin-bottom: 40%;
margin-left: 20%;
@@ -3323,7 +3323,7 @@ def get_widths(css):
page, = parse('''
<style>
@page {
- -weasy-size: 800px;
+ size: 800px;
margin: 100px;
padding: 42px;
border: 7px solid;
@@ -3495,7 +3495,7 @@ def test_margin_boxes_vertical_align():
page, = parse('''
<style>
@page {
- -weasy-size: 800px;
+ size: 800px;
margin: 106px; /* margin boxes’ content height is 100px */
@top-left {
@@ -3930,7 +3930,7 @@ def test_absolute_positioning():
page, = parse('''
<style>
- @page { -weasy-size: 1000px 2000px }
+ @page { size: 1000px 2000px }
html { font-size: 0 }
p { height: 20px }
</style>
View
2 weasyprint/tests/test_pdf.py
@@ -43,7 +43,7 @@ def test_pdf_parser():
def get_metadata(html, base_url=resource_filename('<inline HTML>')):
document = TestPDFDocument(html, base_url=base_url,
user_stylesheets=[CSS(
- string='@page { -weasy-size: 500pt 1000pt; margin: 50pt }')])
+ string='@page { size: 500pt 1000pt; margin: 50pt }')])
return pdf.gather_metadata(document)
View
2 weasyprint/tests/w3_test_suite/run.py
@@ -40,7 +40,7 @@
RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__), 'test_results')
PAGE_SIZE_STYLESHEET = CSS(string='''
- @page { margin: 0; -weasy-size: 640px }
+ @page { margin: 0; size: 640px }
''')
IGNORED_FLAGS = {'interact', 'dom'}
View
2 weasyprint/tests/w3_test_suite/web.py
@@ -116,7 +116,7 @@ def section(chapter_num, section_num):
default_stylesheet = CSS(string='''
- @page { margin: 20px; -weasy-size: 680px }
+ @page { margin: 20px; size: 680px }
body { margin: 0 }
''')

0 comments on commit 279386b

Please sign in to comment.