I have now tried it on another machine (running macOS 10.12) as well, but it doesn't work either (neither with the Carbon nor the Cocoa widgetset).
I don't think that it has to do with
fpvectorial or
TAChartFPVectorial, but rather with a bug in the initialisation of fonts. After inspecting the
save demo of TAChart again, I found that there are two possible implementations of the SVG
save handler hidden in the code. One is the standard form, which uses the
SaveToSVGFile method of TChart:
procedure TForm1.tbSaveAsSVGClick(Sender: TObject);
begin
Chart1.SaveToSVGFile(GetFilename('svg'));
end;
{ or ...
var
fs: TFileStream;
id: IChartDrawer;
begin
fs := TFileStream.Create(GetFileName('svg'), fmCreate);
try
id := TSVGDrawer.Create(fs, true);
with Chart1 do
Draw(id, Rect(0, 0, Width, Height));
finally
fs.Free;
end;
end; }
The standard code can be commented out to enable another version that allows for more thorough investigations:
procedure TForm1.tbSaveAsSVGClick(Sender: TObject);
{begin
Chart1.SaveToSVGFile(GetFilename('svg'));
end;
or ... }
var
fs: TFileStream;
id: IChartDrawer;
begin
fs := TFileStream.Create(GetFileName('svg'), fmCreate);
try
id := TSVGDrawer.Create(fs, true);
id.SetFont();
with Chart1 do
Draw(id, Rect(0, 0, Width, Height));
finally
fs.Free;
end;
end;
However, it fails, too, with the default font.
I then changed it by explicitly assigning the font "Helvetica" (which is always installed on Macs since 1984) with:
procedure TForm1.tbSaveAsSVGClick(Sender: TObject);
{begin
Chart1.SaveToSVGFile(GetFilename('svg'));
end;
or ...}
var
fs: TFileStream;
id: IChartDrawer;
ft: TFPCustomFont; // added
begin
fs := TFileStream.Create(GetFileName('svg'), fmCreate);
ft := TFPCustomFont.Create; // added
ft.Name := 'Helvetica'; // added
try
id := TSVGDrawer.Create(fs, true);
id.SetFont(ft); // added
with Chart1 do
Draw(id, Rect(0, 0, Width, Height));
finally
ft.free; // added
fs.Free;
end;
end;
Unfortunately, this fails as well. The failure is caused by the fact that the
TSVGDrawer.SetFont method is unable to load the font (the font is
nil after calling LoadFont). LoadFont delivers
nil, since it is unable again to assign the variable
familyItem (which is of type
TCustomFamilyCollectionItem).
This is where my knowledge ends. I simply don't know enough about the LazFreeTypeFontCollection to fix it, the more as this unit seems to be nearly undocumented.
In my opinion, the fact that the SVG export appears to work on some machines and crashes on other ones might result from an initialisation issue in the font handlers.