ws2_32/tests: Initialize a test buffer (valgrind).
[wine/wine-gecko.git] / dlls / winex11.drv / pen.c
blobc6a15daabf95344dd2c2189d3f3d92015c4d2189
1 /*
2 * X11DRV pen objects
4 * Copyright 1993 Alexandre Julliard
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
21 #include "config.h"
23 #include "x11drv.h"
26 static DWORD get_user_dashes( char *res, const DWORD *style, DWORD len )
28 DWORD i, pos, dashes[MAX_DASHLEN];
30 len = min( len, MAX_DASHLEN );
31 memcpy( dashes, style, len * sizeof(DWORD) );
32 for (i = pos = 0; i < len; i++)
34 if (!dashes[i]) /* get rid of 0 entry */
36 if (i < len - 1)
38 i++;
39 if (pos) dashes[pos - 1] += dashes[i];
40 else dashes[len - 1] += dashes[i];
42 else if (pos)
44 dashes[0] += dashes[pos - 1];
45 pos--;
48 else dashes[pos++] = dashes[i];
50 for (i = 0; i < pos; i++) res[i] = min( dashes[i], 255 );
51 return pos;
54 /***********************************************************************
55 * SelectPen (X11DRV.@)
57 HPEN X11DRV_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern )
59 static const char PEN_dash[] = { 16,8 };
60 static const char PEN_dot[] = { 4,4 };
61 static const char PEN_dashdot[] = { 12,8,4,8 };
62 static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
63 static const char PEN_alternate[] = { 1,1 };
64 static const char EXTPEN_dash[] = { 3,1 };
65 static const char EXTPEN_dot[] = { 1,1 };
66 static const char EXTPEN_dashdot[] = { 3,1,1,1 };
67 static const char EXTPEN_dashdotdot[] = { 3,1,1,1,1,1 };
68 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
69 LOGPEN logpen;
70 int i;
71 EXTLOGPEN *elp = NULL;
73 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
75 /* must be an extended pen */
76 INT size = GetObjectW( hpen, 0, NULL );
78 if (!size) return 0;
80 physDev->pen.ext = 1;
81 elp = HeapAlloc( GetProcessHeap(), 0, size );
83 GetObjectW( hpen, size, elp );
84 logpen.lopnStyle = elp->elpPenStyle;
85 logpen.lopnWidth.x = elp->elpWidth;
86 logpen.lopnWidth.y = 0;
87 logpen.lopnColor = elp->elpColor;
89 else
90 physDev->pen.ext = 0;
92 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
93 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
94 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
95 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
97 physDev->pen.width = logpen.lopnWidth.x;
98 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width >= 1))
100 physDev->pen.width = X11DRV_XWStoDS( dev->hdc, physDev->pen.width );
101 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
104 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
105 if (hpen == GetStockObject( DC_PEN ))
106 logpen.lopnColor = GetDCPenColor( dev->hdc );
107 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
108 switch(logpen.lopnStyle & PS_STYLE_MASK)
110 case PS_DASH:
111 physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
112 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dash : PEN_dash,
113 physDev->pen.dash_len);
114 break;
115 case PS_DOT:
116 physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
117 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dot : PEN_dot,
118 physDev->pen.dash_len);
119 break;
120 case PS_DASHDOT:
121 physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
122 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdot : PEN_dashdot,
123 physDev->pen.dash_len);
124 break;
125 case PS_DASHDOTDOT:
126 physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
127 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdotdot : PEN_dashdotdot,
128 physDev->pen.dash_len);
129 break;
130 case PS_ALTERNATE:
131 physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
132 memcpy(physDev->pen.dashes, PEN_alternate, physDev->pen.dash_len);
133 break;
134 case PS_USERSTYLE:
135 physDev->pen.dash_len = get_user_dashes( physDev->pen.dashes,
136 elp->elpStyleEntry, elp->elpNumEntries );
137 break;
138 default:
139 physDev->pen.dash_len = 0;
140 break;
142 if(physDev->pen.ext && physDev->pen.dash_len && physDev->pen.width &&
143 (logpen.lopnStyle & PS_STYLE_MASK) != PS_USERSTYLE &&
144 (logpen.lopnStyle & PS_STYLE_MASK) != PS_ALTERNATE)
145 for(i = 0; i < physDev->pen.dash_len; i++)
146 physDev->pen.dashes[i] = min( physDev->pen.dashes[i] * physDev->pen.width, 255 );
148 HeapFree( GetProcessHeap(), 0, elp );
150 return hpen;
154 /***********************************************************************
155 * SetDCPenColor (X11DRV.@)
157 COLORREF X11DRV_SetDCPenColor( PHYSDEV dev, COLORREF crColor )
159 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
161 if (GetCurrentObject(dev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
162 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
164 return crColor;