Polygon: Draw a Polygon of up to 20 points   [ 63 ]

Description

This function draws a Polygon formed by a maximum of 20 points defined by their abscissa and ordinate.  These points are specified by an array of up to 40 float numbers which are the abscissa and ordinates of each and every points which form the polygon.  A second parameter is a pointer to a string character which indicates whether the Polygon should be only drawn (="D"), only filled (="F") or drawn and filled (="DF" or "FD").

FPDF4ZOS engine considers Polygon is completed whenever either a point abscissa (=X) or ordinate (=Y) is either null or negative. THis means that for a polygon of seven points, the eighth pair of the array should contain negative numbers.



C calling syntax
void Polygon (float points ??(??), char *style);
Cobol calling syntax
CALL "Polygon" using by value X1,Y1,X2,Y2,X3,Y3,X4,Y4,X5,Y5,X6,Y6,X7,Y7,X8,Y8,X9,Y9,XA,YA,STYLE.
C sample code
#include   "fpdf.h"

static char   f_ini ??(??) = ??< "ini??/??/demofpdf.ini" ??>;
static char   f_out ??(??) = ??< "pdf??/??/demo_e.pdf" ??>;
static char   buf0 ??(1024??);
static float  points ??(??) =
       ??<105, 160, 145, 190, 145, 240, 115, 240, 115, 215, 95, 215, 95, 240, 65, 240, 65, 190, 104.4, 160.4, -1??>;

/* ----------------------------------------------------------------- */

int  main (int argc, char *argv [])

??<
int   link1, link2;

NewPdfy (f_ini, 1);
AddPage("P");

SetLineWidth (0.3);
Line (20,10,180,10);
InLine ("[3 3] 0 d");
Line (20,18,180,18);
InLine ("[6 6] 0 d");
Line (20,26,180,26);
InLine ("[] 0 d");

SetLineWidth (1);
SetDrawColor (32, 32, 32);
SetFillColor (160, 255, 200);
Sector (50, 80, 40, 0, 60, "DF", true, 90);
SetFillColor (240, 255, 16);
Sector (50, 80, 40, 60, 90, "DF", true, 90);
SetFillColor (64, 64, 255);
Sector (50, 80, 40, 90, 150, "DF", true, 90);
SetFillColor (255, 30, 50);
Sector (50, 80, 40, 150, 260, "DF", true, 90);
SetFillColor (120, 200, 64);
Sector (50, 80, 40, 260, 360, "DF", true, 90);

SetLineWidth (2);
SetDrawColor (128, 32, 32);
SetFillColor (0, 240, 240);
Rect (130, 80, 40, 70, "DF");
Circle (150, 80, 40, "DF");

link1 = AddLink ();
link2 = AddLink ();
SetLink (link1, 0, -1);

SetMargins (40, 10, 40);
SetXY (40, 180);
SetFont ("Arial", "N", 10);
strcpy (buf0, "Lorem ipsum dolor sit amet consectetuer nonummy et convallis parturient et. ");
strcat (buf0, "Volutpat congue Quisque neque Nulla vitae non ut quis Vestibulum wisi. ");
strcat (buf0, "Curabitur et suscipit non Quisque Nam eros non semper convallis Morbi.\n\n");
strcat (buf0, "Lorem ipsum dolor sit amet consectetuer nonummy et convallis parturient et. ");
strcat (buf0, "Volutpat congue Quisque neque Nulla vitae non ut quis Vestibulum wisi. ");
strcat (buf0, "Curabitur et suscipit non Quisque Nam eros non semper convallis Morbi.");
Write (4, buf0, 0);
SetMargins (15, 10, 15);
Ln (20);
SetFont ("Courier", "B", 12);
Write (4, "This is a text carrying no link\n\n\n", 0);
SetHorzScaling (120);
Write (4, "This is an expanded text carrying a link to the top of next page\n\n\n", link2);
SetHorzScaling (50);
Write (4, "This is a shrunken text without any link", 0);
SetHorzScaling (100);


AddPage("P");
SetLink (link2, 0, -1);
SetFont ("Courier", "B", 12);
SetXY (20, 20);
Write (4, "This is a text carrying a link to the top of previous page", link1);
SetFillColor (30, 50, 240);
SetTextColor (64, 64, 64);
Code39 (20, 50, "195454828620151618", 1, 12,  "H", "N");
SetFillColor (240, 30, 50);
i25 (20, 80, "195454828620151618", 1, 12);
SetFillColor (10, 128, 20);
Code39 (150, 140, "195454828620151618", 1, 12,  "V", "P");

SetFillColor (240, 255, 16);
Polygon (points, "DF");

Output (f_out);
??>
Description of sample code
This programs illustrates various functions found in FPDF4ZOS interface.  It opens a PDF context, draws 3 different lines with 3 different dash patterns, thanks to the Inline instructions.
It then draws side by side 
- a circle formed by 5 different sectors each of which exhibit a different fill color,
- a circle above a rectangle with Draw and Fill pattern.

It then writes text in flow mode which takes into account left and right margins as well as LineFeed characters.  The final write also illustrates Various Horizontal scaling which enables to expand or shrink text.
Another page is added which illustrates the usage of the two codebar functions, say Code39 and i25.  Note that two among write calls exhibit an internal link usage.
On the second page, a Polygon is also drawn.

The following functions are used in this piece:
- NewPdfy()         -->  Initialisation of a pdf context
- AddPage()         -->  As it says
- SetLineWidth()    -->  Instruct that PDF is to be protected at user and owner levels
- Line()            -->  Draw a straight line between point P1 [X1,Y1] and point P2 [X2,Y2]
- InLine()          -->  Insert a Raw PDF instruction
- SetDrawColor()    -->  Set the color of lines to be drawn
- SetFillColor()    -->  Set the color of area to be filled
- Rect()            -->  Draw a Rectangle
- Circle()          -->  Draw a Circle
- AddLink()         -->  Allocate an internal link
- SetLink()         -->  Specify destination (page number and Y position) of a previously defined internal link
- SetFont()         -->  Set current font
- SetMargins()      -->  Specify page margins (left, top, right)
- Ln()              -->  Insert a line break, meaning return to left margin while incrementing Y position
- Write()           -->  Write text in flow mode
- SetHorzScaling()  -->  Change default hirizontal scaling when writing text
- SetXY()           -->  Set X and Y current position
- Code39()          -->  Output a Code39 codebar
- i25()             -->  Output a Interleaved I25 codebar
- Polygon()         -->  Draw a Polygon defined as a set of points
- Output()          -->  Output PDF file taking into account all the instructions invoked since context initialization
See sample source code in 'C' as well as PDF execution result  -  NB: For encrypted PDFs, user password is USER-PSWD