#1 2015-02-05 09:43:12

Tom
Member
Registered: 2015-02-05
Posts: 5

EMF clipping problem

Hello

I started using this great library and it works really good.

But when converting a small EMF file to PDF I encountered a clipping problem, and I don't know how to solve it.

http://sharesend.com/thr2lv3k - EMF-File
http://sharesend.com/w79yhbu8 - converted PDF with synopse
http://sharesend.com/69xdiuvm - converted PDF with Adobe

Are there any settings I can use to adjust the clipping behavior in the PDF Engine?

Best regards
Tom

Offline

#2 2015-02-17 15:11:05

Tom
Member
Registered: 2015-02-05
Posts: 5

Re: EMF clipping problem

After digging into the EnumEMFFunc I see at least two problem areas concerning the emf conversion:

1. Clipping of geometric objects is not implemented (only rectangular clipping of a text is supported).
2. Rendering of chord/arc is not implemented.

http://sharesend.com/qummwept - EMF-File
http://sharesend.com/npm7mf9k - converted PDF with synopse

I used the following code to generate the PDF:

procedure TForm1.Button1Click(Sender: TObject);
var
  oPDF: TPdfDocumentGDI;
  oMeta: TMetaFile;
begin
 oPDF:= TPdfDocumentGDI.Create;
 oMeta:= TMetaFile.Create;
 try
   oMeta.LoadFromFile('c:\temp\test.emf');
   oPDF.AddPage;
   oPDF.Canvas.RenderMetaFile(oMeta, 1, 0, 0, tpExactTextCharacterPositining);
   oPDF.SaveToFile('c:\temp\test.pdf');
 finally
   oPDF.Free;
   oMeta.Free;
 end;
end;

Is this correct and are there plans to enhance these areas?

Best regards
Tom

Offline

#3 2015-02-21 10:16:38

Marsh
Member
Registered: 2015-02-21
Posts: 6

Re: EMF clipping problem

Hi,

I'm getting great results with this library, it made generating a Pdf really easy. But I also noticed that clipping for EMF is not supported. So far I managed to get around with a hack, but now I'm looking for a proper solution.
Would be great to see an update on that soon.

Cheers

Offline

#4 2015-02-21 10:32:11

Marsh
Member
Registered: 2015-02-21
Posts: 6

Re: EMF clipping problem

Well right after I posted the above message, I guess I found part of the bug. I made a quick fix that works, at least for a single clipping rectangle.

In SynPdf.pas in the function EnumEMFFunc, change the EMR_INTERSECTCLIPRECT statement:

EMR_INTERSECTCLIPRECT:
  begin
    ClipRgn := e.IntersectClipRect
      (e.Canvas.BoxI(PEMRIntersectClipRect(r)^.rclClip,
      true), ClipRgn);

    e.Canvas.Clip;
    with e.Canvas.BoxI(PEMRIntersectClipRect(r)^.rclClip, true) do
      e.Canvas.Rectangle(Left, Top, Width, Height);
    e.Canvas.EoClip;
  end;

Furthermore, I noticed a bug in TPdfCanvas.EoClip, instead of upper case W, lower case w should be added to the stream, so:

procedure TPdfCanvas.EoClip;
begin
  if FContents <> nil then
    // FContents.Writer.Add('W*'#10);
    FContents.Writer.Add('w*'#10);
end;

Offline

#5 2015-02-21 12:10:04

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

Re: EMF clipping problem

I've included the fixes.
See http://synopse.info/fossil/info/716bbd23f6

Hope it helps.

Thanks for the patch!

Offline

#6 2015-02-25 09:42:48

Tom
Member
Registered: 2015-02-05
Posts: 5

Re: EMF clipping problem

Hello Marsh

Thanks for your patch.

I tried it but unfortunately the changes in EnumEMFFunc leads to a corrupt PDF.

Please see the EMF and the resulting PDF:
http://sharesend.com/3yijqymn - EMF-File
http://sharesend.com/y1b91w22 - corrupt PDFFile


Best regards
Tom

Offline

#7 2015-03-18 10:22:50

Marsh
Member
Registered: 2015-02-21
Posts: 6

Re: EMF clipping problem

Hi Tom,

sorry for my delayed answer.
Yeah I noticed that problem, that's why i mentioned it works for a single clipping rectangle only. I couldn't figure out yet how to resolve that issue unfortunately.

Offline

#8 2016-04-19 11:33:20

MtwStark
Member
From: Italy
Registered: 2016-01-05
Posts: 27

Re: EMF clipping problem

Marsh wrote:

Furthermore, I noticed a bug in TPdfCanvas.EoClip, instead of upper case W, lower case w should be added to the stream, so:

procedure TPdfCanvas.EoClip;
begin
  if FContents <> nil then
    // FContents.Writer.Add('W*'#10);
    FContents.Writer.Add('w*'#10);
end;
Tom wrote:

Hello Marsh

Thanks for your patch.

I tried it but unfortunately the changes in EnumEMFFunc leads to a corrupt PDF.

Sorry Marsh but in current PDF Reference 1.7 EoClip MUST be 'W*' (uppercase)
maybe this could be the cause of your EMR_INTERSECTCLIPRECT bringing to corrupted pdf?

Tom, could you test it with 'W*' instead of 'w*' in EoClip?

kind regards

Offline

#9 2016-06-07 09:23:17

MtwStark
Member
From: Italy
Registered: 2016-01-05
Posts: 27

Re: EMF clipping problem

** UP **

Can anyone correct the EoClip function?

'w*' means nothing in PDF reference, it should be 'W*'

thanks

Offline

#10 2016-06-07 14:03:40

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

Re: EMF clipping problem

Offline

#11 2018-01-30 07:48:30

Tom
Member
Registered: 2015-02-05
Posts: 5

Re: EMF clipping problem

Hello all

MtwStark solved all the above clipping problems with his SynPDF.pas unit enhancements.

He posted the unit in the topic: PDFEngine Clipping Implementation + Output stream optimizations

Thanks for the great work MtwStark.

Best regards
Tom

Offline

Board footer

Powered by FluxBB