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