2 * DIB driver GDI objects.
4 * Copyright 2011 Huw 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
24 #include "gdi_private.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dib
);
33 * Decompose the 16 ROP2s into an expression of the form
37 * Where A and X depend only on P (and so can be precomputed).
42 * R2_NOTMERGEPEN ~(D | P) ~P ~P
43 * R2_MASKNOTPEN ~P & D ~P 0
44 * R2_NOTCOPYPEN ~P 0 ~P
45 * R2_MASKPENNOT P & ~D P P
48 * R2_NOTMASKPEN ~(P & D) P 1
49 * R2_MASKPEN P & D P 0
50 * R2_NOTXORPEN ~(P ^ D) 1 ~P
52 * R2_MERGENOTPEN ~P | D P ~P
54 * R2_MERGEPENNOT P | ~D ~P 1
55 * R2_MERGEPEN P | D ~P P
60 /* A = (P & A1) ^ A2 */
61 #define ZERO { 0u, 0u}
62 #define ONE { 0u, ~0u}
64 #define NOT_P {~0u, ~0u}
66 static const DWORD rop2_and_array
[16][2] =
68 ZERO
, NOT_P
, NOT_P
, ZERO
,
71 ZERO
, NOT_P
, NOT_P
, ZERO
74 /* X = (P & X1) ^ X2 */
75 static const DWORD rop2_xor_array
[16][2] =
77 ZERO
, NOT_P
, ZERO
, NOT_P
,
79 ZERO
, NOT_P
, ZERO
, NOT_P
,
88 void get_rop_codes(INT rop
, struct rop_codes
*codes
)
90 /* NB The ROP2 codes start at one and the arrays are zero-based */
91 codes
->a1
= rop2_and_array
[rop
-1][0];
92 codes
->a2
= rop2_and_array
[rop
-1][1];
93 codes
->x1
= rop2_xor_array
[rop
-1][0];
94 codes
->x2
= rop2_xor_array
[rop
-1][1];
97 static inline void calc_and_xor_masks(INT rop
, DWORD color
, DWORD
*and, DWORD
*xor)
99 struct rop_codes codes
;
100 get_rop_codes( rop
, &codes
);
102 *and = (color
& codes
.a1
) ^ codes
.a2
;
103 *xor = (color
& codes
.x1
) ^ codes
.x2
;
106 static inline void calc_rop_masks(INT rop
, DWORD color
, rop_mask
*masks
)
108 calc_and_xor_masks( rop
, color
, &masks
->and, &masks
->xor );
111 static inline RGBQUAD
rgbquad_from_colorref(COLORREF c
)
115 ret
.rgbRed
= GetRValue(c
);
116 ret
.rgbGreen
= GetGValue(c
);
117 ret
.rgbBlue
= GetBValue(c
);
122 static inline BOOL
rgbquad_equal(const RGBQUAD
*a
, const RGBQUAD
*b
)
124 if(a
->rgbRed
== b
->rgbRed
&&
125 a
->rgbGreen
== b
->rgbGreen
&&
126 a
->rgbBlue
== b
->rgbBlue
)
131 COLORREF
make_rgb_colorref( HDC hdc
, dib_info
*dib
, COLORREF color
, BOOL
*got_pixel
, DWORD
*pixel
)
136 if (color
& (1 << 24)) /* PALETTEINDEX */
138 HPALETTE pal
= GetCurrentObject( hdc
, OBJ_PAL
);
139 PALETTEENTRY pal_ent
;
141 if (!GetPaletteEntries( pal
, LOWORD(color
), 1, &pal_ent
))
142 GetPaletteEntries( pal
, 0, 1, &pal_ent
);
143 return RGB( pal_ent
.peRed
, pal_ent
.peGreen
, pal_ent
.peBlue
);
146 if (color
>> 16 == 0x10ff) /* DIBINDEX */
148 WORD index
= LOWORD( color
);
150 if (!dib
->color_table
|| index
>= (1 << dib
->bit_count
)) return 0;
152 return RGB( dib
->color_table
[index
].rgbRed
,
153 dib
->color_table
[index
].rgbGreen
,
154 dib
->color_table
[index
].rgbBlue
);
157 return color
& 0xffffff;
160 /******************************************************************
163 * 1 bit bitmaps map the fg/bg colors as follows:
164 * If the fg colorref exactly matches one of the color table entries then
165 * that entry is the fg color and the other is the bg.
166 * Otherwise the bg color is mapped to the closest entry in the table and
167 * the fg takes the other one.
169 DWORD
get_pixel_color( dibdrv_physdev
*pdev
, COLORREF color
, BOOL mono_fixup
)
176 rgb_ref
= make_rgb_colorref( pdev
->dev
.hdc
, &pdev
->dib
, color
, &got_pixel
, &pixel
);
177 if (got_pixel
) return pixel
;
179 if (pdev
->dib
.bit_count
!= 1 || !mono_fixup
)
180 return pdev
->dib
.funcs
->colorref_to_pixel( &pdev
->dib
, rgb_ref
);
182 fg_quad
= rgbquad_from_colorref( rgb_ref
);
183 if(rgbquad_equal(&fg_quad
, pdev
->dib
.color_table
))
185 if(rgbquad_equal(&fg_quad
, pdev
->dib
.color_table
+ 1))
188 pixel
= get_pixel_color( pdev
, GetBkColor(pdev
->dev
.hdc
), FALSE
);
189 if (color
== GetBkColor(pdev
->dev
.hdc
)) return pixel
;
193 /***************************************************************************
196 * Returns the color masks unless the dib is 1 bpp. In this case since
197 * there are several fg sources (pen, brush, text) we take as bg the inverse
198 * of the relevant fg color (which is always set up correctly).
200 static inline void get_color_masks( dibdrv_physdev
*pdev
, UINT rop
, COLORREF colorref
,
201 INT bkgnd_mode
, rop_mask
*fg_mask
, rop_mask
*bg_mask
)
203 DWORD color
= get_pixel_color( pdev
, colorref
, TRUE
);
205 calc_rop_masks( rop
, color
, fg_mask
);
207 if (bkgnd_mode
== TRANSPARENT
)
214 if (pdev
->dib
.bit_count
!= 1) color
= get_pixel_color( pdev
, GetBkColor(pdev
->dev
.hdc
), FALSE
);
215 else if (colorref
!= GetBkColor(pdev
->dev
.hdc
)) color
= !color
;
217 calc_rop_masks( rop
, color
, bg_mask
);
220 static inline void order_end_points(int *s
, int *e
)
231 #define Y_INCREASING_MASK 0x0f
232 #define X_INCREASING_MASK 0xc3
233 #define X_MAJOR_MASK 0x99
234 #define POS_SLOPE_MASK 0x33
236 static inline BOOL
is_xmajor(DWORD octant
)
238 return octant
& X_MAJOR_MASK
;
241 static inline BOOL
is_pos_slope(DWORD octant
)
243 return octant
& POS_SLOPE_MASK
;
246 static inline BOOL
is_x_increasing(DWORD octant
)
248 return octant
& X_INCREASING_MASK
;
251 static inline BOOL
is_y_increasing(DWORD octant
)
253 return octant
& Y_INCREASING_MASK
;
256 /**********************************************************************
259 * Return the octant number starting clockwise from the +ve x-axis.
261 static inline int get_octant_number(int dx
, int dy
)
265 return ( dx
> dy
) ? 1 : 2;
267 return (-dx
> dy
) ? 4 : 3;
270 return (-dx
> -dy
) ? 5 : 6;
272 return ( dx
> -dy
) ? 8 : 7;
275 static inline DWORD
get_octant_mask(int dx
, int dy
)
277 return 1 << (get_octant_number(dx
, dy
) - 1);
280 static inline int get_bias( DWORD mask
)
282 /* Octants 3, 5, 6 and 8 take a bias */
283 return (mask
& 0xb4) ? 1 : 0;
291 static inline DWORD
calc_outcode(const POINT
*pt
, const RECT
*clip
)
294 if(pt
->x
< clip
->left
) out
|= OUT_LEFT
;
295 else if(pt
->x
>= clip
->right
) out
|= OUT_RIGHT
;
296 if(pt
->y
< clip
->top
) out
|= OUT_TOP
;
297 else if(pt
->y
>= clip
->bottom
) out
|= OUT_BOTTOM
;
302 /******************************************************************************
305 * Clips the start and end points to a rectangle.
307 * Note, this treats the end point like the start point. If the
308 * caller doesn't want it displayed, it should exclude it. If the end
309 * point is clipped out, then the likelihood is that the new end point
310 * should be displayed.
312 * Returns 0 if totally excluded, 1 if partially clipped and 2 if unclipped.
314 * This derivation is based on the comments in X.org's xserver/mi/mizerclip.c,
315 * however the Bresenham error term is defined differently so the equations
318 * For x major lines we have 2dy >= err + bias > 2dy - 2dx
319 * 0 >= err + bias - 2dy > -2dx
321 * Note dx, dy, m and n are all +ve.
323 * Moving the start pt from x1 to x1 + m, we need to figure out y1 + n.
324 * err = 2dy - dx + 2mdy - 2ndx
325 * 0 >= 2dy - dx + 2mdy - 2ndx + bias - 2dy > -2dx
326 * 0 >= 2mdy - 2ndx + bias - dx > -2dx
327 * which of course will give exactly one solution for n,
328 * so looking at the >= inequality
329 * n >= (2mdy + bias - dx) / 2dx
330 * n = ceiling((2mdy + bias - dx) / 2dx)
331 * = (2mdy + bias + dx - 1) / 2dx (assuming division truncation)
333 * Moving start pt from y1 to y1 + n we need to figure out x1 + m - there may be several
334 * solutions we pick the one that minimizes m (ie that first unlipped pt). As above:
335 * 0 >= 2mdy - 2ndx + bias - dx > -2dx
336 * 2mdy > 2ndx - bias - dx
337 * m > (2ndx - bias - dx) / 2dy
338 * m = floor((2ndx - bias - dx) / 2dy) + 1
339 * m = (2ndx - bias - dx) / 2dy + 1
341 * Moving end pt from x2 to x2 - m, we need to figure out y2 - n
342 * err = 2dy - dx + 2(dx - m)dy - 2(dy - n)dx
343 * = 2dy - dx - 2mdy + 2ndx
344 * 0 >= 2dy - dx - 2mdy + 2ndx + bias - 2dy > -2dx
345 * 0 >= 2ndx - 2mdy + bias - dx > -2dx
346 * again exactly one solution.
347 * 2ndx <= 2mdy - bias + dx
348 * n = floor((2mdy - bias + dx) / 2dx)
349 * = (2mdy - bias + dx) / 2dx
351 * Moving end pt from y2 to y2 - n when need x2 - m this time maximizing x2 - m so
352 * mininizing m to include all of the points at y = y2 - n. As above:
353 * 0 >= 2ndx - 2mdy + bias - dx > -2dx
354 * 2mdy >= 2ndx + bias - dx
355 * m = ceiling((2ndx + bias - dx) / 2dy)
356 * = (2ndx + bias - dx - 1) / 2dy + 1
358 * For y major lines, symmetry (dx <-> dy and swap the cases over) gives:
360 * Moving start point from y1 to y1 + n find x1 + m
361 * m = (2ndx + bias + dy - 1) / 2dy
363 * Moving start point from x1 to x1 + m find y1 + n
364 * n = (2mdy - bias - dy) / 2ndx + 1
366 * Moving end point from y2 to y2 - n find x1 - m
367 * m = (2ndx - bias + dy) / 2dy
369 * Moving end point from x2 to x2 - m find y2 - n
370 * n = (2mdy + bias - dy - 1) / 2dx + 1
372 int clip_line(const POINT
*start
, const POINT
*end
, const RECT
*clip
,
373 const bres_params
*params
, POINT
*pt1
, POINT
*pt2
)
376 INT64 m
, n
; /* 64-bit to avoid overflows (FIXME: find a more efficient way) */
377 BOOL clipped
= FALSE
;
378 DWORD start_oc
, end_oc
;
379 const int bias
= params
->bias
;
380 const unsigned int dx
= params
->dx
;
381 const unsigned int dy
= params
->dy
;
382 const unsigned int two_dx
= params
->dx
* 2;
383 const unsigned int two_dy
= params
->dy
* 2;
384 const BOOL xmajor
= is_xmajor(params
->octant
);
385 const BOOL neg_slope
= !is_pos_slope(params
->octant
);
390 start_oc
= calc_outcode(start
, clip
);
391 end_oc
= calc_outcode(end
, clip
);
395 if(start_oc
== 0 && end_oc
== 0) return clipped
? 1 : 2; /* trivial accept */
396 if(start_oc
& end_oc
) return 0; /* trivial reject */
399 if(start_oc
& OUT_LEFT
)
401 m
= clip
->left
- start
->x
;
403 n
= (m
* two_dy
+ bias
+ dx
- 1) / two_dx
;
405 n
= (m
* two_dy
- bias
- dy
) / two_dx
+ 1;
408 if(neg_slope
) n
= -n
;
409 pt1
->y
= start
->y
+ n
;
410 start_oc
= calc_outcode(pt1
, clip
);
412 else if(start_oc
& OUT_RIGHT
)
414 m
= start
->x
- clip
->right
+ 1;
416 n
= (m
* two_dy
+ bias
+ dx
- 1) / two_dx
;
418 n
= (m
* two_dy
- bias
- dy
) / two_dx
+ 1;
420 pt1
->x
= clip
->right
- 1;
421 if(neg_slope
) n
= -n
;
422 pt1
->y
= start
->y
- n
;
423 start_oc
= calc_outcode(pt1
, clip
);
425 else if(start_oc
& OUT_TOP
)
427 n
= clip
->top
- start
->y
;
429 m
= (n
* two_dx
- bias
- dx
) / two_dy
+ 1;
431 m
= (n
* two_dx
+ bias
+ dy
- 1) / two_dy
;
434 if(neg_slope
) m
= -m
;
435 pt1
->x
= start
->x
+ m
;
436 start_oc
= calc_outcode(pt1
, clip
);
438 else if(start_oc
& OUT_BOTTOM
)
440 n
= start
->y
- clip
->bottom
+ 1;
442 m
= (n
* two_dx
- bias
- dx
) / two_dy
+ 1;
444 m
= (n
* two_dx
+ bias
+ dy
- 1) / two_dy
;
446 pt1
->y
= clip
->bottom
- 1;
447 if(neg_slope
) m
= -m
;
448 pt1
->x
= start
->x
- m
;
449 start_oc
= calc_outcode(pt1
, clip
);
451 else if(end_oc
& OUT_LEFT
)
453 m
= clip
->left
- end
->x
;
455 n
= (m
* two_dy
- bias
+ dx
) / two_dx
;
457 n
= (m
* two_dy
+ bias
- dy
- 1) / two_dx
+ 1;
460 if(neg_slope
) n
= -n
;
462 end_oc
= calc_outcode(pt2
, clip
);
464 else if(end_oc
& OUT_RIGHT
)
466 m
= end
->x
- clip
->right
+ 1;
468 n
= (m
* two_dy
- bias
+ dx
) / two_dx
;
470 n
= (m
* two_dy
+ bias
- dy
- 1) / two_dx
+ 1;
472 pt2
->x
= clip
->right
- 1;
473 if(neg_slope
) n
= -n
;
475 end_oc
= calc_outcode(pt2
, clip
);
477 else if(end_oc
& OUT_TOP
)
479 n
= clip
->top
- end
->y
;
481 m
= (n
* two_dx
+ bias
- dx
- 1) / two_dy
+ 1;
483 m
= (n
* two_dx
- bias
+ dy
) / two_dy
;
486 if(neg_slope
) m
= -m
;
488 end_oc
= calc_outcode(pt2
, clip
);
490 else if(end_oc
& OUT_BOTTOM
)
492 n
= end
->y
- clip
->bottom
+ 1;
494 m
= (n
* two_dx
+ bias
- dx
- 1) / two_dy
+ 1;
496 m
= (n
* two_dx
- bias
+ dy
) / two_dy
;
498 pt2
->y
= clip
->bottom
- 1;
499 if(neg_slope
) m
= -m
;
501 end_oc
= calc_outcode(pt2
, clip
);
506 static void bres_line_with_bias(const POINT
*start
, const struct line_params
*params
,
507 void (* callback
)(dibdrv_physdev
*,INT
,INT
), dibdrv_physdev
*pdev
)
510 int len
= params
->length
, err
= params
->err_start
;
516 callback(pdev
, pt
.x
, pt
.y
);
517 if (err
+ params
->bias
> 0)
519 pt
.y
+= params
->y_inc
;
520 err
+= params
->err_add_1
;
522 else err
+= params
->err_add_2
;
523 pt
.x
+= params
->x_inc
;
530 callback(pdev
, pt
.x
, pt
.y
);
531 if (err
+ params
->bias
> 0)
533 pt
.x
+= params
->x_inc
;
534 err
+= params
->err_add_1
;
536 else err
+= params
->err_add_2
;
537 pt
.y
+= params
->y_inc
;
542 static BOOL
solid_pen_line(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, DWORD
and, DWORD
xor)
544 struct clipped_rects clipped_rects
;
548 if(start
->y
== end
->y
)
550 rect
.left
= start
->x
;
553 rect
.bottom
= end
->y
+ 1;
554 order_end_points(&rect
.left
, &rect
.right
);
555 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
556 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, and, xor);
558 else if(start
->x
== end
->x
)
560 rect
.left
= start
->x
;
562 rect
.right
= end
->x
+ 1;
563 rect
.bottom
= end
->y
;
564 order_end_points(&rect
.top
, &rect
.bottom
);
565 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
566 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, and, xor);
570 bres_params clip_params
;
571 struct line_params line_params
;
572 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
573 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
575 clip_params
.dx
= abs_dx
;
576 clip_params
.dy
= abs_dy
;
577 clip_params
.octant
= get_octant_mask(dx
, dy
);
578 clip_params
.bias
= get_bias( clip_params
.octant
);
580 line_params
.bias
= clip_params
.bias
;
581 line_params
.x_major
= is_xmajor( clip_params
.octant
);
582 line_params
.x_inc
= is_x_increasing( clip_params
.octant
) ? 1 : -1;
583 line_params
.y_inc
= is_y_increasing( clip_params
.octant
) ? 1 : -1;
585 if (line_params
.x_major
)
587 line_params
.err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
588 line_params
.err_add_2
= 2 * abs_dy
;
592 line_params
.err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
593 line_params
.err_add_2
= 2 * abs_dx
;
596 rect
.left
= min( start
->x
, end
->x
);
597 rect
.top
= min( start
->y
, end
->y
);
598 rect
.right
= max( start
->x
, end
->x
) + 1;
599 rect
.bottom
= max( start
->y
, end
->y
) + 1;
600 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
601 for (i
= 0; i
< clipped_rects
.count
; i
++)
603 POINT clipped_start
, clipped_end
;
606 clip_status
= clip_line(start
, end
, clipped_rects
.rects
+ i
, &clip_params
, &clipped_start
, &clipped_end
);
609 int m
= abs(clipped_start
.x
- start
->x
);
610 int n
= abs(clipped_start
.y
- start
->y
);
612 if (line_params
.x_major
)
614 line_params
.err_start
= 2 * abs_dy
- abs_dx
+ m
* 2 * abs_dy
- n
* 2 * abs_dx
;
615 line_params
.length
= abs( clipped_end
.x
- clipped_start
.x
) + 1;
619 line_params
.err_start
= 2 * abs_dx
- abs_dy
+ n
* 2 * abs_dx
- m
* 2 * abs_dy
;
620 line_params
.length
= abs( clipped_end
.y
- clipped_start
.y
) + 1;
623 if (clipped_end
.x
== end
->x
&& clipped_end
.y
== end
->y
) line_params
.length
--;
625 pdev
->dib
.funcs
->solid_line( &pdev
->dib
, &clipped_start
, &line_params
, and, xor );
627 if(clip_status
== 2) break; /* completely unclipped, so we can finish */
631 free_clipped_rects( &clipped_rects
);
635 static BOOL
solid_pen_line_region( dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, HRGN region
)
639 rect
.left
= start
->x
;
641 rect
.right
= start
->x
+ 1;
642 rect
.bottom
= start
->y
+ 1;
644 if (start
->y
== end
->y
)
647 order_end_points(&rect
.left
, &rect
.right
);
648 add_rect_to_region( region
, &rect
);
650 else if(start
->x
== end
->x
)
652 rect
.bottom
= end
->y
;
653 order_end_points(&rect
.top
, &rect
.bottom
);
654 add_rect_to_region( region
, &rect
);
658 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
659 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
660 DWORD octant
= get_octant_mask(dx
, dy
);
661 INT bias
= get_bias( octant
);
663 if (is_xmajor( octant
))
665 int y_inc
= is_y_increasing( octant
) ? 1 : -1;
666 int err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
667 int err_add_2
= 2 * abs_dy
;
668 int err
= 2 * abs_dy
- abs_dx
;
670 if (is_x_increasing( octant
))
672 for (rect
.right
= start
->x
+ 1; rect
.right
<= end
->x
; rect
.right
++)
676 add_rect_to_region( region
, &rect
);
677 rect
.left
= rect
.right
;
679 rect
.bottom
+= y_inc
;
682 else err
+= err_add_2
;
687 for (rect
.left
= start
->x
; rect
.left
> end
->x
; rect
.left
--)
691 add_rect_to_region( region
, &rect
);
692 rect
.right
= rect
.left
;
694 rect
.bottom
+= y_inc
;
697 else err
+= err_add_2
;
703 int x_inc
= is_x_increasing( octant
) ? 1 : -1;
704 int err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
705 int err_add_2
= 2 * abs_dx
;
706 int err
= 2 * abs_dx
- abs_dy
;
708 if (is_y_increasing( octant
))
710 for (rect
.bottom
= start
->y
+ 1; rect
.bottom
<= end
->y
; rect
.bottom
++)
714 add_rect_to_region( region
, &rect
);
715 rect
.top
= rect
.bottom
;
720 else err
+= err_add_2
;
725 for (rect
.top
= start
->y
; rect
.top
> end
->y
; rect
.top
--)
729 add_rect_to_region( region
, &rect
);
730 rect
.bottom
= rect
.top
;
735 else err
+= err_add_2
;
740 add_rect_to_region( region
, &rect
);
745 static BOOL
solid_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
753 for (i
= 0; i
< num
- 1; i
++)
754 if (!solid_pen_line_region( pdev
, pts
+ i
, pts
+ i
+ 1, region
))
756 if (close
) return solid_pen_line_region( pdev
, pts
+ num
- 1, pts
, region
);
760 DWORD color
, and, xor;
762 color
= get_pixel_color( pdev
, pdev
->pen_brush
.colorref
, TRUE
);
763 calc_and_xor_masks( GetROP2(pdev
->dev
.hdc
), color
, &and, &xor );
765 for (i
= 0; i
< num
- 1; i
++)
766 if (!solid_pen_line( pdev
, pts
+ i
, pts
+ i
+ 1, and, xor ))
768 if (close
) return solid_pen_line( pdev
, pts
+ num
- 1, pts
, and, xor );
773 void reset_dash_origin(dibdrv_physdev
*pdev
)
775 pdev
->dash_pos
.cur_dash
= 0;
776 pdev
->dash_pos
.left_in_dash
= pdev
->pen_pattern
.dashes
[0];
777 pdev
->dash_pos
.mark
= TRUE
;
780 static inline void skip_dash(dibdrv_physdev
*pdev
, unsigned int skip
)
782 skip
%= pdev
->pen_pattern
.total_len
;
785 if(pdev
->dash_pos
.left_in_dash
> skip
)
787 pdev
->dash_pos
.left_in_dash
-= skip
;
790 skip
-= pdev
->dash_pos
.left_in_dash
;
791 pdev
->dash_pos
.cur_dash
++;
792 if(pdev
->dash_pos
.cur_dash
== pdev
->pen_pattern
.count
) pdev
->dash_pos
.cur_dash
= 0;
793 pdev
->dash_pos
.left_in_dash
= pdev
->pen_pattern
.dashes
[pdev
->dash_pos
.cur_dash
];
794 pdev
->dash_pos
.mark
= !pdev
->dash_pos
.mark
;
799 static void dashed_pen_line_callback(dibdrv_physdev
*pdev
, INT x
, INT y
)
802 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
809 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
813 static BOOL
dashed_pen_line(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
)
815 struct clipped_rects clipped_rects
;
818 const dash_pos start_pos
= pdev
->dash_pos
;
820 if(start
->y
== end
->y
) /* hline */
823 INT left
, right
, cur_x
;
826 rect
.bottom
= start
->y
+ 1;
828 if(start
->x
<= end
->x
)
841 rect
.left
= min( start
->x
, end
->x
);
842 rect
.right
= max( start
->x
, end
->x
) + 1;
843 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
844 for (i
= 0; i
< clipped_rects
.count
; i
++)
846 if(clipped_rects
.rects
[i
].right
> left
&& clipped_rects
.rects
[i
].left
<= right
)
848 int clipped_left
= max(clipped_rects
.rects
[i
].left
, left
);
849 int clipped_right
= min(clipped_rects
.rects
[i
].right
- 1, right
);
851 pdev
->dash_pos
= start_pos
;
855 cur_x
= clipped_left
;
857 skip_dash(pdev
, clipped_left
- left
);
859 while(cur_x
<= clipped_right
)
861 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
862 dash_len
= pdev
->dash_pos
.left_in_dash
;
863 if(cur_x
+ dash_len
> clipped_right
+ 1)
864 dash_len
= clipped_right
- cur_x
+ 1;
866 rect
.right
= cur_x
+ dash_len
;
868 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
870 skip_dash(pdev
, dash_len
);
875 cur_x
= clipped_right
;
877 skip_dash(pdev
, right
- clipped_right
);
879 while(cur_x
>= clipped_left
)
881 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
882 dash_len
= pdev
->dash_pos
.left_in_dash
;
883 if(cur_x
- dash_len
< clipped_left
- 1)
884 dash_len
= cur_x
- clipped_left
+ 1;
885 rect
.left
= cur_x
- dash_len
+ 1;
886 rect
.right
= cur_x
+ 1;
888 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
890 skip_dash(pdev
, dash_len
);
895 pdev
->dash_pos
= start_pos
;
896 skip_dash(pdev
, right
- left
+ 1);
898 else if(start
->x
== end
->x
) /* vline */
901 INT top
, bottom
, cur_y
;
903 rect
.left
= start
->x
;
904 rect
.right
= start
->x
+ 1;
906 if(start
->y
<= end
->y
)
919 rect
.top
= min( start
->y
, end
->y
);
920 rect
.bottom
= max( start
->y
, end
->y
) + 1;
921 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
922 for (i
= 0; i
< clipped_rects
.count
; i
++)
924 if(clipped_rects
.rects
[i
].right
> start
->x
&& clipped_rects
.rects
[i
].left
<= start
->x
)
926 int clipped_top
= max(clipped_rects
.rects
[i
].top
, top
);
927 int clipped_bottom
= min(clipped_rects
.rects
[i
].bottom
- 1, bottom
);
929 pdev
->dash_pos
= start_pos
;
935 skip_dash(pdev
, clipped_top
- top
);
937 while(cur_y
<= clipped_bottom
)
939 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
940 dash_len
= pdev
->dash_pos
.left_in_dash
;
941 if(cur_y
+ dash_len
> clipped_bottom
+ 1)
942 dash_len
= clipped_bottom
- cur_y
+ 1;
944 rect
.bottom
= cur_y
+ dash_len
;
946 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
948 skip_dash(pdev
, dash_len
);
953 cur_y
= clipped_bottom
;
955 skip_dash(pdev
, bottom
- clipped_bottom
);
957 while(cur_y
>= clipped_top
)
959 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
960 dash_len
= pdev
->dash_pos
.left_in_dash
;
961 if(cur_y
- dash_len
< clipped_top
- 1)
962 dash_len
= cur_y
- clipped_top
+ 1;
963 rect
.top
= cur_y
- dash_len
+ 1;
964 rect
.bottom
= cur_y
+ 1;
966 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
968 skip_dash(pdev
, dash_len
);
973 pdev
->dash_pos
= start_pos
;
974 skip_dash(pdev
, bottom
- top
+ 1);
978 bres_params clip_params
;
979 struct line_params line_params
;
980 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
981 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
983 clip_params
.dx
= abs_dx
;
984 clip_params
.dy
= abs_dy
;
985 clip_params
.octant
= get_octant_mask(dx
, dy
);
986 clip_params
.bias
= get_bias( clip_params
.octant
);
988 line_params
.bias
= clip_params
.bias
;
989 line_params
.x_major
= is_xmajor( clip_params
.octant
);
990 line_params
.x_inc
= is_x_increasing( clip_params
.octant
) ? 1 : -1;
991 line_params
.y_inc
= is_y_increasing( clip_params
.octant
) ? 1 : -1;
993 if (line_params
.x_major
)
995 line_params
.err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
996 line_params
.err_add_2
= 2 * abs_dy
;
1000 line_params
.err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
1001 line_params
.err_add_2
= 2 * abs_dx
;
1004 rect
.left
= min( start
->x
, end
->x
);
1005 rect
.top
= min( start
->y
, end
->y
);
1006 rect
.right
= max( start
->x
, end
->x
) + 1;
1007 rect
.bottom
= max( start
->y
, end
->y
) + 1;
1008 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
1009 for (i
= 0; i
< clipped_rects
.count
; i
++)
1011 POINT clipped_start
, clipped_end
;
1013 clip_status
= clip_line(start
, end
, clipped_rects
.rects
+ i
, &clip_params
, &clipped_start
, &clipped_end
);
1017 int m
= abs(clipped_start
.x
- start
->x
);
1018 int n
= abs(clipped_start
.y
- start
->y
);
1020 pdev
->dash_pos
= start_pos
;
1022 if (line_params
.x_major
)
1024 line_params
.err_start
= 2 * abs_dy
- abs_dx
+ m
* 2 * abs_dy
- n
* 2 * abs_dx
;
1025 line_params
.length
= abs( clipped_end
.x
- clipped_start
.x
) + 1;
1030 line_params
.err_start
= 2 * abs_dx
- abs_dy
+ n
* 2 * abs_dx
- m
* 2 * abs_dy
;
1031 line_params
.length
= abs( clipped_end
.y
- clipped_start
.y
) + 1;
1034 if (clipped_end
.x
== end
->x
&& clipped_end
.y
== end
->y
) line_params
.length
--;
1036 bres_line_with_bias( &clipped_start
, &line_params
, dashed_pen_line_callback
, pdev
);
1038 if(clip_status
== 2) break; /* completely unclipped, so we can finish */
1041 pdev
->dash_pos
= start_pos
;
1042 if(line_params
.x_major
)
1043 skip_dash(pdev
, abs_dx
);
1045 skip_dash(pdev
, abs_dy
);
1048 free_clipped_rects( &clipped_rects
);
1052 static BOOL
dashed_pen_line_region(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, HRGN region
)
1057 rect
.left
= start
->x
;
1058 rect
.top
= start
->y
;
1059 rect
.right
= start
->x
+ 1;
1060 rect
.bottom
= start
->y
+ 1;
1062 if (start
->y
== end
->y
) /* hline */
1064 if (start
->x
<= end
->x
)
1066 for (i
= start
->x
; i
< end
->x
; i
+= dash_len
)
1068 dash_len
= min( pdev
->dash_pos
.left_in_dash
, end
->x
- i
);
1069 if (pdev
->dash_pos
.mark
)
1072 rect
.right
= i
+ dash_len
;
1073 add_rect_to_region( region
, &rect
);
1075 skip_dash(pdev
, dash_len
);
1080 for (i
= start
->x
; i
> end
->x
; i
-= dash_len
)
1082 dash_len
= min( pdev
->dash_pos
.left_in_dash
, i
- end
->x
);
1083 if (pdev
->dash_pos
.mark
)
1085 rect
.left
= i
- dash_len
+ 1;
1087 add_rect_to_region( region
, &rect
);
1089 skip_dash(pdev
, dash_len
);
1093 else if (start
->x
== end
->x
) /* vline */
1095 if (start
->y
<= end
->y
)
1097 for (i
= start
->y
; i
< end
->y
; i
+= dash_len
)
1099 dash_len
= min( pdev
->dash_pos
.left_in_dash
, end
->y
- i
);
1100 if (pdev
->dash_pos
.mark
)
1103 rect
.bottom
= i
+ dash_len
;
1104 add_rect_to_region( region
, &rect
);
1106 skip_dash(pdev
, dash_len
);
1111 for (i
= start
->y
; i
> end
->y
; i
-= dash_len
)
1113 dash_len
= min( pdev
->dash_pos
.left_in_dash
, i
- end
->y
);
1114 if (pdev
->dash_pos
.mark
)
1116 rect
.top
= i
- dash_len
+ 1;
1117 rect
.bottom
= i
+ 1;
1118 add_rect_to_region( region
, &rect
);
1120 skip_dash(pdev
, dash_len
);
1126 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
1127 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
1128 DWORD octant
= get_octant_mask(dx
, dy
);
1129 INT bias
= get_bias( octant
);
1130 int x_inc
= is_x_increasing( octant
) ? 1 : -1;
1131 int y_inc
= is_y_increasing( octant
) ? 1 : -1;
1133 if (is_xmajor( octant
))
1135 int err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
1136 int err_add_2
= 2 * abs_dy
;
1137 int err
= 2 * abs_dy
- abs_dx
;
1141 if (pdev
->dash_pos
.mark
) add_rect_to_region( region
, &rect
);
1144 rect
.right
+= x_inc
;
1148 rect
.bottom
+= y_inc
;
1151 else err
+= err_add_2
;
1157 int err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
1158 int err_add_2
= 2 * abs_dx
;
1159 int err
= 2 * abs_dx
- abs_dy
;
1163 if (pdev
->dash_pos
.mark
) add_rect_to_region( region
, &rect
);
1166 rect
.bottom
+= y_inc
;
1170 rect
.right
+= x_inc
;
1173 else err
+= err_add_2
;
1180 static BOOL
dashed_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
1188 for (i
= 0; i
< num
- 1; i
++)
1189 if (!dashed_pen_line_region( pdev
, pts
+ i
, pts
+ i
+ 1, region
))
1191 if (close
) return dashed_pen_line_region( pdev
, pts
+ num
- 1, pts
, region
);
1195 get_color_masks( pdev
, GetROP2(pdev
->dev
.hdc
), pdev
->pen_brush
.colorref
,
1196 pdev
->pen_is_ext
? TRANSPARENT
: GetBkMode(pdev
->dev
.hdc
),
1197 &pdev
->dash_masks
[1], &pdev
->dash_masks
[0] );
1199 for (i
= 0; i
< num
- 1; i
++)
1200 if (!dashed_pen_line( pdev
, pts
+ i
, pts
+ i
+ 1 ))
1202 if (close
) return dashed_pen_line( pdev
, pts
+ num
- 1, pts
);
1207 static BOOL
null_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
1218 static void add_cap( dibdrv_physdev
*pdev
, HRGN region
, HRGN round_cap
, const POINT
*pt
)
1220 switch (pdev
->pen_endcap
)
1222 default: FIXME( "Unknown end cap %x\n", pdev
->pen_endcap
);
1224 case PS_ENDCAP_ROUND
:
1225 OffsetRgn( round_cap
, pt
->x
, pt
->y
);
1226 CombineRgn( region
, region
, round_cap
, RGN_OR
);
1227 OffsetRgn( round_cap
, -pt
->x
, -pt
->y
);
1230 case PS_ENDCAP_SQUARE
: /* already been handled */
1231 case PS_ENDCAP_FLAT
:
1236 #define round( f ) (((f) > 0) ? (f) + 0.5 : (f) - 0.5)
1238 /*******************************************************************************
1239 * create_miter_region
1241 * We need to calculate the intersection of two lines. We know a point
1242 * on each line (a face start and the other face end point) and
1243 * the direction vector of each line eg. (dx_1, dy_1).
1245 * (x, y) = (x_1, y_1) + u * (dx_1, dy_1) = (x_2, y_2) + v * (dx_2, dy_2)
1246 * solving (eg using Cramer's rule) gives:
1247 * u = ((x_2 - x_1) dy_2 - (y_2 - y_1) dx_2) / det
1248 * with det = dx_1 dy_2 - dx_2 dy_1
1249 * substituting back in and simplifying gives
1250 * (x, y) = a (dx_1, dy_1) - b (dx_2, dy_2)
1251 * with a = (x_2 dy_2 - y_2 dx_2) / det
1252 * and b = (x_1 dy_1 - y_1 dx_1) / det
1254 static HRGN
create_miter_region( dibdrv_physdev
*pdev
, const POINT
*pt
,
1255 const struct face
*face_1
, const struct face
*face_2
)
1257 int det
= face_1
->dx
* face_2
->dy
- face_1
->dy
* face_2
->dx
;
1258 POINT pt_1
, pt_2
, pts
[5];
1262 if (det
== 0) return 0;
1266 const struct face
*tmp
= face_1
;
1272 pt_1
= face_1
->start
;
1275 a
= (double)((pt_2
.x
* face_2
->dy
- pt_2
.y
* face_2
->dx
)) / det
;
1276 b
= (double)((pt_1
.x
* face_1
->dy
- pt_1
.y
* face_1
->dx
)) / det
;
1278 x
= a
* face_1
->dx
- b
* face_2
->dx
;
1279 y
= a
* face_1
->dy
- b
* face_2
->dy
;
1281 GetMiterLimit( pdev
->dev
.hdc
, &limit
);
1283 if (((x
- pt
->x
) * (x
- pt
->x
) + (y
- pt
->y
) * (y
- pt
->y
)) * 4 > limit
* limit
* pdev
->pen_width
* pdev
->pen_width
)
1286 pts
[0] = face_2
->start
;
1287 pts
[1] = face_1
->start
;
1288 pts
[2].x
= round( x
);
1289 pts
[2].y
= round( y
);
1290 pts
[3] = face_2
->end
;
1291 pts
[4] = face_1
->end
;
1293 return CreatePolygonRgn( pts
, 5, ALTERNATE
);
1296 static void add_join( dibdrv_physdev
*pdev
, HRGN region
, HRGN round_cap
, const POINT
*pt
,
1297 const struct face
*face_1
, const struct face
*face_2
)
1302 switch (pdev
->pen_join
)
1304 default: FIXME( "Unknown line join %x\n", pdev
->pen_join
);
1307 OffsetRgn( round_cap
, pt
->x
, pt
->y
);
1308 CombineRgn( region
, region
, round_cap
, RGN_OR
);
1309 OffsetRgn( round_cap
, -pt
->x
, -pt
->y
);
1313 join
= create_miter_region( pdev
, pt
, face_1
, face_2
);
1317 pts
[0] = face_1
->start
;
1318 pts
[1] = face_2
->end
;
1319 pts
[2] = face_1
->end
;
1320 pts
[3] = face_2
->start
;
1321 join
= CreatePolygonRgn( pts
, 4, ALTERNATE
);
1325 CombineRgn( region
, region
, join
, RGN_OR
);
1326 DeleteObject( join
);
1330 static int wide_line_segment( dibdrv_physdev
*pdev
, HRGN total
,
1331 const POINT
*pt_1
, const POINT
*pt_2
, int dx
, int dy
,
1332 BOOL need_cap_1
, BOOL need_cap_2
, struct face
*face_1
, struct face
*face_2
)
1335 BOOL sq_cap_1
= need_cap_1
&& (pdev
->pen_endcap
== PS_ENDCAP_SQUARE
);
1336 BOOL sq_cap_2
= need_cap_2
&& (pdev
->pen_endcap
== PS_ENDCAP_SQUARE
);
1338 if (dx
== 0 && dy
== 0) return 0;
1342 rect
.left
= min( pt_1
->x
, pt_2
->x
);
1343 rect
.right
= max( pt_1
->x
, pt_2
->x
);
1344 rect
.top
= pt_1
->y
- pdev
->pen_width
/ 2;
1345 rect
.bottom
= rect
.top
+ pdev
->pen_width
;
1346 if ((sq_cap_1
&& dx
> 0) || (sq_cap_2
&& dx
< 0)) rect
.left
-= pdev
->pen_width
/ 2;
1347 if ((sq_cap_2
&& dx
> 0) || (sq_cap_1
&& dx
< 0)) rect
.right
+= pdev
->pen_width
/ 2;
1348 add_rect_to_region( total
, &rect
);
1351 face_1
->start
.x
= face_1
->end
.x
= rect
.left
;
1352 face_1
->start
.y
= face_2
->end
.y
= rect
.bottom
;
1353 face_1
->end
.y
= face_2
->start
.y
= rect
.top
;
1354 face_2
->start
.x
= face_2
->end
.x
= rect
.right
- 1;
1358 face_1
->start
.x
= face_1
->end
.x
= rect
.right
;
1359 face_1
->start
.y
= face_2
->end
.y
= rect
.top
;
1360 face_1
->end
.y
= face_2
->start
.y
= rect
.bottom
;
1361 face_2
->start
.x
= face_2
->end
.x
= rect
.left
+ 1;
1366 rect
.top
= min( pt_1
->y
, pt_2
->y
);
1367 rect
.bottom
= max( pt_1
->y
, pt_2
->y
);
1368 rect
.left
= pt_1
->x
- pdev
->pen_width
/ 2;
1369 rect
.right
= rect
.left
+ pdev
->pen_width
;
1370 if ((sq_cap_1
&& dy
> 0) || (sq_cap_2
&& dy
< 0)) rect
.top
-= pdev
->pen_width
/ 2;
1371 if ((sq_cap_2
&& dy
> 0) || (sq_cap_1
&& dy
< 0)) rect
.bottom
+= pdev
->pen_width
/ 2;
1372 add_rect_to_region( total
, &rect
);
1375 face_1
->start
.x
= face_2
->end
.x
= rect
.left
;
1376 face_1
->start
.y
= face_1
->end
.y
= rect
.top
;
1377 face_1
->end
.x
= face_2
->start
.x
= rect
.right
;
1378 face_2
->start
.y
= face_2
->end
.y
= rect
.bottom
- 1;
1382 face_1
->start
.x
= face_2
->end
.x
= rect
.right
;
1383 face_1
->start
.y
= face_1
->end
.y
= rect
.bottom
;
1384 face_1
->end
.x
= face_2
->start
.x
= rect
.left
;
1385 face_2
->start
.y
= face_2
->end
.y
= rect
.top
+ 1;
1390 double len
= hypot( dx
, dy
);
1391 double width_x
, width_y
;
1393 POINT wide_half
, narrow_half
;
1396 width_x
= pdev
->pen_width
* abs( dy
) / len
;
1397 width_y
= pdev
->pen_width
* abs( dx
) / len
;
1399 narrow_half
.x
= round( width_x
/ 2 );
1400 narrow_half
.y
= round( width_y
/ 2 );
1401 wide_half
.x
= round( (width_x
+ 1) / 2 );
1402 wide_half
.y
= round( (width_y
+ 1) / 2 );
1406 wide_half
.y
= -wide_half
.y
;
1407 narrow_half
.y
= -narrow_half
.y
;
1412 POINT tmp
= narrow_half
; narrow_half
= wide_half
; wide_half
= tmp
;
1413 wide_half
.x
= -wide_half
.x
;
1414 narrow_half
.x
= -narrow_half
.x
;
1417 seg_pts
[0].x
= pt_1
->x
- narrow_half
.x
;
1418 seg_pts
[0].y
= pt_1
->y
+ narrow_half
.y
;
1419 seg_pts
[1].x
= pt_1
->x
+ wide_half
.x
;
1420 seg_pts
[1].y
= pt_1
->y
- wide_half
.y
;
1421 seg_pts
[2].x
= pt_2
->x
+ wide_half
.x
;
1422 seg_pts
[2].y
= pt_2
->y
- wide_half
.y
;
1423 seg_pts
[3].x
= pt_2
->x
- narrow_half
.x
;
1424 seg_pts
[3].y
= pt_2
->y
+ narrow_half
.y
;
1428 seg_pts
[0].x
-= narrow_half
.y
;
1429 seg_pts
[1].x
-= narrow_half
.y
;
1430 seg_pts
[0].y
-= narrow_half
.x
;
1431 seg_pts
[1].y
-= narrow_half
.x
;
1436 seg_pts
[2].x
+= wide_half
.y
;
1437 seg_pts
[3].x
+= wide_half
.y
;
1438 seg_pts
[2].y
+= wide_half
.x
;
1439 seg_pts
[3].y
+= wide_half
.x
;
1442 segment
= CreatePolygonRgn( seg_pts
, 4, ALTERNATE
);
1443 CombineRgn( total
, total
, segment
, RGN_OR
);
1444 DeleteObject( segment
);
1446 face_1
->start
= seg_pts
[0];
1447 face_1
->end
= seg_pts
[1];
1448 face_2
->start
= seg_pts
[2];
1449 face_2
->end
= seg_pts
[3];
1452 face_1
->dx
= face_2
->dx
= dx
;
1453 face_1
->dy
= face_2
->dy
= dy
;
1458 static void wide_line_segments( dibdrv_physdev
*pdev
, int num
, const POINT
*pts
, BOOL close
,
1459 int start
, int count
, const POINT
*first_pt
, const POINT
*last_pt
,
1460 HRGN round_cap
, HRGN total
)
1463 struct face face_1
, face_2
, prev_face
, first_face
;
1464 const POINT
*pt_1
, *pt_2
;
1468 add_cap( pdev
, total
, round_cap
, first_pt
);
1469 add_cap( pdev
, total
, round_cap
, last_pt
);
1475 pt_2
= &pts
[(start
+ 1) % num
];
1476 wide_line_segment( pdev
, total
, first_pt
, last_pt
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1477 TRUE
, TRUE
, &face_1
, &face_2
);
1482 pt_2
= &pts
[(start
+ 1) % num
];
1483 wide_line_segment( pdev
, total
, first_pt
, pt_2
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1484 !close
, FALSE
, &first_face
, &prev_face
);
1487 for (i
= 1; i
< count
- 1; i
++)
1489 pt_1
= &pts
[(start
+ i
) % num
];
1490 pt_2
= &pts
[(start
+ i
+ 1) % num
];
1491 if (wide_line_segment( pdev
, total
, pt_1
, pt_2
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1492 FALSE
, FALSE
, &face_1
, &face_2
))
1494 add_join( pdev
, total
, round_cap
, pt_1
, &prev_face
, &face_1
);
1499 pt_1
= &pts
[(start
+ count
- 1) % num
];
1500 pt_2
= &pts
[(start
+ count
) % num
];
1501 wide_line_segment( pdev
, total
, pt_1
, last_pt
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1502 FALSE
, !close
, &face_1
, &face_2
);
1503 add_join( pdev
, total
, round_cap
, pt_1
, &prev_face
, &face_1
);
1504 if (close
) add_join( pdev
, total
, round_cap
, last_pt
, &face_2
, &first_face
);
1507 static BOOL
wide_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN total
)
1511 assert( total
!= 0 ); /* wide pens should always be drawn through a region */
1514 /* skip empty segments */
1515 while (num
> 2 && pts
[0].x
== pts
[1].x
&& pts
[0].y
== pts
[1].y
) { pts
++; num
--; }
1516 while (num
> 2 && pts
[num
- 1].x
== pts
[num
- 2].x
&& pts
[num
- 1].y
== pts
[num
- 2].y
) num
--;
1518 if (pdev
->pen_join
== PS_JOIN_ROUND
|| pdev
->pen_endcap
== PS_ENDCAP_ROUND
)
1519 round_cap
= CreateEllipticRgn( -(pdev
->pen_width
/ 2), -(pdev
->pen_width
/ 2),
1520 (pdev
->pen_width
+ 1) / 2 + 1, (pdev
->pen_width
+ 1) / 2 + 1 );
1523 wide_line_segments( pdev
, num
, pts
, TRUE
, 0, num
, &pts
[0], &pts
[0], round_cap
, total
);
1525 wide_line_segments( pdev
, num
, pts
, FALSE
, 0, num
- 1, &pts
[0], &pts
[num
- 1], round_cap
, total
);
1527 if (round_cap
) DeleteObject( round_cap
);
1531 static BOOL
dashed_wide_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN total
)
1533 int i
, start
, cur_len
, initial_num
= 0;
1534 POINT initial_point
, start_point
, end_point
;
1537 assert( total
!= 0 ); /* wide pens should always be drawn through a region */
1540 /* skip empty segments */
1541 while (num
> 2 && pts
[0].x
== pts
[1].x
&& pts
[0].y
== pts
[1].y
) { pts
++; num
--; }
1542 while (num
> 2 && pts
[num
- 1].x
== pts
[num
- 2].x
&& pts
[num
- 1].y
== pts
[num
- 2].y
) num
--;
1544 if (pdev
->pen_join
== PS_JOIN_ROUND
|| pdev
->pen_endcap
== PS_ENDCAP_ROUND
)
1545 round_cap
= CreateEllipticRgn( -(pdev
->pen_width
/ 2), -(pdev
->pen_width
/ 2),
1546 (pdev
->pen_width
+ 1) / 2 + 1, (pdev
->pen_width
+ 1) / 2 + 1);
1550 start_point
= pts
[0];
1552 for (i
= 0; i
< (close
? num
: num
- 1); i
++)
1554 const POINT
*pt_1
= pts
+ i
;
1555 const POINT
*pt_2
= pts
+ ((close
&& i
== num
- 1) ? 0 : i
+ 1);
1556 int dx
= pt_2
->x
- pt_1
->x
;
1557 int dy
= pt_2
->y
- pt_1
->y
;
1559 if (dx
== 0 && dy
== 0) continue;
1563 if (abs( dx
) - cur_len
< pdev
->dash_pos
.left_in_dash
)
1565 skip_dash( pdev
, abs( dx
) - cur_len
);
1569 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1570 dx
= (dx
> 0) ? cur_len
: -cur_len
;
1574 if (abs( dy
) - cur_len
< pdev
->dash_pos
.left_in_dash
)
1576 skip_dash( pdev
, abs( dy
) - cur_len
);
1580 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1581 dy
= (dy
> 0) ? cur_len
: -cur_len
;
1585 double len
= hypot( dx
, dy
);
1587 if (len
- cur_len
< pdev
->dash_pos
.left_in_dash
)
1589 skip_dash( pdev
, len
- cur_len
);
1593 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1594 dx
= dx
* cur_len
/ len
;
1595 dy
= dy
* cur_len
/ len
;
1597 end_point
.x
= pt_1
->x
+ dx
;
1598 end_point
.y
= pt_1
->y
+ dy
;
1600 if (pdev
->dash_pos
.mark
)
1602 if (!initial_num
&& close
) /* this is the first dash, save it for later */
1604 initial_num
= i
- start
+ 1;
1605 initial_point
= end_point
;
1607 else wide_line_segments( pdev
, num
, pts
, FALSE
, start
, i
- start
+ 1,
1608 &start_point
, &end_point
, round_cap
, total
);
1610 if (!initial_num
) initial_num
= -1; /* no need to close it */
1612 skip_dash( pdev
, pdev
->dash_pos
.left_in_dash
);
1613 start_point
= end_point
;
1615 i
--; /* go on with the same segment */
1618 if (pdev
->dash_pos
.mark
) /* we have a final dash */
1622 if (initial_num
> 0)
1624 count
= num
- start
+ initial_num
;
1625 end_point
= initial_point
;
1629 count
= num
- start
;
1634 count
= num
- start
- 1;
1635 end_point
= pts
[num
- 1];
1637 wide_line_segments( pdev
, num
, pts
, FALSE
, start
, count
,
1638 &start_point
, &end_point
, round_cap
, total
);
1640 else if (initial_num
> 0) /* initial dash only */
1642 wide_line_segments( pdev
, num
, pts
, FALSE
, 0, initial_num
,
1643 &pts
[0], &initial_point
, round_cap
, total
);
1646 if (round_cap
) DeleteObject( round_cap
);
1650 static const dash_pattern dash_patterns_cosmetic
[4] =
1652 {2, {18, 6}, 24}, /* PS_DASH */
1653 {2, {3, 3}, 6}, /* PS_DOT */
1654 {4, {9, 6, 3, 6}, 24}, /* PS_DASHDOT */
1655 {6, {9, 3, 3, 3, 3, 3}, 24} /* PS_DASHDOTDOT */
1658 static const dash_pattern dash_patterns_geometric
[4] =
1660 {2, {3, 1}, 4}, /* PS_DASH */
1661 {2, {1, 1}, 2}, /* PS_DOT */
1662 {4, {3, 1, 1, 1}, 6}, /* PS_DASHDOT */
1663 {6, {3, 1, 1, 1, 1, 1}, 8} /* PS_DASHDOTDOT */
1666 static inline void set_dash_pattern( dash_pattern
*pattern
, DWORD count
, DWORD
*dashes
)
1670 pattern
->count
= count
;
1671 pattern
->total_len
= 0;
1672 memcpy( pattern
->dashes
, dashes
, count
* sizeof(DWORD
) );
1673 for (i
= 0; i
< count
; i
++) pattern
->total_len
+= dashes
[i
];
1674 if (pattern
->count
% 2) pattern
->total_len
*= 2;
1677 static inline void scale_dash_pattern( dash_pattern
*pattern
, DWORD scale
, DWORD endcap
)
1681 for (i
= 0; i
< pattern
->count
; i
++) pattern
->dashes
[i
] *= scale
;
1682 pattern
->total_len
*= scale
;
1684 if (endcap
!= PS_ENDCAP_FLAT
) /* shrink the dashes to leave room for the caps */
1686 for (i
= 0; i
< pattern
->count
; i
+= 2)
1688 pattern
->dashes
[i
] -= scale
;
1689 pattern
->dashes
[i
+ 1] += scale
;
1694 static inline int get_pen_device_width( dibdrv_physdev
*pdev
, int width
)
1698 if (!width
) return 1;
1699 pts
[0].x
= pts
[0].y
= pts
[1].y
= 0;
1701 LPtoDP( pdev
->dev
.hdc
, pts
, 2 );
1702 width
= abs( pts
[1].x
- pts
[0].x
);
1703 return max( width
, 1 );
1706 /***********************************************************************
1707 * dibdrv_SetDCPenColor
1709 COLORREF
dibdrv_SetDCPenColor( PHYSDEV dev
, COLORREF color
)
1711 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
1713 if (GetCurrentObject(dev
->hdc
, OBJ_PEN
) == GetStockObject( DC_PEN
))
1714 pdev
->pen_brush
.colorref
= color
;
1719 /**********************************************************************
1722 * Fill a number of rectangles with the solid brush
1724 static BOOL
solid_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1725 int num
, const RECT
*rects
, INT rop
)
1727 rop_mask brush_color
;
1728 DWORD color
= get_pixel_color( pdev
, brush
->colorref
, TRUE
);
1730 calc_rop_masks( rop
, color
, &brush_color
);
1731 dib
->funcs
->solid_rects( dib
, num
, rects
, brush_color
.and, brush_color
.xor );
1735 static void free_pattern_brush_bits( dib_brush
*brush
)
1737 HeapFree(GetProcessHeap(), 0, brush
->and_bits
);
1738 HeapFree(GetProcessHeap(), 0, brush
->xor_bits
);
1739 brush
->and_bits
= NULL
;
1740 brush
->xor_bits
= NULL
;
1743 void free_pattern_brush( dib_brush
*brush
)
1745 free_pattern_brush_bits( brush
);
1746 free_dib_info( &brush
->dib
);
1749 static BOOL
create_pattern_brush_bits( dib_brush
*brush
)
1751 DWORD size
= brush
->dib
.height
* abs(brush
->dib
.stride
);
1752 DWORD
*brush_bits
= brush
->dib
.bits
.ptr
;
1753 DWORD
*and_bits
, *xor_bits
;
1755 assert(brush
->and_bits
== NULL
);
1756 assert(brush
->xor_bits
== NULL
);
1758 assert(brush
->dib
.stride
> 0);
1760 and_bits
= brush
->and_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1761 xor_bits
= brush
->xor_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1763 if(!and_bits
|| !xor_bits
)
1765 ERR("Failed to create pattern brush bits\n");
1766 free_pattern_brush_bits( brush
);
1772 calc_and_xor_masks(brush
->rop
, *brush_bits
++, and_bits
++, xor_bits
++);
1779 static const DWORD hatches
[6][8] =
1781 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
1782 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
1783 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HS_FDIAGONAL */
1784 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HS_BDIAGONAL */
1785 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HS_CROSS */
1786 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 } /* HS_DIAGCROSS */
1789 static BOOL
create_hatch_brush_bits(dibdrv_physdev
*pdev
, dib_brush
*brush
, BOOL
*needs_reselect
)
1792 rop_mask fg_mask
, bg_mask
;
1793 rop_mask_bits mask_bits
;
1797 assert(brush
->and_bits
== NULL
);
1798 assert(brush
->xor_bits
== NULL
);
1800 /* Just initialise brush dib with the color / sizing info. We don't
1801 need the bits as we'll calculate the rop masks straight from
1802 the hatch patterns. */
1804 copy_dib_color_info(&brush
->dib
, &pdev
->dib
);
1805 brush
->dib
.width
= 8;
1806 brush
->dib
.height
= 8;
1807 brush
->dib
.stride
= get_dib_stride( brush
->dib
.width
, brush
->dib
.bit_count
);
1809 size
= brush
->dib
.height
* brush
->dib
.stride
;
1811 mask_bits
.and = brush
->and_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1812 mask_bits
.xor = brush
->xor_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1814 if(!mask_bits
.and || !mask_bits
.xor)
1816 ERR("Failed to create pattern brush bits\n");
1817 free_pattern_brush_bits( brush
);
1821 hatch
.bit_count
= 1;
1822 hatch
.height
= hatch
.width
= 8;
1824 hatch
.bits
.ptr
= (void *) hatches
[brush
->hatch
];
1825 hatch
.bits
.free
= hatch
.bits
.param
= NULL
;
1826 hatch
.bits
.is_copy
= FALSE
;
1828 get_color_masks( pdev
, brush
->rop
, brush
->colorref
, GetBkMode(pdev
->dev
.hdc
),
1829 &fg_mask
, &bg_mask
);
1831 if (brush
->colorref
& (1 << 24)) /* PALETTEINDEX */
1832 *needs_reselect
= TRUE
;
1833 if (GetBkMode(pdev
->dev
.hdc
) != TRANSPARENT
&& (GetBkColor(pdev
->dev
.hdc
) & (1 << 24)))
1834 *needs_reselect
= TRUE
;
1836 ret
= brush
->dib
.funcs
->create_rop_masks( &brush
->dib
, &hatch
, &fg_mask
, &bg_mask
, &mask_bits
);
1837 if(!ret
) free_pattern_brush_bits( brush
);
1842 static BOOL
matching_pattern_format( dib_info
*dib
, dib_info
*pattern
)
1844 if (dib
->bit_count
!= pattern
->bit_count
) return FALSE
;
1845 if (dib
->stride
!= pattern
->stride
) return FALSE
;
1847 switch (dib
->bit_count
)
1852 if (dib
->color_table_size
!= pattern
->color_table_size
) return FALSE
;
1853 return !memcmp( dib
->color_table
, pattern
->color_table
, dib
->color_table_size
* sizeof(RGBQUAD
) );
1856 return (dib
->red_mask
== pattern
->red_mask
&&
1857 dib
->green_mask
== pattern
->green_mask
&&
1858 dib
->blue_mask
== pattern
->blue_mask
);
1863 static BOOL
select_pattern_brush( dibdrv_physdev
*pdev
, dib_brush
*brush
, BOOL
*needs_reselect
)
1865 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1866 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
1867 RGBQUAD color_table
[2];
1871 if (!brush
->pattern
.info
)
1873 BITMAPOBJ
*bmp
= GDI_GetObjPtr( brush
->pattern
.bitmap
, OBJ_BITMAP
);
1876 if (!bmp
) return FALSE
;
1877 ret
= init_dib_info_from_bitmapobj( &pattern
, bmp
, 0 );
1878 GDI_ReleaseObj( brush
->pattern
.bitmap
);
1879 if (!ret
) return FALSE
;
1881 else if (brush
->pattern
.info
->bmiHeader
.biClrUsed
&& brush
->pattern
.usage
== DIB_PAL_COLORS
)
1883 copy_bitmapinfo( info
, brush
->pattern
.info
);
1884 fill_color_table_from_pal_colors( info
, pdev
->dev
.hdc
);
1885 init_dib_info_from_bitmapinfo( &pattern
, info
, brush
->pattern
.bits
.ptr
, 0 );
1886 *needs_reselect
= TRUE
;
1890 init_dib_info_from_bitmapinfo( &pattern
, brush
->pattern
.info
, brush
->pattern
.bits
.ptr
, 0 );
1893 if (pattern
.bit_count
== 1 && !pattern
.color_table
)
1895 /* monochrome DDB pattern uses DC colors */
1900 color
= make_rgb_colorref( pdev
->dev
.hdc
, &pdev
->dib
, GetTextColor( pdev
->dev
.hdc
),
1901 &got_pixel
, &pixel
);
1902 color_table
[0].rgbRed
= GetRValue( color
);
1903 color_table
[0].rgbGreen
= GetGValue( color
);
1904 color_table
[0].rgbBlue
= GetBValue( color
);
1905 color_table
[0].rgbReserved
= 0;
1907 color
= make_rgb_colorref( pdev
->dev
.hdc
, &pdev
->dib
, GetBkColor( pdev
->dev
.hdc
),
1908 &got_pixel
, &pixel
);
1909 color_table
[1].rgbRed
= GetRValue( color
);
1910 color_table
[1].rgbGreen
= GetGValue( color
);
1911 color_table
[1].rgbBlue
= GetBValue( color
);
1912 color_table
[1].rgbReserved
= 0;
1914 pattern
.color_table
= color_table
;
1915 pattern
.color_table_size
= 2;
1916 *needs_reselect
= TRUE
;
1919 copy_dib_color_info(&brush
->dib
, &pdev
->dib
);
1921 brush
->dib
.height
= pattern
.height
;
1922 brush
->dib
.width
= pattern
.width
;
1923 brush
->dib
.stride
= get_dib_stride( brush
->dib
.width
, brush
->dib
.bit_count
);
1925 if (matching_pattern_format( &brush
->dib
, &pattern
))
1927 brush
->dib
.bits
.ptr
= pattern
.bits
.ptr
;
1928 brush
->dib
.bits
.is_copy
= FALSE
;
1929 brush
->dib
.bits
.free
= NULL
;
1933 brush
->dib
.bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, brush
->dib
.height
* brush
->dib
.stride
);
1934 brush
->dib
.bits
.is_copy
= TRUE
;
1935 brush
->dib
.bits
.free
= free_heap_bits
;
1937 rect
.left
= rect
.top
= 0;
1938 rect
.right
= pattern
.width
;
1939 rect
.bottom
= pattern
.height
;
1941 brush
->dib
.funcs
->convert_to(&brush
->dib
, &pattern
, &rect
);
1946 /**********************************************************************
1949 * Fill a number of rectangles with the pattern brush
1950 * FIXME: Should we insist l < r && t < b? Currently we assume this.
1952 static BOOL
pattern_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1953 int num
, const RECT
*rects
, INT rop
)
1956 BOOL needs_reselect
= FALSE
;
1958 if (rop
!= brush
->rop
)
1960 free_pattern_brush_bits( brush
);
1964 if(brush
->and_bits
== NULL
)
1966 switch(brush
->style
)
1969 if (!brush
->dib
.bits
.ptr
&& !select_pattern_brush( pdev
, brush
, &needs_reselect
))
1971 if(!create_pattern_brush_bits( brush
))
1976 if(!create_hatch_brush_bits(pdev
, brush
, &needs_reselect
))
1981 ERR("Unexpected brush style %d\n", brush
->style
);
1986 GetBrushOrgEx(pdev
->dev
.hdc
, &origin
);
1988 dib
->funcs
->pattern_rects( dib
, num
, rects
, &origin
, &brush
->dib
, brush
->and_bits
, brush
->xor_bits
);
1990 if (needs_reselect
) free_pattern_brush( brush
);
1994 static BOOL
null_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1995 int num
, const RECT
*rects
, INT rop
)
2000 static void select_brush( dib_brush
*brush
, const LOGBRUSH
*logbrush
, const struct brush_pattern
*pattern
)
2002 free_pattern_brush( brush
);
2006 brush
->style
= BS_DIBPATTERN
;
2007 brush
->pattern
= *pattern
; /* brush is actually selected only when it's used */
2008 brush
->rects
= pattern_brush
;
2012 brush
->style
= logbrush
->lbStyle
;
2013 brush
->colorref
= logbrush
->lbColor
;
2014 brush
->hatch
= logbrush
->lbHatch
;
2016 switch (logbrush
->lbStyle
)
2018 case BS_SOLID
: brush
->rects
= solid_brush
; break;
2019 case BS_NULL
: brush
->rects
= null_brush
; break;
2020 case BS_HATCHED
: brush
->rects
= pattern_brush
; break;
2025 /***********************************************************************
2026 * dibdrv_SelectBrush
2028 HBRUSH
dibdrv_SelectBrush( PHYSDEV dev
, HBRUSH hbrush
, const struct brush_pattern
*pattern
)
2030 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2033 TRACE("(%p, %p)\n", dev
, hbrush
);
2035 GetObjectW( hbrush
, sizeof(logbrush
), &logbrush
);
2037 if (hbrush
== GetStockObject( DC_BRUSH
))
2038 logbrush
.lbColor
= GetDCBrushColor( dev
->hdc
);
2040 select_brush( &pdev
->brush
, &logbrush
, pattern
);
2044 /***********************************************************************
2047 HPEN
dibdrv_SelectPen( PHYSDEV dev
, HPEN hpen
, const struct brush_pattern
*pattern
)
2049 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2052 EXTLOGPEN
*elp
= NULL
;
2054 TRACE("(%p, %p)\n", dev
, hpen
);
2056 if (!GetObjectW( hpen
, sizeof(logpen
), &logpen
))
2058 /* must be an extended pen */
2059 INT size
= GetObjectW( hpen
, 0, NULL
);
2061 if (!size
) return 0;
2063 elp
= HeapAlloc( GetProcessHeap(), 0, size
);
2065 GetObjectW( hpen
, size
, elp
);
2066 logpen
.lopnStyle
= elp
->elpPenStyle
;
2067 logpen
.lopnWidth
.x
= elp
->elpWidth
;
2068 /* cosmetic ext pens are always 1-pixel wide */
2069 if (!(logpen
.lopnStyle
& PS_GEOMETRIC
)) logpen
.lopnWidth
.x
= 0;
2071 logbrush
.lbStyle
= elp
->elpBrushStyle
;
2072 logbrush
.lbColor
= elp
->elpColor
;
2073 logbrush
.lbHatch
= elp
->elpHatch
;
2077 logbrush
.lbStyle
= BS_SOLID
;
2078 logbrush
.lbColor
= logpen
.lopnColor
;
2079 logbrush
.lbHatch
= 0;
2082 pdev
->pen_join
= logpen
.lopnStyle
& PS_JOIN_MASK
;
2083 pdev
->pen_endcap
= logpen
.lopnStyle
& PS_ENDCAP_MASK
;
2084 pdev
->pen_width
= get_pen_device_width( pdev
, logpen
.lopnWidth
.x
);
2086 if (hpen
== GetStockObject( DC_PEN
))
2087 logbrush
.lbColor
= GetDCPenColor( dev
->hdc
);
2089 set_dash_pattern( &pdev
->pen_pattern
, 0, NULL
);
2090 select_brush( &pdev
->pen_brush
, &logbrush
, pattern
);
2092 pdev
->pen_style
= logpen
.lopnStyle
& PS_STYLE_MASK
;
2094 switch (pdev
->pen_style
)
2100 if (logpen
.lopnStyle
& PS_GEOMETRIC
)
2102 pdev
->pen_pattern
= dash_patterns_geometric
[pdev
->pen_style
- 1];
2103 if (pdev
->pen_width
> 1)
2105 scale_dash_pattern( &pdev
->pen_pattern
, pdev
->pen_width
, pdev
->pen_endcap
);
2106 pdev
->pen_lines
= dashed_wide_pen_lines
;
2108 else pdev
->pen_lines
= dashed_pen_lines
;
2111 if (pdev
->pen_width
== 1) /* wide cosmetic pens are not dashed */
2113 pdev
->pen_lines
= dashed_pen_lines
;
2114 pdev
->pen_pattern
= dash_patterns_cosmetic
[pdev
->pen_style
- 1];
2119 case PS_INSIDEFRAME
:
2120 pdev
->pen_lines
= (pdev
->pen_width
== 1) ? solid_pen_lines
: wide_pen_lines
;
2124 pdev
->pen_width
= 0;
2125 pdev
->pen_lines
= null_pen_lines
;
2129 pdev
->pen_lines
= dashed_pen_lines
;
2130 pdev
->pen_pattern
= dash_patterns_geometric
[PS_DOT
- 1];
2134 pdev
->pen_lines
= (pdev
->pen_width
== 1) ? dashed_pen_lines
: dashed_wide_pen_lines
;
2135 set_dash_pattern( &pdev
->pen_pattern
, elp
->elpNumEntries
, elp
->elpStyleEntry
);
2136 if (!(logpen
.lopnStyle
& PS_GEOMETRIC
)) scale_dash_pattern( &pdev
->pen_pattern
, 3, PS_ENDCAP_FLAT
);
2140 pdev
->pen_uses_region
= (logpen
.lopnStyle
& PS_GEOMETRIC
|| pdev
->pen_width
> 1);
2141 pdev
->pen_is_ext
= (elp
!= NULL
);
2142 HeapFree( GetProcessHeap(), 0, elp
);
2146 /***********************************************************************
2147 * dibdrv_SetDCBrushColor
2149 COLORREF
dibdrv_SetDCBrushColor( PHYSDEV dev
, COLORREF color
)
2151 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2153 if (GetCurrentObject(dev
->hdc
, OBJ_BRUSH
) == GetStockObject( DC_BRUSH
))
2154 pdev
->brush
.colorref
= color
;
2159 BOOL
brush_rect(dibdrv_physdev
*pdev
, dib_brush
*brush
, const RECT
*rect
, HRGN clip
, INT rop
)
2161 struct clipped_rects clipped_rects
;
2164 if (!get_clipped_rects( &pdev
->dib
, rect
, clip
, &clipped_rects
)) return TRUE
;
2165 ret
= brush
->rects( pdev
, brush
, &pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, rop
);
2166 free_clipped_rects( &clipped_rects
);