-
Notifications
You must be signed in to change notification settings - Fork 12
/
bgracustomtextfx.pas
616 lines (548 loc) · 20.9 KB
/
bgracustomtextfx.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
{ ***************************************************************************
* *
* This file is part of BGRABitmap library which is distributed under the *
* modified LGPL. *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
************************* BGRABitmap library ******************************
- Drawing routines with transparency and antialiasing with Lazarus.
Offers also various transforms.
- These routines allow to manipulate 32bit images in BGRA format or RGBA
format (depending on the platform).
- This code is under modified LGPL (see COPYING.modifiedLGPL.txt).
This means that you can link this library inside your programs for any purpose.
Only the included part of the code must remain LGPL.
- If you make some improvements to this library, please notify here:
http://www.lazarus.freepascal.org/index.php/topic,12037.0.html
********************* Contact : Circular at operamail.com *******************
******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with FPC ($Mode objfpc/delphi) and delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
Unit BGRACustomTextFX;
{$i bgrabitmap.inc}{$H+}
interface
uses
Classes, SysUtils, Types, BGRATypes, BGRABitmapTypes, BGRAPhongTypes, BGRAGraphics;
const DefaultOutlineWidth = 3;
type
{ TBGRACustomTextEffect }
TBGRACustomTextEffect = class
private
function GetBounds: TRect;
function GetMaskHeight: integer;
class function GetOutlineWidth: integer; static;
function GetShadowBounds(ARadius: integer): TRect;
function GetMaskWidth: integer;
function GetTextHeight: integer;
function GetTextWidth: integer;
procedure SetShadowQuality(AValue: TRadialBlurType);
protected
FShadowQuality: TRadialBlurType;
FTextMask: TBGRACustomBitmap;
FShadowRadius: integer;
FOutlineMask, FShadowMask, FShadingMask : TBGRACustomBitmap;
FShadingAltitude: integer;
FShadingRounded: boolean;
FTextSize: TSize;
FOffset: TPoint;
function DrawMaskMulticolored(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; const AColors: array of TBGRAPixel): TRect;
function DrawMask(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; AColor: TBGRAPixel): TRect; overload;
function DrawMask(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; ATexture: IBGRAScanner): TRect; overload;
function InternalDrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; ATexture: IBGRAScanner; ARounded: Boolean): TRect;
public
constructor Create(AMask: TBGRACustomBitmap; AMaskOwner: boolean; AWidth,AHeight: integer; AOffset: TPoint);
procedure ApplySphere;
procedure ApplyVerticalCylinder;
procedure ApplyHorizontalCylinder;
function Draw(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel): TRect; overload;
function Draw(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner): TRect; overload;
function Draw(ADest: TBGRACustomBitmap; X, Y: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect; overload;
function Draw(ADest: TBGRACustomBitmap; X, Y: integer; ATexture: IBGRAScanner; AAlign: TAlignment): TRect; overload;
function DrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; ARounded: Boolean = true): TRect; overload;
function DrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner; ARounded: Boolean = true): TRect; overload;
function DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; AAlign: TAlignment; ARounded: Boolean = true): TRect; overload;
function DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer; Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner; AAlign: TAlignment; ARounded: Boolean = true): TRect; overload;
function DrawMulticolored(ADest: TBGRACustomBitmap; X,Y: integer; const AColors: array of TBGRAPixel): TRect; overload;
function DrawMulticolored(ADest: TBGRACustomBitmap; X,Y: integer; const AColors: array of TBGRAPixel; AAlign: TAlignment): TRect; overload;
function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel): TRect; overload;
function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner): TRect; overload;
function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect; overload;
function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner; AAlign: TAlignment): TRect; overload;
function DrawShadow(ADest: TBGRACustomBitmap; X,Y,Radius: integer; AColor: TBGRAPixel): TRect; overload;
function DrawShadow(ADest: TBGRACustomBitmap; X,Y,Radius: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect; overload;
destructor Destroy; override;
property TextMask: TBGRACustomBitmap read FTextMask;
property TextMaskOffset: TPoint read FOffset;
property Width: integer read GetTextWidth; {$IFDEF FPC}deprecated;{$ENDIF}
property Height: integer read GetTextHeight; {$IFDEF FPC}deprecated;{$ENDIF}
property MaskWidth: integer read GetMaskWidth;
property MaskHeight: integer read GetMaskHeight;
property TextSize: TSize read FTextSize;
property TextWidth: integer read GetTextWidth;
property TextHeight: integer read GetTextHeight;
property Bounds: TRect read GetBounds;
property ShadowBounds[ARadius: integer]: TRect read GetShadowBounds;
property ShadowQuality: TRadialBlurType read FShadowQuality write SetShadowQuality;
class property OutlineWidth: integer read GetOutlineWidth;
end;
implementation
uses Math, BGRAGradientScanner;
procedure BGRACustomReplace(var Destination: TBGRACustomBitmap; Temp: TObject);
begin
Destination.Free;
Destination := Temp as TBGRACustomBitmap;
end;
{ TBGRACustomTextEffect }
function TBGRACustomTextEffect.GetBounds: TRect;
begin
if TextMask = nil then
result := EmptyRect else
with TextMaskOffset do
result := rect(X,Y,X+TextMask.Width,Y+TextMask.Height);
end;
function TBGRACustomTextEffect.GetMaskHeight: integer;
begin
if FTextMask = nil then
result := 0
else
result := FTextMask.Height;
end;
class function TBGRACustomTextEffect.GetOutlineWidth: integer;{$IFDEF OBJ}static;{$ENDIF}
begin
result := DefaultOutlineWidth;
end;
function TBGRACustomTextEffect.GetShadowBounds(ARadius: integer): TRect;
begin
result := Bounds;
if (ARadius > 0) and not IsRectEmpty(result) then
begin
result.left := result.left -ARadius;
result.top := result.top -ARadius;
result.right := result.right +ARadius;
result.bottom := result.bottom +ARadius;
end;
end;
function TBGRACustomTextEffect.GetMaskWidth: integer;
begin
if FTextMask = nil then
result := 0
else
result := FTextMask.Width;
end;
function TBGRACustomTextEffect.GetTextHeight: integer;
begin
result := FTextSize.cy;
end;
function TBGRACustomTextEffect.GetTextWidth: integer;
begin
result := FTextSize.cx;
end;
procedure TBGRACustomTextEffect.SetShadowQuality(AValue: TRadialBlurType);
begin
if FShadowQuality=AValue then Exit;
FShadowQuality:=AValue;
FreeAndNil(FShadowMask);
end;
function TBGRACustomTextEffect.DrawMaskMulticolored(ADest: TBGRACustomBitmap;
AMask: TBGRACustomBitmap; X, Y: Integer; const AColors: array of TBGRAPixel
): TRect;
var
scan: TBGRASolidColorMaskScanner;
xb,yb,startX,numColor: integer;
p0,p: PBGRAPixel;
emptyCol, nextCol: boolean;
begin
if (AMask = nil) or (length(AColors)=0) then
begin
result := EmptyRect;
exit;
end;
if (length(AColors)=0) then
begin
result := DrawMask(ADest,AMask,X,Y,AColors[0]);
exit;
end;
scan := TBGRASolidColorMaskScanner.Create(AMask,Point(-X,-Y),AColors[0]);
numColor := 0;
startX := -1;
p0 := AMask.data;
for xb := 0 to AMask.Width-1 do
begin
p := p0;
if startX=-1 then
begin
emptyCol := true;
for yb := AMask.Height-1 downto 0 do
begin
if not BGRAPixelEqual(p^,{<>}BGRABlack) then
begin
emptyCol := false;
break;
end;
inc(p, AMask.Width);
end;
if not emptyCol then
begin
if startX=-1 then
startX := xb;
end else
begin
if startX<>-1 then
begin
ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);
inc(numColor);
if numColor = length(AColors) then
numColor := 0;
scan.Color := AColors[numColor];
startX := -1;
end;
end;
end else
begin
emptyCol := true;
nextCol := true;
for yb := AMask.Height-1 downto 0 do
begin
if not BGRAPixelEqual(p^,{<>}BGRABlack) then
begin
emptyCol := false;
if not BGRAPixelEqual((p-1)^,{<>}BGRABlack) then
begin
nextCol := false;
break;
end;
end;
inc(p, AMask.Width);
end;
if nextCol or emptyCol then
begin
ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);
inc(numColor);
if numColor = length(AColors) then
numColor := 0;
scan.Color := AColors[numColor];
if emptyCol then startX := -1
else startX := xb;
end;
end;
inc(p0);
end;
if startX<>-1 then
ADest.FillRect(X+startX,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
scan.Free;
result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
end;
function TBGRACustomTextEffect.DrawMask(ADest: TBGRACustomBitmap;
AMask: TBGRACustomBitmap; X, Y: Integer; AColor: TBGRAPixel): TRect;
var
scan: TBGRACustomScanner;
begin
if AMask = nil then
begin
result := EmptyRect;
exit;
end;
scan := TBGRASolidColorMaskScanner.Create(AMask,Point(-X,-Y),AColor);
ADest.FillRect(X,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
scan.Free;
result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
end;
function TBGRACustomTextEffect.DrawMask(ADest: TBGRACustomBitmap;
AMask: TBGRACustomBitmap; X, Y: Integer; ATexture: IBGRAScanner): TRect;
var
scan: TBGRACustomScanner;
begin
if AMask = nil then
begin
result := EmptyRect;
exit;
end;
scan := TBGRATextureMaskScanner.Create(AMask,Point(-X,-Y),ATexture);
ADest.FillRect(X,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
scan.Free;
result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
end;
function TBGRACustomTextEffect.InternalDrawShaded(ADest: TBGRACustomBitmap; X,
Y: integer; Shader: TCustomPhongShading; Altitude: integer;
AColor: TBGRAPixel; ATexture: IBGRAScanner; ARounded: Boolean): TRect;
var
WithMargin,Map: TBGRACustomBitmap;
p: PBGRAPixel;
n,maxv: integer;
v,blurRadius: single;
iBlurRadius: integer;
begin
if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
begin
result := EmptyRect;
exit;
end;
if (FShadingMask <> nil) and ((FShadingAltitude <> Altitude) or (FShadingRounded <> ARounded)) then
FreeAndNil(FShadingMask);
if FShadingMask = nil then
begin
FShadingRounded := ARounded;
FShadingAltitude := Altitude;
if ARounded then blurRadius := Altitude
else blurRadius := Altitude*0.5;
iBlurRadius := ceil(blurRadius);
WithMargin := BGRABitmapFactory.Create(FTextMask.Width+iBlurRadius*2, FTextMask.Height+iBlurRadius*2,BGRABlack);
WithMargin.PutImage(iBlurRadius,iBlurRadius,FTextMask,dmSet);
if (iBlurRadius <> blurRadius) and (blurRadius < 3) then
Map := WithMargin.FilterBlurRadial(round(blurRadius*10),rbPrecise)
else
Map := WithMargin.FilterBlurRadial(iBlurRadius,rbFast);
p := Map.Data;
maxv := 0;
for n := Map.NbPixels-1 downto 0 do
begin
if p^.green > maxv then
maxv := p^.green;
inc(p);
end;
if maxv > 0 then
begin
p := Map.Data;
for n := Map.NbPixels-1 downto 0 do
begin
v := p^.green/maxv;
if ARounded then
begin
if v <= 0.5 then
v := v*v*2 else
v := 1-(1-v)*(1-v)*2;
end;
p^ := MapHeightToBGRA( v, p^.alpha);
inc(p);
end;
end;
Map.ApplyMask(WithMargin);
WithMargin.Free;
BGRACustomReplace(Map, Map.GetPart(rect(iBlurRadius,iBlurRadius,Map.Width-iBlurRadius,Map.Height-iBlurRadius)));
FShadingMask := Map;
end;
inc(X, FOffset.X);
Inc(Y, FOffset.Y);
if ATexture <> nil then
Shader.DrawScan(ADest,FShadingMask,Altitude,X,Y, ATexture)
else
Shader.Draw(ADest,FShadingMask,Altitude,X,Y, AColor);
result := rect(X,Y, X+FShadingMask.Width,Y+FShadingMask.Height);
end;
function TBGRACustomTextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
AColor: TBGRAPixel; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := Draw(ADest,X-TextSize.cx,Y,AColor);
taCenter: result := Draw(ADest,X-TextSize.cx div 2,Y,AColor);
else result := Draw(ADest,X,Y,AColor);
end;
end;
function TBGRACustomTextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := Draw(ADest,X-TextSize.cx,Y,ATexture);
taCenter: result := Draw(ADest,X-TextSize.cx div 2,Y,ATexture);
else result := Draw(ADest,X,Y,ATexture);
end;
end;
function TBGRACustomTextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel;
ARounded: Boolean): TRect;
begin
result := InternalDrawShaded(ADest,X,Y,Shader,Altitude,AColor,nil,ARounded);
end;
function TBGRACustomTextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner;
ARounded: Boolean): TRect;
begin
result := InternalDrawShaded(ADest,X,Y,Shader,Altitude,BGRAPixelTransparent,ATexture,ARounded);
end;
function TBGRACustomTextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel;
AAlign: TAlignment; ARounded: Boolean): TRect;
begin
Case AAlign of
taLeftJustify: result := DrawShaded(ADest,X,Y,Shader,Altitude,AColor,ARounded);
taRightJustify: result := DrawShaded(ADest,X-TextSize.cx,Y,Shader,Altitude,AColor,ARounded);
taCenter: result := DrawShaded(ADest,X-TextSize.cx div 2,Y,Shader,Altitude,AColor,ARounded);
else
result := EmptyRect;
end;
end;
function TBGRACustomTextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner;
AAlign: TAlignment; ARounded: Boolean): TRect;
begin
Case AAlign of
taLeftJustify: result := DrawShaded(ADest,X,Y,Shader,Altitude,ATexture,ARounded);
taRightJustify: result := DrawShaded(ADest,X-TextSize.cx,Y,Shader,Altitude,ATexture,ARounded);
taCenter: result := DrawShaded(ADest,X-TextSize.cx div 2,Y,Shader,Altitude,ATexture,ARounded);
else
result := EmptyRect;
end;
end;
constructor TBGRACustomTextEffect.Create(AMask: TBGRACustomBitmap; AMaskOwner: boolean; AWidth,
AHeight: integer; AOffset: TPoint);
begin
{$IFDEF BDS}
FTextSize.cx := AWidth;
FTextSize.cy := AHeight;
{$ELSE}
FTextSize := Size(AWidth,AHeight);
{$ENDIF}
FOffset := AOffset;
if not AMaskOwner then
FTextMask := AMask.Duplicate()
else
FTextMask := AMask;
end;
procedure TBGRACustomTextEffect.ApplySphere;
var sphere: TBGRACustomBitmap;
begin
if FTextMask = nil then exit;
FreeAndNil(FOutlineMask);
FreeAndNil(FShadowMask);
FShadowRadius := 0;
sphere := FTextMask.FilterSphere;
FTextMask.Fill(BGRABlack);
FTextMask.PutImage(0,0,sphere,dmDrawWithTransparency);
sphere.Free;
end;
procedure TBGRACustomTextEffect.ApplyVerticalCylinder;
begin
if FTextMask = nil then exit;
FreeAndNil(FOutlineMask);
FreeAndNil(FShadowMask);
FShadowRadius := 0;
BGRACustomReplace(FTextMask,FTextMask.FilterCylinder);
end;
procedure TBGRACustomTextEffect.ApplyHorizontalCylinder;
begin
if FTextMask = nil then exit;
FreeAndNil(FOutlineMask);
FreeAndNil(FShadowMask);
FShadowRadius := 0;
BGRACustomReplace(FTextMask,FTextMask.RotateCW);
BGRACustomReplace(FTextMask,FTextMask.FilterCylinder);
BGRACustomReplace(FTextMask,FTextMask.RotateCCW);
end;
function TBGRACustomTextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
AColor: TBGRAPixel): TRect;
begin
result := DrawMask(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,AColor);
end;
function TBGRACustomTextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
ATexture: IBGRAScanner): TRect;
begin
result := DrawMask(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,ATexture);
end;
function TBGRACustomTextEffect.DrawMulticolored(ADest: TBGRACustomBitmap; X,
Y: integer; const AColors: array of TBGRAPixel): TRect;
begin
result := DrawMaskMulticolored(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,AColors);
end;
function TBGRACustomTextEffect.DrawMulticolored(ADest: TBGRACustomBitmap; X,
Y: integer; const AColors: array of TBGRAPixel; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := DrawMulticolored(ADest,X-TextSize.cx,Y,AColors);
taCenter: result := DrawMulticolored(ADest,X-TextSize.cx div 2,Y,AColors);
else result := DrawMulticolored(ADest,X,Y,AColors);
end;
end;
function TBGRACustomTextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
AColor: TBGRAPixel): TRect;
begin
if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
begin
result := EmptyRect;
exit;
end;
if FOutlineMask = nil then
begin
FOutlineMask := FTextMask.FilterContour;
FOutlineMask.LinearNegative;
end;
result := DrawMask(ADest,FOutlineMask,X+FOffset.X,Y+FOffset.Y,AColor);
end;
function TBGRACustomTextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
ATexture: IBGRAScanner): TRect;
begin
if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
begin
result := EmptyRect;
exit;
end;
if FOutlineMask = nil then
begin
FOutlineMask := FTextMask.FilterContour;
FOutlineMask.LinearNegative;
end;
result := DrawMask(ADest,FOutlineMask,X+FOffset.X,Y+FOffset.Y,ATexture);
end;
function TBGRACustomTextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
AColor: TBGRAPixel; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := DrawOutline(ADest,X-TextSize.cx,Y,AColor);
taCenter: result := DrawOutline(ADest,X-TextSize.cx div 2,Y,AColor);
else result := DrawOutline(ADest,X,Y,AColor);
end;
end;
function TBGRACustomTextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := DrawOutline(ADest,X-TextSize.cx,Y,ATexture);
taCenter: result := DrawOutline(ADest,X-TextSize.cx div 2,Y,ATexture);
else result := DrawOutline(ADest,X,Y,ATexture);
end;
end;
function TBGRACustomTextEffect.DrawShadow(ADest: TBGRACustomBitmap; X, Y,
Radius: integer; AColor: TBGRAPixel): TRect;
begin
if (Radius <= 0) or (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
begin
result := Draw(ADest,X,Y,AColor);
exit;
end;
if (FShadowRadius <> Radius) or (FShadowMask = nil) then
begin
FShadowRadius := Radius;
FreeAndNil(FShadowMask);
FShadowMask := BGRABitmapFactory.Create(FTextMask.Width+Radius*2,FTextMask.Height+Radius*2,BGRABlack);
FShadowMask.PutImage(Radius,Radius,FTextMask,dmSet);
BGRACustomReplace(FShadowMask, FShadowMask.FilterBlurRadial(Radius,ShadowQuality));
end;
Inc(X,FOffset.X-Radius);
Inc(Y,FOffset.Y-Radius);
DrawMask(ADest,FShadowMask,X,Y,AColor);
result := rect(X,Y,X+FShadowMask.Width,Y+FShadowMask.Height);
end;
function TBGRACustomTextEffect.DrawShadow(ADest: TBGRACustomBitmap; X, Y,
Radius: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect;
begin
Case AAlign of
taRightJustify: result := DrawShadow(ADest,X-TextSize.cx,Y,Radius,AColor);
taCenter: result := DrawShadow(ADest,X-TextSize.cx div 2,Y,Radius,AColor);
else result := DrawShadow(ADest,X,Y,Radius,AColor);
end;
end;
destructor TBGRACustomTextEffect.Destroy;
begin
FShadowMask.free;
textMask.Free;
FOutlineMask.Free;
FShadingMask.Free;
inherited Destroy;
end;
end.