Skip to content

Commit 322e722

Browse files
committed
Force snapping off only when actually stamping markers.
Issue pointed out by afvincent.
1 parent 796cb7c commit 322e722

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/_mplcairo.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,6 @@ void GraphicsContextRenderer::draw_markers(
713713
throw std::invalid_argument("Non-matching GraphicsContext");
714714
}
715715
auto const& ac = additional_context();
716-
auto const& old_snap = get_additional_state().snap;
717-
get_additional_state().snap = false;
718716

719717
// As paths store their vertices in an array, the .cast<>() will not make a
720718
// copy and we don't need to explicitly keep the intermediate result alive.
@@ -754,11 +752,19 @@ void GraphicsContextRenderer::draw_markers(
754752
}
755753

756754
if (patterns) {
755+
// When stamping subpixel-positioned markers, there is no benefit in
756+
// snapping (we're going to shift the path by subpixels anyways). We don't
757+
// want to force snapping off in the non-stamped case, as that would e.g.
758+
// ruin alignment of ticks and spines, so the change is only applied in
759+
// this branch.
760+
auto const& old_snap = get_additional_state().snap;
761+
get_additional_state().snap = false;
762+
load_path_exact(cr_, marker_path, &marker_matrix);
763+
get_additional_state().snap = old_snap;
757764
// Get the extent of the marker. Importantly, cairo_*_extents() ignores
758765
// surface dimensions and clipping.
759766
// Matplotlib chooses *not* to call draw_markers() if the marker is bigger
760767
// than the canvas (which may make sense if the marker is indeed huge...).
761-
load_path_exact(cr_, marker_path, &marker_matrix);
762768
double x0, y0, x1, y1;
763769
cairo_stroke_extents(cr_, &x0, &y0, &x1, &y1);
764770
if (fc) {
@@ -850,6 +856,7 @@ void GraphicsContextRenderer::draw_markers(
850856
raw + std::lround(y) * stride + 4 * std::lround(x)) = fc_argb32;
851857
}
852858
cairo_surface_mark_dirty(surface);
859+
853860
} else {
854861
for (auto i = 0; i < n_vertices; ++i) {
855862
cairo_save(cr_);
@@ -862,8 +869,6 @@ void GraphicsContextRenderer::draw_markers(
862869
cairo_restore(cr_);
863870
}
864871
}
865-
866-
get_additional_state().snap = old_snap;
867872
}
868873

869874
void GraphicsContextRenderer::draw_path(

0 commit comments

Comments
 (0)