Release 20030408.
[wine/gsoc-2012-control.git] / dlls / wineps / clipping.c
blobe6f46e7adca9166386caea7d3d1096f45a5b8a24
1 /*
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
21 #include "psdrv.h"
22 #include "wine/debug.h"
23 #include "winbase.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27 /***********************************************************************
28 * PSDRV_SetDeviceClipping
30 VOID PSDRV_SetDeviceClipping( PSDRV_PDEVICE *physDev, HRGN ignored )
32 CHAR szArrayName[] = "clippath";
33 DWORD size;
34 RGNDATA *rgndata = NULL;
35 HRGN hrgn = CreateRectRgn(0,0,0,0);
36 BOOL empty;
38 TRACE("hdc=%p\n", physDev->hdc);
40 empty = !GetClipRgn(physDev->hdc, hrgn);
42 /* We really shouldn't be using initclip */
43 PSDRV_WriteInitClip(physDev);
45 if(!empty) {
46 size = GetRegionData(hrgn, 0, NULL);
47 if(!size) {
48 ERR("Invalid region\n");
49 goto end;
52 rgndata = HeapAlloc( GetProcessHeap(), 0, size );
53 if(!rgndata) {
54 ERR("Can't allocate buffer\n");
55 goto end;
58 GetRegionData(hrgn, size, rgndata);
60 /* check for NULL region */
61 if (rgndata->rdh.nCount == 0)
63 /* set an empty clip path. */
64 PSDRV_WriteRectClip(physDev, 0, 0, 0, 0);
66 /* optimize when it is a simple region */
67 else if (rgndata->rdh.nCount == 1)
69 RECT *pRect = (RECT *)rgndata->Buffer;
71 PSDRV_WriteRectClip(physDev, pRect->left, pRect->top,
72 pRect->right - pRect->left,
73 pRect->bottom - pRect->top);
75 else
77 INT i;
78 RECT *pRect = (RECT *)rgndata->Buffer;
80 PSDRV_WriteArrayDef(physDev, szArrayName, rgndata->rdh.nCount * 4);
82 for (i = 0; i < rgndata->rdh.nCount; i++, pRect++)
84 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4,
85 pRect->left);
86 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 1,
87 pRect->top);
88 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 2,
89 pRect->right - pRect->left);
90 PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 3,
91 pRect->bottom - pRect->top);
93 PSDRV_WriteRectClip2(physDev, szArrayName);
96 end:
97 if(rgndata) HeapFree( GetProcessHeap(), 0, rgndata );
98 DeleteObject(hrgn);