gfx/cairo/win32-ExtCreatePen-zero-size.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 From: Robert O'Callahan <robert@ocallahan.org>
michael@0 2 Bug 768348. Avoid ExtCreatePen failures by avoiding rounding widths and dash lengths down to zero. r=jrmuizel
michael@0 3
michael@0 4 diff --git a/gfx/cairo/cairo/src/cairo-win32-printing-surface.c b/gfx/cairo/cairo/src/cairo-win32-printing-surface.c
michael@0 5 --- a/gfx/cairo/cairo/src/cairo-win32-printing-surface.c
michael@0 6 +++ b/gfx/cairo/cairo/src/cairo-win32-printing-surface.c
michael@0 7 @@ -1251,22 +1251,24 @@ static cairo_int_status_t
michael@0 8 {
michael@0 9 cairo_win32_surface_t *surface = abstract_surface;
michael@0 10 cairo_int_status_t status;
michael@0 11 HPEN pen;
michael@0 12 LOGBRUSH brush;
michael@0 13 COLORREF color;
michael@0 14 XFORM xform;
michael@0 15 DWORD pen_style;
michael@0 16 + DWORD pen_width;
michael@0 17 DWORD *dash_array;
michael@0 18 HGDIOBJ obj;
michael@0 19 unsigned int i;
michael@0 20 cairo_solid_pattern_t clear;
michael@0 21 cairo_matrix_t mat;
michael@0 22 double scale;
michael@0 23 + double scaled_width;
michael@0 24
michael@0 25 status = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
michael@0 26 if (status)
michael@0 27 return status;
michael@0 28
michael@0 29 if (op == CAIRO_OPERATOR_CLEAR) {
michael@0 30 _cairo_win32_printing_surface_init_clear_color (surface, &clear);
michael@0 31 source = (cairo_pattern_t*) &clear;
michael@0 32 @@ -1288,17 +1290,21 @@ static cairo_int_status_t
michael@0 33 _cairo_matrix_factor_out_scale (&mat, &scale);
michael@0 34
michael@0 35 pen_style = PS_GEOMETRIC;
michael@0 36 dash_array = NULL;
michael@0 37 if (style->num_dashes) {
michael@0 38 pen_style |= PS_USERSTYLE;
michael@0 39 dash_array = calloc (sizeof (DWORD), style->num_dashes);
michael@0 40 for (i = 0; i < style->num_dashes; i++) {
michael@0 41 - dash_array[i] = (DWORD) (scale * style->dash[i]);
michael@0 42 + DWORD dashes = (DWORD) (scale * style->dash[i]);
michael@0 43 + /* zero dash-lengths cause ExtCreatePen to fail. Make the dashes
michael@0 44 + * longer if necessary.
michael@0 45 + */
michael@0 46 + dash_array[i] = MAX(1, dashes);
michael@0 47 }
michael@0 48 } else {
michael@0 49 pen_style |= PS_SOLID;
michael@0 50 }
michael@0 51
michael@0 52 SetMiterLimit (surface->dc, (FLOAT) (style->miter_limit), NULL);
michael@0 53 if (source->type == CAIRO_PATTERN_TYPE_SOLID) {
michael@0 54 cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) source;
michael@0 55 @@ -1310,18 +1316,29 @@ static cairo_int_status_t
michael@0 56 /* Color not used as the pen will only be used by WidenPath() */
michael@0 57 color = RGB (0,0,0);
michael@0 58 }
michael@0 59 brush.lbStyle = BS_SOLID;
michael@0 60 brush.lbColor = color;
michael@0 61 brush.lbHatch = 0;
michael@0 62 pen_style |= _cairo_win32_line_cap (style->line_cap);
michael@0 63 pen_style |= _cairo_win32_line_join (style->line_join);
michael@0 64 + scaled_width = scale * style->line_width;
michael@0 65 + if (scaled_width == 0.0)
michael@0 66 + return status;
michael@0 67 + pen_width = (DWORD)scaled_width;
michael@0 68 + if (pen_width == 0) {
michael@0 69 + /* ExtCreatePen will fail if passed zero width. We have to choose
michael@0 70 + * between drawing something too wide, or drawing nothing at all.
michael@0 71 + * Let's draw something.
michael@0 72 + */
michael@0 73 + pen_width = 1;
michael@0 74 + }
michael@0 75 pen = ExtCreatePen(pen_style,
michael@0 76 - scale * style->line_width,
michael@0 77 + pen_width,
michael@0 78 &brush,
michael@0 79 style->num_dashes,
michael@0 80 dash_array);
michael@0 81 if (pen == NULL)
michael@0 82 return _cairo_win32_print_gdi_error ("_win32_surface_stroke:ExtCreatePen");
michael@0 83 obj = SelectObject (surface->dc, pen);
michael@0 84 if (obj == NULL)
michael@0 85 return _cairo_win32_print_gdi_error ("_win32_surface_stroke:SelectObject");

mercurial