diff --git a/components/tachart/demo/save/main.lfm b/components/tachart/demo/save/main.lfm index fd667e901d..5c33c5b2d2 100644 --- a/components/tachart/demo/save/main.lfm +++ b/components/tachart/demo/save/main.lfm @@ -1,5 +1,5 @@ object Form1: TForm1 - Left = 318 + Left = 350 Height = 299 Top = 151 Width = 538 @@ -7,7 +7,7 @@ object Form1: TForm1 ClientHeight = 299 ClientWidth = 538 OnCreate = FormCreate - LCLVersion = '0.9.31' + LCLVersion = '1.5' object Chart1: TChart Left = 0 Height = 275 @@ -15,10 +15,30 @@ object Form1: TForm1 Width = 538 AxisList = < item + Minors = <> + Title.LabelFont.CharSet = ANSI_CHARSET + Title.LabelFont.Color = clRed + Title.LabelFont.Height = -19 + Title.LabelFont.Name = 'Times New Roman' Title.LabelFont.Orientation = 900 + Title.LabelFont.Pitch = fpVariable + Title.LabelFont.Quality = fqDraft + Title.LabelFont.Style = [fsItalic] + Title.Visible = True + Title.Caption = 'y axis' end item Alignment = calBottom + Minors = <> + Title.LabelFont.CharSet = ANSI_CHARSET + Title.LabelFont.Color = clBlue + Title.LabelFont.Height = -19 + Title.LabelFont.Name = 'Times New Roman' + Title.LabelFont.Pitch = fpVariable + Title.LabelFont.Quality = fqDraft + Title.LabelFont.Style = [fsItalic] + Title.Visible = True + Title.Caption = 'x axis' end> Foot.Brush.Color = clBtnFace Foot.Font.Color = clBlue @@ -83,7 +103,7 @@ object Form1: TForm1 end end object SaveDialog1: TSaveDialog - left = 64 + left = 120 top = 56 end end diff --git a/components/tachart/demo/save/main.pas b/components/tachart/demo/save/main.pas index bc37203097..4bd2a03951 100644 --- a/components/tachart/demo/save/main.pas +++ b/components/tachart/demo/save/main.pas @@ -98,7 +98,6 @@ begin fs := TFileStream.Create(GetFileName('svg'), fmCreate); try id := TSVGDrawer.Create(fs, true); - id.DoChartColorToFPColor := @ChartColorSysToFPColor; with Chart1 do Draw(id, Rect(0, 0, Width, Height)); finally diff --git a/components/tachart/demo/save/savedemo.lpi b/components/tachart/demo/save/savedemo.lpi index 906a36c0a2..4089897517 100644 --- a/components/tachart/demo/save/savedemo.lpi +++ b/components/tachart/demo/save/savedemo.lpi @@ -1,4 +1,4 @@ - + @@ -48,19 +48,19 @@ - + - + @@ -81,11 +81,5 @@ - - - - - - diff --git a/components/tachart/tadrawersvg.pas b/components/tachart/tadrawersvg.pas index 4247bbd65a..41ff19d895 100644 --- a/components/tachart/tadrawersvg.pas +++ b/components/tachart/tadrawersvg.pas @@ -14,9 +14,20 @@ unit TADrawerSVG; interface uses - Classes, FPImage, FPCanvas, TAChartUtils, TADrawUtils; + Graphics, Classes, FPImage, FPCanvas, TAChartUtils, TADrawUtils; type + TSVGFont = record + Name: String; + Color: TFPColor; + Size: integer; + Orientation: Integer; // angle * 10 (90° --> 900), >0 if ccw. + Bold: boolean; + Italic: boolean; + Underline: boolean; + StrikeThrough: boolean; + end; + TSVGDrawer = class(TBasicDrawer, IChartDrawer) strict private @@ -24,8 +35,7 @@ type FBrushColor: TFPColor; FBrushStyle: TFPBrushStyle; FClippingPathId: Integer; - FFont: TFPCustomFont; - FFontAngle: Double; + FFont: TSVGFont; FPatterns: TStrings; FPen: TFPCustomPen; FPrevPos: TPoint; @@ -49,6 +59,7 @@ type function GetFontAngle: Double; override; function SimpleTextExtent(const AText: String): TPoint; override; procedure SimpleTextOut(AX, AY: Integer; const AText: String); override; + public constructor Create(AStream: TStream; AWriteDocType: Boolean); destructor Destroy; override; @@ -115,11 +126,25 @@ begin Result := FloatToStr(AValue, fmtSettings); end; +function SVGGetFontOrientationFunc(AFont: TFPCustomFont): Integer; +begin + if AFont is TFont then + Result := (AFont as TFont).Orientation + else + Result := AFont.Orientation; +end; + +function SVGChartColorToFPColor(AChartColor: TChartColor): TFPColor; +begin + Result := ChartColorToFPColor(ColorToRGB(AChartColor)); +end; + + { TSVGDrawer } procedure TSVGDrawer.AddToFontOrientation(ADelta: Integer); begin - FFontAngle += OrientToRad(ADelta); + FFont.Orientation += ADelta; end; procedure TSVGDrawer.ClippingStart(const AClipRect: TRect); @@ -148,6 +173,8 @@ begin FStream := AStream; FPatterns := TStringList.Create; FPen := TFPCustomPen.Create; + FGetFontOrientationFunc := @SVGGetFontOrientationFunc; + FChartColorToFPColorFunc := @SVGChartColorToFPColor; if AWriteDocType then begin WriteStr(''); WriteStr(' clTAColor then - FFont.FPColor := FChartColorToFPColorFunc(FMonochromeColor); + with FFont do begin + Name := AFont.Name; + Size := IfThen(AFont.Size=0, 8, AFont.Size); + + // ??? + if FMonochromeColor <> clTAColor then + Color := FChartColorToFPColorFunc(FMonochromeColor) + else + Color := AFont.FPColor; + + Orientation := FGetFontOrientationFunc(AFont); + FFont.Bold := AFont.Bold; + FFont.Italic := AFont.Italic; + FFont.Underline := AFont.Underline; + FFont.Strikethrough := AFont.Strikethrough; + end; end; procedure TSVGDrawer.SetPen(APen: TFPCustomPen); @@ -404,15 +446,35 @@ end; procedure TSVGDrawer.SimpleTextOut(AX, AY: Integer; const AText: String); var p: TPoint; + stext: String; + sstyle: String; + fs: TFormatSettings; begin - p := RotatePoint(Point(0, FontSize), -FFontAngle) + Point(AX, AY); - WriteFmt( - '' + - '%s', - [p.X, p.Y, SimpleTextExtent(AText).X, - ColorToHex(FFont.FPColor), FormatIfNotEmpty(' opacity:%s;', OpacityStr), - FFont.Name, FontSize, AText]); + fs := DefaultFormatSettings; + fs.DecimalSeparator := '.'; + fs.ThousandSeparator := '#'; + + p := RotatePoint(Point(0, FontSize), OrientToRad(-FFont.Orientation)) + Point(AX, AY); + stext := Format('x="%d" y="%d"', [p.X, p.Y]); + if FFont.Orientation <> 0 then + stext := stext + Format(' transform="rotate(%g,%d,%d)"', [-FFont.Orientation*0.1, p.X, p.Y], fs); + + sstyle := Format('fill:%s; font-family:''%s''; font-size:%dpt;', + [ColorToHex(FFont.Color), FFont.Name, FontSize]); + if FFont.Bold then + sstyle := sstyle + ' font-weight:bold;'; + if FFont.Italic then + sstyle := sstyle + ' font-style:oblique;'; + if FFont.Underline and FFont.Strikethrough then + sstyle := sstyle + ' text-decoration:underline,line-through;' + else if FFont.Underline then + sstyle := sstyle + ' text-deocration:underline;' + else if FFont.Strikethrough then + sstyle := sstyle + ' text-decoration:line-through;'; + if OpacityStr <> '' then + sstyle := sstyle + OpacityStr + ';'; + + WriteFmt('%s', [stext, sstyle, AText]); end; function TSVGDrawer.StyleFill: String;