1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Test presentational hints

This commit is contained in:
Guillaume Ayoub 2016-09-01 02:11:33 +02:00
parent 207694ac14
commit 7925baa5f8
3 changed files with 389 additions and 98 deletions

View File

@ -230,20 +230,21 @@ def find_style_attributes(element_tree, presentational_hints=False):
continue
specificity = (0, 0, 0, 0)
if element.tag == 'body':
for prop, position in (
# TODO: we should check the container frame element
for part, position in (
('height', 'top'), ('height', 'bottom'),
('width', 'left'), ('width', 'right')):
style_attribute = None
for prop in ('margin%s' % prop, '%smargin' % prop):
for prop in ('margin%s' % part, '%smargin' % position):
if element.get(prop):
style_attribute = 'margin-%s:%spx' % (
position, element.get('margin%s' % prop))
position, element.get(prop))
break
if style_attribute:
yield specificity, check_style_attribute(
parser, element, style_attribute)
if element.get('background'):
style_attribute = 'background-image:%s' % (
style_attribute = 'background-image:url(%s)' % (
element.get('background'))
yield specificity, check_style_attribute(
parser, element, style_attribute)
@ -254,8 +255,9 @@ def find_style_attributes(element_tree, presentational_hints=False):
parser, element, style_attribute)
if element.get('text'):
style_attribute = 'color:%s' % element.get('text')
yield check_style_attribute(
yield specificity, check_style_attribute(
parser, element, style_attribute)
# TODO: we should support link, vlink, alink
elif element.tag == 'center':
yield specificity, check_style_attribute(
parser, element, 'text-align:center')
@ -292,16 +294,17 @@ def find_style_attributes(element_tree, presentational_hints=False):
4: 'large',
5: 'x-large',
6: 'xx-large',
7: '48px',
7: '48px', # 1.5 * xx-large
}
if relative_plus:
size += 3
elif relative_minus:
size -= 3
size = min(1, max(7, size))
size = max(1, min(7, size))
yield specificity, check_style_attribute(
parser, element, 'font-size:%s' % font_sizes[size])
elif element.tag == 'table':
# TODO: we should support cellpadding
if element.get('cellspacing'):
yield specificity, check_style_attribute(
parser, element,
@ -333,7 +336,7 @@ def find_style_attributes(element_tree, presentational_hints=False):
yield specificity, check_style_attribute(
parser, element, style_attribute)
if element.get('background'):
style_attribute = 'background-image:%s' % (
style_attribute = 'background-image:url(%s)' % (
element.get('background'))
yield specificity, check_style_attribute(
parser, element, style_attribute)
@ -359,7 +362,7 @@ def find_style_attributes(element_tree, presentational_hints=False):
yield specificity, check_style_attribute(
parser, element, 'text-align:%s' % align)
if element.get('background'):
style_attribute = 'background-image:%s' % (
style_attribute = 'background-image:url(%s)' % (
element.get('background'))
yield specificity, check_style_attribute(
parser, element, style_attribute)
@ -376,10 +379,6 @@ def find_style_attributes(element_tree, presentational_hints=False):
yield specificity, check_style_attribute(
parser, element, style_attribute)
if element.tag in ('td', 'th'):
if element.get('cellpadding'):
yield specificity, check_style_attribute(
parser, element,
'padding:%spx' % element.get('cellpadding'))
if element.get('width'):
style_attribute = 'width:%s' % element.get('width')
if element.get('width').isdigit():
@ -406,10 +405,10 @@ def find_style_attributes(element_tree, presentational_hints=False):
size = int(element.get('size'))
except ValueError:
LOGGER.warning('Invalid value for size: %s' % size)
if 'color' in element or 'noshade' in element:
if (element.get('color'), element.get('noshade')) != (None, None):
if size >= 1:
yield specificity, check_style_attribute(
parser, element, 'border-width:%spx' % size / 2)
parser, element, 'border-width:%spx' % (size / 2))
elif size == 1:
yield specificity, check_style_attribute(
parser, element, 'border-bottom-width:0')

View File

@ -7,81 +7,84 @@ expressed as CSS.
See https://www.w3.org/TR/html5/rendering.html#rendering
TODO: Attribute values are not case-insensitive, but they should be. We can add
a "i" flag when CSS Selectors Level 4 is supported.
*/
pre[wrap] { white-space: pre-wrap; }
br[clear=left i] { clear: left; }
br[clear=right i] { clear: right; }
br[clear=all i], br[clear=both i] { clear: both; }
br[clear=left] { clear: left; }
br[clear=right] { clear: right; }
br[clear=all], br[clear=both] { clear: both; }
ol[type=1], li[type=1] { list-style-type: decimal; }
ol[type=a], li[type=a] { list-style-type: lower-alpha; }
ol[type=A], li[type=A] { list-style-type: upper-alpha; }
ol[type=i], li[type=i] { list-style-type: lower-roman; }
ol[type=I], li[type=I] { list-style-type: upper-roman; }
ul[type=disc i], li[type=disc i] { list-style-type: disc; }
ul[type=circle i], li[type=circle i] { list-style-type: circle; }
ul[type=square i], li[type=square i] { list-style-type: square; }
ul[type=disc], li[type=disc] { list-style-type: disc; }
ul[type=circle], li[type=circle] { list-style-type: circle; }
ul[type=square], li[type=square] { list-style-type: square; }
table[align=left i] { float: left; }
table[align=right i] { float: right; }
table[align=center i] { margin-left: auto; margin-right: auto; }
thead[align=absmiddle i], tbody[align=absmiddle i], tfoot[align=absmiddle i],
tr[align=absmiddle i], td[align=absmiddle i], th[align=absmiddle i] {
table[align=left] { float: left; }
table[align=right] { float: right; }
table[align=center] { margin-left: auto; margin-right: auto; }
thead[align=absmiddle], tbody[align=absmiddle], tfoot[align=absmiddle],
tr[align=absmiddle], td[align=absmiddle], th[align=absmiddle] {
text-align: center;
}
caption[align=bottom i] { caption-side: bottom; }
p[align=left i], h1[align=left i], h2[align=left i], h3[align=left i],
h4[align=left i], h5[align=left i], h6[align=left i] {
caption[align=bottom] { caption-side: bottom; }
p[align=left], h1[align=left], h2[align=left], h3[align=left],
h4[align=left], h5[align=left], h6[align=left] {
text-align: left;
}
p[align=right i], h1[align=right i], h2[align=right i], h3[align=right i],
h4[align=right i], h5[align=right i], h6[align=right i] {
p[align=right], h1[align=right], h2[align=right], h3[align=right],
h4[align=right], h5[align=right], h6[align=right] {
text-align: right;
}
p[align=center i], h1[align=center i], h2[align=center i], h3[align=center i],
h4[align=center i], h5[align=center i], h6[align=center i] {
p[align=center], h1[align=center], h2[align=center], h3[align=center],
h4[align=center], h5[align=center], h6[align=center] {
text-align: center;
}
p[align=justify i], h1[align=justify i], h2[align=justify i], h3[align=justify i],
h4[align=justify i], h5[align=justify i], h6[align=justify i] {
p[align=justify], h1[align=justify], h2[align=justify], h3[align=justify],
h4[align=justify], h5[align=justify], h6[align=justify] {
text-align: justify;
}
thead[valign=top i], tbody[valign=top i], tfoot[valign=top i],
tr[valign=top i], td[valign=top i], th[valign=top i] {
thead[valign=top], tbody[valign=top], tfoot[valign=top],
tr[valign=top], td[valign=top], th[valign=top] {
vertical-align: top;
}
thead[valign=middle i], tbody[valign=middle i], tfoot[valign=middle i],
tr[valign=middle i], td[valign=middle i], th[valign=middle i] {
thead[valign=middle], tbody[valign=middle], tfoot[valign=middle],
tr[valign=middle], td[valign=middle], th[valign=middle] {
vertical-align: middle;
}
thead[valign=bottom i], tbody[valign=bottom i], tfoot[valign=bottom i],
tr[valign=bottom i], td[valign=bottom i], th[valign=bottom i] {
thead[valign=bottom], tbody[valign=bottom], tfoot[valign=bottom],
tr[valign=bottom], td[valign=bottom], th[valign=bottom] {
vertical-align: bottom;
}
thead[valign=baseline i], tbody[valign=baseline i], tfoot[valign=baseline i],
tr[valign=baseline i], td[valign=baseline i], th[valign=baseline i] {
thead[valign=baseline], tbody[valign=baseline], tfoot[valign=baseline],
tr[valign=baseline], td[valign=baseline], th[valign=baseline] {
vertical-align: baseline;
}
td[nowrap], th[nowrap] { white-space: nowrap; }
table[rules=none i], table[rules=groups i], table[rules=rows i],
table[rules=cols i], table[rules=all i] {
table[rules=none], table[rules=groups], table[rules=rows],
table[rules=cols], table[rules=all] {
border-style: hidden;
border-collapse: collapse;
}
table[border] { border-style: outset; } /* only if border is not equivalent to zero */
table[frame=void i] { border-style: hidden; }
table[frame=above i] { border-style: outset hidden hidden hidden; }
table[frame=below i] { border-style: hidden hidden outset hidden; }
table[frame=hsides i] { border-style: outset hidden outset hidden; }
table[frame=lhs i] { border-style: hidden hidden hidden outset; }
table[frame=rhs i] { border-style: hidden outset hidden hidden; }
table[frame=vsides i] { border-style: hidden outset; }
table[frame=box i], table[frame=border i] { border-style: outset; }
table[frame=void] { border-style: hidden; }
table[frame=above] { border-style: outset hidden hidden hidden; }
table[frame=below] { border-style: hidden hidden outset hidden; }
table[frame=hsides] { border-style: outset hidden outset hidden; }
table[frame=lhs] { border-style: hidden hidden hidden outset; }
table[frame=rhs] { border-style: hidden outset hidden hidden; }
table[frame=vsides] { border-style: hidden outset; }
table[frame=box], table[frame=border] { border-style: outset; }
table[border] > tr > td, table[border] > tr > th,
table[border] > thead > tr > td, table[border] > thead > tr > th,
@ -91,53 +94,53 @@ table[border] > tfoot > tr > td, table[border] > tfoot > tr > th {
border-width: 1px;
border-style: inset;
}
table[rules=none i] > tr > td, table[rules=none i] > tr > th,
table[rules=none i] > thead > tr > td, table[rules=none i] > thead > tr > th,
table[rules=none i] > tbody > tr > td, table[rules=none i] > tbody > tr > th,
table[rules=none i] > tfoot > tr > td, table[rules=none i] > tfoot > tr > th,
table[rules=groups i] > tr > td, table[rules=groups i] > tr > th,
table[rules=groups i] > thead > tr > td, table[rules=groups i] > thead > tr > th,
table[rules=groups i] > tbody > tr > td, table[rules=groups i] > tbody > tr > th,
table[rules=groups i] > tfoot > tr > td, table[rules=groups i] > tfoot > tr > th,
table[rules=rows i] > tr > td, table[rules=rows i] > tr > th,
table[rules=rows i] > thead > tr > td, table[rules=rows i] > thead > tr > th,
table[rules=rows i] > tbody > tr > td, table[rules=rows i] > tbody > tr > th,
table[rules=rows i] > tfoot > tr > td, table[rules=rows i] > tfoot > tr > th {
table[rules=none] > tr > td, table[rules=none] > tr > th,
table[rules=none] > thead > tr > td, table[rules=none] > thead > tr > th,
table[rules=none] > tbody > tr > td, table[rules=none] > tbody > tr > th,
table[rules=none] > tfoot > tr > td, table[rules=none] > tfoot > tr > th,
table[rules=groups] > tr > td, table[rules=groups] > tr > th,
table[rules=groups] > thead > tr > td, table[rules=groups] > thead > tr > th,
table[rules=groups] > tbody > tr > td, table[rules=groups] > tbody > tr > th,
table[rules=groups] > tfoot > tr > td, table[rules=groups] > tfoot > tr > th,
table[rules=rows] > tr > td, table[rules=rows] > tr > th,
table[rules=rows] > thead > tr > td, table[rules=rows] > thead > tr > th,
table[rules=rows] > tbody > tr > td, table[rules=rows] > tbody > tr > th,
table[rules=rows] > tfoot > tr > td, table[rules=rows] > tfoot > tr > th {
border-width: 1px;
border-style: none;
}
table[rules=cols i] > tr > td, table[rules=cols i] > tr > th,
table[rules=cols i] > thead > tr > td, table[rules=cols i] > thead > tr > th,
table[rules=cols i] > tbody > tr > td, table[rules=cols i] > tbody > tr > th,
table[rules=cols i] > tfoot > tr > td, table[rules=cols i] > tfoot > tr > th {
table[rules=cols] > tr > td, table[rules=cols] > tr > th,
table[rules=cols] > thead > tr > td, table[rules=cols] > thead > tr > th,
table[rules=cols] > tbody > tr > td, table[rules=cols] > tbody > tr > th,
table[rules=cols] > tfoot > tr > td, table[rules=cols] > tfoot > tr > th {
border-width: 1px;
border-style: none solid;
}
table[rules=all i] > tr > td, table[rules=all i] > tr > th,
table[rules=all i] > thead > tr > td, table[rules=all i] > thead > tr > th,
table[rules=all i] > tbody > tr > td, table[rules=all i] > tbody > tr > th,
table[rules=all i] > tfoot > tr > td, table[rules=all i] > tfoot > tr > th {
table[rules=all] > tr > td, table[rules=all] > tr > th,
table[rules=all] > thead > tr > td, table[rules=all] > thead > tr > th,
table[rules=all] > tbody > tr > td, table[rules=all] > tbody > tr > th,
table[rules=all] > tfoot > tr > td, table[rules=all] > tfoot > tr > th {
border-width: 1px;
border-style: solid;
}
table[rules=groups i] > colgroup {
table[rules=groups] > colgroup {
border-left-width: 1px;
border-left-style: solid;
border-right-width: 1px;
border-right-style: solid;
}
table[rules=groups i] > thead,
table[rules=groups i] > tbody,
table[rules=groups i] > tfoot {
table[rules=groups] > thead,
table[rules=groups] > tbody,
table[rules=groups] > tfoot {
border-top-width: 1px;
border-top-style: solid;
border-bottom-width: 1px;
border-bottom-style: solid;
}
table[rules=rows i] > tr, table[rules=rows i] > thead > tr,
table[rules=rows i] > tbody > tr, table[rules=rows i] > tfoot > tr {
table[rules=rows] > tr, table[rules=rows] > thead > tr,
table[rules=rows] > tbody > tr, table[rules=rows] > tfoot > tr {
border-top-width: 1px;
border-top-style: solid;
border-bottom-width: 1px;
@ -149,42 +152,42 @@ hr[align=right] { margin-left: auto; margin-right: 0; }
hr[align=center] { margin-left: auto; margin-right: auto; }
hr[color], hr[noshade] { border-style: solid; }
iframe[frameborder=0], iframe[frameborder=no i] { border: none; }
iframe[frameborder=0], iframe[frameborder=no] { border: none; }
applet[align=left i], embed[align=left i], iframe[align=left i],
img[align=left i], input[type=image i][align=left i], object[align=left i] {
applet[align=left], embed[align=left], iframe[align=left],
img[align=left], input[type=image][align=left], object[align=left] {
float: left;
}
applet[align=right i], embed[align=right i], iframe[align=right i],
img[align=right i], input[type=image i][align=right i], object[align=right i] {
applet[align=right], embed[align=right], iframe[align=right],
img[align=right], input[type=image][align=right], object[align=right] {
float: right;
}
applet[align=top i], embed[align=top i], iframe[align=top i],
img[align=top i], input[type=image i][align=top i], object[align=top i] {
applet[align=top], embed[align=top], iframe[align=top],
img[align=top], input[type=image][align=top], object[align=top] {
vertical-align: top;
}
applet[align=baseline i], embed[align=baseline i], iframe[align=baseline i],
img[align=baseline i], input[type=image i][align=baseline i], object[align=baseline i] {
applet[align=baseline], embed[align=baseline], iframe[align=baseline],
img[align=baseline], input[type=image][align=baseline], object[align=baseline] {
vertical-align: baseline;
}
applet[align=texttop i], embed[align=texttop i], iframe[align=texttop i],
img[align=texttop i], input[type=image i][align=texttop i], object[align=texttop i] {
applet[align=texttop], embed[align=texttop], iframe[align=texttop],
img[align=texttop], input[type=image][align=texttop], object[align=texttop] {
vertical-align: text-top;
}
applet[align=absmiddle i], embed[align=absmiddle i], iframe[align=absmiddle i],
img[align=absmiddle i], input[type=image i][align=absmiddle i], object[align=absmiddle i],
applet[align=abscenter i], embed[align=abscenter i], iframe[align=abscenter i],
img[align=abscenter i], input[type=image i][align=abscenter i], object[align=abscenter i] {
applet[align=absmiddle], embed[align=absmiddle], iframe[align=absmiddle],
img[align=absmiddle], input[type=image][align=absmiddle], object[align=absmiddle],
applet[align=abscenter], embed[align=abscenter], iframe[align=abscenter],
img[align=abscenter], input[type=image][align=abscenter], object[align=abscenter] {
vertical-align: middle;
}
applet[align=bottom i], embed[align=bottom i], iframe[align=bottom i],
img[align=bottom i], input[type=image i][align=bottom i],
object[align=bottom i] {
applet[align=bottom], embed[align=bottom], iframe[align=bottom],
img[align=bottom], input[type=image][align=bottom],
object[align=bottom] {
vertical-align: bottom;
}
}

View File

@ -0,0 +1,289 @@
# coding: utf-8
"""
weasyprint.tests.test_presentational_hints
------------------------------------------
Test the HTML presentational hints.
:copyright: Copyright 2016 Simon Sapin and contributors, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import division, unicode_literals
from .testing_utils import assert_no_logs
from .. import HTML, CSS
PH_TESTING_CSS = CSS(string='''
@page {margin: 0; size: 1000px 1000px}
body {margin: 0}
''')
@assert_no_logs
def test_no_ph():
"""Check that presentational hints are not applied when not requested."""
# Test both CSS and non-CSS rules
document = HTML(string='''
<hr size=100 />
<table align=right width=100><td>0</td></table>
''').render(stylesheets=[PH_TESTING_CSS])
page, = document.pages
html, = page._page_box.children
body, = html.children
hr, table = body.children
assert hr.border_height() != 100
assert table.position_x == 0
@assert_no_logs
def test_ph_page():
"""Check presentational hints on the page."""
document = HTML(string='''
<body marginheight=2 topmargin=3 leftmargin=5
bgcolor=red text=blue />
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
assert body.margin_top == 2
assert body.margin_bottom == 2
assert body.margin_left == 5
assert body.margin_right == 0
assert body.style.background_color == (1, 0, 0, 1)
assert body.style.color == (0, 0, 1, 1)
@assert_no_logs
def test_ph_flow():
"""Check presentational hints on the flow content."""
document = HTML(string='''
<pre wrap></pre>
<center></center>
<div align=center></div>
<div align=middle></div>
<div align=left></div>
<div align=right></div>
<div align=justify></div>
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
pre, center, div1, div2, div3, div4, div5 = body.children
assert pre.style.white_space == 'pre-wrap'
assert center.style.text_align == 'center'
assert div1.style.text_align == 'center'
assert div2.style.text_align == 'center'
assert div3.style.text_align == 'left'
assert div4.style.text_align == 'right'
assert div5.style.text_align == 'justify'
@assert_no_logs
def test_ph_phrasing():
"""Check presentational hints on the phrasing content."""
document = HTML(string='''
<br clear=left>
<br clear=right />
<br clear=both />
<br clear=all />
<font color=red face=ahem size=7></font>
<Font size=4></Font>
<font size=+5 ></font>
<font size=-5 ></font>
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
line1, line2, line3, line4, line5 = body.children
br1, = line1.children
br2, = line2.children
br3, = line3.children
br4, = line4.children
font1, font2, font3, font4 = line5.children
assert br1.style.clear == 'left'
assert br2.style.clear == 'right'
assert br3.style.clear == 'both'
assert br4.style.clear == 'both'
assert font1.style.color == (1, 0, 0, 1)
assert font1.style.font_family == ['ahem']
assert font1.style.font_size == 1.5 * 2 * 16
assert font2.style.font_size == 6 / 5 * 16
assert font3.style.font_size == 1.5 * 2 * 16
assert font4.style.font_size == 8 / 9 * 16
@assert_no_logs
def test_ph_lists():
"""Check presentational hints on lists."""
document = HTML(string='''
<ol>
<li type=A></li>
<li type=1></li>
<li type=a></li>
<li type=i></li>
<li type=I></li>
</ol>
<ul>
<li type=circle></li>
<li type=disc></li>
<li type=square></li>
</ul>
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
ol, ul = body.children
oli1, oli2, oli3, oli4, oli5 = ol.children
uli1, uli2, uli3 = ul.children
assert oli1.style.list_style_type == 'upper-alpha'
assert oli2.style.list_style_type == 'decimal'
assert oli3.style.list_style_type == 'lower-alpha'
assert oli4.style.list_style_type == 'lower-roman'
assert oli5.style.list_style_type == 'upper-roman'
assert uli1.style.list_style_type == 'circle'
assert uli2.style.list_style_type == 'disc'
assert uli3.style.list_style_type == 'square'
document = HTML(string='''
<ol type=A></ol>
<ol type=1></ol>
<ol type=a></ol>
<ol type=i></ol>
<ol type=I></ol>
<ul type=circle></ul>
<ul type=disc></ul>
<ul type=square></ul>
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
ol1, ol2, ol3, ol4, ol5, ul1, ul2, ul3 = body.children
assert ol1.style.list_style_type == 'upper-alpha'
assert ol2.style.list_style_type == 'decimal'
assert ol3.style.list_style_type == 'lower-alpha'
assert ol4.style.list_style_type == 'lower-roman'
assert ol5.style.list_style_type == 'upper-roman'
assert ul1.style.list_style_type == 'circle'
assert ul2.style.list_style_type == 'disc'
assert ul3.style.list_style_type == 'square'
@assert_no_logs
def test_ph_tables():
"""Check presentational hints on tables."""
document = HTML(string='''
<table align=left rules=none></table>
<table align=right rules=groups></table>
<table align=center rules=rows></table>
<table border=10 cellspacing=3 bordercolor=green>
<thead>
<tr>
<th valign=top></th>
</tr>
</thead>
<tr>
<td nowrap><h1 align=right></h1><p align=center></p></td>
</tr>
<tr>
</tr>
<tfoot align=justify>
<tr>
<td></td>
</tr>
</tfoot>
</table>
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
wrapper1, wrapper2, wrapper3, wrapper4, = body.children
assert wrapper1.style.float == 'left'
assert wrapper2.style.float == 'right'
assert wrapper3.style.margin_left == 'auto'
assert wrapper3.style.margin_right == 'auto'
assert wrapper1.children[0].style.border_left_style == 'hidden'
assert wrapper1.style.border_collapse == 'collapse'
assert wrapper2.children[0].style.border_left_style == 'hidden'
assert wrapper2.style.border_collapse == 'collapse'
assert wrapper3.children[0].style.border_left_style == 'hidden'
assert wrapper3.style.border_collapse == 'collapse'
table4, = wrapper4.children
assert table4.style.border_top_style == 'outset'
assert table4.style.border_top_width == 10
assert table4.style.border_spacing == (3, 3)
r, g, b, a = table4.style.border_left_color
assert g > r and g > b
head_group, rows_group, foot_group = table4.children
head, = head_group.children
th, = head.children
assert th.style.vertical_align == 'top'
line1, line2 = rows_group.children
td, = line1.children
assert td.style.white_space == 'nowrap'
assert td.style.border_top_width == 1
assert td.style.border_top_style == 'inset'
h1, p = td.children
assert h1.style.text_align == 'right'
assert p.style.text_align == 'center'
foot, = foot_group.children
tr, = foot.children
assert tr.style.text_align == 'justify'
@assert_no_logs
def test_ph_hr():
"""Check presentational hints on horizontal rules."""
document = HTML(string='''
<hr align=left>
<hr align=right />
<hr align=both color=red />
<hr align=center noshade size=10 />
<hr align=all size=8 width=100 />
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
hr1, hr2, hr3, hr4, hr5 = body.children
assert hr1.margin_left == 0
assert hr1.style.margin_right == 'auto'
assert hr2.style.margin_left == 'auto'
assert hr2.margin_right == 0
assert hr3.style.margin_left == 'auto'
assert hr3.style.margin_right == 'auto'
assert hr3.style.color == (1, 0, 0, 1)
assert hr4.style.margin_left == 'auto'
assert hr4.style.margin_right == 'auto'
assert hr4.border_height() == 10
assert hr4.style.border_top_width == 5
assert hr5.border_height() == 8
assert hr5.height == 6
assert hr5.width == 100
assert hr5.style.border_top_width == 1
@assert_no_logs
def test_ph_embedded():
"""Check presentational hints on embedded contents."""
document = HTML(string='''
<object data="data:image/svg+xml,<svg></svg>"
align=top hspace=10 vspace=20></object>
<img src="data:image/svg+xml,<svg></svg>" alt=text
align=right width=10 height=20 />
<embed src="data:image/svg+xml,<svg></svg>" align=texttop />
''').render(stylesheets=[PH_TESTING_CSS], presentational_hints=True)
page, = document.pages
html, = page._page_box.children
body, = html.children
line, = body.children
object_, text1, img, embed, text2 = line.children
print(line.children)
assert embed.style.vertical_align == 'text-top'
assert object_.style.vertical_align == 'top'
assert object_.margin_top == 20
assert object_.margin_left == 10
assert img.style.float == 'right'
assert img.width == 10
assert img.height == 20