Merge pull request #7715 from dotCooCoo/fix/svg-open-path-type-before-start

Type on a path: type on an open path can start before the path
This commit is contained in:
BFlat
2026-11-15 10:46:42 +07:00
committed by GitHub
35 changed files with 652 additions and 55 deletions
+1
View File
@@ -120,6 +120,7 @@ pub use style_libs::StyleLibrary;
pub use text::FontHeightReference;
pub use text::GlyphChoice;
pub use text::GlyphForm;
pub use text::PATH_LEAD_MAX;
pub use text::WarichuAlign;
pub use text::{
AreaFit, AreaOptions, Burasagari, CharAlign, CharPosition, CharStyle, Composer, Digits, FirstBaseline, HyphenationOptions, InlineArt,
+1
View File
@@ -29,6 +29,7 @@ pub use para_style::{
Burasagari, Composer, FirstBaseline, HyphenationOptions, JustificationOptions, Justify, Kashida, Kinsoku, KinsokuShoriType, LeadingModel,
Mojikumi, ParaDirection, ParaStyle, SingleWordJustify,
};
pub use runs::PATH_LEAD_MAX;
pub use runs::{INLINE_CHAR, INLINE_MAX_SCALE, InlineArt, RubyAlign, RubyPosition, RubySpan, TextKind, TextRun, TextStyleDef, TypeAntiAlias};
pub use tabs_lists::{
Bullet, DEFAULT_TAB_INTERVAL, LIST_HANGING_INDENT, LIST_LEVEL_INDENT, LIST_LEVELS, ListAlign, ListCounts, NumberStyle, ParaList, TabAlign,
+4 -1
View File
@@ -352,7 +352,10 @@ impl TextObject {
}
/// Flip type on a path to the other side of its path (Type on a Path Options › Flip, or its
/// centre bracket dragged across the path): the path runs the other way and the brackets swap
/// ends, so the type keeps its stretch of the path. False, changing nothing, for other type.
/// ends, so the type keeps its stretch of the path. Type that starts before an open path's start
/// ([`TextKind::path_text_start`]) starts at its start bracket after the flip: the part of its
/// span before the path's start would come after the path's end. False, changing nothing, for
/// other type.
pub fn flip_on_path(&mut self) -> bool {
let Some((s, e)) = self.kind.path_span() else { return false };
let TextKind::OnPath { path, start, end } = &mut self.kind else { return false };
+18 -2
View File
@@ -93,8 +93,10 @@ pub enum TextKind {
/// Area type flowed inside `frame` (document coordinates, untransformed by `xf`).
Area { frame: PathData },
/// Type on a path, flowing from its start bracket `start` to its end bracket `end` (0..1 of the
/// path length; no `end`: the end of the path, or once round a closed path). See
/// [`TextKind::path_span`].
/// path length; no `end`: the end of the path, or once round a closed path). On an open path
/// `start` may be below 0: the type starts that far before the path's start, and the characters
/// whose middle falls before the path's start are not drawn ([`TextKind::path_text_start`]).
/// See [`TextKind::path_span`].
OnPath {
path: PathData,
start: f64,
@@ -117,8 +119,22 @@ impl TextKind {
(s, end.map_or(1.0, |e| fraction(e).max(s)))
})
}
/// Where type on a path's text starts, as a fraction of its path's length: its start bracket
/// ([`Self::path_span`]), or on an open path a start before the path's start (below 0, at most
/// [`PATH_LEAD_MAX`] path lengths before it). None for other type.
pub fn path_text_start(&self) -> Option<f64> {
let TextKind::OnPath { path, start, .. } = self else { return None };
if !path.is_closed() && start.is_finite() && *start < 0.0 { Some(start.max(-PATH_LEAD_MAX)) } else { self.path_span().map(|(s, _)| s) }
}
/// Does type on an open path start before its path's start ([`Self::path_text_start`])?
pub fn starts_before_path(&self) -> bool {
self.path_text_start().is_some_and(|s| s < 0.0)
}
}
/// How far before its path's start type on an open path may start, in lengths of the path.
pub const PATH_LEAD_MAX: f64 = 1e6;
/// Move anchors `refs` of `path`, in text space, by `d` in document space (`to_text`: the
/// document → text map). False when an anchor doesn't exist.
pub(super) fn move_anchors(path: &mut PathData, to_text: Affine, refs: &[(usize, usize)], d: Vec2) -> bool {
+27
View File
@@ -563,6 +563,33 @@ fn area_anchors_move_in_document_space() {
assert_eq!(t, before);
}
/// Type on an open path may start before the path's start: the start is kept, saved and read back,
/// while the start bracket stays at the path's start. On a closed path, and for a start that is not
/// finite, the start is the start bracket as before.
#[test]
fn type_on_an_open_path_starts_before_the_path() {
let pts = [Point::new(0.0, 0.0), Point::new(100.0, 0.0), Point::new(100.0, 100.0)];
let on = |closed: bool, start: f64| TextKind::OnPath {
path: PathData::new(vec![vectorcraft_geom::SubPath::polyline(&pts, closed)]),
start,
end: None,
};
let open = on(false, -0.25);
assert_eq!(open.path_text_start(), Some(-0.25));
assert!(open.starts_before_path());
assert_eq!(open.path_span(), Some((0.0, 1.0)));
let saved = serde_json::to_value(&open).unwrap();
assert_eq!(saved["start"], -0.25);
assert_eq!(serde_json::from_value::<TextKind>(saved).unwrap(), open);
assert_eq!(on(false, -1e9).path_text_start(), Some(-PATH_LEAD_MAX));
assert_eq!(on(false, f64::NEG_INFINITY).path_text_start(), Some(0.0));
assert_eq!(on(false, 0.25).path_text_start(), Some(0.25));
assert!(!on(false, 0.0).starts_before_path());
assert_eq!(on(true, -0.25).path_text_start(), Some(0.0));
assert!(!on(true, -0.25).starts_before_path());
assert_eq!(TextKind::Point.path_text_start(), None);
}
/// Builds from before [`Justify::Auto`] read new type's alignment as Left or Right (and ignore
/// `justify_auto`); this build reads Auto back.
#[test]
+32 -8
View File
@@ -61,7 +61,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Release Type on a Path…",
["Object", "Plug-ins", "Type Tools"],
None,
"{mode?: \"both\" (point type and the path) | \"path\" (the path only) | \"text\" (point type only) (\"both\"), keepOriginal?: false (true: the type on a path stays and the released objects go just above it), ids?: [id…], id? (instead of ids; neither: the selection)} split each type on a path among the objects (inside groups too) into point type and the path it was set on. The point type holds the same text with the same character and paragraph attributes, on one straight line whose baseline starts where the first character sat on the path; Type on a Path Options (effect, align to path, spacing, flip, brackets) don't apply to point type and are dropped; type with Dynamic Text on (type.dynamicText) comes out with it off, at the sizes it was drawn at. The path keeps its exact shape (open or closed, anchors and handles, the object's transform) and comes out with no fill and no stroke, in the type's layer and place in the stacking order. Other objects are left alone, and with no type on a path among them nothing changes and no undo step is made. One undo step; the released objects are selected → {ids (released, bottom to top), paths, texts}",
"{mode?: \"both\" (point type and the path) | \"path\" (the path only) | \"text\" (point type only) (\"both\"), keepOriginal?: false (true: the type on a path stays and the released objects go just above it), ids?: [id…], id? (instead of ids; neither: the selection)} split each type on a path among the objects (inside groups too) into point type and the path it was set on. The point type holds the same text with the same character and paragraph attributes, on one straight line whose baseline starts where the first character sat on the path (when the type starts before an open path's start, the first character drawn on the path stays where it was drawn and the characters that were not drawn come before it); Type on a Path Options (effect, align to path, spacing, flip, brackets) don't apply to point type and are dropped; type with Dynamic Text on (type.dynamicText) comes out with it off, at the sizes it was drawn at. The path keeps its exact shape (open or closed, anchors and handles, the object's transform) and comes out with no fill and no stroke, in the type's layer and place in the stacking order. Other objects are left alone, and with no type on a path among them nothing changes and no undo step is made. One undo step; the released objects are selected → {ids (released, bottom to top), paths, texts}",
has_selection,
release_path
),
@@ -229,6 +229,28 @@ fn first_pen(lay: &vectorcraft_text::TextLayout) -> Option<Point> {
lay.glyphs.iter().filter(|g| g.origin.x.is_finite() && g.origin.y.is_finite()).min_by_key(|g| (g.byte, g.len != 0)).map(|g| g.origin)
}
/// A glyph of a character: its byte, whether it stands for characters (a list marker does not),
/// and its place among the glyphs of that byte and kind (an All Caps ß is two glyphs).
type GlyphKey = (usize, bool, usize);
/// The key and pen position of the first glyph drawn in `lay`, in text order: characters before an
/// open path's start are not drawn ([`vectorcraft_text::PositionedGlyph::off_path`]). None without
/// a drawn glyph.
fn first_drawn_pen(lay: &vectorcraft_text::TextLayout) -> Option<(GlyphKey, Point)> {
let (gi, g) = (lay.glyphs.iter().enumerate())
.filter(|(_, g)| !g.off_path && g.origin.x.is_finite() && g.origin.y.is_finite())
.min_by_key(|(gi, g)| (g.byte, g.len != 0, *gi))?;
let kind = g.len != 0;
let nth = lay.glyphs.iter().take(gi).filter(|h| h.byte == g.byte && (h.len != 0) == kind).count();
Some(((g.byte, kind, nth), g.origin))
}
/// The pen position of the glyph `key` names in `lay`. None without one.
fn pen_at(lay: &vectorcraft_text::TextLayout, (byte, kind, nth): GlyphKey) -> Option<Point> {
let g = lay.glyphs.iter().filter(|g| g.byte == byte && (g.len != 0) == kind).nth(nth)?;
(g.origin.x.is_finite() && g.origin.y.is_finite()).then_some(g.origin)
}
/// `t`, type on a path, as point type on one straight line: the same runs and character and
/// paragraph attributes, its baseline starting where its first character sat on the path (in the
/// object's own text space, so its transform stays). Type on a Path Options are dropped, and
@@ -237,13 +259,14 @@ fn first_pen(lay: &vectorcraft_text::TextLayout) -> Option<Point> {
fn released_text(t: &TextObject) -> Option<TextObject> {
let TextKind::OnPath { path, .. } = &t.kind else { return None };
let db = vectorcraft_text::FontDb::global();
// Where the first character sat. Text that didn't fit on the path has no glyph there: it
// starts at the start bracket.
let at = first_pen(&vectorcraft_text::layout(db, t)).or_else(|| {
// Where the first drawn character sat; characters before an open path's start come before it
// on the line. Text that didn't fit on the path has no glyph there: it starts at the start
// bracket.
let (key, at) = first_drawn_pen(&vectorcraft_text::layout(db, t)).map(|(b, p)| (Some(b), p)).or_else(|| {
let ap = ArcPath::new(path);
let (from, _) = t.kind.path_span()?;
let (p, _) = ap.at(from * ap.len());
(p.x.is_finite() && p.y.is_finite()).then_some(p)
(p.x.is_finite() && p.y.is_finite()).then_some((None, p))
})?;
let mut out = t.clone();
// Point type has no brackets to fit: it keeps the sizes the path drew it at.
@@ -254,9 +277,10 @@ fn released_text(t: &TextObject) -> Option<TextObject> {
out.path_spacing = 0.0;
// Point type is in no thread: its first paragraph starts in it.
out.first_para_continues = false;
// Where the point type puts its own first character; the origin moves so it lands at `at`,
// whatever the paragraph's alignment and direction.
let own = first_pen(&vectorcraft_text::layout(db, &out)).unwrap_or(Point::ZERO);
// Where the point type puts that glyph; the origin moves so it lands at `at`, whatever the
// paragraph's alignment and direction.
let own_lay = vectorcraft_text::layout(db, &out);
let own = key.and_then(|k| pen_at(&own_lay, k)).or_else(|| first_pen(&own_lay)).unwrap_or(Point::ZERO);
let shift = at - own;
if !(shift.x.is_finite() && shift.y.is_finite()) {
return None;
@@ -482,6 +482,44 @@ mod release {
}
}
/// Type that starts before its open path: the first drawn character stays where it was drawn,
/// and the characters that were not drawn come before it on the line.
#[test]
fn type_starting_before_its_open_path_keeps_its_drawn_characters_in_place() {
let mut s = session();
let id = path_type(&mut s, "M100 300 L500 300", [100.0, 300.0], "Hidden start");
s.execute("type.pathOptions", &json!({"start": -0.05})).unwrap();
let before = text(&s, id);
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &before);
let first = lay.glyphs.iter().filter(|g| !g.off_path).min_by_key(|g| g.byte).unwrap();
let (byte, drawn) = (first.byte, before.xf * first.origin);
assert!(byte > 0, "some characters are before the path");
s.execute(C, &json!({"mode": "text"})).unwrap();
let after = text(&s, id);
assert_eq!(after.kind, TextKind::Point);
assert_eq!(after.plain_text(), before.plain_text());
let back = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &after);
let same = back.glyphs.iter().find(|g| g.byte == byte).unwrap();
assert!(close(after.xf * same.origin, drawn), "{:?} vs {drawn:?}", after.xf * same.origin);
let lead = back.glyphs.iter().find(|g| g.byte == 0).unwrap();
assert!((after.xf * lead.origin).x < drawn.x, "the hidden characters come before it");
// An All Caps ß is two glyphs: with the first before the path's start, the second stays
// where it was drawn.
let id = path_type(&mut s, "M100 400 L500 400", [100.0, 400.0], "ße");
s.execute("text.setRangeStyle", &json!({"id": id.0, "start": 0, "end": 4, "allCaps": true})).unwrap();
let adv = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &text(&s, id)).glyphs[0].advance;
s.execute("type.pathOptions", &json!({"start": -1.2 * adv / 400.0})).unwrap();
let before = text(&s, id);
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &before);
assert!(lay.glyphs[0].byte == 0 && lay.glyphs[1].byte == 0 && lay.glyphs[0].off_path && !lay.glyphs[1].off_path);
let drawn = before.xf * lay.glyphs[1].origin;
s.execute(C, &json!({"mode": "text"})).unwrap();
let after = text(&s, id);
let back = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &after);
let second = back.glyphs.iter().filter(|g| g.byte == 0).nth(1).unwrap();
assert!(close(after.xf * second.origin, drawn), "{:?} vs {drawn:?}", after.xf * second.origin);
}
#[test]
fn flipped_type_releases_its_path_as_it_runs() {
let mut s = session();
+20 -7
View File
@@ -49,7 +49,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Touch Type",
[],
None,
"{id, start: byte (a character of it), dx?: pt, dy?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright)} change one character (a ligature, one glyph for several characters, as a whole) as a Touch Type tool drag does, as one undo step: dx moves it along its line in reading order by changing the kerning of the character before it on the line and its own kerning, and the characters after it stay where they are (an error for the first logical character of a line or at a reading-direction boundary; supported in either reading direction; limited to what kerning from -1000 to 10000 can give); dy raises it (baseline shift, up from its line whatever its rotation, also for the first character of a line and a right-to-left character); dx and dy are document points; hScale (including the object transform), vScale and rotation set its scales and rotation as text.setRangeStyle does. The kerning of the two characters also keeps the character and the ones after it where they were along the line when the font kerned them with their neighbors; a wider or narrower character moves the ones after it by the change in its width → {id, start, end} (the character's bytes)",
"{id, start: byte (a character of it), dx?: pt, dy?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright)} change one character (a ligature, one glyph for several characters, as a whole) as a Touch Type tool drag does, as one undo step: dx moves it along its line in reading order by changing the kerning of the character before it on the line and its own kerning, and the characters after it stay where they are (an error for the first logical character of a line or at a reading-direction boundary; supported in either reading direction; limited to what kerning from -1000 to 10000 can give); dy raises it (baseline shift, up from its line whatever its rotation, also for the first character of a line and a right-to-left character); dx and dy are document points; hScale (including the object transform), vScale and rotation set its scales and rotation as text.setRangeStyle does. The kerning of the two characters also keeps the character and the ones after it where they were along the line when the font kerned them with their neighbors; a wider or narrower character moves the ones after it by the change in its width. An error for a character of type on an open path that is not drawn because it falls before the path's start → {id, start, end} (the character's bytes)",
has_doc,
touch_type
),
@@ -1550,8 +1550,21 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
change.localize(&t, C)?;
let points = t.style_scale().ok_or_else(|| bad(C, "text transform is collapsed or unrepresentable"))?.points;
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &t);
let g = lay.glyphs.iter().find(|g| g.byte <= start && start < g.byte + g.len).ok_or_else(|| bad(C, format!("no character at byte {start}")))?;
let holds = |g: &&vectorcraft_text::PositionedGlyph| g.byte <= start && start < g.byte + g.len;
lay.glyphs.iter().find(holds).ok_or_else(|| bad(C, format!("no character at byte {start}")))?;
// A character before an open path's start is not drawn; one whose glyphs straddle the start
// is changed by its first drawn glyph.
let g = lay
.glyphs
.iter()
.filter(holds)
.find(|g| !g.off_path)
.ok_or_else(|| bad(C, format!("the character at byte {start} is not drawn: it falls before its path's start")))?;
let (a, b) = (g.byte, g.byte + g.len);
// The same glyph of the character in another layout of the type: its place among the glyphs
// of the character.
let nth = lay.glyphs.iter().filter(|h| h.byte == a && h.len > 0).position(|h| std::ptr::eq(h, g)).unwrap_or(0);
let same = |l: &vectorcraft_text::TextLayout| l.glyphs.iter().filter(|h| h.byte == a && h.len > 0).nth(nth).cloned();
// The line's direction in reading order.
let d = Vec2::new(g.angle.cos(), g.angle.sin());
let along = if g.rtl { -d } else { d };
@@ -1623,7 +1636,7 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
// rises, which would make its horizontal drift count as baseline movement.
touch(&mut trial, pr.map(|_| 0.0), Some(0.0), to - shift);
let l = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &trial);
l.glyphs.iter().find(|h| h.byte == a && h.len > 0).map(|h| h.xf * Point::ZERO)
same(&l).map(|h| h.xf * Point::ZERO)
};
let (per_step, across) = match (pen_at(from + step), pen_at(from + 2.0 * step)) {
(Some(p), Some(q)) => (linear(t.xf, q - p).hypot() / step.abs(), (q - p).dot(up) / step),
@@ -1653,7 +1666,7 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
touch(&mut trial, None, None, 0.0);
let l = vectorcraft_text::layout(db, &trial);
let intrinsic = |h: &vectorcraft_text::PositionedGlyph| h.xf * Point::ZERO - h.xf * h.pivot;
l.glyphs.iter().find(|h| h.byte == a && h.len > 0).map_or(Vec2::ZERO, |h| intrinsic(h) - intrinsic(g))
same(&l).map_or(Vec2::ZERO, |h| intrinsic(&h) - intrinsic(g))
} else {
Vec2::ZERO
};
@@ -1681,7 +1694,7 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
let mut trial = t.clone();
touch(&mut trial, k.0, k.1, raise);
let l = vectorcraft_text::layout(db, &trial);
let h = l.glyphs.iter().find(|h| h.byte == a && h.len > 0).ok_or_else(|| bad(C, "the character's size can't be measured"))?;
let h = same(&l).ok_or_else(|| bad(C, "the character's size can't be measured"))?;
let across_goal = (g.xf * Point::ZERO).to_vec2().dot(up) + dy / doc_len(up) + intrinsic_delta.dot(up);
raise += (across_goal - (h.xf * Point::ZERO).to_vec2().dot(up)) / baseline_step;
if !raise.is_finite() {
@@ -1695,7 +1708,7 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
let mut trial = t.clone();
touch(&mut trial, k.0, k.1, raise);
let l = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &trial);
let h = l.glyphs.iter().find(|h| h.byte == a && h.len > 0)?;
let h = same(&l)?;
let next = match (l.glyphs.iter().find(|n| n.byte == b && n.len > 0 && n.line == h.line), next_goal) {
(Some(n), Some(at)) => pen(n) - at,
_ => 0.0,
@@ -1704,7 +1717,7 @@ fn touch_type(s: &mut Session, p: &Value) -> Result<Value> {
(Some(n), Some(at)) => pen(n) - at,
_ => 0.0,
};
Some([pen(h) - goal, next, previous])
Some([pen(&h) - goal, next, previous])
};
let placed = |m: [f64; 3]| m.iter().all(|v| v.abs() <= 1e-9);
// A manual kerning value turns off the font's kerning for its character, each style run is
+17 -6
View File
@@ -57,7 +57,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Type on a Path Options…",
["Type", "Type on a Path"],
None,
"{ids?|id?, start?: 0..1, end?: 0..1|null, flip?: bool, effect?: rainbow|skew|3dRibbon|stairStep|gravity, alignToPath?: ascender|descender|center|baseline, spacing?: pt} set the selected type on a path's options: start and end place its start and end brackets as fractions of the path's length (end null: the end of the path, or once round a closed path), and flip then turns the type to the other side of its path (the path runs the other way, the brackets swap ends); alignToPath runs each character's em box top (ascender), font bounding box bottom (descender), half the height of its H's top above the baseline (center) or baseline along the path, by the character's own font, size and vertical scale (vertical type: half an em either way, or none for center); none given: query → the first object's {start, end, flip: false, effect, alignToPath, spacing}",
"{ids?|id?, start?: -1000000..1 (below 0 only on an open path), end?: 0..1|null, flip?: bool, effect?: rainbow|skew|3dRibbon|stairStep|gravity, alignToPath?: ascender|descender|center|baseline, spacing?: pt} set the selected type on a path's options: start and end place its start and end brackets as fractions of the path's length (end null: the end of the path, or once round a closed path); on an open path a start below 0 starts the text that far before the path's start, and the characters whose middle falls before it are not drawn (on a closed path it is the path's start), and flip then turns the type to the other side of its path (the path runs the other way, the brackets swap ends); alignToPath runs each character's em box top (ascender), font bounding box bottom (descender), half the height of its H's top above the baseline (center) or baseline along the path, by the character's own font, size and vertical scale (vertical type: half an em either way, or none for center); none given: query → the first object's {start, end, flip: false, effect, alignToPath, spacing}",
has_selection,
path_options
),
@@ -1018,7 +1018,18 @@ fn path_options(s: &mut Session, p: &Value) -> Result<Value> {
Some(v) => v.as_f64().filter(|x| x.is_finite()).map(|x| Some(x.clamp(0.0, 1.0))).ok_or_else(|| bad(C, format!("`{k}` is a number 0..1"))),
}
};
let start = fraction("start")?;
// On an open path the text may start before the path's start (below 0, see
// `TextKind::path_text_start`); on a closed path a start below 0 is the path's start.
let start = match p.get("start") {
None | Some(Value::Null) => None,
Some(v) => Some(
v.as_f64()
.filter(|x| x.is_finite())
.map(|x| x.clamp(-vectorcraft_doc::PATH_LEAD_MAX, 1.0))
.ok_or_else(|| bad(C, "`start` is a number up to 1 (below 0: before an open path's start)"))?,
),
};
let start_on = |path: &vectorcraft_geom::PathData, v: f64| if path.is_closed() { v.max(0.0) } else { v };
// `end: null` puts the end bracket back at the end of the path.
let end = p.get("end").map(|_| fraction("end")).transpose()?;
let flip = switch_or(p, "flip", false, C)?;
@@ -1037,8 +1048,8 @@ fn path_options(s: &mut Session, p: &Value) -> Result<Value> {
// Without a flip, when every object already has every value given, the document and its undo
// history stay as they are.
let has_values = |t: &TextObject| match &t.kind {
TextKind::OnPath { start: st, end: en, .. } => {
start.is_none_or(|v| v == *st)
TextKind::OnPath { path, start: st, end: en } => {
start.is_none_or(|v| start_on(path, v) == *st)
&& end.is_none_or(|v| v == *en)
&& effect.is_none_or(|e| t.path_effect == e)
&& align.is_none_or(|a| t.path_align == a)
@@ -1053,9 +1064,9 @@ fn path_options(s: &mut Session, p: &Value) -> Result<Value> {
s.edit("Type on a Path Options", |d, _| {
for id in &ids {
let Some(NodeKind::Text(t)) = d.node_mut(*id).map(|n| &mut n.kind) else { continue };
let TextKind::OnPath { start: st, end: en, .. } = &mut t.kind else { continue };
let TextKind::OnPath { path, start: st, end: en } = &mut t.kind else { continue };
if let Some(v) = start {
*st = v;
*st = start_on(path, v);
}
if let Some(v) = end {
*en = v;
+26
View File
@@ -127,6 +127,32 @@ fn options_keep_the_brackets() {
}
}
/// `start` below 0 starts type on an open path before the path's start, one undo step; on a closed
/// path it is the path's start, and a start that is not a number is an error.
#[test]
fn options_start_type_before_an_open_path() {
let mut s = session();
let id = on_line(&mut s);
let n = undo_len(&s);
let r = s.execute("type.pathOptions", &json!({"start": -0.25})).unwrap();
assert_eq!(brackets(&s, id), (-0.25, None));
assert!(near(r["start"].as_f64().unwrap(), -0.25), "{r}");
assert_eq!(undo_len(&s), n + 1);
// The same start again records nothing.
s.execute("type.pathOptions", &json!({"start": -0.25})).unwrap();
assert_eq!(undo_len(&s), n + 1);
// 100 pt before a 400 pt line: the 12 pt word is drawn nowhere.
let laid = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &text(&s, id));
assert!(!laid.glyphs.is_empty() && laid.glyphs.iter().all(|g| g.outline.elements().is_empty()));
assert!(s.execute("type.pathOptions", &json!({"start": "-0.5"})).is_err());
// A flip keeps the stretch from the path's start: the type then starts at the start bracket.
s.execute("type.pathOptions", &json!({"flip": true})).unwrap();
assert_eq!(brackets(&s, id), (0.0, None));
let ring = path_type(&mut s, "M100 100 L300 100 L300 300 L100 300 Z", [200.0, 90.0], "Ring");
s.execute("type.pathOptions", &json!({"ids": [ring.0], "start": -0.25})).unwrap();
assert_eq!(brackets(&s, ring).0, 0.0);
}
/// Type on a Path Options given the values the type has (OK in the dialog with nothing changed, the
/// effect it has from the Type on a Path menu, the end bracket at the end of the path, or the
/// query's own reply) records no undo step: the step to redo stays and the document stays
+38
View File
@@ -724,6 +724,44 @@ fn touch_type_moves_one_character_and_leaves_the_others_where_they_are() {
assert!(s.execute("text.touchType", &json!({"id": id.0, "start": (1u64 << 32) + 1, "dy": 1})).is_err(), "no character there");
}
/// Touch Type does not change a character of type on an open path that is not drawn because it
/// falls before the path's start; a drawn character of the same type still changes.
#[test]
fn touch_type_refuses_a_character_before_an_open_paths_start() {
let mut s = session();
let pid = s.execute("path.create", &json!({"d": "M100 300 L500 300"})).unwrap()["id"].as_u64().unwrap();
let r = s.execute("text.createInPath", &json!({"path": pid, "mode": "onPath", "text": "Hidden", "size": 12, "at": [100, 300]})).unwrap();
let id = NodeId(r["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
s.execute("type.pathOptions", &json!({"start": -0.02})).unwrap();
let steps = undo_labels(&s).len();
assert!(s.execute("text.touchType", &json!({"id": id.0, "start": 0, "dy": 2})).is_err(), "the H is not drawn");
assert_eq!(undo_labels(&s).len(), steps);
s.execute("text.touchType", &json!({"id": id.0, "start": 5, "dy": 2})).unwrap();
// An All Caps ß is two glyphs: with the first before the path's start and the second drawn, it
// still changes.
let pid = s.execute("path.create", &json!({"d": "M100 400 L500 400"})).unwrap()["id"].as_u64().unwrap();
let r = s.execute("text.createInPath", &json!({"path": pid, "mode": "onPath", "text": "ße", "size": 40, "at": [100, 400]})).unwrap();
let id = NodeId(r["id"].as_u64().unwrap());
s.execute("text.setRangeStyle", &json!({"id": id.0, "start": 0, "end": 4, "allCaps": true})).unwrap();
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
let adv = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &obj(&s, id)).glyphs[0].advance;
s.execute("type.pathOptions", &json!({"start": -1.2 * adv / 400.0})).unwrap();
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &obj(&s, id));
assert!(lay.glyphs[0].byte == 0 && lay.glyphs[1].byte == 0 && lay.glyphs[0].off_path && !lay.glyphs[1].off_path);
let drawn = |s: &Session| {
let t = obj(s, id);
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &t);
let g = lay.glyphs.iter().rfind(|g| g.byte == 0 && !g.off_path).unwrap();
t.xf * (g.xf * Point::ZERO)
};
let before = drawn(&s);
s.execute("text.touchType", &json!({"id": id.0, "start": 0, "dy": 2})).unwrap();
// The drawn glyph rises 2 points.
let after = drawn(&s);
assert!((after.x - before.x).abs() < 1e-6 && (after.y - (before.y - 2.0)).abs() < 1e-6, "{before:?} -> {after:?}");
}
/// Touch Type on the first character of a list item moves that character and leaves the bullet
/// where it is. The bullet stands for no character, so the first character still moves only up
/// and down.
+10
View File
@@ -5128,6 +5128,16 @@ fn a_first_baseline_minimum_and_a_path_end_the_reader_cant_read_are_reported() {
};
assert_eq!(with(on_path(Some(0.999))).0, [writer::TYPE_ATTRIBUTES]);
assert!(with(on_path(None)).0.is_empty());
// Type that starts before its open path comes back starting at the path's start.
let mut before = on_path(None);
if let TextKind::OnPath { start, .. } = &mut before.kind {
*start = -0.25;
}
let (warnings, back) = with(before);
assert_eq!(warnings, [writer::TYPE_ATTRIBUTES]);
let NodeKind::Text(t) = &back.layers[0].children().unwrap()[0].kind else { panic!("type") };
let TextKind::OnPath { start, .. } = t.kind else { panic!("type on a path") };
assert!(start.abs() < 1e-3, "{start}");
let (warnings, back) = with(on_path(Some(0.5)));
assert!(warnings.is_empty(), "{warnings:?}");
let NodeKind::Text(t) = &back.layers[0].children().unwrap()[0].kind else { panic!("type") };
+7 -1
View File
@@ -440,7 +440,13 @@ pub(in crate::ai_editing) fn loses(t: &TextObject) -> bool {
// The text document holds the Ascent first baseline by leaving it out, without a minimum.
|| (t.area.first_baseline == FirstBaseline::Ascent && t.area.first_baseline_min != 0.0)))
|| (matches!(t.kind, TextKind::OnPath { .. })
&& (t.path_effect != PathEffect::default() || t.path_align != PathAlign::default() || t.path_spacing != 0.0 || end_read_as_none(t)))
&& (t.path_effect != PathEffect::default()
|| t.path_align != PathAlign::default()
|| t.path_spacing != 0.0
|| end_read_as_none(t)
// The writer writes type that starts before its open path starting at the
// path's start.
|| t.kind.starts_before_path()))
}
/// Key 35 of a run in style `st`, as the reader's `Texts::style` reads it: 3 for Tate-chu-yoko, 1
+5 -1
View File
@@ -137,7 +137,11 @@ pub(super) fn lost_attributes(t: &TextObject) -> bool {
|| !t.fractional_widths
|| (matches!(t.kind, TextKind::Area { .. }) && t.area != AreaOptions::default())
|| (matches!(t.kind, TextKind::OnPath { .. })
&& (t.path_effect != PathEffect::default() || t.path_align != PathAlign::default() || t.path_spacing != 0.0 || end_bracket(t)))
&& (t.path_effect != PathEffect::default()
|| t.path_align != PathAlign::default()
|| t.path_spacing != 0.0
|| end_bracket(t)
|| t.kind.starts_before_path()))
|| several_paths(&t.kind)
}
+16
View File
@@ -1560,6 +1560,22 @@ fn type_on_a_path_alignment_and_end_bracket_are_warned_as_left_out() {
assert!(warned(&|t| t.kind = TextKind::OnPath { path: along(true), start: 0.7, end: Some(0.5) }));
// An open path's end bracket before its start bracket.
assert!(warned(&|t| t.kind = TextKind::OnPath { path: along(false), start: 0.5, end: Some(0.3) }));
// Type that starts before its open path: the text path holds a start on the path only.
assert!(warned(&|t| t.kind = TextKind::OnPath { path: along(false), start: -0.25, end: None }));
assert!(!warned(&|t| t.kind = TextKind::OnPath { path: along(false), start: 0.0, end: None }));
// It is written starting at the path's start: the same text object as a start of 0.
let written = |start: f64| {
let mut doc = Document::new(300.0, 200.0);
let layer = doc.layers[0].id;
let mut t = TextObject::point(vectorcraft_geom::Point::ZERO, "Along", style(12.0, Paint::solid(Color::BLACK)));
t.kind = TextKind::OnPath { path: along(false), start, end: None };
t.xf = Affine::IDENTITY;
let n = Node::new(doc.alloc_id(), NodeKind::Text(Box::new(t)));
doc.insert(Some(layer), usize::MAX, n).unwrap();
write(&doc).bytes
};
assert_eq!(written(-0.25), written(0.0));
assert_ne!(written(0.25), written(0.0));
let two = |first_closed: bool| {
let mut path = along(first_closed);
let pts = [(150.0, 100.0).into(), (250.0, 100.0).into()];
+2 -1
View File
@@ -246,7 +246,8 @@ impl Exporter<'_> {
// Spaces are written too (text extraction needs them); control characters and soft
// hyphens draw nothing.
let blank = g.outline.elements().is_empty() && !coloured;
if blank && !ch.is_some_and(|c| c.is_whitespace() && !c.is_control()) {
// Characters before the start of an open path are not drawn, spaces included.
if g.off_path || (blank && !ch.is_some_and(|c| c.is_whitespace() && !c.is_control())) {
continue;
}
// The glyph at the font size of its vertical scale: `frame` maps that size's glyph
+20
View File
@@ -304,6 +304,26 @@ fn real_text_lands_within_half_a_point_of_the_outlines() {
}
}
/// Type on an open path that starts before the path writes only the characters drawn on the path,
/// as text and as outlines.
#[test]
fn type_starting_before_its_open_path_writes_only_what_is_drawn() {
let mut line = BezPath::new();
line.move_to((20.0, 150.0));
line.line_to((380.0, 150.0));
let mut t = TextObject::point(Point::ZERO, "A C DEF", style(20.0));
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
t.xf = Affine::IDENTITY;
let laid = vectorcraft_text::layout(FontDb::global(), &t);
// Four glyphs, two of them spaces, and a little more before the start: "DEF" is drawn.
let lead: f64 = laid.glyphs.iter().take(4).map(|g| g.advance).sum::<f64>() + 1.0;
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -lead / 360.0, end: None };
let d = doc(vec![t]);
assert_eq!(texts(&import_as(&pdf(&d, false).bytes, TextAs::Text)).concat(), "DEF");
let outlined = ink(&import_as(&pdf(&d, true).bytes, TextAs::Outlines));
assert!(outlined.x0 > 20.0 - 1e-6, "{outlined:?}");
}
/// Area type 200 points wide holding `text`, its paragraphs in lists `lists`, with an 18 pt
/// hanging indent.
fn listed(text: &str, lists: &[Option<ParaList>]) -> TextObject {
+18
View File
@@ -117,6 +117,24 @@ fn variable_font_settings_are_not_highlighted_as_substituted_glyphs() {
assert!(g.alternate_glyphs(&t).elements().is_empty());
}
/// Type in a missing font that starts before its open path: only the characters drawn on the path
/// are highlighted as substituted.
#[test]
fn characters_before_an_open_path_are_not_highlighted() {
let _steady = fonts_steady();
let style = CharStyle { size: 20.0, font_family: "No Such Family 5932".into(), ..Default::default() };
let mut t = TextObject::point(Point::ZERO, "MMMM", style);
let mut line = vectorcraft_geom::BezPath::new();
line.move_to((0.0, 50.0));
line.line_to((500.0, 50.0));
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
let whole = text_geom(&t).substituted_fonts;
assert!(!whole.elements().is_empty());
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -0.9, end: None };
let g = text_geom(&t);
assert!(g.all.elements().is_empty() && g.substituted_fonts.elements().is_empty(), "{:?}", g.substituted_fonts);
}
/// Type in a composite font draws each class of character in its part's face, which is not a
/// substitute: Document Setup's highlight of substituted glyphs leaves it alone.
#[test]
+2 -1
View File
@@ -183,7 +183,8 @@ pub(crate) fn text_geom_snapped(t: &TextObject, snap: Option<Affine>) -> TextGeo
let (mut substituted_fonts, mut substituted_glyphs, mut alternate_candidates) = (BezPath::new(), BezPath::new(), vec![]);
let plain = t.plain_text();
let (mut images, mut colours) = (vec![], vec![]);
for g in &layout.glyphs {
// Glyphs before the start of an open path draw nothing and have no highlight cells.
for g in layout.glyphs.iter().filter(|g| !g.off_path) {
push(&mut all, g.run, &g.outline);
if let Some((image, xf)) = g.placed_image() {
images.push((g.run, image.clone(), xf));
+3
View File
@@ -571,6 +571,9 @@ impl Writer<'_> {
let base = self.char_props(&drawn.first_style(), space);
let mut props = base.clone();
let (from, to) = t.kind.path_span().unwrap_or((start, 1.0));
// Type on an open path may start before the path: a negative `startOffset`, and a reader
// does not draw the characters before the path's start, as the layout does not.
let from = t.kind.path_text_start().unwrap_or(from);
// The anchor sits where the layout aligns the line within its span.
let at = match t.para_at(0).justify {
Justify::Center | Justify::JustifyCenter => {
+13 -3
View File
@@ -1473,16 +1473,26 @@ impl Ctx {
let offset = tp.attribute("startOffset").and_then(|v| self.length(v, em, len)).unwrap_or(0.0) + dx[0];
let width = if anchor > 0.0 { advance(&point_text(&cells)) } else { 0.0 };
// On a path of one closed subpath, text that starts before the path's start or past its
// end wraps around the path. Otherwise it starts at the path's start or end.
// end wraps around the path. On an open path text may start before the path's start,
// and its characters before the start are not drawn; text that starts past the end
// starts at the end. Other paths start it at the path's start or end.
let path = PathData::from_bezpath(&bp);
let wraps = path.subpaths.len() == 1 && path.is_closed();
let open = !path.is_closed();
let wrap = |s: f64| {
// `rem_euclid` can round a tiny negative value up to 1.
let s = s.rem_euclid(1.0);
if s < 1.0 { s } else { 0.0 }
};
let start =
Some((offset - anchor * width) / len).filter(|s| s.is_finite()).map_or(0.0, |s| if wraps { wrap(s) } else { s.clamp(0.0, 1.0) });
let start = Some((offset - anchor * width) / len).filter(|s| s.is_finite()).map_or(0.0, |s| {
if wraps {
wrap(s)
} else if open {
s.clamp(-vectorcraft_doc::PATH_LEAD_MAX, 1.0)
} else {
s.clamp(0.0, 1.0)
}
});
obj.kind = TextKind::OnPath { path, start, end: None };
obj.xf = Affine::IDENTITY;
} else if vertical {
+51 -3
View File
@@ -335,10 +335,12 @@ fn text_on_a_closed_path_wraps_past_the_path_start() {
// A negative startOffset, in user units or as a percentage, counts back from the path's end.
assert!(close(start_of(t[4]), 0.9, 1e-9), "{}", start_of(t[4]));
assert!(close(start_of(t[5]), 0.9, 1e-9), "{}", start_of(t[5]));
// A path of two closed subpaths, and an open path, do not wrap: the text starts at the path's
// start or end.
// A path of two closed subpaths does not wrap: the text starts at the path's start. An open
// path does not wrap either: text anchored before its start starts there
// (`text_on_an_open_path_starts_before_the_path`), and text offset past its end starts at
// its end.
assert_eq!(start_of(t[6]), 0.0);
assert_eq!(start_of(t[7]), 0.0);
assert!(close(start_of(t[7]), -width / 300.0, 1e-6), "{} {width}", start_of(t[7]));
assert_eq!(start_of(t[8]), 1.0);
// Laid out, the end-anchored text draws every glyph up the left side and ends at the start
@@ -372,6 +374,52 @@ fn text_on_a_closed_path_wraps_past_the_path_start() {
assert!(lay.glyphs.iter().enumerate().all(|(i, g)| g.byte == i), "{:?}", lay.glyphs.iter().map(|g| g.byte).collect::<Vec<_>>());
}
#[test]
fn text_on_an_open_path_starts_before_the_path() {
// An open path 300 long. Text anchored, or offset, before its start starts that far before it,
// and only the characters whose middle is on the path are drawn; the text keeps every character.
let d = open(
r##"<path id="o" d="M50 50 H150 V150 H50" fill="none" stroke="black"/>
<text font-size="20" text-anchor="end"><textPath href="#o">Wave</textPath></text>
<text font-size="20" text-anchor="middle"><textPath href="#o">Wave</textPath></text>
<text font-size="20"><textPath href="#o" startOffset="-20%">Wave</textPath></text>
<text font-size="20"><textPath href="#o">Wave</textPath></text>"##,
);
let t = texts(&d);
assert_eq!(t.len(), 4);
let start_of = |t: &TextObject| match t.kind {
TextKind::OnPath { start, .. } => start,
_ => panic!("{:?}", t.kind),
};
let whole = layout(FontDb::global(), t[3]);
let width: f64 = whole.glyphs.iter().map(|g| g.advance).sum();
assert!(width > 0.0 && width < 60.0, "{width}");
assert!(close(start_of(t[0]), -width / 300.0, 1e-6), "{} {width}", start_of(t[0]));
assert!(close(start_of(t[1]), -width / 600.0, 1e-6), "{} {width}", start_of(t[1]));
assert!(close(start_of(t[2]), -0.2, 1e-9), "{}", start_of(t[2]));
let drawn = |t: &TextObject| {
let lay = layout(FontDb::global(), t);
assert!(!lay.overflow && lay.glyphs.len() == 4, "{} {}", lay.overflow, lay.glyphs.len());
assert_eq!(t.plain_text(), "Wave");
lay.glyphs.iter().map(|g| !g.outline.elements().is_empty()).collect::<Vec<_>>()
};
// Ending at the path's start: nothing is drawn.
assert_eq!(drawn(t[0]), [false; 4]);
// Centered on the path's start: the characters whose middle is past the start are drawn, the
// last ones of the text.
// (A hidden glyph has no advance: the advances are the ones the text takes on the path.)
let middle = drawn(t[1]);
let mut x = -width / 2.0;
for (g, shown) in whole.glyphs.iter().zip(&middle) {
assert_eq!(*shown, x + g.advance / 2.0 >= 0.0, "{x} {middle:?}");
x += g.advance;
}
assert!(middle.iter().any(|d| *d) && !middle[0] && middle[3], "{middle:?}");
// 60 before the start, more than the text's width: nothing is drawn.
assert_eq!(drawn(t[2]), [false; 4]);
assert_eq!(drawn(t[3]), [true; 4]);
}
/// The unit vector along a glyph's baseline.
fn baseline_dir(angle: f64) -> vectorcraft_geom::Vec2 {
vectorcraft_geom::Vec2::new(angle.cos(), angle.sin())
+25
View File
@@ -478,6 +478,31 @@ fn aligned_text_on_path_anchors_within_its_span() {
}
}
/// Type on an open path that starts before the path is written with a negative `startOffset` and
/// reads back starting there, with the same characters drawn.
#[test]
fn text_on_an_open_path_starting_before_it_round_trips() {
let mut line = vectorcraft_geom::BezPath::new();
line.move_to((0.0, 100.0));
line.line_to((200.0, 100.0));
let mut d = Document::new(200.0, 200.0);
let mut t = TextObject::point(Point::ZERO, "Before", CharStyle { size: 14.0, ..CharStyle::default() });
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -0.1, end: None };
let shown = |t: &TextObject| {
vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).glyphs.iter().map(|g| !g.outline.elements().is_empty()).collect::<Vec<_>>()
};
let before = shown(&t);
assert!(before.contains(&true) && before.contains(&false), "{before:?}");
let id = d.alloc_id();
let svg = export(&doc_with(vec![Node::new(id, NodeKind::Text(Box::new(t)))]), &ExportOptions::default());
assert!(svg.contains("startOffset=\"-10%\""), "{svg}");
let r = import(&svg).unwrap();
let NodeKind::Text(t) = &art(&r)[0].kind else { panic!() };
let TextKind::OnPath { start, .. } = &t.kind else { panic!("not type on a path: {:?}", t.kind) };
assert!((start + 0.1).abs() < 1e-6, "start {start}");
assert_eq!(shown(t), before);
}
/// An end bracket, Align to Path or Spacing, which `<textPath>` can't express, keep their look as
/// outlines (#429).
#[test]
+1
View File
@@ -626,6 +626,7 @@ impl Ctx<'_> {
width_start,
warichu: g.wari.map(|w| w.start),
warichu_line: g.wari.map_or(0.0, |w| w.across),
off_path: false,
});
}
+38 -2
View File
@@ -380,6 +380,35 @@ pub(crate) fn layout_trying_each_start(db: &crate::fontdb::FontDb, t: &TextObjec
l
}
/// For type that starts before its open path `ap` (`lead`), a glyph whose middle is `mid` along the
/// path and falls before the path's start is not drawn, as SVG 2 lays out text on a path
/// (https://www.w3.org/TR/SVG2/text.html#TextLayoutPath): glyph `at` keeps its place in the layout
/// for the caret, with no length at the path's start (moved off the path by `rise`, as Align to Path
/// moves the glyph), and draws nothing ([`crate::PositionedGlyph::off_path`]). True when it is hidden.
fn hide_before_open_path(cx: &mut Ctx<'_>, ap: &ArcPath, lead: bool, at: usize, mid: f64, rise: f64) -> bool {
if !lead || ap.is_closed() || mid >= 0.0 {
return false;
}
let (p, dir) = ap.at(0.0);
let start = p + Vec2::new(-dir.y, dir.x) * rise;
if let Some(glyph) = cx.out.glyphs.get_mut(at) {
glyph.origin = start;
glyph.advance = 0.0;
glyph.width = 0.0;
glyph.width_start = 0.0;
glyph.outline = BezPath::new();
glyph.image = None;
glyph.colour = None;
// A ligature's caret stops stay, at the path's start with the glyph.
for c in &mut glyph.carets {
c.1 = 0.0;
}
glyph.off_path = true;
}
cx.out.inlines.retain(|i| i.glyph != at);
true
}
/// Lay type on a path out along `path` (text space), between its brackets.
pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject, path: &PathData) {
cx.out.on_path = true;
@@ -453,6 +482,11 @@ pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject,
}
let centre = path.bounds().unwrap_or_default().center();
let (from, to) = t.kind.path_span().unwrap_or((0.0, 1.0));
// On an open path the text may start before the path's start: the span runs from there, so
// Dynamic Text fills it to the end bracket, and the drawn text runs from the path's start to the
// end bracket.
let from = t.kind.path_text_start().unwrap_or(from);
let lead = t.kind.starts_before_path();
let s_start = from * ap.len();
let avail = (to - from) * ap.len();
let spacing = if t.path_spacing.is_finite() { t.path_spacing } else { 0.0 };
@@ -491,7 +525,7 @@ pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject,
}
}
} else {
(l.min(s_start), r.min((ap.len() - s_start - avail).max(0.0)))
(l.min(s_start.max(0.0)), r.min((ap.len() - s_start - avail).max(0.0)))
};
(l, r, hung_r)
};
@@ -673,10 +707,12 @@ pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject,
m.tab = at;
}
}
let at = cx.out.glyphs.len();
cx.emit(g, pre, origin, angle, g.adv, 0);
let hidden = hide_before_open_path(cx, &ap, lead, at, s + step * 0.5, rise);
// A glyph of a script whose letters join is bent along a curved path (Rainbow), so its
// joining strokes meet its neighbours' instead of standing off the curve.
if t.path_effect == PathEffect::Rainbow && g.cursive && !cx.vertical && g.inline.is_none() {
if !hidden && t.path_effect == PathEffect::Rainbow && g.cursive && !cx.vertical && g.inline.is_none() {
let bend = GlyphBend { s, step, advance: g.adv, rise };
if let Some(last) = cx.out.glyphs.last_mut()
&& last.image.is_none()
+1
View File
@@ -379,5 +379,6 @@ fn ruby_glyph(g: &PositionedGlyph, m: Affine, run: usize, byte: usize, line: usi
width_start: 0.0,
warichu: None,
warichu_line: 0.0,
off_path: false,
}
}
+13 -3
View File
@@ -188,6 +188,12 @@ pub struct PositionedGlyph {
/// line's baseline before Character Alignment moves the glyph (y down). It names the block
/// line whatever the alignment of each character on it. 0 for any other glyph.
pub warichu_line: f64,
/// Type on an open path that starts before the path: the glyph's middle falls before the
/// path's start, so it draws nothing (its `outline` is empty and it has no image or color
/// art), hit testing and Touch Type skip it while a glyph is drawn, and exports leave it out.
/// It stays in the layout for the caret, at the path's start with no advance or width, and its
/// ligature carets stand there too.
pub off_path: bool,
}
/// How a glyph on a path is bent along it: a point of its pen space (x along its advance from its
@@ -600,11 +606,15 @@ pub fn hit_byte(layout: &TextLayout, p: Point) -> usize {
.map(|(_, d)| (p - (g.origin + along * if g.rtl { g.advance - d } else { d })).hypot2())
.fold(mid, f64::min)
};
let best = layout.glyphs.iter().enumerate().min_by(|(_, a), (_, b)| near(a).total_cmp(&near(b)));
// Glyphs before the start of an open path draw nothing: a click goes to a drawn one when
// there is one.
let drawn = layout.glyphs.iter().any(|g| !g.off_path);
let best = layout.glyphs.iter().enumerate().filter(|(_, g)| !(drawn && g.off_path)).min_by(|(_, a), (_, b)| near(a).total_cmp(&near(b)));
let Some((i, g)) = best else { return layout.lines.first().map_or(0, |l| l.start) };
// `first` and `last` are the first and last glyphs of the cluster. A click before the middle of
// the cluster, measured along the first glyph's direction, goes to the cluster's start.
let same = |o: &&PositionedGlyph| o.byte == g.byte && o.len == g.len;
// the cluster, measured along the first glyph's direction, goes to the cluster's start. A
// cluster's glyphs before an open path's start are left out when one of its glyphs is drawn.
let same = |o: &&PositionedGlyph| o.byte == g.byte && o.len == g.len && !(drawn && o.off_path);
let first = layout.glyphs[..=i].iter().rev().take_while(same).last().unwrap_or(g);
let last = layout.glyphs[i..].iter().take_while(same).last().unwrap_or(g);
let along = dir(first.angle);
+79
View File
@@ -635,6 +635,85 @@ fn on_path_placement() {
assert_eq!(hit_byte(&l, mid), 1);
}
/// Type on an open path that starts before the path's start draws only the glyphs whose middle is
/// on the path; the others stay in the layout, drawing nothing. On a closed path a start below 0 is
/// the path's start, as before.
#[test]
fn on_path_open_start_before_the_path_hides_the_glyphs_before_it() {
let mut line = BezPath::new();
line.move_to((0.0, 50.0));
line.line_to((500.0, 50.0));
let mut t = point("MMMM", style(20.0));
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
let whole = layout(db(), &t);
let adv = whole.glyphs[0].advance;
assert!(adv > 1.0 && whole.glyphs.iter().all(|g| !g.outline.elements().is_empty()));
// 2.4 glyphs before the start: the first two are before it, and the third's middle is just past
// the path's start, so it is drawn.
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -2.4 * adv / 500.0, end: None };
let l = layout(db(), &t);
assert!(l.on_path && !l.overflow);
assert_eq!(l.glyphs.len(), 4);
let drawn: Vec<bool> = l.glyphs.iter().map(|g| !g.outline.elements().is_empty()).collect();
assert_eq!(drawn, [false, false, true, true]);
assert_eq!(l.glyphs.iter().map(|g| g.off_path).collect::<Vec<_>>(), [true, true, false, false]);
assert!(l.glyphs[..2].iter().all(|g| g.carets.iter().all(|c| c.1 == 0.0) && g.advance == 0.0 && g.width == 0.0));
assert!(whole.glyphs.iter().all(|g| !g.off_path));
// Type that starts on the path keeps drawing every glyph, even where negative tracking steps
// its glyphs back before the path's start.
let mut packed = t.clone();
packed.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
packed.runs[0].style.tracking = -1000.0;
let p = layout(db(), &packed);
assert!(p.glyphs.len() == 4 && p.glyphs.iter().all(|g| !g.off_path && !g.outline.elements().is_empty()));
assert!((l.glyphs[2].origin.x + 0.4 * adv).abs() < 1e-6, "{:?}", l.glyphs[2].origin);
assert!((l.glyphs[3].origin.x - 0.6 * adv).abs() < 1e-6, "{:?}", l.glyphs[3].origin);
assert_eq!(l.lines[0].end, 4);
// A click at the path's start goes before the first drawn character, not into a hidden one, and
// the caret in the hidden characters stands at the path's start.
assert_eq!(hit_byte(&l, Point::new(0.0, 50.0)), 2);
for b in [0, 1] {
let (top, bottom) = caret_position(&l, b);
assert!(top.x.abs() < 1e-6 && bottom.x.abs() < 1e-6, "{b}: {top:?} {bottom:?}");
}
// An All Caps ß is two glyphs. With the first before the path's start, a click is measured
// against the drawn one: just past its middle, the caret goes after the character.
let mut caps = point("ße", style(20.0));
caps.runs[0].style.all_caps = true;
caps.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
let s = layout(db(), &caps).glyphs[0].advance;
caps.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -1.2 * s / 500.0, end: None };
let c = layout(db(), &caps);
assert!(c.glyphs[0].byte == 0 && c.glyphs[1].byte == 0 && c.glyphs[0].off_path && !c.glyphs[1].off_path);
let mid = c.glyphs[1].origin.x + c.glyphs[1].advance / 2.0;
assert_eq!(hit_byte(&c, Point::new(mid + 0.05 * s, 50.0)), 2);
assert_eq!(hit_byte(&c, Point::new(mid - 0.05 * s, 50.0)), 0);
// With Align to Path, the hidden characters' caret is moved off the path as the drawn ones are.
let mut aligned = t.clone();
aligned.path_align = vectorcraft_doc::PathAlign::Ascender;
let a = layout(db(), &aligned);
let rise = a.glyphs[2].origin.y - 50.0;
assert!(rise.abs() > 1.0, "{rise}");
for g in &a.glyphs[..2] {
assert!(g.off_path && g.origin.x.abs() < 1e-6 && (g.origin.y - 50.0 - rise).abs() < 1e-6, "{:?}", g.origin);
}
// The whole text before the path: nothing is drawn, and nothing overflows.
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: -0.9, end: None };
let l = layout(db(), &t);
assert!(!l.overflow && l.glyphs.len() == 4 && l.glyphs.iter().all(|g| g.outline.elements().is_empty()));
// A closed path starts the text at the path's start.
let mut square = BezPath::new();
square.move_to((0.0, 0.0));
square.line_to((200.0, 0.0));
square.line_to((200.0, 200.0));
square.line_to((0.0, 200.0));
square.close_path();
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&square), start: -0.1, end: None };
let l = layout(db(), &t);
assert!(l.glyphs.iter().all(|g| !g.outline.elements().is_empty()));
assert!(l.glyphs[0].origin.x.abs() < 1e-6 && l.glyphs[0].origin.y.abs() < 1e-6, "{:?}", l.glyphs[0].origin);
}
#[test]
fn on_path_effects_orient_glyphs() {
use vectorcraft_doc::PathEffect;
+1
View File
@@ -170,6 +170,7 @@ fn lines_of_clusters(lines: &[&[(usize, usize, f64)]], rtl: bool) -> TextLayout
width_start: 0.0,
warichu: None,
warichu_line: 0.0,
off_path: false,
});
x += advance;
}
+1
View File
@@ -649,6 +649,7 @@ fn duplicate_authored_glyphs_keep_occurrence_order() {
width_start: 0.0,
warichu: None,
warichu_line: 0.0,
off_path: false,
};
let before = TextLayout { glyphs: vec![glyph(0), glyph(1)], ..TextLayout::default() };
assert_eq!(assert_kashida_ownership(&text, &before, &before, &red(), "duplicate glyphs", false), 0);
+41 -2
View File
@@ -59,6 +59,8 @@ pub struct Brackets {
arc: ArcPath,
/// [`TextKind::path_span`].
span: (f64, f64),
/// [`TextKind::path_text_start`]: below 0 when the type starts before an open path's start.
text_start: f64,
/// The end bracket was placed (not the end of the path, or once round it).
end_set: bool,
}
@@ -78,7 +80,9 @@ impl Brackets {
if !det.is_finite() || det.abs() < 1e-12 || arc.is_empty() {
return None;
}
Some(Self { id, xf: t.xf, arc, span: t.kind.path_span()?, end_set: end.is_some() })
let span = t.kind.path_span()?;
let text_start = t.kind.path_text_start().unwrap_or(span.0);
Some(Self { id, xf: t.xf, arc, span, text_start, end_set: end.is_some() })
}
/// Where bracket `b` stands, as a fraction of the path's length (past 1 round a closed path).
@@ -269,7 +273,13 @@ impl BracketDrag {
d -= d.round();
}
let place = |x: f64| if closed { x.rem_euclid(1.0) } else { x.clamp(0.0, 1.0) };
let start = place(s + d);
// Type that starts before an open path's start slides from there, and goes no
// further before the path than it was: both brackets stay where they are.
let lead = !closed && b.text_start < 0.0;
if lead {
d = d.max(0.0);
}
let start = if lead { (b.text_start + d).min(1.0) } else { place(s + d) };
m.insert("start".into(), json!(start));
if b.end_set {
m.insert("end".into(), json!(if closed { place(e + d) } else { place(e + d).max(start) }));
@@ -409,6 +419,35 @@ mod tests {
assert!(v.get("flip").is_none(), "{v}");
}
/// Type that starts before its open path slides from where it starts, not from the path's start.
#[test]
fn dragging_the_center_bracket_slides_type_that_starts_before_the_path() {
let (mut d, id) = doc_with_path_type();
if let Some(vectorcraft_doc::NodeKind::Text(t)) = d.node_mut(id).map(|n| &mut n.kind)
&& let TextKind::OnPath { start, .. } = &mut t.kind
{
*start = -0.25;
}
let s = selected(id);
let p = paint();
let cx = cx(&d, &s, &p);
// The center bracket stands in the middle of the brackets (the start bracket at the path's start).
let v = preview(&drag(&cx, Point::new(250.0, 295.0), Point::new(280.0, 295.0), Mods::default())).clone();
assert!((v["start"].as_f64().unwrap() + 0.15).abs() < 1e-6, "{v}");
// Back past where it started: it stays there, and so does a placed end bracket.
let v = preview(&drag(&cx, Point::new(250.0, 295.0), Point::new(150.0, 295.0), Mods::default())).clone();
assert!((v["start"].as_f64().unwrap() + 0.25).abs() < 1e-6, "{v}");
if let Some(NodeKind::Text(t)) = d.node_mut(id).map(|n| &mut n.kind)
&& let TextKind::OnPath { end, .. } = &mut t.kind
{
*end = Some(0.5);
}
let ended = crate::testutil::cx(&d, &s, &p);
// The center bracket stands at 0.25 of the path, between the start bracket (0) and the end.
let v = preview(&drag(&ended, Point::new(175.0, 295.0), Point::new(130.0, 295.0), Mods::default())).clone();
assert!((v["start"].as_f64().unwrap() + 0.25).abs() < 1e-6 && (v["end"].as_f64().unwrap() - 0.5).abs() < 1e-6, "{v}");
}
#[test]
fn dragging_the_start_and_end_brackets_moves_them() {
let (d, id) = doc_with_path_type();
+8 -5
View File
@@ -150,7 +150,7 @@ fn is_inline(lay: &TextLayout, gi: usize) -> bool {
/// inline graphics, glyphs whose font is gone and type whose transform is collapsed.
fn char_box(t: &TextObject, lay: &TextLayout, gi: usize) -> Option<CharBox> {
let g: &PositionedGlyph = lay.glyphs.get(gi)?;
if is_inline(lay, gi) {
if is_inline(lay, gi) || g.off_path {
return None;
}
let m = g.xf;
@@ -161,7 +161,7 @@ fn char_box(t: &TextObject, lay: &TextLayout, gi: usize) -> Option<CharBox> {
let corners: Vec<Point> = lay
.glyphs
.iter()
.filter(|h| h.byte == g.byte && h.len > 0 && h.line == g.line)
.filter(|h| h.byte == g.byte && h.len > 0 && h.line == g.line && !h.off_path)
.filter_map(glyph_quad)
.flatten()
.map(|p| to_glyph * p)
@@ -218,7 +218,8 @@ impl TouchTypeTool {
let selected = std::iter::successors(Some(id), |c| cx.doc.parent_of(*c)).any(|c| cx.selection.contains(c));
let t = text_of(cx, id).filter(|_| selected)?;
let lay = self.layout(t);
let gi = lay.glyphs.iter().position(|g| g.byte <= start && start < g.byte + g.len)?;
// The character's first drawn glyph: glyphs before an open path's start are not drawn.
let gi = lay.glyphs.iter().position(|g| g.byte <= start && start < g.byte + g.len && !g.off_path)?;
Some((id, t, char_box(t, &lay, gi)?))
}
@@ -230,7 +231,7 @@ impl TouchTypeTool {
let lay = self.layout(t);
let local = t.xf.inverse() * p;
let boxes: Vec<(usize, [Point; 4])> = (lay.glyphs.iter().enumerate())
.filter(|(gi, g)| g.len > 0 && !is_inline(&lay, *gi))
.filter(|(gi, g)| g.len > 0 && !g.off_path && !is_inline(&lay, *gi))
.filter_map(|(_, g)| Some((g.byte, glyph_quad(g)?)))
.collect();
let center = |q: &[Point; 4]| q[0].midpoint(q[2]);
@@ -360,7 +361,9 @@ impl Tool for TouchTypeTool {
let Some(t) = text_of(cx, id) else { return out };
let lay = self.layout(t);
let start = self.target.map_or(0, |(_, s)| s);
let Some(b) = lay.glyphs.iter().position(|g| g.byte == start && g.len > 0).and_then(|gi| char_box(t, &lay, gi)) else {
// The character's first drawn glyph: glyphs before an open path's start are not drawn.
let first = lay.glyphs.iter().position(|g| g.byte == start && g.len > 0 && !g.off_path);
let Some(b) = first.and_then(|gi| char_box(t, &lay, gi)) else {
return out;
};
(Part::Move, b)
+54
View File
@@ -388,6 +388,60 @@ fn the_box_of_a_character_drawn_with_two_glyphs_holds_both() {
}
}
/// A character of type on an open path that is not drawn, because it falls before the path's
/// start, has no box, so the tool shows no handles for it; a drawn character of the same type has
/// one.
#[test]
fn a_character_before_an_open_paths_start_has_no_box() {
let mut d = Document::new(600.0, 500.0);
let l = d.layers[0].id;
let id = d.alloc_id();
let mut text = TextObject::point(Point::ZERO, "Type", CharStyle { size: 40.0, ..Default::default() });
let line =
vectorcraft_geom::PathData::new(vec![vectorcraft_geom::SubPath::polyline(&[Point::new(100.0, 200.0), Point::new(500.0, 200.0)], false)]);
text.kind = vectorcraft_doc::TextKind::OnPath { path: line, start: -0.05, end: None };
d.insert(Some(l), 0, Node::new(id, NodeKind::Text(Box::new(text.clone())))).unwrap();
let mut s = Selection::default();
s.add(id);
let p = paint();
let cx = cx(&d, &s, &p);
let lay = vectorcraft_text::layout(FontDb::global(), &text);
assert!(lay.glyphs[0].off_path && !lay.glyphs[1].off_path, "the T is before the path's start, the y is on it");
assert!(char_box(&text, &lay, 0).is_none());
assert!(TouchTypeTool { target: Some((id, 0)), ..Default::default() }.current(&cx).is_none());
assert!(TouchTypeTool { target: Some((id, 1)), ..Default::default() }.current(&cx).is_some());
// An All Caps ß is two glyphs: with the first before the path's start and the second drawn, the
// character has the second's box.
let mut caps = text.clone();
caps.runs = vec![vectorcraft_doc::TextRun::new("ße", CharStyle { size: 40.0, all_caps: true, ..Default::default() })];
if let vectorcraft_doc::TextKind::OnPath { start, .. } = &mut caps.kind {
*start = 0.0;
}
let adv = vectorcraft_text::layout(FontDb::global(), &caps).glyphs[0].advance;
if let vectorcraft_doc::TextKind::OnPath { start, .. } = &mut caps.kind {
*start = -1.2 * adv / 400.0;
}
let mut d = Document::new(600.0, 500.0);
let l = d.layers[0].id;
let id = d.alloc_id();
d.insert(Some(l), 0, Node::new(id, NodeKind::Text(Box::new(caps.clone())))).unwrap();
let mut s = Selection::default();
s.add(id);
let cx = crate::testutil::cx(&d, &s, &p);
let lay = vectorcraft_text::layout(FontDb::global(), &caps);
assert!(lay.glyphs[0].byte == 0 && lay.glyphs[1].byte == 0 && lay.glyphs[0].off_path && !lay.glyphs[1].off_path);
let t = TouchTypeTool { target: Some((id, 0)), ..Default::default() };
let (_, _, b) = t.current(&cx).expect("the ß has a box");
assert!((b.pen - lay.glyphs[1].xf * Point::ZERO).hypot() < 1e-9, "{:?}", b.pen);
// A press on its drawn glyph, on the path, starts a drag of it.
let q = glyph_quad(&lay.glyphs[1]).unwrap();
let at = Point::new(q[0].midpoint(q[2]).x, 200.0);
assert!(in_quad(&q, at), "{at:?} {q:?}");
let mut t = TouchTypeTool::default();
let acts = drag(&mut t, &cx, at, at + Vec2::new(0.0, -5.0));
assert_eq!(preview(&acts[1])["start"], 0, "{:?}", acts[1]);
}
/// A glyph skewed by its transform (the Skew effect of type on a path) keeps its own box.
#[test]
fn a_skewed_glyph_keeps_its_own_box() {
+19 -8
View File
@@ -9750,7 +9750,9 @@ neighbors, the kerning of the two characters keeps it and the characters after i
wider or narrower character moves the characters after it by the change in its width. Touch Type gives the character
before it a kerning value of its own (with `dx`, and with any other change where the font kerned the character with
its neighbors), and that character can then move by the font's kerning pair with the one before
it, as with any style change to one character (`text.setRangeStyle`). The type stays editable.
it, as with any style change to one character (`text.setRangeStyle`). The type stays editable. The characters of type
on an open path that are not drawn because they fall before the path's start cannot be selected with the tool, and
`text.touchType` returns an error for them.
```json
{"name":"run_command","arguments":{"command":"text.touchType","params":{"id":7,"start":1,"dx":10,"dy":4}}}
@@ -9840,9 +9842,10 @@ same in any language. Saved documents keep what they say, and imported text (PDF
Type on a path flows between a start and an end bracket, stored as fractions of its path's length.
`type.pathOptions {start?, end?, flip?, effect?, alignToPath?, spacing?, ids?}` sets them and the rest of Type on a
Path Options: `end: null` puts the end bracket back at the end of the path (or once round a closed one); `flip`
then turns the type to the other side of its path, the path running the other way and the brackets swapping ends so
the type keeps its stretch of the path; `alignToPath` runs the `ascender`, `descender`, `center` or `baseline` (the
Path Options: `end: null` puts the end bracket back at the end of the path (or once round a closed one); on an open
path a `start` below 0 starts the text that far before the path's start (on a closed path it is the path's start);
`flip` then turns the type to the other side of its path, the path running the other way and the brackets swapping
ends so the type keeps its stretch of the path; `alignToPath` runs the `ascender`, `descender`, `center` or `baseline` (the
default) along the path, each character by its own font, size and vertical scale: `ascender` runs the top of the
font's em box along it (its ideographic em box, else an em box centered on the cap height), `descender` runs the
bottom of the font's bounding box along it, and `center` runs a line at half the height of the top of the font's H
@@ -9855,6 +9858,13 @@ show selected type on a path's brackets: dragging the start or end bracket (`poi
begins or ends, dragging the centre bracket slides the type along its path and, dragged across the path, flips it
(with Cmd/Ctrl held it only slides). Each is one undo step.
Type on an open path that starts before the path's start keeps every character, and the characters whose middle falls
before the path's start are not drawn. A `flip` starts it at the start bracket, and dragging the center bracket slides
it from where it starts and no further before the path. Past the path's end, text that does not fit is overflow, as
for other type on a path. SVG import reads a `<textPath>` anchored or offset before an open path's start this way, and
SVG export writes it as a negative `startOffset`. Releasing it to point type keeps the first drawn character where it
was drawn.
```json
{"name":"run_command","arguments":{"command":"type.pathOptions","params":{"start":0.25,"end":0.75,"flip":true}}}
```
@@ -12219,10 +12229,11 @@ VectorCraft addition and changes no parity score.
the path's fill and stroke), so the released path has no fill and no stroke.
- **The text** keeps its runs with their character attributes and its paragraph attributes, and becomes point type on
one straight line along the object's own axis, with the baseline starting where the first character sat on the path
(type with no characters starts at its start bracket). Type on a Path Options (effect, align to path, spacing, flip,
brackets) don't apply to point type and are dropped. Type with Dynamic Text on (`type.dynamicText`) becomes point
type with it off, at the sizes it was drawn at: each size, leading and baseline shift is multiplied by the fit factor.
Without `keepOriginal` the type object itself becomes the point
(type with no characters starts at its start bracket; type that starts before an open path's start keeps its first
drawn character where it was drawn, with the characters that were not drawn before it). Type on a Path Options
(effect, align to path, spacing, flip, brackets) don't apply to point type and are dropped. Type with Dynamic Text
on (`type.dynamicText`) becomes point type with it off, at the sizes it was drawn at: each size, leading and
baseline shift is multiplied by the fit factor. Without `keepOriginal` the type object itself becomes the point
type, keeping its id, so a frame of threaded text leaves its thread with the text it holds, as
`type.convertToPointType` does for area type.
- It acts on the type on a path among `ids` (or `id`, else the selection), groups included; other objects are left
+2 -1
View File
@@ -1739,7 +1739,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
SVG import's style cascade, used for hidden objects, non-scaling strokes and type, tests each element only against the `<style>` rules for its id, its classes and its element name, and the rules whose selector ends in none of these (`*`, `[x]`).
SVG import places right-to-left point type and type on a path as [SVG 2's `text-anchor`](https://www.w3.org/TR/SVG2/text.html#TextAnchoringProperties) says: with `direction: rtl`, `start` puts the right edge of the text at its position (on a path, the text ends at `startOffset`) and `end` puts the left edge there. Each line and each absolutely placed chunk is anchored by the `text-anchor` and `direction` of the element holding its first character, a `<tspan>`'s own included, and each line starts at its own `x`. An absolutely placed chunk is anchored by the left and right edges of its glyphs as they are drawn, so a chunk of several right-to-left characters, whose first character is drawn at its right, sits on its anchor too. A letter-spaced right-to-left line keeps the tracking of all its letters inside the advance it anchors (`rtl_point_text_start_and_end_use_directional_edges`, `rtl_type_on_a_path_starts_at_its_directional_edge`, `rtl_letter_spaced_lines_stay_on_their_anchor`, `rtl_lines_use_each_chunk_first_character_direction_and_anchor`, `each_line_starts_at_its_own_x`, `absolutely_placed_chunks_use_their_own_rtl_anchor` and `absolutely_placed_rtl_chunks_of_several_characters_anchor_by_their_visual_edges` in `crates/svg/tests/it/import_text.rs`).
SVG import puts each absolutely placed character of right-to-left text on its own `x`, as [SVG 1.1's text chunks](https://www.w3.org/TR/SVG11/text.html#TextLayoutIntroduction) require, also when the characters run right to left on a later line: in `<text direction="rtl" font-size="20">`, `<tspan x="100 160" y="80 80">אב</tspan>` after a first line puts the right edges of `א` and `ב` at 100 and 160, where import put the right edge of `א` at 393.48 before. Chunks that overlap keep their own anchors, and characters stretched by `lengthAdjust="spacingAndGlyphs"` land on their `x` too. A left-to-right character drawn between two absolutely placed right-to-left characters leaves the one after it where the line puts it, and the import warns about it (`absolutely_placed_right_to_left_characters_sit_on_their_own_x` in `crates/svg/tests/it/import_text.rs`).
SVG import places type on a path of one closed subpath as [SVG 2's `startOffset` attribute](https://www.w3.org/TR/SVG2/text.html#TextPathElementStartOffsetAttribute) describes: text anchored to start before the path's start point, or offset past its end, wraps around the path, so text with `text-anchor="end"` at `startOffset` 0 ends at the start point, and a negative `startOffset` counts back from the end. Text longer than the loop draws its first characters whatever its anchor. A path of several subpaths, and an open path, still start the text at the path's start or end (`text_on_a_closed_path_wraps_past_the_path_start` in `crates/svg/tests/it/import_text.rs`).
SVG import places type on a path of one closed subpath as [SVG 2's `startOffset` attribute](https://www.w3.org/TR/SVG2/text.html#TextPathElementStartOffsetAttribute) describes: text anchored to start before the path's start point, or offset past its end, wraps around the path, so text with `text-anchor="end"` at `startOffset` 0 ends at the start point, and a negative `startOffset` counts back from the end. Text longer than the loop draws its first characters whatever its anchor. A path of several closed subpaths still starts the text at the path's start or end (`text_on_a_closed_path_wraps_past_the_path_start` in `crates/svg/tests/it/import_text.rs`).
Type on an open path can start before the path's start (`type.pathOptions` `start` below 0), and the characters whose middle falls before the path's start are not drawn, as [SVG 2's text on a path layout](https://www.w3.org/TR/SVG2/text.html#TextLayoutPath) describes for the path's start; past the path's end, text that does not fit is overflow, as for other type on a path. The text keeps every character, and the start bracket stays at the path's start. SVG import reads text anchored or offset before an open path's start this way instead of starting it at the path's start, and SVG export writes it with a negative `startOffset`. PDF export writes only the characters drawn on the path, the legacy `.ai` and `.ai` editing data writers write the type from the path's start with a warning, and Release Type on a Path keeps the first drawn character where it was drawn (`type_on_an_open_path_starts_before_the_path` in `crates/doc/src/text/tests.rs`, `on_path_open_start_before_the_path_hides_the_glyphs_before_it` in `crates/text/src/tests.rs`, `text_on_an_open_path_starts_before_the_path` in `crates/svg/tests/it/import_text.rs`, `text_on_an_open_path_starting_before_it_round_trips` in `crates/svg/tests/it/roundtrip.rs`, `options_start_type_before_an_open_path` in `crates/engine/src/tests/pathtype.rs`).
SVG import reads the bidi embedding of a `<tspan>`, `<textPath>` or `<a>` inside a `<text>` as [SVG 1.1's bidi section](https://www.w3.org/TR/SVG11/text.html#RelationshipWithBi-directionality) describes: with `unicode-bidi: embed` its characters take its `direction` as their Character Direction, an element with `normal` stays in its parent's embedding, and the `<text>` keeps its own paragraph direction, so a run that SVG export writes with `direction` and `unicode-bidi="embed"` opens with its Character Direction again. Character Direction holds one level of embedding, so `bidi-override`, `isolate` and `isolate-override` are imported as embeddings in their `direction`, `plaintext` as an embedding in the direction of its first strong character, and an embedding inside another as an embedding of its own, each with an import warning. With `unicode-bidi: plaintext` on the `<text>`, each of its paragraphs runs, and each chunk is anchored, in the direction of its first strong character (`a_tspan_bidi_embedding_becomes_its_character_direction`, `unicode_bidi_is_not_inherited_and_reads_from_the_cascade` and `unicode_bidi_values_the_text_model_cannot_hold_are_reported` in `crates/svg/tests/it/import_text.rs`; `character_direction_reads_back` in `crates/svg/tests/it/text_layout.rs`).
A `.svgz` file copied in a file manager pastes as its art, as a copied `.svg` file does.
SVG export (Save As, Export As, Export for Screens, Asset Export and the clipboard share the writer) writes simple shapes as SVG basic shapes, as the reference app does (an ellipse is an `ellipse` tag until an anchor is added, [forum](https://community.adobe.com/t5/illustrator-discussions/trouble-exporting-shape-with-points-to-svg/td-p/10720325); rectangles come out as `<rect>` and `<polygon>`, [forum](https://community.adobe.com/t5/illustrator-discussions/force-svg-export-using-all-lt-rect-gt/td-p/11282378)): an axis-aligned rectangle as `<rect>`, a circle or ellipse drawn with four standard arcs as `<circle>`/`<ellipse>`, a straight line as `<line>`, and other straight-segment paths as `<polygon>`/`<polyline>`, at the written precision (#4652). A rectangle or ellipse with a dashed stroke, whose dashes would start elsewhere, a turned ellipse, curves and compound paths stay `<path>`. `crates/svg/tests/it/basic_shapes.rs` checks each element, that the picture renders as the canvas does and that the geometry reimports.