2 * PostScript pen handling
4 * Copyright 1998 Huw D M Davies
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
31 static const char PEN_dash[] = "50 30"; /* ----- ----- ----- */
32 static const char PEN_dot[] = "20"; /* -- -- -- -- -- -- */
33 static const char PEN_dashdot[] = "40 30 20 30"; /* ---- -- ---- -- */
34 static const char PEN_dashdotdot[] = "40 20 20 20 20 20"; /* ---- -- -- ---- */
35 static const char PEN_alternate[] = "1";
37 /***********************************************************************
38 * SelectPen (WINEPS.@)
40 HPEN PSDRV_SelectPen( PHYSDEV dev, HPEN hpen )
42 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
45 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
47 /* must be an extended pen */
49 INT size = GetObjectW( hpen, 0, NULL );
53 elp = HeapAlloc( GetProcessHeap(), 0, size );
55 GetObjectW( hpen, size, elp );
56 /* FIXME: add support for user style pens */
57 logpen.lopnStyle = elp->elpPenStyle;
58 logpen.lopnWidth.x = elp->elpWidth;
59 logpen.lopnWidth.y = 0;
60 logpen.lopnColor = elp->elpColor;
62 HeapFree( GetProcessHeap(), 0, elp );
65 TRACE("hpen = %p colour = %08x\n", hpen, logpen.lopnColor);
67 physDev->pen.width = logpen.lopnWidth.x;
68 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width > 1))
70 physDev->pen.width = PSDRV_XWStoDS( dev, physDev->pen.width );
71 if(physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
73 if (hpen == GetStockObject( DC_PEN ))
74 logpen.lopnColor = GetDCPenColor( dev->hdc );
76 switch (logpen.lopnStyle & PS_JOIN_MASK)
79 case PS_JOIN_ROUND: physDev->pen.join = 1; break;
80 case PS_JOIN_BEVEL: physDev->pen.join = 2; break;
81 case PS_JOIN_MITER: physDev->pen.join = 0; break;
84 switch (logpen.lopnStyle & PS_ENDCAP_MASK)
87 case PS_ENDCAP_ROUND: physDev->pen.endcap = 1; break;
88 case PS_ENDCAP_SQUARE: physDev->pen.endcap = 2; break;
89 case PS_ENDCAP_FLAT: physDev->pen.endcap = 0; break;
92 PSDRV_CreateColor(dev, &physDev->pen.color, logpen.lopnColor);
93 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
95 switch(physDev->pen.style) {
97 physDev->pen.dash = PEN_dash;
101 physDev->pen.dash = PEN_dot;
105 physDev->pen.dash = PEN_dashdot;
109 physDev->pen.dash = PEN_dashdotdot;
113 physDev->pen.dash = PEN_alternate;
117 physDev->pen.dash = NULL;
120 if ((physDev->pen.width > 1) && (physDev->pen.dash != NULL)) {
121 physDev->pen.style = PS_SOLID;
122 physDev->pen.dash = NULL;
125 physDev->pen.set = FALSE;
130 /***********************************************************************
131 * SetDCPenColor (WINEPS.@)
133 COLORREF PSDRV_SetDCPenColor( PHYSDEV dev, COLORREF color )
135 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
137 if (GetCurrentObject( dev->hdc, OBJ_PEN ) == GetStockObject( DC_PEN ))
138 PSDRV_CreateColor( dev, &physDev->pen.color, color );
143 /**********************************************************************
148 BOOL PSDRV_SetPen( PHYSDEV dev )
150 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
152 if (physDev->pen.style != PS_NULL) {
153 PSDRV_WriteSetColor(dev, &physDev->pen.color);
155 if(!physDev->pen.set) {
156 PSDRV_WriteSetPen(dev);
157 physDev->pen.set = TRUE;