Image_Frame_Reflower

Image reflower class.

Defined (1)

The class is defined in the following location(s).

/lib/dompdf/include/image_frame_reflower.cls.php  
  1. class Image_Frame_Reflower extends Frame_Reflower { 
  2.  
  3. function __construct(Image_Frame_Decorator $frame) { 
  4. parent::__construct($frame); 
  5.  
  6. function reflow(Block_Frame_Decorator $block = null) { 
  7. $this->_frame->position(); 
  8.  
  9. //FLOAT 
  10. //$frame = $this->_frame; 
  11. //$page = $frame->get_root(); 
  12.  
  13. //$enable_css_float = $this->get_dompdf()->get_option("enable_css_float"); 
  14. //if ($enable_css_float && $frame->get_style()->float !== "none" ) { 
  15. // $page->add_floating_frame($this); 
  16. //} 
  17. // Set the frame's width 
  18. $this->get_min_max_width(); 
  19.  
  20. if ( $block ) { 
  21. $block->add_frame_to_line($this->_frame); 
  22.  
  23. function get_min_max_width() { 
  24. if (DEBUGPNG) { 
  25. // Determine the image's size. Time consuming. Only when really needed? 
  26. list($img_width, $img_height) = dompdf_getimagesize($this->_frame->get_image_url()); 
  27. print "get_min_max_width() ". 
  28. $this->_frame->get_style()->width.' '. 
  29. $this->_frame->get_style()->height.';'. 
  30. $this->_frame->get_parent()->get_style()->width." ". 
  31. $this->_frame->get_parent()->get_style()->height.";". 
  32. $this->_frame->get_parent()->get_parent()->get_style()->width.' '. 
  33. $this->_frame->get_parent()->get_parent()->get_style()->height.';'. 
  34. $img_width. ' '. 
  35. $img_height.'|' ; 
  36.  
  37. $style = $this->_frame->get_style(); 
  38.  
  39. $width_forced = true; 
  40. $height_forced = true; 
  41.  
  42. //own style auto or invalid value: use natural size in px 
  43. //own style value: ignore suffix text including unit, use given number as px 
  44. //own style %: walk up parent chain until found available space in pt; fill available space 
  45. // 
  46. //special ignored unit: e.g. 10ex: e treated as exponent; x ignored; 10e completely invalid ->like auto 
  47.  
  48. $width = ($style->width > 0 ? $style->width : 0); 
  49. if ( is_percent($width) ) { 
  50. $t = 0.0; 
  51. for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) { 
  52. $f_style = $f->get_style(); 
  53. $t = $f_style->length_in_pt($f_style->width); 
  54. if ($t != 0) { 
  55. break; 
  56. $width = ((float)rtrim($width, "%") * $t)/100; //maybe 0 
  57. } elseif ( !mb_strpos($width, 'pt') ) { 
  58. // Don't set image original size if "%" branch was 0 or size not given. 
  59. // Otherwise aspect changed on %/auto combination for width/height 
  60. // Resample according to px per inch 
  61. // See also List_Bullet_Image_Frame_Decorator::__construct 
  62. $width = $style->length_in_pt($width); 
  63.  
  64. $height = ($style->height > 0 ? $style->height : 0); 
  65. if ( is_percent($height) ) { 
  66. $t = 0.0; 
  67. for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) { 
  68. $f_style = $f->get_style(); 
  69. $t = $f_style->length_in_pt($f_style->height); 
  70. if ($t != 0) { 
  71. break; 
  72. $height = ((float)rtrim($height, "%") * $t)/100; //maybe 0 
  73. } elseif ( !mb_strpos($height, 'pt') ) { 
  74. // Don't set image original size if "%" branch was 0 or size not given. 
  75. // Otherwise aspect changed on %/auto combination for width/height 
  76. // Resample according to px per inch 
  77. // See also List_Bullet_Image_Frame_Decorator::__construct 
  78. $height = $style->length_in_pt($height); 
  79.  
  80. if ($width == 0 || $height == 0) { 
  81. // Determine the image's size. Time consuming. Only when really needed! 
  82. list($img_width, $img_height) = dompdf_getimagesize($this->_frame->get_image_url()); 
  83.  
  84. // don't treat 0 as error. Can be downscaled or can be catched elsewhere if image not readable. 
  85. // Resample according to px per inch 
  86. // See also List_Bullet_Image_Frame_Decorator::__construct 
  87. if ($width == 0 && $height == 0) { 
  88. $dpi = $this->_frame->get_dompdf()->get_option("dpi"); 
  89. $width = (float)($img_width * 72) / $dpi; 
  90. $height = (float)($img_height * 72) / $dpi; 
  91. $width_forced = false; 
  92. $height_forced = false; 
  93. } elseif ($height == 0 && $width != 0) { 
  94. $height_forced = false; 
  95. $height = ($width / $img_width) * $img_height; //keep aspect ratio 
  96. } elseif ($width == 0 && $height != 0) { 
  97. $width_forced = false; 
  98. $width = ($height / $img_height) * $img_width; //keep aspect ratio 
  99.  
  100. // Handle min/max width/height 
  101. if ( $style->min_width !== "none" ||  
  102. $style->max_width !== "none" ||  
  103. $style->min_height !== "none" ||  
  104. $style->max_height !== "none" ) { 
  105.  
  106. list(/**$x*/, /**$y*/, $w, $h) = $this->_frame->get_containing_block(); 
  107.  
  108. $min_width = $style->length_in_pt($style->min_width, $w); 
  109. $max_width = $style->length_in_pt($style->max_width, $w); 
  110. $min_height = $style->length_in_pt($style->min_height, $h); 
  111. $max_height = $style->length_in_pt($style->max_height, $h); 
  112.  
  113. if ( $max_width !== "none" && $width > $max_width ) { 
  114. if ( !$height_forced ) { 
  115. $height *= $max_width / $width; 
  116.  
  117. $width = $max_width; 
  118.  
  119. if ( $min_width !== "none" && $width < $min_width ) { 
  120. if ( !$height_forced ) { 
  121. $height *= $min_width / $width; 
  122.  
  123. $width = $min_width; 
  124.  
  125. if ( $max_height !== "none" && $height > $max_height ) { 
  126. if ( !$width_forced ) { 
  127. $width *= $max_height / $height; 
  128.  
  129. $height = $max_height; 
  130.  
  131. if ( $min_height !== "none" && $height < $min_height ) { 
  132. if ( !$width_forced ) { 
  133. $width *= $min_height / $height; 
  134.  
  135. $height = $min_height; 
  136.  
  137. if (DEBUGPNG) print $width.' '.$height.';'; 
  138.  
  139. $style->width = $width . "pt"; 
  140. $style->height = $height . "pt"; 
  141.  
  142. $style->min_width = "none"; 
  143. $style->max_width = "none"; 
  144. $style->min_height = "none"; 
  145. $style->max_height = "none"; 
  146.  
  147. return array( $width, $width, "min" => $width, "max" => $width); 
  148.