absolute_positioner.cls.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. */
  8. /**
  9. * Positions absolutely positioned frames
  10. */
  11. class Absolute_Positioner extends Positioner {
  12. function __construct(Frame_Decorator $frame) { parent::__construct($frame); }
  13. function position() {
  14. $frame = $this->_frame;
  15. $style = $frame->get_style();
  16. $p = $frame->find_positionned_parent();
  17. list($x, $y, $w, $h) = $frame->get_containing_block();
  18. $top = $style->length_in_pt($style->top, $h);
  19. $right = $style->length_in_pt($style->right, $w);
  20. $bottom = $style->length_in_pt($style->bottom, $h);
  21. $left = $style->length_in_pt($style->left, $w);
  22. if ( $p && !($left === "auto" && $right === "auto") ) {
  23. // Get the parent's padding box (see http://www.w3.org/TR/CSS21/visuren.html#propdef-top)
  24. list($x, $y, $w, $h) = $p->get_padding_box();
  25. }
  26. list($width, $height) = array($frame->get_margin_width(), $frame->get_margin_height());
  27. $orig_style = $this->_frame->get_original_style();
  28. $orig_width = $orig_style->width;
  29. $orig_height = $orig_style->height;
  30. /****************************
  31. Width auto:
  32. ____________| left=auto | left=fixed |
  33. right=auto | A | B |
  34. right=fixed | C | D |
  35. Width fixed:
  36. ____________| left=auto | left=fixed |
  37. right=auto | E | F |
  38. right=fixed | G | H |
  39. *****************************/
  40. if ( $left === "auto" ) {
  41. if ( $right === "auto" ) {
  42. // A or E - Keep the frame at the same position
  43. }
  44. else {
  45. if ( $orig_width === "auto" ) {
  46. // C
  47. $x += $w - $width - $right;
  48. }
  49. else {
  50. // G
  51. $x += $w - $width - $right;
  52. }
  53. }
  54. }
  55. else {
  56. if ( $right === "auto" ) {
  57. // B or F
  58. $x += $left;
  59. }
  60. else {
  61. if ( $orig_width === "auto" ) {
  62. // D - TODO change width
  63. $x += $left;
  64. }
  65. else {
  66. // H - Everything is fixed: left + width win
  67. $x += $left;
  68. }
  69. }
  70. }
  71. // The same vertically
  72. if ( $top === "auto" ) {
  73. if ( $bottom === "auto" ) {
  74. // A or E - Keep the frame at the same position
  75. $y = $frame->get_parent()->get_current_line_box()->y;
  76. }
  77. else {
  78. if ( $orig_height === "auto" ) {
  79. // C
  80. $y += $h - $height - $bottom;
  81. }
  82. else {
  83. // G
  84. $y += $h - $height - $bottom;
  85. }
  86. }
  87. }
  88. else {
  89. if ( $bottom === "auto" ) {
  90. // B or F
  91. $y += $top;
  92. }
  93. else {
  94. if ( $orig_height === "auto" ) {
  95. // D - TODO change height
  96. $y += $top;
  97. }
  98. else {
  99. // H - Everything is fixed: top + height win
  100. $y += $top;
  101. }
  102. }
  103. }
  104. $frame->set_position($x, $y);
  105. }
  106. }