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 DWORD PEN_dash
[] = { 50, 30 }; /* ----- ----- ----- */
32 static const DWORD PEN_dot
[] = { 20 }; /* -- -- -- -- -- -- */
33 static const DWORD PEN_dashdot
[] = { 40, 30, 20, 30 }; /* ---- -- ---- -- */
34 static const DWORD PEN_dashdotdot
[] = { 40, 20, 20, 20, 20, 20 }; /* ---- -- -- ---- */
35 static const DWORD PEN_alternate
[] = { 1 };
37 /***********************************************************************
40 HPEN
PSDRV_SelectPen( print_ctx
*ctx
, HPEN hpen
, const struct ps_brush_pattern
*pattern
)
43 EXTLOGPEN
*elp
= NULL
;
45 if (!GetObjectW( hpen
, sizeof(logpen
), &logpen
))
47 /* must be an extended pen */
48 INT size
= GetObjectW( hpen
, 0, NULL
);
52 elp
= HeapAlloc( GetProcessHeap(), 0, size
);
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
;
62 TRACE("hpen = %p colour = %08lx\n", hpen
, logpen
.lopnColor
);
64 ctx
->pen
.width
= logpen
.lopnWidth
.x
;
65 if ((logpen
.lopnStyle
& PS_GEOMETRIC
) || (ctx
->pen
.width
> 1))
67 ctx
->pen
.width
= PSDRV_XWStoDS( ctx
, ctx
->pen
.width
);
68 if(ctx
->pen
.width
< 0) ctx
->pen
.width
= -ctx
->pen
.width
;
70 if (hpen
== GetStockObject( DC_PEN
))
71 logpen
.lopnColor
= GetDCPenColor( ctx
->hdc
);
73 switch (logpen
.lopnStyle
& PS_JOIN_MASK
)
76 case PS_JOIN_ROUND
: ctx
->pen
.join
= 1; break;
77 case PS_JOIN_BEVEL
: ctx
->pen
.join
= 2; break;
78 case PS_JOIN_MITER
: ctx
->pen
.join
= 0; break;
81 switch (logpen
.lopnStyle
& PS_ENDCAP_MASK
)
84 case PS_ENDCAP_ROUND
: ctx
->pen
.endcap
= 1; break;
85 case PS_ENDCAP_SQUARE
: ctx
->pen
.endcap
= 2; break;
86 case PS_ENDCAP_FLAT
: ctx
->pen
.endcap
= 0; break;
89 PSDRV_CreateColor(ctx
, &ctx
->pen
.color
, logpen
.lopnColor
);
90 ctx
->pen
.style
= logpen
.lopnStyle
& PS_STYLE_MASK
;
92 switch(ctx
->pen
.style
) {
94 memcpy( ctx
->pen
.dash
, PEN_dash
, sizeof(PEN_dash
) );
95 ctx
->pen
.dash_len
= ARRAY_SIZE( PEN_dash
);
99 memcpy( ctx
->pen
.dash
, PEN_dot
, sizeof(PEN_dot
) );
100 ctx
->pen
.dash_len
= ARRAY_SIZE( PEN_dot
);
104 memcpy( ctx
->pen
.dash
, PEN_dashdot
, sizeof(PEN_dashdot
) );
105 ctx
->pen
.dash_len
= ARRAY_SIZE( PEN_dashdot
);
109 memcpy( ctx
->pen
.dash
, PEN_dashdotdot
, sizeof(PEN_dashdotdot
) );
110 ctx
->pen
.dash_len
= ARRAY_SIZE( PEN_dashdotdot
);
114 memcpy( ctx
->pen
.dash
, PEN_alternate
, sizeof(PEN_alternate
) );
115 ctx
->pen
.dash_len
= ARRAY_SIZE( PEN_alternate
);
119 ctx
->pen
.dash_len
= min( elp
->elpNumEntries
, MAX_DASHLEN
);
120 memcpy( ctx
->pen
.dash
, elp
->elpStyleEntry
, ctx
->pen
.dash_len
* sizeof(DWORD
) );
124 ctx
->pen
.dash_len
= 0;
127 if ((ctx
->pen
.width
> 1) && ctx
->pen
.dash_len
&&
128 ctx
->pen
.style
!= PS_USERSTYLE
&& ctx
->pen
.style
!= PS_ALTERNATE
)
130 ctx
->pen
.style
= PS_SOLID
;
131 ctx
->pen
.dash_len
= 0;
134 HeapFree( GetProcessHeap(), 0, elp
);
135 ctx
->pen
.set
= FALSE
;
140 /***********************************************************************
143 COLORREF
PSDRV_SetDCPenColor( print_ctx
*ctx
, COLORREF color
)
145 if (GetCurrentObject( ctx
->hdc
, OBJ_PEN
) == GetStockObject( DC_PEN
))
146 PSDRV_CreateColor( ctx
, &ctx
->pen
.color
, color
);
151 /**********************************************************************
156 BOOL
PSDRV_SetPen( print_ctx
*ctx
)
158 if (ctx
->pen
.style
!= PS_NULL
) {
159 PSDRV_WriteSetColor(ctx
, &ctx
->pen
.color
);
162 PSDRV_WriteSetPen(ctx
);