mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Treat italics correction differently
This commit is contained in:
parent
8377159e21
commit
aa0f03fe04
@ -192,11 +192,8 @@ fn scripts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let italics = base.italics_correction();
|
let italics = base.italics_correction();
|
||||||
|
let sup_delta = Abs::zero();
|
||||||
let sub_delta = -italics;
|
let sub_delta = -italics;
|
||||||
let sup_delta = match base.class() {
|
|
||||||
Some(MathClass::Large) => Abs::zero(),
|
|
||||||
_ => italics,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut width = Abs::zero();
|
let mut width = Abs::zero();
|
||||||
let mut ascent = base.ascent();
|
let mut ascent = base.ascent();
|
||||||
|
@ -152,13 +152,19 @@ impl GlyphFragment {
|
|||||||
x_max: 0,
|
x_max: 0,
|
||||||
y_max: 0,
|
y_max: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut width = advance.scaled(ctx);
|
||||||
|
if !is_extended_shape(ctx, id) {
|
||||||
|
width += italics;
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
c,
|
c,
|
||||||
lang: ctx.styles().get(TextNode::LANG),
|
lang: ctx.styles().get(TextNode::LANG),
|
||||||
fill: ctx.styles().get(TextNode::FILL),
|
fill: ctx.styles().get(TextNode::FILL),
|
||||||
font_size: ctx.size,
|
font_size: ctx.size,
|
||||||
width: advance.scaled(ctx),
|
width,
|
||||||
ascent: bbox.y_max.scaled(ctx),
|
ascent: bbox.y_max.scaled(ctx),
|
||||||
descent: -bbox.y_min.scaled(ctx),
|
descent: -bbox.y_min.scaled(ctx),
|
||||||
italics_correction: italics,
|
italics_correction: italics,
|
||||||
@ -249,6 +255,15 @@ fn italics_correction(ctx: &MathContext, id: GlyphId) -> Option<Abs> {
|
|||||||
Some(ctx.table.glyph_info?.italic_corrections?.get(id)?.scaled(ctx))
|
Some(ctx.table.glyph_info?.italic_corrections?.get(id)?.scaled(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Look up the italics correction for a glyph.
|
||||||
|
fn is_extended_shape(ctx: &MathContext, id: GlyphId) -> bool {
|
||||||
|
ctx.table
|
||||||
|
.glyph_info
|
||||||
|
.and_then(|info| info.extended_shapes)
|
||||||
|
.and_then(|info| info.get(id))
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Look up a kerning value at a specific corner and height.
|
/// Look up a kerning value at a specific corner and height.
|
||||||
///
|
///
|
||||||
/// This can be integrated once we've found a font that actually provides this
|
/// This can be integrated once we've found a font that actually provides this
|
||||||
|
@ -59,10 +59,6 @@ impl MathRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut amount = Abs::zero();
|
let mut amount = Abs::zero();
|
||||||
if let MathFragment::Glyph(glyph) = *prev {
|
|
||||||
amount += glyph.italics_correction;
|
|
||||||
}
|
|
||||||
|
|
||||||
amount += spacing(prev, &fragment, style, space, space_width).at(font_size);
|
amount += spacing(prev, &fragment, style, space, space_width).at(font_size);
|
||||||
|
|
||||||
if !amount.is_zero() {
|
if !amount.is_zero() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user