diff options
author | nyamatongwe <unknown> | 2010-11-05 22:50:12 +1100 |
---|---|---|
committer | nyamatongwe <unknown> | 2010-11-05 22:50:12 +1100 |
commit | 39258eb09e8e17263c26036c8768f4656dcb9594 (patch) | |
tree | 3fad519b16f1987d4f927ade31c8919a6838919f | |
parent | d03426fa9b440f618fd13d7028217ef4717a9821 (diff) | |
download | scintilla-mirror-39258eb09e8e17263c26036c8768f4656dcb9594.tar.gz |
Horizontal or vertical lines can be more precisely drawn as a filled
rectangle as this avoids antialiasing the end points which makes them
less intense.
-rw-r--r-- | gtk/PlatGTK.cxx | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 627ac3e68..09e49f370 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -1016,29 +1016,43 @@ void SurfaceImpl::MoveTo(int x_, int y_) { y = y_; } +#ifdef USE_CAIRO +static int Delta(int difference) { + if (difference < 0) + return -1; + else if (difference > 0) + return 1; + else + return 0; +} +#endif + void SurfaceImpl::LineTo(int x_, int y_) { #ifdef USE_CAIRO - // Lines draw their end position, unlike Win32 or GDK with GDK_CAP_NOT_LAST. + // cairo_line_to draws the end position, unlike Win32 or GDK with GDK_CAP_NOT_LAST. // For simple cases, move back one pixel from end. if (context) { - cairo_move_to(context, x + 0.5, y + 0.5); - int xdiff = x_ - x; - int xdelta = 0; - if (xdiff < 0) - xdelta = -1; - else if (xdiff > 0) - xdelta = 1; - int ydiff = y_ - y; - int ydelta = 0; - if (ydiff < 0) - ydelta = -1; - else if (ydiff > 0) - ydelta = 1; - if ((abs(xdiff) == abs(ydiff)) || (xdiff == 0) || (ydiff == 0)) { - // Horizontal, vertical or 45 degree slope - cairo_line_to(context, x_ + 0.5 - xdelta, y_ + 0.5 - ydelta); + int xDiff = x_ - x; + int xDelta = Delta(xDiff); + int yDiff = y_ - y; + int yDelta = Delta(yDiff); + if ((xDiff == 0) || (yDiff == 0)) { + // Horizontal or vertical lines can be more precisely drawn as a filled rectangle + int xEnd = x_ - xDelta; + int left = Platform::Minimum(x, xEnd); + int width = abs(x - xEnd) + 1; + int yEnd = y_ - yDelta; + int top = Platform::Minimum(y, yEnd); + int height = abs(y - yEnd) + 1; + cairo_rectangle(context, left, top, width, height); + cairo_fill(context); + } else if ((abs(xDiff) == abs(yDiff))) { + // 45 degree slope + cairo_move_to(context, x + 0.5, y + 0.5); + cairo_line_to(context, x_ + 0.5 - xDelta, y_ + 0.5 - yDelta); } else { // Line has a different slope so difficult to avoid last pixel + cairo_move_to(context, x + 0.5, y + 0.5); cairo_line_to(context, x_ + 0.5, y_ + 0.5); } cairo_stroke(context); |