4 * @link http://dompdf.github.com/
5 * @author Benj Carson <benjcarson@digitaljunkies.ca>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
9 namespace Dompdf\Positioner
;
11 use Dompdf\FrameDecorator\AbstractFrameDecorator
;
14 * Positions absolutely positioned frames
16 class Absolute
extends AbstractPositioner
20 * @param AbstractFrameDecorator $frame
22 function position(AbstractFrameDecorator
$frame)
24 $style = $frame->get_style();
26 $p = $frame->find_positionned_parent();
28 list($x, $y, $w, $h) = $frame->get_containing_block();
30 $top = $style->length_in_pt($style->top
, $h);
31 $right = $style->length_in_pt($style->right
, $w);
32 $bottom = $style->length_in_pt($style->bottom
, $h);
33 $left = $style->length_in_pt($style->left
, $w);
35 if ($p && !($left === "auto" && $right === "auto")) {
36 // Get the parent's padding box (see http://www.w3.org/TR/CSS21/visuren.html#propdef-top)
37 list($x, $y, $w, $h) = $p->get_padding_box();
40 list($width, $height) = array($frame->get_margin_width(), $frame->get_margin_height());
42 $orig_style = $frame->get_original_style();
43 $orig_width = $orig_style->width
;
44 $orig_height = $orig_style->height
;
46 /****************************
49 * ____________| left=auto | left=fixed |
50 * right=auto | A | B |
51 * right=fixed | C | D |
54 * ____________| left=auto | left=fixed |
55 * right=auto | E | F |
56 * right=fixed | G | H |
57 *****************************/
59 if ($left === "auto") {
60 if ($right === "auto") {
61 // A or E - Keep the frame at the same position
62 $x = $x +
$frame->find_block_parent()->get_current_line_box()->w
;
64 if ($orig_width === "auto") {
66 $x +
= $w - $width - $right;
69 $x +
= $w - $width - $right;
73 if ($right === "auto") {
77 if ($orig_width === "auto") {
78 // D - TODO change width
81 // H - Everything is fixed: left + width win
87 // The same vertically
88 if ($top === "auto") {
89 if ($bottom === "auto") {
90 // A or E - Keep the frame at the same position
91 $y = $frame->find_block_parent()->get_current_line_box()->y
;
93 if ($orig_height === "auto") {
95 $y +
= (float)$h - $height - (float)$bottom;
98 $y +
= (float)$h - $height - (float)$bottom;
102 if ($bottom === "auto") {
106 if ($orig_height === "auto") {
107 // D - TODO change height
110 // H - Everything is fixed: top + height win
116 $frame->set_position($x, $y);