| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Header: /cvsroot/html2ps/css.vertical-align.inc.php,v 1.23 2006/09/07 18:38:14 Konstantin Exp $
|
|
|
3 |
|
|
|
4 |
define('VA_SUPER' ,0);
|
|
|
5 |
define('VA_SUB' ,1);
|
|
|
6 |
define('VA_TOP' ,2);
|
|
|
7 |
define('VA_MIDDLE' ,3);
|
|
|
8 |
define('VA_BOTTOM' ,4);
|
|
|
9 |
define('VA_BASELINE' ,5);
|
|
|
10 |
define('VA_TEXT_TOP' ,6);
|
|
|
11 |
define('VA_TEXT_BOTTOM',7);
|
|
|
12 |
|
|
|
13 |
class VerticalAlignSuper {
|
|
|
14 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
15 |
return; // Do nothing
|
|
|
16 |
}
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
class VerticalAlignSub {
|
|
|
20 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
21 |
return; // Do nothing
|
|
|
22 |
}
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
class VerticalAlignTop {
|
|
|
26 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
27 |
return; // Do nothing
|
|
|
28 |
}
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
class VerticalAlignMiddle {
|
|
|
32 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
33 |
$delta = max(0, ($row_height - $cell->get_real_full_height()) / 2);
|
|
|
34 |
|
|
|
35 |
$old_top = $cell->get_top();
|
|
|
36 |
$cell->offset(0, -$delta);
|
|
|
37 |
$cell->put_top($old_top);
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
class VerticalAlignBottom {
|
|
|
42 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
43 |
$delta = ($row_height - $cell->get_real_full_height());
|
|
|
44 |
|
|
|
45 |
$old_top = $cell->get_top();
|
|
|
46 |
$cell->offset(0, -$delta);
|
|
|
47 |
$cell->put_top($old_top);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
class VerticalAlignBaseline {
|
|
|
52 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
53 |
$delta = ($row_baseline - $cell->get_cell_baseline());
|
|
|
54 |
|
|
|
55 |
$old_top = $cell->get_top();
|
|
|
56 |
$cell->offset(0, -$delta);
|
|
|
57 |
$cell->put_top($old_top);
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
class VerticalAlignTextTop {
|
|
|
62 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
63 |
return; // Do nothing
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
class VerticalAlignTextBottom {
|
|
|
68 |
function apply_cell(&$cell, $row_height, $row_baseline) {
|
|
|
69 |
$delta = ($row_baseline - $cell->get_cell_baseline());
|
|
|
70 |
|
|
|
71 |
$old_top = $cell->get_top();
|
|
|
72 |
$cell->offset(0, -$delta);
|
|
|
73 |
$cell->put_top($old_top);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
class CSSVerticalAlign extends CSSPropertyHandler {
|
|
|
78 |
function CSSVerticalAlign() {
|
|
|
79 |
// Note that in general, parameters 'true' and 'false' are non meaningful in out case,
|
|
|
80 |
// as we anyway override 'inherit' and 'inherit_text' in this class.
|
|
|
81 |
$this->CSSPropertyHandler(true, true);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
function inherit($old_state, &$new_state) {
|
|
|
85 |
// Determine parent 'display' value
|
|
|
86 |
$parent_display = $old_state[CSS_DISPLAY];
|
|
|
87 |
|
|
|
88 |
// Inherit vertical-align from table-rows
|
|
|
89 |
if ($parent_display === "table-row") {
|
|
|
90 |
$this->replace_array($this->get($old_state),
|
|
|
91 |
$new_state);
|
|
|
92 |
return;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
if (is_inline_element($parent_display)) {
|
|
|
96 |
$this->replace_array($this->get($old_state), $new_state);
|
|
|
97 |
return;
|
|
|
98 |
};
|
|
|
99 |
|
|
|
100 |
$this->replace_array($this->default_value(), $new_state);
|
|
|
101 |
return;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
function inherit_text($old_state, &$new_state) {
|
|
|
105 |
// Determine parent 'display' value
|
|
|
106 |
$parent_display = $old_state[CSS_DISPLAY];
|
|
|
107 |
|
|
|
108 |
$this->replace_array(is_inline_element($parent_display) ? $this->get($old_state) : $this->default_value(),
|
|
|
109 |
$new_state);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
function default_value() { return VA_BASELINE; }
|
|
|
113 |
|
|
|
114 |
function parse($value) {
|
|
|
115 |
if ($value === 'inherit') {
|
|
|
116 |
return CSS_PROPERTY_INHERIT;
|
|
|
117 |
};
|
|
|
118 |
|
|
|
119 |
// Convert value to lower case, as html allows values
|
|
|
120 |
// in both cases to be entered
|
|
|
121 |
$value = strtolower($value);
|
|
|
122 |
|
|
|
123 |
if ($value === 'baseline') { return VA_BASELINE; };
|
|
|
124 |
if ($value === 'sub') { return VA_SUB; };
|
|
|
125 |
if ($value === 'super') { return VA_SUPER; };
|
|
|
126 |
if ($value === 'top') { return VA_TOP; };
|
|
|
127 |
if ($value === 'middle') { return VA_MIDDLE; };
|
|
|
128 |
|
|
|
129 |
// As some brainless designers sometimes use 'center' instead of 'middle',
|
|
|
130 |
// we'll add support for it
|
|
|
131 |
if ($value === 'center') { return VA_MIDDLE; }
|
|
|
132 |
|
|
|
133 |
if ($value === 'bottom') { return VA_BOTTOM; };
|
|
|
134 |
if ($value === 'text-top') { return VA_TEXT_TOP; };
|
|
|
135 |
if ($value === 'text-bottom') { return VA_TEXT_BOTTOM; };
|
|
|
136 |
return $this->default_value();
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
function value2pdf($value) {
|
|
|
140 |
if ($value === VA_SUPER) { return new VerticalAlignSuper; }
|
|
|
141 |
if ($value === VA_SUB) { return new VerticalAlignSub; }
|
|
|
142 |
if ($value === VA_TOP) { return new VerticalAlignTop; }
|
|
|
143 |
if ($value === VA_MIDDLE) { return new VerticalAlignMiddle; }
|
|
|
144 |
if ($value === VA_BOTTOM) { return new VerticalAlignBottom; }
|
|
|
145 |
if ($value === VA_BASELINE) { return new VerticalAlignBaseline; }
|
|
|
146 |
if ($value === VA_TEXT_TOP) { return new VerticalAlignTextTop; }
|
|
|
147 |
if ($value === VA_TEXT_BOTTOM) { return new VerticalAlignTextBottom; }
|
|
|
148 |
return new VerticalAlignBaseline;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
function applicable($css_state) {
|
|
|
152 |
$handler =& CSS::get_handler(CSS_DISPLAY);
|
|
|
153 |
$display = $handler->get($css_state->getState());
|
|
|
154 |
return
|
|
|
155 |
$display === 'table-cell' ||
|
|
|
156 |
$display === 'table-row' ||
|
|
|
157 |
is_inline_element($display);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
function get_property_code() {
|
|
|
161 |
return CSS_VERTICAL_ALIGN;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
function get_property_name() {
|
|
|
165 |
return 'vertical-align';
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
CSS::register_css_property(new CSSVerticalAlign);
|
|
|
170 |
|
|
|
171 |
?>
|