List_Bullet_Image_Frame_Decorator

Decorates frames for list bullets with custom images.

Defined (1)

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

/lib/dompdf/include/list_bullet_image_frame_decorator.cls.php  
  1. class List_Bullet_Image_Frame_Decorator extends Frame_Decorator { 
  2.  
  3. /** 
  4. * The underlying image frame 
  5. *  
  6. * @var Image_Frame_Decorator 
  7. */ 
  8. protected $_img; 
  9.  
  10. /** 
  11. * The image's width in pixels 
  12. * @var int 
  13. */ 
  14. protected $_width; 
  15.  
  16. /** 
  17. * The image's height in pixels 
  18. * @var int 
  19. */ 
  20. protected $_height; 
  21.  
  22. /** 
  23. * Class constructor 
  24. * @param Frame $frame the bullet frame to decorate 
  25. * @param DOMPDF $dompdf the document's dompdf object 
  26. */ 
  27. function __construct(Frame $frame, DOMPDF $dompdf) { 
  28. $style = $frame->get_style(); 
  29. $url = $style->list_style_image; 
  30. $frame->get_node()->setAttribute("src", $url); 
  31. $this->_img = new Image_Frame_Decorator($frame, $dompdf); 
  32. parent::__construct($this->_img, $dompdf); 
  33. list($width, $height) = dompdf_getimagesize($this->_img->get_image_url()); 
  34.  
  35. // Resample the bullet image to be consistent with 'auto' sized images 
  36. // See also Image_Frame_Reflower::get_min_max_width 
  37. // Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary. 
  38. $dpi = $this->_dompdf->get_option("dpi"); 
  39. $this->_width = ((float)rtrim($width, "px") * 72) / $dpi; 
  40. $this->_height = ((float)rtrim($height, "px") * 72) / $dpi; 
  41.  
  42. //If an image is taller as the containing block/box, the box should be extended. 
  43. //Neighbour elements are overwriting the overlapping image areas. 
  44. //Todo: Where can the box size be extended?  
  45. //Code below has no effect. 
  46. //See block_frame_reflower _calculate_restricted_height 
  47. //See generated_frame_reflower, Dompdf:render() "list-item", "-dompdf-list-bullet"S. 
  48. //Leave for now  
  49. //if ($style->min_height < $this->_height ) { 
  50. // $style->min_height = $this->_height; 
  51. //} 
  52. //$style->height = "auto";  
  53.  
  54. /** 
  55. * Return the bullet's width 
  56. * @return int 
  57. */ 
  58. function get_width() { 
  59. //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator 
  60. //for proper alignment of bullet image and text. Allow image to not fitting on left border. 
  61. //This controls the distance between bullet image and text  
  62. //return $this->_width; 
  63. return $this->_frame->get_style()->get_font_size()*List_Bullet_Frame_Decorator::BULLET_SIZE +  
  64. 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; 
  65.  
  66. /** 
  67. * Return the bullet's height 
  68. * @return int 
  69. */ 
  70. function get_height() { 
  71. //based on image height 
  72. return $this->_height; 
  73.  
  74. /** 
  75. * Override get_margin_width 
  76. * @return int 
  77. */ 
  78. function get_margin_width() { 
  79. //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator 
  80. //for proper alignment of bullet image and text. Allow image to not fitting on left border. 
  81. //This controls the extra indentation of text to make room for the bullet image. 
  82. //Here use actual image size, not predefined bullet size  
  83. //return $this->_frame->get_style()->get_font_size()*List_Bullet_Frame_Decorator::BULLET_SIZE +  
  84. // 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; 
  85.  
  86. // Small hack to prevent indenting of list text 
  87. // Image Might not exist, then position like on list_bullet_frame_decorator fallback to none.  
  88. if ( $this->_frame->get_style()->list_style_position === "outside" || 
  89. $this->_width == 0)  
  90. return 0; 
  91. //This aligns the "inside" image position with the text. 
  92. //The text starts to the right of the image. 
  93. //Between the image and the text there is an added margin of image width. 
  94. //Where this comes from is unknown. 
  95. //The corresponding List_Bullet_Frame_Decorator sets a smaller margin. bullet size? 
  96. return $this->_width + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; 
  97.  
  98. /** 
  99. * Override get_margin_height() 
  100. * @return int 
  101. */ 
  102. function get_margin_height() { 
  103. //Hits only on "inset" lists items, to increase height of box 
  104. //based on image height 
  105. return $this->_height + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; 
  106.  
  107. /** 
  108. * Return image url 
  109. * @return string 
  110. */ 
  111. function get_image_url() { 
  112. return $this->_img->get_image_url(); 
  113.