Tekenen
Geometrie
PDF gebruikt dezelfde geometrie als PostScript. Het begint van de beneden-linkse
hoek van de pagina en is standaard afgemeten in points (1/72 van een duim).
De grootte van een pagina kan worden verkregen van het pagina object:
getWidth();
$height = $pdfPage->getHeight();]]>
Kleur
PDF heeft geweldig goede kleurweergavemogelijkheden. Zend_Pdf ondersteunt grijsschalen, RGB en CMYK
kleuren. Elk van deze notaties kan worden gebruikt daar waar een Zend_Pdf_Color object
nodig is. De Zend_Pdf_Color_GrayScale, Zend_Pdf_Color_RGB en
Zend_Pdf_Color_CMYK klassen verstrekken deze functionaliteit:
Vormen tekenen
Alle tekenoperaties kunnen worden uitgevoerd in de context van een PDF pagina.
De Zend_Pdf_Page klasse verstrekt een set van teken methodes:
Tekst schrijven
Ook tekst wordt geschreven in de paginacontext:
Het huidige lettertype en de lettertypegrootte worden gebruikt om tekst te schrijven. Zie de gedetailleerde beschrijving
hieronder.
Lettertypes gebruiken
De Zend_Pdf_Page::drawText() methode gebruikt het actieve lettertype die kan gezet worden door
de Zend_Pdf_Page::drawText() methode:
PDF ondersteunt Type1, TrueType, Type3 and composite lettertypes. Er zijn ook 14 standaard Type1 lettertypes
voorzien in PDF. De Zend_Pdf module verstrekt op dit moment alleen de 14 standaard lettertypes. Die kunnen
verkregen worden door de Zend_Pdf_Font_Standard klasse te gebruiken. Een bepaalde lettertype
moet worden gebruikt als argument:
Een standaard lettertype maken
setFont($font, 36);
...
?>]]>
De Zend_Pdf_Const verstrekt constanten voor de 14 standaard lettertypes:
Zend_Pdf_Const::FONT_TIMES_ROMAN
Zend_Pdf_Const::FONT_TIMES_BOLD
Zend_Pdf_Const::FONT_TIMES_ITALIC
Zend_Pdf_Const::FONT_TIMES_BOLDITALIC
Zend_Pdf_Const::FONT_HELVETICA
Zend_Pdf_Const::FONT_HELVETICA_BOLD
Zend_Pdf_Const::FONT_HELVETICA_ITALIC
Zend_Pdf_Const::FONT_HELVETICA_BOLDITALIC
Zend_Pdf_Const::FONT_COURIER
Zend_Pdf_Const::FONT_COURIER_BOLD
Zend_Pdf_Const::FONT_COURIER_ITALIC
Zend_Pdf_Const::FONT_COURIER_BOLDITALIC
Zend_Pdf_Const::FONT_SYMBOL
Zend_Pdf_Const::FONT_ZAPFDINGBATS
Beelden tekenen
De Zend_Pdf_Page klasse voorziet de drawImage() methode om beelden te tekenen:
Beeldobjecten worden door afstammelingen van de Zend_Pdf_Image klasse voorgesteld.
Alleen JPG beelden zijn momenteel ondersteund:
Beelden tekenen
drawImage($image, 100, 100, 400, 300);;
...
?>]]>
Belangrijk! De Zend_Pdf_Image_JPEG klasse heeft de PHP GD extensie nodig.
Zie de PHP documentatie voor meer informatie
(http://www.php.net/manual/nl/ref.image.php).
Lijnstijl tekenen
De lijnstijl wordt gedefinieerd door lijndikte, lijnkleur en lijnstippenpatroon. Al deze parameters kunnen door de Zend_Pdf_Page klasse methodes worden aangegeven:
Vulstijl
De Zend_Pdf_Page::drawRectangle(), Zend_Pdf_Page::drawPoligon(),
Zend_Pdf_Page::drawCircle() en Zend_Pdf_Page::drawEllipse() methodes aanvaarden
het optionele argument $fillType. Dit kan het volgende zijn:
Zend_Pdf_Const::SHAPEDRAW_STROKE - streep
Zend_Pdf_Const::SHAPEDRAW_FILL - alleen opvullen
Zend_Pdf_Const::SHAPEDRAW_FILLNSTROKE - opvullen en doorstrepen (standaard)
De Zend_Pdf_Page::drawPoligon() methode accepteert ook een optionele parameter
$fillMethod:
Zend_Pdf_Const::FILLMETHOD_NONZEROWINDING (standaard)
De PDF referentie beschrijft deze regel als volgt (originele tekst):
The nonzero winding number rule determines whether a given point is inside a
path by conceptually drawing a ray from that point to infinity in any direction
and then examining the places where a segment of the path crosses the ray. Starting
with a count of 0, the rule adds 1 each time a path segment crosses the ray
from left to right and subtracts 1 each time a segment crosses from right to left.
After counting all the crossings, if the result is 0 then the point is outside the path;
otherwise it is inside.
Note: The method just described does not specify what to do if a path segment coincides
with or is tangent to the chosen ray. Since the direction of the ray is arbitrary,
the rule simply chooses a ray that does not encounter such problem intersections.
For simple convex paths, the nonzero winding number rule defines the inside
and outside as one would intuitively expect. The more interesting cases are those
involving complex or self-intersecting paths like the ones shown in Figure 4.10
(in a PDF Reference).
For a path consisting of a five-pointed star, drawn with five connected straight
line segments intersecting each other, the rule considers the inside to be the entire
area enclosed by the star, including the pentagon in the center. For a path composed
of two concentric circles, the areas enclosed by both circles are considered
to be inside, provided that both are drawn in the same direction. If the circles are
drawn in opposite directions, only the "doughnut" shape between them is inside,
according to the rule; the "doughnut hole" is outside.
Zend_Pdf_Const::FILLMETHOD_EVENODD
De PDF referentie beschrijft deze regel als volgt (originele tekst):
An alternative to the nonzero winding number rule is the even-odd rule. This rule
determines the "insideness" of a point by drawing a ray from that point in any
direction and simply counting the number of path segments that cross the ray,
regardless of direction. If this number is odd, the point is inside; if even, the point
is outside. This yields the same results as the nonzero winding number rule for
paths with simple shapes, but produces different results for more complex
shapes.
Figure 4.11 (in a PDF Reference) shows the effects of applying the even-odd rule
to complex paths. For the five-pointed star, the rule considers the triangular
points to be inside the path, but not the pentagon in the center. For the two
concentric circles, only the "doughnut" shape between the two circles is considered inside,
regardless of the directions in which the circles are drawn.
Rotaties
Een PDF pagina kan geroteerd worden zo lang er nog niets op werd geschreven of getekend.
Het wordt gedaan door de Zend_Pdf_Page::rotate() methode:
Opslaan/herstellen van een grafische staat
Op eender welk moment kan een grafische staat van een pagina (huidig lettertype, lettertype
grootte, lijnkleur, vulkleur, lijnstijl, paginarotatie, clip area) worden opgeslagen
en worden hersteld. De opsla-operatie slaat de data in een grafische staatstapel op,
de hersteloperatie haalt ze er weer uit.
Dit zijn de Zend_Pdf_Page klassemethodes om deze operaties uit te voeren:
Clipping draw area
PDF en de Zend_Pdf module ondersteunen clippen van een teken area.
De actieve clip area begrenst de regios van de pagina die door tekenoperaties worden beïnvloed.
Initieel is het de volledige pagina.
De Zend_Pdf_Page klasse verstrekt een set methodes voor clipoperaties.
Stijlen
De Zend_Pdf_Style klasse voorziet in stijlen
Stijlen kunnen gebruikt worden om een set grafische parameters op te slaan en ze toe te brengen op een
PDF pagina in één operatie:
De Zend_Pdf_Style klasse voorziet in een set methodes om verschillende grafische
staat parameters te zetten of te verkrijgen: