mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
Type: Tsume applies in vertical type and to color glyphs
Tsume no longer stops at horizontal type. In vertical type an upright character loses its share of the blank space above and below its ink, inside its cell down the column (the font's vertical metrics, else at least one em, with the Proportional Metrics change), in point type and on a path. A character lying on its side is measured along its own width, and the characters of a tate-chu-yoko block close up across the column while the block keeps its one em. Tsume now measures what a glyph paints: its COLR or SVG art, else its color bitmap, else its outline, so a color glyph is no longer measured by the outline its art replaces. Docs: docs/mcp.md, docs/target-app-parity.md, text.setRangeStyle and text.setFormat params.
This commit is contained in:
@@ -48,8 +48,10 @@ pub struct CharStyle {
|
||||
/// of the character's ink, inside its own width, that is taken away, 0 to [`MAX_TSUME`]. 50
|
||||
/// halves that space and 100 sets the ink edge to edge; the glyph itself is not scaled. A
|
||||
/// cluster takes the value of its first character. Tracking, kerning and Insert Aki are added
|
||||
/// after it. Horizontal type only.
|
||||
/// after it. In vertical type an upright character is measured above and below its ink, inside
|
||||
/// its cell down the column.
|
||||
/// <https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html>
|
||||
/// <https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html>
|
||||
#[serde(default, skip_serializing_if = "crate::skip::is_default")]
|
||||
pub tsume: f64,
|
||||
/// Use glyph shapes for automatic pair spacing; false uses font metrics.
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -258,18 +258,43 @@ impl Ctx<'_> {
|
||||
// of the glyph before it takes no cell of its own: it turns with that glyph (`emit`).
|
||||
for i in 0..v.len() {
|
||||
let continues = continues_cluster(i.checked_sub(1).and_then(|p| v.get(p)), v.get(i));
|
||||
let Some(g) = v.get_mut(i).filter(|g| g.adv > 0.0 && !continues && stands_upright(g)) else { continue };
|
||||
let extra = upright_cell(g) - g.face.advance(g.gid) * g.sx;
|
||||
if continues || !v.get(i).is_some_and(stands_upright) {
|
||||
continue;
|
||||
}
|
||||
// Tsume measured the cluster across its glyphs' widths when it was shaped: an
|
||||
// upright glyph's blank space runs down its cell, so that is taken back first.
|
||||
let measured_down = v.get(i).is_some_and(|g| g.tcy.is_none());
|
||||
if measured_down {
|
||||
let end = (i + 1..v.len()).find(|&j| !continues_cluster(v.get(j - 1), v.get(j))).unwrap_or(v.len());
|
||||
let tsume = v.get(end - 1).map_or(0.0, |g| g.tsume);
|
||||
for g in v.get_mut(i..end).unwrap_or_default() {
|
||||
g.dx += g.tsume_shift;
|
||||
g.tsume_shift = 0.0;
|
||||
}
|
||||
if let Some(g) = v.get_mut(end - 1) {
|
||||
g.adv += tsume;
|
||||
g.tsume = 0.0;
|
||||
}
|
||||
}
|
||||
let Some(g) = v.get_mut(i).filter(|g| g.adv > 0.0) else { continue };
|
||||
let cell = upright_cell(g);
|
||||
let extra = cell - g.face.advance(g.gid) * g.sx;
|
||||
g.dx += extra * 0.5;
|
||||
g.adv += extra;
|
||||
// Proportional Metrics: `vpal` (and the vertical kerning with it) moves it and
|
||||
// changes its length down the column, in fonts with vertical metrics (else the cell
|
||||
// stays as it is, #966).
|
||||
let mut length = cell;
|
||||
if let Some(a) = g.vpal.filter(|_| g.tcy.is_none() && g.face.vertical_glyph(g.gid).is_some()) {
|
||||
g.dx += a.dx;
|
||||
g.dy += a.dy;
|
||||
g.adv += a.advance;
|
||||
g.proportional = a.proportional;
|
||||
length += a.advance;
|
||||
}
|
||||
let st = style(g);
|
||||
if measured_down && st.tsume > 0.0 {
|
||||
self.tighten_upright(g, cell, length, st.size, st.tsume);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,6 +311,25 @@ impl Ctx<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tsume `tsume` on upright glyph `g` in vertical type, in type of size `em`, its cell `cell`
|
||||
/// long down the column and `length` long with the Proportional Metrics change to it: its share
|
||||
/// of the blank space above and below what it paints, inside that length, comes out of its
|
||||
/// advance, and it is drawn the share above it earlier, keeping its shape. A combining mark in
|
||||
/// its cluster moves with it. A glyph that paints nothing keeps its place and length.
|
||||
fn tighten_upright(&self, g: &mut SGlyph, cell: f64, length: f64, em: f64, tsume: f64) {
|
||||
let Some(b) = crate::shape::painted_box(self.db, g) else { return };
|
||||
// The glyph turns about the center of its cell, which is `upright_centre` above the
|
||||
// baseline: a point of it in font units (y down) lands that far below the center, down the
|
||||
// column from the top of the cell.
|
||||
let centre = cell * 0.5 + upright_centre(g, cell, em) + g.dy;
|
||||
let (a, z) = (centre + b.y0 * g.sy, centre + b.y1 * g.sy);
|
||||
let Some((above, below)) = crate::shape::tsume_shares((a.min(z), a.max(z)), length, tsume) else { return };
|
||||
g.kern_shift -= above;
|
||||
g.tsume_shift = above;
|
||||
g.adv -= above + below;
|
||||
g.tsume = above + below;
|
||||
}
|
||||
|
||||
/// Bullets and numbered lists: put marker `text` (the bullet, or the number and its period;
|
||||
/// [`list_markers`]) of list paragraph `pr` (attributes `para`, right to left when `rtl`)
|
||||
/// before its glyphs `sg` and return how many glyphs went in (none for a paragraph without a
|
||||
|
||||
+45
-28
@@ -598,7 +598,7 @@ pub(crate) fn shape_runs(
|
||||
// Synthesized Small Caps shape lowercase letters separately (as smaller capitals).
|
||||
let small_caps = st.small_caps.is_some() && !st.all_caps;
|
||||
// Split into segments by font coverage (and case, for Small Caps).
|
||||
let mut seg = Segment { range: a..a, runs, source_runs, st, face: primary.clone(), small: false, level: level_at(a) };
|
||||
let mut seg = Segment { db, range: a..a, runs, source_runs, st, face: primary.clone(), small: false, level: level_at(a) };
|
||||
let mut cache: std::collections::HashMap<&str, Arc<FontFace>> = std::collections::HashMap::new();
|
||||
let mut script = Script::Common;
|
||||
// A grapheme cluster (a letter and its marks, an emoji sequence) is set in one face.
|
||||
@@ -1354,6 +1354,7 @@ fn inline_glyph(
|
||||
/// alike ([`shapes_alike`]).
|
||||
#[derive(Clone)]
|
||||
struct Segment<'a> {
|
||||
db: &'a FontDb,
|
||||
range: Range<usize>,
|
||||
/// All the runs, and the indices of those the piece's shaping span takes in.
|
||||
runs: &'a [(Range<usize>, &'a CharStyle)],
|
||||
@@ -1413,7 +1414,7 @@ fn is_mark(c: char) -> bool {
|
||||
/// SS). A cluster that would take in characters of runs with different drawing attributes (a
|
||||
/// ligature, a base with its marks) is not formed, except for paint-only harakat differences.
|
||||
fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFeatures, out: &mut Vec<SGlyph>) {
|
||||
let Segment { range, runs, source_runs, st, face, small, level } = seg;
|
||||
let Segment { db, range, runs, source_runs, st, face, small, level } = seg;
|
||||
let (range, small) = (range.clone(), *small);
|
||||
// The source runs the segment's bytes lie in (a span can hold many segments).
|
||||
let span = runs.get(source_runs.clone()).unwrap_or_default();
|
||||
@@ -1507,8 +1508,8 @@ fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFe
|
||||
}
|
||||
ranged
|
||||
};
|
||||
// Horizontal type with Tsume on any of the segment's characters.
|
||||
let tsume_here = !feats.vertical && runs.get(source_runs.clone()).unwrap_or_default().iter().any(|(_, s)| s.tsume > 0.0);
|
||||
// Tsume on any of the segment's characters.
|
||||
let tsume_here = runs.get(source_runs.clone()).unwrap_or_default().iter().any(|(_, s)| s.tsume > 0.0);
|
||||
// Shape the segment as if all of it were in `st`, with the features `more` on top.
|
||||
let shape_in = |st: &CharStyle, more: &[Feature]| {
|
||||
// A BCP 47 tag is short ASCII; anything else (a file may hold anything) is shaped without one.
|
||||
@@ -1888,10 +1889,11 @@ fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFe
|
||||
hyphen_language: crate::hyphen::Language::from_tag(gst.language.as_deref()),
|
||||
});
|
||||
// Tsume takes its share of the blank space beside the cluster's ink once the cluster is
|
||||
// complete, in horizontal type.
|
||||
if last_in_cluster && !invisible && !feats.vertical && gst.tsume > 0.0 {
|
||||
// complete, along the line. In vertical type a glyph that stands upright is measured down
|
||||
// the column instead, once its cell is known ([`crate::layout`]).
|
||||
if last_in_cluster && !invisible && gst.tsume > 0.0 {
|
||||
let first = out.iter().rposition(|g| g.byte != cl).map_or(0, |i| i + 1);
|
||||
tighten(out.get_mut(first..).unwrap_or_default(), own, gst.tsume);
|
||||
tighten(db, out.get_mut(first..).unwrap_or_default(), own, gst.tsume);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1902,25 +1904,20 @@ fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFe
|
||||
/// and its ink, on each side, comes out of the cluster's advance, and its glyphs are drawn the
|
||||
/// left side's share earlier ([`SGlyph::tsume`] and [`SGlyph::tsume_shift`] hold both, for Optical
|
||||
/// kerning to measure the pair without them). A cluster without ink, such as a space, or with a
|
||||
/// width that is not positive, keeps its place and width.
|
||||
fn tighten(glyphs: &mut [SGlyph], own: f64, tsume: f64) {
|
||||
/// width that is not positive, keeps its place and width. The ink is what the glyph paints
|
||||
/// ([`painted_box`]): its color art or bitmap when it has one, else its outline.
|
||||
fn tighten(db: &FontDb, glyphs: &mut [SGlyph], own: f64, tsume: f64) {
|
||||
let Some(last) = glyphs.len().checked_sub(1) else { return };
|
||||
let share = if tsume.is_nan() { 0.0 } else { tsume.clamp(0.0, MAX_TSUME) / 100.0 };
|
||||
let (mut pen, mut ink): (f64, Option<(f64, f64)>) = (0.0, None);
|
||||
for (i, g) in glyphs.iter().enumerate() {
|
||||
if let Some((a, b)) = ink_across(&g.face, g.gid) {
|
||||
let (a, b) = (pen + g.dx + a * g.sx, pen + g.dx + b * g.sx);
|
||||
if let Some(b) = painted_box(db, g) {
|
||||
let (a, b) = (pen + g.dx + b.x0 * g.sx, pen + g.dx + b.x1 * g.sx);
|
||||
let (lo, hi) = (a.min(b), a.max(b));
|
||||
ink = Some(ink.map_or((lo, hi), |(l, h)| (l.min(lo), h.max(hi))));
|
||||
}
|
||||
pen += if i == last { own } else { g.adv };
|
||||
}
|
||||
let Some((lo, hi)) = ink.filter(|(lo, hi)| lo.is_finite() && hi.is_finite()) else { return };
|
||||
if !(pen.is_finite() && pen > 0.0) {
|
||||
return;
|
||||
}
|
||||
let left = lo.clamp(0.0, pen) * share;
|
||||
let right = (pen - hi).clamp(0.0, pen) * share;
|
||||
let Some((left, right)) = ink.and_then(|ink| tsume_shares(ink, pen, tsume)) else { return };
|
||||
for g in glyphs.iter_mut() {
|
||||
g.dx -= left;
|
||||
g.tsume_shift = left;
|
||||
@@ -1931,18 +1928,38 @@ fn tighten(glyphs: &mut [SGlyph], own: f64, tsume: f64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The left and right edges of glyph `gid`'s outline in `face`, in font units; `None` for a glyph
|
||||
/// without an outline (a space, or a bitmap or color glyph without one).
|
||||
fn ink_across(face: &FontFace, gid: u32) -> Option<(f64, f64)> {
|
||||
let font = face.skrifa()?;
|
||||
let glyph = font.outline_glyphs().get(skrifa::GlyphId::new(gid))?;
|
||||
let mut pen = crate::fontdb::FlipPen(kurbo::BezPath::new());
|
||||
glyph.draw(skrifa::outline::DrawSettings::unhinted(Size::unscaled(), face.location()), &mut pen).ok()?;
|
||||
if pen.0.elements().is_empty() {
|
||||
/// What Tsume `tsume` (percent) takes off before and after ink running from `lo` to `hi` along a
|
||||
/// cell running from 0 to `length`: its share of the blank space on each side, inside the cell.
|
||||
/// `None` when the ink or the cell is not finite, or the cell's length is not positive.
|
||||
pub(crate) fn tsume_shares((lo, hi): (f64, f64), length: f64, tsume: f64) -> Option<(f64, f64)> {
|
||||
let share = if tsume.is_nan() { 0.0 } else { tsume.clamp(0.0, MAX_TSUME) / 100.0 };
|
||||
if !(lo.is_finite() && hi.is_finite() && length.is_finite() && length > 0.0) {
|
||||
return None;
|
||||
}
|
||||
let b = pen.0.bounding_box();
|
||||
Some((b.x0, b.x1))
|
||||
Some((lo.clamp(0.0, length) * share, (length - hi).clamp(0.0, length) * share))
|
||||
}
|
||||
|
||||
/// The box of what glyph `g` paints, in font units (y down, as outlines are), as the layout draws
|
||||
/// it: its COLR or SVG art, else its color bitmap, else its outline. `None` for a glyph that paints
|
||||
/// nothing: a space, a control or format character, or art, an image or an outline that is empty
|
||||
/// or not finite.
|
||||
pub(crate) fn painted_box(db: &FontDb, g: &SGlyph) -> Option<kurbo::Rect> {
|
||||
if g.inline.is_some() || g.is_soft_hyphen() || g.ch.is_control() || g.ch == '\u{2028}' || crate::justify::is_format_control(g.ch) {
|
||||
return None;
|
||||
}
|
||||
let image_box = |image: &crate::GlyphImage| image.xf.transform_rect_bbox(image.rect());
|
||||
let b = match db.glyph_colour(&g.face, g.gid, vectorcraft_doc::color::Color::BLACK, None) {
|
||||
Some(crate::colr::ColourContent::Art(art)) => art.geometric_bounds(),
|
||||
Some(crate::colr::ColourContent::Image(image)) => Some(image_box(&image)),
|
||||
None => match db.glyph_image(&g.face, g.gid) {
|
||||
Some(image) => Some(image_box(&image)),
|
||||
None => {
|
||||
let outline = db.outline(&g.face, g.gid);
|
||||
(!outline.elements().is_empty()).then(|| outline.bounding_box())
|
||||
}
|
||||
},
|
||||
};
|
||||
b.filter(|b| [b.x0, b.y0, b.x1, b.y1].iter().all(|v| v.is_finite()) && (b.width() > 0.0 || b.height() > 0.0))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Tsume (`CharStyle::tsume`): the share of the blank space on each side of a character's ink,
|
||||
//! inside its own width, that horizontal type takes away, the glyph keeping its shape.
|
||||
//! inside its own width (in vertical type, down an upright character's cell), that is taken away,
|
||||
//! the glyph keeping its shape.
|
||||
use super::{area, db, point, style};
|
||||
use crate::*;
|
||||
use kurbo::Shape;
|
||||
@@ -150,13 +151,134 @@ fn justification_keeps_the_tsume() {
|
||||
assert!(gap(<) < gap(&lp) - 1.0, "{} {}", gap(&lp), gap(<));
|
||||
}
|
||||
|
||||
fn vertical(text: &str, st: CharStyle) -> TextObject {
|
||||
let mut t = point(text, st);
|
||||
t.xf = Affine::IDENTITY;
|
||||
t.vertical = true;
|
||||
t
|
||||
}
|
||||
|
||||
/// The box of what glyph `byte` paints: its outline, its bitmap or its color art.
|
||||
fn painted(l: &TextLayout, byte: usize) -> Rect {
|
||||
let g = l.glyphs.iter().find(|g| g.byte == byte).unwrap();
|
||||
let image = g.placed_image().map(|(image, xf)| xf.transform_rect_bbox(image.rect()));
|
||||
let colour = g.colour.as_ref().and_then(|c| c.geometric_bounds()).map(|b| g.xf.transform_rect_bbox(b));
|
||||
image.or(colour).unwrap_or_else(|| g.outline.bounding_box())
|
||||
}
|
||||
|
||||
/// Where glyph `byte`'s cell starts down a vertical column.
|
||||
fn cell_top(l: &TextLayout, byte: usize) -> f64 {
|
||||
l.glyphs.iter().find(|g| g.byte == byte).map(|g| g.origin.y).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vertical_type_keeps_its_spacing() {
|
||||
for text in ["§§", "ab"] {
|
||||
let mut plain = point(text, style(20.0));
|
||||
plain.xf = Affine::IDENTITY;
|
||||
plain.vertical = true;
|
||||
let centers = |t: &TextObject| layout(db(), t).glyphs.iter().map(|g| g.outline.bounding_box().center()).collect::<Vec<_>>();
|
||||
assert_eq!(centers(&with(&plain, 0, |s| s.tsume = 100.0)), centers(&plain), "{text}");
|
||||
fn upright_glyphs_take_their_share_of_the_space_above_and_below_their_ink() {
|
||||
use crate::test_fonts::{VERTICAL_FAMILY, vertical_font};
|
||||
// The bundled font without vertical metrics (a cell of one em), and with them: § 1.4 em down
|
||||
// the column from its vertical origin, given by VORG or by its top side bearing.
|
||||
for vorg in [None, Some(false), Some(true)] {
|
||||
let fonts = FontDb::with_font_dirs(vec![]);
|
||||
let mut st = style(20.0);
|
||||
if let Some(vorg) = vorg {
|
||||
fonts.add_font(vertical_font(vorg).unwrap());
|
||||
st.font_family = VERTICAL_FAMILY.into();
|
||||
}
|
||||
let plain = vertical("§§§", st.clone());
|
||||
let lp = layout(&fonts, &plain);
|
||||
let (before, after) = (painted(&lp, 2).y0 - cell_top(&lp, 2), cell_top(&lp, 4) - painted(&lp, 2).y1);
|
||||
assert!(before > 1.0 && after > 1.0, "{vorg:?}: {before} {after}");
|
||||
for tsume in [25.0, 100.0] {
|
||||
let share = tsume / 100.0;
|
||||
let lt = layout(&fonts, &with(&plain, 2, |s| s.tsume = tsume));
|
||||
// The middle § moves up by its share of the space above its ink, and the § after it by
|
||||
// the share of the space above and below it; the first stays, and the glyph keeps its
|
||||
// shape.
|
||||
let moved = (painted(<, 2).y0 - painted(&lp, 2).y0, painted(<, 4).y0 - painted(&lp, 4).y0);
|
||||
assert!((moved.0 + before * share).abs() < 1e-6, "{vorg:?} {tsume}: {moved:?}");
|
||||
assert!((moved.1 + (before + after) * share).abs() < 1e-6, "{vorg:?} {tsume}: {moved:?}");
|
||||
assert!((painted(<, 2).height() - painted(&lp, 2).height()).abs() < 1e-6);
|
||||
assert!((painted(<, 2).center().x - painted(&lp, 2).center().x).abs() < 1e-6, "it stays on the column's center line");
|
||||
assert!((painted(<, 0).y0 - painted(&lp, 0).y0).abs() < 1e-9);
|
||||
}
|
||||
// At 100% the ink runs edge to edge down the column.
|
||||
let lt = layout(&fonts, &with(&plain, 2, |s| s.tsume = 100.0));
|
||||
assert!((painted(<, 2).y0 - cell_top(&lp, 2)).abs() < 1e-6 && (cell_top(<, 4) - painted(<, 2).y1).abs() < 1e-6, "{vorg:?}");
|
||||
// A space keeps its length down the column.
|
||||
let spaced = vertical("§ §", st);
|
||||
let tops = |t: &TextObject| layout(&fonts, t).glyphs.iter().map(|g| g.origin.y).collect::<Vec<_>>();
|
||||
assert_eq!(tops(&with(&spaced, 2, |s| s.tsume = 100.0)), tops(&spaced), "{vorg:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn letters_on_their_side_take_the_tsume_of_horizontal_type() {
|
||||
// In vertical type a letter lies on its side: its space before and after its ink runs down
|
||||
// the column, as far as it runs along a horizontal line.
|
||||
let (across, down) = (point("HOH", style(20.0)), vertical("HOH", style(20.0)));
|
||||
let moves_along = |t: &TextObject, vertical: bool| {
|
||||
let (lp, lt) = (layout(db(), t), layout(db(), &with(t, 1, |s| s.tsume = 100.0)));
|
||||
[1, 2].map(|i| if vertical { painted(<, i).y0 - painted(&lp, i).y0 } else { painted(<, i).x0 - painted(&lp, i).x0 })
|
||||
};
|
||||
let (h, v) = (moves_along(&across, false), moves_along(&down, true));
|
||||
assert!(h[1] < -1.0 && near(&v, &h), "{h:?} {v:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tsume_inside_a_tate_chu_yoko_block_keeps_its_cell() {
|
||||
// Two digits are set across the column as one block one em long; Tsume closes them up across
|
||||
// it, and the letter after the block keeps its place.
|
||||
let plain = vertical("H12H", style(20.0));
|
||||
let tight = with(&with(&plain, 1, |s| s.tsume = 100.0), 2, |s| s.tsume = 100.0);
|
||||
let (lp, lt) = (layout(db(), &plain), layout(db(), &tight));
|
||||
let side_by_side = (painted(&lp, 1).center().y - painted(&lp, 2).center().y).abs();
|
||||
assert!(side_by_side < 1.0, "the digits stand side by side across the column: {side_by_side}");
|
||||
let apart = |l: &TextLayout| (painted(l, 2).center().x - painted(l, 1).center().x).abs();
|
||||
assert!(apart(<) < apart(&lp) - 1.0, "{} {}", apart(&lp), apart(<));
|
||||
assert!((painted(<, 3).y0 - painted(&lp, 3).y0).abs() < 1e-9);
|
||||
assert!((painted(<, 1).width() - painted(&lp, 1).width()).abs() < 1e-6, "the digits keep their size");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upright_glyphs_on_a_vertical_path_take_the_tsume_of_point_type() {
|
||||
use vectorcraft_doc::TextKind;
|
||||
use vectorcraft_geom::PathData;
|
||||
let point_type = vertical("§§§", style(20.0));
|
||||
let mut on_path = point_type.clone();
|
||||
on_path.kind =
|
||||
TextKind::OnPath { path: PathData::from_bezpath(&kurbo::Line::new((0.0, 0.0), (0.0, 3000.0)).to_path(0.1)), start: 0.0, end: None };
|
||||
let moved = |t: &TextObject| {
|
||||
let (lp, lt) = (layout(db(), t), layout(db(), &with(t, 2, |s| s.tsume = 100.0)));
|
||||
[2, 4].map(|i| painted(<, i).y0 - painted(&lp, i).y0)
|
||||
};
|
||||
let (p, path) = (moved(&point_type), moved(&on_path));
|
||||
assert!(p[1] < -1.0 && near(&path, &p), "{p:?} {path:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitmap_and_color_glyphs_measure_what_they_paint() {
|
||||
use crate::test_fonts::{COLOUR_CHAR, colour_bitmap_family, colour_bitmap_font, colr_family, colr_font};
|
||||
// Each font keeps the base outline of its color glyph; the image or art drawn in its place is
|
||||
// what Tsume measures.
|
||||
let fonts = [
|
||||
(colour_bitmap_font(true), colour_bitmap_family(true)),
|
||||
(colour_bitmap_font(false), colour_bitmap_family(false)),
|
||||
(colr_font(false), colr_family(false)),
|
||||
(colr_font(true), colr_family(true)),
|
||||
];
|
||||
for (font, family) in fonts {
|
||||
let fonts = FontDb::with_font_dirs(vec![]);
|
||||
fonts.add_font(font.expect("the test font builds"));
|
||||
let plain = point(&format!("{COLOUR_CHAR}H"), CharStyle { font_family: family.into(), ..style(100.0) });
|
||||
let lp = layout(&fonts, &plain);
|
||||
let g = &lp.glyphs[0];
|
||||
assert!(g.image.is_some() || g.colour.is_some(), "{family}");
|
||||
let (start, end) = (g.origin.x, lp.glyphs[1].origin.x);
|
||||
let p = painted(&lp, 0);
|
||||
let width = end - start;
|
||||
let (left, right) = ((p.x0 - start).clamp(0.0, width), (end - p.x1).clamp(0.0, width));
|
||||
let lt = layout(&fonts, &with(&plain, 0, |s| s.tsume = 100.0));
|
||||
let moved = (painted(<, 0).x0 - p.x0, lt.glyphs[1].origin.x - end);
|
||||
assert!((moved.0 + left).abs() < 1e-6 && (moved.1 + left + right).abs() < 1e-6, "{family}: {moved:?} {left} {right}");
|
||||
assert!((painted(<, 0).width() - p.width()).abs() < 1e-6, "{family}");
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -9606,9 +9606,15 @@ around them ([the help page](https://helpx.adobe.com/illustrator/using/formattin
|
||||
the default and how the space is measured are VectorCraft's own rules: the value is from 0 to 100, 0 by default and
|
||||
saved only when not 0, and it is the share of the blank space on each side of a character's ink, inside the
|
||||
character's own width, that is taken away. 50 halves that space, and 100 sets the ink against the characters before and
|
||||
after it; the glyph keeps its shape. A character without ink, such as a space, keeps its width. A ligature or a letter
|
||||
with its marks takes the value of its first character. Tracking, kerning and Insert Aki are added after it, and
|
||||
justification keeps it. Tsume applies to horizontal type; vertical type keeps its spacing. Character styles carry it
|
||||
after it; the glyph keeps its shape. The ink of a color glyph is the color art or bitmap drawn for it, not its outline.
|
||||
A character without ink, such as a space, keeps its width. A ligature or a letter with its marks takes the value of its
|
||||
first character. Tracking, kerning and Insert Aki are added after it, and justification keeps it. Vertical type takes
|
||||
it too ([the help page](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html)):
|
||||
a character that stands upright loses the share of the space above and below its ink, inside its cell down the column
|
||||
(its vertical advance from the font's vertical metrics, else at least one em, with the Proportional Metrics change to
|
||||
it), and moves up with it; a character lying on its side is measured along its own width, as in horizontal type; the
|
||||
characters of a tate-chu-yoko block move closer across the column, and the block keeps its one em down the column. A
|
||||
mark in an upright character's cluster moves with it, and Tsume measures the character's own ink only. Character styles carry it
|
||||
(`charStyle.new`, `charStyle.setAttrs` and `charStyle.edit` refuse a value outside the range). A value that is not a
|
||||
number is refused with `` `tsume` must be a number ``, and one outside the range with `` `tsume` must be from 0 to
|
||||
100 ``. One undo step, and a call that gives the value the characters already have records none. With Show East Asian
|
||||
|
||||
@@ -1504,7 +1504,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
A file whose character styles hold a Tate-chu-yoko Up/Down or Left/Right offset past the coordinate limit (`MAX_COORD`) either way opens with the nearer end, as the type's own offsets do; an offset within it stays as saved.
|
||||
Character panel › Insert Aki Left and Insert Aki Right (with the East Asian options; `text.setFormat` or `text.setRangeStyle {akiLeft, akiRight}`, thousandths of an em from 0 to 1000, 0 by default) add space before and after each selected character, measured as tracking is, and kept as set through justification ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); before and after follow the reading order in vertical and right-to-left type, character styles carry both values (Character Style Options › Advanced Character Formats edits them), and a file holding a value outside the range opens with the nearer end.
|
||||
Insert Aki Left and Right open from an `.ai` file's text document (read in thousandths of an em, the unit the [scripting reference](https://web.archive.org/web/20160410092022/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/pdfs/illustrator_scripting_reference_applescript.pdf#page=90) gives `aki left` and `aki right`; VectorCraft's own rule for the stored value) from the run, its character style, the styles that one is based on, `[Normal Character Style]` and the document's defaults in that order. A negative value or one that is not a number opens as 0, and a value past 1000 opens as 1000. An `.ai` save writes each run's nonzero values in the form that reader reads. A legacy `.ai` save writes type with Insert Aki as text without it and reports that it is left out; type it writes as outlines keeps the space.
|
||||
Character panel › Tsume (with the East Asian options; `text.setFormat` or `text.setRangeStyle {tsume}`) narrows the space around each selected character ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); by VectorCraft's own rule the value is a percentage from 0 to 100, 0 by default, of the blank space on each side of the character's ink that horizontal type takes away without changing the glyph's shape, with tracking, kerning and Insert Aki added after it. Character styles carry it (Character Style Options › Advanced Character Formats edits it), and a file holding a value outside the range opens with the nearer end.
|
||||
Character panel › Tsume (with the East Asian options; `text.setFormat` or `text.setRangeStyle {tsume}`) narrows the space around each selected character ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); by VectorCraft's own rule the value is a percentage from 0 to 100, 0 by default, of the blank space on each side of the character's ink that is taken away without changing the glyph's shape, with tracking, kerning and Insert Aki added after it; a color glyph's ink is its color art or bitmap. Vertical type takes it too ([the help page](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html)): by VectorCraft's own rule an upright character is measured above and below its ink inside its cell down the column, a character lying on its side along its own width, and a tate-chu-yoko block's characters across the column, the block keeping its one em. Character styles carry it (Character Style Options › Advanced Character Formats edits it), and a file holding a value outside the range opens with the nearer end.
|
||||
The Character panel's All Caps, Underline and Strikethrough buttons and its menu's All Caps, Underline, Strikethrough, Proportional Metrics, Tate-chu-yoko and No Break show off while only some of the selected characters have the attribute, and choosing one then turns it on for all of them, as `type.underline` (Cmd+Shift+U) does for underlining; the Character Alignment and Digits submenus check no item while the selected characters differ. `text.setFormat` refuses a value that is not true or false for its on/off attributes, as `text.setRangeStyle` does.
|
||||
- **Transparency:** opacity masks (clip/invert/disable/link), exported as SVG `<mask>` and PDF soft masks. The constant alpha soft mask that PDF and `.ai` export draw a CMYK page with transparency through is white, so applications that read every soft mask by its luminosity show the page too (#1359, part of #1286).
|
||||
Isolation mode and opacity mask editing exclude each other ([transparency and blending modes](https://web.archive.org/web/20230102045151/https://helpx.adobe.com/illustrator/using/transparency-blending-modes.html)): in isolation mode a click or Alt-click on the mask thumbnail does not edit the mask, and Make Mask is off for one object; while a mask is edited, Enter Isolation Mode and Object › Perspective › Edit Text are off, the Contextual Task Bar leaves out Isolate, and Quick Actions leave out Isolate Group.
|
||||
|
||||
Reference in New Issue
Block a user