#1 2010-11-29 12:43:59

moggco
Member
Registered: 2010-09-27
Posts: 9

Is there a typo about TTestSynopsePDF._TPdfDocument?

In the SynSelfTests.pas:

Procedure TTestSynopsePDF._TPdfDocument;
var MS: THeapMemoryStream;
    i,y: integer;
    embed: boolean;
const
  Hash: array[boolean] of Cardinal =
    ($7DFB537,$4CC9F0E8);
  Name: array[boolean] of PDFString =
    ('Arial','Helvetica');
begin
  MS := THeapMemoryStream.Create;
  with TPdfDocument.Create do
  try
    for embed := false to true do begin
      Info.CreationDate := Date;
      StandardFontsReplace := embed;
      AddPage;
      Canvas.SetFont('arial',10,[]);
      Check(Canvas.Page.Font.Name=Name[embed]);
      y := 800;
      for i := 1 to 30 do begin
        Canvas.SetFont('Arial',9+i,[]);
        Canvas.TextOut(100,y,WinAnsiString('Texte accentu?n?+IntToStr(i)));
        dec(y,9+i);
      end;
      SaveToStream(MS,Date);
      Check(Hash32(MS.Memory,MS.Position)=Hash[embed]);
      if not embed then begin
        NewDoc;
        MS.Clear;
      end;
    end;
// MS.SaveToFile(ChangeFileExt(paramstr(0),'.pdf'));
  finally
    Free;
    MS.Free;
  end;
end;

I modified as follow:

procedure TTestSynopsePDF._TPdfDocument;
var MS: THeapMemoryStream;
    i,y: integer;
    embed: boolean;
const
  Hash: array[boolean] of Cardinal =
    ($A9373411,$61C142{.$7DFB537,$4CC9F0E8});
  Name: array[boolean] of PDFString =
    ('Arial','Tahoma');
begin
  MS := THeapMemoryStream.Create;
  with TPdfDocument.Create do
  try
    for embed := false to true do begin
      Info.CreationDate := Date;
      StandardFontsReplace := embed;
      AddPage;
      Canvas.SetFont(Name[embed],10,[]);
      writeln(Canvas.Page.Font.Name);
      Check(Canvas.Page.Font.Name=Name[embed]);
      ...

Canvas.SetFont(Name[embed],10,[]);

ps. In my Windows, there is not exist 'Helvetica' font, so I use 'Tahoma' font.

Last edited by moggco (2010-11-29 13:02:04)

Offline

#2 2010-11-30 09:20:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,315
Website

Re: Is there a typo about TTestSynopsePDF._TPdfDocument?

There is no typo at all.

The purpose of this test is to test the StandardFontsReplace property feature.

When set to TRUE, the Arial font is set and replaced on the fly with an Helvetica font, which is handled in the pdf reader, even if no Helvetica font is installed on your Windows.

So the test seems 100% correct.

But it's very nice having people looking at the code so closely!
Thanks! smile

Offline

Board footer

Powered by FluxBB