directw

The Gravity PDF directw class.

Defined (1)

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

/vendor/blueliquiddesigns/mpdf/classes/directw.php  
  1. class directw 
  2.  
  3. var $mpdf = null; 
  4.  
  5. public function __construct(mPDF $mpdf) 
  6. $this->mpdf = $mpdf; 
  7.  
  8. function Write($h, $txt, $currentx = 0, $link = '', $directionality = 'ltr', $align = '') 
  9. if (!$align) { 
  10. if ($directionality == 'rtl') { 
  11. $align = 'R'; 
  12. } else { 
  13. $align = 'L'; 
  14. if ($h == 0) { 
  15. $this->mpdf->SetLineHeight(); 
  16. $h = $this->mpdf->lineheight; 
  17. //Output text in flowing mode 
  18. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  19.  
  20. $wmax = ($w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR)); 
  21. $s = str_replace("\r", '', $txt); 
  22. if ($this->mpdf->usingCoreFont) { 
  23. $nb = strlen($s); 
  24. } else { 
  25. $nb = mb_strlen($s, $this->mpdf->mb_enc); 
  26. // handle single space character 
  27. if (($nb == 1) && $s == " ") { 
  28. $this->mpdf->x += $this->mpdf->GetStringWidth($s); 
  29. return; 
  30. $sep = -1; 
  31. $i = 0; 
  32. $j = 0; 
  33. $l = 0; 
  34. $nl = 1; 
  35. if (!$this->mpdf->usingCoreFont) { 
  36. if (preg_match("/([" . $this->mpdf->pregRTLchars . "])/u", $txt)) { 
  37. $this->mpdf->biDirectional = true; 
  38. } // *RTL* 
  39. while ($i < $nb) { 
  40. //Get next character 
  41. $c = mb_substr($s, $i, 1, $this->mpdf->mb_enc); 
  42. if ($c == "\n") { 
  43. // WORD SPACING 
  44. $this->mpdf->ResetSpacing(); 
  45. //Explicit line break 
  46. $tmp = rtrim(mb_substr($s, $j, $i - $j, $this->mpdf->mb_enc)); 
  47. $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); 
  48. $i++; 
  49. $sep = -1; 
  50. $j = $i; 
  51. $l = 0; 
  52. if ($nl == 1) { 
  53. if ($currentx != 0) 
  54. $this->mpdf->x = $currentx; 
  55. else 
  56. $this->mpdf->x = $this->mpdf->lMargin; 
  57. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  58. $wmax = ($w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR)); 
  59. $nl++; 
  60. continue; 
  61. if ($c == " ") { 
  62. $sep = $i; 
  63. $l += $this->mpdf->GetCharWidthNonCore($c); // mPDF 5.3.04 
  64. if ($l > $wmax) { 
  65. //Automatic line break (word wrapping) 
  66. if ($sep == -1) { 
  67. // WORD SPACING 
  68. $this->mpdf->ResetSpacing(); 
  69. if ($this->mpdf->x > $this->mpdf->lMargin) { 
  70. //Move to next line 
  71. if ($currentx != 0) 
  72. $this->mpdf->x = $currentx; 
  73. else 
  74. $this->mpdf->x = $this->mpdf->lMargin; 
  75. $this->mpdf->y+=$h; 
  76. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  77. $wmax = ($w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR)); 
  78. $i++; 
  79. $nl++; 
  80. continue; 
  81. if ($i == $j) { 
  82. $i++; 
  83. $tmp = rtrim(mb_substr($s, $j, $i - $j, $this->mpdf->mb_enc)); 
  84. $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); 
  85. } else { 
  86. $tmp = rtrim(mb_substr($s, $j, $sep - $j, $this->mpdf->mb_enc)); 
  87.  
  88. if ($align == 'J') { 
  89. ////////////////////////////////////////// 
  90. // JUSTIFY J using Unicode fonts (Word spacing doesn't work) 
  91. // WORD SPACING 
  92. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly 
  93. $tmp = str_replace(chr(194) . chr(160), chr(32), $tmp); 
  94. $len_ligne = $this->mpdf->GetStringWidth($tmp); 
  95. $nb_carac = mb_strlen($tmp, $this->mpdf->mb_enc); 
  96. $nb_spaces = mb_substr_count($tmp, ' ', $this->mpdf->mb_enc); 
  97. $inclCursive = false; 
  98. if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) { 
  99. if (preg_match("/([" . $this->mpdf->pregCURSchars . "])/u", $tmp)) { 
  100. $inclCursive = true; 
  101. list($charspacing, $ws) = $this->mpdf->GetJspacing($nb_carac, $nb_spaces, ((($w - 2) - $len_ligne) * _MPDFK), $inclCursive); 
  102. $this->mpdf->SetSpacing($charspacing, $ws); 
  103. ////////////////////////////////////////// 
  104. $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); 
  105. $i = $sep + 1; 
  106. $sep = -1; 
  107. $j = $i; 
  108. $l = 0; 
  109. if ($nl == 1) { 
  110. if ($currentx != 0) 
  111. $this->mpdf->x = $currentx; 
  112. else 
  113. $this->mpdf->x = $this->mpdf->lMargin; 
  114. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  115. $wmax = ($w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR)); 
  116. $nl++; 
  117. else { 
  118. $i++; 
  119. //Last chunk 
  120. // WORD SPACING 
  121. $this->mpdf->ResetSpacing(); 
  122. } else { 
  123. while ($i < $nb) { 
  124. //Get next character 
  125. $c = $s[$i]; 
  126. if ($c == "\n") { 
  127. //Explicit line break 
  128. // WORD SPACING 
  129. $this->mpdf->ResetSpacing(); 
  130. $this->mpdf->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, $align, $fill, $link); 
  131. $i++; 
  132. $sep = -1; 
  133. $j = $i; 
  134. $l = 0; 
  135. if ($nl == 1) { 
  136. if ($currentx != 0) 
  137. $this->mpdf->x = $currentx; 
  138. else 
  139. $this->mpdf->x = $this->mpdf->lMargin; 
  140. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  141. $wmax = $w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR); 
  142. $nl++; 
  143. continue; 
  144. if ($c == " ") { 
  145. $sep = $i; 
  146. $l += $this->mpdf->GetCharWidthCore($c); // mPDF 5.3.04 
  147. if ($l > $wmax) { 
  148. //Automatic line break (word wrapping) 
  149. if ($sep == -1) { 
  150. // WORD SPACING 
  151. $this->mpdf->ResetSpacing(); 
  152. if ($this->mpdf->x > $this->mpdf->lMargin) { 
  153. //Move to next line 
  154. if ($currentx != 0) 
  155. $this->mpdf->x = $currentx; 
  156. else 
  157. $this->mpdf->x = $this->mpdf->lMargin; 
  158. $this->mpdf->y+=$h; 
  159. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  160. $wmax = $w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR); 
  161. $i++; 
  162. $nl++; 
  163. continue; 
  164. if ($i == $j) { 
  165. $i++; 
  166. $this->mpdf->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, $align, $fill, $link); 
  167. } else { 
  168. $tmp = substr($s, $j, $sep - $j); 
  169. if ($align == 'J') { 
  170. ////////////////////////////////////////// 
  171. // JUSTIFY J using Unicode fonts 
  172. // WORD SPACING is not fully supported for complex scripts 
  173. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly 
  174. $tmp = str_replace(chr(160), chr(32), $tmp); 
  175. $len_ligne = $this->mpdf->GetStringWidth($tmp); 
  176. $nb_carac = strlen($tmp); 
  177. $nb_spaces = substr_count($tmp, ' '); 
  178. list($charspacing, $ws) = $this->mpdf->GetJspacing($nb_carac, $nb_spaces, ((($w - 2) - $len_ligne) * _MPDFK), $false); 
  179. $this->mpdf->SetSpacing($charspacing, $ws); 
  180. ////////////////////////////////////////// 
  181. $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); 
  182. $i = $sep + 1; 
  183. $sep = -1; 
  184. $j = $i; 
  185. $l = 0; 
  186. if ($nl == 1) { 
  187. if ($currentx != 0) 
  188. $this->mpdf->x = $currentx; 
  189. else 
  190. $this->mpdf->x = $this->mpdf->lMargin; 
  191. $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x; 
  192. $wmax = $w - ($this->mpdf->cMarginL + $this->mpdf->cMarginR); 
  193. $nl++; 
  194. else { 
  195. $i++; 
  196. // WORD SPACING 
  197. $this->mpdf->ResetSpacing(); 
  198. //Last chunk 
  199. if ($i != $j) { 
  200. if ($currentx != 0) 
  201. $this->mpdf->x = $currentx; 
  202. else 
  203. $this->mpdf->x = $this->mpdf->lMargin; 
  204. if ($this->mpdf->usingCoreFont) { 
  205. $tmp = substr($s, $j, $i - $j); 
  206. } else { 
  207. $tmp = mb_substr($s, $j, $i - $j, $this->mpdf->mb_enc); 
  208. $this->mpdf->Cell($w, $h, $tmp, 0, 0, $align, $fill, $link); 
  209.  
  210. function CircularText($x, $y, $r, $text, $align = 'top', $fontfamily = '', $fontsizePt = 0, $fontstyle = '', $kerning = 120, $fontwidth = 100, $divider = '') 
  211. if ($fontfamily || $fontstyle || $fontsizePt) 
  212. $this->mpdf->SetFont($fontfamily, $fontstyle, $fontsizePt); 
  213. $kerning/=100; 
  214. $fontwidth/=100; 
  215. if ($kerning == 0) 
  216. $this->mpdf->Error('Please use values unequal to zero for kerning (CircularText)'); 
  217. if ($fontwidth == 0) 
  218. $this->mpdf->Error('Please use values unequal to zero for font width (CircularText)'); 
  219. $text = str_replace("\r", '', $text); 
  220. //circumference 
  221. $u = ($r * 2) * M_PI; 
  222. $checking = true; 
  223. $autoset = false; 
  224. while ($checking) { 
  225. $t = 0; 
  226. $w = array(); 
  227. if ($this->mpdf->usingCoreFont) { 
  228. $nb = strlen($text); 
  229. for ($i = 0; $i < $nb; $i++) { 
  230. $w[$i] = $this->mpdf->GetStringWidth($text[$i]); 
  231. $w[$i]*=$kerning * $fontwidth; 
  232. $t+=$w[$i]; 
  233. } else { 
  234. $nb = mb_strlen($text, $this->mpdf->mb_enc); 
  235. $lastchar = ''; 
  236. $unicode = $this->mpdf->UTF8StringToArray($text); 
  237. for ($i = 0; $i < $nb; $i++) { 
  238. $c = mb_substr($text, $i, 1, $this->mpdf->mb_enc); 
  239. $w[$i] = $this->mpdf->GetStringWidth($c); 
  240. $w[$i]*=$kerning * $fontwidth; 
  241. $char = $unicode[$i]; 
  242. if ($this->mpdf->useKerning && $lastchar) { 
  243. if (isset($this->mpdf->CurrentFont['kerninfo'][$lastchar][$char])) { 
  244. $tk = $this->mpdf->CurrentFont['kerninfo'][$lastchar][$char] * ($this->mpdf->FontSize / 1000) * $kerning * $fontwidth; 
  245. $w[$i] += $tk / 2; 
  246. $w[$i - 1] += $tk / 2; 
  247. $t+=$tk; 
  248. $lastchar = $char; 
  249. $t+=$w[$i]; 
  250. if ($fontsizePt >= 0 || $autoset) { 
  251. $checking = false; 
  252. } else { 
  253. $t+=$this->mpdf->GetStringWidth(' '); 
  254. if ($divider) 
  255. $t+=$this->mpdf->GetStringWidth(' '); 
  256. if ($fontsizePt == -2) 
  257. $fontsizePt = $this->mpdf->FontSizePt * 0.5 * $u / $t; 
  258. else 
  259. $fontsizePt = $this->mpdf->FontSizePt * $u / $t; 
  260. $this->mpdf->SetFontSize($fontsizePt); 
  261. $autoset = true; 
  262.  
  263. //total width of string in degrees 
  264. $d = ($t / $u) * 360; 
  265.  
  266. $this->mpdf->StartTransform(); 
  267. // rotate matrix for the first letter to center the text 
  268. // (half of total degrees) 
  269. if ($align == 'top') { 
  270. $this->mpdf->transformRotate(-$d / 2, $x, $y); 
  271. } else { 
  272. $this->mpdf->transformRotate($d / 2, $x, $y); 
  273. //run through the string 
  274. for ($i = 0; $i < $nb; $i++) { 
  275. if ($align == 'top') { 
  276. //rotate matrix half of the width of current letter + half of the width of preceding letter 
  277. if ($i == 0) { 
  278. $this->mpdf->transformRotate((($w[$i] / 2) / $u) * 360, $x, $y); 
  279. } else { 
  280. $this->mpdf->transformRotate((($w[$i] / 2 + $w[$i - 1] / 2) / $u) * 360, $x, $y); 
  281. if ($fontwidth != 1) { 
  282. $this->mpdf->StartTransform(); 
  283. $this->mpdf->transformScale($fontwidth * 100, 100, $x, $y); 
  284. $this->mpdf->SetXY($x - $w[$i] / 2, $y - $r); 
  285. } else { 
  286. //rotate matrix half of the width of current letter + half of the width of preceding letter 
  287. if ($i == 0) { 
  288. $this->mpdf->transformRotate(-(($w[$i] / 2) / $u) * 360, $x, $y); 
  289. } else { 
  290. $this->mpdf->transformRotate(-(($w[$i] / 2 + $w[$i - 1] / 2) / $u) * 360, $x, $y); 
  291. if ($fontwidth != 1) { 
  292. $this->mpdf->StartTransform(); 
  293. $this->mpdf->transformScale($fontwidth * 100, 100, $x, $y); 
  294. $this->mpdf->SetXY($x - $w[$i] / 2, $y + $r - ($this->mpdf->FontSize)); 
  295. if ($this->mpdf->usingCoreFont) { 
  296. $c = $text[$i]; 
  297. } else { 
  298. $c = mb_substr($text, $i, 1, $this->mpdf->mb_enc); 
  299. $this->mpdf->Cell(($w[$i]), $this->mpdf->FontSize, $c, 0, 0, 'C'); // mPDF 5.3.53 
  300. if ($fontwidth != 1) { 
  301. $this->mpdf->StopTransform(); 
  302. $this->mpdf->StopTransform(); 
  303.  
  304. // mPDF 5.5.23 
  305. if ($align == 'top' && $divider != '') { 
  306. $wc = $this->mpdf->GetStringWidth($divider); 
  307. $wc*=$kerning * $fontwidth; 
  308.  
  309. $this->mpdf->StartTransform(); 
  310. $this->mpdf->transformRotate(90, $x, $y); 
  311. $this->mpdf->SetXY($x - $wc / 2, $y - $r); 
  312. $this->mpdf->Cell(($wc), $this->mpdf->FontSize, $divider, 0, 0, 'C'); 
  313. $this->mpdf->StopTransform(); 
  314.  
  315. $this->mpdf->StartTransform(); 
  316. $this->mpdf->transformRotate(-90, $x, $y); 
  317. $this->mpdf->SetXY($x - $wc / 2, $y - $r); 
  318. $this->mpdf->Cell(($wc), $this->mpdf->FontSize, $divider, 0, 0, 'C'); 
  319. $this->mpdf->StopTransform(); 
  320.  
  321. function Shaded_box($text, $font = '', $fontstyle = 'B', $szfont = '', $width = '70%', $style = 'DF', $radius = 2.5, $fill = '#FFFFFF', $color = '#000000', $pad = 2) 
  322. // F (shading - no line), S (line, no shading), DF (both) 
  323. if (!$font) { 
  324. $font = $this->mpdf->default_font; 
  325. if (!$szfont) { 
  326. $szfont = ($this->mpdf->default_font_size * 1.8); 
  327.  
  328. $text = ' ' . $text . ' '; 
  329. $this->mpdf->SetFont($font, $fontstyle, $szfont, false); 
  330.  
  331. $text = $this->mpdf->purify_utf8_text($text); 
  332. if ($this->mpdf->text_input_as_HTML) { 
  333. $text = $this->mpdf->all_entities_to_utf8($text); 
  334. if ($this->mpdf->usingCoreFont) { 
  335. $text = mb_convert_encoding($text, $this->mpdf->mb_enc, 'UTF-8'); 
  336.  
  337.  
  338. // DIRECTIONALITY 
  339. if (preg_match("/([" . $this->mpdf->pregRTLchars . "])/u", $text)) { 
  340. $this->mpdf->biDirectional = true; 
  341. } // *RTL* 
  342.  
  343. $textvar = 0; 
  344. $save_OTLtags = $this->mpdf->OTLtags; 
  345. $this->mpdf->OTLtags = array(); 
  346. if ($this->mpdf->useKerning) { 
  347. if ($this->mpdf->CurrentFont['haskernGPOS']) { 
  348. $this->mpdf->OTLtags['Plus'] .= ' kern'; 
  349. } else { 
  350. $textvar = ($textvar | FC_KERNING); 
  351. // Use OTL OpenType Table Layout - GSUB & GPOS 
  352. if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) { 
  353. $text = $this->mpdf->otl->applyOTL($text, $this->mpdf->CurrentFont['useOTL']); 
  354. $OTLdata = $this->mpdf->otl->OTLdata; 
  355. $this->mpdf->OTLtags = $save_OTLtags; 
  356.  
  357. $this->mpdf->magic_reverse_dir($text, $this->mpdf->directionality, $OTLdata); 
  358.  
  359. if (!$width) { 
  360. $width = $this->mpdf->pgwidth; 
  361. } else { 
  362. $width = $this->mpdf->ConvertSize($width, $this->mpdf->pgwidth); 
  363. $midpt = $this->mpdf->lMargin + ($this->mpdf->pgwidth / 2); 
  364. $r1 = $midpt - ($width / 2); //($this->mpdf->w / 2) - 40; 
  365. $r2 = $r1 + $width; //$r1 + 80; 
  366. $y1 = $this->mpdf->y; 
  367.  
  368.  
  369. $mid = ($r1 + $r2 ) / 2; 
  370. $loop = 0; 
  371.  
  372. while ($loop == 0) { 
  373. $this->mpdf->SetFont($font, $fontstyle, $szfont, false); 
  374. $sz = $this->mpdf->GetStringWidth($text, true, $OTLdata, $textvar); 
  375. if (($r1 + $sz) > $r2) 
  376. $szfont --; 
  377. else 
  378. $loop ++; 
  379. $this->mpdf->SetFont($font, $fontstyle, $szfont, true, true); 
  380.  
  381. $y2 = $this->mpdf->FontSize + ($pad * 2); 
  382.  
  383. $this->mpdf->SetLineWidth(0.1); 
  384. $fc = $this->mpdf->ConvertColor($fill); 
  385. $tc = $this->mpdf->ConvertColor($color); 
  386. $this->mpdf->SetFColor($fc); 
  387. $this->mpdf->SetTColor($tc); 
  388. $this->mpdf->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style); 
  389. $this->mpdf->SetX($r1); 
  390. $this->mpdf->Cell($r2 - $r1, $y2, $text, 0, 1, "C", 0, '', 0, 0, 0, 'M', 0, false, $OTLdata, $textvar); 
  391. $this->mpdf->SetY($y1 + $y2 + 2); // +2 = mm margin below shaded box 
  392. $this->mpdf->Reset(); 
  393.