In CopyDIBSection, use source DIB colormap instead if no palette has
[wine] / graphics / x11drv / pen.c
1 /*
2  * X11DRV pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #include "pen.h"
10 #include "color.h"
11 #include "x11drv.h"
12 #include "debugtools.h"
13
14 DEFAULT_DEBUG_CHANNEL(x11drv);
15
16 static const char PEN_dash[]       = { 16,8 };
17 static const char PEN_dot[]        = { 4,4 };
18 static const char PEN_dashdot[]    = { 12,8,4,8 };
19 static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
20 static const char PEN_alternate[]  = { 1,1 };
21
22 /***********************************************************************
23  *           PEN_SelectObject
24  */
25 HPEN X11DRV_PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen )
26 {
27     HPEN prevHandle = dc->hPen;
28     X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
29
30     dc->hPen = hpen;
31     physDev->pen.style = pen->logpen.lopnStyle & PS_STYLE_MASK;
32     physDev->pen.type = pen->logpen.lopnStyle & PS_TYPE_MASK;
33     physDev->pen.endcap = pen->logpen.lopnStyle & PS_ENDCAP_MASK;
34     physDev->pen.linejoin = pen->logpen.lopnStyle & PS_JOIN_MASK;
35
36     physDev->pen.width = GDI_ROUND((FLOAT)pen->logpen.lopnWidth.x *
37                                    dc->xformWorld2Vport.eM11 * 0.5);
38     if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
39     if (physDev->pen.width == 1) physDev->pen.width = 0;  /* Faster */
40     physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( dc, pen->logpen.lopnColor );    
41     switch(pen->logpen.lopnStyle & PS_STYLE_MASK)
42     {
43       case PS_DASH:
44         physDev->pen.dashes = (char *)PEN_dash;
45         physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
46         break;
47       case PS_DOT:
48         physDev->pen.dashes = (char *)PEN_dot;
49         physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
50         break;
51       case PS_DASHDOT:
52         physDev->pen.dashes = (char *)PEN_dashdot;
53         physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
54         break;
55       case PS_DASHDOTDOT:
56         physDev->pen.dashes = (char *)PEN_dashdotdot;
57         physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
58         break;
59       case PS_ALTERNATE:
60         physDev->pen.dashes = (char *)PEN_alternate;
61         physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
62         break;
63       case PS_USERSTYLE:
64         FIXME("PS_USERSTYLE is not supported\n");
65         break;
66     }
67     
68     return prevHandle;
69 }