pen.c 3.43 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 char PEN_dash[]       = "50 30";     /* -----   -----   -----  */
static const char PEN_dot[]        = "20";      /* --  --  --  --  --  -- */
static const char PEN_dashdot[]    = "40 30 20 30";  /* ----   --   ----   --  */
static const char PEN_dashdotdot[] = "40 20 20 20 20 20"; /* ----  --  --  ----  */
static const char 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( PSDRV_PDEVICE *physDev, HPEN hpen )
Alexandre Julliard's avatar
Alexandre Julliard committed
41
{
42
    LOGPEN logpen;
Alexandre Julliard's avatar
Alexandre Julliard committed
43

44 45 46
    if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
    {
        /* must be an extended pen */
47 48 49 50 51 52 53 54 55 56 57
        EXTLOGPEN *elp;
        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;
58
        logpen.lopnWidth.y = 0;
59 60 61
        logpen.lopnColor = elp->elpColor;

        HeapFree( GetProcessHeap(), 0, elp );
62
    }
63

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

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

73 74
    PSDRV_CreateColor(physDev, &physDev->pen.color, logpen.lopnColor);
    physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    switch(physDev->pen.style) {
    case PS_DASH:
	physDev->pen.dash = PEN_dash;
	break;

    case PS_DOT:
	physDev->pen.dash = PEN_dot;
	break;

    case PS_DASHDOT:
	physDev->pen.dash = PEN_dashdot;
	break;

    case PS_DASHDOTDOT:
	physDev->pen.dash = PEN_dashdotdot;
	break;

    case PS_ALTERNATE:
	physDev->pen.dash = PEN_alternate;
	break;

    default:
	physDev->pen.dash = NULL;
99
    }
100 101 102 103

    if ((physDev->pen.width > 1) && (physDev->pen.dash != NULL)) {
	physDev->pen.style = PS_SOLID;
         physDev->pen.dash = NULL;
104
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
105 106

    physDev->pen.set = FALSE;
107
    return hpen;
Alexandre Julliard's avatar
Alexandre Julliard committed
108 109 110 111 112 113 114 115
}


/**********************************************************************
 *
 *	PSDRV_SetPen
 *
 */
116
BOOL PSDRV_SetPen(PSDRV_PDEVICE *physDev)
Alexandre Julliard's avatar
Alexandre Julliard committed
117
{
118
    if (physDev->pen.style != PS_NULL) {
119
	PSDRV_WriteSetColor(physDev, &physDev->pen.color);
120

121
	if(!physDev->pen.set) {
122
	    PSDRV_WriteSetPen(physDev);
123
	    physDev->pen.set = TRUE;
124
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
125 126 127 128
    }

    return TRUE;
}