1 // NOTE: This is very experimental code. Do not expect it to work!
2 
3 unit Main;
4 
5 {$mode objfpc}{$H+}
6 
7 interface
8 
9 uses
10   Classes, ExtCtrls, StdCtrls, SysUtils, FileUtil, Forms, Controls, Graphics,
11   Dialogs, TAGraph, TASeries, TASources;
12 
13 type
14 
15   { TForm1 }
16 
17   TForm1 = class(TForm)
18     btnSVG: TButton;
19     btnGCode: TButton;
20     btnWMF: TButton;
21     Chart1: TChart;
22     Chart1BarSeries1: TBarSeries;
23     Chart1LineSeries1: TLineSeries;
24     Panel1: TPanel;
25     RandomChartSource1: TRandomChartSource;
26     procedure btnGCodeClick(Sender: TObject);
27     procedure btnSVGClick(Sender: TObject);
28     procedure btnWMFClick(Sender: TObject);
29   end;
30 
31 var
32   Form1: TForm1;
33 
34 implementation
35 
36 {$R *.lfm}
37 
38 uses
39   FPVectorial,
40   TADrawerFPVectorial, TADrawUtils, TADrawerCanvas;
41 
42 procedure SaveAs(AChart: TChart; AFormat: TvVectorialFormat);
43 const
44   ext: array [TvVectorialFormat] of String = (
45     '',  // vfUnknown
46     'pdf', 'svg', 'svgz', 'cdr', 'wmf', 'odg',
47     'dxf',
48     'laf', 'laz',
49     'ps', 'eps',
50     'gcode5', 'gcode6',
51     'mathml',
52     'odt', 'docx', 'html',
53     'raw');
54 var
55   d: TvVectorialDocument;
56   v: IChartDrawer;
57   fn: String;
58 begin
59   d := TvVectorialDocument.Create;
60   try
61     d.Width := AChart.Width;
62     d.Height := AChart.Height;
63     d.AddPage;
64     v := TFPVectorialDrawer.Create(d.GetCurrentPageAsVectorial);
65     with AChart do
66       Draw(v, Rect(0, 0, Width, Height));
67     fn := 'test.' + ext[AFormat];
68     d.WriteToFile(fn, AFormat);
69     ShowMessage(Format('Chart saved as "%s"', [fn]));
70   finally
71     d.Free;
72   end;
73 end;
74 
75 { TForm1 }
76 
77 procedure TForm1.btnGCodeClick(Sender: TObject);
78 begin
79   SaveAs(Chart1, vfGCodeAvisoCNCPrototipoV5);
80 end;
81 
82 procedure TForm1.btnSVGClick(Sender: TObject);
83 begin
84   SaveAs(Chart1, vfSVG);
85 end;
86 
87 procedure TForm1.btnWMFClick(Sender: TObject);
88 begin
89   SaveAs(Chart1, vfWindowsMetafileWMF);
90 end;
91 
92 end.
93 
94