Ignore:
Timestamp:
Dec 22, 2016, 8:49:19 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgratextfx.pas

    r472 r494  
    2626
    2727uses
    28   Classes, SysUtils, Graphics, Types, BGRABitmapTypes, BGRAPhongTypes, BGRAText, BGRAVectorize;
     28  Classes, SysUtils, Graphics, Types, BGRABitmapTypes, BGRAPhongTypes, BGRAText,
     29  BGRACustomTextFX, BGRAVectorize;
    2930
    3031type
     
    8081  { TBGRATextEffect }
    8182
    82   TBGRATextEffect = class
    83   private
    84     FShadowQuality: TRadialBlurType;
    85     function GetBounds: TRect;
    86     function GetMaskHeight: integer;
    87     class function GetOutlineWidth: integer; static;
    88     function GetShadowBounds(ARadius: integer): TRect;
    89     function GetMaskWidth: integer;
    90     function GetTextHeight: integer;
    91     function GetTextWidth: integer;
    92     procedure SetShadowQuality(AValue: TRadialBlurType);
     83  TBGRATextEffect = class(TBGRACustomTextEffect)
    9384  protected
    94     FTextMask: TBGRACustomBitmap;
    95     FShadowRadius: integer;
    96     FOutlineMask, FShadowMask, FShadingMask : TBGRACustomBitmap;
    97     FShadingAltitude: integer;
    98     FShadingRounded: boolean;
    99     FTextSize: TSize;
    100     FOffset: TPoint;
    101     function DrawMaskMulticolored(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; const AColors: array of TBGRAPixel): TRect;
    102     function DrawMask(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; AColor: TBGRAPixel): TRect;
    103     function DrawMask(ADest: TBGRACustomBitmap; AMask: TBGRACustomBitmap; X,Y: Integer; ATexture: IBGRAScanner): TRect;
    104     function InternalDrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; ATexture: IBGRAScanner; ARounded: Boolean): TRect;
    10585    procedure InitImproveReadability(AText: string; Font: TFont; SubOffsetX,SubOffsetY: single);
    10686    procedure Init(AText: string; Font: TFont; Antialiasing: boolean; SubOffsetX,SubOffsetY: single; GrainX, GrainY: Integer);
     
    11494    constructor Create(AText: string; AFontName: string; AFullHeight: integer; AStyle: TFontStyles; Antialiasing: boolean);
    11595    constructor Create(AText: string; AFontName: string; AFullHeight: integer; AStyle: TFontStyles; Antialiasing: boolean; SubOffsetX,SubOffsetY: single);
    116     constructor Create(AMask: TBGRACustomBitmap; AMaskOwner: boolean; AWidth,AHeight: integer; AOffset: TPoint);
    117     procedure ApplySphere;
    118     procedure ApplyVerticalCylinder;
    119     procedure ApplyHorizontalCylinder;
    120     function Draw(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel): TRect;
    121     function Draw(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner): TRect;
    122     function Draw(ADest: TBGRACustomBitmap; X, Y: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    123     function Draw(ADest: TBGRACustomBitmap; X, Y: integer; ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
    124 
    125     function DrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; ARounded: Boolean = true): TRect;
    126     function DrawShaded(ADest: TBGRACustomBitmap; X,Y: integer; Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner; ARounded: Boolean = true): TRect;
    127     function DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer; Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel; AAlign: TAlignment; ARounded: Boolean = true): TRect;
    128     function DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer; Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner; AAlign: TAlignment; ARounded: Boolean = true): TRect;
    129 
    130     function DrawMulticolored(ADest: TBGRACustomBitmap; X,Y: integer; const AColors: array of TBGRAPixel): TRect;
    131     function DrawMulticolored(ADest: TBGRACustomBitmap; X,Y: integer; const AColors: array of TBGRAPixel; AAlign: TAlignment): TRect;
    132     function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel): TRect;
    133     function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner): TRect;
    134     function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    135     function DrawOutline(ADest: TBGRACustomBitmap; X,Y: integer; ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
    136     function DrawShadow(ADest: TBGRACustomBitmap; X,Y,Radius: integer; AColor: TBGRAPixel): TRect;
    137     function DrawShadow(ADest: TBGRACustomBitmap; X,Y,Radius: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    138     destructor Destroy; override;
    139     property TextMask: TBGRACustomBitmap read FTextMask;
    140     property TextMaskOffset: TPoint read FOffset;
    141     property Width: integer read GetTextWidth; deprecated;
    142     property Height: integer read GetTextHeight; deprecated;
    143     property MaskWidth: integer read GetMaskWidth;
    144     property MaskHeight: integer read GetMaskHeight;
    145     property TextSize: TSize read FTextSize;
    146     property TextWidth: integer read GetTextWidth;
    147     property TextHeight: integer read GetTextHeight;
    148     property Bounds: TRect read GetBounds;
    149     property ShadowBounds[ARadius: integer]: TRect read GetShadowBounds;
    150     property ShadowQuality: TRadialBlurType read FShadowQuality write SetShadowQuality;
    151     class property OutlineWidth: integer read GetOutlineWidth;
    15296  end;
    15397
     
    160104
    161105uses BGRAGradientScanner, GraphType, Math, BGRAGrayscaleMask;
    162 
    163 const DefaultOutlineWidth = 3;
    164106
    165107procedure BGRATextOutImproveReadability(bmp: TBGRACustomBitmap; AFont: TFont; xf,yf: single; text: string; color: TBGRAPixel; tex: IBGRAScanner; align: TAlignment; mode : TBGRATextOutImproveReadabilityMode);
     
    190132  FxFont.Assign(AFont);
    191133  FxFont.Height := fxFont.Height*FontAntialiasingLevel;
    192   metric := GetFontPixelMetric(FxFont);
     134  metric := GetLCLFontPixelMetric(FxFont);
    193135  if not metric.Defined or (metric.Lineheight < 8*FontAntialiasingLevel) or (metric.Lineheight >= 24*FontAntialiasingLevel) then
    194136  begin
     
    579521{ TBGRATextEffect }
    580522
    581 function TBGRATextEffect.GetBounds: TRect;
    582 begin
    583   if TextMask = nil then
    584     result := EmptyRect else
    585   with TextMaskOffset do
    586     result := rect(X,Y,X+TextMask.Width,Y+TextMask.Height);
    587 end;
    588 
    589 function TBGRATextEffect.GetMaskHeight: integer;
    590 begin
    591   if FTextMask = nil then
    592     result := 0
    593   else
    594     result := FTextMask.Height;
    595 end;
    596 
    597 class function TBGRATextEffect.GetOutlineWidth: integer; static;
    598 begin
    599   result := DefaultOutlineWidth;
    600 end;
    601 
    602 function TBGRATextEffect.GetShadowBounds(ARadius: integer): TRect;
    603 begin
    604   result := Bounds;
    605   if (ARadius > 0) and not IsRectEmpty(result) then
    606   begin
    607     result.left -= ARadius;
    608     result.top -= ARadius;
    609     result.right += ARadius;
    610     result.bottom += ARadius;
    611   end;
    612 end;
    613 
    614 function TBGRATextEffect.GetMaskWidth: integer;
    615 begin
    616   if FTextMask = nil then
    617     result := 0
    618   else
    619     result := FTextMask.Width;
    620 end;
    621 
    622 function TBGRATextEffect.GetTextHeight: integer;
    623 begin
    624   result := FTextSize.cy;
    625 end;
    626 
    627 function TBGRATextEffect.GetTextWidth: integer;
    628 begin
    629   result := FTextSize.cx;
    630 end;
    631 
    632 procedure TBGRATextEffect.SetShadowQuality(AValue: TRadialBlurType);
    633 begin
    634   if FShadowQuality=AValue then Exit;
    635   FShadowQuality:=AValue;
    636   FreeAndNil(FShadowMask);
    637 end;
    638 
    639 function TBGRATextEffect.DrawMaskMulticolored(ADest: TBGRACustomBitmap;
    640   AMask: TBGRACustomBitmap; X, Y: Integer; const AColors: array of TBGRAPixel
    641   ): TRect;
    642 var
    643   scan: TBGRASolidColorMaskScanner;
    644   xb,yb,startX,numColor: integer;
    645   p0,p: PBGRAPixel;
    646   emptyCol, nextCol: boolean;
    647 begin
    648   if (AMask = nil) or (length(AColors)=0) then
    649   begin
    650     result := EmptyRect;
    651     exit;
    652   end;
    653   if (length(AColors)=0) then
    654   begin
    655     result := DrawMask(ADest,AMask,X,Y,AColors[0]);
    656     exit;
    657   end;
    658   scan := TBGRASolidColorMaskScanner.Create(AMask,Point(-X,-Y),AColors[0]);
    659   numColor := 0;
    660   startX := -1;
    661   p0 := AMask.data;
    662   for xb := 0 to AMask.Width-1 do
    663   begin
    664     p := p0;
    665 
    666     if startX=-1 then
    667     begin
    668       emptyCol := true;
    669       for yb := AMask.Height-1 downto 0 do
    670       begin
    671         if (p^<>BGRABlack) then
    672         begin
    673           emptyCol := false;
    674           break;
    675         end;
    676         inc(p, AMask.Width);
    677       end;
    678 
    679       if not emptyCol then
    680       begin
    681         if startX=-1 then
    682           startX := xb;
    683       end else
    684       begin
    685         if startX<>-1 then
    686         begin
    687           ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);
    688           inc(numColor);
    689           if numColor = length(AColors) then
    690             numColor := 0;
    691           scan.Color := AColors[numColor];
    692           startX := -1;
    693         end;
    694       end;
    695 
    696     end else
    697     begin
    698       emptyCol := true;
    699       nextCol := true;
    700       for yb := AMask.Height-1 downto 0 do
    701       begin
    702         if (p^<>BGRABlack) then
    703         begin
    704           emptyCol := false;
    705           if ((p-1)^<>BGRABlack) then
    706           begin
    707             nextCol := false;
    708             break;
    709           end;
    710         end;
    711         inc(p, AMask.Width);
    712       end;
    713       if nextCol or emptyCol then
    714       begin
    715         ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);
    716         inc(numColor);
    717         if numColor = length(AColors) then
    718           numColor := 0;
    719         scan.Color := AColors[numColor];
    720         if emptyCol then startX := -1
    721          else startX := xb;
    722       end;
    723     end;
    724 
    725     inc(p0);
    726   end;
    727   if startX<>-1 then
    728     ADest.FillRect(X+startX,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
    729   scan.Free;
    730   result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
    731 end;
    732 
    733 function TBGRATextEffect.DrawMask(ADest: TBGRACustomBitmap;
    734   AMask: TBGRACustomBitmap; X, Y: Integer; AColor: TBGRAPixel): TRect;
    735 var
    736   scan: TBGRACustomScanner;
    737 begin
    738   if AMask = nil then
    739   begin
    740     result := EmptyRect;
    741     exit;
    742   end;
    743   scan := TBGRASolidColorMaskScanner.Create(AMask,Point(-X,-Y),AColor);
    744   ADest.FillRect(X,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
    745   scan.Free;
    746   result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
    747 end;
    748 
    749 function TBGRATextEffect.DrawMask(ADest: TBGRACustomBitmap;
    750   AMask: TBGRACustomBitmap; X, Y: Integer; ATexture: IBGRAScanner): TRect;
    751 var
    752   scan: TBGRACustomScanner;
    753 begin
    754   if AMask = nil then
    755   begin
    756     result := EmptyRect;
    757     exit;
    758   end;
    759   scan := TBGRATextureMaskScanner.Create(AMask,Point(-X,-Y),ATexture);
    760   ADest.FillRect(X,Y,X+AMask.Width,Y+AMask.Height,scan,dmDrawWithTransparency);
    761   scan.Free;
    762   result := rect(X,Y,X+AMask.Width,Y+AMask.Height);
    763 end;
    764 
    765 function TBGRATextEffect.InternalDrawShaded(ADest: TBGRACustomBitmap; X,
    766   Y: integer; Shader: TCustomPhongShading; Altitude: integer;
    767   AColor: TBGRAPixel; ATexture: IBGRAScanner; ARounded: Boolean): TRect;
    768 var
    769   WithMargin,Map: TBGRACustomBitmap;
    770   p: PBGRAPixel;
    771   n,maxv: integer;
    772   v,blurRadius: single;
    773   iBlurRadius: integer;
    774 begin
    775   if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
    776   begin
    777     result := EmptyRect;
    778     exit;
    779   end;
    780 
    781   if (FShadingMask <> nil) and ((FShadingAltitude <> Altitude) or (FShadingRounded <> ARounded)) then
    782     FreeAndNil(FShadingMask);
    783 
    784   if FShadingMask = nil then
    785   begin
    786     FShadingRounded := ARounded;
    787     FShadingAltitude := Altitude;
    788 
    789     if ARounded then blurRadius := Altitude
    790       else blurRadius := Altitude*0.5;
    791 
    792     iBlurRadius := ceil(blurRadius);
    793 
    794     WithMargin := BGRABitmapFactory.Create(FTextMask.Width+iBlurRadius*2, FTextMask.Height+iBlurRadius*2,BGRABlack);
    795     WithMargin.PutImage(iBlurRadius,iBlurRadius,FTextMask,dmSet);
    796     if (iBlurRadius <> blurRadius) and (blurRadius < 3) then
    797       Map := WithMargin.FilterBlurRadial(round(blurRadius*10),rbPrecise)
    798     else
    799       Map := WithMargin.FilterBlurRadial(iBlurRadius,rbFast);
    800 
    801     p := Map.Data;
    802     maxv := 0;
    803     for n := Map.NbPixels-1 downto 0 do
    804     begin
    805       if p^.green > maxv then
    806         maxv := p^.green;
    807       inc(p);
    808     end;
    809 
    810     if maxv > 0 then
    811     begin
    812       p := Map.Data;
    813       for n := Map.NbPixels-1 downto 0 do
    814       begin
    815         v := p^.green/maxv;
    816         if ARounded then
    817         begin
    818           if v <= 0.5 then
    819             v := v*v*2 else
    820             v := 1-(1-v)*(1-v)*2;
    821         end;
    822         p^ := MapHeightToBGRA( v, p^.alpha);
    823         inc(p);
    824       end;
    825     end;
    826 
    827     Map.ApplyMask(WithMargin);
    828     WithMargin.Free;
    829     BGRAReplace(Map, Map.GetPart(rect(iBlurRadius,iBlurRadius,Map.Width-iBlurRadius,Map.Height-iBlurRadius)));
    830     FShadingMask := Map;
    831   end;
    832 
    833   inc(X, FOffset.X);
    834   Inc(Y, FOffset.Y);
    835   if ATexture <> nil then
    836     Shader.DrawScan(ADest,FShadingMask,Altitude,X,Y, ATexture)
    837   else
    838     Shader.Draw(ADest,FShadingMask,Altitude,X,Y, AColor);
    839   result := rect(X,Y, X+FShadingMask.Width,Y+FShadingMask.Height);
    840 end;
    841 
    842523procedure TBGRATextEffect.InitImproveReadability(AText: string; Font: TFont;
    843524  SubOffsetX, SubOffsetY: single);
     
    859540end;
    860541
    861 function TBGRATextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
    862   AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    863 begin
    864   Case AAlign of
    865   taRightJustify: result := Draw(ADest,X-TextSize.cx,Y,AColor);
    866   taCenter: result := Draw(ADest,X-TextSize.cx div 2,Y,AColor);
    867   else result := Draw(ADest,X,Y,AColor);
    868   end;
    869 end;
    870 
    871 function TBGRATextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
    872   ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
    873 begin
    874   Case AAlign of
    875   taRightJustify: result := Draw(ADest,X-TextSize.cx,Y,ATexture);
    876   taCenter: result := Draw(ADest,X-TextSize.cx div 2,Y,ATexture);
    877   else result := Draw(ADest,X,Y,ATexture);
    878   end;
    879 end;
    880 
    881 function TBGRATextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
    882   Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel;
    883   ARounded: Boolean): TRect;
    884 begin
    885   result := InternalDrawShaded(ADest,X,Y,Shader,Altitude,AColor,nil,ARounded);
    886 end;
    887 
    888 function TBGRATextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
    889   Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner;
    890   ARounded: Boolean): TRect;
    891 begin
    892   result := InternalDrawShaded(ADest,X,Y,Shader,Altitude,BGRAPixelTransparent,ATexture,ARounded);
    893 end;
    894 
    895 function TBGRATextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
    896   Shader: TCustomPhongShading; Altitude: integer; AColor: TBGRAPixel;
    897   AAlign: TAlignment; ARounded: Boolean): TRect;
    898 begin
    899   Case AAlign of
    900   taLeftJustify: result := DrawShaded(ADest,X,Y,Shader,Altitude,AColor,ARounded);
    901   taRightJustify: result := DrawShaded(ADest,X-TextSize.cx,Y,Shader,Altitude,AColor,ARounded);
    902   taCenter: result := DrawShaded(ADest,X-TextSize.cx div 2,Y,Shader,Altitude,AColor,ARounded);
    903   else
    904     result := EmptyRect;
    905   end;
    906 end;
    907 
    908 function TBGRATextEffect.DrawShaded(ADest: TBGRACustomBitmap; X, Y: integer;
    909   Shader: TCustomPhongShading; Altitude: integer; ATexture: IBGRAScanner;
    910   AAlign: TAlignment; ARounded: Boolean): TRect;
    911 begin
    912   Case AAlign of
    913   taLeftJustify: result := DrawShaded(ADest,X,Y,Shader,Altitude,ATexture,ARounded);
    914   taRightJustify: result := DrawShaded(ADest,X-TextSize.cx,Y,Shader,Altitude,ATexture,ARounded);
    915   taCenter: result := DrawShaded(ADest,X-TextSize.cx div 2,Y,Shader,Altitude,ATexture,ARounded);
    916   else
    917     result := EmptyRect;
    918   end;
    919 end;
    920 
    921542constructor TBGRATextEffect.Create(AText: string; Font: TFont;
    922543  Antialiasing: boolean; SubOffsetX,SubOffsetY: single);
     
    955576begin
    956577  InitWithFontName(AText, AFontName, AFullHeight, AStyle, Antialiasing, SubOffsetX, SubOffsetY);
    957 end;
    958 
    959 constructor TBGRATextEffect.Create(AMask: TBGRACustomBitmap; AMaskOwner: boolean; AWidth,
    960   AHeight: integer; AOffset: TPoint);
    961 begin
    962   FTextSize := Size(AWidth,AHeight);
    963   FOffset := AOffset;
    964   if not AMaskOwner then
    965     FTextMask := AMask.Duplicate()
    966   else
    967     FTextMask := AMask;
    968578end;
    969579
     
    1126736end;
    1127737
    1128 procedure TBGRATextEffect.ApplySphere;
    1129 var sphere: TBGRACustomBitmap;
    1130 begin
    1131   if FTextMask = nil then exit;
    1132   FreeAndNil(FOutlineMask);
    1133   FreeAndNil(FShadowMask);
    1134   FShadowRadius := 0;
    1135   sphere := FTextMask.FilterSphere;
    1136   FTextMask.Fill(BGRABlack);
    1137   FTextMask.PutImage(0,0,sphere,dmDrawWithTransparency);
    1138   sphere.Free;
    1139 end;
    1140 
    1141 procedure TBGRATextEffect.ApplyVerticalCylinder;
    1142 begin
    1143   if FTextMask = nil then exit;
    1144   FreeAndNil(FOutlineMask);
    1145   FreeAndNil(FShadowMask);
    1146   FShadowRadius := 0;
    1147   BGRAReplace(FTextMask,FTextMask.FilterCylinder);
    1148 end;
    1149 
    1150 procedure TBGRATextEffect.ApplyHorizontalCylinder;
    1151 begin
    1152   if FTextMask = nil then exit;
    1153   FreeAndNil(FOutlineMask);
    1154   FreeAndNil(FShadowMask);
    1155   FShadowRadius := 0;
    1156   BGRAReplace(FTextMask,FTextMask.RotateCW);
    1157   BGRAReplace(FTextMask,FTextMask.FilterCylinder);
    1158   BGRAReplace(FTextMask,FTextMask.RotateCCW);
    1159 end;
    1160 
    1161 function TBGRATextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
    1162   AColor: TBGRAPixel): TRect;
    1163 begin
    1164   result := DrawMask(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,AColor);
    1165 end;
    1166 
    1167 function TBGRATextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;
    1168   ATexture: IBGRAScanner): TRect;
    1169 begin
    1170   result := DrawMask(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,ATexture);
    1171 end;
    1172 
    1173 function TBGRATextEffect.DrawMulticolored(ADest: TBGRACustomBitmap; X,
    1174   Y: integer; const AColors: array of TBGRAPixel): TRect;
    1175 begin
    1176   result := DrawMaskMulticolored(ADest,FTextMask,X+FOffset.X,Y+FOffset.Y,AColors);
    1177 end;
    1178 
    1179 function TBGRATextEffect.DrawMulticolored(ADest: TBGRACustomBitmap; X,
    1180   Y: integer; const AColors: array of TBGRAPixel; AAlign: TAlignment): TRect;
    1181 begin
    1182   Case AAlign of
    1183   taRightJustify: result := DrawMulticolored(ADest,X-TextSize.cx,Y,AColors);
    1184   taCenter: result := DrawMulticolored(ADest,X-TextSize.cx div 2,Y,AColors);
    1185   else result := DrawMulticolored(ADest,X,Y,AColors);
    1186   end;
    1187 end;
    1188 
    1189 function TBGRATextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
    1190   AColor: TBGRAPixel): TRect;
    1191 begin
    1192   if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
    1193   begin
    1194     result := EmptyRect;
    1195     exit;
    1196   end;
    1197   if FOutlineMask = nil then
    1198   begin
    1199     FOutlineMask := FTextMask.FilterContour;
    1200     FOutlineMask.LinearNegative;
    1201   end;
    1202   result := DrawMask(ADest,FOutlineMask,X+FOffset.X,Y+FOffset.Y,AColor);
    1203 end;
    1204 
    1205 function TBGRATextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
    1206   ATexture: IBGRAScanner): TRect;
    1207 begin
    1208   if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
    1209   begin
    1210     result := EmptyRect;
    1211     exit;
    1212   end;
    1213   if FOutlineMask = nil then
    1214   begin
    1215     FOutlineMask := FTextMask.FilterContour;
    1216     FOutlineMask.LinearNegative;
    1217   end;
    1218   result := DrawMask(ADest,FOutlineMask,X+FOffset.X,Y+FOffset.Y,ATexture);
    1219 end;
    1220 
    1221 function TBGRATextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
    1222   AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    1223 begin
    1224   Case AAlign of
    1225   taRightJustify: result := DrawOutline(ADest,X-TextSize.cx,Y,AColor);
    1226   taCenter: result := DrawOutline(ADest,X-TextSize.cx div 2,Y,AColor);
    1227   else result := DrawOutline(ADest,X,Y,AColor);
    1228   end;
    1229 end;
    1230 
    1231 function TBGRATextEffect.DrawOutline(ADest: TBGRACustomBitmap; X, Y: integer;
    1232   ATexture: IBGRAScanner; AAlign: TAlignment): TRect;
    1233 begin
    1234   Case AAlign of
    1235   taRightJustify: result := DrawOutline(ADest,X-TextSize.cx,Y,ATexture);
    1236   taCenter: result := DrawOutline(ADest,X-TextSize.cx div 2,Y,ATexture);
    1237   else result := DrawOutline(ADest,X,Y,ATexture);
    1238   end;
    1239 end;
    1240 
    1241 function TBGRATextEffect.DrawShadow(ADest: TBGRACustomBitmap; X, Y,
    1242   Radius: integer; AColor: TBGRAPixel): TRect;
    1243 begin
    1244   if (Radius <= 0) or (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then
    1245   begin
    1246     result := Draw(ADest,X,Y,AColor);
    1247     exit;
    1248   end;
    1249   if (FShadowRadius <> Radius) or (FShadowMask = nil) then
    1250   begin
    1251     FShadowRadius := Radius;
    1252     FreeAndNil(FShadowMask);
    1253     FShadowMask := BGRABitmapFactory.Create(FTextMask.Width+Radius*2,FTextMask.Height+Radius*2,BGRABlack);
    1254     FShadowMask.PutImage(Radius,Radius,FTextMask,dmSet);
    1255     BGRAReplace(FShadowMask, FShadowMask.FilterBlurRadial(Radius,ShadowQuality));
    1256   end;
    1257   Inc(X,FOffset.X-Radius);
    1258   Inc(Y,FOffset.Y-Radius);
    1259   DrawMask(ADest,FShadowMask,X,Y,AColor);
    1260   result := rect(X,Y,X+FShadowMask.Width,Y+FShadowMask.Height);
    1261 end;
    1262 
    1263 function TBGRATextEffect.DrawShadow(ADest: TBGRACustomBitmap; X, Y,
    1264   Radius: integer; AColor: TBGRAPixel; AAlign: TAlignment): TRect;
    1265 begin
    1266   Case AAlign of
    1267   taRightJustify: result := DrawShadow(ADest,X-TextSize.cx,Y,Radius,AColor);
    1268   taCenter: result := DrawShadow(ADest,X-TextSize.cx div 2,Y,Radius,AColor);
    1269   else result := DrawShadow(ADest,X,Y,Radius,AColor);
    1270   end;
    1271 end;
    1272 
    1273 destructor TBGRATextEffect.Destroy;
    1274 begin
    1275   FShadowMask.free;
    1276   textMask.Free;
    1277   FOutlineMask.Free;
    1278   FShadingMask.Free;
    1279   inherited Destroy;
    1280 end;
    1281 
    1282738initialization
    1283739
Note: See TracChangeset for help on using the changeset viewer.