clipping.c 4.26 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
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 CDECL PSDRV_SetDeviceClipping( PSDRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
{
    /* We could set a dirty flag here to speed up PSDRV_SetClip */
    return;
}

/***********************************************************************
 *           PSDRV_SetClip
 *
 * The idea here is that every graphics operation should bracket
 * output in PSDRV_SetClip/ResetClip calls.  The clip path outside
 * these calls will be empty; the reason for this is that it is
 * impossible in PostScript to cleanly make the clip path larger than
 * the current one.  Also Photoshop assumes that despite having set a
 * small clip area in the printer dc that it can still write raw
 * PostScript to the driver and expect this code not to be clipped.
 */
void PSDRV_SetClip( PSDRV_PDEVICE *physDev )
48 49
{
    CHAR szArrayName[] = "clippath";
50
    DWORD size;
51 52 53
    RGNDATA *rgndata = NULL;
    HRGN hrgn = CreateRectRgn(0,0,0,0);
    BOOL empty;
54

55
    TRACE("hdc=%p\n", physDev->hdc);
56

57 58 59 60 61
    if(physDev->pathdepth) {
        TRACE("inside a path, so not clipping\n");
        goto end;
    }

62
    empty = !GetClipRgn(physDev->hdc, hrgn);
63

64 65 66 67 68 69
    if(!empty) {
        size = GetRegionData(hrgn, 0, NULL);
        if(!size) {
            ERR("Invalid region\n");
            goto end;
        }
70

71 72 73 74 75
        rgndata = HeapAlloc( GetProcessHeap(), 0, size );
        if(!rgndata) {
            ERR("Can't allocate buffer\n");
            goto end;
        }
76

77
        GetRegionData(hrgn, size, rgndata);
78

79 80
        PSDRV_WriteGSave(physDev);

81 82
        /* check for NULL region */
        if (rgndata->rdh.nCount == 0)
83
        {
84 85 86 87 88 89 90 91 92 93
            /* 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,
94 95
                                pRect->bottom - pRect->top);
        }
96 97
        else
        {
98
            UINT i;
99
            RECT *pRect = (RECT *)rgndata->Buffer;
100

101
            PSDRV_WriteArrayDef(physDev, szArrayName, rgndata->rdh.nCount * 4);
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
            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:
118
    HeapFree( GetProcessHeap(), 0, rgndata );
119
    DeleteObject(hrgn);
120
}
121 122 123 124 125 126 127 128 129 130


/***********************************************************************
 *           PSDRV_ResetClip
 */
void PSDRV_ResetClip( PSDRV_PDEVICE *physDev )
{
    HRGN hrgn = CreateRectRgn(0,0,0,0);
    BOOL empty;

131 132 133
    empty = !GetClipRgn(physDev->hdc, hrgn);
    if(!empty && !physDev->pathdepth)
        PSDRV_WriteGRestore(physDev);
134 135
    DeleteObject(hrgn);
}