/wp-content/plugins/dk-pdf/vendor/mpdf/mpdf/src/Tag/TextCircle.php

https://github.com/livinglab/openlab · PHP · 250 lines · 225 code · 20 blank · 5 comment · 55 complexity · 8baa02a996d0fb40db80f78139844632 MD5 · raw file

  1. <?php
  2. namespace Mpdf\Tag;
  3. use Mpdf\Mpdf;
  4. use Mpdf\Utils\UtfString;
  5. class TextCircle extends Tag
  6. {
  7. public function open($attr, &$ahtml, &$ihtml)
  8. {
  9. $objattr = [];
  10. $objattr['margin_top'] = 0;
  11. $objattr['margin_bottom'] = 0;
  12. $objattr['margin_left'] = 0;
  13. $objattr['margin_right'] = 0;
  14. $objattr['padding_top'] = 0;
  15. $objattr['padding_bottom'] = 0;
  16. $objattr['padding_left'] = 0;
  17. $objattr['padding_right'] = 0;
  18. $objattr['width'] = 0;
  19. $objattr['height'] = 0;
  20. $objattr['border_top']['w'] = 0;
  21. $objattr['border_bottom']['w'] = 0;
  22. $objattr['border_left']['w'] = 0;
  23. $objattr['border_right']['w'] = 0;
  24. $objattr['top-text'] = '';
  25. $objattr['bottom-text'] = '';
  26. $objattr['r'] = 20; // radius (default value here for safety)
  27. $objattr['space-width'] = 120;
  28. $objattr['char-width'] = 100;
  29. $this->mpdf->InlineProperties['TEXTCIRCLE'] = $this->mpdf->saveInlineProperties();
  30. $properties = $this->cssManager->MergeCSS('INLINE', 'TEXTCIRCLE', $attr);
  31. if (isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY']) === 'none') {
  32. return;
  33. }
  34. if (isset($attr['R'])) {
  35. $objattr['r'] = $this->sizeConverter->convert(
  36. $attr['R'],
  37. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  38. $this->mpdf->FontSize,
  39. false
  40. );
  41. }
  42. if (isset($attr['TOP-TEXT'])) {
  43. $objattr['top-text'] = UtfString::strcode2utf($attr['TOP-TEXT']);
  44. $objattr['top-text'] = $this->mpdf->lesser_entity_decode($objattr['top-text']);
  45. if ($this->mpdf->onlyCoreFonts) {
  46. $objattr['top-text'] = mb_convert_encoding($objattr['top-text'], $this->mpdf->mb_enc, 'UTF-8');
  47. }
  48. }
  49. if (isset($attr['BOTTOM-TEXT'])) {
  50. $objattr['bottom-text'] = UtfString::strcode2utf($attr['BOTTOM-TEXT']);
  51. $objattr['bottom-text'] = $this->mpdf->lesser_entity_decode($objattr['bottom-text']);
  52. if ($this->mpdf->onlyCoreFonts) {
  53. $objattr['bottom-text'] = mb_convert_encoding($objattr['bottom-text'], $this->mpdf->mb_enc, 'UTF-8');
  54. }
  55. }
  56. if (!empty($attr['SPACE-WIDTH'])) {
  57. $objattr['space-width'] = $attr['SPACE-WIDTH'];
  58. }
  59. if (!empty($attr['CHAR-WIDTH'])) {
  60. $objattr['char-width'] = $attr['CHAR-WIDTH'];
  61. }
  62. // VISIBILITY
  63. $objattr['visibility'] = 'visible';
  64. if (isset($properties['VISIBILITY'])) {
  65. $v = strtolower($properties['VISIBILITY']);
  66. if (($v === 'hidden' || $v === 'printonly' || $v === 'screenonly') && $this->mpdf->visibility === 'visible') {
  67. $objattr['visibility'] = $v;
  68. }
  69. }
  70. if (isset($properties['FONT-SIZE'])) {
  71. if (strtolower($properties['FONT-SIZE']) === 'auto') {
  72. if ($objattr['top-text'] && $objattr['bottom-text']) {
  73. $objattr['fontsize'] = -2;
  74. } else {
  75. $objattr['fontsize'] = -1;
  76. }
  77. } else {
  78. $mmsize = $this->sizeConverter->convert($properties['FONT-SIZE'], $this->mpdf->default_font_size / Mpdf::SCALE);
  79. $this->mpdf->SetFontSize($mmsize * Mpdf::SCALE, false);
  80. $objattr['fontsize'] = $this->mpdf->FontSizePt;
  81. }
  82. }
  83. if (isset($attr['DIVIDER'])) {
  84. $objattr['divider'] = UtfString::strcode2utf($attr['DIVIDER']);
  85. $objattr['divider'] = $this->mpdf->lesser_entity_decode($objattr['divider']);
  86. if ($this->mpdf->onlyCoreFonts) {
  87. $objattr['divider'] = mb_convert_encoding($objattr['divider'], $this->mpdf->mb_enc, 'UTF-8');
  88. }
  89. }
  90. if (isset($properties['COLOR'])) {
  91. $objattr['color'] = $this->colorConverter->convert($properties['COLOR'], $this->mpdf->PDFAXwarnings);
  92. }
  93. $objattr['fontstyle'] = '';
  94. if (isset($properties['FONT-WEIGHT'])) {
  95. if (strtoupper($properties['FONT-WEIGHT']) === 'BOLD') {
  96. $objattr['fontstyle'] .= 'B';
  97. }
  98. }
  99. if (isset($properties['FONT-STYLE'])) {
  100. if (strtoupper($properties['FONT-STYLE']) === 'ITALIC') {
  101. $objattr['fontstyle'] .= 'I';
  102. }
  103. }
  104. if (isset($properties['FONT-FAMILY'])) {
  105. $this->mpdf->SetFont($properties['FONT-FAMILY'], $this->mpdf->FontStyle, 0, false);
  106. }
  107. $objattr['fontfamily'] = $this->mpdf->FontFamily;
  108. // VSPACE and HSPACE converted to margins in MergeCSS
  109. if (isset($properties['MARGIN-TOP'])) {
  110. $objattr['margin_top'] = $this->sizeConverter->convert(
  111. $properties['MARGIN-TOP'],
  112. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  113. $this->mpdf->FontSize,
  114. false
  115. );
  116. }
  117. if (isset($properties['MARGIN-BOTTOM'])) {
  118. $objattr['margin_bottom'] = $this->sizeConverter->convert(
  119. $properties['MARGIN-BOTTOM'],
  120. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  121. $this->mpdf->FontSize,
  122. false
  123. );
  124. }
  125. if (isset($properties['MARGIN-LEFT'])) {
  126. $objattr['margin_left'] = $this->sizeConverter->convert(
  127. $properties['MARGIN-LEFT'],
  128. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  129. $this->mpdf->FontSize,
  130. false
  131. );
  132. }
  133. if (isset($properties['MARGIN-RIGHT'])) {
  134. $objattr['margin_right'] = $this->sizeConverter->convert(
  135. $properties['MARGIN-RIGHT'],
  136. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  137. $this->mpdf->FontSize,
  138. false
  139. );
  140. }
  141. if (isset($properties['PADDING-TOP'])) {
  142. $objattr['padding_top'] = $this->sizeConverter->convert(
  143. $properties['PADDING-TOP'],
  144. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  145. $this->mpdf->FontSize,
  146. false
  147. );
  148. }
  149. if (isset($properties['PADDING-BOTTOM'])) {
  150. $objattr['padding_bottom'] = $this->sizeConverter->convert(
  151. $properties['PADDING-BOTTOM'],
  152. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  153. $this->mpdf->FontSize,
  154. false
  155. );
  156. }
  157. if (isset($properties['PADDING-LEFT'])) {
  158. $objattr['padding_left'] = $this->sizeConverter->convert(
  159. $properties['PADDING-LEFT'],
  160. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  161. $this->mpdf->FontSize,
  162. false
  163. );
  164. }
  165. if (isset($properties['PADDING-RIGHT'])) {
  166. $objattr['padding_right'] = $this->sizeConverter->convert(
  167. $properties['PADDING-RIGHT'],
  168. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  169. $this->mpdf->FontSize,
  170. false
  171. );
  172. }
  173. if (isset($properties['BORDER-TOP'])) {
  174. $objattr['border_top'] = $this->mpdf->border_details($properties['BORDER-TOP']);
  175. }
  176. if (isset($properties['BORDER-BOTTOM'])) {
  177. $objattr['border_bottom'] = $this->mpdf->border_details($properties['BORDER-BOTTOM']);
  178. }
  179. if (isset($properties['BORDER-LEFT'])) {
  180. $objattr['border_left'] = $this->mpdf->border_details($properties['BORDER-LEFT']);
  181. }
  182. if (isset($properties['BORDER-RIGHT'])) {
  183. $objattr['border_right'] = $this->mpdf->border_details($properties['BORDER-RIGHT']);
  184. }
  185. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) {
  186. $objattr['opacity'] = $properties['OPACITY'];
  187. }
  188. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') {
  189. $objattr['bgcolor'] = $this->colorConverter->convert($properties['BACKGROUND-COLOR'], $this->mpdf->PDFAXwarnings);
  190. } else {
  191. $objattr['bgcolor'] = false;
  192. }
  193. if ($this->mpdf->HREF) {
  194. if (strpos($this->mpdf->HREF, '.') === false && strpos($this->mpdf->HREF, '@') !== 0) {
  195. $href = $this->mpdf->HREF;
  196. while (array_key_exists($href, $this->mpdf->internallink)) {
  197. $href = '#' . $href;
  198. }
  199. $this->mpdf->internallink[$href] = $this->mpdf->AddLink();
  200. $objattr['link'] = $this->mpdf->internallink[$href];
  201. } else {
  202. $objattr['link'] = $this->mpdf->HREF;
  203. }
  204. }
  205. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  206. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  207. $w = $objattr['r'] * 2;
  208. $h = $w;
  209. $objattr['height'] = $h + $extraheight;
  210. $objattr['width'] = $w + $extrawidth;
  211. $objattr['type'] = 'textcircle';
  212. $e = "\xbb\xa4\xactype=image,objattr=" . serialize($objattr) . "\xbb\xa4\xac";
  213. /* -- TABLES -- */
  214. // Output it to buffers
  215. if ($this->mpdf->tableLevel) {
  216. $this->mpdf->_saveCellTextBuffer($e, $this->mpdf->HREF);
  217. $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] += $objattr['width'];
  218. } else {
  219. /* -- END TABLES -- */
  220. $this->mpdf->_saveTextBuffer($e, $this->mpdf->HREF);
  221. } // *TABLES*
  222. if ($this->mpdf->InlineProperties['TEXTCIRCLE']) {
  223. $this->mpdf->restoreInlineProperties($this->mpdf->InlineProperties['TEXTCIRCLE']);
  224. }
  225. unset($this->mpdf->InlineProperties['TEXTCIRCLE']);
  226. }
  227. public function close(&$ahtml, &$ihtml)
  228. {
  229. }
  230. }