diff --git a/SynPdf.pas b/SynPdf.pas index 312c70c93..3c65c24c3 100644 --- a/SynPdf.pas +++ b/SynPdf.pas @@ -1664,6 +1664,7 @@ TPdfCanvas = class(TObject) // property getters function GetDoc: TPdfDocument; {$ifdef HASINLINE}inline;{$endif} function GetPage: TPdfPage; {$ifdef HASINLINE}inline;{$endif} + function RectExcludeBottomRight(ARect: TRect): TRect; public /// create the PDF canvas instance constructor Create(APdfDoc: TPdfDocument); @@ -7518,12 +7519,20 @@ procedure NormalizeRect(var Rect: TPdfRect); overload; end; end; +function TPdfCanvas.RectExcludeBottomRight(ARect: TRect): TRect; +begin + Result.Left := ARect.Left; + Result.Top := ARect.Top; + Result.Right := ARect.Right - 1; + Result.Bottom := ARect.Bottom - 1; +end; + function TPdfCanvas.RectI(Rect: TRect; Normalize: boolean): TPdfRect; begin result.Left := I2X(Rect.Left); - result.Right := I2X(Rect.Right-1); + result.Right := I2X(Rect.Right); result.Top := I2Y(Rect.Top); - result.Bottom := I2Y(Rect.Bottom-1); + result.Bottom := I2Y(Rect.Bottom); if Normalize then NormalizeRect(result); end; @@ -8945,6 +8954,12 @@ TPdfEnumStatePen = record width: Single; end; + TPdfEnumStateBrush = record + null: boolean; + color: integer; + style: integer; + end; + /// a state of the EMF enumeration engine, for the PDF canvas // - used also for the SaveDC/RestoreDC stack TPdfEnumState = record @@ -8964,11 +8979,7 @@ TPdfEnumState = record // current selected pen pen: TPdfEnumStatePen; // current selected brush - brush: record - null: boolean; - color: integer; - style: integer; - end; + brush: TPdfEnumStateBrush; // current selected font font: record color: integer; @@ -9058,6 +9069,9 @@ function EnumEMFFunc(DC: HDC; var Table: THandleTable; R: PEnhMetaRecord; var i: integer; InitTransX: XForm; polytypes: PByteArray; + RegionData: PRgnData; + PtrRect: PRect; + CurrentBrush: TPdfEnumStateBrush; begin result := true; with E.DC[E.nDC] do @@ -9224,9 +9238,16 @@ function EnumEMFFunc(DC: HDC; var Table: THandleTable; R: PEnhMetaRecord; end; {$endif USE_ARC} EMR_FILLRGN: begin + MoveFast(E.DC[E.nDC].brush, CurrentBrush, SizeOf(TPdfEnumStateBrush)); E.SelectObjectFromIndex(PEMRFillRgn(R)^.ihBrush); E.NeedBrushAndPen; - E.FillRectangle(PRgnDataHeader(@PEMRFillRgn(R)^.RgnData[0])^.rcBound,false); + RegionData := PRgnData(@PEMRFillRgn(R)^.RgnData[0]); + PtrRect := PRect(@RegionData.Buffer[0]); + for I := 0 to RegionData.rdh.nCount - 1 do begin + E.FillRectangle(PtrRect^, False); + Inc(PtrRect); + end; + MoveFast(CurrentBrush, E.DC[E.nDC].brush, SizeOf(TPdfEnumStateBrush)); end; EMR_POLYGON, EMR_POLYLINE, EMR_POLYGON16, EMR_POLYLINE16: if not brush.null or not pen.null then begin @@ -9534,7 +9555,8 @@ function EnumEMFFunc(DC: HDC; var Table: THandleTable; R: PEnhMetaRecord; EMR_EXTSELECTCLIPRGN: E.ExtSelectClipRgn(@PEMRExtSelectClipRgn(R)^.RgnData[0],PEMRExtSelectClipRgn(R)^.iMode); EMR_INTERSECTCLIPRECT: - ClipRgn := E.IntersectClipRect(E.Canvas.BoxI(PEMRIntersectClipRect(r)^.rclClip,true),ClipRgn); + ClipRgn := E.IntersectClipRect( + E.Canvas.BoxI(E.Canvas.RectExcludeBottomRight(PEMRIntersectClipRect(r)^.rclClip), true), ClipRgn); EMR_SETMAPMODE: MappingMode := PEMRSetMapMode(R)^.iMode; EMR_BEGINPATH: begin @@ -10278,7 +10300,7 @@ procedure TPdfEnum.ExtSelectClipRgn(data: PRgnDataHeader; iMode: DWord); var ExtClip: TRect; begin try - ExtClip := data^.rcBound; + ExtClip := Canvas.RectExcludeBottomRight(data^.rcBound); with DC[nDC] do case iMode of RGN_COPY: begin