composer package updates
[openemr.git] / vendor / dompdf / dompdf / src / Positioner / Absolute.php
blob30dac509a9a190ce9e793aa5b28fe9a8991edd89
1 <?php
2 /**
3 * @package dompdf
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
7 */
9 namespace Dompdf\Positioner;
11 use Dompdf\FrameDecorator\AbstractFrameDecorator;
13 /**
14 * Positions absolutely positioned frames
16 class Absolute extends AbstractPositioner
19 /**
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 /****************************
48 * Width auto:
49 * ____________| left=auto | left=fixed |
50 * right=auto | A | B |
51 * right=fixed | C | D |
53 * Width fixed:
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;
63 } else {
64 if ($orig_width === "auto") {
65 // C
66 $x += $w - $width - $right;
67 } else {
68 // G
69 $x += $w - $width - $right;
72 } else {
73 if ($right === "auto") {
74 // B or F
75 $x += (float)$left;
76 } else {
77 if ($orig_width === "auto") {
78 // D - TODO change width
79 $x += (float)$left;
80 } else {
81 // H - Everything is fixed: left + width win
82 $x += (float)$left;
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;
92 } else {
93 if ($orig_height === "auto") {
94 // C
95 $y += (float)$h - $height - (float)$bottom;
96 } else {
97 // G
98 $y += (float)$h - $height - (float)$bottom;
101 } else {
102 if ($bottom === "auto") {
103 // B or F
104 $y += (float)$top;
105 } else {
106 if ($orig_height === "auto") {
107 // D - TODO change height
108 $y += (float)$top;
109 } else {
110 // H - Everything is fixed: top + height win
111 $y += (float)$top;
116 $frame->set_position($x, $y);