mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Use extended shape information for glyph text_like
-ness (#5483)
This commit is contained in:
parent
6bf1350b16
commit
f29fbea2fc
@ -148,7 +148,8 @@ impl MathFragment {
|
|||||||
|
|
||||||
pub fn is_text_like(&self) -> bool {
|
pub fn is_text_like(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Glyph(_) | Self::Variant(_) => self.class() != MathClass::Large,
|
Self::Glyph(glyph) => !glyph.extended_shape,
|
||||||
|
Self::Variant(variant) => !variant.extended_shape,
|
||||||
MathFragment::Frame(frame) => frame.text_like,
|
MathFragment::Frame(frame) => frame.text_like,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -247,6 +248,7 @@ pub struct GlyphFragment {
|
|||||||
pub dests: SmallVec<[Destination; 1]>,
|
pub dests: SmallVec<[Destination; 1]>,
|
||||||
pub hidden: bool,
|
pub hidden: bool,
|
||||||
pub limits: Limits,
|
pub limits: Limits,
|
||||||
|
pub extended_shape: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlyphFragment {
|
impl GlyphFragment {
|
||||||
@ -302,6 +304,7 @@ impl GlyphFragment {
|
|||||||
span,
|
span,
|
||||||
dests: LinkElem::dests_in(styles),
|
dests: LinkElem::dests_in(styles),
|
||||||
hidden: HideElem::hidden_in(styles),
|
hidden: HideElem::hidden_in(styles),
|
||||||
|
extended_shape: false,
|
||||||
};
|
};
|
||||||
fragment.set_id(ctx, id);
|
fragment.set_id(ctx, id);
|
||||||
fragment
|
fragment
|
||||||
@ -332,7 +335,8 @@ impl GlyphFragment {
|
|||||||
let accent_attach =
|
let accent_attach =
|
||||||
accent_attach(ctx, id, self.font_size).unwrap_or((width + italics) / 2.0);
|
accent_attach(ctx, id, self.font_size).unwrap_or((width + italics) / 2.0);
|
||||||
|
|
||||||
if !is_extended_shape(ctx, id) {
|
let extended_shape = is_extended_shape(ctx, id);
|
||||||
|
if !extended_shape {
|
||||||
width += italics;
|
width += italics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,6 +346,7 @@ impl GlyphFragment {
|
|||||||
self.descent = -bbox.y_min.scaled(ctx, self.font_size);
|
self.descent = -bbox.y_min.scaled(ctx, self.font_size);
|
||||||
self.italics_correction = italics;
|
self.italics_correction = italics;
|
||||||
self.accent_attach = accent_attach;
|
self.accent_attach = accent_attach;
|
||||||
|
self.extended_shape = extended_shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> Abs {
|
pub fn height(&self) -> Abs {
|
||||||
@ -358,6 +363,7 @@ impl GlyphFragment {
|
|||||||
math_size: self.math_size,
|
math_size: self.math_size,
|
||||||
span: self.span,
|
span: self.span,
|
||||||
limits: self.limits,
|
limits: self.limits,
|
||||||
|
extended_shape: self.extended_shape,
|
||||||
frame: self.into_frame(),
|
frame: self.into_frame(),
|
||||||
mid_stretched: None,
|
mid_stretched: None,
|
||||||
}
|
}
|
||||||
@ -465,6 +471,7 @@ pub struct VariantFragment {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub limits: Limits,
|
pub limits: Limits,
|
||||||
pub mid_stretched: Option<bool>,
|
pub mid_stretched: Option<bool>,
|
||||||
|
pub extended_shape: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VariantFragment {
|
impl VariantFragment {
|
||||||
|
@ -295,6 +295,7 @@ fn assemble(
|
|||||||
span: base.span,
|
span: base.span,
|
||||||
limits: base.limits,
|
limits: base.limits,
|
||||||
mid_stretched: None,
|
mid_stretched: None,
|
||||||
|
extended_shape: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/ref/math-attach-scripts-extended-shapes.png
Normal file
BIN
tests/ref/math-attach-scripts-extended-shapes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
tests/ref/math-lr-scripts.png
Normal file
BIN
tests/ref/math-lr-scripts.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 611 B |
BIN
tests/ref/math-stretch-vertical-scripts.png
Normal file
BIN
tests/ref/math-stretch-vertical-scripts.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 379 B |
@ -170,3 +170,9 @@ $ attach(a^b, b: c) quad
|
|||||||
|
|
||||||
$ a0 + a1 + a0_2 \
|
$ a0 + a1 + a0_2 \
|
||||||
a1_2 + a0^2 + a1^2 $
|
a1_2 + a0^2 + a1^2 $
|
||||||
|
|
||||||
|
--- math-attach-scripts-extended-shapes ---
|
||||||
|
// Test script attachments positioning if the base is an extended shape (or a
|
||||||
|
// sequence of extended shapes).
|
||||||
|
$lr(size: #130%, [x])_0^1, [x]_0^1, \]_0^1, x_0^1, A_0^1$ \
|
||||||
|
$n^2, (n + 1)^2, sum_0^1, integral_0^1$
|
||||||
|
@ -115,6 +115,12 @@ $lr(body2, size: #50%)$
|
|||||||
$ (1 / 2) $
|
$ (1 / 2) $
|
||||||
})
|
})
|
||||||
|
|
||||||
|
--- math-lr-scripts ---
|
||||||
|
// Test interactions with script attachments.
|
||||||
|
$ lr(size: #3em, |)_a^b lr(size: #3em, zws|)_a^b
|
||||||
|
lr(size: #3em, [x])_0^1 [x]_0^1
|
||||||
|
lr(size: #1em, lr(size: #10em, [x]))_0^1 $
|
||||||
|
|
||||||
--- issue-4188-lr-corner-brackets ---
|
--- issue-4188-lr-corner-brackets ---
|
||||||
// Test positioning of U+231C to U+231F
|
// Test positioning of U+231C to U+231F
|
||||||
$⌜a⌟⌞b⌝$ = $⌜$$a$$⌟$$⌞$$b$$⌝$
|
$⌜a⌟⌞b⌝$ = $⌜$$a$$⌟$$⌞$$b$$⌝$
|
||||||
|
@ -35,6 +35,12 @@ $stretch(arrow.t)^"map"$
|
|||||||
$stretch(arrow.t, size: #2em)^"map"$
|
$stretch(arrow.t, size: #2em)^"map"$
|
||||||
$stretch(arrow.t, size: #200%)^"map"$
|
$stretch(arrow.t, size: #200%)^"map"$
|
||||||
|
|
||||||
|
--- math-stretch-vertical-scripts ---
|
||||||
|
// Test vertical stretch interactions with script attachments.
|
||||||
|
#let big = $stretch(|, size: #4em)$
|
||||||
|
$ big_0^1 stretch(|, size: #1.5em)_0^1
|
||||||
|
stretch(big, size: #1em)_0^1 |_0^1 $
|
||||||
|
|
||||||
--- math-stretch-horizontal ---
|
--- math-stretch-horizontal ---
|
||||||
// Test stretching along horizontal axis.
|
// Test stretching along horizontal axis.
|
||||||
#let ext(sym) = math.stretch(sym, size: 2em)
|
#let ext(sym) = math.stretch(sym, size: 2em)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user