2
*****************************************************************************
4
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
5
* for details about the copyright. *
7
* This program is distributed in the hope that it will be useful, *
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
11
*****************************************************************************
13
Authors: Alexander Klenin
16
unit TADrawerFPVectorial;
23
Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils;
27
{ TFPVectorialDrawer }
29
TFPVectorialDrawer = class(TBasicDrawer, IChartDrawer)
32
FBrushColor: TFPColor;
33
FBrushStyle: TFPBrushStyle;
34
FCanvas: TvVectorialPage;
37
FPenStyle: TFPPenStyle;
40
procedure AddLine(AX, AY: Integer);
43
function InvertY(AY: Integer): Integer; inline;
45
function GetFontAngle: Double; override;
46
procedure SetBrush(ABrush: TFPCustomBrush);
47
procedure SetFont(AFont: TFPCustomFont);
48
procedure SetPen(APen: TFPCustomPen);
49
function SimpleTextExtent(const AText: String): TPoint; override;
50
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
52
constructor Create(ACanvas: TvVectorialPage);
54
procedure AddToFontOrientation(ADelta: Integer);
55
procedure ClippingStart;
56
procedure ClippingStart(const AClipRect: TRect);
57
procedure ClippingStop;
58
procedure DrawingBegin(const ABoundingBox: TRect); override;
59
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
60
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
61
function GetBrushColor: TChartColor;
62
procedure Line(AX1, AY1, AX2, AY2: Integer);
63
procedure Line(const AP1, AP2: TPoint); overload;
64
procedure LineTo(AX, AY: Integer); override;
65
procedure MoveTo(AX, AY: Integer); override; overload;
67
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
69
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
70
procedure PrepareSimplePen(AColor: TChartColor);
72
AX1, AY1, AX2, AY2: Integer;
73
AStartAngle16Deg, AAngleLength16Deg: Integer);
74
procedure Rectangle(const ARect: TRect);
75
procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
76
procedure SetBrushColor(AColor: TChartColor);
77
procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
78
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
86
{ TFPVectorialDrawer }
88
procedure TFPVectorialDrawer.AddLine(AX, AY: Integer);
90
FCanvas.AddLineToPath(AX, InvertY(AY));
93
procedure TFPVectorialDrawer.AddToFontOrientation(ADelta: Integer);
99
procedure TFPVectorialDrawer.ApplyBrush;
101
FCanvas.SetBrushColor(FBrushColor);
102
FCanvas.SetBrushStyle(FBrushStyle);
105
procedure TFPVectorialDrawer.ApplyPen;
107
FCanvas.SetPenColor(FPenColor);
108
FCanvas.SetPenStyle(FPenStyle);
109
FCanvas.SetPenWidth(FPenWidth);
112
procedure TFPVectorialDrawer.ClippingStart(const AClipRect: TRect);
114
Unused(AClipRect); // Not implemented.
117
procedure TFPVectorialDrawer.ClippingStart;
122
procedure TFPVectorialDrawer.ClippingStop;
127
constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage);
133
procedure TFPVectorialDrawer.DrawingBegin(const ABoundingBox: TRect);
135
FBoundingBox := ABoundingBox;
138
procedure TFPVectorialDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
140
cx, cy, rx, ry: Integer;
142
BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry);
143
FCanvas.AddEllipse(cx, InvertY(cy), rx, ry, 0.0);
146
procedure TFPVectorialDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);
153
FCanvas.SetBrushStyle(bsClear);
154
FCanvas.SetPenColor(FPenColor);
158
function TFPVectorialDrawer.GetBrushColor: TChartColor;
160
Result := FPColorToChartColor(FBrushColor);
163
function TFPVectorialDrawer.GetFontAngle: Double;
168
function TFPVectorialDrawer.InvertY(AY: Integer): Integer;
171
Result := Bottom - Top - AY;
174
procedure TFPVectorialDrawer.Line(AX1, AY1, AX2, AY2: Integer);
176
FCanvas.StartPath(AX1, InvertY(AY1));
178
FCanvas.SetPenColor(FPenColor);
182
procedure TFPVectorialDrawer.Line(const AP1, AP2: TPoint);
184
Line(AP1.X, AP1.Y, AP2.X, AP2.Y);
187
procedure TFPVectorialDrawer.LineTo(AX, AY: Integer);
189
FCanvas.AddLineToPath(AX, InvertY(AY), FPenColor);
192
procedure TFPVectorialDrawer.MoveTo(AX, AY: Integer);
195
FCanvas.StartPath(AX, InvertY(AY));
198
procedure TFPVectorialDrawer.Polygon(
199
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
203
if ANumPts <= 0 then exit;
204
MoveTo(APoints[AStartIndex]);
205
for i := 1 to ANumPts - 1 do
206
with APoints[i + AStartIndex] do
213
procedure TFPVectorialDrawer.Polyline(
214
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
218
if ANumPts <= 0 then exit;
219
MoveTo(APoints[AStartIndex]);
220
for i := 1 to ANumPts - 1 do
221
with APoints[i + AStartIndex] do
227
procedure TFPVectorialDrawer.PrepareSimplePen(AColor: TChartColor);
229
FPenColor := FChartColorToFPColorFunc(AColor);
230
FPenStyle := psSolid;
234
procedure TFPVectorialDrawer.RadialPie(
235
AX1, AY1, AX2, AY2: Integer; AStartAngle16Deg, AAngleLength16Deg: Integer);
240
Unused(AStartAngle16Deg, AAngleLength16Deg);
243
procedure TFPVectorialDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer);
255
procedure TFPVectorialDrawer.Rectangle(const ARect: TRect);
258
Rectangle(Left, Top, Right, Bottom);
261
procedure TFPVectorialDrawer.SetBrush(ABrush: TFPCustomBrush);
263
FBrushColor := ABrush.FPColor;
264
FBrushStyle := ABrush.Style;
267
procedure TFPVectorialDrawer.SetBrushColor(AColor: TChartColor);
269
FBrushColor := FChartColorToFPColorFunc(AColor);
272
procedure TFPVectorialDrawer.SetBrushParams(
273
AStyle: TFPBrushStyle; AColor: TChartColor);
275
SetBrushColor(AColor);
276
FBrushStyle := AStyle;
279
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
281
FFontSize := IfThen(AFont.Size = 0, 10, AFont.Size);
284
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
286
FPenColor := APen.FPColor;
287
FPenStyle := APen.Style;
288
FPenWidth := APen.Width;
291
procedure TFPVectorialDrawer.SetPenParams(
292
AStyle: TFPPenStyle; AColor: TChartColor);
295
FPenColor := FChartColorToFPColorFunc(AColor);
298
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
300
Result.X := FFontSize * Length(AText) * 2 div 3;
301
Result.Y := FFontSize;
304
procedure TFPVectorialDrawer.SimpleTextOut(
305
AX, AY: Integer; const AText: String);
307
// FPVectorial uses lower-left instead of upper-left corner as text start.
308
FCanvas.AddText(AX, InvertY(AY) - FFontSize, 0, AText);