-
Notifications
You must be signed in to change notification settings - Fork 12
/
IGDIPlusHelpers.pas
322 lines (282 loc) · 11.9 KB
/
IGDIPlusHelpers.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
unit IGDIPlusHelpers;
{$IFDEF FPC}
{$mode delphi}
{$I IGDIPlusAPI_FPC}
{$ENDIF}
{$IFDEF DCC}{$I IGDIPlusAPI_DCC.inc}{$ENDIF}
interface
uses
Classes, SysUtils, Graphics, Types,
IGDIPlus
{$IFDEF DELPHIXE2_OR_ABOVE},System.UITypes{$ENDIF}
;
{$IFDEF FPC}
type
TPointFHelper = record helper for Types.TPointF
public
class function Create(const ax, ay: Single): TPointF; overload; static; inline;
class function Create(const apt: TPoint): TPointF; overload; static; inline;
end;
{$ENDIF}
type
TGPHatchStyleDynArray = array of TIGPHatchStyle;
function GPPointF(const ax, ay: Single): TPointF; overload;
function GPPointF(const apt: TPoint): TPointF; overload;
function GPPointFMove(const Point: TPointF; const dx, dy: Single): TPointF;
function GPColor(const AColor: TColor; Alpha: Byte = 255): TAlphaColor;
{$IFDEF MSWINDOWS}
function GPTextWidthF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
function GPTextHeightF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
{$ENDIF}
function GPHatchStyleToStrID(const HatchStyle: TIGPHatchStyle): string;
function GPHatchStyleToDisplayName(const HatchStyle: TIGPHatchStyle): string;
function GPTryStrIDToHatchStyle(const StrID: string; var hs: TIGPHatchStyle): Boolean;
function GPGetAllHatchStylesArray: TGPHatchStyleDynArray;
implementation
function GPGetAllHatchStylesArray: TGPHatchStyleDynArray;
var
i: integer;
begin
SetLength(Result, GPHatchStyleTotal);
for i := 0 to High(Result) do
Result[i] := TIGPHatchStyle(i);
end;
function GPHatchStyleToStrID(const HatchStyle: TIGPHatchStyle): string;
var
s: string;
begin
case HatchStyle of
HatchStyleHorizontal: s := 'Horizontal';
HatchStyleVertical: s := 'Vertical';
HatchStyleForwardDiagonal: s := 'ForwardDiagonal';
HatchStyleBackwardDiagonal: s := 'BackwardDiagonal';
HatchStyleCross: s := 'Cross';
HatchStyleDiagonalCross: s := 'DiagonalCross';
HatchStyle05Percent: s := '05Percent';
HatchStyle10Percent: s := '10Percent';
HatchStyle20Percent: s := '20Percent';
HatchStyle25Percent: s := '25Percent';
HatchStyle30Percent: s := '30Percent';
HatchStyle40Percent: s := '40Percent';
HatchStyle50Percent: s := '50Percent';
HatchStyle60Percent: s := '60Percent';
HatchStyle70Percent: s := '70Percent';
HatchStyle75Percent: s := '75Percent';
HatchStyle80Percent: s := '80Percent';
HatchStyle90Percent: s := '90Percent';
HatchStyleLightDownwardDiagonal: s := 'LightDownwardDiagonal';
HatchStyleLightUpwardDiagonal: s:= 'LightUpwardDiagonal';
HatchStyleDarkDownwardDiagonal: s := 'DarkDownwardDiagonal';
HatchStyleDarkUpwardDiagonal: s := 'DarkUpwardDiagonal';
HatchStyleWideDownwardDiagonal: s := 'WideDownwardDiagonal';
HatchStyleWideUpwardDiagonal: s := 'WideUpwardDiagonal';
HatchStyleLightVertical: s := 'LightVertical';
HatchStyleLightHorizontal: s := 'LightHorizontal';
HatchStyleNarrowVertical: s := 'NarrowVertical';
HatchStyleNarrowHorizontal: s := 'NarrowHorizontal';
HatchStyleDarkVertical: s := 'DarkVertical';
HatchStyleDarkHorizontal: s := 'DarkHorizontal';
HatchStyleDashedDownwardDiagonal: s := 'DashedDownwardDiagonal';
HatchStyleDashedUpwardDiagonal: s := 'DashedUpwardDiagonal';
HatchStyleDashedHorizontal: s := 'DashedHorizontal';
HatchStyleDashedVertical: s := 'DashedVertical';
HatchStyleSmallConfetti: s := 'SmallConfetti';
HatchStyleLargeConfetti: s := 'LargeConfetti';
HatchStyleZigZag: s := 'ZigZag';
HatchStyleWave: s := 'Wave';
HatchStyleDiagonalBrick: s := 'DiagonalBrick';
HatchStyleHorizontalBrick: s := 'HorizontalBrick';
HatchStyleWeave: s := 'Weave';
HatchStylePlaid: s := 'Plaid';
HatchStyleDivot: s := 'Divot';
HatchStyleDottedGrid: s := 'DottedGrid';
HatchStyleDottedDiamond: s := 'DottedDiamond';
HatchStyleShingle: s := 'Shingle';
HatchStyleTrellis: s := 'Trellis';
HatchStyleSphere: s := 'Sphere';
HatchStyleSmallGrid: s := 'SmallGrid';
HatchStyleSmallCheckerBoard: s := 'SmallCheckerBoard';
HatchStyleLargeCheckerBoard: s := 'LargeCheckerBoard';
HatchStyleOutlinedDiamond: s := 'OutlinedDiamond';
HatchStyleSolidDiamond: s := 'SolidDiamond';
end;
Result := s;
end;
function GPHatchStyleToDisplayName(const HatchStyle: TIGPHatchStyle): string;
var
s: string;
begin
case HatchStyle of
HatchStyleHorizontal: s := 'Horizontal';
HatchStyleVertical: s := 'Vertical';
HatchStyleForwardDiagonal: s := 'Forward Diagonal';
HatchStyleBackwardDiagonal: s := 'Backward Diagonal';
HatchStyleCross: s := 'Cross';
HatchStyleDiagonalCross: s := 'Diagonal Cross';
HatchStyle05Percent: s := '5%';
HatchStyle10Percent: s := '10%';
HatchStyle20Percent: s := '20%';
HatchStyle25Percent: s := '25%';
HatchStyle30Percent: s := '30%';
HatchStyle40Percent: s := '40%';
HatchStyle50Percent: s := '50%';
HatchStyle60Percent: s := '60%';
HatchStyle70Percent: s := '70%';
HatchStyle75Percent: s := '75%';
HatchStyle80Percent: s := '80%';
HatchStyle90Percent: s := '90%';
HatchStyleLightDownwardDiagonal: s := 'Light Downward Diagonal';
HatchStyleLightUpwardDiagonal: s:= 'Light Upward Diagonal';
HatchStyleDarkDownwardDiagonal: s := 'Dark Downward Diagonal';
HatchStyleDarkUpwardDiagonal: s := 'Dark Upward Diagonal';
HatchStyleWideDownwardDiagonal: s := 'Wide Downward Diagonal';
HatchStyleWideUpwardDiagonal: s := 'Wide Upward Diagonal';
HatchStyleLightVertical: s := 'Light Vertical';
HatchStyleLightHorizontal: s := 'Light Horizontal';
HatchStyleNarrowVertical: s := 'Narrow Vertical';
HatchStyleNarrowHorizontal: s := 'Narrow Horizontal';
HatchStyleDarkVertical: s := 'Dark Vertical';
HatchStyleDarkHorizontal: s := 'Dark Horizontal';
HatchStyleDashedDownwardDiagonal: s := 'Dashed Downward Diagonal';
HatchStyleDashedUpwardDiagonal: s := 'Dashed Upward Diagonal';
HatchStyleDashedHorizontal: s := 'Dashed Horizontal';
HatchStyleDashedVertical: s := 'Dashed Vertical';
HatchStyleSmallConfetti: s := 'Small Confetti';
HatchStyleLargeConfetti: s := 'Large Confetti';
HatchStyleZigZag: s := 'Zig Zag';
HatchStyleWave: s := 'Wave';
HatchStyleDiagonalBrick: s := 'Diagonal Brick';
HatchStyleHorizontalBrick: s := 'Horizontal Brick';
HatchStyleWeave: s := 'Weave';
HatchStylePlaid: s := 'Plaid';
HatchStyleDivot: s := 'Divot';
HatchStyleDottedGrid: s := 'Dotted Grid';
HatchStyleDottedDiamond: s := 'Dotted Diamond';
HatchStyleShingle: s := 'Shingle';
HatchStyleTrellis: s := 'Trellis';
HatchStyleSphere: s := 'Sphere';
HatchStyleSmallGrid: s := 'Small Grid';
HatchStyleSmallCheckerBoard: s := 'Small Checker Board';
HatchStyleLargeCheckerBoard: s := 'Large Checker Board';
HatchStyleOutlinedDiamond: s := 'Outlined Diamond';
HatchStyleSolidDiamond: s := 'Solid Diamond';
end;
Result := s;
end;
function GPTryStrIDToHatchStyle(const StrID: string; var hs: TIGPHatchStyle): Boolean;
var
s: string;
function TrimFromStart(const s: string; const StringToCut: string): string;
begin
if Copy(s, 1, Length(StringToCut)) = StringToCut then Result := Copy(s, Length(StringToCut) + 1, Length(s))
else Result := s;
end;
begin
Result := False;
s := StrID;
s := TrimFromStart(s, 'HatchStyle');
s := Trim(LowerCase(s));
if s = 'horizontal' then hs := HatchStyleHorizontal
else if s = 'vertical' then hs := HatchStyleVertical
else if s = 'forwarddiagonal' then hs := HatchStyleForwardDiagonal
else if s = 'backwarddiagonal' then hs := HatchStyleBackwardDiagonal
else if s = 'cross' then hs := HatchStyleCross
else if s = 'diagonalcross' then hs := HatchStyleDiagonalCross
else if s = '05percent' then hs := HatchStyle05Percent
else if s = '10percent' then hs := HatchStyle10Percent
else if s = '20percent' then hs := HatchStyle20Percent
else if s = '25percent' then hs := HatchStyle25Percent
else if s = '30percent' then hs := HatchStyle30Percent
else if s = '40percent' then hs := HatchStyle40Percent
else if s = '50percent' then hs := HatchStyle50Percent
else if s = '60percent' then hs := HatchStyle60Percent
else if s = '70percent' then hs := HatchStyle70Percent
else if s = '75percent' then hs := HatchStyle75Percent
else if s = '80percent' then hs := HatchStyle80Percent
else if s = '90percent' then hs := HatchStyle90Percent
else if s = 'lightdownwarddiagonal' then hs := HatchStyleLightDownwardDiagonal
else if s = 'lightupwarddiagonal' then hs := HatchStyleLightUpwardDiagonal
else if s = 'darkdownwarddiagonal' then hs := HatchStyleDarkDownwardDiagonal
else if s = 'darkupwarddiagonal' then hs := HatchStyleDarkUpwardDiagonal
else if s = 'widedownwarddiagonal' then hs := HatchStyleWideDownwardDiagonal
else if s = 'wideupwarddiagonal' then hs := HatchStyleWideUpwardDiagonal
else if s = 'lightvertical' then hs := HatchStyleLightVertical
else if s = 'lighthorizontal' then hs := HatchStyleLightHorizontal
else if s = 'narrowvertical' then hs := HatchStyleNarrowVertical
else if s = 'narrowhorizontal' then hs := HatchStyleNarrowHorizontal
else if s = 'darkvertical' then hs := HatchStyleDarkVertical
else if s = 'darkhorizontal' then hs := HatchStyleDarkHorizontal
else if s = 'dasheddownwarddiagonal' then hs := HatchStyleDashedDownwardDiagonal
else if s = 'dashedupwarddiagonal' then hs := HatchStyleDashedUpwardDiagonal
else if s = 'dashedhorizontal' then hs := HatchStyleDashedHorizontal
else if s = 'dashedvertical' then hs := HatchStyleDashedVertical
else if s = 'smallconfetti' then hs := HatchStyleSmallConfetti
else if s = 'largeconfetti' then hs := HatchStyleLargeConfetti
else if s = 'zigzag' then hs := HatchStyleZigZag
else if s = 'wave' then hs := HatchStyleWave
else if s = 'diagonalbrick' then hs := HatchStyleDiagonalBrick
else if s = 'horizontalbrick' then hs := HatchStyleHorizontalBrick
else if s = 'weave' then hs := HatchStyleWeave
else if s = 'plaid' then hs := HatchStylePlaid
else if s = 'divot' then hs := HatchStyleDivot
else if s = 'dottedgrid' then hs := HatchStyleDottedGrid
else if s = 'dotteddiamond' then hs := HatchStyleDottedDiamond
else if s = 'shingle' then hs := HatchStyleShingle
else if s = 'trellis' then hs := HatchStyleTrellis
else if s = 'sphere' then hs := HatchStyleSphere
else if s = 'smallgrid' then hs := HatchStyleSmallGrid
else if s = 'smallcheckerboard' then hs := HatchStyleSmallCheckerBoard
else if s = 'largecheckerboard' then hs := HatchStyleLargeCheckerBoard
else if s = 'outlineddiamond' then hs := HatchStyleOutlinedDiamond
else if s = 'soliddiamond' then hs := HatchStyleSolidDiamond
else Exit;
Result := True;
end;
function GPPointF(const ax, ay: Single): TPointF;
begin
Result.x := ax;
Result.y := ay;
end;
function GPPointF(const apt: TPoint): TPointF;
begin
Result.x := apt.X;
Result.y := apt.Y;
end;
function GPPointFMove(const Point: TPointF; const dx, dy: Single): TPointF;
begin
Result.X := Point.X + dx;
Result.Y := Point.Y + dy;
end;
function GPColor(const AColor: TColor; Alpha: Byte): TAlphaColor;
begin
Result := GPMakeColor(Alpha, AColor);
end;
{$IFDEF MSWINDOWS}
function GPTextWidthF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
var
RectF: TIGPRectF;
begin
RectF := gr.GetStringBoundingBoxF(WideString(Text), Font, GPPointF(px, py));
Result := RectF.Width;
end;
function GPTextHeightF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
var
RectF: TIGPRectF;
begin
RectF := gr.GetStringBoundingBoxF(WideString(Text), Font, GPPointF(px, py));
Result := RectF.Height;
end;
{$ENDIF}
{$IFDEF FPC}
class function TPointFHelper.Create(const ax, ay: Single): TPointF;
begin
Result.x := ax;
Result.y := ay;
end;
class function TPointFHelper.Create(const apt: TPoint): TPointF;
begin
Result.x := apt.X;
Result.y := apt.Y;
end;
{$ENDIF}
end.