msdaps: Add support for remoting IAccessor_CreateAccessor.
[wine] / dlls / wineps.drv / pen.c
1 /*
2  *      PostScript pen handling
3  *
4  *      Copyright 1998  Huw D M Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "psdrv.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
30
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";
36
37 /***********************************************************************
38  *           SelectPen   (WINEPS.@)
39  */
40 HPEN CDECL PSDRV_SelectPen( PSDRV_PDEVICE *physDev, HPEN hpen )
41 {
42     LOGPEN logpen;
43
44     if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
45     {
46         /* must be an extended pen */
47         EXTLOGPEN *elp;
48         INT size = GetObjectW( hpen, 0, NULL );
49
50         if (!size) return 0;
51
52         elp = HeapAlloc( GetProcessHeap(), 0, size );
53
54         GetObjectW( hpen, size, elp );
55         /* FIXME: add support for user style pens */
56         logpen.lopnStyle = elp->elpPenStyle;
57         logpen.lopnWidth.x = elp->elpWidth;
58         logpen.lopnWidth.y = 0;
59         logpen.lopnColor = elp->elpColor;
60
61         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         physDev->pen.width = PSDRV_XWStoDS( physDev, physDev->pen.width );
70         if(physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
71     }
72
73     switch (logpen.lopnStyle & PS_JOIN_MASK)
74     {
75     default:
76     case PS_JOIN_ROUND: physDev->pen.join = 1; break;
77     case PS_JOIN_BEVEL: physDev->pen.join = 2; break;
78     case PS_JOIN_MITER: physDev->pen.join = 0; break;
79     }
80
81     switch (logpen.lopnStyle & PS_ENDCAP_MASK)
82     {
83     default:
84     case PS_ENDCAP_ROUND:  physDev->pen.endcap = 1; break;
85     case PS_ENDCAP_SQUARE: physDev->pen.endcap = 2; break;
86     case PS_ENDCAP_FLAT:   physDev->pen.endcap = 0; break;
87     }
88
89     PSDRV_CreateColor(physDev, &physDev->pen.color, logpen.lopnColor);
90     physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
91
92     switch(physDev->pen.style) {
93     case PS_DASH:
94         physDev->pen.dash = PEN_dash;
95         break;
96
97     case PS_DOT:
98         physDev->pen.dash = PEN_dot;
99         break;
100
101     case PS_DASHDOT:
102         physDev->pen.dash = PEN_dashdot;
103         break;
104
105     case PS_DASHDOTDOT:
106         physDev->pen.dash = PEN_dashdotdot;
107         break;
108
109     case PS_ALTERNATE:
110         physDev->pen.dash = PEN_alternate;
111         break;
112
113     default:
114         physDev->pen.dash = NULL;
115     }
116
117     if ((physDev->pen.width > 1) && (physDev->pen.dash != NULL)) {
118         physDev->pen.style = PS_SOLID;
119          physDev->pen.dash = NULL;
120     }
121
122     physDev->pen.set = FALSE;
123     return hpen;
124 }
125
126
127 /**********************************************************************
128  *
129  *      PSDRV_SetPen
130  *
131  */
132 BOOL PSDRV_SetPen(PSDRV_PDEVICE *physDev)
133 {
134     if (physDev->pen.style != PS_NULL) {
135         PSDRV_WriteSetColor(physDev, &physDev->pen.color);
136
137         if(!physDev->pen.set) {
138             PSDRV_WriteSetPen(physDev);
139             physDev->pen.set = TRUE;
140         }
141     }
142
143     return TRUE;
144 }