mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 12:00:02 +02:00
TAChart: Support Brush.Style in SVG drawing back-end
git-svn-id: trunk@40094 -
This commit is contained in:
parent
8ac53ca5f8
commit
214494a95c
@ -24,15 +24,15 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TSVGDrawer }
|
|
||||||
|
|
||||||
TSVGDrawer = class(TBasicDrawer, IChartDrawer)
|
TSVGDrawer = class(TBasicDrawer, IChartDrawer)
|
||||||
strict private
|
strict private
|
||||||
FAntialiasingMode: TChartAntialiasingMode;
|
FAntialiasingMode: TChartAntialiasingMode;
|
||||||
FBrushColor: TFPColor;
|
FBrushColor: TFPColor;
|
||||||
|
FBrushStyle: TFPBrushStyle;
|
||||||
FClippingPathId: Integer;
|
FClippingPathId: Integer;
|
||||||
FFont: TFPCustomFont;
|
FFont: TFPCustomFont;
|
||||||
FFontAngle: Double;
|
FFontAngle: Double;
|
||||||
|
FPatterns: TStrings;
|
||||||
FPen: TFPCustomPen;
|
FPen: TFPCustomPen;
|
||||||
FPrevPos: TPoint;
|
FPrevPos: TPoint;
|
||||||
FStream: TStream;
|
FStream: TStream;
|
||||||
@ -152,6 +152,7 @@ constructor TSVGDrawer.Create(AStream: TStream; AWriteDocType: Boolean);
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FStream := AStream;
|
FStream := AStream;
|
||||||
|
FPatterns := TStringList.Create;
|
||||||
FPen := TFPCustomPen.Create;
|
FPen := TFPCustomPen.Create;
|
||||||
if AWriteDocType then begin
|
if AWriteDocType then begin
|
||||||
WriteStr('<?xml version="1.0"?>');
|
WriteStr('<?xml version="1.0"?>');
|
||||||
@ -162,6 +163,7 @@ end;
|
|||||||
|
|
||||||
destructor TSVGDrawer.Destroy;
|
destructor TSVGDrawer.Destroy;
|
||||||
begin
|
begin
|
||||||
|
FreeAndNil(FPatterns);
|
||||||
FreeAndNil(FPen);
|
FreeAndNil(FPen);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
@ -180,9 +182,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSVGDrawer.DrawingEnd;
|
procedure TSVGDrawer.DrawingEnd;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if FAntialiasingMode <> amDontCare then
|
if FAntialiasingMode <> amDontCare then
|
||||||
WriteStr('</g>');
|
WriteStr('</g>');
|
||||||
|
if FPatterns.Count > 0 then
|
||||||
|
WriteStr('<defs>');
|
||||||
|
for i := 0 to FPatterns.Count - 1 do begin
|
||||||
|
WriteFmt(
|
||||||
|
'<pattern id="bs%d" width="8" height="8" patternUnits="userSpaceOnUse">' +
|
||||||
|
'%s</pattern>',
|
||||||
|
[i, FPatterns[i]]);
|
||||||
|
end;
|
||||||
|
if FPatterns.Count > 0 then
|
||||||
|
WriteStr('</defs>');
|
||||||
WriteStr('</svg>');
|
WriteStr('</svg>');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -284,7 +298,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSVGDrawer.PutImage(AX, AY: Integer; AImage: TFPCustomImage);
|
procedure TSVGDrawer.PutImage(AX, AY: Integer; AImage: TFPCustomImage);
|
||||||
|
|
||||||
var
|
var
|
||||||
s: TStringStream = nil;
|
s: TStringStream = nil;
|
||||||
w: TFPWriterPNG = nil;
|
w: TFPWriterPNG = nil;
|
||||||
@ -351,6 +364,7 @@ end;
|
|||||||
procedure TSVGDrawer.SetBrush(ABrush: TFPCustomBrush);
|
procedure TSVGDrawer.SetBrush(ABrush: TFPCustomBrush);
|
||||||
begin
|
begin
|
||||||
FBrushColor := FPColorOrMono(ABrush.FPColor);
|
FBrushColor := FPColorOrMono(ABrush.FPColor);
|
||||||
|
FBrushStyle := ABrush.Style;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSVGDrawer.SetBrushColor(AColor: TChartColor);
|
procedure TSVGDrawer.SetBrushColor(AColor: TChartColor);
|
||||||
@ -362,7 +376,7 @@ procedure TSVGDrawer.SetBrushParams(
|
|||||||
AStyle: TFPBrushStyle; AColor: TChartColor);
|
AStyle: TFPBrushStyle; AColor: TChartColor);
|
||||||
begin
|
begin
|
||||||
FBrushColor := FChartColorToFPColorFunc(ColorOrMono(AColor));
|
FBrushColor := FChartColorToFPColorFunc(ColorOrMono(AColor));
|
||||||
Unused(AStyle);
|
FBrushStyle := AStyle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSVGDrawer.SetFont(AFont: TFPCustomFont);
|
procedure TSVGDrawer.SetFont(AFont: TFPCustomFont);
|
||||||
@ -408,10 +422,41 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TSVGDrawer.StyleFill: String;
|
function TSVGDrawer.StyleFill: String;
|
||||||
|
|
||||||
|
function AddPattern(APattern: String): String;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
i := FPatterns.IndexOf(APattern);
|
||||||
|
if i < 0 then
|
||||||
|
i := FPatterns.Add(APattern);
|
||||||
|
Result := Format('url(#bs%d)', [i]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
const
|
||||||
|
PATTERNS: array [TFPBrushStyle] of String = (
|
||||||
|
'', '',
|
||||||
|
'M0,4 h8', // bsHorizontal
|
||||||
|
'M4,0 v8', // bsVertical
|
||||||
|
'M0,0 l8,8', // bsFDiagonal
|
||||||
|
'M0,8 l8,-8', // bsBDiagonal
|
||||||
|
'M0,4 h8 M4,0 v8', // bsCross
|
||||||
|
'M0,0 l8,8 M0,8 l8,-8', // bsDiagCross
|
||||||
|
'', '');
|
||||||
|
var
|
||||||
|
fill: String;
|
||||||
begin
|
begin
|
||||||
|
case FBrushStyle of
|
||||||
|
bsClear: exit('fill: none;');
|
||||||
|
bsHorizontal..bsDiagCross:
|
||||||
|
fill := AddPattern(Format(
|
||||||
|
'<path d="%s" stroke="%s"/>',
|
||||||
|
[PATTERNS[FBrushStyle], ColorToHex(FBrushColor)]));
|
||||||
|
else
|
||||||
|
fill := ColorToHex(FBrushColor);
|
||||||
|
end;
|
||||||
Result :=
|
Result :=
|
||||||
Format('fill:%s;', [ColorToHex(FBrushColor)]) +
|
Format('fill:%s;', [fill]) + FormatIfNotEmpty('fill-opacity:%s;', OpacityStr);
|
||||||
FormatIfNotEmpty('fill-opacity:%s;', OpacityStr);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSVGDrawer.StyleStroke: String;
|
function TSVGDrawer.StyleStroke: String;
|
||||||
|
Loading…
Reference in New Issue
Block a user