Merge branch 'clamp-coordinates' into 'master'

Clamp path coordinates

Closes poppler/poppler#1250

See merge request cairo/cairo!325
This commit is contained in:
Adrian Johnson 2022-05-28 23:13:23 +00:00
commit 451dcd3143
30 changed files with 42 additions and 13 deletions

View file

@ -13,6 +13,8 @@ ft-show-glyphs-positioning
ft-text-vertical-layout-type1
ft-text-vertical-layout-type3
halo-transform
huge-linear
huge-radial
linear-gradient-reflect
mask
overlapping-glyphs

View file

@ -23,6 +23,8 @@ ft-text-vertical-layout-type3
gradient-zero-stops
gradient-zero-stops-mask
halo-transform
huge-linear
huge-radial
image-surface-source
linear-gradient-one-stop
linear-gradient-reflect

View file

@ -713,10 +713,12 @@ _cairo_default_context_move_to (void *abstract_cr, double x, double y)
{
cairo_default_context_t *cr = abstract_cr;
cairo_fixed_t x_fixed, y_fixed;
double width;
_cairo_gstate_user_to_backend (cr->gstate, &x, &y);
x_fixed = _cairo_fixed_from_double (x);
y_fixed = _cairo_fixed_from_double (y);
width = _cairo_gstate_get_line_width (cr->gstate);
x_fixed = _cairo_fixed_from_double_clamped (x, width);
y_fixed = _cairo_fixed_from_double_clamped (y, width);
return _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed);
}
@ -726,10 +728,12 @@ _cairo_default_context_line_to (void *abstract_cr, double x, double y)
{
cairo_default_context_t *cr = abstract_cr;
cairo_fixed_t x_fixed, y_fixed;
double width;
_cairo_gstate_user_to_backend (cr->gstate, &x, &y);
x_fixed = _cairo_fixed_from_double (x);
y_fixed = _cairo_fixed_from_double (y);
width = _cairo_gstate_get_line_width (cr->gstate);
x_fixed = _cairo_fixed_from_double_clamped (x, width);
y_fixed = _cairo_fixed_from_double_clamped (y, width);
return _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed);
}
@ -744,19 +748,21 @@ _cairo_default_context_curve_to (void *abstract_cr,
cairo_fixed_t x1_fixed, y1_fixed;
cairo_fixed_t x2_fixed, y2_fixed;
cairo_fixed_t x3_fixed, y3_fixed;
double width;
_cairo_gstate_user_to_backend (cr->gstate, &x1, &y1);
_cairo_gstate_user_to_backend (cr->gstate, &x2, &y2);
_cairo_gstate_user_to_backend (cr->gstate, &x3, &y3);
width = _cairo_gstate_get_line_width (cr->gstate);
x1_fixed = _cairo_fixed_from_double (x1);
y1_fixed = _cairo_fixed_from_double (y1);
x1_fixed = _cairo_fixed_from_double_clamped (x1, width);
y1_fixed = _cairo_fixed_from_double_clamped (y1, width);
x2_fixed = _cairo_fixed_from_double (x2);
y2_fixed = _cairo_fixed_from_double (y2);
x2_fixed = _cairo_fixed_from_double_clamped (x2, width);
y2_fixed = _cairo_fixed_from_double_clamped (y2, width);
x3_fixed = _cairo_fixed_from_double (x3);
y3_fixed = _cairo_fixed_from_double (y3);
x3_fixed = _cairo_fixed_from_double_clamped (x3, width);
y3_fixed = _cairo_fixed_from_double_clamped (y3, width);
return _cairo_path_fixed_curve_to (cr->path,
x1_fixed, y1_fixed,

View file

@ -53,6 +53,11 @@
#define CAIRO_FIXED_ONE_DOUBLE ((double)(1 << CAIRO_FIXED_FRAC_BITS))
#define CAIRO_FIXED_EPSILON ((cairo_fixed_t)(1))
#define CAIRO_FIXED_MAX INT32_MAX /* Maximum fixed point value */
#define CAIRO_FIXED_MIN INT32_MIN /* Minimum fixed point value */
#define CAIRO_FIXED_MAX_DOUBLE (((double) CAIRO_FIXED_MAX) / CAIRO_FIXED_ONE_DOUBLE)
#define CAIRO_FIXED_MIN_DOUBLE (((double) CAIRO_FIXED_MIN) / CAIRO_FIXED_ONE_DOUBLE)
#define CAIRO_FIXED_ERROR_DOUBLE (1. / (2 * CAIRO_FIXED_ONE_DOUBLE))
#define CAIRO_FIXED_FRAC_MASK ((cairo_fixed_t)(((cairo_fixed_unsigned_t)(-1)) >> (CAIRO_FIXED_BITS - CAIRO_FIXED_FRAC_BITS)))
@ -128,6 +133,17 @@ _cairo_fixed_from_double (double d)
# error See cairo-fixed-private.h for details.
#endif
static inline cairo_fixed_t
_cairo_fixed_from_double_clamped (double d, double tolerance)
{
if (d > CAIRO_FIXED_MAX_DOUBLE - tolerance)
d = CAIRO_FIXED_MAX_DOUBLE - tolerance;
else if (d < CAIRO_FIXED_MIN_DOUBLE + tolerance)
d = CAIRO_FIXED_MIN_DOUBLE + tolerance;
return _cairo_fixed_from_double (d);
}
static inline cairo_fixed_t
_cairo_fixed_from_26_6 (uint32_t i)
{

View file

@ -29,6 +29,9 @@
#define LINE_WIDTH 1.
#define SIZE 10
#define LINE_NBR 6
#define WIDTH (SIZE * (LINE_NBR + 1))
#define HEIGHT (SIZE * (LINE_NBR + 1))
struct {
double length;
@ -66,8 +69,8 @@ draw (cairo_t *cr, int width, int height)
}
/* This should display a perfect vertically centered black line */
cairo_move_to (cr, 0.5, -1e100);
cairo_line_to (cr, pos, 1e100);
cairo_move_to (cr, -1e100, HEIGHT/2);
cairo_line_to (cr, 1e100, HEIGHT/2);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_stroke (cr);
@ -80,6 +83,6 @@ CAIRO_TEST (long_lines,
"\nLong lines are not drawn due to the limitations of the internal 16.16 fixed-point coordinates",
"stroke, stress", /* keywords */
NULL, /* requirements */
SIZE * (LINE_NBR + 1), SIZE * (LINE_NBR + 1),
WIDTH, HEIGHT,
NULL, draw)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B