#1 2016-12-21 23:24:43

jkelley
Member
Registered: 2015-10-11
Posts: 6

Clipping problems

One of our PDF reports (containing some metafiles drawn by some third-party code outside of our control then copied to PDF) isn't working in the current version of SynPDF.

Most of each page appears blank, and Adobe Reader is complaining that "An error exists on this page."

I have checked against the latest version of SynPDF from GitHub. The report worked in older versions of SynPDF. I did some investigating, and it looks like the "enhanced clipping process" patch's change to TPdfEnum.ExtSelectClipRgn introduced the problem. (In other words, if I edit SynPdf.pas and change back just the TPdfEnum.ExtSelectClipRgn function, my PDFs work.)

I spent some time playing around with ExtSelectClipRgn to see if I could fix the problem, but unfortunately, I'm having trouble figuring out my way around the codebase. I tried the RGN_COPY change described here, and that didn't help.

I can post examples of the functioning and non-functioning PDFs, if that would help. Unfortunately, since the report generator code involves some third party-code, I can't easily share that.

Last edited by jkelley (2016-12-21 23:25:48)

Offline

#2 2016-12-24 10:45:00

Fritz
Member
Registered: 2015-05-08
Posts: 13

Re: Clipping problems

Hello,
if you can share the not working metafiles i will take a look on these problem

Offline

#3 2017-01-04 19:30:06

jkelley
Member
Registered: 2015-10-11
Posts: 6

Re: Clipping problems

Thank you.

I've uploaded the metafile to https://dl.dropboxusercontent.com/u/152 … tafile.emf.

Here's a simplified version of the C++ code we're using to create the PDF.

  TPdfDocumentGDI *document = new TPdfDocumentGDI(false, CP_UTF8, false, NULL);

  document->DefaultPaperSize = psLetter;
  document->ScreenLogPixels = 254;
  document->DefaultPageLandscape = true;
  document->CompressionMethod = TPdfCompressionMethod::cmFlateDecode;
  document->AddPage();

  TMetafile *mf = new TMetafile;
  mf->LoadFromFile("c:\\temp\\metafile.emf");

  document->VCLCanvas->StretchDraw(TRect(127, 127, 2667, 2032), mf);
  document->SaveToFile("c:\\temp\\file.pdf");

  delete document;
  delete mf;

Offline

#4 2017-01-13 13:50:18

Fritz
Member
Registered: 2015-05-08
Posts: 13

Re: Clipping problems

After investigate the clipping in SynPDF i must say there are a lot of problems with it. I will spend some more time to find a proper solution.
But at moment im running out of spare time  so it will take some weeks.

Offline

#5 2017-01-13 14:04:09

jkelley
Member
Registered: 2015-10-11
Posts: 6

Re: Clipping problems

Thank you very much for looking into this.

In case anyone else runs into this problem, I was able to get my code working again simply by reverting the enhanced clipping process patch in my local copy of SynPDF (so I don't have any immediate needs for a fix).

Offline

#6 2017-01-13 16:32:00

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

Re: Clipping problems

I reverted this patch.

See http://synopse.info/fossil/info/2924b52b36

Offline

#7 2017-01-31 10:04:55

WBTeam
Member
Registered: 2017-01-31
Posts: 7

Re: Clipping problems

Hello,

Just wanted to point out that after installing yesterday's version (fe6aa68421) the clipping issue is still not solved. I'm hoping for someone to take care of this, I'll try myself, but I'm no expert.

We're using Unicode, Builder XE5.

Oh and also, there's an error, multiple declaration of ESynException in SynCommons when compiling.

Offline

#8 2017-02-22 16:17:04

jeanmilost
Member
Registered: 2016-01-21
Posts: 35

Re: Clipping problems

Hello,

I have the exactly same issue using the latest nightly build. If I just revert the following function:

procedure TPdfEnum.ExtSelectClipRgn(data: PRgnDataHeader; iMode: DWord);
var ExtClip: TRect;
begin
  try
    ExtClip := data^.rcBound;
    with DC[nDC] do
    case iMode of
      RGN_COPY: begin
        ClipRgn := MetaRgn;
        ClipRgnNull := False;
      end;
    end;
  except
    on E: Exception do ; // ignore any error (continue EMF enumeration)
  end;
end;

To his previous version:

procedure TPdfEnum.ExtSelectClipRgn(data: PEMRExtSelectClipRgn);
var RGNs: PRgnData;
    i: Integer;
    RCT: TRect;
    ClipRect: TPdfBox;
begin // see http://www.codeproject.com/Articles/1944/Guide-to-WIN-Regions
  if not DC[nDC].ClipRgnNull then begin
    Canvas.GRestore;
    Canvas.NewPath;
    Canvas.fNewPath := False;
    DC[nDC].ClipRgnNull := True;
    fFillColor := -1;
  end;
  if Data^.cbRgnData>0 then begin
    Canvas.GSave;
    Canvas.NewPath;
    DC[nDC].ClipRgnNull := False;
    RGNs := @Data^.RgnData;
    for i := 0 to RGNs^.rdh.nCount-1 do begin
      Move(Rgns^.Buffer[i*SizeOf(TRect)], RCT, SizeOf(RCT));
      Inc(RCT.Bottom);
      ClipRect := Canvas.BoxI(RCT, False);
      Canvas.Rectangle(ClipRect.Left,ClipRect.Top,ClipRect.Width,ClipRect.Height);
    end;
    Canvas.Closepath;
    Canvas.Clip;
    Canvas.NewPath;
    Canvas.FNewPath := False;
  end;
end;

All become fine again and I can use the latest nightly build without problems.

Regards

Offline

#9 2017-04-05 15:15:36

WBTeam
Member
Registered: 2017-01-31
Posts: 7

Re: Clipping problems

After many research, I found a solution to my issue.

The clipping is fixed if I use : RenderMetaFile(pMetaFile, 1, 0, 0, 0, tpSetTextJustification, 99, 101, tcNeverClip);
Instead of : RenderMetaFile(pMetaFile, 1, 0, 0, 0, tpSetTextJustification, 99, 101, tcAlwaysClip);

For a long time, I was using this method like this : RenderMetaFile(pMetaFile, 1, 0, 0, 0) and only discovered recently the TPdfCanvasRenderMetaFileTextClipping parameter!

I hope this will help other people with the same issue! :-)

Offline

Board footer

Powered by FluxBB