2 * PostScript clipping functions
4 * Copyright 1999 Luc Tourangau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27 /***********************************************************************
28 * PSDRV_SetDeviceClipping
30 VOID PSDRV_SetDeviceClipping( PSDRV_PDEVICE *physDev, HRGN ignored )
32 /* We could set a dirty flag here to speed up PSDRV_SetClip */
36 /***********************************************************************
39 * The idea here is that every graphics operation should bracket
40 * output in PSDRV_SetClip/ResetClip calls. The clip path outside
41 * these calls will be empty; the reason for this is that it is
42 * impossible in PostScript to cleanly make the clip path larger than
43 * the current one. Also Photoshop assumes that despite having set a
44 * small clip area in the printer dc that it can still write raw
45 * PostScript to the driver and expect this code not to be clipped.
47 void PSDRV_SetClip( PSDRV_PDEVICE *physDev )
49 CHAR szArrayName[] = "clippath";
51 RGNDATA *rgndata = NULL;
52 HRGN hrgn = CreateRectRgn(0,0,0,0);
55 TRACE("hdc=%p\n", physDev->hdc);
57 empty = !GetClipRgn(physDev->hdc, hrgn);
60 size = GetRegionData(hrgn, 0, NULL);
62 ERR("Invalid region\n");
66 rgndata = HeapAlloc( GetProcessHeap(), 0, size );
68 ERR("Can't allocate buffer\n");
72 GetRegionData(hrgn, size, rgndata);
74 PSDRV_WriteGSave(physDev);
76 /* check for NULL region */
77 if (rgndata->rdh.nCount == 0)
79 /* set an empty clip path. */
80 PSDRV_WriteRectClip(physDev, 0, 0, 0, 0);
82 /* optimize when it is a simple region */
83 else if (rgndata->rdh.nCount == 1)
85 RECT *pRect = (RECT *)rgndata->Buffer;
87 PSDRV_WriteRectClip(physDev, pRect->left, pRect->top,
88 pRect->right - pRect->left,
89 pRect->bottom - pRect->top);
94 RECT *pRect = (RECT *)rgndata->Buffer;
96 PSDRV_WriteArrayDef(physDev, szArrayName, rgndata->rdh.nCount * 4);
98 for (i = 0; i < rgndata->rdh.nCount; i++, pRect++)
100 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4,
102 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 1,
104 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 2,
105 pRect->right - pRect->left);
106 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 3,
107 pRect->bottom - pRect->top);
109 PSDRV_WriteRectClip2(physDev, szArrayName);
113 if(rgndata) HeapFree( GetProcessHeap(), 0, rgndata );
118 /***********************************************************************
121 void PSDRV_ResetClip( PSDRV_PDEVICE *physDev )
123 HRGN hrgn = CreateRectRgn(0,0,0,0);
126 empty = !GetClipRgn(physDev->hdc, hrgn);
128 PSDRV_WriteGRestore(physDev);