]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/classes/directw.php
7 function directw(&$mpdf) {
12 function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
14 if ($directionality=='rtl') { $align
= 'R'; }
15 else { $align
= 'L'; }
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
;
21 $wmax = ($w - ($this->mpdf
->cMarginL+
$this->mpdf
->cMarginR
));
22 $s=str_replace("\r",'',$txt);
23 if ($this->mpdf
->usingCoreFont
) { $nb
=strlen($s
); }
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);
37 if (!$this->mpdf
->usingCoreFont
) {
38 if (preg_match("/([".$this->mpdf
->pregRTLchars
."])/u", $txt)) { $this
->mpdf
->biDirectional
= true; } // *RTL*
40 if ($this->mpdf
->biDirectional
) { $checkCursive
=true; } // *RTL*
41 else if (isset($this->mpdf
->CurrentFont
['indic']) && $this->mpdf
->CurrentFont
['indic']) { $checkCursive
=true; } // *INDIC*
44 $c = mb_substr($s,$i,1,$this->mpdf
->mb_enc
);
47 $this->mpdf
->ResetSpacing();
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);
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
));
66 if($c == " ") { $sep
= $i
; }
67 $l +
= $this->mpdf
->GetCharWidthNonCore($c); // mPDF 5.3.04
69 //Automatic line break (word wrapping)
72 $this->mpdf
->ResetSpacing();
73 if($this->mpdf
->x
> $this->mpdf
->lMargin
) {
75 if ($currentx != 0) $this->mpdf
->x
=$currentx;
76 else $this->mpdf
->x
=$this->mpdf
->lMargin
;
78 $w=$this->mpdf
->w
-$this->mpdf
->rMargin
-$this->mpdf
->x
;
79 $wmax = ($w - ($this->mpdf
->cMarginL+
$this->mpdf
->cMarginR
));
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);
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*
96 //////////////////////////////////////////
97 // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
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
) ;
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*
109 list($charspacing,$ws) = $this->mpdf
->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK
),$inclCursive);
110 $this->mpdf
->SetSpacing($charspacing,$ws);
111 //////////////////////////////////////////
113 $this->mpdf
->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
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
));
131 $this->mpdf
->ResetSpacing();
138 //Explicit line break
140 $this->mpdf
->ResetSpacing();
141 $this->mpdf
->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
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
);
155 if($c == " ") { $sep
= $i
; }
156 $l +
= $this->mpdf
->GetCharWidthCore($c); // mPDF 5.3.04
158 //Automatic line break (word wrapping)
161 $this->mpdf
->ResetSpacing();
162 if($this->mpdf
->x
> $this->mpdf
->lMargin
) {
164 if ($currentx != 0) $this->mpdf
->x
=$currentx;
165 else $this->mpdf
->x
=$this->mpdf
->lMargin
;
167 $w=$this->mpdf
->w
-$this->mpdf
->rMargin
-$this->mpdf
->x
;
168 $wmax=$w-($this->mpdf
->cMarginL+
$this->mpdf
->cMarginR
);
174 $this->mpdf
->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
177 $tmp = substr($s, $j, $sep-$j);
179 //////////////////////////////////////////
180 // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
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 //////////////////////////////////////////
191 $this->mpdf
->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
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
);
210 $this->mpdf
->ResetSpacing();
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
); }
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*
222 $this->mpdf
->Cell($w,$h,$tmp,0,0,$align,$fill,$link);
227 function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsizePt=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider='') { // mPDF 5.5.23
228 if ($font || $fontstyle || $fontsizePt) $this->mpdf
->SetFont($fontfamily,$fontstyle,$fontsizePt);
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 $text=str_replace("\r",'',$text);
242 if ($this->mpdf
->usingCoreFont
) {
244 for($i=0; $i<$nb; $i++
){
245 $w[$i]=$this->mpdf
->GetStringWidth($text[$i]);
246 $w[$i]*=$kerning*$fontwidth;
251 $nb=mb_strlen($text, $this->mpdf
->mb_enc
);
253 $unicode = $this->mpdf
->UTF8StringToArray($text);
254 for($i=0; $i<$nb; $i++
){
255 $c = mb_substr($text,$i,1,$this->mpdf
->mb_enc
);
256 $w[$i]=$this->mpdf
->GetStringWidth($c);
257 $w[$i]*=$kerning*$fontwidth;
258 $char = $unicode[$i];
259 if ($this->mpdf
->useKerning
&& $lastchar) {
260 if (isset($this->mpdf
->CurrentFont
['kerninfo'][$lastchar][$char])) {
261 $tk = $this->mpdf
->CurrentFont
['kerninfo'][$lastchar][$char] * ($this->mpdf
->FontSize
/ 1000) * $kerning * $fontwidth;
271 if ($fontsizePt>=0 || $autoset) { $checking
= false; }
273 $t+
=$this->mpdf
->GetStringWidth(' ');
275 $t+
=$this->mpdf
->GetStringWidth(' ');
277 $fontsizePt = $this->mpdf
->FontSizePt
* 0.5 * $u/$t;
279 $fontsizePt = $this->mpdf
->FontSizePt
* $u/$t;
280 $this->mpdf
->SetFontSize($fontsizePt);
285 //total width of string in degrees
288 $this->mpdf
->StartTransform();
289 // rotate matrix for the first letter to center the text
290 // (half of total degrees)
292 $this->mpdf
->transformRotate(-$d/2, $x, $y);
295 $this->mpdf
->transformRotate($d/2, $x, $y);
297 //run through the string
298 for($i=0; $i<$nb; $i++
){
300 //rotate matrix half of the width of current letter + half of the width of preceding letter
302 $this->mpdf
->transformRotate((($w[$i]/2)/$u)*360, $x, $y);
305 $this->mpdf
->transformRotate((($w[$i]/2+
$w[$i-1]/2)/$u)*360, $x, $y);
308 $this->mpdf
->StartTransform();
309 $this->mpdf
->transformScale($fontwidth*100, 100, $x, $y);
311 $this->mpdf
->SetXY($x-$w[$i]/2, $y-$r);
314 //rotate matrix half of the width of current letter + half of the width of preceding letter
316 $this->mpdf
->transformRotate(-(($w[$i]/2)/$u)*360, $x, $y);
319 $this->mpdf
->transformRotate(-(($w[$i]/2+
$w[$i-1]/2)/$u)*360, $x, $y);
322 $this->mpdf
->StartTransform();
323 $this->mpdf
->transformScale($fontwidth*100, 100, $x, $y);
325 $this->mpdf
->SetXY($x-$w[$i]/2, $y+
$r-($this->mpdf
->FontSize
));
327 if ($this->mpdf
->usingCoreFont
) { $c
=$text
[$i
]; }
328 else { $c
= mb_substr($text
,$i
,1,$this
->mpdf
->mb_enc
); }
329 $this->mpdf
->Cell(($w[$i]),$this->mpdf
->FontSize
,$c,0,0,'C'); // mPDF 5.3.53
331 $this->mpdf
->StopTransform();
334 $this->mpdf
->StopTransform();
337 if($align=='top' && $divider!=''){
338 $wc=$this->mpdf
->GetStringWidth($divider);
339 $wc*=$kerning*$fontwidth;
341 $this->mpdf
->StartTransform();
342 $this->mpdf
->transformRotate(90, $x, $y);
343 $this->mpdf
->SetXY($x-$wc/2, $y-$r);
344 $this->mpdf
->Cell(($wc),$this->mpdf
->FontSize
,$divider,0,0,'C');
345 $this->mpdf
->StopTransform();
347 $this->mpdf
->StartTransform();
348 $this->mpdf
->transformRotate(-90, $x, $y);
349 $this->mpdf
->SetXY($x-$wc/2, $y-$r);
350 $this->mpdf
->Cell(($wc),$this->mpdf
->FontSize
,$divider,0,0,'C');
351 $this->mpdf
->StopTransform();
355 function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 )
357 // F (shading - no line),S (line, no shading),DF (both)
358 if (!$font) { $font
= $this
->mpdf
->default_font
; }
359 if (!$szfont) { $szfont
= ($this
->mpdf
->default_font_size
* 1.8); }
361 $text = $this->mpdf
->purify_utf8_text($text);
362 if ($this->mpdf
->text_input_as_HTML
) {
363 $text = $this->mpdf
->all_entities_to_utf8($text);
365 if ($this->mpdf
->usingCoreFont
) { $text
= mb_convert_encoding($text
,$this
->mpdf
->mb_enc
,'UTF-8'); }
367 $this->mpdf
->magic_reverse_dir($text, true, $this->mpdf
->directionality
); // *RTL*
368 // Font-specific ligature substitution for Indic fonts
369 if (isset($this->mpdf
->CurrentFont
['indic']) && $this->mpdf
->CurrentFont
['indic']) $this->mpdf
->ConvertIndic($text); // *INDIC*
370 $text = ' '.$text.' ';
371 if (!$width) { $width
= $this
->mpdf
->pgwidth
; } else { $width
=$this
->mpdf
->ConvertSize($width
,$this
->mpdf
->pgwidth
); }
372 $midpt = $this->mpdf
->lMargin+
($this->mpdf
->pgwidth
/2);
373 $r1 = $midpt-($width/2); //($this->mpdf->w / 2) - 40;
374 $r2 = $r1 +
$width; //$r1 + 80;
375 $y1 = $this->mpdf
->y
;
378 $mid = ($r1 +
$r2 ) / 2;
383 $this->mpdf
->SetFont( $font, $fontstyle, $szfont );
384 $sz = $this->mpdf
->GetStringWidth( $text );
385 if ( ($r1+
$sz) > $r2 )
391 $y2 = $this->mpdf
->FontSize+
($pad*2);
393 $this->mpdf
->SetLineWidth(0.1);
394 $fc = $this->mpdf
->ConvertColor($fill);
395 $tc = $this->mpdf
->ConvertColor($color);
396 $this->mpdf
->SetFColor($fc);
397 $this->mpdf
->SetTColor($tc);
398 $this->mpdf
->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style);
399 $this->mpdf
->SetX( $r1);
400 $this->mpdf
->Cell($r2-$r1, $y2, $text, 0, 1, "C" );
401 $this->mpdf
->SetY($y1+
$y2+
2); // +2 = mm margin below shaded box
402 $this->mpdf
->Reset();