diff options
| author | Max <me@mkor.je> | 2024-12-20 12:35:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-20 12:35:57 +0000 |
| commit | bb38a01d0625d5bdab0af50daf479e60c774d90e (patch) | |
| tree | b588b09ce44b698e7602d84ec3e43dd86a47b552 /crates/typst-layout/src/math/shared.rs | |
| parent | 39706fe42f269b3a283eeff9b595480631737159 (diff) | |
Fix math size resolving (#5596)
Diffstat (limited to 'crates/typst-layout/src/math/shared.rs')
| -rw-r--r-- | crates/typst-layout/src/math/shared.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/typst-layout/src/math/shared.rs b/crates/typst-layout/src/math/shared.rs index 74e62e8f..5aebdaca 100644 --- a/crates/typst-layout/src/math/shared.rs +++ b/crates/typst-layout/src/math/shared.rs @@ -2,7 +2,6 @@ use ttf_parser::math::MathValue; use typst_library::foundations::{Style, StyleChain}; use typst_library::layout::{Abs, Em, FixedAlignment, Frame, Point, Size, VAlignment}; use typst_library::math::{EquationElem, MathSize}; -use typst_library::text::TextElem; use typst_utils::LazyHash; use super::{LeftRightAlternator, MathContext, MathFragment, MathRun}; @@ -18,7 +17,7 @@ macro_rules! scaled { $crate::math::Scaled::scaled( $ctx.constants.$name(), $ctx, - $crate::math::scaled_font_size($ctx, $styles), + typst_library::text::TextElem::size_in($styles), ) }; } @@ -55,16 +54,6 @@ impl Scaled for MathValue<'_> { } } -/// Get the font size scaled with the `MathSize`. -pub fn scaled_font_size(ctx: &MathContext, styles: StyleChain) -> Abs { - let factor = match EquationElem::size_in(styles) { - MathSize::Display | MathSize::Text => 1.0, - MathSize::Script => percent!(ctx, script_percent_scale_down), - MathSize::ScriptScript => percent!(ctx, script_script_percent_scale_down), - }; - factor * TextElem::size_in(styles) -} - /// Styles something as cramped. pub fn style_cramped() -> LazyHash<Style> { EquationElem::set_cramped(true).wrap() @@ -99,6 +88,15 @@ pub fn style_for_denominator(styles: StyleChain) -> [LazyHash<Style>; 2] { [style_for_numerator(styles), EquationElem::set_cramped(true).wrap()] } +/// Styles to add font constants to the style chain. +pub fn style_for_script_scale(ctx: &MathContext) -> LazyHash<Style> { + EquationElem::set_script_scale(( + ctx.constants.script_percent_scale_down(), + ctx.constants.script_script_percent_scale_down(), + )) + .wrap() +} + /// How a delimieter should be aligned when scaling. pub fn delimiter_alignment(delimiter: char) -> VAlignment { match delimiter { |
