absolute_positioner.cls.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: absolute_positioner.cls.php,v $
  6. * Created on: 2004-06-08
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.dompdf.com/
  32. *
  33. * @link http://www.dompdf.com/
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @package dompdf
  37. */
  38. /* $Id */
  39. /**
  40. * Positions absolutly positioned frames
  41. */
  42. class Absolute_Positioner extends Positioner {
  43. function __construct(Frame_Decorator $frame) { parent::__construct($frame); }
  44. function position() {
  45. $cb = $this->_frame->get_containing_block();
  46. $style = $this->_frame->get_style();
  47. $top = $style->length_in_pt($style->top, $cb["w"]);
  48. $left = $style->length_in_pt($style->left, $cb["w"]);
  49. $right = $style->length_in_pt($style->right, $cb["w"]);
  50. $bottom = $style->length_in_pt($style->bottom, $cb["w"]);
  51. $p = $this->_frame->find_block_parent();
  52. if ( $p ) {
  53. // Get the parent's padding box (see http://www.w3.org/TR/CSS21/visuren.html#propdef-top)
  54. list($x, $y, $w, $h) = $p->get_padding_box();
  55. } else {
  56. $x = $cb["x"];
  57. $y = $cb["y"];
  58. }
  59. if ( isset($top) ) {
  60. $y += $top;
  61. } else if ( isset($bottom) ) {
  62. // FIXME: need to know this frame's height before we can do this correctly
  63. }
  64. $x += $left;
  65. $this->_frame->set_position($x, $y);
  66. }
  67. }