diff options
author | Timothy Pearson <[email protected]> | 2012-11-22 15:17:23 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-11-22 15:17:23 -0600 |
commit | 6953f223818a5a84c8d7a7e12e5f2a2558fd20c5 (patch) | |
tree | 52f0ee885abf2aa442f449bd19238bdb47eaa6c8 /tdegtk/tqtcairopainter.cpp | |
parent | e8c3a67b5a6c7b9e737071393d00ab0d6d09983d (diff) | |
download | gtk3-tqt-engine-6953f223818a5a84c8d7a7e12e5f2a2558fd20c5.tar.gz gtk3-tqt-engine-6953f223818a5a84c8d7a7e12e5f2a2558fd20c5.zip |
Fix drawing glitch when line width < 1px
Diffstat (limited to 'tdegtk/tqtcairopainter.cpp')
-rw-r--r-- | tdegtk/tqtcairopainter.cpp | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/tdegtk/tqtcairopainter.cpp b/tdegtk/tqtcairopainter.cpp index d926541..8666b8b 100644 --- a/tdegtk/tqtcairopainter.cpp +++ b/tdegtk/tqtcairopainter.cpp @@ -756,6 +756,24 @@ void TQt3CairoPaintDevice::drawPolygon(const TQPointArray* pointarray, bool wind cairo_close_path(FASTEST_AVAILABLE_PAINTER); } dualStrokePen(); + + // WARNING + // The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines! + // See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details. + // This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn. + if (m_pen.width() < 1) { + cairo_save(FASTEST_AVAILABLE_PAINTER); + cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1); + for (i=0;i<pointarray->count();i++) { + pointarray->point(i, &x, &y); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + } + cairo_stroke(FASTEST_AVAILABLE_PAINTER); + cairo_restore(FASTEST_AVAILABLE_PAINTER); + } } } cairo_restore(FASTEST_AVAILABLE_PAINTER); @@ -1354,8 +1372,32 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) if (FASTEST_AVAILABLE_PAINTER) { cairo_save(FASTEST_AVAILABLE_PAINTER); if (m_pen.style() != TQPen::NoPen) { - cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + bool has_current_point = cairo_has_current_point(FASTEST_AVAILABLE_PAINTER); + double cr_x2; + double cr_y2; + cairo_get_current_point(FASTEST_AVAILABLE_PAINTER, &cr_x2, &cr_y2); + int x2 = cr_x2-CAIRO_PEN_PIXEL_OFFSET; + int y2 = cr_y2-CAIRO_PEN_PIXEL_OFFSET; + + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); dualStrokePen(); + + // WARNING + // The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines! + // See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details. + // This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn. + if (m_pen.width() < 1) { + cairo_save(FASTEST_AVAILABLE_PAINTER); + cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_stroke(FASTEST_AVAILABLE_PAINTER); + cairo_restore(FASTEST_AVAILABLE_PAINTER); + } } cairo_restore(FASTEST_AVAILABLE_PAINTER); } @@ -1367,6 +1409,23 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); dualStrokePen(); + + // WARNING + // The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines! + // See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details. + // This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn. + if (m_pen.width() < 1) { + cairo_save(FASTEST_AVAILABLE_PAINTER); + cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_stroke(FASTEST_AVAILABLE_PAINTER); + cairo_restore(FASTEST_AVAILABLE_PAINTER); + } } cairo_restore(FASTEST_AVAILABLE_PAINTER); } @@ -1459,6 +1518,23 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); dualStrokePen(); + + // WARNING + // The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines! + // See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details. + // This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn. + if (m_pen.width() < 1) { + cairo_save(FASTEST_AVAILABLE_PAINTER); + cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET); + cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET); + cairo_stroke(FASTEST_AVAILABLE_PAINTER); + cairo_restore(FASTEST_AVAILABLE_PAINTER); + } } } } |