/vendor/dompdf/dompdf/include/list_bullet_image_frame_decorator.cls.php

https://gitlab.com/techniconline/kmc · PHP · 151 lines · 44 code · 14 blank · 93 comment · 2 complexity · 6906fef75f71ff0ea527774e708ec549 MD5 · raw file

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