Implement XeTeX OpenType letterspacing and contextual line widths
This commit is contained in:
1 parent
4a77540e46
commit
cc0246016d
10 files changed
+223
-97
No files matched your search
@@ -92,6 +92,9 @@ fn shape_row(
|
||||
let TextNode::OpenType(first) = node else {
|
||||
continue;
|
||||
};
|
||||
if first.font.letter_space() != 0 {
|
||||
continue;
|
||||
}
|
||||
let mut text = String::new();
|
||||
let mut sources = Vec::new();
|
||||
let mut units = 0;
|
||||
|
||||
@@ -70,11 +70,12 @@ impl Executor {
|
||||
}
|
||||
let font = self.font_identifier(files)?;
|
||||
let slot = self.integer(files)?;
|
||||
if let Some(face) = self.state.fonts.font(font).map_err(|e| self.error(e, self.current))?.opentype() {
|
||||
let instance = self.state.fonts.font(font).map_err(|e| self.error(e, self.current))?;
|
||||
if let Some(face) = instance.opentype() {
|
||||
let character = u32::try_from(slot).ok().and_then(char::from_u32)
|
||||
.ok_or_else(|| self.error("invalid Unicode font character", self.current))?;
|
||||
let metrics = face.glyph_metrics(character)
|
||||
.map_err(|e| self.error(e, self.current))?.unwrap_or([0; 4]);
|
||||
let metrics = face.glyph_metrics(character, instance.parameters())
|
||||
.map_err(|e| self.error(e, self.current))?;
|
||||
return Ok(match p {
|
||||
Primitive::Fontcharwd => metrics[0],
|
||||
Primitive::Fontcharht => metrics[1],
|
||||
@@ -85,13 +86,7 @@ impl Executor {
|
||||
}
|
||||
let slot = u8::try_from(slot)
|
||||
.map_err(|_| self.error("font character index must be in 0..255", self.current))?;
|
||||
let Some(m) = self
|
||||
.state
|
||||
.fonts
|
||||
.font(font)
|
||||
.map_err(|e| self.error(e, self.current))?
|
||||
.metrics()
|
||||
else {
|
||||
let Some(m) = instance.metrics() else {
|
||||
return Ok(0);
|
||||
};
|
||||
let c = char::from(slot);
|
||||
|
||||
@@ -131,6 +131,10 @@ impl Executor {
|
||||
};
|
||||
let italic = match paragraph.nodes.last() {
|
||||
Some(TextNode::Glyph { glyph, .. } | TextNode::MathChar(glyph)) => glyph.italic,
|
||||
Some(TextNode::OpenType(run)) if self.state.input_profile() == InputProfile::XeTeX => {
|
||||
run.glyphs.last().map_or(Ok(0), |glyph| run.font.italic_correction(glyph.id))
|
||||
.map_err(|error| self.error(error, self.current))?
|
||||
}
|
||||
_ => return Ok(()),
|
||||
};
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
|
||||
@@ -450,7 +450,7 @@ impl FontCatalog {
|
||||
area: String::new(),
|
||||
resource: Some(resource),
|
||||
glyph_font: None,
|
||||
opentype: Some(Arc::new(font)),
|
||||
opentype: Some(font),
|
||||
parameters: Arc::new(parameters),
|
||||
integers: defaults,
|
||||
selector,
|
||||
|
||||
@@ -626,6 +626,7 @@ struct Active {
|
||||
serial: usize,
|
||||
previous: usize,
|
||||
start: usize,
|
||||
measurement_start: usize,
|
||||
post_break: Option<usize>,
|
||||
line: usize,
|
||||
fitness: u8,
|
||||
@@ -793,6 +794,7 @@ fn break_lines(
|
||||
projected[i - 1],
|
||||
BreakNode::Content(_)
|
||||
| BreakNode::AccentKern(_)
|
||||
| BreakNode::SpaceAdjustment(_)
|
||||
| BreakNode::Discretionary { .. }
|
||||
| BreakNode::Kern {
|
||||
explicit: false,
|
||||
@@ -873,6 +875,7 @@ fn break_lines(
|
||||
serial: 0,
|
||||
previous: 0,
|
||||
start: 0,
|
||||
measurement_start: 0,
|
||||
post_break: None,
|
||||
line: 0,
|
||||
fitness: 1,
|
||||
@@ -922,7 +925,7 @@ fn break_lines(
|
||||
let (natural, mut stretch, shrink) = break_cache::candidate_widths(
|
||||
projected,
|
||||
&widths,
|
||||
a.start,
|
||||
a.measurement_start,
|
||||
b.end,
|
||||
a.post_break,
|
||||
b.pre_break,
|
||||
@@ -1030,15 +1033,22 @@ fn break_lines(
|
||||
let mut path = a.path.clone();
|
||||
path.push((b, bad));
|
||||
let mut next = b.next;
|
||||
let mut measurement_start = None;
|
||||
while !b.pre_break.is_some_and(|i| projected[i].has_post())
|
||||
&& projected.get(next).is_some_and(BreakNode::discardable)
|
||||
{
|
||||
// XeTeX stops subtracting discardable widths at a space
|
||||
// adjustment during search, then drops it when packing.
|
||||
if matches!(projected[next], BreakNode::SpaceAdjustment(_)) {
|
||||
measurement_start.get_or_insert(next);
|
||||
}
|
||||
next += 1;
|
||||
}
|
||||
let candidate = Active {
|
||||
serial: 0,
|
||||
previous: a.serial,
|
||||
start: next,
|
||||
measurement_start: measurement_start.unwrap_or(next),
|
||||
post_break: b.pre_break,
|
||||
line: a.line + 1,
|
||||
fitness,
|
||||
|
||||
@@ -134,6 +134,7 @@ pub(super) enum BreakNode {
|
||||
replacement_count: u8,
|
||||
},
|
||||
AccentKern(i32),
|
||||
SpaceAdjustment(i32),
|
||||
Direction,
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ impl BreakNode {
|
||||
TextNode::MarginKern { width, .. } | TextNode::AutoKern(width) => {
|
||||
Self::Content(i64::from(*width))
|
||||
}
|
||||
TextNode::SpaceAdjustment(width) => Self::Kern { width: *width, explicit: false },
|
||||
TextNode::SpaceAdjustment(width) => Self::SpaceAdjustment(*width),
|
||||
TextNode::Kern { width, explicit } => Self::Kern {
|
||||
width: *width,
|
||||
explicit: *explicit,
|
||||
@@ -194,6 +195,7 @@ impl BreakNode {
|
||||
},
|
||||
Self::Kern { width, .. }
|
||||
| Self::AccentKern(width)
|
||||
| Self::SpaceAdjustment(width)
|
||||
| Self::MathBoundary { width, .. } => Widths {
|
||||
natural: i64::from(width),
|
||||
..Default::default()
|
||||
@@ -214,7 +216,12 @@ impl BreakNode {
|
||||
pub(super) fn discardable(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Glue(_) | Self::Kern { .. } | Self::MathBoundary { .. } | Self::Direction | Self::Penalty(_)
|
||||
Self::Glue(_)
|
||||
| Self::Kern { .. }
|
||||
| Self::SpaceAdjustment(_)
|
||||
| Self::MathBoundary { .. }
|
||||
| Self::Direction
|
||||
| Self::Penalty(_)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,20 @@ pub(crate) struct Request {
|
||||
language: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mapping: Option<String>,
|
||||
// XeTeX reads the percentage into a single-precision float. Store its
|
||||
// bits so it can also be part of the font's deterministic identity.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
letterspace: Option<u32>,
|
||||
}
|
||||
|
||||
fn read_decimal_prefix(value: &str) -> f64 {
|
||||
let value = value.trim_start_matches([' ', '\t']);
|
||||
let digits = value.strip_prefix(['-', '+']).unwrap_or(value);
|
||||
let integer = digits.bytes().take_while(u8::is_ascii_digit).count();
|
||||
let fraction = digits[integer..].strip_prefix('.')
|
||||
.map_or(0, |tail| 1 + tail.bytes().take_while(u8::is_ascii_digit).count());
|
||||
let end = value.len() - digits.len() + integer + fraction;
|
||||
value[..end].parse().unwrap_or(0.)
|
||||
}
|
||||
|
||||
impl Request {
|
||||
@@ -77,6 +91,7 @@ impl Request {
|
||||
script: None,
|
||||
language: None,
|
||||
mapping: None,
|
||||
letterspace: None,
|
||||
};
|
||||
for feature in features
|
||||
.split([';', ','])
|
||||
@@ -96,6 +111,12 @@ impl Request {
|
||||
return Err("empty TECkit font mapping name".into());
|
||||
}
|
||||
request.mapping = Some(format!("{name}.tec"));
|
||||
} else if let Some(value) = feature.strip_prefix("letterspace=") {
|
||||
let value = read_decimal_prefix(value) as f32;
|
||||
if !value.is_finite() {
|
||||
return Err("OpenType letterspace percentage exceeds the supported range".into());
|
||||
}
|
||||
request.letterspace = (value != 0.).then(|| value.to_bits());
|
||||
} else {
|
||||
feature
|
||||
.parse::<Feature>()
|
||||
@@ -106,6 +127,12 @@ impl Request {
|
||||
Ok(request)
|
||||
}
|
||||
|
||||
fn letter_space(&self, size: i64) -> f64 {
|
||||
self.letterspace.map_or(0., |bits| {
|
||||
(f64::from(f32::from_bits(bits)) / 100. * size as f64).trunc()
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn resource_names(&self) -> Vec<(ResourceKind, String)> {
|
||||
match Path::new(&self.file)
|
||||
.extension()
|
||||
@@ -207,7 +234,7 @@ impl OpenTypeFont {
|
||||
request: Request,
|
||||
mapping: Option<Arc<FontMapping>>,
|
||||
size: FontSize,
|
||||
) -> Result<(Self, Vec<i32>), String> {
|
||||
) -> Result<(Arc<Self>, Vec<i32>), String> {
|
||||
let face = ttf_parser::Face::parse(&resource.data, request.index).map_err(|error| {
|
||||
format!(
|
||||
"invalid OpenType face {}: {error}",
|
||||
@@ -228,6 +255,10 @@ impl OpenTypeFont {
|
||||
FontSize::Scaled(ratio) => design_size * i64::from(ratio) / 1000,
|
||||
};
|
||||
FontSize::At(size).validate()?;
|
||||
let letter_space = request.letter_space(size);
|
||||
if !letter_space.is_finite() || letter_space.abs() > 1_073_741_823. {
|
||||
return Err("OpenType letterspace exceeds the TeX dimension range".into());
|
||||
}
|
||||
let scale = |value| scale_units(value, size, face.units_per_em());
|
||||
let [ascent, descent] = sized_face_metrics(&face, size);
|
||||
let xheight = |reported: Option<i16>, letter: char, fallback: i64| {
|
||||
@@ -240,38 +271,40 @@ impl OpenTypeFont {
|
||||
|value| scale(i64::from(value)),
|
||||
)
|
||||
};
|
||||
let advance = |character| {
|
||||
face.glyph_index(character)
|
||||
.and_then(|id| face.glyph_hor_advance(id))
|
||||
.map_or(0, |w| scale(i64::from(w)))
|
||||
};
|
||||
let space = advance(' ');
|
||||
let slant = (-f64::from(face.italic_angle()).to_radians().tan() * 65536.).round() as i32;
|
||||
let mut params = vec![
|
||||
slant,
|
||||
space as i32,
|
||||
(space / 2) as i32,
|
||||
(space / 3) as i32,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
xheight(face.x_height(), 'x', ascent / 2) as i32,
|
||||
size as i32,
|
||||
(space / 3) as i32,
|
||||
0,
|
||||
xheight(face.capital_height(), 'X', ascent) as i32,
|
||||
];
|
||||
font_info::append_math_parameters(&face, size, &mut params);
|
||||
Ok((
|
||||
Self {
|
||||
id,
|
||||
resource,
|
||||
name,
|
||||
size,
|
||||
design_size,
|
||||
ascent,
|
||||
descent,
|
||||
request,
|
||||
mapping,
|
||||
},
|
||||
params,
|
||||
))
|
||||
let font = Arc::new(Self {
|
||||
id,
|
||||
resource,
|
||||
name,
|
||||
size,
|
||||
design_size,
|
||||
ascent,
|
||||
descent,
|
||||
request,
|
||||
mapping,
|
||||
});
|
||||
// The unmapped space can itself undergo OpenType substitution.
|
||||
// XeTeX adds tracking to its glue even for a single shaped glyph.
|
||||
let space = font.shape_mapped(" ".into(), Vec::new(), false)?.width + font.letter_space();
|
||||
if space.abs() > 1_073_741_823 {
|
||||
return Err("OpenType interword space exceeds the TeX dimension range".into());
|
||||
}
|
||||
params[1] = space as i32;
|
||||
params[2] = (space / 2) as i32;
|
||||
params[3] = (space / 3) as i32;
|
||||
params[6] = params[3];
|
||||
Ok((font, params))
|
||||
}
|
||||
|
||||
pub(crate) fn requested_size(&self, size: FontSize) -> i64 {
|
||||
@@ -299,30 +332,48 @@ impl OpenTypeFont {
|
||||
self.request.index
|
||||
}
|
||||
|
||||
pub(crate) fn glyph_metrics(&self, character: char) -> Result<Option<[i64; 4]>, String> {
|
||||
pub(crate) fn letter_space(&self) -> i64 {
|
||||
self.request.letter_space(self.size) as i64
|
||||
}
|
||||
|
||||
pub(crate) fn italic_correction(&self, glyph: u16) -> Result<i64, String> {
|
||||
let face = self.face()?;
|
||||
let Some(id) = face.glyph_index(character) else {
|
||||
return Ok(None);
|
||||
let glyph = GlyphId(glyph);
|
||||
let [_, _, right, _] = glyph_control_bounds(&face, glyph);
|
||||
let advance = f32::from(face.glyph_hor_advance(glyph).unwrap_or(0));
|
||||
let points = |units| units_to_points(units, self.size, face.units_per_em());
|
||||
Ok(points_to_sp((points(right) - points(advance)).max(0.)) + self.letter_space())
|
||||
}
|
||||
|
||||
pub(crate) fn glyph_metrics(
|
||||
&self,
|
||||
character: char,
|
||||
font_dimensions: &[i32],
|
||||
) -> Result<[i64; 4], String> {
|
||||
let face = self.face()?;
|
||||
let glyph = face.glyph_index(character).unwrap_or(GlyphId(0));
|
||||
let [_, bottom, right, top] = glyph_control_bounds(&face, glyph);
|
||||
let points = |units| units_to_points(units, self.size, face.units_per_em());
|
||||
let advance = points(f32::from(face.glyph_hor_advance(glyph).unwrap_or(0)));
|
||||
let mut height = points_to_sp(points(top));
|
||||
let mut depth = points_to_sp(-points(bottom));
|
||||
let fuzz = i64::from(font_dimensions[5] / 25);
|
||||
let snap = |value: &mut i64, zone: i64| {
|
||||
if (*value - zone).abs() <= fuzz {
|
||||
*value = zone;
|
||||
}
|
||||
};
|
||||
let bounds = face.glyph_bounding_box(id);
|
||||
let advance = face.glyph_hor_advance(id).unwrap_or(0);
|
||||
let italic = bounds
|
||||
.map_or(0, |bounds| i64::from(bounds.x_max) - i64::from(advance))
|
||||
.max(0);
|
||||
Ok(Some([
|
||||
scale_units(i64::from(advance), self.size, face.units_per_em()),
|
||||
scale_units(
|
||||
i64::from(bounds.map_or(0, |b| b.y_max)),
|
||||
self.size,
|
||||
face.units_per_em(),
|
||||
),
|
||||
-scale_units(
|
||||
i64::from(bounds.map_or(0, |b| b.y_min)),
|
||||
self.size,
|
||||
face.units_per_em(),
|
||||
),
|
||||
scale_units(italic, self.size, face.units_per_em()),
|
||||
]))
|
||||
snap(&mut depth, 0);
|
||||
for zone in [0, font_dimensions[4], font_dimensions[7]] {
|
||||
snap(&mut height, i64::from(zone));
|
||||
}
|
||||
let right_bearing = points_to_sp(advance - points(right));
|
||||
Ok([
|
||||
points_to_sp(advance),
|
||||
height,
|
||||
depth,
|
||||
self.letter_space() - right_bearing.min(0),
|
||||
])
|
||||
}
|
||||
|
||||
pub(crate) fn map_text(
|
||||
@@ -370,6 +421,8 @@ impl OpenTypeFont {
|
||||
let bidi = BidiInfo::new(&text, None);
|
||||
let mut glyphs = Vec::new();
|
||||
let mut x_origin = 0;
|
||||
let letter_space = self.letter_space();
|
||||
let mut tracking = 0;
|
||||
let scale = |value: i64| scale_units(value, self.size, face.tables().head.units_per_em);
|
||||
for paragraph in &bidi.paragraphs {
|
||||
let (levels, runs) = bidi.visual_runs(paragraph, paragraph.range.clone());
|
||||
@@ -403,14 +456,18 @@ impl OpenTypeFont {
|
||||
for (info, pos) in shaped.glyph_infos().iter().zip(shaped.glyph_positions()) {
|
||||
let cluster = range.start + info.cluster as usize;
|
||||
let end = starts[starts.partition_point(|at| *at <= cluster)];
|
||||
if tracking != 0 && scale(i64::from(pos.x_advance)) == 0 {
|
||||
tracking -= letter_space;
|
||||
}
|
||||
glyphs.push(OpenTypeGlyph {
|
||||
id: info.glyph_id as u16,
|
||||
x: x_origin + scale(x + i64::from(pos.x_offset)),
|
||||
x: x_origin + scale(x + i64::from(pos.x_offset)) + tracking,
|
||||
y: scale(-y - i64::from(pos.y_offset)),
|
||||
advance: scale(x + i64::from(pos.x_advance)) - scale(x),
|
||||
cluster: cluster..end,
|
||||
cluster_start: cluster != previous,
|
||||
});
|
||||
tracking += letter_space;
|
||||
x += i64::from(pos.x_advance);
|
||||
y += i64::from(pos.y_advance);
|
||||
previous = cluster;
|
||||
@@ -418,6 +475,9 @@ impl OpenTypeFont {
|
||||
x_origin += scale(x);
|
||||
}
|
||||
}
|
||||
if tracking != 0 {
|
||||
x_origin += tracking - letter_space;
|
||||
}
|
||||
let glyph_extents = (use_glyph_metrics && !glyphs.is_empty())
|
||||
.then(|| glyph_extents(&face, self.size, &glyphs));
|
||||
Ok(OpenTypeRun {
|
||||
@@ -435,45 +495,53 @@ impl OpenTypeFont {
|
||||
// FreeType's unscaled control box includes off-curve points. In particular
|
||||
// it can be larger than the tight bounds of a CFF cubic outline.
|
||||
#[derive(Default)]
|
||||
struct VerticalControlBox(Option<[f32; 2]>);
|
||||
impl VerticalControlBox {
|
||||
fn point(&mut self, y: f32) {
|
||||
let y = y.round();
|
||||
let bounds = self.0.get_or_insert([y, y]);
|
||||
bounds[0] = bounds[0].min(y);
|
||||
bounds[1] = bounds[1].max(y);
|
||||
struct GlyphControlBox(Option<[f32; 4]>);
|
||||
|
||||
impl GlyphControlBox {
|
||||
fn point(&mut self, x: f32, y: f32) {
|
||||
let (x, y) = (x.round(), y.round());
|
||||
let bounds = self.0.get_or_insert([x, y, x, y]);
|
||||
bounds[0] = bounds[0].min(x);
|
||||
bounds[1] = bounds[1].min(y);
|
||||
bounds[2] = bounds[2].max(x);
|
||||
bounds[3] = bounds[3].max(y);
|
||||
}
|
||||
}
|
||||
impl ttf_parser::OutlineBuilder for VerticalControlBox {
|
||||
fn move_to(&mut self, _: f32, y: f32) {
|
||||
self.point(y);
|
||||
|
||||
impl ttf_parser::OutlineBuilder for GlyphControlBox {
|
||||
fn move_to(&mut self, x: f32, y: f32) {
|
||||
self.point(x, y);
|
||||
}
|
||||
fn line_to(&mut self, _: f32, y: f32) {
|
||||
self.point(y);
|
||||
fn line_to(&mut self, x: f32, y: f32) {
|
||||
self.point(x, y);
|
||||
}
|
||||
fn quad_to(&mut self, _: f32, control: f32, _: f32, y: f32) {
|
||||
self.point(control);
|
||||
self.point(y);
|
||||
fn quad_to(&mut self, cx: f32, cy: f32, x: f32, y: f32) {
|
||||
self.point(cx, cy);
|
||||
self.point(x, y);
|
||||
}
|
||||
fn curve_to(&mut self, _: f32, first: f32, _: f32, second: f32, _: f32, y: f32) {
|
||||
self.point(first);
|
||||
self.point(second);
|
||||
self.point(y);
|
||||
fn curve_to(&mut self, cx1: f32, cy1: f32, cx2: f32, cy2: f32, x: f32, y: f32) {
|
||||
self.point(cx1, cy1);
|
||||
self.point(cx2, cy2);
|
||||
self.point(x, y);
|
||||
}
|
||||
fn close(&mut self) {}
|
||||
}
|
||||
|
||||
fn glyph_control_bounds(face: &ttf_parser::Face<'_>, glyph: GlyphId) -> [f32; 4] {
|
||||
let mut outline = GlyphControlBox::default();
|
||||
if face.outline_glyph(glyph, &mut outline).is_some() {
|
||||
outline.0.unwrap_or_default()
|
||||
} else {
|
||||
[0.; 4]
|
||||
}
|
||||
}
|
||||
|
||||
fn glyph_extents(face: &Face<'_>, size: i64, glyphs: &[OpenTypeGlyph]) -> [i64; 2] {
|
||||
let mut minimum = f32::INFINITY;
|
||||
let mut maximum = f32::NEG_INFINITY;
|
||||
let points = |units| units * (size as f32 / 65536.) / f32::from(face.tables().head.units_per_em);
|
||||
let points = |units| units_to_points(units, size, face.tables().head.units_per_em);
|
||||
for glyph in glyphs {
|
||||
let mut outline = VerticalControlBox::default();
|
||||
let [bottom, top] = if face.outline_glyph(GlyphId(glyph.id), &mut outline).is_some() {
|
||||
outline.0.unwrap_or_default()
|
||||
} else {
|
||||
[0., 0.]
|
||||
};
|
||||
let [_, bottom, _, top] = glyph_control_bounds(face, GlyphId(glyph.id));
|
||||
let baseline = -(glyph.y as f32 / 65536.);
|
||||
minimum = minimum.min(baseline + points(bottom));
|
||||
maximum = maximum.max(baseline + points(top));
|
||||
@@ -481,6 +549,10 @@ fn glyph_extents(face: &Face<'_>, size: i64, glyphs: &[OpenTypeGlyph]) -> [i64;
|
||||
[points_to_sp(maximum), -points_to_sp(minimum)]
|
||||
}
|
||||
|
||||
fn units_to_points(value: f32, size: i64, units: u16) -> f32 {
|
||||
value * (size as f32 / 65536.) / f32::from(units)
|
||||
}
|
||||
|
||||
fn points_to_sp(points: f32) -> i64 {
|
||||
(f64::from(points) * 65536. + 0.5) as i64
|
||||
}
|
||||
@@ -514,9 +586,8 @@ fn sized_face_metrics(face: &ttf_parser::Face<'_>, size: i64) -> [i64; 2] {
|
||||
}
|
||||
|
||||
pub(crate) fn scale_units(value: i64, size: i64, units: u16) -> i64 {
|
||||
let points = (value as f32 * (size as f32 / 65536.)) / f32::from(units);
|
||||
// XeTeX converts the float point position by adding 0.5 and truncating.
|
||||
points_to_sp(points)
|
||||
points_to_sp(units_to_points(value as f32, size, units))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -148,9 +148,7 @@ pub(crate) fn script_kern(
|
||||
return Ok(0);
|
||||
}
|
||||
let bounds = |face: &ttf_parser::Face<'_>, glyph| {
|
||||
let mut outline = VerticalControlBox::default();
|
||||
face.outline_glyph(glyph, &mut outline);
|
||||
let [bottom, top] = outline.0.unwrap_or_default();
|
||||
let [_, bottom, _, top] = glyph_control_bounds(face, glyph);
|
||||
[top as i32, -bottom as i32]
|
||||
};
|
||||
let [base_height, base_depth] = bounds(&base_face, base_id);
|
||||
@@ -218,10 +216,8 @@ pub(crate) fn painted_glyph(
|
||||
cluster: 0..text.len(),
|
||||
cluster_start: true,
|
||||
};
|
||||
let mut outline = VerticalControlBox::default();
|
||||
face.outline_glyph(id, &mut outline);
|
||||
let [bottom, top] = outline.0.unwrap_or_default();
|
||||
let points = |value| value * (font.size as f32 / 65536.) / f32::from(units);
|
||||
let [_, bottom, _, top] = glyph_control_bounds(face, id);
|
||||
let points = |value| units_to_points(value, font.size, units);
|
||||
let height = points_to_sp(points(top));
|
||||
let depth = points_to_sp(points(-bottom));
|
||||
let italic = face
|
||||
|
||||
@@ -2175,6 +2175,36 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### XeTeX OpenType 字距、单字度量与断行
|
||||
|
||||
OpenType `letterspace` 按所选字体的实际字号换算为 sp。正负字距进入
|
||||
原生字形位置和词宽,按实际字形前进距离处理零宽组合标记。原生
|
||||
词间胶取实际造型后的未映射空格宽度,非零字距禁止发页时的跨词
|
||||
合并,换算为 0 sp 时保留合并。单字宽高深和斜体修正使用实际字体
|
||||
轮廓控制点与活的字体尺寸参数。词尾的 `\/` 以最后一个字形
|
||||
生成显式 kern。断行搜索保留行首词间调整量对候选宽度的影响,
|
||||
实际装箱舍弃该行首调整量。
|
||||
[XeTeX 字距、单字度量与字体修正](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/XeTeX_ext.c#L1778-L1917)
|
||||
[断行搜索的宽度扣除](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L20310-L20336)
|
||||
[行首节点丢弃](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L21157-L21187)
|
||||
|
||||
三个同源作业共 14 页、82 个实际字形的编号、字号、顺序和坐标全部
|
||||
与参考一致。字体参数、实际轮廓度量、ActualText 和版面文本提取
|
||||
一致。保留旧版不支持字距的诊断,以及首个候选的字体查询与一页
|
||||
断行差异。复验上阶段 19 页、100 个字形、specials 位置及延迟写出,
|
||||
全部维持参考结果。XeTeX profile 和两组段落定向回归共 23 项通过。
|
||||
|
||||
三次跨文件修订把字距依次改为 12.5%、−12.5%、0%。各复用 66 步,
|
||||
重放两次调用,只更新第二页。每版的 PDF、SVG 和来源映射与独立
|
||||
全量一致。原样 ACL 加载同一 schema71 及真实已收敛辅助文件,PDF
|
||||
与 aux、out、bbl 和上一版逐字节一致。既有 ACL 整页对照仍待闭合。
|
||||
回执 `target/p3-xetex-letterspace/receipt.json` 的 SHA-256 为
|
||||
`283b8632866707e15d31a510720d2453b7268ba66ec95bb856bbba75df450533`。
|
||||
|
||||
下一入口为 OpenType `extend`,涉及水平度量、字形绘制与来源定位。
|
||||
`target/p3-xetex-font-stretch` 已冻结四页参考及当前原生在加载
|
||||
`extend=1.1875` 时的实际诊断。
|
||||
|
||||
### XeTeX 上下文词间距与跨词造型
|
||||
|
||||
`\XeTeXinterwordspaceshaping` 在扫描原生词时测量实际字体的
|
||||
|
||||
@@ -758,6 +758,16 @@ XDV 链接注释接入后,沿原样 ACL 的第二轮辅助文件和 BibTeX
|
||||
`target/p3-xdv-annotation/receipt.json`。
|
||||
[链接注释阶段记录](P2_M1_PROGRESS.md#xdv-链接注释与实际矩形)
|
||||
|
||||
#### XeTeX 字距与断行复编
|
||||
|
||||
原样 ACL 用同一 schema71、真实字体及已收敛的生成文件复编。
|
||||
PDF、aux、out、bbl 与上一版逐字节一致。另以 CFF 和 TrueType
|
||||
的 XeTeX 参考输出对照字距、实际换行和单字度量。原样 ACL 的既有
|
||||
词框顺序与光栅差异继续留在整页门禁中。
|
||||
回执 `target/p3-xetex-letterspace/receipt.json` 的 SHA-256 为
|
||||
`283b8632866707e15d31a510720d2453b7268ba66ec95bb856bbba75df450533`。
|
||||
[字距与断行阶段记录](P2_M1_PROGRESS.md#xetex-opentype-字距单字度量与断行)
|
||||
|
||||
#### XeTeX 词间造型复编
|
||||
|
||||
原样 ACL 使用同一 schema71、真实字体与已收敛生成初态复编。
|
||||
|
||||
Reference in new issue
Block a user