| |
Text rotations
InformationsAuthor: Pivkin Vladimir License: Freeware
DescriptionThis extension allows to print rotated and sheared (i.e. distorted like in italic) text.
TextWithDirection(float x, float y, string txt [, string direction])
x: abscissa
y: ordinate
txt: text string
direction: one of the following values (R by default):
- R (Right): Left to Right
- U (Up): Bottom to Top
- D (Down): Top To Bottom
- L (Left): Right to Left
TextWithRotation(float x, float y, string txt, float txt_angle [, float font_angle])
x: abscissa
y: ordinate
txt: text string
txt_angle: angle of the text
font_angle: shear angle (0 by default)
Source
<?php require('fpdf.php');
class RPDF extends FPDF {
function TextWithDirection($x, $y, $txt, $direction='R') { $txt=str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); if ($direction=='R') $s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 1, 0, 0, 1, $x*$this->k, ($this->h-$y)*$this->k, $txt); elseif ($direction=='L') $s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', -1, 0, 0, -1, $x*$this->k, ($this->h-$y)*$this->k, $txt); elseif ($direction=='U') $s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 0, 1, -1, 0, $x*$this->k, ($this->h-$y)*$this->k, $txt); elseif ($direction=='D') $s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 0, -1, 1, 0, $x*$this->k, ($this->h-$y)*$this->k, $txt); else $s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x*$this->k, ($this->h-$y)*$this->k, $txt); if ($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q'; $this->_out($s); }
function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0) { $txt=str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt)));
$font_angle+=90+$txt_angle; $txt_angle*=M_PI/180; $font_angle*=M_PI/180;
$txt_dx=cos($txt_angle); $txt_dy=sin($txt_angle); $font_dx=cos($font_angle); $font_dy=sin($font_angle);
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', $txt_dx, $txt_dy, $font_dx, $font_dy, $x*$this->k, ($this->h-$y)*$this->k, $txt); if ($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q'; $this->_out($s); }
}
?>
|
Example
<?php define('FPDF_FONTPATH', 'font/'); require('rpdf.php');
$pdf=new RPDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial', '', 40); $pdf->TextWithRotation(50, 65, 'Hello', 45, -45); $pdf->SetFontSize(30); $pdf->TextWithDirection(110, 50, 'world!', 'L'); $pdf->TextWithDirection(110, 50, 'world!', 'U'); $pdf->TextWithDirection(110, 50, 'world!', 'R'); $pdf->TextWithDirection(110, 50, 'world!', 'D'); $pdf->Output(); ?>
|
View the result here.
DownloadZIP | TGZ
|