Retype: stacked lines split from one compound path become one object

Lines that a compound path of several glyphs splits into share that
shape, so the check that one line's shape comes right after the last
line's never passed for them, and each line stayed an object of its own.
Two lines of one shape now follow each other, and the other joining
rules decide as for lines of separate shapes. The lines of the existing
paint-order test are moved farther apart so they still make two objects.
This commit is contained in:
dotCooCoo committed 2026-11-19 21:57:11 -08:00
1 parent 8483baf11f
commit 2fa3e32c83
3 files changed
+24 -5

No files matched your search

+3 -2
View File
@@ -999,7 +999,7 @@ fn share_tracking(lines: &mut [Line], system_layout: bool) {
/// `lines`, in paint order, as the objects Retype makes: runs of lines that stack as the lines of
/// one paragraph do become one object ([`Block`]). `follows(a, b)`: shape `b` comes right after
/// shape `a`, with nothing between them in paint order. `budget`: see [`Block::made`].
/// shape `a`, or is `a`, with nothing between them in paint order. `budget`: see [`Block::made`].
fn blocks(lines: Vec<Line>, follows: impl Fn(NodeId, NodeId) -> bool, system_layout: bool, budget: &mut usize) -> Vec<Made> {
let mut out = vec![];
let mut block: Option<Block> = None;
@@ -1489,8 +1489,9 @@ fn retype(s: &mut Session, p: &Value) -> Result<Value> {
let mut seen = std::collections::HashSet::new();
unmatched.retain(|id| !kept.contains(id) && seen.insert(*id));
let at: std::collections::HashMap<NodeId, usize> = pieces.iter().enumerate().map(|(i, pc)| (pc.id, i)).collect();
// Lines split from one compound path share its shape, with nothing between them.
let follows = |a: NodeId, b: NodeId| match (at.get(&a), at.get(&b)) {
(Some(i), Some(j)) => *j == i + 1 && pieces.get(*j).is_some_and(|pc| !pc.after_barrier),
(Some(i), Some(j)) => *j == *i || (*j == i + 1 && pieces.get(*j).is_some_and(|pc| !pc.after_barrier)),
_ => false,
};
// Joining lines takes at most four tries' work per glyph (see [`Block::made`]), with room
+20 -2
View File
@@ -1146,9 +1146,10 @@ fn a_lone_period_in_a_compound_selected_alone_stays_an_outline() {
#[test]
fn lines_from_one_compound_path_keep_their_order() {
let mut s = session();
// Two lines of outlines made into one compound path.
// Two lines of outlines made into one compound path, farther apart than the lines of one
// paragraph, so each stays an object of its own.
let top = outlined(&mut s, json!({"x": 40, "y": 100, "text": "Tim", "size": 40}));
let low = outlined(&mut s, json!({"x": 40, "y": 220, "text": "Ham", "size": 40}));
let low = outlined(&mut s, json!({"x": 40, "y": 300, "text": "Ham", "size": 40}));
let mut glyphs = children_of(&s, top);
glyphs.extend(children_of(&s, low));
s.execute("select.set", &json!({"ids": glyphs})).unwrap();
@@ -1166,6 +1167,23 @@ fn lines_from_one_compound_path_keep_their_order() {
assert!(at[first] < at[second], "{texts:?} at {at:?}");
}
#[test]
fn stacked_lines_from_one_compound_path_become_one_object() {
let mut s = session();
// Two lines of one paragraph, outlined and made into one compound path: they join as the
// lines of separate outlines do.
let text = "Tim\nHam";
let g = outlined(&mut s, json!({"x": 40, "y": 100, "text": text, "size": 40}));
let glyphs = children_of(&s, g);
s.execute("select.set", &json!({"ids": glyphs})).unwrap();
let c = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap();
s.execute("select.set", &json!({"ids": [c]})).unwrap();
let r = s.execute("type.retype", &json!({})).unwrap();
assert_eq!(r["texts"], json!([text]), "{r}");
assert_eq!(r["unmatched"], json!([]), "{r}");
assert!(s.doc().unwrap().doc.node(NodeId(c)).is_none(), "the compound becomes the type");
}
#[test]
fn a_compound_whose_parts_are_not_all_glyphs_stays_whole() {
let mut s = session();
+1 -1
View File
@@ -12526,7 +12526,7 @@ tracking their own gaps give. These rules are VectorCraft's own. Each entry of t
## Retype several lines
`type.retype` joins lines that follow each other in paint order, with the same group, paint, font, size, turn and
`type.retype` joins lines that follow each other in paint order (lines split from one compound path do), with the same group, paint, font, size, turn and
tracking (an untracked line of one or two glyphs takes the tracking of the others), into one type object when each
line's baseline is the same distance below the one before (between 0.25 and 3 times the size) and the lines line up at their starts, ends or centers. The object is area type with Convert To Area
Type's frame, its lines separated by line breaks, with left, right or center alignment, checked in that order. Its