Problem saving in emf

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Jonp
Newbie
Newbie
Posts: 7
Joined: Mon Oct 17, 2022 12:00 am

Problem saving in emf

Post by Jonp » Thu Oct 20, 2022 12:32 pm

Hi,
I am trying to export charts to files of various formats . Most work fine. However, while wmf export is ok, the emf crashes in the Winapi.GDIPOBJ in the following function

Code: Select all

function TGPGraphics.MeasureString(string_: WideString; length: Integer; font: TGPFont;
       const origin: TGPPointF; out boundingBox: TGPRectF): TStatus;
  var
    nFont: GpFont;
    rect: TGPRectF;
  begin
    if assigned(font) then nfont := font.nativeFont else nfont := nil;
    rect.X := origin.X;
    rect.Y := origin.Y;
    rect.Width := 0.0;
    rect.Height := 0.0;

    result := SetStatus(GdipMeasureString(
        nativeGraphics,
        PWideChar(string_),
        length,
        nfont,
        @rect,
        nil,
        @boundingBox,
        nil,
        nil
    ));
  end;
The file is generated, though.
The teechart version is Pro 2022.36
My code is simply:

Code: Select all

Case SaveDialog.FilterIndex of
                    1:  qualitychart.SaveToBitmapFile(SaveDialog.FileName);     // BMP
                    2:  begin   // JPG
                         With GetChartJPEG(Qualitychart) do
                         try
                          SaveToFile(savedialog.filename);    { <-- save the JPEG to disk }
                         finally
                          Free;  { <-- free the temporary JPEG object }
                         end;
                        end;
                    3:  Qualitychart.SaveToMetafile(SaveDialog.FileName);    // WMF
                    4:  Qualitychart.SaveToMetafileEnh(SaveDialog.FileName) ;    //EMF
                    5:  TeeSaveToPNG(QualityChart,SaveDialog.FileName);    // png
                    6:  TeeSaveToPDFFile(QualityChart,savedialog.FileName);   // pdf
                  End;
Best,
Jon

Yeray
Site Admin
Site Admin
Posts: 9611
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem saving in emf

Post by Yeray » Wed Nov 02, 2022 1:49 pm

Hello Jon,

I can't reproduce the problem.
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Jonp
Newbie
Newbie
Posts: 7
Joined: Mon Oct 17, 2022 12:00 am

Re: Problem saving in emf

Post by Jonp » Fri Dec 09, 2022 11:58 am

Hi Yeray,
Sorry for not answering before. The way to get to the save is rather complex, so I have to figure out a way to reproduce the error in a simple example.
But: the problem does not seem to be your fault, at least not totally.
It also crashes if I use

Code: Select all

metafile:=QualityChart.TeeCreateMetafile(False,Qualitychart.clientRect);
 metafile.SaveToFile(SaveDialog.FileName) ;
but it does not crash in the save routines themselves, that is, both the TeeCreateMetaFile and the SaveToMetafile complete without any quarrel.

Interestingly, the program does not crash if I do the following:

Code: Select all

 Qualitychart.SaveToMetafile(SaveDialog.FileName);    // WMF
  TeeSaveToPNG(Qualitychart,'$$$$$.png');

That is, save to a PNG (or any other format except wmf and emf) after having saved to emf/wmf.
Thus, it seems that some cleanup that the other file routines fixes the problem.
Best,
Jon

Yeray
Site Admin
Site Admin
Posts: 9611
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem saving in emf

Post by Yeray » Mon Dec 12, 2022 1:35 pm

Hello Jon,

I've tried both SaveToMetafile and TeeCreateMetafile + SaveToFile with a new simple example project and I get no errors here.
Just add a TChart and a TButton to the form and this code:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1 do
  begin
    Legend.Hide;
    Color:=clWhite;
    Gradient.Visible:=False;
    Walls.Back.Color:=clWhite;
    Walls.Back.Gradient.Visible:=False;

    AddSeries(TBarSeries).FillSampleValues;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var metafile: TMetafile;
begin
  Chart1.SaveToMetafile('E:\tmp\exports\metafiletest_vcl.wmf');

  metafile:=Chart1.TeeCreateMetafile(False, Chart1.ClientRect);
  metafile.SaveToFile('E:\tmp\exports\metafiletest_vcl2.wmf') ;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply