#1 2011-12-14 17:59:11

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

AccessViolation at saving PDF to stream

PDF Engine 1.15

I`m creating a PDF GDI and saving to a stream. During the save progress, a access violation occours (accessing a NIL value)


I have done a workaround (but I dont known if is correct) in SynPdf.pas added after line 3047:

    procedure TPdfDictionary.AddItem(const AKey: PDFString; AValue: TPdfObject;
      AInternal: Boolean);
    var FItem: TPdfDictionaryElement;
    begin
      RemoveItem(AKey);
      if AValue = nil then Exit;    /// <<<<<<<< THIS IS MY W.A.  <<<<<<<<<<
      if AValue.ObjectType = otDirectObject then

The exception cause comes from (line 6490, SynPdf.pas):

      procedure TPdfFontTrueType.PrepareForSaving;    
      ....
        if fDoc.PDFA1 or not WinAnsiFont.fFixedWidth then begin
          WR.Add('['); // fixed width will use /DW value
          // WinAnsiFont.fUsedWide[] contains glyphs used by ShowText
          for i := 0 to n-1 do
            with WinAnsiFont.fUsedWide[i] do
              if int<>0 then
                WR.Add(Glyph).Add('[').Add(Width).Add(']');
        Descendant.AddItem('W',TPdfRawText.Create(WR.Add(']').ToPDFString));
        end;
        Descendant.AddItem('FontDescriptor',WinAnsiFont.fFontDescriptor);   //// BUG: WinAnsiFont.fFontDescriptor = nil !!! WHY ?
        fDoc.FXref.AddObject(Descendant);

     

This is the stacktrace :

[0080BEBD] SynPdf.TPdfDictionary.AddItem (Line 3048, "JJWCommon\Third Part\pdf\SynPdf.pas" + 3) + $3 
[0080BEB5] SynPdf.TPdfDictionary.AddItem (Line 3046, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $6 
[0080BF78] SynPdf.TPdfDictionary.AddItem (Line 3062, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $19 
[00815974] SynPdf.TPdfFontTrueType.PrepareForSaving (Line 6491, "JJWCommon\Third Part\pdf\SynPdf.pas" + 28) + $13 
[0080BF11] SynPdf.TPdfDictionary.AddItem (Line 3052, "JJWCommon\Third Part\pdf\SynPdf.pas" + 7) + $9 
[0081010C] SynPdf.TPdfDocument.SaveToStream (Line 4631, "JJWCommon\Third Part\pdf\SynPdf.pas" + 15) + $3 
[00817AB5] SynPdf.TPdfDocumentGDI.SaveToStream (Line 7119, "JJWCommon\Third Part\pdf\SynPdf.pas" + 12) + $C 

Sorry about my english!

Bye.

Offline

#2 2011-12-14 19:41:45

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

Re: AccessViolation at saving PDF to stream

I do not understand why WinAnsiFont.fFontDescriptor could be nil, since the fFontDescriptor is created in TPdfFontTrueType.Create constructor.

Are you using only non WinAnsi characters within this pdf?

Without the FontDescriptor element within the Font resource, the pdf layout will be invalid, in all cases.

Could you provide some code to reproduce it?

Offline

#3 2011-12-15 10:26:12

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Re: AccessViolation at saving PDF to stream

This PDF is only created drawing Metafiles (renderMetafile method)...

In this metafiles exists custom fonts (created by windows API CreateFont http://msdn.microsoft.com/en-us/library … s.85).aspx ). This fonts are created based on Courier New and has diferent fixed widths.

Can this be the problem? If yes, how can I fix this? (I cannot stop using the CreateFont because of  my Report Generator)

Offline

#4 2011-12-15 16:37:25

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

Re: AccessViolation at saving PDF to stream

This may be the source of the problem, even if CreateFont is handled by SynPdf.

Do you have some code to reproduce the issue?

Offline

#5 2011-12-16 11:47:24

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Re: AccessViolation at saving PDF to stream

Example at:
http://www.4shared.com/file/U8fV6lTV/SynPdfBUG.html

Decompress, open in delphi, run and click on the button!

The example creates a TPdfDocumentGDI and render 24 metafiles on it. At the TPdfDocumentGDI.savetostream the A.V. occours.

Bye.

Offline

#6 2011-12-16 12:46:55

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

Re: AccessViolation at saving PDF to stream

Thanks to your feedback and the code to reproduce the issue, I think I've found its root cause.

In fact, there was an issue when the first time a font was used was for an Unicode character (which occurred at page 14 of your emfs).

See http://synopse.info/fossil/info/4de0e6641f

I suspect that it will work without using UniScribe also.

Offline

#7 2011-12-16 12:58:19

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Re: AccessViolation at saving PDF to stream

Working 100%, nice work!

Ps.: I also need to use UniScribe=true to render the PDF correctly....

Thanks!
bye!

Offline

#8 2011-12-16 13:10:16

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

Re: AccessViolation at saving PDF to stream

What is the issue without UniScribe=true?

I was not able to find out the difference with UniScribe=false in the resulting pdf....

Offline

Board footer

Powered by FluxBB