1program cairoprog;
2
3{$mode objfpc}{$H+}
4
5uses
6  Classes, Printers, Graphics, CairoCanvas;
7
8var // This could also be TCairoSvgCanvas, TCairoPngCanvas or TCairoPsCanvas
9  PrinterPDFCanvas: TCairoPdfCanvas;
10  PrinterPSCanvas : TCairoPSCanvas;
11  ImgSVG          : TCairoSvgCanvas;
12  ImgPNG          : TCairoPngCanvas;
13begin
14  PrinterPDFCanvas := TCairoPdfCanvas.Create;
15  try
16    PrinterPDFCanvas.OutputFileName := 'CairoCanvas.pdf'; // OutputFileName must set before BeginDoc; Otherwise use stream property
17    PrinterPDFCanvas.BeginDoc;
18    // Font properties must be set, does not work otherwise.
19    {$IFDEF MSWindows}
20    PrinterPDFCanvas.Font.Name := 'Arial Unicode MS';
21    {$ELSE}
22    PrinterPDFCanvas.Font.Name := 'Arial'; // Font properties must be set, does not work otherwise.
23    {$ENDIF}
24
25    PrinterPDFCanvas.Brush.Color:=clYellow;
26    PrinterPDFCanvas.Font.Height := 24;
27
28    PrinterPDFCanvas.Ellipse(10, 20, 260, 120);
29
30    PrinterPDFCanvas.TextOut(50, 60, 'Portrait');
31    PrinterPDFCanvas.TextOut(50, 150, 'abcdefghijklmnopqrstuvwxyzåäö');
32    PrinterPDFCanvas.TextOut(50, 220, 'ฉันหิวแล้ว');
33    PrinterPDFCanvas.TextOut(50, 290, 'К нам в око́шко застучи́т');
34    PrinterPDFCanvas.TextOut(50, 360, 'لا أتَكَلّمُ الْعَرَبيّة');
35
36    PrinterPDFCanvas.Orientation:=poLandscape; //Orientation must set before new page
37    PrinterPDFCanvas.NewPage;
38    PrinterPDFCanvas.Ellipse(10, 20, 260, 120);
39    PrinterPDFCanvas.Font.Color:=clnavy;
40    PrinterPDFCanvas.TextOut(50, 60, 'Landscape');
41    PrinterPDFCanvas.Font.Color:=clBlack;
42    PrinterPDFCanvas.TextOut(50, 150, 'Finnish: wxyzåäö1234567890');
43    PrinterPDFCanvas.TextOut(50, 220, 'Thai: ฉันหิวแล้ว');
44    PrinterPDFCanvas.TextOut(50, 290, 'Russian: К нам в око́шко застучи́т');
45    PrinterPDFCanvas.TextOut(50, 360, 'Arabic: لا أتَكَلّمُ الْعَرَبيّة');
46
47    WriteLn('Written file ' + PrinterPDFCanvas.OutputFileName);
48    PrinterPDFCanvas.EndDoc;
49  finally
50    PrinterPDFCanvas.Free;
51  end;
52
53  PrinterPSCanvas := TCairoPSCanvas.Create;
54  try
55    PrinterPDFCanvas.OutputFileName := 'CairoCanvas.ps'; // OutputFileName must set before BeginDoc; Otherwise use stream property
56    PrinterPSCanvas.BeginDoc;
57    // Font properties must be set, does not work otherwise.
58    {$IFDEF MSWindows}
59    PrinterPSCanvas.Font.Name := 'Arial Unicode MS';
60    {$ELSE}
61    PrinterPSCanvas.Font.Name := 'Arial'; // Font properties must be set, does not work otherwise.
62    {$ENDIF}
63    PrinterPSCanvas.Brush.Color:=clYellow;
64    PrinterPSCanvas.Font.Height := 24;
65
66    PrinterPSCanvas.Ellipse(10, 20, 260, 120);
67
68    PrinterPSCanvas.TextOut(50, 60, 'Portrait');
69    PrinterPSCanvas.TextOut(50, 150, 'abcdefghijklmnopqrstuvwxyzåäö');
70    PrinterPSCanvas.TextOut(50, 220, 'ฉันหิวแล้ว');
71    PrinterPSCanvas.TextOut(50, 290, 'К нам в око́шко застучи́т');
72    PrinterPSCanvas.TextOut(50, 360, 'لا أتَكَلّمُ الْعَرَبيّة');
73
74    PrinterPSCanvas.Orientation:=poLandscape; //Orientation must set before new page
75    PrinterPSCanvas.NewPage;
76    PrinterPSCanvas.Orientation:=poLandscape; //Orientation must set before new page
77    PrinterPSCanvas.Ellipse(10, 20, 260, 120);
78    PrinterPSCanvas.Font.Color:=clnavy;
79    PrinterPSCanvas.TextOut(50, 60, 'Landscape');
80    PrinterPSCanvas.Font.Color:=clBlack;
81    PrinterPSCanvas.TextOut(50, 150, 'Finnish: wxyzåäö1234567890');
82    PrinterPSCanvas.TextOut(50, 220, 'Thai: ฉันหิวแล้ว');
83    PrinterPSCanvas.TextOut(50, 290, 'Russian: К нам в око́шко застучи́т');
84    PrinterPSCanvas.TextOut(50, 360, 'Arabic: لا أتَكَلّمُ الْعَرَبيّة');
85
86    WriteLn('Written file ' + PrinterPSCanvas.OutputFileName);
87    PrinterPSCanvas.EndDoc;
88  finally
89    PrinterPSCanvas.Free;
90  end;
91
92  ImgSVG := TCairoSvgCanvas.Create;
93  try
94    ImgSVG.OutputFileName := 'CairoCanvas.svg'; // OutputFileName must set before BeginDoc; Otherwise use stream property
95    ImgSVG.BeginDoc;
96    // Font properties must be set, does not work otherwise.
97    {$IFDEF MSWindows}
98    ImgSVG.Font.Name := 'Arial Unicode MS';
99    {$ELSE}
100    ImgSVG.Font.Name := 'Arial'; // Font properties must be set, does not work otherwise.
101    {$ENDIF}
102    ImgSVG.Brush.Color:=clYellow;
103    ImgSVG.Font.Height := 24;
104
105    ImgSVG.Orientation:=poLandscape; //Orientation must set before new page
106    ImgSVG.NewPage;
107    ImgSVG.Ellipse(10, 20, 260, 120);
108    ImgSVG.Font.Color:=clnavy;
109    ImgSVG.TextOut(50, 60, 'Landscape');
110    ImgSVG.Font.Color:=clBlack;
111    ImgSVG.TextOut(50, 150, 'Finnish: wxyzåäö1234567890');
112    ImgSVG.TextOut(50, 220, 'Thai: ฉันหิวแล้ว');
113    ImgSVG.TextOut(50, 290, 'Russian: К нам в око́шко застучи́т');
114    ImgSVG.TextOut(50, 360, 'Arabic: لا أتَكَلّمُ الْعَرَبيّة');
115
116    ImgSVG.Orientation:=poLandscape; //Orientation must set before new page
117    ImgSVG.NewPage;
118    ImgSVG.Orientation:=poLandscape; //Orientation must set before new page
119    ImgSVG.Ellipse(10, 20, 260, 120);
120    ImgSVG.Font.Color:=clnavy;
121    ImgSVG.TextOut(50, 60, 'Landscape');
122    ImgSVG.Font.Color:=clBlack;
123    ImgSVG.TextOut(50, 150, 'Finnish: wxyzåäö1234567890');
124    ImgSVG.TextOut(50, 220, 'Thai: ฉันหิวแล้ว');
125    ImgSVG.TextOut(50, 290, 'Russian: К нам в око́шко застучи́т');
126    ImgSVG.TextOut(50, 360, 'Arabic: لا أتَكَلّمُ الْعَرَبيّة');
127
128    WriteLn('Written file ' + ImgSVG.OutputFileName);
129    ImgSVG.EndDoc;
130  finally
131    ImgSVG.Free;
132  end;
133  ImgPNG := TCairoPNGCanvas.Create;
134  try
135    ImgPNG.OutputFileName := 'CairoCanvas.png'; // OutputFileName must set before BeginDoc; Otherwise use stream property
136    ImgPNG.BeginDoc;
137    // Font properties must be set, does not work otherwise.
138    {$IFDEF MSWindows}
139    ImgPNG.Font.Name := 'Arial Unicode MS';
140    {$ELSE}
141    ImgPNG.Font.Name := 'Arial'; // Font properties must be set, does not work otherwise.
142    {$ENDIF}
143    ImgPNG.Brush.Color:=clYellow;
144    ImgPNG.Font.Height := 24;
145
146    ImgPNG.Orientation:=poLandscape; //Orientation must set before new page
147    ImgPNG.NewPage;
148    ImgPNG.Ellipse(10, 20, 260, 120);
149    ImgPNG.Font.Color:=clnavy;
150    ImgPNG.TextOut(50, 60, 'Landscape');
151    ImgPNG.Font.Color:=clBlack;
152    ImgPNG.TextOut(50, 150, 'Finnish: wxyzåäö1234567890');
153    ImgPNG.TextOut(50, 220, 'Thai: ฉันหิวแล้ว');
154    ImgPNG.TextOut(50, 290, 'Russian: К нам в око́шко застучи́т');
155    ImgPNG.TextOut(50, 360, 'Arabic: لا أتَكَلّمُ الْعَرَبيّة');
156
157    WriteLn('Written file ' + ImgPNG.OutputFileName);
158    ImgPNG.EndDoc;
159  finally
160    ImgPNG.Free;
161  end;
162
163end.
164
165