mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 04:07:12 -06:00
refactor(text): move tests_*.rs to tests/<topic>.rs
This commit is contained in:
@@ -699,49 +699,5 @@ pub fn logical_order(visual: &str) -> Option<(Vec<usize>, bool)> {
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
mod tests_axes;
|
||||
#[cfg(test)]
|
||||
mod tests_bidi;
|
||||
#[cfg(test)]
|
||||
mod tests_bitmaps;
|
||||
#[cfg(test)]
|
||||
mod tests_colr;
|
||||
#[cfg(test)]
|
||||
mod tests_combos;
|
||||
#[cfg(test)]
|
||||
mod tests_devanagari;
|
||||
#[cfg(test)]
|
||||
mod tests_embed;
|
||||
#[cfg(test)]
|
||||
mod tests_fit;
|
||||
#[cfg(test)]
|
||||
mod tests_hang;
|
||||
#[cfg(test)]
|
||||
mod tests_inline;
|
||||
#[cfg(test)]
|
||||
mod tests_joiners;
|
||||
#[cfg(test)]
|
||||
mod tests_justify;
|
||||
#[cfg(test)]
|
||||
mod tests_path_joins;
|
||||
#[cfg(test)]
|
||||
mod tests_ruby;
|
||||
#[cfg(test)]
|
||||
mod tests_scripts;
|
||||
#[cfg(test)]
|
||||
mod tests_snap;
|
||||
#[cfg(test)]
|
||||
mod tests_svg_glyphs;
|
||||
#[cfg(test)]
|
||||
mod tests_sysfonts;
|
||||
#[cfg(test)]
|
||||
mod tests_typo;
|
||||
#[cfg(test)]
|
||||
mod tests_variable;
|
||||
#[cfg(test)]
|
||||
mod tests_versions;
|
||||
#[cfg(test)]
|
||||
mod tests_vertical;
|
||||
#[cfg(test)]
|
||||
#[path = "../build/web_fonts.rs"]
|
||||
mod web_fonts_build;
|
||||
|
||||
@@ -3,6 +3,29 @@ use kurbo::{Affine, Shape};
|
||||
use vectorcraft_doc::{CharStyle, Justify, TextKind, TextRun};
|
||||
use vectorcraft_geom::PathData;
|
||||
|
||||
mod axes;
|
||||
mod bidi;
|
||||
mod bitmaps;
|
||||
mod colr;
|
||||
mod combos;
|
||||
mod devanagari;
|
||||
mod embed;
|
||||
mod fit;
|
||||
mod hang;
|
||||
mod inline;
|
||||
mod joiners;
|
||||
mod justify;
|
||||
mod path_joins;
|
||||
mod ruby;
|
||||
mod scripts;
|
||||
mod snap;
|
||||
mod svg_glyphs;
|
||||
mod sysfonts;
|
||||
mod typo;
|
||||
mod variable;
|
||||
mod versions;
|
||||
mod vertical;
|
||||
|
||||
/// The bundled fonts only: what these tests measure doesn't change with the fonts installed.
|
||||
fn db() -> &'static FontDb {
|
||||
static DB: std::sync::OnceLock<FontDb> = std::sync::OnceLock::new();
|
||||
|
||||
@@ -9,8 +9,8 @@ use skrifa::instance::{LocationRef, Size};
|
||||
use skrifa::raw::TableProvider;
|
||||
use vectorcraft_doc::CharStyle;
|
||||
|
||||
use super::test_fonts::{TWO_AXIS_FAMILY as FAMILY, TWO_AXIS_NARROW, VARIABLE_CHARS, VARIABLE_WIDEN, two_axis_font};
|
||||
use super::*;
|
||||
use crate::test_fonts::{TWO_AXIS_FAMILY as FAMILY, TWO_AXIS_NARROW, VARIABLE_CHARS, VARIABLE_WIDEN, two_axis_font};
|
||||
use crate::*;
|
||||
|
||||
/// A database of the bundled fonts and the two-axis test font.
|
||||
fn db() -> FontDb {
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Direction, source-cluster and editing regressions; no RTL font assets required.
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, BezPath, Point, Rect, Shape};
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
@@ -6,8 +6,8 @@ use skrifa::MetadataProvider;
|
||||
use skrifa::instance::{LocationRef, Size};
|
||||
use vectorcraft_doc::CharStyle;
|
||||
|
||||
use super::test_fonts::{COLOUR_CBDT_BEARINGS, COLOUR_CHAR, COLOUR_PPEM, colour_bitmap_family, colour_bitmap_font};
|
||||
use super::*;
|
||||
use crate::test_fonts::{COLOUR_CBDT_BEARINGS, COLOUR_CHAR, COLOUR_PPEM, colour_bitmap_family, colour_bitmap_font};
|
||||
use crate::*;
|
||||
|
||||
fn db(sbix: bool) -> FontDb {
|
||||
let db = FontDb::with_font_dirs(vec![]);
|
||||
@@ -32,7 +32,7 @@ fn assert_near(a: Rect, b: Rect) {
|
||||
|
||||
/// The left side bearing of [`COLOUR_CHAR`] in the bundled Source Sans 3 (font units of 1000).
|
||||
fn lsb() -> f64 {
|
||||
let font = skrifa::FontRef::new(include_bytes!("../../../assets/fonts/SourceSans3-Regular.ttf")).unwrap();
|
||||
let font = skrifa::FontRef::new(include_bytes!("../../../../assets/fonts/SourceSans3-Regular.ttf")).unwrap();
|
||||
let gid = font.charmap().map(COLOUR_CHAR).unwrap();
|
||||
f64::from(font.glyph_metrics(Size::unscaled(), LocationRef::default()).left_side_bearing(gid).unwrap())
|
||||
}
|
||||
@@ -95,8 +95,8 @@ fn other_glyphs_of_a_colour_font_keep_their_outlines() {
|
||||
/// decoded (a font is untrusted input).
|
||||
#[test]
|
||||
fn a_bitmap_past_the_caps_or_without_a_header_is_no_image() {
|
||||
use super::bitmap::{MAX_PNG_BYTES, MAX_SIDE};
|
||||
use super::test_fonts::{COLOUR_LARGE, colour_bitmap_font_with, solid_png};
|
||||
use crate::bitmap::{MAX_PNG_BYTES, MAX_SIDE};
|
||||
use crate::test_fonts::{COLOUR_LARGE, colour_bitmap_font_with, solid_png};
|
||||
let good = solid_png(COLOUR_PPEM.into(), COLOUR_LARGE);
|
||||
// A header claiming a side past the cap (the IHDR width).
|
||||
let mut wide = good.clone();
|
||||
@@ -4,7 +4,7 @@
|
||||
use skrifa::MetadataProvider;
|
||||
use skrifa::color::ColorGlyphFormat;
|
||||
|
||||
use super::test_fonts::{COLOUR_CHAR, COLR_SWEEP_CHAR, colr_font};
|
||||
use crate::test_fonts::{COLOUR_CHAR, COLR_SWEEP_CHAR, colr_font};
|
||||
|
||||
#[test]
|
||||
fn colr_fonts_build_and_read() {
|
||||
@@ -24,8 +24,8 @@ use skrifa::instance::LocationRef;
|
||||
use vectorcraft_doc::color::{BlendMode, Color, GradientKind, Paint};
|
||||
use vectorcraft_doc::{Node, NodeKind};
|
||||
|
||||
use super::colr::{ColourContent, colour_glyph};
|
||||
use super::test_fonts::{COLR_GREEN, COLR_RED};
|
||||
use crate::colr::{ColourContent, colour_glyph};
|
||||
use crate::test_fonts::{COLR_GREEN, COLR_RED};
|
||||
|
||||
const FOREGROUND: Color = Color::Rgb { r: 0.25, g: 0.5, b: 0.75 };
|
||||
|
||||
@@ -120,7 +120,7 @@ fn a_colr_graph_that_paints_itself_is_no_colour_glyph() {
|
||||
let base = GlyphId16::new(u16::try_from(base).unwrap());
|
||||
let mut colr = Colr::new(0, None, None, 0);
|
||||
colr.base_glyph_list = Some(BaseGlyphList::new(1, vec![BaseGlyphPaint::new(base, Paint::colr_glyph(base))])).into();
|
||||
let font = super::test_fonts::colr_font_with("Colrtest Loop", &colr).unwrap();
|
||||
let font = crate::test_fonts::colr_font_with("Colrtest Loop", &colr).unwrap();
|
||||
assert!(content(&font, COLOUR_CHAR).is_none());
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ fn a_colr_graph_nested_past_the_cap_is_no_colour_glyph() {
|
||||
}
|
||||
let mut colr = Colr::new(0, None, None, 0);
|
||||
colr.base_glyph_list = Some(BaseGlyphList::new(1, vec![BaseGlyphPaint::new(base, paint)])).into();
|
||||
let font = super::test_fonts::colr_font_with("Colrtest Deep", &colr).unwrap();
|
||||
let font = crate::test_fonts::colr_font_with("Colrtest Deep", &colr).unwrap();
|
||||
assert!(content(&font, COLOUR_CHAR).is_none());
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ fn a_colr_graph_nested_past_the_cap_is_no_colour_glyph() {
|
||||
use kurbo::Point as KPoint;
|
||||
use vectorcraft_doc::{CharStyle, TextObject};
|
||||
|
||||
use super::test_fonts::colr_family;
|
||||
use super::{FontDb, layout};
|
||||
use crate::test_fonts::colr_family;
|
||||
use crate::{FontDb, layout};
|
||||
|
||||
fn colr_db(v1: bool) -> FontDb {
|
||||
let db = FontDb::with_font_dirs(vec![]);
|
||||
@@ -223,7 +223,7 @@ fn a_face_with_colr_and_sbix_draws_colr() {
|
||||
use write_fonts::FontBuilder;
|
||||
use write_fonts::types::Tag;
|
||||
let colr = colr_font(false).unwrap();
|
||||
let sbix = super::test_fonts::colour_bitmap_font(true).unwrap();
|
||||
let sbix = crate::test_fonts::colour_bitmap_font(true).unwrap();
|
||||
let sbix = skrifa::FontRef::new(&sbix).unwrap();
|
||||
let font = skrifa::FontRef::new(&colr).unwrap();
|
||||
let mut builder = FontBuilder::new();
|
||||
@@ -251,7 +251,7 @@ fn v1_font(family: &str, base: char, paint: impl Fn(write_fonts::types::GlyphId1
|
||||
let mut colr = Colr::new(0, None, None, 0);
|
||||
colr.base_glyph_list = Some(BaseGlyphList::new(1, vec![BaseGlyphPaint::new(gid(base), paint(gid('O')))])).into();
|
||||
colr.layer_list = Some(LayerList::new(1, vec![solid(0)])).into();
|
||||
super::test_fonts::colr_font_with(family, &colr).unwrap()
|
||||
crate::test_fonts::colr_font_with(family, &colr).unwrap()
|
||||
}
|
||||
|
||||
use write_fonts::tables::colr::Paint as ColrPaint;
|
||||
@@ -312,7 +312,7 @@ fn a_collapsed_sweep_glyph_draws_nothing() {
|
||||
// A clip box, so the image is made.
|
||||
let clip = ClipBox::format_1(FWord::new(0), FWord::new(0), FWord::new(500), FWord::new(500));
|
||||
colr.clip_list = Some(ClipList::new(1, 1, vec![Clip::new(gid(COLOUR_CHAR), gid(COLOUR_CHAR), clip)])).into();
|
||||
let font = super::test_fonts::colr_font_with("Colrtest Flat", &colr).unwrap();
|
||||
let font = crate::test_fonts::colr_font_with("Colrtest Flat", &colr).unwrap();
|
||||
let Some(ColourContent::Image(image)) = content(&font, COLOUR_CHAR) else { panic!("an image") };
|
||||
assert!(image.blob.bytes.starts_with(b"\x89PNG"));
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
//! per-paragraph attributes and inline graphics. Each feature has its own tests; these check that
|
||||
//! one doesn't undo or skip another (as vertical alignment once left inline art behind).
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::Shape;
|
||||
use vectorcraft_doc::{AreaFit, CharStyle, Composer, InlineArt, Justify, TextKind, TextRun, VerticalAlign};
|
||||
use vectorcraft_geom::PathData;
|
||||
@@ -3,7 +3,7 @@
|
||||
//! (https://learn.microsoft.com/en-us/typography/script-development/devanagari) and the Unicode
|
||||
//! Standard's Devanagari section (https://www.unicode.org/versions/latest/core-spec/chapter-12/).
|
||||
//! No font is committed: the tests use an installed face and print SKIPPED when none is found.
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{BezPath, Point};
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{CharStyle, TextKind};
|
||||
@@ -5,8 +5,8 @@ use skrifa::instance::{LocationRef, Size};
|
||||
use skrifa::raw::types::Tag;
|
||||
use skrifa::raw::{FontData, FontRead, TableProvider};
|
||||
|
||||
use super::embed::Embedding;
|
||||
use super::*;
|
||||
use crate::embed::Embedding;
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn fs_type_flags_decide_the_embedding() {
|
||||
@@ -22,7 +22,7 @@ fn fs_type_flags_decide_the_embedding() {
|
||||
/// The bundled Source Sans 3 Regular renamed `family` (13 characters, as long as the original
|
||||
/// name) with OS/2 `fsType` set to `fs_type`.
|
||||
fn licensed_font(family: &str, fs_type: u16) -> Vec<u8> {
|
||||
let mut data = include_bytes!("../../../assets/fonts/SourceSans3-Regular.ttf").to_vec();
|
||||
let mut data = include_bytes!("../../../../assets/fonts/SourceSans3-Regular.ttf").to_vec();
|
||||
let table = |data: &[u8], tag: &[u8; 4]| {
|
||||
let f = skrifa::FontRef::new(data).unwrap();
|
||||
let r = f.table_directory.table_records().iter().find(|r| r.tag().to_be_bytes() == *tag).unwrap();
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Area type fitting: Shrink Text to Fit.
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::Shape;
|
||||
use vectorcraft_doc::{AreaFit, CharStyle, TextKind};
|
||||
use vectorcraft_geom::PathData;
|
||||
@@ -3,7 +3,7 @@
|
||||
//! paragraphs" › Hanging punctuation,
|
||||
//! <https://helpx.adobe.com/illustrator/using/formatting-paragraphs.html>).
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, Shape};
|
||||
use vectorcraft_doc::{CharStyle, Composer, Justify, TextKind};
|
||||
use vectorcraft_geom::PathData;
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Inline graphics in text: a symbol's art laid out like a glyph.
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, Shape};
|
||||
use vectorcraft_doc::text::INLINE_CHAR;
|
||||
use vectorcraft_doc::{CharStyle, InlineArt, Justify, TextKind, TextRun};
|
||||
@@ -7,7 +7,7 @@
|
||||
//! https://learn.microsoft.com/en-us/typography/script-development/bengali).
|
||||
//! No font is committed: the tests use installed faces and print SKIPPED when none is found, except
|
||||
//! the check of the half-form test's face filter, which builds its faces in code.
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::Point;
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::CharStyle;
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Paragraph panel menu › Justification…: word spacing, letter spacing, glyph scaling, Single Word
|
||||
//! Justification and Auto Leading in layout.
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, Shape};
|
||||
use vectorcraft_doc::text::Kashida;
|
||||
use vectorcraft_doc::{CharStyle, JustificationOptions, Justify, SingleWordJustify, TextKind};
|
||||
@@ -2,7 +2,7 @@
|
||||
//! between one glyph's edge and the next one's, at the baseline and at the height of the joining
|
||||
//! stroke, is the measure. Fonts are installed ones (none is kept in the repository): the tests
|
||||
//! that need an Arabic font say so and stop without one.
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, BezPath, Point, Shape};
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{CharStyle, TextKind};
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Ruby (furigana) tests: geometry over the base text in horizontal and vertical type, line
|
||||
//! growth, overhang/squeeze, splitting over a line break, and the byte ranges following edits.
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, Point, Rect, Shape};
|
||||
use vectorcraft_doc::{CharStyle, RubyAlign, RubyPosition, RubySpan, TextKind};
|
||||
use vectorcraft_geom::PathData;
|
||||
@@ -3,7 +3,7 @@
|
||||
use kurbo::Shape;
|
||||
use vectorcraft_doc::{CharPosition, CharStyle, ScriptMetrics, TextObject};
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
|
||||
fn layout_of(text: &str, st: CharStyle) -> TextLayout {
|
||||
layout(FontDb::global(), &TextObject::point(kurbo::Point::ZERO, text, st))
|
||||
@@ -3,7 +3,7 @@
|
||||
use kurbo::{Affine, Shape};
|
||||
use vectorcraft_doc::CharStyle;
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
|
||||
fn text_at(x: f64, y: f64) -> TextObject {
|
||||
TextObject::point(Point::new(x, y), "Hill", CharStyle { size: 9.0, ..CharStyle::default() })
|
||||
@@ -8,11 +8,11 @@ use vectorcraft_doc::color::{Color, Paint};
|
||||
use vectorcraft_doc::{Appearance, CharStyle, Node, NodeId, TextObject};
|
||||
use vectorcraft_geom::PathData;
|
||||
|
||||
use super::test_fonts::{SVG_CHAR, source_sans_gid, svg_font};
|
||||
use crate::test_fonts::{SVG_CHAR, source_sans_gid, svg_font};
|
||||
|
||||
/// The family of the SVG test fonts here (each database holds one).
|
||||
const FAMILY: &str = "Svgtest Glyphs";
|
||||
use super::{FontDb, layout, set_svg_glyph_reader};
|
||||
use crate::{FontDb, layout, set_svg_glyph_reader};
|
||||
|
||||
/// Stands in for the SVG importer, which this crate can't use (it is a layer up): a square one em
|
||||
/// wide in the fill, stroked when there is a stroke, for a document that has the glyph's element.
|
||||
@@ -88,7 +88,7 @@ fn colr_comes_before_svg() {
|
||||
use write_fonts::FontBuilder;
|
||||
use write_fonts::types::Tag;
|
||||
set_svg_glyph_reader(reader);
|
||||
let colr = super::test_fonts::colr_font(false).unwrap();
|
||||
let colr = crate::test_fonts::colr_font(false).unwrap();
|
||||
let colr = skrifa::FontRef::new(&colr).unwrap();
|
||||
let g = gid(SVG_CHAR);
|
||||
let svg = svg_font(FAMILY, &[(g, g, &document(""))]).unwrap();
|
||||
@@ -103,7 +103,7 @@ fn colr_comes_before_svg() {
|
||||
}
|
||||
let db = FontDb::with_font_dirs(vec![]);
|
||||
assert_eq!(db.add_font(builder.build()), 1);
|
||||
let st = CharStyle { font_family: super::test_fonts::colr_family(false).into(), size: 100.0, ..CharStyle::default() };
|
||||
let st = CharStyle { font_family: crate::test_fonts::colr_family(false).into(), size: 100.0, ..CharStyle::default() };
|
||||
let l = layout(&db, &TextObject::point(Point::ZERO, &SVG_CHAR.to_string(), st));
|
||||
// The COLR glyph has two layers; the reader's art one path.
|
||||
let colour = l.glyphs[0].colour.clone().unwrap();
|
||||
@@ -122,7 +122,7 @@ fn a_glyph_whose_colr_layers_dont_read_keeps_its_outline() {
|
||||
let g = gid(SVG_CHAR);
|
||||
let mut colr = Colr::new(0, None, None, 0);
|
||||
colr.base_glyph_list = Some(BaseGlyphList::new(1, vec![BaseGlyphPaint::new(GlyphId16::new(g), Paint::colr_glyph(GlyphId16::new(g)))])).into();
|
||||
let looped = super::test_fonts::colr_font_with(FAMILY, &colr).unwrap();
|
||||
let looped = crate::test_fonts::colr_font_with(FAMILY, &colr).unwrap();
|
||||
let looped = skrifa::FontRef::new(&looped).unwrap();
|
||||
let svg = svg_font(FAMILY, &[(g, g, &document(""))]).unwrap();
|
||||
let svg = skrifa::FontRef::new(&svg).unwrap();
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use crate::fontdb::fonts_outside;
|
||||
|
||||
const FAMILY: &str = "Sysfont Sans3";
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Typography tests: rich-text editing, caret navigation, selection, area flow, composer,
|
||||
//! hyphenation, OpenType features, area type options.
|
||||
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::{Affine, Circle, Shape};
|
||||
use vectorcraft_doc::{CharStyle, Justify, TextKind, TextRun};
|
||||
use vectorcraft_geom::PathData;
|
||||
@@ -7,8 +7,8 @@ use skrifa::instance::{LocationRef, Size};
|
||||
use skrifa::raw::TableProvider;
|
||||
use vectorcraft_doc::CharStyle;
|
||||
|
||||
use super::test_fonts::{VARIABLE_CHARS, VARIABLE_FAMILY as FAMILY, VARIABLE_WIDEN, name_table, variable_font};
|
||||
use super::*;
|
||||
use crate::test_fonts::{VARIABLE_CHARS, VARIABLE_FAMILY as FAMILY, VARIABLE_WIDEN, name_table, variable_font};
|
||||
use crate::*;
|
||||
|
||||
fn font() -> Vec<u8> {
|
||||
variable_font().expect("the test font builds")
|
||||
@@ -5,8 +5,8 @@
|
||||
use kurbo::Point;
|
||||
use vectorcraft_doc::CharStyle;
|
||||
|
||||
use super::test_fonts::{TWIN_FAMILY as FAMILY, TWIN_VERSIONS as VERSIONS, twin_font};
|
||||
use super::*;
|
||||
use crate::test_fonts::{TWIN_FAMILY as FAMILY, TWIN_VERSIONS as VERSIONS, twin_font};
|
||||
use crate::*;
|
||||
|
||||
/// A database of the bundled fonts, the newer version of the test family loaded first.
|
||||
fn db() -> FontDb {
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Vertical type (bundled fonts: `§` and `×` stand upright like CJK, letters lie on their side;
|
||||
//! Japanese text only with craft-fonts' faces, skipped without them).
|
||||
use super::*;
|
||||
use crate::*;
|
||||
use kurbo::Shape;
|
||||
use vectorcraft_doc::{CharStyle, Justify, TextKind, TextRun};
|
||||
use vectorcraft_geom::PathData;
|
||||
Reference in New Issue
Block a user