mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Fixed symbol style reset in stretching (#1195)
This commit is contained in:
parent
84b9d9c990
commit
42c3a6fa72
@ -164,6 +164,32 @@ impl GlyphFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_id(ctx: &MathContext, c: char, id: GlyphId, span: Span) -> Self {
|
pub fn with_id(ctx: &MathContext, c: char, id: GlyphId, span: Span) -> Self {
|
||||||
|
let mut fragment = Self {
|
||||||
|
id,
|
||||||
|
c,
|
||||||
|
font: ctx.font.clone(),
|
||||||
|
lang: TextElem::lang_in(ctx.styles()),
|
||||||
|
fill: TextElem::fill_in(ctx.styles()),
|
||||||
|
style: ctx.style,
|
||||||
|
font_size: ctx.size,
|
||||||
|
width: Abs::zero(),
|
||||||
|
ascent: Abs::zero(),
|
||||||
|
descent: Abs::zero(),
|
||||||
|
italics_correction: Abs::zero(),
|
||||||
|
class: match c {
|
||||||
|
':' => Some(MathClass::Relation),
|
||||||
|
_ => unicode_math_class::class(c),
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
meta: MetaElem::data_in(ctx.styles()),
|
||||||
|
};
|
||||||
|
fragment.set_id(ctx, id);
|
||||||
|
fragment
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets element id and boxes in appropriate way without changing other
|
||||||
|
/// styles. This is used to replace the glyph with a stretch variant.
|
||||||
|
pub fn set_id(&mut self, ctx: &MathContext, id: GlyphId) {
|
||||||
let advance = ctx.ttf.glyph_hor_advance(id).unwrap_or_default();
|
let advance = ctx.ttf.glyph_hor_advance(id).unwrap_or_default();
|
||||||
let italics = italics_correction(ctx, id).unwrap_or_default();
|
let italics = italics_correction(ctx, id).unwrap_or_default();
|
||||||
let bbox = ctx.ttf.glyph_bounding_box(id).unwrap_or(Rect {
|
let bbox = ctx.ttf.glyph_bounding_box(id).unwrap_or(Rect {
|
||||||
@ -178,25 +204,11 @@ impl GlyphFragment {
|
|||||||
width += italics;
|
width += italics;
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
self.id = id;
|
||||||
id,
|
self.width = width;
|
||||||
c,
|
self.ascent = bbox.y_max.scaled(ctx);
|
||||||
font: ctx.font.clone(),
|
self.descent = -bbox.y_min.scaled(ctx);
|
||||||
lang: TextElem::lang_in(ctx.styles()),
|
self.italics_correction = italics;
|
||||||
fill: TextElem::fill_in(ctx.styles()),
|
|
||||||
style: ctx.style,
|
|
||||||
font_size: ctx.size,
|
|
||||||
width,
|
|
||||||
ascent: bbox.y_max.scaled(ctx),
|
|
||||||
descent: -bbox.y_min.scaled(ctx),
|
|
||||||
italics_correction: italics,
|
|
||||||
class: match c {
|
|
||||||
':' => Some(MathClass::Relation),
|
|
||||||
_ => unicode_math_class::class(c),
|
|
||||||
},
|
|
||||||
span,
|
|
||||||
meta: MetaElem::data_in(ctx.styles()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> Abs {
|
pub fn height(&self) -> Abs {
|
||||||
|
@ -33,7 +33,7 @@ impl GlyphFragment {
|
|||||||
/// The resulting frame may not have the exact desired width.
|
/// The resulting frame may not have the exact desired width.
|
||||||
fn stretch_glyph(
|
fn stretch_glyph(
|
||||||
ctx: &MathContext,
|
ctx: &MathContext,
|
||||||
base: GlyphFragment,
|
mut base: GlyphFragment,
|
||||||
target: Abs,
|
target: Abs,
|
||||||
short_fall: Abs,
|
short_fall: Abs,
|
||||||
horizontal: bool,
|
horizontal: bool,
|
||||||
@ -73,7 +73,8 @@ fn stretch_glyph(
|
|||||||
|
|
||||||
// This is either good or the best we've got.
|
// This is either good or the best we've got.
|
||||||
if short_target <= best_advance || construction.assembly.is_none() {
|
if short_target <= best_advance || construction.assembly.is_none() {
|
||||||
return GlyphFragment::with_id(ctx, base.c, best_id, base.span).into_variant();
|
base.set_id(ctx, best_id);
|
||||||
|
return base.into_variant();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble from parts.
|
// Assemble from parts.
|
||||||
@ -142,7 +143,8 @@ fn assemble(
|
|||||||
advance += ratio * (max_overlap - min_overlap);
|
advance += ratio * (max_overlap - min_overlap);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fragment = GlyphFragment::with_id(ctx, base.c, part.glyph_id, base.span);
|
let mut fragment = base.clone();
|
||||||
|
fragment.set_id(ctx, part.glyph_id);
|
||||||
selected.push((fragment, advance));
|
selected.push((fragment, advance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 22 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
@ -36,3 +36,10 @@ $ lr(]sum_(x=1)^n x], size: #70%)
|
|||||||
---
|
---
|
||||||
// Test predefined delimiter pairings.
|
// Test predefined delimiter pairings.
|
||||||
$floor(x/2), ceil(x/2), abs(x), norm(x)$
|
$floor(x/2), ceil(x/2), abs(x), norm(x)$
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test colored delimiters
|
||||||
|
$ lr(
|
||||||
|
text("(", fill: #green) a/b
|
||||||
|
text(")", fill: #blue)
|
||||||
|
) $
|
||||||
|
Loading…
x
Reference in New Issue
Block a user