Blame view

dompdf/src/FrameDecorator/Inline.php 2.55 KB
670b6d6f8   tuan   2016/09/22 - Copy...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  <?php
  /**
   * @package dompdf
   * @link    http://dompdf.github.com/
   * @author  Benj Carson <benjcarson@digitaljunkies.ca>
   * @author  Helmut Tischer <htischer@weihenstephan.org>
   * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
   */
  namespace Dompdf\FrameDecorator;
  
  use Dompdf\Dompdf;
  use Dompdf\Frame;
  use Dompdf\Exception;
  
  /**
   * Decorates frames for inline layout
   *
   * @access  private
   * @package dompdf
   */
  class Inline extends AbstractFrameDecorator
  {
  
      function __construct(Frame $frame, Dompdf $dompdf)
      {
          parent::__construct($frame, $dompdf);
      }
  
      function split(Frame $frame = null, $force_pagebreak = false)
      {
  
          if (is_null($frame)) {
              $this->get_parent()->split($this, $force_pagebreak);
              return;
          }
  
          if ($frame->get_parent() !== $this) {
              throw new Exception("Unable to split: frame is not a child of this one.");
          }
  
          $split = $this->copy($this->_frame->get_node()->cloneNode());
          $this->get_parent()->insert_child_after($split, $this);
  
          // Unset the current node's right style properties
          $style = $this->_frame->get_style();
          $style->margin_right = 0;
          $style->padding_right = 0;
          $style->border_right_width = 0;
  
          // Unset the split node's left style properties since we don't want them
          // to propagate
          $style = $split->get_style();
          $style->margin_left = 0;
          $style->padding_left = 0;
          $style->border_left_width = 0;
  
          //On continuation of inline element on next line,
          //don't repeat non-vertically repeatble background images
          //See e.g. in testcase image_variants, long desriptions
          if (($url = $style->background_image) && $url !== "none"
              && ($repeat = $style->background_repeat) && $repeat !== "repeat" && $repeat !== "repeat-y"
          ) {
              $style->background_image = "none";
          }
  
          // Add $frame and all following siblings to the new split node
          $iter = $frame;
          while ($iter) {
              $frame = $iter;
              $iter = $iter->get_next_sibling();
              $frame->reset();
              $split->append_child($frame);
          }
  
          $page_breaks = array("always", "left", "right");
          $frame_style = $frame->get_style();
          if ($force_pagebreak ||
              in_array($frame_style->page_break_before, $page_breaks) ||
              in_array($frame_style->page_break_after, $page_breaks)
          ) {
  
              $this->get_parent()->split($split, true);
          }
      }
  
  }