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 BOOL clipped
= FALSE
;
377 DWORD start_oc
, end_oc
;
378 const int bias
= params
->bias
;
379 const unsigned int dx
= params
->dx
;
380 const unsigned int dy
= params
->dy
;
381 const unsigned int two_dx
= params
->dx
* 2;
382 const unsigned int two_dy
= params
->dy
* 2;
383 const BOOL xmajor
= is_xmajor(params
->octant
);
384 const BOOL neg_slope
= !is_pos_slope(params
->octant
);
389 start_oc
= calc_outcode(start
, clip
);
390 end_oc
= calc_outcode(end
, clip
);
394 if(start_oc
== 0 && end_oc
== 0) return clipped
? 1 : 2; /* trivial accept */
395 if(start_oc
& end_oc
) return 0; /* trivial reject */
398 if(start_oc
& OUT_LEFT
)
400 m
= clip
->left
- start
->x
;
402 n
= (m
* two_dy
+ bias
+ dx
- 1) / two_dx
;
404 n
= (m
* two_dy
- bias
- dy
) / two_dx
+ 1;
407 if(neg_slope
) n
= -n
;
408 pt1
->y
= start
->y
+ n
;
409 start_oc
= calc_outcode(pt1
, clip
);
411 else if(start_oc
& OUT_RIGHT
)
413 m
= start
->x
- clip
->right
+ 1;
415 n
= (m
* two_dy
+ bias
+ dx
- 1) / two_dx
;
417 n
= (m
* two_dy
- bias
- dy
) / two_dx
+ 1;
419 pt1
->x
= clip
->right
- 1;
420 if(neg_slope
) n
= -n
;
421 pt1
->y
= start
->y
- n
;
422 start_oc
= calc_outcode(pt1
, clip
);
424 else if(start_oc
& OUT_TOP
)
426 n
= clip
->top
- start
->y
;
428 m
= (n
* two_dx
- bias
- dx
) / two_dy
+ 1;
430 m
= (n
* two_dx
+ bias
+ dy
- 1) / two_dy
;
433 if(neg_slope
) m
= -m
;
434 pt1
->x
= start
->x
+ m
;
435 start_oc
= calc_outcode(pt1
, clip
);
437 else if(start_oc
& OUT_BOTTOM
)
439 n
= start
->y
- clip
->bottom
+ 1;
441 m
= (n
* two_dx
- bias
- dx
) / two_dy
+ 1;
443 m
= (n
* two_dx
+ bias
+ dy
- 1) / two_dy
;
445 pt1
->y
= clip
->bottom
- 1;
446 if(neg_slope
) m
= -m
;
447 pt1
->x
= start
->x
- m
;
448 start_oc
= calc_outcode(pt1
, clip
);
450 else if(end_oc
& OUT_LEFT
)
452 m
= clip
->left
- end
->x
;
454 n
= (m
* two_dy
- bias
+ dx
) / two_dx
;
456 n
= (m
* two_dy
+ bias
- dy
- 1) / two_dx
+ 1;
459 if(neg_slope
) n
= -n
;
461 end_oc
= calc_outcode(pt2
, clip
);
463 else if(end_oc
& OUT_RIGHT
)
465 m
= end
->x
- clip
->right
+ 1;
467 n
= (m
* two_dy
- bias
+ dx
) / two_dx
;
469 n
= (m
* two_dy
+ bias
- dy
- 1) / two_dx
+ 1;
471 pt2
->x
= clip
->right
- 1;
472 if(neg_slope
) n
= -n
;
474 end_oc
= calc_outcode(pt2
, clip
);
476 else if(end_oc
& OUT_TOP
)
478 n
= clip
->top
- end
->y
;
480 m
= (n
* two_dx
+ bias
- dx
- 1) / two_dy
+ 1;
482 m
= (n
* two_dx
- bias
+ dy
) / two_dy
;
485 if(neg_slope
) m
= -m
;
487 end_oc
= calc_outcode(pt2
, clip
);
489 else if(end_oc
& OUT_BOTTOM
)
491 n
= end
->y
- clip
->bottom
+ 1;
493 m
= (n
* two_dx
+ bias
- dx
- 1) / two_dy
+ 1;
495 m
= (n
* two_dx
- bias
+ dy
) / two_dy
;
497 pt2
->y
= clip
->bottom
- 1;
498 if(neg_slope
) m
= -m
;
500 end_oc
= calc_outcode(pt2
, clip
);
505 static void bres_line_with_bias(const POINT
*start
, const struct line_params
*params
,
506 void (* callback
)(dibdrv_physdev
*,INT
,INT
), dibdrv_physdev
*pdev
)
509 int len
= params
->length
, err
= params
->err_start
;
515 callback(pdev
, pt
.x
, pt
.y
);
516 if (err
+ params
->bias
> 0)
518 pt
.y
+= params
->y_inc
;
519 err
+= params
->err_add_1
;
521 else err
+= params
->err_add_2
;
522 pt
.x
+= params
->x_inc
;
529 callback(pdev
, pt
.x
, pt
.y
);
530 if (err
+ params
->bias
> 0)
532 pt
.x
+= params
->x_inc
;
533 err
+= params
->err_add_1
;
535 else err
+= params
->err_add_2
;
536 pt
.y
+= params
->y_inc
;
541 static BOOL
solid_pen_line(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, DWORD
and, DWORD
xor)
543 struct clipped_rects clipped_rects
;
547 if(start
->y
== end
->y
)
549 rect
.left
= start
->x
;
552 rect
.bottom
= end
->y
+ 1;
553 order_end_points(&rect
.left
, &rect
.right
);
554 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
555 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, and, xor);
557 else if(start
->x
== end
->x
)
559 rect
.left
= start
->x
;
561 rect
.right
= end
->x
+ 1;
562 rect
.bottom
= end
->y
;
563 order_end_points(&rect
.top
, &rect
.bottom
);
564 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
565 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, and, xor);
569 bres_params clip_params
;
570 struct line_params line_params
;
571 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
572 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
574 clip_params
.dx
= abs_dx
;
575 clip_params
.dy
= abs_dy
;
576 clip_params
.octant
= get_octant_mask(dx
, dy
);
577 clip_params
.bias
= get_bias( clip_params
.octant
);
579 line_params
.bias
= clip_params
.bias
;
580 line_params
.x_major
= is_xmajor( clip_params
.octant
);
581 line_params
.x_inc
= is_x_increasing( clip_params
.octant
) ? 1 : -1;
582 line_params
.y_inc
= is_y_increasing( clip_params
.octant
) ? 1 : -1;
584 if (line_params
.x_major
)
586 line_params
.err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
587 line_params
.err_add_2
= 2 * abs_dy
;
591 line_params
.err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
592 line_params
.err_add_2
= 2 * abs_dx
;
595 rect
.left
= min( start
->x
, end
->x
);
596 rect
.top
= min( start
->y
, end
->y
);
597 rect
.right
= max( start
->x
, end
->x
) + 1;
598 rect
.bottom
= max( start
->y
, end
->y
) + 1;
599 if (!get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
)) return TRUE
;
600 for (i
= 0; i
< clipped_rects
.count
; i
++)
602 POINT clipped_start
, clipped_end
;
605 clip_status
= clip_line(start
, end
, clipped_rects
.rects
+ i
, &clip_params
, &clipped_start
, &clipped_end
);
608 int m
= abs(clipped_start
.x
- start
->x
);
609 int n
= abs(clipped_start
.y
- start
->y
);
611 if (line_params
.x_major
)
613 line_params
.err_start
= 2 * abs_dy
- abs_dx
+ m
* 2 * abs_dy
- n
* 2 * abs_dx
;
614 line_params
.length
= abs( clipped_end
.x
- clipped_start
.x
) + 1;
618 line_params
.err_start
= 2 * abs_dx
- abs_dy
+ n
* 2 * abs_dx
- m
* 2 * abs_dy
;
619 line_params
.length
= abs( clipped_end
.y
- clipped_start
.y
) + 1;
622 if (clipped_end
.x
== end
->x
&& clipped_end
.y
== end
->y
) line_params
.length
--;
624 pdev
->dib
.funcs
->solid_line( &pdev
->dib
, &clipped_start
, &line_params
, and, xor );
626 if(clip_status
== 2) break; /* completely unclipped, so we can finish */
630 free_clipped_rects( &clipped_rects
);
634 static BOOL
solid_pen_line_region( dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, HRGN region
)
638 rect
.left
= start
->x
;
640 rect
.right
= start
->x
+ 1;
641 rect
.bottom
= start
->y
+ 1;
643 if (start
->y
== end
->y
)
646 order_end_points(&rect
.left
, &rect
.right
);
647 add_rect_to_region( region
, &rect
);
649 else if(start
->x
== end
->x
)
651 rect
.bottom
= end
->y
;
652 order_end_points(&rect
.top
, &rect
.bottom
);
653 add_rect_to_region( region
, &rect
);
657 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
658 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
659 DWORD octant
= get_octant_mask(dx
, dy
);
660 INT bias
= get_bias( octant
);
662 if (is_xmajor( octant
))
664 int y_inc
= is_y_increasing( octant
) ? 1 : -1;
665 int err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
666 int err_add_2
= 2 * abs_dy
;
667 int err
= 2 * abs_dy
- abs_dx
;
669 if (is_x_increasing( octant
))
671 for (rect
.right
= start
->x
+ 1; rect
.right
<= end
->x
; rect
.right
++)
675 add_rect_to_region( region
, &rect
);
676 rect
.left
= rect
.right
;
678 rect
.bottom
+= y_inc
;
681 else err
+= err_add_2
;
686 for (rect
.left
= start
->x
; rect
.left
> end
->x
; rect
.left
--)
690 add_rect_to_region( region
, &rect
);
691 rect
.right
= rect
.left
;
693 rect
.bottom
+= y_inc
;
696 else err
+= err_add_2
;
702 int x_inc
= is_x_increasing( octant
) ? 1 : -1;
703 int err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
704 int err_add_2
= 2 * abs_dx
;
705 int err
= 2 * abs_dx
- abs_dy
;
707 if (is_y_increasing( octant
))
709 for (rect
.bottom
= start
->y
+ 1; rect
.bottom
<= end
->y
; rect
.bottom
++)
713 add_rect_to_region( region
, &rect
);
714 rect
.top
= rect
.bottom
;
719 else err
+= err_add_2
;
724 for (rect
.top
= start
->y
; rect
.top
> end
->y
; rect
.top
--)
728 add_rect_to_region( region
, &rect
);
729 rect
.bottom
= rect
.top
;
734 else err
+= err_add_2
;
739 add_rect_to_region( region
, &rect
);
744 static BOOL
solid_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
752 for (i
= 0; i
< num
- 1; i
++)
753 if (!solid_pen_line_region( pdev
, pts
+ i
, pts
+ i
+ 1, region
))
755 if (close
) return solid_pen_line_region( pdev
, pts
+ num
- 1, pts
, region
);
759 DWORD color
, and, xor;
761 color
= get_pixel_color( pdev
, pdev
->pen_brush
.colorref
, TRUE
);
762 calc_and_xor_masks( GetROP2(pdev
->dev
.hdc
), color
, &and, &xor );
764 for (i
= 0; i
< num
- 1; i
++)
765 if (!solid_pen_line( pdev
, pts
+ i
, pts
+ i
+ 1, and, xor ))
767 if (close
) return solid_pen_line( pdev
, pts
+ num
- 1, pts
, and, xor );
772 void reset_dash_origin(dibdrv_physdev
*pdev
)
774 pdev
->dash_pos
.cur_dash
= 0;
775 pdev
->dash_pos
.left_in_dash
= pdev
->pen_pattern
.dashes
[0];
776 pdev
->dash_pos
.mark
= TRUE
;
779 static inline void skip_dash(dibdrv_physdev
*pdev
, unsigned int skip
)
781 skip
%= pdev
->pen_pattern
.total_len
;
784 if(pdev
->dash_pos
.left_in_dash
> skip
)
786 pdev
->dash_pos
.left_in_dash
-= skip
;
789 skip
-= pdev
->dash_pos
.left_in_dash
;
790 pdev
->dash_pos
.cur_dash
++;
791 if(pdev
->dash_pos
.cur_dash
== pdev
->pen_pattern
.count
) pdev
->dash_pos
.cur_dash
= 0;
792 pdev
->dash_pos
.left_in_dash
= pdev
->pen_pattern
.dashes
[pdev
->dash_pos
.cur_dash
];
793 pdev
->dash_pos
.mark
= !pdev
->dash_pos
.mark
;
798 static void dashed_pen_line_callback(dibdrv_physdev
*pdev
, INT x
, INT y
)
801 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
808 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
812 static BOOL
dashed_pen_line(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
)
814 struct clipped_rects clipped_rects
;
817 const dash_pos start_pos
= pdev
->dash_pos
;
819 if(start
->y
== end
->y
) /* hline */
822 INT left
, right
, cur_x
;
825 rect
.bottom
= start
->y
+ 1;
827 if(start
->x
<= end
->x
)
840 rect
.left
= min( start
->x
, end
->x
);
841 rect
.right
= max( start
->x
, end
->x
) + 1;
842 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
843 for (i
= 0; i
< clipped_rects
.count
; i
++)
845 if(clipped_rects
.rects
[i
].right
> left
&& clipped_rects
.rects
[i
].left
<= right
)
847 int clipped_left
= max(clipped_rects
.rects
[i
].left
, left
);
848 int clipped_right
= min(clipped_rects
.rects
[i
].right
- 1, right
);
850 pdev
->dash_pos
= start_pos
;
854 cur_x
= clipped_left
;
856 skip_dash(pdev
, clipped_left
- left
);
858 while(cur_x
<= clipped_right
)
860 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
861 dash_len
= pdev
->dash_pos
.left_in_dash
;
862 if(cur_x
+ dash_len
> clipped_right
+ 1)
863 dash_len
= clipped_right
- cur_x
+ 1;
865 rect
.right
= cur_x
+ dash_len
;
867 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
869 skip_dash(pdev
, dash_len
);
874 cur_x
= clipped_right
;
876 skip_dash(pdev
, right
- clipped_right
);
878 while(cur_x
>= clipped_left
)
880 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
881 dash_len
= pdev
->dash_pos
.left_in_dash
;
882 if(cur_x
- dash_len
< clipped_left
- 1)
883 dash_len
= cur_x
- clipped_left
+ 1;
884 rect
.left
= cur_x
- dash_len
+ 1;
885 rect
.right
= cur_x
+ 1;
887 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
889 skip_dash(pdev
, dash_len
);
894 pdev
->dash_pos
= start_pos
;
895 skip_dash(pdev
, right
- left
+ 1);
897 else if(start
->x
== end
->x
) /* vline */
900 INT top
, bottom
, cur_y
;
902 rect
.left
= start
->x
;
903 rect
.right
= start
->x
+ 1;
905 if(start
->y
<= end
->y
)
918 rect
.top
= min( start
->y
, end
->y
);
919 rect
.bottom
= max( start
->y
, end
->y
) + 1;
920 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
921 for (i
= 0; i
< clipped_rects
.count
; i
++)
923 if(clipped_rects
.rects
[i
].right
> start
->x
&& clipped_rects
.rects
[i
].left
<= start
->x
)
925 int clipped_top
= max(clipped_rects
.rects
[i
].top
, top
);
926 int clipped_bottom
= min(clipped_rects
.rects
[i
].bottom
- 1, bottom
);
928 pdev
->dash_pos
= start_pos
;
934 skip_dash(pdev
, clipped_top
- top
);
936 while(cur_y
<= clipped_bottom
)
938 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
939 dash_len
= pdev
->dash_pos
.left_in_dash
;
940 if(cur_y
+ dash_len
> clipped_bottom
+ 1)
941 dash_len
= clipped_bottom
- cur_y
+ 1;
943 rect
.bottom
= cur_y
+ dash_len
;
945 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
947 skip_dash(pdev
, dash_len
);
952 cur_y
= clipped_bottom
;
954 skip_dash(pdev
, bottom
- clipped_bottom
);
956 while(cur_y
>= clipped_top
)
958 rop_mask mask
= pdev
->dash_masks
[pdev
->dash_pos
.mark
];
959 dash_len
= pdev
->dash_pos
.left_in_dash
;
960 if(cur_y
- dash_len
< clipped_top
- 1)
961 dash_len
= cur_y
- clipped_top
+ 1;
962 rect
.top
= cur_y
- dash_len
+ 1;
963 rect
.bottom
= cur_y
+ 1;
965 pdev
->dib
.funcs
->solid_rects(&pdev
->dib
, 1, &rect
, mask
.and, mask
.xor);
967 skip_dash(pdev
, dash_len
);
972 pdev
->dash_pos
= start_pos
;
973 skip_dash(pdev
, bottom
- top
+ 1);
977 bres_params clip_params
;
978 struct line_params line_params
;
979 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
980 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
982 clip_params
.dx
= abs_dx
;
983 clip_params
.dy
= abs_dy
;
984 clip_params
.octant
= get_octant_mask(dx
, dy
);
985 clip_params
.bias
= get_bias( clip_params
.octant
);
987 line_params
.bias
= clip_params
.bias
;
988 line_params
.x_major
= is_xmajor( clip_params
.octant
);
989 line_params
.x_inc
= is_x_increasing( clip_params
.octant
) ? 1 : -1;
990 line_params
.y_inc
= is_y_increasing( clip_params
.octant
) ? 1 : -1;
992 if (line_params
.x_major
)
994 line_params
.err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
995 line_params
.err_add_2
= 2 * abs_dy
;
999 line_params
.err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
1000 line_params
.err_add_2
= 2 * abs_dx
;
1003 rect
.left
= min( start
->x
, end
->x
);
1004 rect
.top
= min( start
->y
, end
->y
);
1005 rect
.right
= max( start
->x
, end
->x
) + 1;
1006 rect
.bottom
= max( start
->y
, end
->y
) + 1;
1007 get_clipped_rects( &pdev
->dib
, &rect
, pdev
->clip
, &clipped_rects
);
1008 for (i
= 0; i
< clipped_rects
.count
; i
++)
1010 POINT clipped_start
, clipped_end
;
1012 clip_status
= clip_line(start
, end
, clipped_rects
.rects
+ i
, &clip_params
, &clipped_start
, &clipped_end
);
1016 int m
= abs(clipped_start
.x
- start
->x
);
1017 int n
= abs(clipped_start
.y
- start
->y
);
1019 pdev
->dash_pos
= start_pos
;
1021 if (line_params
.x_major
)
1023 line_params
.err_start
= 2 * abs_dy
- abs_dx
+ m
* 2 * abs_dy
- n
* 2 * abs_dx
;
1024 line_params
.length
= abs( clipped_end
.x
- clipped_start
.x
) + 1;
1029 line_params
.err_start
= 2 * abs_dx
- abs_dy
+ n
* 2 * abs_dx
- m
* 2 * abs_dy
;
1030 line_params
.length
= abs( clipped_end
.y
- clipped_start
.y
) + 1;
1033 if (clipped_end
.x
== end
->x
&& clipped_end
.y
== end
->y
) line_params
.length
--;
1035 bres_line_with_bias( &clipped_start
, &line_params
, dashed_pen_line_callback
, pdev
);
1037 if(clip_status
== 2) break; /* completely unclipped, so we can finish */
1040 pdev
->dash_pos
= start_pos
;
1041 if(line_params
.x_major
)
1042 skip_dash(pdev
, abs_dx
);
1044 skip_dash(pdev
, abs_dy
);
1047 free_clipped_rects( &clipped_rects
);
1051 static BOOL
dashed_pen_line_region(dibdrv_physdev
*pdev
, POINT
*start
, POINT
*end
, HRGN region
)
1056 rect
.left
= start
->x
;
1057 rect
.top
= start
->y
;
1058 rect
.right
= start
->x
+ 1;
1059 rect
.bottom
= start
->y
+ 1;
1061 if (start
->y
== end
->y
) /* hline */
1063 if (start
->x
<= end
->x
)
1065 for (i
= start
->x
; i
< end
->x
; i
+= dash_len
)
1067 dash_len
= min( pdev
->dash_pos
.left_in_dash
, end
->x
- i
);
1068 if (pdev
->dash_pos
.mark
)
1071 rect
.right
= i
+ dash_len
;
1072 add_rect_to_region( region
, &rect
);
1074 skip_dash(pdev
, dash_len
);
1079 for (i
= start
->x
; i
> end
->x
; i
-= dash_len
)
1081 dash_len
= min( pdev
->dash_pos
.left_in_dash
, i
- end
->x
);
1082 if (pdev
->dash_pos
.mark
)
1084 rect
.left
= i
- dash_len
+ 1;
1086 add_rect_to_region( region
, &rect
);
1088 skip_dash(pdev
, dash_len
);
1092 else if (start
->x
== end
->x
) /* vline */
1094 if (start
->y
<= end
->y
)
1096 for (i
= start
->y
; i
< end
->y
; i
+= dash_len
)
1098 dash_len
= min( pdev
->dash_pos
.left_in_dash
, end
->y
- i
);
1099 if (pdev
->dash_pos
.mark
)
1102 rect
.bottom
= i
+ dash_len
;
1103 add_rect_to_region( region
, &rect
);
1105 skip_dash(pdev
, dash_len
);
1110 for (i
= start
->y
; i
> end
->y
; i
-= dash_len
)
1112 dash_len
= min( pdev
->dash_pos
.left_in_dash
, i
- end
->y
);
1113 if (pdev
->dash_pos
.mark
)
1115 rect
.top
= i
- dash_len
+ 1;
1116 rect
.bottom
= i
+ 1;
1117 add_rect_to_region( region
, &rect
);
1119 skip_dash(pdev
, dash_len
);
1125 INT dx
= end
->x
- start
->x
, dy
= end
->y
- start
->y
;
1126 INT abs_dx
= abs(dx
), abs_dy
= abs(dy
);
1127 DWORD octant
= get_octant_mask(dx
, dy
);
1128 INT bias
= get_bias( octant
);
1129 int x_inc
= is_x_increasing( octant
) ? 1 : -1;
1130 int y_inc
= is_y_increasing( octant
) ? 1 : -1;
1132 if (is_xmajor( octant
))
1134 int err_add_1
= 2 * abs_dy
- 2 * abs_dx
;
1135 int err_add_2
= 2 * abs_dy
;
1136 int err
= 2 * abs_dy
- abs_dx
;
1140 if (pdev
->dash_pos
.mark
) add_rect_to_region( region
, &rect
);
1143 rect
.right
+= x_inc
;
1147 rect
.bottom
+= y_inc
;
1150 else err
+= err_add_2
;
1156 int err_add_1
= 2 * abs_dx
- 2 * abs_dy
;
1157 int err_add_2
= 2 * abs_dx
;
1158 int err
= 2 * abs_dx
- abs_dy
;
1162 if (pdev
->dash_pos
.mark
) add_rect_to_region( region
, &rect
);
1165 rect
.bottom
+= y_inc
;
1169 rect
.right
+= x_inc
;
1172 else err
+= err_add_2
;
1179 static BOOL
dashed_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
1187 for (i
= 0; i
< num
- 1; i
++)
1188 if (!dashed_pen_line_region( pdev
, pts
+ i
, pts
+ i
+ 1, region
))
1190 if (close
) return dashed_pen_line_region( pdev
, pts
+ num
- 1, pts
, region
);
1194 get_color_masks( pdev
, GetROP2(pdev
->dev
.hdc
), pdev
->pen_brush
.colorref
,
1195 pdev
->pen_is_ext
? TRANSPARENT
: GetBkMode(pdev
->dev
.hdc
),
1196 &pdev
->dash_masks
[1], &pdev
->dash_masks
[0] );
1198 for (i
= 0; i
< num
- 1; i
++)
1199 if (!dashed_pen_line( pdev
, pts
+ i
, pts
+ i
+ 1 ))
1201 if (close
) return dashed_pen_line( pdev
, pts
+ num
- 1, pts
);
1206 static BOOL
null_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN region
)
1217 static void add_cap( dibdrv_physdev
*pdev
, HRGN region
, HRGN round_cap
, const POINT
*pt
)
1219 switch (pdev
->pen_endcap
)
1221 default: FIXME( "Unknown end cap %x\n", pdev
->pen_endcap
);
1223 case PS_ENDCAP_ROUND
:
1224 OffsetRgn( round_cap
, pt
->x
, pt
->y
);
1225 CombineRgn( region
, region
, round_cap
, RGN_OR
);
1226 OffsetRgn( round_cap
, -pt
->x
, -pt
->y
);
1229 case PS_ENDCAP_SQUARE
: /* already been handled */
1230 case PS_ENDCAP_FLAT
:
1235 #define round( f ) (((f) > 0) ? (f) + 0.5 : (f) - 0.5)
1237 /*******************************************************************************
1238 * create_miter_region
1240 * We need to calculate the intersection of two lines. We know a point
1241 * on each line (a face start and the other face end point) and
1242 * the direction vector of each line eg. (dx_1, dy_1).
1244 * (x, y) = (x_1, y_1) + u * (dx_1, dy_1) = (x_2, y_2) + v * (dx_2, dy_2)
1245 * solving (eg using Cramer's rule) gives:
1246 * u = ((x_2 - x_1) dy_2 - (y_2 - y_1) dx_2) / det
1247 * with det = dx_1 dy_2 - dx_2 dy_1
1248 * substituting back in and simplifying gives
1249 * (x, y) = a (dx_1, dy_1) - b (dx_2, dy_2)
1250 * with a = (x_2 dy_2 - y_2 dx_2) / det
1251 * and b = (x_1 dy_1 - y_1 dx_1) / det
1253 static HRGN
create_miter_region( dibdrv_physdev
*pdev
, const POINT
*pt
,
1254 const struct face
*face_1
, const struct face
*face_2
)
1256 int det
= face_1
->dx
* face_2
->dy
- face_1
->dy
* face_2
->dx
;
1257 POINT pt_1
, pt_2
, pts
[5];
1261 if (det
== 0) return 0;
1265 const struct face
*tmp
= face_1
;
1271 pt_1
= face_1
->start
;
1274 a
= (double)((pt_2
.x
* face_2
->dy
- pt_2
.y
* face_2
->dx
)) / det
;
1275 b
= (double)((pt_1
.x
* face_1
->dy
- pt_1
.y
* face_1
->dx
)) / det
;
1277 x
= a
* face_1
->dx
- b
* face_2
->dx
;
1278 y
= a
* face_1
->dy
- b
* face_2
->dy
;
1280 GetMiterLimit( pdev
->dev
.hdc
, &limit
);
1282 if (((x
- pt
->x
) * (x
- pt
->x
) + (y
- pt
->y
) * (y
- pt
->y
)) * 4 > limit
* limit
* pdev
->pen_width
* pdev
->pen_width
)
1285 pts
[0] = face_2
->start
;
1286 pts
[1] = face_1
->start
;
1287 pts
[2].x
= round( x
);
1288 pts
[2].y
= round( y
);
1289 pts
[3] = face_2
->end
;
1290 pts
[4] = face_1
->end
;
1292 return CreatePolygonRgn( pts
, 5, ALTERNATE
);
1295 static void add_join( dibdrv_physdev
*pdev
, HRGN region
, HRGN round_cap
, const POINT
*pt
,
1296 const struct face
*face_1
, const struct face
*face_2
)
1301 switch (pdev
->pen_join
)
1303 default: FIXME( "Unknown line join %x\n", pdev
->pen_join
);
1306 OffsetRgn( round_cap
, pt
->x
, pt
->y
);
1307 CombineRgn( region
, region
, round_cap
, RGN_OR
);
1308 OffsetRgn( round_cap
, -pt
->x
, -pt
->y
);
1312 join
= create_miter_region( pdev
, pt
, face_1
, face_2
);
1316 pts
[0] = face_1
->start
;
1317 pts
[1] = face_2
->end
;
1318 pts
[2] = face_1
->end
;
1319 pts
[3] = face_2
->start
;
1320 join
= CreatePolygonRgn( pts
, 4, ALTERNATE
);
1324 CombineRgn( region
, region
, join
, RGN_OR
);
1325 DeleteObject( join
);
1329 static void wide_line_segment( dibdrv_physdev
*pdev
, HRGN total
,
1330 const POINT
*pt_1
, const POINT
*pt_2
, int dx
, int dy
,
1331 BOOL need_cap_1
, BOOL need_cap_2
, struct face
*face_1
, struct face
*face_2
)
1334 BOOL sq_cap_1
= need_cap_1
&& (pdev
->pen_endcap
== PS_ENDCAP_SQUARE
);
1335 BOOL sq_cap_2
= need_cap_2
&& (pdev
->pen_endcap
== PS_ENDCAP_SQUARE
);
1337 if (dx
== 0 && dy
== 0) return;
1341 rect
.left
= min( pt_1
->x
, pt_2
->x
);
1342 rect
.right
= max( pt_1
->x
, pt_2
->x
);
1343 rect
.top
= pt_1
->y
- pdev
->pen_width
/ 2;
1344 rect
.bottom
= rect
.top
+ pdev
->pen_width
;
1345 if ((sq_cap_1
&& dx
> 0) || (sq_cap_2
&& dx
< 0)) rect
.left
-= pdev
->pen_width
/ 2;
1346 if ((sq_cap_2
&& dx
> 0) || (sq_cap_1
&& dx
< 0)) rect
.right
+= pdev
->pen_width
/ 2;
1347 add_rect_to_region( total
, &rect
);
1350 face_1
->start
.x
= face_1
->end
.x
= rect
.left
;
1351 face_1
->start
.y
= face_2
->end
.y
= rect
.bottom
;
1352 face_1
->end
.y
= face_2
->start
.y
= rect
.top
;
1353 face_2
->start
.x
= face_2
->end
.x
= rect
.right
- 1;
1357 face_1
->start
.x
= face_1
->end
.x
= rect
.right
;
1358 face_1
->start
.y
= face_2
->end
.y
= rect
.top
;
1359 face_1
->end
.y
= face_2
->start
.y
= rect
.bottom
;
1360 face_2
->start
.x
= face_2
->end
.x
= rect
.left
+ 1;
1365 rect
.top
= min( pt_1
->y
, pt_2
->y
);
1366 rect
.bottom
= max( pt_1
->y
, pt_2
->y
);
1367 rect
.left
= pt_1
->x
- pdev
->pen_width
/ 2;
1368 rect
.right
= rect
.left
+ pdev
->pen_width
;
1369 if ((sq_cap_1
&& dy
> 0) || (sq_cap_2
&& dy
< 0)) rect
.top
-= pdev
->pen_width
/ 2;
1370 if ((sq_cap_2
&& dy
> 0) || (sq_cap_1
&& dy
< 0)) rect
.bottom
+= pdev
->pen_width
/ 2;
1371 add_rect_to_region( total
, &rect
);
1374 face_1
->start
.x
= face_2
->end
.x
= rect
.left
;
1375 face_1
->start
.y
= face_1
->end
.y
= rect
.top
;
1376 face_1
->end
.x
= face_2
->start
.x
= rect
.right
;
1377 face_2
->start
.y
= face_2
->end
.y
= rect
.bottom
- 1;
1381 face_1
->start
.x
= face_2
->end
.x
= rect
.right
;
1382 face_1
->start
.y
= face_1
->end
.y
= rect
.bottom
;
1383 face_1
->end
.x
= face_2
->start
.x
= rect
.left
;
1384 face_2
->start
.y
= face_2
->end
.y
= rect
.top
+ 1;
1389 double len
= hypot( dx
, dy
);
1390 double width_x
, width_y
;
1392 POINT wide_half
, narrow_half
;
1395 width_x
= pdev
->pen_width
* abs( dy
) / len
;
1396 width_y
= pdev
->pen_width
* abs( dx
) / len
;
1398 narrow_half
.x
= round( width_x
/ 2 );
1399 narrow_half
.y
= round( width_y
/ 2 );
1400 wide_half
.x
= round( (width_x
+ 1) / 2 );
1401 wide_half
.y
= round( (width_y
+ 1) / 2 );
1405 wide_half
.y
= -wide_half
.y
;
1406 narrow_half
.y
= -narrow_half
.y
;
1411 POINT tmp
= narrow_half
; narrow_half
= wide_half
; wide_half
= tmp
;
1412 wide_half
.x
= -wide_half
.x
;
1413 narrow_half
.x
= -narrow_half
.x
;
1416 seg_pts
[0].x
= pt_1
->x
- narrow_half
.x
;
1417 seg_pts
[0].y
= pt_1
->y
+ narrow_half
.y
;
1418 seg_pts
[1].x
= pt_1
->x
+ wide_half
.x
;
1419 seg_pts
[1].y
= pt_1
->y
- wide_half
.y
;
1420 seg_pts
[2].x
= pt_2
->x
+ wide_half
.x
;
1421 seg_pts
[2].y
= pt_2
->y
- wide_half
.y
;
1422 seg_pts
[3].x
= pt_2
->x
- narrow_half
.x
;
1423 seg_pts
[3].y
= pt_2
->y
+ narrow_half
.y
;
1427 seg_pts
[0].x
-= narrow_half
.y
;
1428 seg_pts
[1].x
-= narrow_half
.y
;
1429 seg_pts
[0].y
-= narrow_half
.x
;
1430 seg_pts
[1].y
-= narrow_half
.x
;
1435 seg_pts
[2].x
+= wide_half
.y
;
1436 seg_pts
[3].x
+= wide_half
.y
;
1437 seg_pts
[2].y
+= wide_half
.x
;
1438 seg_pts
[3].y
+= wide_half
.x
;
1441 segment
= CreatePolygonRgn( seg_pts
, 4, ALTERNATE
);
1442 CombineRgn( total
, total
, segment
, RGN_OR
);
1443 DeleteObject( segment
);
1445 face_1
->start
= seg_pts
[0];
1446 face_1
->end
= seg_pts
[1];
1447 face_2
->start
= seg_pts
[2];
1448 face_2
->end
= seg_pts
[3];
1451 face_1
->dx
= face_2
->dx
= dx
;
1452 face_1
->dy
= face_2
->dy
= dy
;
1455 static void wide_line_segments( dibdrv_physdev
*pdev
, int num
, const POINT
*pts
, BOOL close
,
1456 int start
, int count
, const POINT
*first_pt
, const POINT
*last_pt
,
1457 HRGN round_cap
, HRGN total
)
1460 struct face face_1
, face_2
, prev_face
, first_face
;
1461 const POINT
*pt_1
, *pt_2
;
1465 add_cap( pdev
, total
, round_cap
, first_pt
);
1466 add_cap( pdev
, total
, round_cap
, last_pt
);
1472 pt_2
= &pts
[(start
+ 1) % num
];
1473 wide_line_segment( pdev
, total
, first_pt
, last_pt
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1474 TRUE
, TRUE
, &face_1
, &face_2
);
1479 pt_2
= &pts
[(start
+ 1) % num
];
1480 wide_line_segment( pdev
, total
, first_pt
, pt_2
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1481 !close
, FALSE
, &first_face
, &prev_face
);
1484 for (i
= 1; i
< count
- 1; i
++)
1486 pt_1
= &pts
[(start
+ i
) % num
];
1487 pt_2
= &pts
[(start
+ i
+ 1) % num
];
1488 wide_line_segment( pdev
, total
, pt_1
, pt_2
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1489 FALSE
, FALSE
, &face_1
, &face_2
);
1490 add_join( pdev
, total
, round_cap
, pt_1
, &prev_face
, &face_1
);
1494 pt_1
= &pts
[(start
+ count
- 1) % num
];
1495 pt_2
= &pts
[(start
+ count
) % num
];
1496 wide_line_segment( pdev
, total
, pt_1
, last_pt
, pt_2
->x
- pt_1
->x
, pt_2
->y
- pt_1
->y
,
1497 FALSE
, !close
, &face_1
, &face_2
);
1498 add_join( pdev
, total
, round_cap
, pt_1
, &prev_face
, &face_1
);
1499 if (close
) add_join( pdev
, total
, round_cap
, last_pt
, &face_2
, &first_face
);
1502 static BOOL
wide_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN total
)
1506 assert( total
!= 0 ); /* wide pens should always be drawn through a region */
1509 /* skip empty segments */
1510 while (num
> 2 && pts
[0].x
== pts
[1].x
&& pts
[0].y
== pts
[1].y
) { pts
++; num
--; }
1511 while (num
> 2 && pts
[num
- 1].x
== pts
[num
- 2].x
&& pts
[num
- 1].y
== pts
[num
- 2].y
) num
--;
1513 if (pdev
->pen_join
== PS_JOIN_ROUND
|| pdev
->pen_endcap
== PS_ENDCAP_ROUND
)
1514 round_cap
= CreateEllipticRgn( -(pdev
->pen_width
/ 2), -(pdev
->pen_width
/ 2),
1515 (pdev
->pen_width
+ 1) / 2, (pdev
->pen_width
+ 1) / 2 );
1518 wide_line_segments( pdev
, num
, pts
, TRUE
, 0, num
, &pts
[0], &pts
[0], round_cap
, total
);
1520 wide_line_segments( pdev
, num
, pts
, FALSE
, 0, num
- 1, &pts
[0], &pts
[num
- 1], round_cap
, total
);
1522 if (round_cap
) DeleteObject( round_cap
);
1526 static BOOL
dashed_wide_pen_lines(dibdrv_physdev
*pdev
, int num
, POINT
*pts
, BOOL close
, HRGN total
)
1528 int i
, start
, cur_len
, initial_num
= 0;
1529 POINT initial_point
, start_point
, end_point
;
1532 assert( total
!= 0 ); /* wide pens should always be drawn through a region */
1535 /* skip empty segments */
1536 while (num
> 2 && pts
[0].x
== pts
[1].x
&& pts
[0].y
== pts
[1].y
) { pts
++; num
--; }
1537 while (num
> 2 && pts
[num
- 1].x
== pts
[num
- 2].x
&& pts
[num
- 1].y
== pts
[num
- 2].y
) num
--;
1539 if (pdev
->pen_join
== PS_JOIN_ROUND
|| pdev
->pen_endcap
== PS_ENDCAP_ROUND
)
1540 round_cap
= CreateEllipticRgn( -(pdev
->pen_width
/ 2), -(pdev
->pen_width
/ 2),
1541 (pdev
->pen_width
+ 1) / 2, (pdev
->pen_width
+ 1) / 2 );
1545 start_point
= pts
[0];
1547 for (i
= 0; i
< (close
? num
: num
- 1); i
++)
1549 const POINT
*pt_1
= pts
+ i
;
1550 const POINT
*pt_2
= pts
+ ((close
&& i
== num
- 1) ? 0 : i
+ 1);
1551 int dx
= pt_2
->x
- pt_1
->x
;
1552 int dy
= pt_2
->y
- pt_1
->y
;
1554 if (dx
== 0 && dy
== 0) continue;
1558 if (abs( dx
) - cur_len
< pdev
->dash_pos
.left_in_dash
)
1560 skip_dash( pdev
, abs( dx
) - cur_len
);
1564 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1565 dx
= (dx
> 0) ? cur_len
: -cur_len
;
1569 if (abs( dy
) - cur_len
< pdev
->dash_pos
.left_in_dash
)
1571 skip_dash( pdev
, abs( dy
) - cur_len
);
1575 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1576 dy
= (dy
> 0) ? cur_len
: -cur_len
;
1580 double len
= hypot( dx
, dy
);
1582 if (len
- cur_len
< pdev
->dash_pos
.left_in_dash
)
1584 skip_dash( pdev
, len
- cur_len
);
1588 cur_len
+= pdev
->dash_pos
.left_in_dash
;
1589 dx
= dx
* cur_len
/ len
;
1590 dy
= dy
* cur_len
/ len
;
1592 end_point
.x
= pt_1
->x
+ dx
;
1593 end_point
.y
= pt_1
->y
+ dy
;
1595 if (pdev
->dash_pos
.mark
)
1597 if (!initial_num
&& close
) /* this is the first dash, save it for later */
1599 initial_num
= i
- start
+ 1;
1600 initial_point
= end_point
;
1602 else wide_line_segments( pdev
, num
, pts
, FALSE
, start
, i
- start
+ 1,
1603 &start_point
, &end_point
, round_cap
, total
);
1605 if (!initial_num
) initial_num
= -1; /* no need to close it */
1607 skip_dash( pdev
, pdev
->dash_pos
.left_in_dash
);
1608 start_point
= end_point
;
1610 i
--; /* go on with the same segment */
1613 if (pdev
->dash_pos
.mark
) /* we have a final dash */
1617 if (initial_num
> 0)
1619 count
= num
- start
+ initial_num
;
1620 end_point
= initial_point
;
1624 count
= num
- start
;
1629 count
= num
- start
- 1;
1630 end_point
= pts
[num
- 1];
1632 wide_line_segments( pdev
, num
, pts
, FALSE
, start
, count
,
1633 &start_point
, &end_point
, round_cap
, total
);
1635 else if (initial_num
> 0) /* initial dash only */
1637 wide_line_segments( pdev
, num
, pts
, FALSE
, 0, initial_num
,
1638 &pts
[0], &initial_point
, round_cap
, total
);
1641 if (round_cap
) DeleteObject( round_cap
);
1645 static const dash_pattern dash_patterns_cosmetic
[4] =
1647 {2, {18, 6}, 24}, /* PS_DASH */
1648 {2, {3, 3}, 6}, /* PS_DOT */
1649 {4, {9, 6, 3, 6}, 24}, /* PS_DASHDOT */
1650 {6, {9, 3, 3, 3, 3, 3}, 24} /* PS_DASHDOTDOT */
1653 static const dash_pattern dash_patterns_geometric
[4] =
1655 {2, {3, 1}, 4}, /* PS_DASH */
1656 {2, {1, 1}, 2}, /* PS_DOT */
1657 {4, {3, 1, 1, 1}, 6}, /* PS_DASHDOT */
1658 {6, {3, 1, 1, 1, 1, 1}, 8} /* PS_DASHDOTDOT */
1661 static inline void set_dash_pattern( dash_pattern
*pattern
, DWORD count
, DWORD
*dashes
)
1665 pattern
->count
= count
;
1666 pattern
->total_len
= 0;
1667 memcpy( pattern
->dashes
, dashes
, count
* sizeof(DWORD
) );
1668 for (i
= 0; i
< count
; i
++) pattern
->total_len
+= dashes
[i
];
1669 if (pattern
->count
% 2) pattern
->total_len
*= 2;
1672 static inline void scale_dash_pattern( dash_pattern
*pattern
, DWORD scale
, DWORD endcap
)
1676 for (i
= 0; i
< pattern
->count
; i
++) pattern
->dashes
[i
] *= scale
;
1677 pattern
->total_len
*= scale
;
1679 if (endcap
!= PS_ENDCAP_FLAT
) /* shrink the dashes to leave room for the caps */
1681 for (i
= 0; i
< pattern
->count
; i
+= 2)
1683 pattern
->dashes
[i
] -= scale
;
1684 pattern
->dashes
[i
+ 1] += scale
;
1689 static inline int get_pen_device_width( dibdrv_physdev
*pdev
, int width
)
1693 if (!width
) return 1;
1694 pts
[0].x
= pts
[0].y
= pts
[1].y
= 0;
1696 LPtoDP( pdev
->dev
.hdc
, pts
, 2 );
1697 width
= abs( pts
[1].x
- pts
[0].x
);
1698 return max( width
, 1 );
1701 /***********************************************************************
1702 * dibdrv_SetDCPenColor
1704 COLORREF
dibdrv_SetDCPenColor( PHYSDEV dev
, COLORREF color
)
1706 PHYSDEV next
= GET_NEXT_PHYSDEV( dev
, pSetDCPenColor
);
1707 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
1709 if (GetCurrentObject(dev
->hdc
, OBJ_PEN
) == GetStockObject( DC_PEN
))
1710 pdev
->pen_brush
.colorref
= color
;
1712 return next
->funcs
->pSetDCPenColor( next
, color
);
1715 /**********************************************************************
1718 * Fill a number of rectangles with the solid brush
1720 static BOOL
solid_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1721 int num
, const RECT
*rects
, INT rop
)
1723 rop_mask brush_color
;
1724 DWORD color
= get_pixel_color( pdev
, brush
->colorref
, TRUE
);
1726 calc_rop_masks( rop
, color
, &brush_color
);
1727 dib
->funcs
->solid_rects( dib
, num
, rects
, brush_color
.and, brush_color
.xor );
1731 static void free_pattern_brush_bits( dib_brush
*brush
)
1733 HeapFree(GetProcessHeap(), 0, brush
->and_bits
);
1734 HeapFree(GetProcessHeap(), 0, brush
->xor_bits
);
1735 brush
->and_bits
= NULL
;
1736 brush
->xor_bits
= NULL
;
1739 void free_pattern_brush( dib_brush
*brush
)
1741 free_pattern_brush_bits( brush
);
1742 free_dib_info( &brush
->dib
);
1745 static BOOL
create_pattern_brush_bits( dib_brush
*brush
)
1747 DWORD size
= brush
->dib
.height
* abs(brush
->dib
.stride
);
1748 DWORD
*brush_bits
= brush
->dib
.bits
.ptr
;
1749 DWORD
*and_bits
, *xor_bits
;
1751 assert(brush
->and_bits
== NULL
);
1752 assert(brush
->xor_bits
== NULL
);
1754 assert(brush
->dib
.stride
> 0);
1756 and_bits
= brush
->and_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1757 xor_bits
= brush
->xor_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1759 if(!and_bits
|| !xor_bits
)
1761 ERR("Failed to create pattern brush bits\n");
1762 free_pattern_brush_bits( brush
);
1768 calc_and_xor_masks(brush
->rop
, *brush_bits
++, and_bits
++, xor_bits
++);
1775 static const DWORD hatches
[6][8] =
1777 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
1778 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
1779 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HS_FDIAGONAL */
1780 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HS_BDIAGONAL */
1781 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HS_CROSS */
1782 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 } /* HS_DIAGCROSS */
1785 static BOOL
create_hatch_brush_bits(dibdrv_physdev
*pdev
, dib_brush
*brush
, BOOL
*needs_reselect
)
1788 rop_mask fg_mask
, bg_mask
;
1789 rop_mask_bits mask_bits
;
1793 assert(brush
->and_bits
== NULL
);
1794 assert(brush
->xor_bits
== NULL
);
1796 /* Just initialise brush dib with the color / sizing info. We don't
1797 need the bits as we'll calculate the rop masks straight from
1798 the hatch patterns. */
1800 copy_dib_color_info(&brush
->dib
, &pdev
->dib
);
1801 brush
->dib
.width
= 8;
1802 brush
->dib
.height
= 8;
1803 brush
->dib
.stride
= get_dib_stride( brush
->dib
.width
, brush
->dib
.bit_count
);
1805 size
= brush
->dib
.height
* brush
->dib
.stride
;
1807 mask_bits
.and = brush
->and_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1808 mask_bits
.xor = brush
->xor_bits
= HeapAlloc(GetProcessHeap(), 0, size
);
1810 if(!mask_bits
.and || !mask_bits
.xor)
1812 ERR("Failed to create pattern brush bits\n");
1813 free_pattern_brush_bits( brush
);
1817 hatch
.bit_count
= 1;
1818 hatch
.height
= hatch
.width
= 8;
1820 hatch
.bits
.ptr
= (void *) hatches
[brush
->hatch
];
1821 hatch
.bits
.free
= hatch
.bits
.param
= NULL
;
1822 hatch
.bits
.is_copy
= FALSE
;
1824 get_color_masks( pdev
, brush
->rop
, brush
->colorref
, GetBkMode(pdev
->dev
.hdc
),
1825 &fg_mask
, &bg_mask
);
1827 if (brush
->colorref
& (1 << 24)) /* PALETTEINDEX */
1828 *needs_reselect
= TRUE
;
1829 if (GetBkMode(pdev
->dev
.hdc
) != TRANSPARENT
&& (GetBkColor(pdev
->dev
.hdc
) & (1 << 24)))
1830 *needs_reselect
= TRUE
;
1832 ret
= brush
->dib
.funcs
->create_rop_masks( &brush
->dib
, &hatch
, &fg_mask
, &bg_mask
, &mask_bits
);
1833 if(!ret
) free_pattern_brush_bits( brush
);
1838 static BOOL
matching_pattern_format( dib_info
*dib
, dib_info
*pattern
)
1840 if (dib
->bit_count
!= pattern
->bit_count
) return FALSE
;
1841 if (dib
->stride
!= pattern
->stride
) return FALSE
;
1843 switch (dib
->bit_count
)
1848 if (dib
->color_table_size
!= pattern
->color_table_size
) return FALSE
;
1849 return !memcmp( dib
->color_table
, pattern
->color_table
, dib
->color_table_size
* sizeof(RGBQUAD
) );
1852 return (dib
->red_mask
== pattern
->red_mask
&&
1853 dib
->green_mask
== pattern
->green_mask
&&
1854 dib
->blue_mask
== pattern
->blue_mask
);
1859 static BOOL
select_pattern_brush( dibdrv_physdev
*pdev
, dib_brush
*brush
, BOOL
*needs_reselect
)
1861 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1862 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
1863 RGBQUAD color_table
[2];
1867 if (!brush
->pattern
.info
)
1869 BITMAPOBJ
*bmp
= GDI_GetObjPtr( brush
->pattern
.bitmap
, OBJ_BITMAP
);
1872 if (!bmp
) return FALSE
;
1873 ret
= init_dib_info_from_bitmapobj( &pattern
, bmp
, 0 );
1874 GDI_ReleaseObj( brush
->pattern
.bitmap
);
1875 if (!ret
) return FALSE
;
1877 else if (brush
->pattern
.info
->bmiHeader
.biClrUsed
&& brush
->pattern
.usage
== DIB_PAL_COLORS
)
1879 copy_bitmapinfo( info
, brush
->pattern
.info
);
1880 fill_color_table_from_pal_colors( info
, pdev
->dev
.hdc
);
1881 init_dib_info_from_bitmapinfo( &pattern
, info
, brush
->pattern
.bits
.ptr
, 0 );
1882 *needs_reselect
= TRUE
;
1886 init_dib_info_from_bitmapinfo( &pattern
, brush
->pattern
.info
, brush
->pattern
.bits
.ptr
, 0 );
1889 if (pattern
.bit_count
== 1 && !pattern
.color_table
)
1891 /* monochrome DDB pattern uses DC colors */
1896 color
= make_rgb_colorref( pdev
->dev
.hdc
, &pdev
->dib
, GetTextColor( pdev
->dev
.hdc
),
1897 &got_pixel
, &pixel
);
1898 color_table
[0].rgbRed
= GetRValue( color
);
1899 color_table
[0].rgbGreen
= GetGValue( color
);
1900 color_table
[0].rgbBlue
= GetBValue( color
);
1901 color_table
[0].rgbReserved
= 0;
1903 color
= make_rgb_colorref( pdev
->dev
.hdc
, &pdev
->dib
, GetBkColor( pdev
->dev
.hdc
),
1904 &got_pixel
, &pixel
);
1905 color_table
[1].rgbRed
= GetRValue( color
);
1906 color_table
[1].rgbGreen
= GetGValue( color
);
1907 color_table
[1].rgbBlue
= GetBValue( color
);
1908 color_table
[1].rgbReserved
= 0;
1910 pattern
.color_table
= color_table
;
1911 pattern
.color_table_size
= 2;
1912 *needs_reselect
= TRUE
;
1915 copy_dib_color_info(&brush
->dib
, &pdev
->dib
);
1917 brush
->dib
.height
= pattern
.height
;
1918 brush
->dib
.width
= pattern
.width
;
1919 brush
->dib
.stride
= get_dib_stride( brush
->dib
.width
, brush
->dib
.bit_count
);
1921 if (matching_pattern_format( &brush
->dib
, &pattern
))
1923 brush
->dib
.bits
.ptr
= pattern
.bits
.ptr
;
1924 brush
->dib
.bits
.is_copy
= FALSE
;
1925 brush
->dib
.bits
.free
= NULL
;
1929 brush
->dib
.bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, brush
->dib
.height
* brush
->dib
.stride
);
1930 brush
->dib
.bits
.is_copy
= TRUE
;
1931 brush
->dib
.bits
.free
= free_heap_bits
;
1933 rect
.left
= rect
.top
= 0;
1934 rect
.right
= pattern
.width
;
1935 rect
.bottom
= pattern
.height
;
1937 brush
->dib
.funcs
->convert_to(&brush
->dib
, &pattern
, &rect
);
1942 /**********************************************************************
1945 * Fill a number of rectangles with the pattern brush
1946 * FIXME: Should we insist l < r && t < b? Currently we assume this.
1948 static BOOL
pattern_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1949 int num
, const RECT
*rects
, INT rop
)
1952 BOOL needs_reselect
= FALSE
;
1954 if (rop
!= brush
->rop
)
1956 free_pattern_brush_bits( brush
);
1960 if(brush
->and_bits
== NULL
)
1962 switch(brush
->style
)
1965 if (!brush
->dib
.bits
.ptr
&& !select_pattern_brush( pdev
, brush
, &needs_reselect
))
1967 if(!create_pattern_brush_bits( brush
))
1972 if(!create_hatch_brush_bits(pdev
, brush
, &needs_reselect
))
1977 ERR("Unexpected brush style %d\n", brush
->style
);
1982 GetBrushOrgEx(pdev
->dev
.hdc
, &origin
);
1984 dib
->funcs
->pattern_rects( dib
, num
, rects
, &origin
, &brush
->dib
, brush
->and_bits
, brush
->xor_bits
);
1986 if (needs_reselect
) free_pattern_brush( brush
);
1990 static BOOL
null_brush(dibdrv_physdev
*pdev
, dib_brush
*brush
, dib_info
*dib
,
1991 int num
, const RECT
*rects
, INT rop
)
1996 static void select_brush( dib_brush
*brush
, const LOGBRUSH
*logbrush
, const struct brush_pattern
*pattern
)
1998 free_pattern_brush( brush
);
2002 brush
->style
= BS_DIBPATTERN
;
2003 brush
->pattern
= *pattern
; /* brush is actually selected only when it's used */
2004 brush
->rects
= pattern_brush
;
2008 brush
->style
= logbrush
->lbStyle
;
2009 brush
->colorref
= logbrush
->lbColor
;
2010 brush
->hatch
= logbrush
->lbHatch
;
2012 switch (logbrush
->lbStyle
)
2014 case BS_SOLID
: brush
->rects
= solid_brush
; break;
2015 case BS_NULL
: brush
->rects
= null_brush
; break;
2016 case BS_HATCHED
: brush
->rects
= pattern_brush
; break;
2021 /***********************************************************************
2022 * dibdrv_SelectBrush
2024 HBRUSH
dibdrv_SelectBrush( PHYSDEV dev
, HBRUSH hbrush
, const struct brush_pattern
*pattern
)
2026 PHYSDEV next
= GET_NEXT_PHYSDEV( dev
, pSelectBrush
);
2027 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2030 TRACE("(%p, %p)\n", dev
, hbrush
);
2032 GetObjectW( hbrush
, sizeof(logbrush
), &logbrush
);
2034 if (hbrush
== GetStockObject( DC_BRUSH
))
2035 logbrush
.lbColor
= GetDCBrushColor( dev
->hdc
);
2037 select_brush( &pdev
->brush
, &logbrush
, pattern
);
2039 return next
->funcs
->pSelectBrush( next
, hbrush
, pattern
);
2042 /***********************************************************************
2045 HPEN
dibdrv_SelectPen( PHYSDEV dev
, HPEN hpen
, const struct brush_pattern
*pattern
)
2047 PHYSDEV next
= GET_NEXT_PHYSDEV( dev
, pSelectPen
);
2048 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2051 EXTLOGPEN
*elp
= NULL
;
2053 TRACE("(%p, %p)\n", dev
, hpen
);
2055 if (!GetObjectW( hpen
, sizeof(logpen
), &logpen
))
2057 /* must be an extended pen */
2058 INT size
= GetObjectW( hpen
, 0, NULL
);
2060 if (!size
) return 0;
2062 elp
= HeapAlloc( GetProcessHeap(), 0, size
);
2064 GetObjectW( hpen
, size
, elp
);
2065 logpen
.lopnStyle
= elp
->elpPenStyle
;
2066 logpen
.lopnWidth
.x
= elp
->elpWidth
;
2067 /* cosmetic ext pens are always 1-pixel wide */
2068 if (!(logpen
.lopnStyle
& PS_GEOMETRIC
)) logpen
.lopnWidth
.x
= 0;
2070 logbrush
.lbStyle
= elp
->elpBrushStyle
;
2071 logbrush
.lbColor
= elp
->elpColor
;
2072 logbrush
.lbHatch
= elp
->elpHatch
;
2076 logbrush
.lbStyle
= BS_SOLID
;
2077 logbrush
.lbColor
= logpen
.lopnColor
;
2078 logbrush
.lbHatch
= 0;
2081 pdev
->pen_join
= logpen
.lopnStyle
& PS_JOIN_MASK
;
2082 pdev
->pen_endcap
= logpen
.lopnStyle
& PS_ENDCAP_MASK
;
2083 pdev
->pen_width
= get_pen_device_width( pdev
, logpen
.lopnWidth
.x
);
2085 if (hpen
== GetStockObject( DC_PEN
))
2086 logbrush
.lbColor
= GetDCPenColor( dev
->hdc
);
2088 set_dash_pattern( &pdev
->pen_pattern
, 0, NULL
);
2089 select_brush( &pdev
->pen_brush
, &logbrush
, pattern
);
2091 pdev
->pen_style
= logpen
.lopnStyle
& PS_STYLE_MASK
;
2093 switch (pdev
->pen_style
)
2099 if (logpen
.lopnStyle
& PS_GEOMETRIC
)
2101 pdev
->pen_pattern
= dash_patterns_geometric
[pdev
->pen_style
- 1];
2102 if (pdev
->pen_width
> 1)
2104 scale_dash_pattern( &pdev
->pen_pattern
, pdev
->pen_width
, pdev
->pen_endcap
);
2105 pdev
->pen_lines
= dashed_wide_pen_lines
;
2107 else pdev
->pen_lines
= dashed_pen_lines
;
2110 if (pdev
->pen_width
== 1) /* wide cosmetic pens are not dashed */
2112 pdev
->pen_lines
= dashed_pen_lines
;
2113 pdev
->pen_pattern
= dash_patterns_cosmetic
[pdev
->pen_style
- 1];
2118 case PS_INSIDEFRAME
:
2119 pdev
->pen_lines
= (pdev
->pen_width
== 1) ? solid_pen_lines
: wide_pen_lines
;
2123 pdev
->pen_width
= 0;
2124 pdev
->pen_lines
= null_pen_lines
;
2128 pdev
->pen_lines
= dashed_pen_lines
;
2129 pdev
->pen_pattern
= dash_patterns_geometric
[PS_DOT
- 1];
2133 pdev
->pen_lines
= (pdev
->pen_width
== 1) ? dashed_pen_lines
: dashed_wide_pen_lines
;
2134 set_dash_pattern( &pdev
->pen_pattern
, elp
->elpNumEntries
, elp
->elpStyleEntry
);
2135 if (!(logpen
.lopnStyle
& PS_GEOMETRIC
)) scale_dash_pattern( &pdev
->pen_pattern
, 3, PS_ENDCAP_FLAT
);
2139 pdev
->pen_uses_region
= (logpen
.lopnStyle
& PS_GEOMETRIC
|| pdev
->pen_width
> 1);
2140 pdev
->pen_is_ext
= (elp
!= NULL
);
2141 HeapFree( GetProcessHeap(), 0, elp
);
2143 return next
->funcs
->pSelectPen( next
, hpen
, pattern
);
2146 /***********************************************************************
2147 * dibdrv_SetDCBrushColor
2149 COLORREF
dibdrv_SetDCBrushColor( PHYSDEV dev
, COLORREF color
)
2151 PHYSDEV next
= GET_NEXT_PHYSDEV( dev
, pSetDCBrushColor
);
2152 dibdrv_physdev
*pdev
= get_dibdrv_pdev(dev
);
2154 if (GetCurrentObject(dev
->hdc
, OBJ_BRUSH
) == GetStockObject( DC_BRUSH
))
2155 pdev
->brush
.colorref
= color
;
2157 return next
->funcs
->pSetDCBrushColor( next
, color
);
2160 BOOL
brush_rect(dibdrv_physdev
*pdev
, dib_brush
*brush
, const RECT
*rect
, HRGN clip
, INT rop
)
2162 struct clipped_rects clipped_rects
;
2165 if (!get_clipped_rects( &pdev
->dib
, rect
, clip
, &clipped_rects
)) return TRUE
;
2166 ret
= brush
->rects( pdev
, brush
, &pdev
->dib
, clipped_rects
.count
, clipped_rects
.rects
, rop
);
2167 free_clipped_rects( &clipped_rects
);
2171 /* paint a region with the brush (note: the region can be modified) */
2172 BOOL
brush_region( dibdrv_physdev
*pdev
, HRGN region
)
2174 if (pdev
->clip
) CombineRgn( region
, region
, pdev
->clip
, RGN_AND
);
2175 return brush_rect( pdev
, &pdev
->brush
, NULL
, region
, GetROP2( pdev
->dev
.hdc
));
2178 /* paint a region with the pen (note: the region can be modified) */
2179 BOOL
pen_region( dibdrv_physdev
*pdev
, HRGN region
)
2181 if (pdev
->clip
) CombineRgn( region
, region
, pdev
->clip
, RGN_AND
);
2182 return brush_rect( pdev
, &pdev
->pen_brush
, NULL
, region
, GetROP2( pdev
->dev
.hdc
));