pen.c 5.33 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 *	PostScript pen handling
 *
 *	Copyright 1998  Huw D M Davies
 *
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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21 22 23 24 25
#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
26
#include "psdrv.h"
27
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
28

29
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
30

31 32 33 34 35
static const DWORD PEN_dash[]       = { 50, 30 };                 /* -----   -----   -----  */
static const DWORD PEN_dot[]        = { 20 };                     /* --  --  --  --  --  -- */
static const DWORD PEN_dashdot[]    = { 40, 30, 20, 30 };         /* ----   --   ----   --  */
static const DWORD PEN_dashdotdot[] = { 40, 20, 20, 20, 20, 20 }; /* ----  --  --  ----  */
static const DWORD PEN_alternate[]  = { 1 };
Alexandre Julliard's avatar
Alexandre Julliard committed
36 37

/***********************************************************************
38
 *           SelectPen   (WINEPS.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
39
 */
40
HPEN PSDRV_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern )
Alexandre Julliard's avatar
Alexandre Julliard committed
41
{
42
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
43
    LOGPEN logpen;
44
    EXTLOGPEN *elp = NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
45

46 47 48
    if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
    {
        /* must be an extended pen */
49 50 51 52 53 54 55 56 57 58
        INT size = GetObjectW( hpen, 0, NULL );

        if (!size) return 0;

        elp = HeapAlloc( GetProcessHeap(), 0, size );

        GetObjectW( hpen, size, elp );
        /* FIXME: add support for user style pens */
        logpen.lopnStyle = elp->elpPenStyle;
        logpen.lopnWidth.x = elp->elpWidth;
59
        logpen.lopnWidth.y = 0;
60
        logpen.lopnColor = elp->elpColor;
61
    }
62

63
    TRACE("hpen = %p colour = %08x\n", hpen, logpen.lopnColor);
64

65
    physDev->pen.width = logpen.lopnWidth.x;
66
    if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width > 1))
67
    {
68
        physDev->pen.width = PSDRV_XWStoDS( dev, physDev->pen.width );
69 70
        if(physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
    }
71
    if (hpen == GetStockObject( DC_PEN ))
72
        logpen.lopnColor = GetDCPenColor( dev->hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    switch (logpen.lopnStyle & PS_JOIN_MASK)
    {
    default:
    case PS_JOIN_ROUND: physDev->pen.join = 1; break;
    case PS_JOIN_BEVEL: physDev->pen.join = 2; break;
    case PS_JOIN_MITER: physDev->pen.join = 0; break;
    }

    switch (logpen.lopnStyle & PS_ENDCAP_MASK)
    {
    default:
    case PS_ENDCAP_ROUND:  physDev->pen.endcap = 1; break;
    case PS_ENDCAP_SQUARE: physDev->pen.endcap = 2; break;
    case PS_ENDCAP_FLAT:   physDev->pen.endcap = 0; break;
    }

90
    PSDRV_CreateColor(dev, &physDev->pen.color, logpen.lopnColor);
91
    physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
92

93 94
    switch(physDev->pen.style) {
    case PS_DASH:
95 96
        memcpy( physDev->pen.dash, PEN_dash, sizeof(PEN_dash) );
        physDev->pen.dash_len = sizeof(PEN_dash) / sizeof(DWORD);
97 98 99
	break;

    case PS_DOT:
100 101
        memcpy( physDev->pen.dash, PEN_dot, sizeof(PEN_dot) );
        physDev->pen.dash_len = sizeof(PEN_dot) / sizeof(DWORD);
102 103 104
	break;

    case PS_DASHDOT:
105 106
        memcpy( physDev->pen.dash, PEN_dashdot, sizeof(PEN_dashdot) );
        physDev->pen.dash_len = sizeof(PEN_dashdot) / sizeof(DWORD);
107 108 109
	break;

    case PS_DASHDOTDOT:
110 111
        memcpy( physDev->pen.dash, PEN_dashdotdot, sizeof(PEN_dashdotdot) );
        physDev->pen.dash_len = sizeof(PEN_dashdotdot) / sizeof(DWORD);
112 113 114
	break;

    case PS_ALTERNATE:
115 116 117 118 119 120 121
        memcpy( physDev->pen.dash, PEN_alternate, sizeof(PEN_alternate) );
        physDev->pen.dash_len = sizeof(PEN_alternate) / sizeof(DWORD);
	break;

    case PS_USERSTYLE:
        physDev->pen.dash_len = min( elp->elpNumEntries, MAX_DASHLEN );
        memcpy( physDev->pen.dash, elp->elpStyleEntry, physDev->pen.dash_len * sizeof(DWORD) );
122 123 124
	break;

    default:
125
	physDev->pen.dash_len = 0;
126
    }
127

128 129 130 131 132
    if ((physDev->pen.width > 1) && physDev->pen.dash_len &&
        physDev->pen.style != PS_USERSTYLE && physDev->pen.style != PS_ALTERNATE)
    {
        physDev->pen.style = PS_SOLID;
        physDev->pen.dash_len = 0;
133
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
134

135
    HeapFree( GetProcessHeap(), 0, elp );
Alexandre Julliard's avatar
Alexandre Julliard committed
136
    physDev->pen.set = FALSE;
137
    return hpen;
Alexandre Julliard's avatar
Alexandre Julliard committed
138 139 140
}


141 142 143
/***********************************************************************
 *           SetDCPenColor (WINEPS.@)
 */
144
COLORREF PSDRV_SetDCPenColor( PHYSDEV dev, COLORREF color )
145
{
146 147
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );

148
    if (GetCurrentObject( dev->hdc, OBJ_PEN ) == GetStockObject( DC_PEN ))
149
        PSDRV_CreateColor( dev, &physDev->pen.color, color );
150 151 152 153
    return color;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
154 155 156 157 158
/**********************************************************************
 *
 *	PSDRV_SetPen
 *
 */
159
BOOL PSDRV_SetPen( PHYSDEV dev )
Alexandre Julliard's avatar
Alexandre Julliard committed
160
{
161 162
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );

163
    if (physDev->pen.style != PS_NULL) {
164
	PSDRV_WriteSetColor(dev, &physDev->pen.color);
165

166
	if(!physDev->pen.set) {
167
	    PSDRV_WriteSetPen(dev);
168
	    physDev->pen.set = TRUE;
169
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
170 171 172 173
    }

    return TRUE;
}