XFONT_GetAvgCharWidth: Always round up.
[wine/wine-gecko.git] / objects / pen.c
blobae55d64a9e4aebee20d13178e6645300965a8fa2
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <string.h>
11 #include "windef.h"
12 #include "wingdi.h"
14 #include "wine/wingdi16.h"
15 #include "pen.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(gdi);
23 /***********************************************************************
24 * CreatePen (GDI.61)
26 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
28 LOGPEN logpen;
30 TRACE("%d %d %06lx\n", style, width, color );
32 logpen.lopnStyle = style;
33 logpen.lopnWidth.x = width;
34 logpen.lopnWidth.y = 0;
35 logpen.lopnColor = color;
37 return CreatePenIndirect( &logpen );
41 /***********************************************************************
42 * CreatePen (GDI32.@)
44 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
46 LOGPEN logpen;
48 TRACE("%d %d %06lx\n", style, width, color );
50 logpen.lopnStyle = style;
51 logpen.lopnWidth.x = width;
52 logpen.lopnWidth.y = 0;
53 logpen.lopnColor = color;
55 return CreatePenIndirect( &logpen );
59 /***********************************************************************
60 * CreatePenIndirect (GDI.62)
62 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
64 PENOBJ * penPtr;
65 HPEN hpen;
67 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
68 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
69 penPtr->logpen.lopnStyle = pen->lopnStyle;
70 penPtr->logpen.lopnColor = pen->lopnColor;
71 CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
72 GDI_ReleaseObj( hpen );
73 return hpen;
77 /***********************************************************************
78 * CreatePenIndirect (GDI32.@)
80 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
82 PENOBJ * penPtr;
83 HPEN hpen;
85 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
86 penPtr->logpen.lopnStyle = pen->lopnStyle;
87 penPtr->logpen.lopnWidth = pen->lopnWidth;
88 penPtr->logpen.lopnColor = pen->lopnColor;
89 GDI_ReleaseObj( hpen );
90 return hpen;
93 /***********************************************************************
94 * ExtCreatePen (GDI32.@)
96 * FIXME: PS_USERSTYLE not handled
99 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
100 const LOGBRUSH * brush, DWORD style_count,
101 const DWORD *style_bits )
103 PENOBJ * penPtr;
104 HPEN hpen;
106 if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
107 FIXME("PS_USERSTYLE not handled\n");
108 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
109 if (brush->lbHatch)
110 FIXME("Hatches not implemented\n");
112 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
113 penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK;
115 /* PS_USERSTYLE workaround */
116 if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
117 penPtr->logpen.lopnStyle =
118 (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
120 penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
121 penPtr->logpen.lopnWidth.y = 0;
122 penPtr->logpen.lopnColor = brush->lbColor;
123 GDI_ReleaseObj( hpen );
125 return hpen;
128 /***********************************************************************
129 * PEN_GetObject16
131 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
133 LOGPEN16 logpen;
134 logpen.lopnStyle = pen->logpen.lopnStyle;
135 logpen.lopnColor = pen->logpen.lopnColor;
136 CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
137 if (count > sizeof(logpen)) count = sizeof(logpen);
138 memcpy( buffer, &logpen, count );
139 return count;
143 /***********************************************************************
144 * PEN_GetObject
146 INT PEN_GetObject( PENOBJ * pen, INT count, LPSTR buffer )
148 if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
149 memcpy( buffer, &pen->logpen, count );
150 return count;