inline_positioner.cls.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 inline frames
  10. *
  11. * @access private
  12. * @package dompdf
  13. */
  14. class Inline_Positioner extends Positioner {
  15. function __construct(Frame_Decorator $frame) { parent::__construct($frame); }
  16. //........................................................................
  17. function position() {
  18. /**
  19. * Find our nearest block level parent and access its lines property.
  20. * @var Block_Frame_Decorator
  21. */
  22. $p = $this->_frame->find_block_parent();
  23. // Debugging code:
  24. // pre_r("\nPositioning:");
  25. // pre_r("Me: " . $this->_frame->get_node()->nodeName . " (" . spl_object_hash($this->_frame->get_node()) . ")");
  26. // pre_r("Parent: " . $p->get_node()->nodeName . " (" . spl_object_hash($p->get_node()) . ")");
  27. // End debugging
  28. if ( !$p )
  29. throw new DOMPDF_Exception("No block-level parent found. Not good.");
  30. $f = $this->_frame;
  31. $cb = $f->get_containing_block();
  32. $line = $p->get_current_line_box();
  33. // Skip the page break if in a fixed position element
  34. $is_fixed = false;
  35. while($f = $f->get_parent()) {
  36. if($f->get_style()->position === "fixed") {
  37. $is_fixed = true;
  38. break;
  39. }
  40. }
  41. $f = $this->_frame;
  42. if ( !$is_fixed && $f->get_parent() &&
  43. $f->get_parent() instanceof Inline_Frame_Decorator &&
  44. $f->is_text_node() ) {
  45. $min_max = $f->get_reflower()->get_min_max_width();
  46. // If the frame doesn't fit in the current line, a line break occurs
  47. if ( $min_max["min"] > ($cb["w"] - $line->left - $line->w - $line->right) ) {
  48. $p->add_line();
  49. }
  50. }
  51. $f->set_position($cb["x"] + $line->w, $line->y);
  52. }
  53. }