fixed_positioner.cls.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Fabien Ménager <fabien.menager@gmail.com>
  7. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  8. */
  9. /**
  10. * Positions fixely positioned frames
  11. */
  12. class Fixed_Positioner extends Positioner {
  13. function __construct(Frame_Decorator $frame) { parent::__construct($frame); }
  14. function position() {
  15. $frame = $this->_frame;
  16. $style = $frame->get_original_style();
  17. $root = $frame->get_root();
  18. $initialcb = $root->get_containing_block();
  19. $initialcb_style = $root->get_style();
  20. $p = $frame->find_block_parent();
  21. if ( $p ) {
  22. $p->add_line();
  23. }
  24. // Compute the margins of the @page style
  25. $margin_top = $initialcb_style->length_in_pt($initialcb_style->margin_top, $initialcb["h"]);
  26. $margin_right = $initialcb_style->length_in_pt($initialcb_style->margin_right, $initialcb["w"]);
  27. $margin_bottom = $initialcb_style->length_in_pt($initialcb_style->margin_bottom, $initialcb["h"]);
  28. $margin_left = $initialcb_style->length_in_pt($initialcb_style->margin_left, $initialcb["w"]);
  29. // The needed computed style of the element
  30. $height = $style->length_in_pt($style->height, $initialcb["h"]);
  31. $width = $style->length_in_pt($style->width, $initialcb["w"]);
  32. $top = $style->length_in_pt($style->top, $initialcb["h"]);
  33. $right = $style->length_in_pt($style->right, $initialcb["w"]);
  34. $bottom = $style->length_in_pt($style->bottom, $initialcb["h"]);
  35. $left = $style->length_in_pt($style->left, $initialcb["w"]);
  36. $y = $margin_top;
  37. if ( isset($top) ) {
  38. $y = $top + $margin_top;
  39. if ( $top === "auto" ) {
  40. $y = $margin_top;
  41. if ( isset($bottom) && $bottom !== "auto" ) {
  42. $y = $initialcb["h"] - $bottom - $margin_bottom;
  43. $margin_height = $this->_frame->get_margin_height();
  44. if ( $margin_height !== "auto" ) {
  45. $y -= $margin_height;
  46. }
  47. else {
  48. $y -= $height;
  49. }
  50. }
  51. }
  52. }
  53. $x = $margin_left;
  54. if ( isset($left) ) {
  55. $x = $left + $margin_left;
  56. if ( $left === "auto" ) {
  57. $x = $margin_left;
  58. if ( isset($right) && $right !== "auto" ) {
  59. $x = $initialcb["w"] - $right - $margin_right;
  60. $margin_width = $this->_frame->get_margin_width();
  61. if ( $margin_width !== "auto" ) {
  62. $x -= $margin_width;
  63. }
  64. else {
  65. $x -= $width;
  66. }
  67. }
  68. }
  69. }
  70. $frame->set_position($x, $y);
  71. $children = $frame->get_children();
  72. foreach($children as $child) {
  73. $child->set_position($x, $y);
  74. }
  75. }
  76. }