diff options
author | Federico Mena Quintero <federico@gnome.org> | 2021-03-17 18:35:02 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2021-03-17 18:35:02 -0600 |
commit | 186f31845867d088fdf4d78c06c09ce7ebf11b03 (patch) | |
tree | 9b6f9564a23ca3466bc7ddf8fe863fe115e48269 | |
parent | 098aab786eb975ebb57a7f384fd69806d4989077 (diff) | |
download | librsvg-svenfoo/remove-pangoft2-dependency.tar.gz |
Move the test for #347 to Rustsvenfoo/remove-pangoft2-dependency
This is a test for a particular layer's position; #347 was about text
elements not getting their bounds computed correctly.
Note that the original test in C had this:
if (fixture->has_position) {
g_assert_cmpint (fixture->x, ==, position.x);
g_assert_cmpint (fixture->y, ==, position.y);
}
Even though fixture->x is a double, it is being cast to an int to
compare it to position.x (RsvgPositionData uses ints).
The test effectively does "is the position.y between 48 and 49", so
that's what we use in the Rust test.
-rw-r--r-- | tests/api.c | 7 | ||||
-rw-r--r-- | tests/src/bugs.rs | 40 |
2 files changed, 38 insertions, 9 deletions
diff --git a/tests/api.c b/tests/api.c index 90d75301..bd5f417c 100644 --- a/tests/api.c +++ b/tests/api.c @@ -1556,13 +1556,6 @@ static DimensionsFixtureData dimensions_fixtures[] = FALSE, TRUE }, { - "/dimensions/sub/text_position", - "dimensions/347-wrapper.svg", - "#LabelA", - 80, 48.90, 0, 0, - TRUE, FALSE - }, - { "/dimensions/with_viewbox", "dimensions/521-with-viewbox.svg", "#foo", diff --git a/tests/src/bugs.rs b/tests/src/bugs.rs index c94588ea..320d364b 100644 --- a/tests/src/bugs.rs +++ b/tests/src/bugs.rs @@ -1,9 +1,13 @@ +#![cfg(test)] +use test_generator::test_resources; + use cairo; -use librsvg::{LoadingError, SvgHandle}; +use float_cmp::approx_eq; +use librsvg::{CairoRenderer, Loader, LoadingError, SvgHandle}; use matches::matches; use crate::reference_utils::{Compare, Evaluate, Reference}; -use crate::utils::{load_svg, render_document, SurfaceSize}; +use crate::utils::{load_svg, render_document, setup_font_map, SurfaceSize}; // https://gitlab.gnome.org/GNOME/librsvg/issues/335 #[test] @@ -318,3 +322,35 @@ fn doubly_recursive_use() { test_renders_as_empty(&svg, "308-doubly-recursive-use"); } + +// https://gitlab.gnome.org/GNOME/librsvg/-/issues/347 +#[test_resources("tests/fixtures/dimensions/347-wrapper.svg")] +fn test_text_bounds(name: &str) { + setup_font_map(); + + let handle = Loader::new() + .read_path(name) + .unwrap_or_else(|e| panic!("could not load: {}", e)); + + let renderer = CairoRenderer::new(&handle).test_mode(); + + let (ink_r, _) = renderer + .geometry_for_layer( + Some("#LabelA"), + &cairo::Rectangle { + x: 0.0, + y: 0.0, + width: 248.0, + height: 176.0, + }, + ) + .unwrap(); + + assert!(approx_eq!(f64, ink_r.x, 80.0)); + + // This is kind of suspicious, but we don't know the actual height of the + // text set at y=49 in the test SVG. However, this test is more "text + // elements compute sensible bounds"; the bug #347 was that their ink_rect + // was not being computed correctly at all. + assert!(ink_r.y > 48.0 && ink_r.y < 49.0); +} |