clipping.c 3.16 KB
Newer Older
1 2 3
/*
 *	PostScript clipping functions
 *
4
 *	Copyright 1999  Luc Tourangau
5
 *
6 7 8 9 10 11 12 13 14 15 16 17 18
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 20 21
 */

#include "psdrv.h"
22
#include "wine/debug.h"
23
#include "winbase.h"
24

25
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
26 27 28 29

/***********************************************************************
 *           PSDRV_SetDeviceClipping
 */
30
VOID PSDRV_SetDeviceClipping( PSDRV_PDEVICE *physDev, HRGN ignored )
31 32
{
    CHAR szArrayName[] = "clippath";
33
    DWORD size;
34 35 36
    RGNDATA *rgndata = NULL;
    HRGN hrgn = CreateRectRgn(0,0,0,0);
    BOOL empty;
37

38
    TRACE("hdc=%p\n", physDev->hdc);
39

40
    empty = !GetClipRgn(physDev->hdc, hrgn);
41

42
    /* We really shouldn't be using initclip */
43
    PSDRV_WriteInitClip(physDev);
44

45 46 47 48 49 50
    if(!empty) {
        size = GetRegionData(hrgn, 0, NULL);
        if(!size) {
            ERR("Invalid region\n");
            goto end;
        }
51

52 53 54 55 56
        rgndata = HeapAlloc( GetProcessHeap(), 0, size );
        if(!rgndata) {
            ERR("Can't allocate buffer\n");
            goto end;
        }
57

58
        GetRegionData(hrgn, size, rgndata);
59

60 61
        /* check for NULL region */
        if (rgndata->rdh.nCount == 0)
62
        {
63 64 65 66 67 68 69 70 71 72
            /* set an empty clip path. */
            PSDRV_WriteRectClip(physDev, 0, 0, 0, 0);
        }
        /* optimize when it is a simple region */
        else if (rgndata->rdh.nCount == 1)
        {
            RECT *pRect = (RECT *)rgndata->Buffer;

            PSDRV_WriteRectClip(physDev, pRect->left, pRect->top,
                                pRect->right - pRect->left,
73 74
                                pRect->bottom - pRect->top);
        }
75 76 77 78
        else
        {
            INT i;
            RECT *pRect = (RECT *)rgndata->Buffer;
79

80
            PSDRV_WriteArrayDef(physDev, szArrayName, rgndata->rdh.nCount * 4);
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            for (i = 0; i < rgndata->rdh.nCount; i++, pRect++)
            {
                PSDRV_WriteArrayPut(physDev, szArrayName, i * 4,
                                    pRect->left);
                PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 1,
                                    pRect->top);
                PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 2,
                                    pRect->right - pRect->left);
                PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 3,
                                    pRect->bottom - pRect->top);
            }
            PSDRV_WriteRectClip2(physDev, szArrayName);
        }
    }
end:
    if(rgndata) HeapFree( GetProcessHeap(), 0, rgndata );
    DeleteObject(hrgn);
99
}