暂无描述

absolute_positioner.cls.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. $x = $x + $frame->find_block_parent()->get_current_line_box()->w;
  44. }
  45. else {
  46. if ( $orig_width === "auto" ) {
  47. // C
  48. $x += $w - $width - $right;
  49. }
  50. else {
  51. // G
  52. $x += $w - $width - $right;
  53. }
  54. }
  55. }
  56. else {
  57. if ( $right === "auto" ) {
  58. // B or F
  59. $x += $left;
  60. }
  61. else {
  62. if ( $orig_width === "auto" ) {
  63. // D - TODO change width
  64. $x += $left;
  65. }
  66. else {
  67. // H - Everything is fixed: left + width win
  68. $x += $left;
  69. }
  70. }
  71. }
  72. // The same vertically
  73. if ( $top === "auto" ) {
  74. if ( $bottom === "auto" ) {
  75. // A or E - Keep the frame at the same position
  76. $y = $frame->find_block_parent()->get_current_line_box()->y;
  77. }
  78. else {
  79. if ( $orig_height === "auto" ) {
  80. // C
  81. $y += $h - $height - $bottom;
  82. }
  83. else {
  84. // G
  85. $y += $h - $height - $bottom;
  86. }
  87. }
  88. }
  89. else {
  90. if ( $bottom === "auto" ) {
  91. // B or F
  92. $y += $top;
  93. }
  94. else {
  95. if ( $orig_height === "auto" ) {
  96. // D - TODO change height
  97. $y += $top;
  98. }
  99. else {
  100. // H - Everything is fixed: top + height win
  101. $y += $top;
  102. }
  103. }
  104. }
  105. $frame->set_position($x, $y);
  106. }
  107. }