VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Tests: engine tests that add fonts to the shared font database take one lock
bflatasticb2835c4f2b34
diff --git a/crates/engine/src/cmd/textstyles.rs b/crates/engine/src/cmd/textstyles.rsindex 3f60435f3..680024832 100644--- a/crates/engine/src/cmd/textstyles.rs+++ b/crates/engine/src/cmd/textstyles.rs@@ -911,6 +911,7 @@ mod tests {/// resets the type that uses it.#[test]fn variable_font_settings_are_captured_explicitly() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{TWO_AXIS_FAMILY, two_axis_font};vectorcraft_text::FontDb::global().add_font(two_axis_font().unwrap());let (mut s, source) = session_with_text("Source");@@ -934,6 +935,7 @@ mod tests {/// version and Variable Font settings, unless the style sets them.#[test]fn another_font_from_a_style_clears_the_old_fonts_version_and_settings() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{TWO_AXIS_FAMILY, two_axis_font};vectorcraft_text::FontDb::global().add_font(two_axis_font().unwrap());let (mut s, id) = session_with_text("Source");diff --git a/crates/engine/src/cmd/typecmd.rs b/crates/engine/src/cmd/typecmd.rsindex bbcae06a9..b8314b1dc 100644--- a/crates/engine/src/cmd/typecmd.rs+++ b/crates/engine/src/cmd/typecmd.rs@@ -1867,6 +1867,7 @@ mod area_tests {/// when set, each value clamped to its axis's range, and cleared by another font or style.#[test]fn variable_font_settings_are_a_character_attribute_saved_only_when_set() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{TWO_AXIS_FAMILY as FAMILY, two_axis_font};vectorcraft_text::FontDb::global().add_font(two_axis_font().unwrap());let mut s = Session::new();diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex 33125dae1..bec7d9d9f 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -2356,6 +2356,15 @@ fn refresh_tree_text_bounds(n: &mut Arc<vectorcraft_doc::Node>) {}}+/// Held by the tests that add fonts to the shared [`vectorcraft_text::FontDb::global`] for as long+/// as they run: adding a font clears the database's caches, which would change how another such+/// test's type resolves between its layout and its export.+#[cfg(test)]+pub(crate) fn adding_fonts() -> std::sync::MutexGuard<'static, ()> {+ static FONTS: std::sync::Mutex<()> = std::sync::Mutex::new(());+ FONTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner)+}+#[cfg(test)]mod tests;#[cfg(test)]diff --git a/crates/engine/src/tests_colourfonts.rs b/crates/engine/src/tests_colourfonts.rsindex 4ef7c8f76..bd7aa377d 100644--- a/crates/engine/src/tests_colourfonts.rs+++ b/crates/engine/src/tests_colourfonts.rs@@ -60,6 +60,7 @@ fn with_svg_type(family: &str, document: &str) -> Session {/// session registers.#[test]fn create_outlines_turns_svg_glyphs_into_groups() {+ let _fonts = crate::adding_fonts();let g = source_sans_gid(SVG_CHAR).unwrap();let doc = format!(r##"<svg xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="a"><stop offset="0" stop-color="#f00"/><stop offset="1" stop-color="#00f"/></linearGradient></defs><g id="glyph{g}"><path fill="url(#a)" d="M0 0h500v-700h-500z"/></g></svg>"##@@ -81,6 +82,7 @@ fn create_outlines_turns_svg_glyphs_into_groups() {/// draws nothing itself, and its art is drawn where it sits: no outline of the font's covers it.#[test]fn pdf_real_text_draws_svg_glyphs_as_art_and_keeps_their_characters() {+ let _fonts = crate::adding_fonts();let g = source_sans_gid(SVG_CHAR).unwrap();let doc = format!(r##"<svg xmlns="http://www.w3.org/2000/svg"><g id="glyph{g}"><path fill="#f00" d="M0 0h500v-700h-500z"/></g></svg>"##);let s = with_svg_type("Svgtest Pdf", &doc);@@ -110,6 +112,7 @@ fn pdf_real_text_draws_svg_glyphs_as_art_and_keeps_their_characters() {/// text draws nothing, as SVG glyphs' do).#[test]fn pdf_real_text_draws_the_outline_of_an_svg_glyph_without_art() {+ let _fonts = crate::adding_fonts();let doc = r##"<svg xmlns="http://www.w3.org/2000/svg"><g id="glyph1"/></svg>"##;let s = with_svg_type("Svgtest Bare Pdf", doc);let d = s.doc().unwrap().doc.clone();@@ -122,6 +125,7 @@ fn pdf_real_text_draws_the_outline_of_an_svg_glyph_without_art() {/// In a font that may not be embedded, an SVG glyph's art is drawn once.#[test]fn pdf_draws_an_svg_glyphs_art_once_when_its_font_cant_be_embedded() {+ let _fonts = crate::adding_fonts();let g = source_sans_gid(SVG_CHAR).unwrap();let doc = format!(r##"<svg xmlns="http://www.w3.org/2000/svg"><g id="glyph{g}"><path fill="#f00" d="M0 0h500v-700h-500z"/></g></svg>"##);let mut s = session();@@ -137,6 +141,7 @@ fn pdf_draws_an_svg_glyphs_art_once_when_its_font_cant_be_embedded() {/// colour glyphs, as their art.#[test]fn expand_appearance_keeps_the_colour_glyphs_of_type_with_effects() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, colr_family, colr_font};vectorcraft_text::FontDb::global().add_font(colr_font(true).unwrap());let mut s = session();@@ -156,6 +161,7 @@ fn expand_appearance_keeps_the_colour_glyphs_of_type_with_effects() {/// `currentColor`.#[test]fn the_canvas_draws_svg_glyphs_as_their_art() {+ let _fonts = crate::adding_fonts();let g = source_sans_gid(SVG_CHAR).unwrap();// The left half of a 500 by 700 box red, the right half in the text's colour.let doc = format!(@@ -173,6 +179,7 @@ fn the_canvas_draws_svg_glyphs_as_their_art() {/// the document; the PDF of the type before expanding draws them too.#[test]fn expand_appearance_keeps_the_emoji_of_type_with_effects() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, COLOUR_LARGE, COLOUR_PPEM, colour_bitmap_family, colour_bitmap_font, solid_png};vectorcraft_text::FontDb::global().add_font(colour_bitmap_font(false).unwrap());let mut s = session();@@ -206,6 +213,7 @@ fn expand_appearance_keeps_the_emoji_of_type_with_effects() {/// pieces, and Object › Expand takes them into the document.#[test]fn an_envelope_shares_and_expands_the_emoji_of_its_type() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, colour_bitmap_family, colour_bitmap_font};vectorcraft_text::FontDb::global().add_font(colour_bitmap_font(false).unwrap());let mut s = session();diff --git a/crates/engine/src/tests_pathops.rs b/crates/engine/src/tests_pathops.rsindex 257d0608d..1cda89bad 100644--- a/crates/engine/src/tests_pathops.rs+++ b/crates/engine/src/tests_pathops.rs@@ -856,6 +856,7 @@ fn create_outlines_matches_text_bounds() {/// share its pixels.#[test]fn create_outlines_turns_bitmap_glyphs_into_images() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, colour_bitmap_family, colour_bitmap_font};vectorcraft_text::FontDb::global().add_font(colour_bitmap_font(false).unwrap());let mut s = session();@@ -886,6 +887,7 @@ fn create_outlines_turns_bitmap_glyphs_into_images() {/// A glyph image whose key another image of the document holds gets a key of its own.#[test]fn create_outlines_keeps_an_image_already_under_a_glyph_images_key() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, COLOUR_LARGE, COLOUR_PPEM, colour_bitmap_family, colour_bitmap_font, solid_png};vectorcraft_text::FontDb::global().add_font(colour_bitmap_font(false).unwrap());let mut s = session();@@ -1078,6 +1080,7 @@ fn offset_path_that_leaves_nothing_says_so() {/// composite's blend mode kept, every node with an id of the document's.#[test]fn create_outlines_turns_colr_glyphs_into_layer_groups() {+ let _fonts = crate::adding_fonts();use vectorcraft_text::test_fonts::{COLOUR_CHAR, colr_family, colr_font};vectorcraft_text::FontDb::global().add_font(colr_font(true).unwrap());let mut s = session();