From ec5142c76ca91e02f7a24bed9eadbe0c8f76bd6b Mon Sep 17 00:00:00 2001 From: maxim Date: Tue, 10 Feb 2015 22:59:20 +0000 Subject: [PATCH] Merged revision(s) 47663 #d4a19485ed from trunk: TAChart: Improved output of fpvectorial writer (related to issue #0027321) ........ git-svn-id: branches/fixes_1_4@47698 - --- components/tachart/demo/fpvectorial/Main.lfm | 63 ++++++++++++++++++-- components/tachart/demo/fpvectorial/Main.pas | 49 +++++---------- components/tachart/tadrawerfpvectorial.pas | 45 +++++++++++--- 3 files changed, 111 insertions(+), 46 deletions(-) diff --git a/components/tachart/demo/fpvectorial/Main.lfm b/components/tachart/demo/fpvectorial/Main.lfm index f90ee99e49..699b0c1c91 100644 --- a/components/tachart/demo/fpvectorial/Main.lfm +++ b/components/tachart/demo/fpvectorial/Main.lfm @@ -7,7 +7,7 @@ object Form1: TForm1 ClientHeight = 342 ClientWidth = 422 Position = poScreenCenter - LCLVersion = '1.3' + LCLVersion = '1.5' object Chart1: TChart Left = 0 Height = 300 @@ -15,20 +15,71 @@ object Form1: TForm1 Width = 422 AxisList = < item + Grid.Color = clSilver + Grid.Style = psDash + Marks.LabelFont.CharSet = ANSI_CHARSET + Marks.LabelFont.Height = -13 + Marks.LabelFont.Name = 'Arial Narrow' + Marks.LabelFont.Pitch = fpVariable + Marks.LabelFont.Quality = fqDraft 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 + Grid.Color = clSilver Alignment = calBottom + Marks.LabelFont.CharSet = ANSI_CHARSET + Marks.LabelFont.Height = -13 + Marks.LabelFont.Name = 'Arial Narrow' + Marks.LabelFont.Pitch = fpVariable + Marks.LabelFont.Quality = fqDraft Minors = <> + Title.LabelFont.CharSet = ANSI_CHARSET + Title.LabelFont.Color = clGreen + 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> + BackColor = clWhite + Foot.Alignment = taLeftJustify Foot.Brush.Color = clBtnFace - Foot.Font.Color = clBlue - Title.Brush.Color = clBtnFace - Title.Font.Color = clBlue - Title.Text.Strings = ( - 'TAChart' + Foot.Brush.Style = bsClear + Foot.Font.CharSet = ANSI_CHARSET + Foot.Font.Color = clGray + Foot.Font.Height = -11 + Foot.Font.Name = 'Courier New' + Foot.Font.Pitch = fpFixed + Foot.Font.Quality = fqDraft + Foot.Text.Strings = ( + 'printed by TAChart and fpvectorial' ) + Foot.Visible = True + Title.Brush.Color = clBtnFace + Title.Brush.Style = bsClear + Title.Font.CharSet = ANSI_CHARSET + Title.Font.Color = clBlue + Title.Font.Height = -16 + Title.Font.Name = 'Arial' + Title.Font.Pitch = fpVariable + Title.Font.Quality = fqDraft + Title.Font.Style = [fsBold, fsUnderline] + Title.Text.Strings = ( + 'Sample chart' + ) + Title.Visible = True Align = alClient ParentColor = False object Chart1LineSeries1: TLineSeries diff --git a/components/tachart/demo/fpvectorial/Main.pas b/components/tachart/demo/fpvectorial/Main.pas index 1828a928a8..fdc4b73b3e 100644 --- a/components/tachart/demo/fpvectorial/Main.pas +++ b/components/tachart/demo/fpvectorial/Main.pas @@ -34,30 +34,11 @@ implementation {$R *.lfm} uses - FPVectorial, SVGVectorialWriter, avisocncgcodewriter, TADrawerFPVectorial, - TADrawUtils, TADrawerCanvas; + FPVectorial, + TADrawerFPVectorial, TADrawUtils, TADrawerCanvas; procedure SaveAs(AChart: TChart; AFormat: TvVectorialFormat); const -(* - vfUnknown, - { Multi-purpose document formats } - vfPDF, vfSVG, vfSVGZ, vfCorelDrawCDR, vfWindowsMetafileWMF, vfODG, - { CAD formats } - vfDXF, - { Geospatial formats } - vfLAS, vfLAZ, - { Printing formats } - vfPostScript, vfEncapsulatedPostScript, - { GCode formats } - vfGCodeAvisoCNCPrototipoV5, vfGCodeAvisoCNCPrototipoV6, - { Formula formats } - vfMathML, - { Text Document formats } - vfODT, vfDOCX, vfHTML, - { Raster Image formats } - vfRAW -*) ext: array [TvVectorialFormat] of String = ( '', // vfUnknown 'pdf', 'svg', 'svgz', 'cdr', 'wmf', 'odg', @@ -71,20 +52,22 @@ const var d: TvVectorialDocument; v: IChartDrawer; + fn: String; begin d := TvVectorialDocument.Create; - d.AddPage; - d.Width := AChart.Width; - d.Height := AChart.Height; - v := TFPVectorialDrawer.Create(d.GetCurrentPageAsVectorial); - v.DoChartColorToFPColor := @ChartColorSysToFPColor; - - with AChart do - Draw(v, Rect(0, Height, Width, Height*2)); - // why is it necessary to add 1x Height to y? - // Otherwise the chart would not be on the page. - - d.WriteToFile('test.' + ext[AFormat], AFormat); + try + d.Width := AChart.Width; + d.Height := AChart.Height; + d.AddPage; + v := TFPVectorialDrawer.Create(d.GetCurrentPageAsVectorial); + with AChart do + Draw(v, Rect(0, 0, Width, Height)); + fn := 'test.' + ext[AFormat]; + d.WriteToFile(fn, AFormat); + ShowMessage(Format('Chart saved as "%s"', [fn])); + finally + d.Free; + end; end; { TForm1 } diff --git a/components/tachart/tadrawerfpvectorial.pas b/components/tachart/tadrawerfpvectorial.pas index ea74c7c282..cc71bbaf9c 100644 --- a/components/tachart/tadrawerfpvectorial.pas +++ b/components/tachart/tadrawerfpvectorial.pas @@ -14,7 +14,7 @@ unit TADrawerFPVectorial; interface uses - Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils; + Graphics, Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils; type @@ -26,7 +26,7 @@ type FBrushColor: TFPColor; FBrushStyle: TFPBrushStyle; FCanvas: TvVectorialPage; - FFontSize: Integer; + FFont: TvFont; FPenColor: TFPColor; FPenStyle: TFPPenStyle; FPenWidth: Integer; @@ -77,6 +77,20 @@ implementation uses Math, TAGeometry; +function SVGGetFontOrientationFunc(AFont: TFPCustomFont): Integer; +begin + if AFont is TFont then + Result := round(TFont(AFont).Orientation * 0.1) + else + Result := round(AFont.Orientation * 0.1); +end; + +function SVGChartColorToFPColor(AChartColor: TChartColor): TFPColor; +begin + Result := ChartColorToFPColor(ColorToRGB(AChartColor)); +end; + + { TFPVectorialDrawer } procedure TFPVectorialDrawer.AddLine(AX, AY: Integer); @@ -122,6 +136,8 @@ constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage); begin inherited Create; FCanvas := ACanvas; + FGetFontOrientationFunc := @SVGGetFontOrientationFunc; + FChartColorToFPColorFunc := @SVGChartColorToFPColor; end; procedure TFPVectorialDrawer.DrawingBegin(const ABoundingBox: TRect); @@ -156,7 +172,7 @@ end; function TFPVectorialDrawer.GetFontAngle: Double; begin - Result := 0.0; + Result := FFont.Orientation; end; function TFPVectorialDrawer.InvertY(AY: Integer): Integer; @@ -274,8 +290,18 @@ begin end; procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont); +var + angle: Integer; begin - FFontSize := IfThen(AFont.Size = 0, 10, AFont.Size); + angle := AFont.Orientation; + FFont.Name := AFont.Name; + FFont.Size := IfThen(AFont.Size = 0, 10, AFont.Size); + FFont.Color := AFont.FPColor; + FFont.Orientation := FGetFontOrientationFunc(AFont); + FFont.Bold := AFont.Bold; + FFont.Italic := AFont.Italic; + FFont.Underline := AFont.Underline; + FFont.Strikethrough := AFont.Strikethrough; end; procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen); @@ -294,15 +320,20 @@ end; function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint; begin - Result.X := FFontSize * Length(AText) * 2 div 3; - Result.Y := FFontSize; + Result.X := FFont.Size * Length(AText) * 2 div 3; + Result.Y := FFont.Size; end; procedure TFPVectorialDrawer.SimpleTextOut( AX, AY: Integer; const AText: String); +var + txt: TvText; + p: TPoint; begin // FPVectorial uses lower-left instead of upper-left corner as text start. - FCanvas.AddText(AX, InvertY(AY) - FFontSize, 0, AText); + p := RotatePoint(Point(0, -FFont.Size), DegToRad(FFont.Orientation)) + Point(AX, InvertY(AY)); + txt := FCanvas.AddText(p.X, p.Y, 0, AText); + txt.Font := FFont; end; end.