Merge a7fd7fae5f87c789c2edd7107655ccbad4fee148 into 9b09146a6b5e936966ed7ee73bce9dd2df3810ae

This commit is contained in:
Mikołaj 2025-05-07 12:05:39 +02:00 committed by GitHub
commit b854d3d475
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 4 deletions

View File

@ -11,7 +11,7 @@ use typst_library::layout::{
}; };
use typst_library::math::{EquationElem, MathSize}; use typst_library::math::{EquationElem, MathSize};
use typst_library::text::{Font, Glyph, Lang, Region, TextElem, TextItem}; use typst_library::text::{Font, Glyph, Lang, Region, TextElem, TextItem};
use typst_library::visualize::Paint; use typst_library::visualize::{FixedStroke, Paint};
use typst_syntax::Span; use typst_syntax::Span;
use typst_utils::default_math_class; use typst_utils::default_math_class;
use unicode_math_class::MathClass; use unicode_math_class::MathClass;
@ -227,14 +227,51 @@ impl From<FrameFragment> for MathFragment {
} }
} }
/// A single glyph in math.
#[derive(Clone)] #[derive(Clone)]
pub struct GlyphFragment { pub struct GlyphFragment {
/// The id of the glyph in the font.
pub id: GlyphId, pub id: GlyphId,
/// The base character.
pub c: char, pub c: char,
/// A single OpenType font for this glyph.
///
/// A show rule must be used to affect this.
///
/// ```example
/// #show math.equation: set text(font: "Fira Math")
/// $ f i r a m a t h $
/// ```
pub font: Font, pub font: Font,
/// An [ISO 639-1/2/3 language code.](https://en.wikipedia.org/wiki/ISO_639)
///
/// See [TextElem]
pub lang: Lang, pub lang: Lang,
/// An [ISO 3166-1 alpha-2 region code.](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
///
/// See [TextElem]
pub region: Option<Region>, pub region: Option<Region>,
/// The glyph fill paint.
///
/// ```example
/// #show math.equation: set text(fill: red)
/// $ r e d $
/// ```
pub fill: Paint, pub fill: Paint,
/// How to stroke the text.
///
/// ```example
/// #show math.equation: set text(stroke: red + 0.5pt)
/// $ r e d a g a i n $
/// ```
pub stroke: Option<FixedStroke>,
pub shift: Abs, pub shift: Abs,
pub width: Abs, pub width: Abs,
pub ascent: Abs, pub ascent: Abs,
@ -286,6 +323,7 @@ impl GlyphFragment {
lang: TextElem::lang_in(styles), lang: TextElem::lang_in(styles),
region: TextElem::region_in(styles), region: TextElem::region_in(styles),
fill: TextElem::fill_in(styles).as_decoration(), fill: TextElem::fill_in(styles).as_decoration(),
stroke: TextElem::stroke_in(styles).map(|s| s.unwrap_or_default()),
shift: TextElem::baseline_in(styles), shift: TextElem::baseline_in(styles),
font_size: TextElem::size_in(styles), font_size: TextElem::size_in(styles),
math_size: EquationElem::size_in(styles), math_size: EquationElem::size_in(styles),
@ -368,10 +406,10 @@ impl GlyphFragment {
font: self.font.clone(), font: self.font.clone(),
size: self.font_size, size: self.font_size,
fill: self.fill, fill: self.fill,
stroke: self.stroke,
lang: self.lang, lang: self.lang,
region: self.region, region: self.region,
text: self.c.into(), text: self.c.into(),
stroke: None,
glyphs: vec![Glyph { glyphs: vec![Glyph {
id: self.id.0, id: self.id.0,
x_advance: Em::from_length(self.width, self.font_size), x_advance: Em::from_length(self.width, self.font_size),

View File

@ -39,7 +39,7 @@ impl TextItem {
impl Debug for TextItem { impl Debug for TextItem {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.write_str("Text(")?; f.write_str("TextItem(")?;
self.text.fmt(f)?; self.text.fmt(f)?;
f.write_str(")") f.write_str(")")
} }

View File

@ -763,7 +763,7 @@ impl TextElem {
impl Debug for TextElem { impl Debug for TextElem {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "Text({})", self.text) write!(f, "TextElem({})", self.text)
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -297,3 +297,10 @@ Looks at the @quadratic formula.
#set page(width: 150pt) #set page(width: 150pt)
#set text(lang: "he") #set text(lang: "he")
תהא סדרה $a_n$: $[a_n: 1, 1/2, 1/3, dots]$ תהא סדרה $a_n$: $[a_n: 1, 1/2, 1/3, dots]$
--- issue-6170-equation-stroke ---
// In this bug stroke settings did not apply to math content.
// We expect all of these to have a green stroke.
#set text(stroke: green + 0.5pt)
A $B^2$ $ grave(C)' $