diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2019-05-19 19:22:21 +0000 |
|---|---|---|
| committer | Diederik van Lierop <mail@diedenrezi.nl> | 2019-05-20 16:22:27 +0000 |
| commit | e0eb5d33c213ad8e36dcd667ed9c06d32ffc9544 (patch) | |
| tree | a855b07be15b415e5df4e03fb2116288d945df9c | |
| parent | Fix pixel alignment of box selection cue (diff) | |
| download | inkscape-e0eb5d33c213ad8e36dcd667ed9c06d32ffc9544.tar.gz inkscape-e0eb5d33c213ad8e36dcd667ed9c06d32ffc9544.zip | |
Fix alignment of ruler ticks
| -rw-r--r-- | src/desktop.cpp | 4 | ||||
| -rw-r--r-- | src/desktop.h | 2 | ||||
| -rw-r--r-- | src/display/sp-canvas.cpp | 8 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.cpp | 17 | ||||
| -rw-r--r-- | src/widgets/gimp/ruler.cpp | 21 |
5 files changed, 25 insertions, 27 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index ebc3e5591..4c28cd918 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -940,9 +940,9 @@ SPDesktop::set_display_area( Geom::Rect const &r, double border, bool log) /** * Return viewbox dimensions. FixMe: Doesn't handle rotation. FixMe InvertedY */ -Geom::Rect SPDesktop::get_display_area() const +Geom::Rect SPDesktop::get_display_area(bool use_integer_viewbox) const { - Geom::Rect const viewbox = canvas->getViewbox(); + Geom::Rect const viewbox = use_integer_viewbox ? canvas->getViewboxIntegers() : canvas->getViewbox(); double const scale = _current_affine.getZoom(); return viewbox * Geom::Scale(1. / scale, _doc2dt[3] / scale); diff --git a/src/desktop.h b/src/desktop.h index 69ccd7bd9..66fad5a65 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -331,7 +331,7 @@ public: void set_display_area (bool log = true); void set_display_area (Geom::Point const &c, Geom::Point const &w, bool log = true); void set_display_area (Geom::Rect const &a, Geom::Coord border, bool log = true); - Geom::Rect get_display_area() const; + Geom::Rect get_display_area(bool use_integer_viewbox = false) const; void zoom_absolute_keep_point (Geom::Point const &c, double const zoom); void zoom_relative_keep_point (Geom::Point const &c, double const zoom); diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index e8a36a3a7..bb8848a18 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -2814,8 +2814,7 @@ Geom::Rect SPCanvas::getViewbox() const GtkAllocation allocation; gtk_widget_get_allocation (GTK_WIDGET (this), &allocation); - return Geom::Rect(Geom::Point(_dx0, _dy0), - Geom::Point(_dx0 + allocation.width, _dy0 + allocation.height)); + return Geom::Rect::from_xywh(_dx0, _dy0, allocation.width, allocation.height); } /** @@ -2826,10 +2825,7 @@ Geom::IntRect SPCanvas::getViewboxIntegers() const GtkAllocation allocation; gtk_widget_get_allocation (GTK_WIDGET(this), &allocation); - Geom::IntRect ret; - ret.setMin(Geom::IntPoint(_x0, _y0)); - ret.setMax(Geom::IntPoint(_x0 + allocation.width, _y0 + allocation.height)); - return ret; + return Geom::IntRect::from_xywh(_x0, _y0, allocation.width, allocation.height); } inline int sp_canvas_tile_floor(int x) diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 40bada366..32ca1bac2 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1713,14 +1713,19 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPDocument *document) void SPDesktopWidget::update_rulers() { - Geom::Rect viewbox = desktop->get_display_area(); + Geom::Rect viewbox = desktop->get_display_area(true); + // "true" means: Use integer values of the canvas for calculating the display area, similar + // to the integer values used for positioning the grid lines. (see SPCanvas::scrollTo(), + // where ix and iy are rounded integer values; these values are stored in SPCanvasBuf->rect, + // and used for drawing the grid). By using the integer values here too, the ruler ticks + // will be perfectly aligned to the grid double lower_x = _dt2r * (viewbox.left() - _ruler_origin[Geom::X]); double upper_x = _dt2r * (viewbox.right() - _ruler_origin[Geom::X]); sp_ruler_set_range(SP_RULER(_hruler->gobj()), - lower_x, - upper_x, - (upper_x - lower_x)); + lower_x, + upper_x, + upper_x - lower_x); double lower_y = _dt2r * (viewbox.bottom() - _ruler_origin[Geom::Y]); double upper_y = _dt2r * (viewbox.top() - _ruler_origin[Geom::Y]); @@ -1729,8 +1734,8 @@ SPDesktopWidget::update_rulers() } sp_ruler_set_range(SP_RULER(_vruler->gobj()), lower_y, - upper_y, - (upper_y - lower_y)); + upper_y, + upper_y - lower_y); } diff --git a/src/widgets/gimp/ruler.cpp b/src/widgets/gimp/ruler.cpp index 1d196d2b0..48ed4a5dd 100644 --- a/src/widgets/gimp/ruler.cpp +++ b/src/widgets/gimp/ruler.cpp @@ -1088,7 +1088,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gint digit_offset; gchar digit_str[2] = { '\0', '\0' }; gint text_size; - gint pos; + gdouble pos; gdouble max_size; Inkscape::Util::Unit const *unit = nullptr; SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ @@ -1123,6 +1123,8 @@ sp_ruler_draw_ticks (SPRuler *ruler) cr = cairo_create (priv->backing_store); + cairo_set_line_width(cr, 1.0); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); @@ -1221,24 +1223,19 @@ sp_ruler_draw_ticks (SPRuler *ruler) for (cur = start; cur <= end; cur += subd_incr) { - // 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-9 (that's only one nanopixel ;-)) - pos = gint(round((cur - lower) * increment + 1e-12)); + pos = floor((cur - lower) * increment) + 0.5; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { - cairo_rectangle (cr, - pos, height + border.top - length, - 1, length); + cairo_move_to(cr, pos, height + border.top - length); + cairo_line_to(cr, pos, height + border.top); } else { - cairo_rectangle (cr, - height + border.left - length, pos, - length, 1); + cairo_move_to(cr, height + border.left - length, pos); + cairo_line_to(cr, height + border.left , pos); } + cairo_stroke(cr); /* draw label */ double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]); |
