summaryrefslogtreecommitdiffstats
path: root/src/widgets/ruler.cpp
diff options
context:
space:
mode:
authorDiederik van Lierop <mail@diedenrezi.nl>2008-02-01 21:59:48 +0000
committerdvlierop2 <dvlierop2@users.sourceforge.net>2008-02-01 21:59:48 +0000
commit56fb56a2417f31c94f1802501cd39e048ead7491 (patch)
tree010c608446cd9ecd249eded783ce9eda00c6cc67 /src/widgets/ruler.cpp
parenttry to preserve layers, strip top-level switch and foreignObject (diff)
downloadinkscape-56fb56a2417f31c94f1802501cd39e048ead7491.tar.gz
inkscape-56fb56a2417f31c94f1802501cd39e048ead7491.zip
Suppress the jitter that sometimes occurs when drawing the ticks of the rulers
(bzr r4632)
Diffstat (limited to 'src/widgets/ruler.cpp')
-rw-r--r--src/widgets/ruler.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index abc8cddfe..597034faf 100644
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
@@ -184,8 +184,8 @@ sp_hruler_draw_ticks (GtkRuler *ruler)
if ((upper - lower) == 0)
return;
increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower);
-
- /* determine the scale
+
+ /* determine the scale
* We calculate the text size as for the vruler instead of using
* text_width = gdk_string_width(font, unit_str), so that the result
* for the scale looks consistent with an accompanying vruler
@@ -208,7 +208,7 @@ sp_hruler_draw_ticks (GtkRuler *ruler)
subd_incr = ruler->metric->ruler_scale[scale] /
ruler->metric->subdivide[i];
if (subd_incr * fabs(increment) <= MINIMUM_INCR)
- continue;
+ continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
@@ -233,8 +233,12 @@ sp_hruler_draw_ticks (GtkRuler *ruler)
while (cur <= end)
{
- pos = int(Inkscape::round ((cur - lower) * increment) - UNUSED_PIXELS);
-
+ // due to the typical values for cur, lower and increment, pos will often end up to
+ // be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h)
+ // and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a
+ // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-12
+ pos = int(Inkscape::round((cur - lower) * increment + 1e-12)) - UNUSED_PIXELS;
+
gdk_draw_line (ruler->backing_store, gc,
pos, height + ythickness,
pos, height - length + ythickness);
@@ -261,7 +265,7 @@ sp_hruler_draw_ticks (GtkRuler *ruler)
* errors in subd_incr.
*/
++tick_index;
- cur = start + (((double)tick_index) * (double)ruler->metric->ruler_scale[scale])/ ruler->metric->subdivide[i];
+ cur = start + tick_index * subd_incr;
}
}
}
@@ -565,7 +569,11 @@ sp_vruler_draw_ticks (GtkRuler *ruler)
cur = start;
while (cur < end) {
- pos = int(Inkscape::round ((cur - lower) * increment) - UNUSED_PIXELS);
+ // due to the typical values for cur, lower and increment, pos will often end up to
+ // be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h)
+ // and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a
+ // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-12
+ pos = int(Inkscape::round((cur - lower) * increment + 1e-12)) - UNUSED_PIXELS;
gdk_draw_line (ruler->backing_store, gc,
height + xthickness - length, pos,
@@ -599,7 +607,7 @@ sp_vruler_draw_ticks (GtkRuler *ruler)
* errors in subd_incr.
*/
++tick_index;
- cur = start + (((double)tick_index) * (double)ruler->metric->ruler_scale[scale])/ ruler->metric->subdivide[i];
+ cur = start + tick_index * subd_incr;
}
}
}