mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 13:08:59 +00:00
Paragraph: Kurikaeshi Moji Shori draws a threaded type-on-path frame's first repeat mark
A frame of type on a path whose first paragraph continues from the frame before now draws a repeat mark at its start as the character before it in the frames before, as area and point type do. The mark keeps its advance, so the glyphs stay where they were, and live SVG text writes the character drawn.
This commit is contained in:
@@ -1298,18 +1298,17 @@ fn emit_line_glyph(
|
||||
}
|
||||
|
||||
/// Kurikaeshi Moji Shori (Paragraph panel menu): the glyph drawn in place of `g`, the first glyph of
|
||||
/// a line of `paragraph`, when `g` is a repeat mark, and the character it shows: the character
|
||||
/// [`repeated_char`] gives, shaped in the mark's style with the type's features (so vertical type
|
||||
/// gets the font's vertical forms), from the same face, with the mark's advance and place, so the
|
||||
/// line breaks stay as they are. None when `g` is no repeat mark, belongs to a tate-chu-yoko or
|
||||
/// warichu block, nothing before it in the paragraph fits, or the face draws the character with no
|
||||
/// glyph or with more than one. The paragraph's `lead` stands before a paragraph that continues
|
||||
/// from the frame before ([`TextObject::first_para_lead`]).
|
||||
fn repeat_mark_glyph(cx: &Ctx<'_>, paragraph: &ParagraphData<'_, '_>, g: &SGlyph) -> Option<(SGlyph, char)> {
|
||||
/// a line, when `g` is a repeat mark, and the character it shows: the character [`repeated_char`]
|
||||
/// gives for the character `base` finds before the mark, shaped in the mark's style with the type's
|
||||
/// features (so vertical type gets the font's vertical forms), from the same face, with the mark's
|
||||
/// advance and place, so the line breaks stay as they are. None when `g` is no repeat mark, belongs
|
||||
/// to a tate-chu-yoko or warichu block, `base` gives None, nothing before it fits, or the face draws
|
||||
/// the character with no glyph or with more than one. `base` runs only for a repeat mark.
|
||||
pub(super) fn repeat_mark_glyph(cx: &Ctx<'_>, g: &SGlyph, base: impl FnOnce() -> Option<Option<char>>) -> Option<(SGlyph, char)> {
|
||||
if g.tcy.is_some() || g.wari.is_some() || g.inline.is_some() || !matches!(g.ch, '々' | 'ゝ' | 'ゞ' | 'ヽ' | 'ヾ') {
|
||||
return None;
|
||||
}
|
||||
let c = repeated_char(paragraph.repeat_base_before(cx.text, g.byte)?, "", g.ch)?;
|
||||
let c = repeated_char(base()?, "", g.ch)?;
|
||||
let mut buf = [0; 4];
|
||||
let s: &str = c.encode_utf8(&mut buf);
|
||||
let mut shaped = Vec::with_capacity(1);
|
||||
@@ -1320,13 +1319,16 @@ fn repeat_mark_glyph(cx: &Ctx<'_>, paragraph: &ParagraphData<'_, '_>, g: &SGlyph
|
||||
|
||||
/// Kurikaeshi Moji Shori: the glyph drawn in place of glyph `first` of `paragraph`, the first
|
||||
/// character of a line that ends before glyph `end`, when the paragraph has the setting on and
|
||||
/// [`repeat_mark_glyph`] gives one; it is recorded in [`crate::TextLayout::repeat_marks`].
|
||||
/// [`repeat_mark_glyph`] gives one for the character before it in the paragraph, or the paragraph's
|
||||
/// `lead` before a paragraph that continues from the frame before ([`TextObject::first_para_lead`]);
|
||||
/// it is recorded in [`crate::TextLayout::repeat_marks`].
|
||||
fn line_start_repeat(cx: &mut Ctx<'_>, paragraph: &ParagraphData<'_, '_>, first: usize, end: usize) -> Option<SGlyph> {
|
||||
if !paragraph.para.kurikaeshi_moji_shori || first >= end {
|
||||
return None;
|
||||
}
|
||||
let g = paragraph.sg.get(first)?;
|
||||
let (glyph, c) = repeat_mark_glyph(cx, paragraph, g)?;
|
||||
let text = cx.text;
|
||||
let (glyph, c) = repeat_mark_glyph(cx, g, || paragraph.repeat_base_before(text, g.byte))?;
|
||||
cx.out.repeat_marks.push((g.byte, c));
|
||||
Some(glyph)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::bidi::{is_rtl, para_bidi_with, visual_order};
|
||||
use super::breaking::{Metrics, optical_hangs, optical_hangs_rtl, optical_share, roman_share};
|
||||
use super::flow::list_markers;
|
||||
use super::flow::{list_markers, repeat_mark_glyph};
|
||||
use super::region::in_range;
|
||||
use super::{
|
||||
Affine, ArcPath, BezPath, Ctx, GlyphBend, Justify, LineInfo, ListMarker, ParamCurve, PathAlign, PathData, PathEffect, PathEl, Point, Range,
|
||||
@@ -409,6 +409,21 @@ fn hide_before_open_path(cx: &mut Ctx<'_>, ap: &ArcPath, lead: bool, at: usize,
|
||||
true
|
||||
}
|
||||
|
||||
/// Kurikaeshi Moji Shori: type on a path is one line, which starts with the first character of its
|
||||
/// first paragraph `pr` (shaped as `glyphs`). When that paragraph continues from the frame before
|
||||
/// and has the setting on, a repeat mark there is drawn as the character before it in the frames
|
||||
/// before ([`TextObject::first_para_lead`]): its glyph in `glyphs` is replaced, and the mark's byte
|
||||
/// and the character drawn are returned.
|
||||
fn line_start_repeat(cx: &Ctx<'_>, t: &TextObject, pr: &Range<usize>, glyphs: &mut [SGlyph]) -> Option<(usize, char)> {
|
||||
if !t.first_para_continues || !t.para_at(0).kurikaeshi_moji_shori {
|
||||
return None;
|
||||
}
|
||||
let g = glyphs.iter_mut().find(|g| g.len > 0 && g.byte == pr.start)?;
|
||||
let (glyph, c) = repeat_mark_glyph(cx, g, || Some(t.first_para_lead))?;
|
||||
*g = glyph;
|
||||
Some((g.byte, c))
|
||||
}
|
||||
|
||||
/// 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;
|
||||
@@ -431,6 +446,8 @@ pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject,
|
||||
}
|
||||
shaped.push((pr.clone(), bidi.filter(|b| b.has_rtl() && !cx.vertical), glyphs));
|
||||
}
|
||||
// Kurikaeshi Moji Shori: the repeat mark that starts the line, recorded when its glyph is drawn.
|
||||
let mut repeat = shaped.first_mut().and_then(|(pr, _, glyphs)| line_start_repeat(cx, t, pr, glyphs));
|
||||
let rtl = rtl.unwrap_or(false);
|
||||
// The text before byte `cut` in visual order, as area type reorders each line it breaks.
|
||||
let visual = |cut: usize| {
|
||||
@@ -710,6 +727,9 @@ pub(super) fn on_path(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &TextObject,
|
||||
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);
|
||||
if !hidden && let Some(mark) = repeat.take_if(|&mut (byte, _)| g.len > 0 && g.byte == byte) {
|
||||
cx.out.repeat_marks.push(mark);
|
||||
}
|
||||
// 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 !hidden && t.path_effect == PathEffect::Rainbow && g.cursive && !cx.vertical && g.inline.is_none() {
|
||||
|
||||
@@ -2808,6 +2808,24 @@ fn kurikaeshi_moji_shori_draws_the_repeated_character_at_a_line_start() {
|
||||
let on = layout(&db, &t);
|
||||
assert_eq!(gid_of(&on, 0), glyph('時'), "the frame's first 々 is drawn as 時");
|
||||
assert_eq!(gid_of(&on, "々す\n".len()), glyph('々'), "the next paragraph's first mark keeps its glyph");
|
||||
assert_eq!(on.repeat_marks, [(0, '時')]);
|
||||
// Type on a path is one line: a threaded frame on a path starts it the same way.
|
||||
let mut line = 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 on = layout(&db, &t);
|
||||
assert!(on.on_path);
|
||||
assert_eq!(gid_of(&on, 0), glyph('時'), "type on a path: the frame's first 々 is drawn as 時");
|
||||
assert_eq!(gid_of(&on, "々す\n".len()), glyph('々'), "type on a path: the next paragraph's first mark keeps its glyph");
|
||||
assert_eq!(on.repeat_marks, [(0, '時')]);
|
||||
t.para.kurikaeshi_moji_shori = false;
|
||||
let off = layout(&db, &t);
|
||||
assert_eq!(gid_of(&off, 0), glyph('々'), "type on a path with the setting off");
|
||||
assert!(off.repeat_marks.is_empty());
|
||||
t.para.kurikaeshi_moji_shori = true;
|
||||
t.first_para_continues = false;
|
||||
assert_eq!(gid_of(&layout(&db, &t), 0), glyph('々'), "type on a path in a frame that does not continue");
|
||||
}
|
||||
|
||||
/// Kurikaeshi Moji Shori: a paragraph with a repeat mark at the start of each of many lines is laid
|
||||
|
||||
Reference in New Issue
Block a user