| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class TestWidows extends GenericTest {
|
|
|
4 |
// No widows at all
|
|
|
5 |
function testWidows1() {
|
|
|
6 |
$media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
|
|
|
7 |
array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
|
|
|
8 |
$tree = $this->runPipeline('
|
|
|
9 |
<html>
|
|
|
10 |
<head>
|
|
|
11 |
<style type="text/css">
|
|
|
12 |
body { font-size: 10pt; line-height: 1; orphans:0; widows: 0; padding: 0; margin: 0; }
|
|
|
13 |
#wrap { width: 2em; }
|
|
|
14 |
#first { line-height: 1; height: 160pt; }
|
|
|
15 |
#second { width: 3em; }
|
|
|
16 |
</style>
|
|
|
17 |
</head>
|
|
|
18 |
<body>
|
|
|
19 |
<div id="first"> </div>
|
|
|
20 |
<div id="second">
|
|
|
21 |
LINE1
|
|
|
22 |
LINE2
|
|
|
23 |
LINE3
|
|
|
24 |
LINE4<!--Page break should be here-->
|
|
|
25 |
LINE5
|
|
|
26 |
</div>
|
|
|
27 |
</body>
|
|
|
28 |
</html>
|
|
|
29 |
', $media);
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Calculate page heights
|
|
|
33 |
*/
|
|
|
34 |
$page_heights = PageBreakLocator::getPages($tree,
|
|
|
35 |
mm2pt($media->real_height()),
|
|
|
36 |
mm2pt($media->height() - $media->margins['top']));
|
|
|
37 |
|
|
|
38 |
$first_div = $tree->get_element_by_id('first');
|
|
|
39 |
$second_div = $tree->get_element_by_id('second');
|
|
|
40 |
|
|
|
41 |
$this->assertEqual(count($page_heights), 2,
|
|
|
42 |
sprintf("Two pages expected, got %s",
|
|
|
43 |
count($page_heights)));
|
|
|
44 |
|
|
|
45 |
$this->assertWithinMargin($page_heights[0],
|
|
|
46 |
$first_div->get_full_height() + pt2pt(40),
|
|
|
47 |
0.01);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
// Default widows value (2)
|
|
|
51 |
function testWidows2() {
|
|
|
52 |
$media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
|
|
|
53 |
array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
|
|
|
54 |
$tree = $this->runPipeline('
|
|
|
55 |
<html>
|
|
|
56 |
<head>
|
|
|
57 |
<style type="text/css">
|
|
|
58 |
body { font-size: 10pt; line-height: 1; padding: 0; margin: 0; }
|
|
|
59 |
#first { line-height: 1; height: 160pt; }
|
|
|
60 |
#second { width: 3em; }
|
|
|
61 |
</style>
|
|
|
62 |
</head>
|
|
|
63 |
<body>
|
|
|
64 |
<div id="first"> </div>
|
|
|
65 |
<div id="second">
|
|
|
66 |
LINE1
|
|
|
67 |
LINE2
|
|
|
68 |
LINE3<!--Page break should be here-->
|
|
|
69 |
LINE4
|
|
|
70 |
LINE5
|
|
|
71 |
</div>
|
|
|
72 |
</body>
|
|
|
73 |
</html>
|
|
|
74 |
', $media);
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Calculate page heights
|
|
|
78 |
*/
|
|
|
79 |
$page_heights = PageBreakLocator::getPages($tree,
|
|
|
80 |
mm2pt($media->real_height()),
|
|
|
81 |
mm2pt($media->height() - $media->margins['top']));
|
|
|
82 |
|
|
|
83 |
$first_div = $tree->get_element_by_id('first');
|
|
|
84 |
$second_div = $tree->get_element_by_id('second');
|
|
|
85 |
|
|
|
86 |
$this->assertEqual(count($page_heights), 2,
|
|
|
87 |
sprintf("Two pages expected, got %s",
|
|
|
88 |
count($page_heights)));
|
|
|
89 |
|
|
|
90 |
$this->assertWithinMargin($page_heights[0],
|
|
|
91 |
$first_div->get_full_height() + pt2pt(30),
|
|
|
92 |
0.01);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
// Increased widows value (3)
|
|
|
96 |
function testWidows3() {
|
|
|
97 |
$media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
|
|
|
98 |
array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
|
|
|
99 |
$tree = $this->runPipeline('
|
|
|
100 |
<html>
|
|
|
101 |
<head>
|
|
|
102 |
<style type="text/css">
|
|
|
103 |
body { font-size: 10pt; line-height: 1; padding: 0; margin: 0; widows: 3; }
|
|
|
104 |
#first { line-height: 1; height: 160pt; }
|
|
|
105 |
#second { width: 3em; }
|
|
|
106 |
</style>
|
|
|
107 |
</head>
|
|
|
108 |
<body>
|
|
|
109 |
<div id="first"> </div>
|
|
|
110 |
<div id="second">
|
|
|
111 |
LINE1
|
|
|
112 |
LINE2<!--Page break should be here-->
|
|
|
113 |
LINE3
|
|
|
114 |
LINE4
|
|
|
115 |
LINE5
|
|
|
116 |
</div>
|
|
|
117 |
</body>
|
|
|
118 |
</html>
|
|
|
119 |
', $media);
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Calculate page heights
|
|
|
123 |
*/
|
|
|
124 |
$page_heights = PageBreakLocator::getPages($tree,
|
|
|
125 |
mm2pt($media->real_height()),
|
|
|
126 |
mm2pt($media->height() - $media->margins['top']));
|
|
|
127 |
|
|
|
128 |
$first_div = $tree->get_element_by_id('first');
|
|
|
129 |
$second_div = $tree->get_element_by_id('second');
|
|
|
130 |
|
|
|
131 |
$this->assertEqual(count($page_heights), 2,
|
|
|
132 |
sprintf("Two pages expected, got %s",
|
|
|
133 |
count($page_heights)));
|
|
|
134 |
|
|
|
135 |
$this->assertWithinMargin($page_heights[0],
|
|
|
136 |
$first_div->get_full_height() + pt2pt(20),
|
|
|
137 |
0.01);
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
?>
|