24
Classes, Graphics, SysUtils;
27
Colors: array [1..15] of TColor = (
28
clRed, clGreen, clYellow, clBlue, clWhite, clGray, clFuchsia,
29
clTeal, clNavy, clMaroon, clLime, clOlive, clPurple, clSilver, clAqua);
32
TPenBrushFont = set of (pbfPen, pbfBrush, pbfFont);
34
{ TPenBrushFontRecall }
36
TPenBrushFontRecall = class
43
constructor Create(ACanvas: TCanvas; AParams: TPenBrushFont);
44
destructor Destroy; override;
48
procedure DrawLineDepth(ACanvas: TCanvas; AX1, AY1, AX2, AY2, ADepth: Integer);
49
procedure DrawLineDepth(ACanvas: TCanvas; const AP1, AP2: TPoint; ADepth: Integer);
51
procedure PrepareSimplePen(ACanvas: TCanvas; AColor: TColor);
52
procedure PrepareXorPen(ACanvas: TCanvas);
54
function TypicalTextHeight(ACanvas: TCanvas): Integer;
24
Classes, FPCanvas, FPImage, Types, TAChartUtils;
27
// Same types as in Graphics unit, but without dependency.
28
TChartAntialiasingMode = (amDontCare, amOn, amOff);
32
ISimpleTextOut = interface
33
procedure SimpleTextOut(AX, AY: Integer; const AText: String);
34
function SimpleTextExtent(const AText: String): TPoint;
35
function GetFontAngle: Double;
42
FAlignment: TAlignment;
44
FSimpleTextOut: ISimpleTextOut;
49
procedure DoTextOutList;
50
procedure DoTextOutString;
52
constructor Create(ASimpleTextOut: ISimpleTextOut);
54
function Alignment(AAlignment: TAlignment): TChartTextOut;
56
function Pos(AX, AY: Integer): TChartTextOut;
57
function Pos(const APos: TPoint): TChartTextOut;
58
function Text(const AText: String): TChartTextOut;
59
function Text(AText: TStrings): TChartTextOut;
60
function Width(AWidth: Integer): TChartTextOut;
63
TChartColorToFPColorFunc = function (AColor: TChartColor): TFPColor;
64
TGetFontOrientationFunc = function (AFont: TFPCustomFont): Integer;
68
IChartDrawer = interface
69
procedure AddToFontOrientation(ADelta: Integer);
70
procedure ClippingStart(const AClipRect: TRect);
71
procedure ClippingStart;
72
procedure ClippingStop;
73
procedure DrawingBegin(const ABoundingBox: TRect);
75
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
76
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
77
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
78
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
79
function GetBrushColor: TChartColor;
80
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
81
procedure Line(AX1, AY1, AX2, AY2: Integer);
82
procedure Line(const AP1, AP2: TPoint);
83
procedure LineTo(AX, AY: Integer);
84
procedure LineTo(const AP: TPoint);
85
procedure MoveTo(AX, AY: Integer);
86
procedure MoveTo(const AP: TPoint);
88
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
90
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
91
procedure PrepareSimplePen(AColor: TChartColor);
93
AX1, AY1, AX2, AY2: Integer;
94
AStartAngle16Deg, AAngleLength16Deg: Integer);
95
procedure Rectangle(const ARect: TRect);
96
procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
97
function Scale(ADistance: Integer): Integer;
98
procedure SetAntialiasingMode(AValue: TChartAntialiasingMode);
99
procedure SetBrushColor(AColor: TChartColor);
100
procedure SetBrush(ABrush: TFPCustomBrush);
101
procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
102
procedure SetFont(AValue: TFPCustomFont);
103
procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
104
procedure SetPen(APen: TFPCustomPen);
105
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
106
function TextExtent(const AText: String): TPoint;
107
function TextExtent(AText: TStrings): TPoint;
108
function TextOut: TChartTextOut;
110
property Brush: TFPCustomBrush write SetBrush;
111
property BrushColor: TChartColor read GetBrushColor write SetBrushColor;
112
property Font: TFPCustomFont write SetFont;
113
property Pen: TFPCustomPen write SetPen;
114
property DoChartColorToFPColor: TChartColorToFPColorFunc
115
write SetDoChartColorToFPColorFunc;
116
property DoGetFontOrientation: TGetFontOrientationFunc
117
write SetGetFontOrientationFunc;
122
TBasicDrawer = class(TInterfacedObject, ISimpleTextOut)
124
FChartColorToFPColorFunc: TChartColorToFPColorFunc;
125
FGetFontOrientationFunc: TGetFontOrientationFunc;
126
function GetFontAngle: Double; virtual; abstract;
127
function SimpleTextExtent(const AText: String): TPoint; virtual; abstract;
128
procedure SimpleTextOut(AX, AY: Integer; const AText: String); virtual; abstract;
131
procedure DrawingBegin(const ABoundingBox: TRect); virtual;
132
procedure DrawingEnd; virtual;
133
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
134
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
135
procedure LineTo(AX, AY: Integer); virtual; abstract;
136
procedure LineTo(const AP: TPoint);
137
procedure MoveTo(AX, AY: Integer); virtual; abstract;
138
procedure MoveTo(const AP: TPoint);
140
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); virtual; abstract;
141
function Scale(ADistance: Integer): Integer; virtual;
142
procedure SetAntialiasingMode(AValue: TChartAntialiasingMode);
143
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
144
procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
145
function TextExtent(const AText: String): TPoint;
146
function TextExtent(AText: TStrings): TPoint;
147
function TextOut: TChartTextOut;
150
function ChartColorToFPColor(AChartColor: TChartColor): TFPColor;
151
function FPColorToChartColor(AFPColor: TFPColor): TChartColor;
152
function ColorDef(AColor, ADefaultColor: TChartColor): TChartColor; inline;
61
procedure DrawLineDepth(ACanvas: TCanvas; AX1, AY1, AX2, AY2, ADepth: Integer);
63
DrawLineDepth(ACanvas, Point(AX1, AY1), Point(AX2, AY2), ADepth);
66
procedure DrawLineDepth(
67
ACanvas: TCanvas; const AP1, AP2: TPoint; ADepth: Integer);
71
d := Size(ADepth, -ADepth);
72
ACanvas.Polygon([AP1, AP1 + d, AP2 + d, AP2]);
75
procedure PrepareSimplePen(ACanvas: TCanvas; AColor: TColor);
77
with ACanvas.Pen do begin
85
procedure PrepareXorPen(ACanvas: TCanvas);
88
Brush.Style := bsClear;
96
function TypicalTextHeight(ACanvas: TCanvas): Integer;
100
Result := ACanvas.TextHeight(TYPICAL_TEXT);
103
{ TPenBrushFontRecall }
105
constructor TPenBrushFontRecall.Create(ACanvas: TCanvas; AParams: TPenBrushFont);
109
if pbfPen in AParams then begin
111
FPen.Assign(FCanvas.Pen);
113
if pbfBrush in AParams then begin
114
FBrush := TBrush.Create;
115
FBrush.Assign(FCanvas.Brush);
117
if pbfFont in AParams then begin
118
FFont := TFont.Create;
119
FFont.Assign(FCanvas.Font);
123
destructor TPenBrushFontRecall.Destroy;
129
procedure TPenBrushFontRecall.Recall;
131
if FPen <> nil then begin
132
FCanvas.Pen.Assign(FPen);
135
if FBrush <> nil then begin
136
FCanvas.Brush.Assign(FBrush);
139
if FFont <> nil then begin
140
FCanvas.Font.Assign(FFont);
162
function ChartColorToFPColor(AChartColor: TChartColor): TFPColor;
165
red := AChartColor and $FF;
167
green := (AChartColor and $FF00);
168
green += green shr 8;
169
blue := (AChartColor and $FF0000) shr 8;
171
alpha := alphaOpaque;
175
function DummyGetFontOrientationFunc(AFont: TFPCustomFont): Integer;
181
function FPColorToChartColor(AFPColor: TFPColor): TChartColor;
184
((AFPColor.red shr 8) and $FF) or
185
(AFPColor.green and $FF00) or
186
((AFPColor.blue shl 8) and $FF0000);
189
function ColorDef(AColor, ADefaultColor: TChartColor): TChartColor;
191
Result := IfThen(AColor = clTAColor, ADefaultColor, AColor);
196
function TChartTextOut.Alignment(AAlignment: TAlignment): TChartTextOut;
198
FAlignment := AAlignment;
202
constructor TChartTextOut.Create(ASimpleTextOut: ISimpleTextOut);
204
FSimpleTextOut := ASimpleTextOut;
205
FAlignment := taLeftJustify;
208
procedure TChartTextOut.Done;
217
procedure TChartTextOut.DoTextOutList;
221
lineExtent, p: TPoint;
223
a := -FSimpleTextOut.GetFontAngle;
224
for i := 0 to FText2.Count - 1 do begin
225
lineExtent := FSimpleTextOut.SimpleTextExtent(FText2[i]);
228
taCenter: p += RotatePointX((FWidth - lineExtent.X) div 2, a);
229
taRightJustify: p += RotatePointX(FWidth - lineExtent.X, a);
231
FSimpleTextOut.SimpleTextOut(p.X, p.Y, FText2[i]);
232
FPos += RotatePoint(Point(0, lineExtent.Y + LINE_INTERVAL), a);
236
procedure TChartTextOut.DoTextOutString;
238
if System.Pos(LineEnding, FText1) = 0 then begin
239
FSimpleTextOut.SimpleTextOut(FPos.X, FPos.Y, FText1);
242
FText2 := TStringList.Create;
244
FText2.Text := FText1;
251
function TChartTextOut.Pos(AX, AY: Integer): TChartTextOut;
253
FPos := Point(AX, AY);
257
function TChartTextOut.Pos(const APos: TPoint): TChartTextOut;
263
function TChartTextOut.Text(const AText: String): TChartTextOut;
269
function TChartTextOut.Text(AText: TStrings): TChartTextOut;
275
function TChartTextOut.Width(AWidth: Integer): TChartTextOut;
283
constructor TBasicDrawer.Create;
285
FChartColorToFPColorFunc := @ChartColorToFPColor;
286
FGetFontOrientationFunc := @DummyGetFontOrientationFunc;
289
procedure TBasicDrawer.DrawingBegin(const ABoundingBox: TRect);
291
Unused(ABoundingBox);
294
procedure TBasicDrawer.DrawingEnd;
299
procedure TBasicDrawer.DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
301
DrawLineDepth(Point(AX1, AY1), Point(AX2, AY2), ADepth);
304
procedure TBasicDrawer.DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
308
d := Point(ADepth, -ADepth);
309
Polygon([AP1, AP1 + d, AP2 + d, AP2], 0, 4);
312
procedure TBasicDrawer.LineTo(const AP: TPoint);
317
procedure TBasicDrawer.MoveTo(const AP: TPoint);
322
function TBasicDrawer.Scale(ADistance: Integer): Integer;
327
procedure TBasicDrawer.SetAntialiasingMode(AValue: TChartAntialiasingMode);
332
procedure TBasicDrawer.SetDoChartColorToFPColorFunc(
333
AValue: TChartColorToFPColorFunc);
335
FChartColorToFPColorFunc := AValue;
338
procedure TBasicDrawer.SetGetFontOrientationFunc(
339
AValue: TGetFontOrientationFunc);
341
FGetFontOrientationFunc := AValue;
344
function TBasicDrawer.TextExtent(const AText: String): TPoint;
348
if Pos(LineEnding, AText) = 0 then
349
exit(SimpleTextExtent(AText));
350
sl := TStringList.Create;
353
Result := TextExtent(sl);
359
function TBasicDrawer.TextExtent(AText: TStrings): TPoint;
363
Result := Size(0, -LINE_INTERVAL);
364
for i := 0 to AText.Count - 1 do
365
with SimpleTextExtent(AText[i]) do begin
366
Result.X := Max(Result.X, X);
367
Result.Y += Y + LINE_INTERVAL;
371
function TBasicDrawer.TextOut: TChartTextOut;
373
Result := TChartTextOut.Create(Self);