Add Fraktur letters, infix fractions and middle delimiters
- bundle eufm10 (TFM + Type1), add the MathFraktur face and map \mathfrak
onto it, including PDF embedding and width lookup;
- parse TeX's infix fractions (\over, \atop, \choose, \brace,
\brack, \overwithdelims, \atopwithdelims): the rest of the current
row becomes the denominator, ar records whether a rule is drawn, and the
painter no longer emits parentheses (a \frac painter bug) and only draws
the bar for \over forms;
- add MathAtom::Middle, size top-level middle delimiters with the enclosing
\left/\right group through the CMEX size classes, and paint
SizedDelimiter at its selected size instead of the base glyph;
- skip the parser's '\u{0}' math spaces before \big, \middle,
\left and the withdelims delimiters, so \big ( parses like \big(.
560 workspace tests (381 route-D unit).
This commit is contained in:
1 parent
cb40cc4634
commit
8c42f2de2f
10 files changed
+499
-72
No files matched your search
@@ -19,6 +19,8 @@ pub enum Cmr10Metrics {
|
||||
MathCalligraphic,
|
||||
/// Blackboard-bold capitals from msbm10 (`\mathbb`).
|
||||
MathBlackboard,
|
||||
/// Euler Fraktur letters from eufm10 (`\mathfrak`).
|
||||
MathFraktur,
|
||||
/// Math face: italic letters from cmmi10, big operators from cmex10.
|
||||
Math,
|
||||
}
|
||||
@@ -33,6 +35,7 @@ static CMMI10_TFM: &[u8] = include_bytes!("../assets/cmmi10.tfm");
|
||||
static CMEX10_TFM: &[u8] = include_bytes!("../assets/cmex10.tfm");
|
||||
static CMSY10_TFM: &[u8] = include_bytes!("../assets/cmsy10.tfm");
|
||||
static MSBM10_TFM: &[u8] = include_bytes!("../assets/msbm10.tfm");
|
||||
static EUFM10_TFM: &[u8] = include_bytes!("../assets/eufm10.tfm");
|
||||
|
||||
static CMR10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
@@ -44,6 +47,7 @@ static CMMI10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMEX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMSY10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static MSBM10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static EUFM10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
|
||||
fn parse(bytes: &[u8]) -> TfmMetrics {
|
||||
TfmMetrics::parse(bytes).expect("embedded TFM must be valid")
|
||||
@@ -105,6 +109,14 @@ fn math_blackboard_metrics() -> &'static TfmMetrics {
|
||||
MSBM10_METRICS.get_or_init(parse_blackboard)
|
||||
}
|
||||
|
||||
fn parse_fraktur() -> TfmMetrics {
|
||||
parse(EUFM10_TFM)
|
||||
}
|
||||
|
||||
fn math_fraktur_metrics() -> &'static TfmMetrics {
|
||||
EUFM10_METRICS.get_or_init(parse_fraktur)
|
||||
}
|
||||
|
||||
fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
match font {
|
||||
Cmr10Metrics::Roman => CMR10_METRICS.get_or_init(parse_roman),
|
||||
@@ -116,6 +128,7 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
Cmr10Metrics::Math => CMR10_METRICS.get_or_init(parse_roman),
|
||||
Cmr10Metrics::MathCalligraphic => CMSY10_METRICS.get_or_init(parse_math_symbol),
|
||||
Cmr10Metrics::MathBlackboard => MSBM10_METRICS.get_or_init(parse_blackboard),
|
||||
Cmr10Metrics::MathFraktur => EUFM10_METRICS.get_or_init(parse_fraktur),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +161,7 @@ impl Cmr10Metrics {
|
||||
7 => Self::Math,
|
||||
8 => Self::Math,
|
||||
9 => Self::MathBlackboard,
|
||||
10 => Self::MathFraktur,
|
||||
_ => Self::Roman,
|
||||
}
|
||||
}
|
||||
@@ -157,14 +171,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
|
||||
pub fn width(&self, character: char) -> i64 {
|
||||
if *self == Self::MathCalligraphic {
|
||||
if character.is_ascii_uppercase() {
|
||||
return self.metrics().width(character);
|
||||
}
|
||||
return Self::Math.width(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
if character.is_ascii_uppercase() {
|
||||
if matches!(
|
||||
*self,
|
||||
Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur
|
||||
) {
|
||||
let capital_only = *self != Self::MathFraktur;
|
||||
if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) {
|
||||
return self.metrics().width(character);
|
||||
}
|
||||
return Self::Math.width(character);
|
||||
@@ -194,14 +206,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
|
||||
pub fn height(&self, character: char) -> i64 {
|
||||
if *self == Self::MathCalligraphic {
|
||||
if character.is_ascii_uppercase() {
|
||||
return self.metrics().height(character);
|
||||
}
|
||||
return Self::Math.height(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
if character.is_ascii_uppercase() {
|
||||
if matches!(
|
||||
*self,
|
||||
Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur
|
||||
) {
|
||||
let capital_only = *self != Self::MathFraktur;
|
||||
if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) {
|
||||
return self.metrics().height(character);
|
||||
}
|
||||
return Self::Math.height(character);
|
||||
@@ -224,14 +234,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
|
||||
pub fn depth(&self, character: char) -> i64 {
|
||||
if *self == Self::MathCalligraphic {
|
||||
if character.is_ascii_uppercase() {
|
||||
return self.metrics().depth(character);
|
||||
}
|
||||
return Self::Math.depth(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
if character.is_ascii_uppercase() {
|
||||
if matches!(
|
||||
*self,
|
||||
Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur
|
||||
) {
|
||||
let capital_only = *self != Self::MathFraktur;
|
||||
if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) {
|
||||
return self.metrics().depth(character);
|
||||
}
|
||||
return Self::Math.depth(character);
|
||||
@@ -254,14 +262,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
|
||||
pub fn italic(&self, character: char) -> i64 {
|
||||
if *self == Self::MathCalligraphic {
|
||||
if character.is_ascii_uppercase() {
|
||||
return self.metrics().italic(character);
|
||||
}
|
||||
return Self::Math.italic(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
if character.is_ascii_uppercase() {
|
||||
if matches!(
|
||||
*self,
|
||||
Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur
|
||||
) {
|
||||
let capital_only = *self != Self::MathFraktur;
|
||||
if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) {
|
||||
return self.metrics().italic(character);
|
||||
}
|
||||
return Self::Math.italic(character);
|
||||
@@ -388,6 +394,17 @@ pub fn math_blackboard_width(character: char) -> Option<i64> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Advance width of an `eufm10` Fraktur letter.
|
||||
pub fn math_fraktur_width(character: char) -> Option<i64> {
|
||||
if character.is_ascii_alphabetic() {
|
||||
let width = math_fraktur_metrics().width(character);
|
||||
if width > 0 {
|
||||
return Some(width);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Advance width of a `cmex10` glyph addressed by a Unicode n-ary operator.
|
||||
pub fn math_extension_width(character: char) -> Option<i64> {
|
||||
math_extension_slot(character)
|
||||
|
||||
Reference in new issue
Block a user