Changeset 494 for GraphicTest/Packages/bgrabitmap/bgratextfx.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgratextfx.pas
r472 r494 26 26 27 27 uses 28 Classes, SysUtils, Graphics, Types, BGRABitmapTypes, BGRAPhongTypes, BGRAText, BGRAVectorize; 28 Classes, SysUtils, Graphics, Types, BGRABitmapTypes, BGRAPhongTypes, BGRAText, 29 BGRACustomTextFX, BGRAVectorize; 29 30 30 31 type … … 80 81 { TBGRATextEffect } 81 82 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) 93 84 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;105 85 procedure InitImproveReadability(AText: string; Font: TFont; SubOffsetX,SubOffsetY: single); 106 86 procedure Init(AText: string; Font: TFont; Antialiasing: boolean; SubOffsetX,SubOffsetY: single; GrainX, GrainY: Integer); … … 114 94 constructor Create(AText: string; AFontName: string; AFullHeight: integer; AStyle: TFontStyles; Antialiasing: boolean); 115 95 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;152 96 end; 153 97 … … 160 104 161 105 uses BGRAGradientScanner, GraphType, Math, BGRAGrayscaleMask; 162 163 const DefaultOutlineWidth = 3;164 106 165 107 procedure BGRATextOutImproveReadability(bmp: TBGRACustomBitmap; AFont: TFont; xf,yf: single; text: string; color: TBGRAPixel; tex: IBGRAScanner; align: TAlignment; mode : TBGRATextOutImproveReadabilityMode); … … 190 132 FxFont.Assign(AFont); 191 133 FxFont.Height := fxFont.Height*FontAntialiasingLevel; 192 metric := Get FontPixelMetric(FxFont);134 metric := GetLCLFontPixelMetric(FxFont); 193 135 if not metric.Defined or (metric.Lineheight < 8*FontAntialiasingLevel) or (metric.Lineheight >= 24*FontAntialiasingLevel) then 194 136 begin … … 579 521 { TBGRATextEffect } 580 522 581 function TBGRATextEffect.GetBounds: TRect;582 begin583 if TextMask = nil then584 result := EmptyRect else585 with TextMaskOffset do586 result := rect(X,Y,X+TextMask.Width,Y+TextMask.Height);587 end;588 589 function TBGRATextEffect.GetMaskHeight: integer;590 begin591 if FTextMask = nil then592 result := 0593 else594 result := FTextMask.Height;595 end;596 597 class function TBGRATextEffect.GetOutlineWidth: integer; static;598 begin599 result := DefaultOutlineWidth;600 end;601 602 function TBGRATextEffect.GetShadowBounds(ARadius: integer): TRect;603 begin604 result := Bounds;605 if (ARadius > 0) and not IsRectEmpty(result) then606 begin607 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 begin616 if FTextMask = nil then617 result := 0618 else619 result := FTextMask.Width;620 end;621 622 function TBGRATextEffect.GetTextHeight: integer;623 begin624 result := FTextSize.cy;625 end;626 627 function TBGRATextEffect.GetTextWidth: integer;628 begin629 result := FTextSize.cx;630 end;631 632 procedure TBGRATextEffect.SetShadowQuality(AValue: TRadialBlurType);633 begin634 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 TBGRAPixel641 ): TRect;642 var643 scan: TBGRASolidColorMaskScanner;644 xb,yb,startX,numColor: integer;645 p0,p: PBGRAPixel;646 emptyCol, nextCol: boolean;647 begin648 if (AMask = nil) or (length(AColors)=0) then649 begin650 result := EmptyRect;651 exit;652 end;653 if (length(AColors)=0) then654 begin655 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 do663 begin664 p := p0;665 666 if startX=-1 then667 begin668 emptyCol := true;669 for yb := AMask.Height-1 downto 0 do670 begin671 if (p^<>BGRABlack) then672 begin673 emptyCol := false;674 break;675 end;676 inc(p, AMask.Width);677 end;678 679 if not emptyCol then680 begin681 if startX=-1 then682 startX := xb;683 end else684 begin685 if startX<>-1 then686 begin687 ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);688 inc(numColor);689 if numColor = length(AColors) then690 numColor := 0;691 scan.Color := AColors[numColor];692 startX := -1;693 end;694 end;695 696 end else697 begin698 emptyCol := true;699 nextCol := true;700 for yb := AMask.Height-1 downto 0 do701 begin702 if (p^<>BGRABlack) then703 begin704 emptyCol := false;705 if ((p-1)^<>BGRABlack) then706 begin707 nextCol := false;708 break;709 end;710 end;711 inc(p, AMask.Width);712 end;713 if nextCol or emptyCol then714 begin715 ADest.FillRect(X+startX,Y,X+xb,Y+AMask.Height,scan,dmDrawWithTransparency);716 inc(numColor);717 if numColor = length(AColors) then718 numColor := 0;719 scan.Color := AColors[numColor];720 if emptyCol then startX := -1721 else startX := xb;722 end;723 end;724 725 inc(p0);726 end;727 if startX<>-1 then728 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 var736 scan: TBGRACustomScanner;737 begin738 if AMask = nil then739 begin740 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 var752 scan: TBGRACustomScanner;753 begin754 if AMask = nil then755 begin756 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 var769 WithMargin,Map: TBGRACustomBitmap;770 p: PBGRAPixel;771 n,maxv: integer;772 v,blurRadius: single;773 iBlurRadius: integer;774 begin775 if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then776 begin777 result := EmptyRect;778 exit;779 end;780 781 if (FShadingMask <> nil) and ((FShadingAltitude <> Altitude) or (FShadingRounded <> ARounded)) then782 FreeAndNil(FShadingMask);783 784 if FShadingMask = nil then785 begin786 FShadingRounded := ARounded;787 FShadingAltitude := Altitude;788 789 if ARounded then blurRadius := Altitude790 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) then797 Map := WithMargin.FilterBlurRadial(round(blurRadius*10),rbPrecise)798 else799 Map := WithMargin.FilterBlurRadial(iBlurRadius,rbFast);800 801 p := Map.Data;802 maxv := 0;803 for n := Map.NbPixels-1 downto 0 do804 begin805 if p^.green > maxv then806 maxv := p^.green;807 inc(p);808 end;809 810 if maxv > 0 then811 begin812 p := Map.Data;813 for n := Map.NbPixels-1 downto 0 do814 begin815 v := p^.green/maxv;816 if ARounded then817 begin818 if v <= 0.5 then819 v := v*v*2 else820 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 then836 Shader.DrawScan(ADest,FShadingMask,Altitude,X,Y, ATexture)837 else838 Shader.Draw(ADest,FShadingMask,Altitude,X,Y, AColor);839 result := rect(X,Y, X+FShadingMask.Width,Y+FShadingMask.Height);840 end;841 842 523 procedure TBGRATextEffect.InitImproveReadability(AText: string; Font: TFont; 843 524 SubOffsetX, SubOffsetY: single); … … 859 540 end; 860 541 861 function TBGRATextEffect.Draw(ADest: TBGRACustomBitmap; X, Y: integer;862 AColor: TBGRAPixel; AAlign: TAlignment): TRect;863 begin864 Case AAlign of865 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 begin874 Case AAlign of875 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 begin885 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 begin892 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 begin899 Case AAlign of900 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 else904 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 begin912 Case AAlign of913 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 else917 result := EmptyRect;918 end;919 end;920 921 542 constructor TBGRATextEffect.Create(AText: string; Font: TFont; 922 543 Antialiasing: boolean; SubOffsetX,SubOffsetY: single); … … 955 576 begin 956 577 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 begin962 FTextSize := Size(AWidth,AHeight);963 FOffset := AOffset;964 if not AMaskOwner then965 FTextMask := AMask.Duplicate()966 else967 FTextMask := AMask;968 578 end; 969 579 … … 1126 736 end; 1127 737 1128 procedure TBGRATextEffect.ApplySphere;1129 var sphere: TBGRACustomBitmap;1130 begin1131 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 begin1143 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 begin1152 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 begin1164 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 begin1170 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 begin1176 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 begin1182 Case AAlign of1183 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 begin1192 if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then1193 begin1194 result := EmptyRect;1195 exit;1196 end;1197 if FOutlineMask = nil then1198 begin1199 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 begin1208 if (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then1209 begin1210 result := EmptyRect;1211 exit;1212 end;1213 if FOutlineMask = nil then1214 begin1215 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 begin1224 Case AAlign of1225 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 begin1234 Case AAlign of1235 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 begin1244 if (Radius <= 0) or (FTextMask = nil) or (FTextMask.Width = 0) or (FTextMask.Height = 0) then1245 begin1246 result := Draw(ADest,X,Y,AColor);1247 exit;1248 end;1249 if (FShadowRadius <> Radius) or (FShadowMask = nil) then1250 begin1251 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 begin1266 Case AAlign of1267 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 begin1275 FShadowMask.free;1276 textMask.Free;1277 FOutlineMask.Free;1278 FShadingMask.Free;1279 inherited Destroy;1280 end;1281 1282 738 initialization 1283 739
Note:
See TracChangeset
for help on using the changeset viewer.