mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 20:43:18 -05:00
Text Wrap: Make's no-type warning checks the wrap objects without copying their shapes
Make Text Wrap called wrap_sources to learn whether a new wrap object sits above area type, which copied every wrap shape of every area text object in the document into text space and threw the copies away. wrap_source_objects gives the same text objects and wrap objects without making those copies, and Make uses it.
This commit is contained in:
1 parent
d1208efe17
commit
c683302d4e
4 files changed
+27
-2
No files matched your search
@@ -44,7 +44,7 @@ pub use tabs_lists::{
|
||||
Bullet, DEFAULT_TAB_INTERVAL, LIST_HANGING_INDENT, LIST_LEVEL_INDENT, LIST_LEVELS, ListAlign, ListCounts, MAX_LIST_START, NumberStyle, ParaList,
|
||||
TabAlign, TabStop,
|
||||
};
|
||||
pub use wrap::{resolve_wrap, wrap_copy_units, wrap_outline, wrap_sources, wrap_work};
|
||||
pub use wrap::{resolve_wrap, wrap_copy_units, wrap_outline, wrap_source_objects, wrap_sources, wrap_work};
|
||||
|
||||
/// A text object. `runs` split into paragraphs at `\n`.
|
||||
///
|
||||
|
||||
@@ -695,6 +695,15 @@ fn a_wrap_object_below_every_area_type_object_makes_no_outline() {
|
||||
});
|
||||
assert_eq!(sources, 1);
|
||||
assert_eq!(wrap::OUTLINES_MADE.with(|c| c.get()), 1, "only the wrap object above the type is outlined");
|
||||
// The objects alone come without a copy of any shape into text space.
|
||||
let mut found = vec![];
|
||||
wrap_source_objects(&d, |n, objects| found.push((n.id, objects.iter().map(|o| o.id).collect::<Vec<_>>())));
|
||||
let mut expected = vec![];
|
||||
wrap_sources(&d, |n, objects, _| expected.push((n.id, objects.iter().map(|o| o.id).collect::<Vec<_>>())));
|
||||
assert_eq!(found, expected);
|
||||
wrap::SHAPES_COPIED.with(|c| c.set(0));
|
||||
wrap_source_objects(&d, |_, _| {});
|
||||
assert_eq!(wrap::SHAPES_COPIED.with(|c| c.get()), 0, "no wrap shape is copied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -11,6 +11,8 @@ use crate::{Document, Node, NodeId, NodeKind};
|
||||
thread_local! {
|
||||
/// How many wrap outlines [`each_text`] has made on this thread (for tests).
|
||||
pub(super) static OUTLINES_MADE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// How many wrap shapes [`shapes_of`] has copied into text space on this thread (for tests).
|
||||
pub(super) static SHAPES_COPIED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// Outline of a wrap object in document coordinates: its paths, or its bounds for other art.
|
||||
@@ -167,6 +169,8 @@ fn shapes_of(t: &TextObject, above: &[(&Node, WrapShape)]) -> Vec<WrapShape> {
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|(_, s)| {
|
||||
#[cfg(test)]
|
||||
SHAPES_COPIED.with(|c| c.set(c.get() + 1));
|
||||
let mut path = s.path.clone();
|
||||
path.transform(inv);
|
||||
WrapShape { path, wrap: s.wrap }
|
||||
@@ -189,6 +193,18 @@ pub fn wrap_sources<'a>(doc: &'a Document, mut f: impl FnMut(&'a Node, Vec<&'a N
|
||||
}
|
||||
}
|
||||
|
||||
/// [`wrap_sources`] without the shapes: each area text object that gets wrap shapes, with the wrap
|
||||
/// objects whose outlines make them, bottom first. No shape is copied into text space.
|
||||
pub fn wrap_source_objects<'a>(doc: &'a Document, mut f: impl FnMut(&'a Node, Vec<&'a Node>)) {
|
||||
for layer in &doc.layers {
|
||||
each_text(layer, |n, above| {
|
||||
if matches!(n.kind, NodeKind::Text(_)) && !above.is_empty() {
|
||||
f(n, above.iter().rev().map(|(s, _)| *s).collect());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve the wrap shapes (`TextObject::wrap`, text space) of each area text object from the
|
||||
/// outlines of the wrap objects above it in its layer. With `before`, the layers it holds unchanged
|
||||
/// are skipped; without it, every layer is resolved. Returns the area text objects whose shapes
|
||||
|
||||
@@ -115,7 +115,7 @@ fn make(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let mut out = json!({ "ids": objects.iter().map(|i| i.0).collect::<Vec<_>>() });
|
||||
let mut wraps = false;
|
||||
vectorcraft_doc::text::wrap_sources(&s.doc()?.doc, |_, sources, _| wraps |= sources.iter().any(|n| objects.contains(&n.id)));
|
||||
vectorcraft_doc::text::wrap_source_objects(&s.doc()?.doc, |_, sources| wraps |= sources.iter().any(|n| objects.contains(&n.id)));
|
||||
if !wraps {
|
||||
out["warning"] = json!(NO_AREA_TYPE_BELOW);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user