mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 20:43:36 +00:00
Merge main into fix/svg-clip-path-effects
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
|
||||
use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
use vectorcraft_doc::text::{CharStyle, TextObject};
|
||||
use vectorcraft_doc::text::{CharStyle, TextKind, TextObject};
|
||||
use vectorcraft_doc::{Node, NodeKind};
|
||||
use vectorcraft_geom::Point;
|
||||
use vectorcraft_geom::{PathData, Point};
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// Taken to add fonts, or to look up an installed one by name (`FontDb::face` loads it, which
|
||||
/// changes the fonts too). Renderers lay type out again when the fonts change, so tests of what
|
||||
/// they keep between frames hold it shared ([`fonts_steady`]) and the tests that change the fonts
|
||||
/// hold it alone ([`adding_fonts`]).
|
||||
/// Taken to add fonts, to look up an installed one by name (`FontDb::face` loads it, which
|
||||
/// changes the fonts too) or to change the hyphenation exceptions. Renderers lay type out again
|
||||
/// when the fonts or the exceptions change, so tests of what they keep between frames hold it
|
||||
/// shared ([`fonts_steady`]) and the tests that change them hold it alone ([`adding_fonts`]).
|
||||
static FONTS: RwLock<()> = RwLock::new(());
|
||||
|
||||
/// No fonts are added by these tests until the guard is dropped.
|
||||
@@ -29,14 +29,12 @@ pub(crate) fn adding_fonts() -> RwLockWriteGuard<'static, ()> {
|
||||
/// What `step` returns from a run in which the fonts stayed the same. The fonts can change while
|
||||
/// [`fonts_steady`] is held: the first lookup by family name catalogs the installed fonts, and
|
||||
/// resolving a cataloged family, or a character no loaded font has, loads a face. `step` runs up
|
||||
/// to 100 times, until [`vectorcraft_text::FontDb::generation`] is the same after a run as before
|
||||
/// it.
|
||||
/// to 100 times, until [`vectorcraft_text::layout_inputs`] is the same after a run as before it.
|
||||
pub(crate) fn with_fonts_unchanged<T>(mut step: impl FnMut() -> T) -> T {
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
for _ in 0..100 {
|
||||
let before = db.generation();
|
||||
let before = vectorcraft_text::layout_inputs();
|
||||
let out = step();
|
||||
if db.generation() == before {
|
||||
if vectorcraft_text::layout_inputs() == before {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -466,6 +464,75 @@ fn enveloped_type_under_effects_redraws_when_its_font_becomes_available() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hyphenated area type redraws with its new line breaks when Preferences › Hyphenation ›
|
||||
/// Exceptions change: its glyph geometry, the pixels of its raster effects, the art drawn for
|
||||
/// geometry effects, the art kept for a symbol instance and an envelope's evaluation are made
|
||||
/// again.
|
||||
#[test]
|
||||
fn hyphenated_type_redraws_when_the_exceptions_change() {
|
||||
let _adding = adding_fonts();
|
||||
struct Clear;
|
||||
impl Drop for Clear {
|
||||
fn drop(&mut self) {
|
||||
vectorcraft_text::set_hyphenation_exceptions("");
|
||||
}
|
||||
}
|
||||
let _clear = Clear;
|
||||
use vectorcraft_doc::Effect;
|
||||
let moved = || Effect { id: "distort.transform".into(), params: serde_json::json!({"moveH": 0.0}), visible: true };
|
||||
const WORDS: &str = "Extraordinarily comprehensive typographical considerations notwithstanding everything.";
|
||||
const NEVER: &str = "extraordinarily, comprehensive, typographical, considerations, notwithstanding";
|
||||
let cases = ["the area type", "the type with a drop shadow", "the group with a Transform effect", "the symbol instance", "the envelope"];
|
||||
for (i, what) in cases.into_iter().enumerate() {
|
||||
vectorcraft_text::set_hyphenation_exceptions("");
|
||||
let mut d = Document::new(300.0, 150.0);
|
||||
let mut t = TextObject::point(Point::ZERO, WORDS, CharStyle { size: 14.0, ..Default::default() });
|
||||
t.kind = TextKind::Area { frame: PathData::from_bezpath(&Rect::new(10.0, 10.0, 130.0, 145.0).to_path(0.1)) };
|
||||
t.xf = Affine::IDENTITY;
|
||||
t.para.hyphenate = true;
|
||||
let mut object = Node::new(d.alloc_id(), NodeKind::Text(Box::new(t)));
|
||||
match i {
|
||||
0 => {}
|
||||
1 => {
|
||||
let params = serde_json::json!({"x": 4, "y": 4, "blur": 1, "opacity": 100});
|
||||
object.appearance.effects.push(Effect { id: "stylize.dropShadow".into(), params, visible: true });
|
||||
}
|
||||
2 => {
|
||||
object = Node::group(d.alloc_id(), vec![Arc::new(object)]);
|
||||
object.appearance.effects.push(moved());
|
||||
}
|
||||
3 => {
|
||||
object.appearance.effects.push(moved());
|
||||
let art = Node::group(d.alloc_id(), vec![Arc::new(object)]);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { dynamic: false, name: "Words".into(), art: Arc::new(art) });
|
||||
object = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Words".into(), xf: Affine::IDENTITY });
|
||||
}
|
||||
_ => {
|
||||
let kind = vectorcraft_doc::EnvelopeKind::Warp { style: "arc".into(), bend: 30.0, h: 0.0, v: 0.0, horizontal: true, version: 0 };
|
||||
let envelope = NodeKind::Envelope {
|
||||
content: vec![Arc::new(object)],
|
||||
kind: Box::new(kind),
|
||||
fidelity: 50.0,
|
||||
editing: false,
|
||||
options: Default::default(),
|
||||
frame: Box::new(Affine::IDENTITY),
|
||||
};
|
||||
object = Node::new(d.alloc_id(), envelope);
|
||||
}
|
||||
}
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, object).unwrap();
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
let before = r.render(&d, 300, 150, Affine::IDENTITY, &opts).pixels;
|
||||
vectorcraft_text::set_hyphenation_exceptions(NEVER);
|
||||
let after = r.render(&d, 300, 150, Affine::IDENTITY, &opts).pixels;
|
||||
let fresh = Renderer::new().render(&d, 300, 150, Affine::IDENTITY, &opts).pixels;
|
||||
assert_ne!(before, fresh, "{what}: the words in the list are not broken");
|
||||
assert!(after == fresh, "{what}: drawn as a new renderer draws it");
|
||||
}
|
||||
}
|
||||
|
||||
/// Without an engine session, a renderer maps an envelope of type from its glyph outline bounds,
|
||||
/// and measures the type again when its font becomes available.
|
||||
#[test]
|
||||
|
||||
@@ -320,13 +320,13 @@ fn kept_glyphs(r: &mut Renderer, d: &Document) -> Vec<Option<Arc<TextGeom>>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `f`'s result from a run during which the fonts did not change: other tests add fonts, and the
|
||||
/// renderer lays all type out again when the fonts change.
|
||||
/// `f`'s result from a run during which the fonts and the hyphenation exceptions did not change:
|
||||
/// other tests change them, and the renderer lays all type out again when they change.
|
||||
fn fonts_unchanged<T>(mut f: impl FnMut() -> T) -> T {
|
||||
loop {
|
||||
let fonts = vectorcraft_text::FontDb::global().generation();
|
||||
let inputs = vectorcraft_text::layout_inputs();
|
||||
let t = f();
|
||||
if vectorcraft_text::FontDb::global().generation() == fonts {
|
||||
if vectorcraft_text::layout_inputs() == inputs {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -859,7 +859,7 @@ fn type_outside_its_frame_is_drawn() {
|
||||
fn a_pan_draws_the_type_from_the_kept_pixels() {
|
||||
let _fonts = crate::tests_fontchange::fonts_steady();
|
||||
let opts = RenderOptions::default();
|
||||
let fonts = || vectorcraft_text::FontDb::global().generation();
|
||||
let fonts = vectorcraft_text::layout_inputs;
|
||||
// How many type objects a renderer drew offscreen for `b` in `second` after drawing `a` in
|
||||
// `first`. The second frame's pixels are a new renderer's, each channel within `near`. The
|
||||
// frames are drawn again while the fonts change between them (other tests load fonts, and the
|
||||
|
||||
Reference in New Issue
Block a user