1 unit Unit2;
2 
3 {$mode objfpc}{$H+}
4 
5 interface
6 
7 uses
8   Classes, SysUtils, LCLProc, FileUtil, LResources, Forms, Controls, Graphics,
9   Dialogs, FPimage, agg_fpimage, Agg_LCL;
10 
11 type
12 
13   { TForm1 }
14 
15   TForm1 = class(TForm)
16     procedure FormCreate(Sender: TObject);
17     procedure FormDestroy(Sender: TObject);
18     procedure FormPaint(Sender: TObject);
19   private
20   public
21     AggLCLCanvas: TAggLCLCanvas;
22     Bitmap1: TBitmap;
23   end;
24 
25 var
26   Form1: TForm1;
27 
28 implementation
29 
30 { TForm1 }
31 
32 procedure TForm1.FormCreate(Sender: TObject);
33 var
34   HasFont: Boolean;
35   FontFilename: String;
36   s: String;
37   TxtW: integer;
38   TxtH: integer;
39   TxtX: Integer;
40   TxtY: Integer;
41 begin
42   Bitmap1:=TBitmap.Create;
43   AggLCLCanvas:=TAggLCLCanvas.Create;
44   with AggLCLCanvas do begin
45     Image.PixelFormat:=afpimRGBA32;
46     Image.SetSize(500,500);
47   end;
48   {$IFDEF LCLGtk2}
49   HasFont:=true;
50   FontFilename:=SetDirSeparators('../../verdana.ttf');
51   if not FileExistsUTF8(FontFilename) then begin
52     ShowMessage('file not found: '+FontFilename+' CurDir='+GetCurrentDirUTF8);
53     HasFont:=false;
54   end;
55   {$ELSE}
56   HasFont:=false;
57   {$ENDIF}
58 
59   // paint to agg canvas
60   with AggLCLCanvas do begin
61     if HasFont then begin
62       Font.LoadFromFile(FontFilename);
63       Font.Size:=10;
64       Font.Color:=clBlack;
65     end;
66 
67     // solid white background
68     Brush.Color:=clWhite;
69     FillRect(0,0,Width,Height);
70 
71     Brush.Color:=clRed;
72     Pen.Color:=clBlue;
73     Pen.Width:=1;
74 
75     Line(12,10,22,10);
76     Line(10,12,10,22);
77     Line(12,12,22,22);
78 
79     FillRect(40,10,50,20);
80     Ellipse(55,10,65,20);
81     GradientFill(Rect(70,10,80,20),clRed,clBlue,gdVertical);
82     Frame(85,10,95,20);
83     Arc(100,10,110,20, 0,2700);
84     Arc(115,10,125,20, 1000,2700);
85     Arc(130,10,140,20, 135,5, 130,20);
86     Chord(145,10,165,30, 0,2000);
87     Chord(170,10,190,30, 1000,2000);
88     Chord(195,10,215,30, 205,5, 195,30);
89     Pie(220,10,240,30, 230,5, 220,30);
90     RadialPie(245,10,265,30, 1000,2000);
91 
92     if HasFont then begin
93       s:='Font.Size='+IntToStr(Font.Size);
94       GetTextSize(s,TxtW,TxtH);
95       TxtX:=10;
96       TxtY:=40;
97       FillRect(TxtX,TxtY,TxtX+TxtW,TxtY+TxtH);
98       TextOut(TxtX,TxtY,s);
99     end;
100 
101     RoundRect(10,80,30,100,15,15);
102     Polyline([Point(35,80),Point(45,80),Point(55,80),Point(55,90),
103               Point(55,90),Point(55,100),Point(35,90),Point(35,100)]);
104     PolyBezier([Point(35,80),Point(45,80),Point(55,80),Point(55,90),
105                 Point(55,90),Point(55,100),Point(35,90),Point(35,100)],
106                 false,false);
107   end;
108 
109   // convert to LCL native pixel format
110   Bitmap1.LoadFromIntfImage(AggLCLCanvas.Image.IntfImg);
111 
112   // paint with widgetset to bitmap
113   with Bitmap1.Canvas do begin
114     Font.Size:=10;
115     Font.Color:=clBlack;
116 
117     Brush.Color:=clRed;
118     Pen.Color:=clBlue;
119     Pen.Width:=1;
120 
121     Line(24,10,34,10);
122     Line(10,24,10,34);
123     Line(24,24,34,34);
124 
125     FillRect(40,22,50,32);
126     Ellipse(55,22,65,32);
127     GradientFill(Rect(70,22,80,32),clRed,clBlue,gdVertical);
128     Frame(85,22,95,32);
129     Arc(100,22,110,32, 0,2700);
130     Arc(115,22,125,32, 1000,2700);
131     Arc(130,22,140,32, 135,15, 130,32);
132     Chord(145,32,165,52, 0,2000);
133     Chord(170,32,190,52, 1000,2000);
134     Chord(195,32,215,52, 205,27, 195,52);
135     Pie(220,32,240,52, 230,27, 220,52);
136     RadialPie(245,32,265,52, 1000,2000);
137 
138     s:='Font.Size='+IntToStr(Font.Size);
139     GetTextSize(s,TxtW,TxtH);
140     TxtX:=10;
141     TxtY:=60;
142     FillRect(TxtX,TxtY,TxtX+TxtW,TxtY+TxtH);
143     TextOut(TxtX,TxtY,s);
144 
145     RoundRect(10,105,30,125,15,15);
146     Polyline([Point(35,105),Point(45,105),Point(55,105),Point(55,115),
147               Point(55,115),Point(55,125),Point(35,115),Point(35,125)]);
148     PolyBezier([Point(35,105),Point(45,105),Point(55,105),Point(55,115),
149                 Point(55,115),Point(55,125),Point(35,115),Point(35,125)],
150                 false,false);
151   end;
152 end;
153 
154 procedure TForm1.FormDestroy(Sender: TObject);
155 begin
156   AggLCLCanvas.Free;
157   Bitmap1.Free;
158 end;
159 
160 procedure TForm1.FormPaint(Sender: TObject);
161 begin
162   Canvas.Draw(0,0,Bitmap1);
163 end;
164 
165 {$R *.lfm}
166 
167 end.
168 
169