You are not logged in.
Pages: 1
Hello,
I use the following code to apply a clipping region on my PDF page
HRGN pClipRegion = NULL;
try
{
::SelectClipRgn(pCanvas->Handle, NULL);
pClipRegion = ::CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom);
if (::SelectClipRgn(pCanvas->Handle, pClipRegion) == ERROR)
{
DWORD error = ::GetLastError();
...
}
else
::SetMetaRgn(pCanvas->Handle);
}
__finally
{
if (pClipRegion)
::DeleteObject(pClipRegion);
}
Where pCanvas is the canvas provided ny the VCLCanvas property. This code works well using the SynPdf version 1.18. But I recently tried the latest SynPdf version, and I noticed that the above code no longer works, as my page is drawn without clipping at all. What is the reason?
Regards
Offline
I found that the issue is in relation with this function in SynPdf.pas:
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;
when I revert to:
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 my clipping works fine again. Would it be possible to fix the bug, or revert to the previous version of this function in the library?
Regards
Offline
Are you sure you retrieved the latest version from trunk?
The one from http://synopse.info/fossil/finfo?name=SynPdf.pas or https://github.com/synopse/mORMot/blob/ … SynPdf.pas do include the working TPdfEnum.ExtSelectClipRgn() method.
IMHO the version included in the mORMot trunk is always to be checked... it is updated/fixed more other than the SynPdf archive or github dedicated repository itself.
Offline
Hi ab,
Thanks for your reply.
The library version is written inside the SynopseCommit.inc file, right? In this case, the latest stable version is the '1.18.1417', and this version contains the above mentioned issue.
I verified again my working version and is the '1.18.2217', so it's a more recent version, and effectively the clipping is working in it. In conclusion, if the code existing in the '1.18.2217' version is destined to replace the code in the latest stable '1.18.1417' version, then then above mentioned issue is effectively resolved.
Regards
Offline
Hi jeanmilost,
please take a look at my post for the same problem here
I have solved adding this test to the beginning of ExtSelectClipRgn procedure:
// we are handling RGN_COPY (5) only..
if data^.iMode <> RGN_COPY then
exit;
Last edited by MtwStark (2016-11-16 11:42:32)
Offline
Today I updated my local copy of SynPDF to the latest trunk version, mostly to get the PDF/A fix; but also to find out that my ExtSelectClipRgn() code was reverted in SVN revision 150.
My code was able to handle non-rectangular clipping areas by interpreting the Region arrays from Windows. Now the old code is active again, which can handle a single rectangle clipping area only. And I have the feeling that even this simple code is wrong, because Data.rcBounds is never used.
I've created a local branch and merged my code back into SynPDF.pas; with some small adjustments as mentioned where by MtwStark: Test for iMode == RGN_COPY. Now everything works fine, again.
AB, can you please dig into your version control software to find out if there was a specific bug, which lead to reverting my enhancements?!
TIA
Achim
BTW:
What would be needed to support PDF/A-3 with attachments (ZUGFeRD, an ugly german acronym for embedding invoice data as XML into PDF documents): http://www.ferd-net.de/front_content.php?idcat=231
Offline
Hello
For info: tried the latest nightly build today (1.18.3764), the issue still exists. Do you think you will deal with it soon?
Regards
Offline
All this back & forth with diverse feedbacks about clipping is confusing.
I didn't code this part (I didn't need it), so included third-party patches, which work in some cases, but not for everyone...
Can anyone contribute some clean code for clipping?
Offline
Pages: 1