mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-11 09:38:52 +02:00
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 -
This commit is contained in:
parent
2db55550a7
commit
ec5142c76c
@ -7,7 +7,7 @@ object Form1: TForm1
|
|||||||
ClientHeight = 342
|
ClientHeight = 342
|
||||||
ClientWidth = 422
|
ClientWidth = 422
|
||||||
Position = poScreenCenter
|
Position = poScreenCenter
|
||||||
LCLVersion = '1.3'
|
LCLVersion = '1.5'
|
||||||
object Chart1: TChart
|
object Chart1: TChart
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 300
|
Height = 300
|
||||||
@ -15,20 +15,71 @@ object Form1: TForm1
|
|||||||
Width = 422
|
Width = 422
|
||||||
AxisList = <
|
AxisList = <
|
||||||
item
|
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 = <>
|
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.Orientation = 900
|
||||||
|
Title.LabelFont.Pitch = fpVariable
|
||||||
|
Title.LabelFont.Quality = fqDraft
|
||||||
|
Title.LabelFont.Style = [fsItalic]
|
||||||
|
Title.Visible = True
|
||||||
|
Title.Caption = 'y axis'
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
|
Grid.Color = clSilver
|
||||||
Alignment = calBottom
|
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 = <>
|
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>
|
end>
|
||||||
|
BackColor = clWhite
|
||||||
|
Foot.Alignment = taLeftJustify
|
||||||
Foot.Brush.Color = clBtnFace
|
Foot.Brush.Color = clBtnFace
|
||||||
Foot.Font.Color = clBlue
|
Foot.Brush.Style = bsClear
|
||||||
Title.Brush.Color = clBtnFace
|
Foot.Font.CharSet = ANSI_CHARSET
|
||||||
Title.Font.Color = clBlue
|
Foot.Font.Color = clGray
|
||||||
Title.Text.Strings = (
|
Foot.Font.Height = -11
|
||||||
'TAChart'
|
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
|
Align = alClient
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
object Chart1LineSeries1: TLineSeries
|
object Chart1LineSeries1: TLineSeries
|
||||||
|
@ -34,30 +34,11 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
FPVectorial, SVGVectorialWriter, avisocncgcodewriter, TADrawerFPVectorial,
|
FPVectorial,
|
||||||
TADrawUtils, TADrawerCanvas;
|
TADrawerFPVectorial, TADrawUtils, TADrawerCanvas;
|
||||||
|
|
||||||
procedure SaveAs(AChart: TChart; AFormat: TvVectorialFormat);
|
procedure SaveAs(AChart: TChart; AFormat: TvVectorialFormat);
|
||||||
const
|
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 = (
|
ext: array [TvVectorialFormat] of String = (
|
||||||
'', // vfUnknown
|
'', // vfUnknown
|
||||||
'pdf', 'svg', 'svgz', 'cdr', 'wmf', 'odg',
|
'pdf', 'svg', 'svgz', 'cdr', 'wmf', 'odg',
|
||||||
@ -71,20 +52,22 @@ const
|
|||||||
var
|
var
|
||||||
d: TvVectorialDocument;
|
d: TvVectorialDocument;
|
||||||
v: IChartDrawer;
|
v: IChartDrawer;
|
||||||
|
fn: String;
|
||||||
begin
|
begin
|
||||||
d := TvVectorialDocument.Create;
|
d := TvVectorialDocument.Create;
|
||||||
d.AddPage;
|
try
|
||||||
d.Width := AChart.Width;
|
d.Width := AChart.Width;
|
||||||
d.Height := AChart.Height;
|
d.Height := AChart.Height;
|
||||||
v := TFPVectorialDrawer.Create(d.GetCurrentPageAsVectorial);
|
d.AddPage;
|
||||||
v.DoChartColorToFPColor := @ChartColorSysToFPColor;
|
v := TFPVectorialDrawer.Create(d.GetCurrentPageAsVectorial);
|
||||||
|
with AChart do
|
||||||
with AChart do
|
Draw(v, Rect(0, 0, Width, Height));
|
||||||
Draw(v, Rect(0, Height, Width, Height*2));
|
fn := 'test.' + ext[AFormat];
|
||||||
// why is it necessary to add 1x Height to y?
|
d.WriteToFile(fn, AFormat);
|
||||||
// Otherwise the chart would not be on the page.
|
ShowMessage(Format('Chart saved as "%s"', [fn]));
|
||||||
|
finally
|
||||||
d.WriteToFile('test.' + ext[AFormat], AFormat);
|
d.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
@ -14,7 +14,7 @@ unit TADrawerFPVectorial;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils;
|
Graphics, Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ type
|
|||||||
FBrushColor: TFPColor;
|
FBrushColor: TFPColor;
|
||||||
FBrushStyle: TFPBrushStyle;
|
FBrushStyle: TFPBrushStyle;
|
||||||
FCanvas: TvVectorialPage;
|
FCanvas: TvVectorialPage;
|
||||||
FFontSize: Integer;
|
FFont: TvFont;
|
||||||
FPenColor: TFPColor;
|
FPenColor: TFPColor;
|
||||||
FPenStyle: TFPPenStyle;
|
FPenStyle: TFPPenStyle;
|
||||||
FPenWidth: Integer;
|
FPenWidth: Integer;
|
||||||
@ -77,6 +77,20 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math, TAGeometry;
|
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 }
|
{ TFPVectorialDrawer }
|
||||||
|
|
||||||
procedure TFPVectorialDrawer.AddLine(AX, AY: Integer);
|
procedure TFPVectorialDrawer.AddLine(AX, AY: Integer);
|
||||||
@ -122,6 +136,8 @@ constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage);
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FCanvas := ACanvas;
|
FCanvas := ACanvas;
|
||||||
|
FGetFontOrientationFunc := @SVGGetFontOrientationFunc;
|
||||||
|
FChartColorToFPColorFunc := @SVGChartColorToFPColor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPVectorialDrawer.DrawingBegin(const ABoundingBox: TRect);
|
procedure TFPVectorialDrawer.DrawingBegin(const ABoundingBox: TRect);
|
||||||
@ -156,7 +172,7 @@ end;
|
|||||||
|
|
||||||
function TFPVectorialDrawer.GetFontAngle: Double;
|
function TFPVectorialDrawer.GetFontAngle: Double;
|
||||||
begin
|
begin
|
||||||
Result := 0.0;
|
Result := FFont.Orientation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFPVectorialDrawer.InvertY(AY: Integer): Integer;
|
function TFPVectorialDrawer.InvertY(AY: Integer): Integer;
|
||||||
@ -274,8 +290,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
|
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
|
||||||
|
var
|
||||||
|
angle: Integer;
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
|
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
|
||||||
@ -294,15 +320,20 @@ end;
|
|||||||
|
|
||||||
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
|
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
|
||||||
begin
|
begin
|
||||||
Result.X := FFontSize * Length(AText) * 2 div 3;
|
Result.X := FFont.Size * Length(AText) * 2 div 3;
|
||||||
Result.Y := FFontSize;
|
Result.Y := FFont.Size;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPVectorialDrawer.SimpleTextOut(
|
procedure TFPVectorialDrawer.SimpleTextOut(
|
||||||
AX, AY: Integer; const AText: String);
|
AX, AY: Integer; const AText: String);
|
||||||
|
var
|
||||||
|
txt: TvText;
|
||||||
|
p: TPoint;
|
||||||
begin
|
begin
|
||||||
// FPVectorial uses lower-left instead of upper-left corner as text start.
|
// 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;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user