From 6d5ee4797bf02d5b25775e742502c1ed4045e4f1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 26 Feb 2012 21:41:35 +1030 Subject: [PATCH] Align fills to device integer coordinates to prevent visible seams in adjacent fills. --- poppler/CairoOutputDev.cc | 30 ++++++++++++++++++++++-------- poppler/CairoOutputDev.h | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index bc5d3a6..d998ba4 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -646,38 +646,52 @@ void CairoOutputDev::alignStrokeCoords(double *x, double *y) cairo_device_to_user (cairo, x, y); } +void CairoOutputDev::alignFillCoords(double *x, double *y) +{ + cairo_user_to_device (cairo, x, y); + *x = floor(*x + 0.5); + *y = floor(*y + 0.5); + cairo_device_to_user (cairo, x, y); +} + void CairoOutputDev::doPath(cairo_t *cairo, GfxState *state, GfxPath *path) { GfxSubpath *subpath; int i, j; + double x, y; cairo_new_path (cairo); for (i = 0; i < path->getNumSubpaths(); ++i) { subpath = path->getSubpath(i); if (subpath->getNumPoints() > 0) { + x = subpath->getX(0); + y = subpath->getY(0); if (align_stroke_coords) { - double x = subpath->getX(0); - double y = subpath->getY(0); alignStrokeCoords(&x, &y); cairo_move_to (cairo, x, y); } else { - cairo_move_to (cairo, subpath->getX(0), subpath->getY(0)); + alignFillCoords(&x, &y); + cairo_move_to (cairo, x, y); } j = 1; while (j < subpath->getNumPoints()) { if (subpath->getCurve(j)) { + x = subpath->getX(j+2); + y = subpath->getY(j+2); + if (j + 3 < subpath->getNumPoints() && !subpath->getCurve(j+3)) + alignFillCoords(&x, &y); cairo_curve_to( cairo, subpath->getX(j), subpath->getY(j), subpath->getX(j+1), subpath->getY(j+1), - subpath->getX(j+2), subpath->getY(j+2)); - + x, y); j += 3; } else { + x = subpath->getX(j); + y = subpath->getY(j); if (align_stroke_coords) { - double x = subpath->getX(j); - double y = subpath->getY(j); alignStrokeCoords(&x, &y); cairo_line_to (cairo, x, y); } else { - cairo_line_to (cairo, subpath->getX(j), subpath->getY(j)); + alignFillCoords(&x, &y); + cairo_line_to (cairo, x, y); } ++j; } diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h index 8b379da..5645872 100644 --- a/poppler/CairoOutputDev.h +++ b/poppler/CairoOutputDev.h @@ -275,6 +275,7 @@ protected: void setMimeData(Stream *str, Object *ref, cairo_surface_t *image); void fillToStrokePathClip(); void alignStrokeCoords(double *x, double *y); + void alignFillCoords(double *x, double *y); GfxRGB fill_color, stroke_color; cairo_pattern_t *fill_pattern, *stroke_pattern; -- 1.7.5.4