Blame view

sources/3rdparty/dompdf/include/image_frame_reflower.cls.php 4.51 KB
31b7f2792   Kload   Upgrade to ownclo...
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  <?php
  /**
   * @package dompdf
   * @link    http://www.dompdf.com/
   * @author  Benj Carson <benjcarson@digitaljunkies.ca>
   * @author  Fabien Ménager <fabien.menager@gmail.com>
   * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
   * @version $Id: image_frame_reflower.cls.php 448 2011-11-13 13:00:03Z fabien.menager $
   */
  
  /**
   * Image reflower class
   *
   * @access private
   * @package dompdf
   */
  class Image_Frame_Reflower extends Frame_Reflower {
  
    function __construct(Image_Frame_Decorator $frame) {
      parent::__construct($frame);
    }
  
    function reflow(Frame_Decorator $block = null) {
      $this->_frame->position();
      
      //FLOAT
      //$frame = $this->_frame;
      //$page = $frame->get_root();
      //if (DOMPDF_ENABLE_CSS_FLOAT && $frame->get_style()->float !== "none" ) {
      //  $page->add_floating_frame($this);
      //}
      // Set the frame's width
      $this->get_min_max_width();
      
      if ( $block ) {
        $block->add_frame_to_line($this->_frame);
      }
    }
  
    function get_min_max_width() {
      if (DEBUGPNG) {
        // Determine the image's size. Time consuming. Only when really needed?
        list($img_width, $img_height) = dompdf_getimagesize($this->_frame->get_image_url());
        print "get_min_max_width() ".
          $this->_frame->get_style()->width.' '.
          $this->_frame->get_style()->height.';'.
          $this->_frame->get_parent()->get_style()->width." ".
          $this->_frame->get_parent()->get_style()->height.";".
          $this->_frame->get_parent()->get_parent()->get_style()->width.' '.
          $this->_frame->get_parent()->get_parent()->get_style()->height.';'.
          $img_width. ' '.
          $img_height.'|' ;
      }
  
      $style = $this->_frame->get_style();
  
      //own style auto or invalid value: use natural size in px
      //own style value: ignore suffix text including unit, use given number as px
      //own style %: walk up parent chain until found available space in pt; fill available space
      //
      //special ignored unit: e.g. 10ex: e treated as exponent; x ignored; 10e completely invalid ->like auto
  
      $width = ($style->width > 0 ? $style->width : 0);
      if ( is_percent($width) ) {
        $t = 0.0;
        for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) {
          $f_style = $f->get_style();
          $t = $f_style->length_in_pt($f_style->width);
          if ($t != 0) {
            break;
          }
        }
        $width = ((float)rtrim($width,"%") * $t)/100; //maybe 0
      } elseif ( !mb_strpos($width, 'pt') ) {
        // Don't set image original size if "%" branch was 0 or size not given.
        // Otherwise aspect changed on %/auto combination for width/height
        // Resample according to px per inch
        // See also List_Bullet_Image_Frame_Decorator::__construct
        $width = $style->length_in_pt($width);
      }
  
      $height = ($style->height > 0 ? $style->height : 0);
      if ( is_percent($height) ) {
        $t = 0.0;
        for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) {
          $f_style = $f->get_style();
          $t = $f_style->length_in_pt($f_style->height);
          if ($t != 0) {
            break;
          }
        }
        $height = ((float)rtrim($height,"%") * $t)/100; //maybe 0
      } elseif ( !mb_strpos($height, 'pt') ) {
        // Don't set image original size if "%" branch was 0 or size not given.
        // Otherwise aspect changed on %/auto combination for width/height
        // Resample according to px per inch
        // See also List_Bullet_Image_Frame_Decorator::__construct
        $height = $style->length_in_pt($height);
      }
  
      if ($width == 0 || $height == 0) {
        // Determine the image's size. Time consuming. Only when really needed!
        list($img_width, $img_height) = dompdf_getimagesize($this->_frame->get_image_url());
        
        // don't treat 0 as error. Can be downscaled or can be catched elsewhere if image not readable.
        // Resample according to px per inch
        // See also List_Bullet_Image_Frame_Decorator::__construct
        if ($width == 0 && $height == 0) {
          $width = (float)($img_width * 72) / DOMPDF_DPI;
          $height = (float)($img_height * 72) / DOMPDF_DPI;
        } elseif ($height == 0 && $width != 0) {
          $height = ($width / $img_width) * $img_height; //keep aspect ratio
        } elseif ($width == 0 && $height != 0) {
          $width = ($height / $img_height) * $img_width; //keep aspect ratio
        }
      }
  
      if (DEBUGPNG) print $width.' '.$height.';';
  
      $style->width = $width . "pt";
      $style->height = $height . "pt";
  
      return array( $width, $width, "min" => $width, "max" => $width);
      
    }
  }