| @@ -35,8 +35,11 @@ | ||
| 35 | 35 | $l=0; |
| 36 | 36 | $nl=1; |
| 37 | 37 | if (!$this->mpdf->usingCoreFont) { |
| 38 | 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* | |
| 39 | 42 | while($i<$nb) { |
| 40 | 43 | //Get next character |
| 41 | 44 | $c = mb_substr($s,$i,1,$this->mpdf->mb_enc ); |
| 42 | 45 | if($c == "\n") { |
| @@ -43,8 +46,10 @@ | ||
| 43 | 46 | // WORD SPACING |
| 44 | 47 | $this->mpdf->ResetSpacing(); |
| 45 | 48 | //Explicit line break |
| 46 | 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* | |
| 47 | 52 | $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); |
| 48 | 53 | $i++; |
| 49 | 54 | $sep = -1; |
| 50 | 55 | $j = $i; |
| @@ -77,12 +82,16 @@ | ||
| 77 | 82 | continue; |
| 78 | 83 | } |
| 79 | 84 | if($i==$j) { $i++; } |
| 80 | 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* | |
| 81 | 88 | $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link); |
| 82 | 89 | } |
| 83 | 90 | else { |
| 84 | 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* | |
| 85 | 94 | |
| 86 | 95 | if($align=='J') { |
| 87 | 96 | ////////////////////////////////////////// |
| 88 | 97 | // JUSTIFY J using Unicode fonts (Word spacing doesn't work) |
| @@ -92,10 +101,11 @@ | ||
| 92 | 101 | $len_ligne = $this->mpdf->GetStringWidth($tmp ); |
| 93 | 102 | $nb_carac = mb_strlen( $tmp , $this->mpdf->mb_enc ) ; |
| 94 | 103 | $nb_spaces = mb_substr_count( $tmp ,' ', $this->mpdf->mb_enc ) ; |
| 95 | 104 | $inclCursive=false; |
| 96 | - if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) { | |
| 97 | - if (preg_match("/([".$this->mpdf->pregCURSchars."])/u", $tmp)) { $inclCursive = true; } | |
| 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* | |
| 98 | 108 | } |
| 99 | 109 | list($charspacing,$ws) = $this->mpdf->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK),$inclCursive); |
| 100 | 110 | $this->mpdf->SetSpacing($charspacing,$ws); |
| 101 | 111 | ////////////////////////////////////////// |
| @@ -166,10 +176,10 @@ | ||
| 166 | 176 | else { |
| 167 | 177 | $tmp = substr($s, $j, $sep-$j); |
| 168 | 178 | if($align=='J') { |
| 169 | 179 | ////////////////////////////////////////// |
| 170 | - // JUSTIFY J using Unicode fonts | |
| 171 | - // WORD SPACING is not fully supported for complex scripts | |
| 180 | + // JUSTIFY J using Unicode fonts (Word spacing doesn't work) | |
| 181 | + // WORD SPACING | |
| 172 | 182 | // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly |
| 173 | 183 | $tmp = str_replace(chr(160),chr(32),$tmp ); |
| 174 | 184 | $len_ligne = $this->mpdf->GetStringWidth($tmp ); |
| 175 | 185 | $nb_carac = strlen( $tmp ) ; |
| @@ -203,29 +213,27 @@ | ||
| 203 | 213 | if($i!=$j) { |
| 204 | 214 | if ($currentx != 0) $this->mpdf->x=$currentx; |
| 205 | 215 | else $this->mpdf->x=$this->mpdf->lMargin; |
| 206 | 216 | if ($this->mpdf->usingCoreFont) { $tmp = substr($s,$j,$i-$j); } |
| 207 | - else { $tmp = mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc); } | |
| 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 | + } | |
| 208 | 222 | $this->mpdf->Cell($w,$h,$tmp,0,0,$align,$fill,$link); |
| 209 | 223 | } |
| 210 | 224 | } |
| 211 | 225 | |
| 212 | 226 | |
| 213 | -function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsizePt=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider='') { | |
| 214 | - if ($fontfamily || $fontstyle || $fontsizePt) $this->mpdf->SetFont($fontfamily,$fontstyle,$fontsizePt); | |
| 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); | |
| 215 | 229 | $kerning/=100; |
| 216 | 230 | $fontwidth/=100; |
| 217 | 231 | if($kerning==0) $this->mpdf->Error('Please use values unequal to zero for kerning (CircularText)'); |
| 218 | - if($fontwidth==0) $this->mpdf->Error('Please use values unequal to zero for font width (CircularText)'); | |
| 232 | + if($fontwidth==0) $this->mpdf->Error('Please use values unequal to zero for font width (CircularText)'); | |
| 233 | + $t=0; | |
| 219 | 234 | $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) { | |
| 235 | + if ($this->mpdf->usingCoreFont) { | |
| 228 | 236 | $nb=strlen($text); |
| 229 | 237 | for($i=0; $i<$nb; $i++){ |
| 230 | 238 | $w[$i]=$this->mpdf->GetStringWidth($text[$i]); |
| 231 | 239 | $w[$i]*=$kerning*$fontwidth; |
| @@ -230,10 +238,10 @@ | ||
| 230 | 238 | $w[$i]=$this->mpdf->GetStringWidth($text[$i]); |
| 231 | 239 | $w[$i]*=$kerning*$fontwidth; |
| 232 | 240 | $t+=$w[$i]; |
| 233 | 241 | } |
| 234 | - } | |
| 235 | - else { | |
| 242 | + } | |
| 243 | + else { | |
| 236 | 244 | $nb=mb_strlen($text, $this->mpdf->mb_enc ); |
| 237 | 245 | $lastchar = ''; |
| 238 | 246 | $unicode = $this->mpdf->UTF8StringToArray($text); |
| 239 | 247 | for($i=0; $i<$nb; $i++){ |
| @@ -251,23 +259,11 @@ | ||
| 251 | 259 | } |
| 252 | 260 | $lastchar = $char; |
| 253 | 261 | $t+=$w[$i]; |
| 254 | 262 | } |
| 255 | - } | |
| 256 | - if ($fontsizePt>=0 || $autoset) { $checking = false; } | |
| 257 | - else { | |
| 258 | - $t+=$this->mpdf->GetStringWidth(' '); | |
| 259 | - if ($divider) | |
| 260 | - $t+=$this->mpdf->GetStringWidth(' '); | |
| 261 | - if ($fontsizePt==-2) | |
| 262 | - $fontsizePt = $this->mpdf->FontSizePt * 0.5 * $u/$t; | |
| 263 | - else | |
| 264 | - $fontsizePt = $this->mpdf->FontSizePt * $u/$t; | |
| 265 | - $this->mpdf->SetFontSize($fontsizePt); | |
| 266 | - $autoset = true; | |
| 267 | - } | |
| 268 | 263 | } |
| 269 | - | |
| 264 | + //circumference | |
| 265 | + $u=($r*2)*M_PI; | |
| 270 | 266 | //total width of string in degrees |
| 271 | 267 | $d=($t/$u)*360; |
| 272 | 268 | |
| 273 | 269 | $this->mpdf->StartTransform(); |
| @@ -316,62 +312,26 @@ | ||
| 316 | 312 | $this->mpdf->StopTransform(); |
| 317 | 313 | } |
| 318 | 314 | } |
| 319 | 315 | $this->mpdf->StopTransform(); |
| 320 | - | |
| 321 | - // mPDF 5.5.23 | |
| 322 | - if($align=='top' && $divider!=''){ | |
| 323 | - $wc=$this->mpdf->GetStringWidth($divider); | |
| 324 | - $wc*=$kerning*$fontwidth; | |
| 325 | - | |
| 326 | - $this->mpdf->StartTransform(); | |
| 327 | - $this->mpdf->transformRotate(90, $x, $y); | |
| 328 | - $this->mpdf->SetXY($x-$wc/2, $y-$r); | |
| 329 | - $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C'); | |
| 330 | - $this->mpdf->StopTransform(); | |
| 331 | - | |
| 332 | - $this->mpdf->StartTransform(); | |
| 333 | - $this->mpdf->transformRotate(-90, $x, $y); | |
| 334 | - $this->mpdf->SetXY($x-$wc/2, $y-$r); | |
| 335 | - $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C'); | |
| 336 | - $this->mpdf->StopTransform(); | |
| 337 | - } | |
| 338 | 316 | } |
| 339 | 317 | |
| 340 | -function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) { | |
| 341 | - // F (shading - no line),S (line, no shading),DF (both) | |
| 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) | |
| 342 | 321 | if (!$font) { $font= $this->mpdf->default_font; } |
| 343 | 322 | if (!$szfont) { $szfont = ($this->mpdf->default_font_size * 1.8); } |
| 344 | 323 | |
| 345 | - $text = ' '.$text.' '; | |
| 346 | - $this->mpdf->SetFont( $font, $fontstyle, $szfont, false ); | |
| 347 | - | |
| 348 | 324 | $text = $this->mpdf->purify_utf8_text($text); |
| 349 | 325 | if ($this->mpdf->text_input_as_HTML) { |
| 350 | 326 | $text = $this->mpdf->all_entities_to_utf8($text); |
| 351 | 327 | } |
| 352 | 328 | if ($this->mpdf->usingCoreFont) { $text = mb_convert_encoding($text,$this->mpdf->mb_enc,'UTF-8'); } |
| 353 | - | |
| 354 | - | |
| 355 | 329 | // DIRECTIONALITY |
| 356 | - if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $text)) { $this->mpdf->biDirectional = true; } // *RTL* | |
| 357 | - | |
| 358 | - $textvar = 0; | |
| 359 | - $save_OTLtags = $this->mpdf->OTLtags; | |
| 360 | - $this->mpdf->OTLtags = array(); | |
| 361 | - if ($this->mpdf->useKerning) { | |
| 362 | - if ($this->mpdf->CurrentFont['haskernGPOS']) { $this->mpdf->OTLtags['Plus'] .= ' kern'; } | |
| 363 | - else { $textvar = ($textvar | FC_KERNING); } | |
| 364 | - } | |
| 365 | - // Use OTL OpenType Table Layout - GSUB & GPOS | |
| 366 | - if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) { | |
| 367 | - $text = $this->mpdf->otl->applyOTL($text, $this->mpdf->CurrentFont['useOTL']); | |
| 368 | - $OTLdata = $this->mpdf->otl->OTLdata; | |
| 369 | - } | |
| 370 | - $this->mpdf->OTLtags = $save_OTLtags ; | |
| 371 | - | |
| 372 | - $this->mpdf->magic_reverse_dir($text, $this->mpdf->directionality, $OTLdata); | |
| 373 | - | |
| 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.' '; | |
| 374 | 334 | if (!$width) { $width = $this->mpdf->pgwidth; } else { $width=$this->mpdf->ConvertSize($width,$this->mpdf->pgwidth); } |
| 375 | 335 | $midpt = $this->mpdf->lMargin+($this->mpdf->pgwidth/2); |
| 376 | 336 | $r1 = $midpt-($width/2); //($this->mpdf->w / 2) - 40; |
| 377 | 337 | $r2 = $r1 + $width; //$r1 + 80; |
| @@ -382,16 +342,15 @@ | ||
| 382 | 342 | $loop = 0; |
| 383 | 343 | |
| 384 | 344 | while ( $loop == 0 ) |
| 385 | 345 | { |
| 386 | - $this->mpdf->SetFont( $font, $fontstyle, $szfont, false ); | |
| 387 | - $sz = $this->mpdf->GetStringWidth( $text, true, $OTLdata, $textvar ); | |
| 346 | + $this->mpdf->SetFont( $font, $fontstyle, $szfont ); | |
| 347 | + $sz = $this->mpdf->GetStringWidth( $text ); | |
| 388 | 348 | if ( ($r1+$sz) > $r2 ) |
| 389 | 349 | $szfont --; |
| 390 | 350 | else |
| 391 | 351 | $loop ++; |
| 392 | 352 | } |
| 393 | - $this->mpdf->SetFont( $font, $fontstyle, $szfont, true, true ); | |
| 394 | 353 | |
| 395 | 354 | $y2 = $this->mpdf->FontSize+($pad*2); |
| 396 | 355 | |
| 397 | 356 | $this->mpdf->SetLineWidth(0.1); |
| @@ -400,9 +359,9 @@ | ||
| 400 | 359 | $this->mpdf->SetFColor($fc); |
| 401 | 360 | $this->mpdf->SetTColor($tc); |
| 402 | 361 | $this->mpdf->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style); |
| 403 | 362 | $this->mpdf->SetX( $r1); |
| 404 | - $this->mpdf->Cell($r2-$r1, $y2, $text, 0, 1, "C",0,'',0,0,0,'M', 0, false, $OTLdata, $textvar ); | |
| 363 | + $this->mpdf->Cell($r2-$r1, $y2, $text, 0, 1, "C" ); | |
| 405 | 364 | $this->mpdf->SetY($y1+$y2+2); // +2 = mm margin below shaded box |
| 406 | 365 | $this->mpdf->Reset(); |
| 407 | 366 | } |
| 408 | 367 | |