Draw mathcal letters from cmsy10
This commit is contained in:
1 parent
66ceabad0e
commit
e229809581
7 files changed
+114
-8
No files matched your search
@@ -15,6 +15,8 @@ pub enum Cmr10Metrics {
|
||||
BoldItalic,
|
||||
Mono,
|
||||
Sans,
|
||||
/// Calligraphic capitals from cmsy10 (`\mathcal`).
|
||||
MathCalligraphic,
|
||||
/// Math face: italic letters from cmmi10, big operators from cmex10.
|
||||
Math,
|
||||
}
|
||||
@@ -100,6 +102,7 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
Cmr10Metrics::Mono => CMTT10_METRICS.get_or_init(parse_mono),
|
||||
Cmr10Metrics::Sans => CMSS10_METRICS.get_or_init(parse_sans),
|
||||
Cmr10Metrics::Math => CMR10_METRICS.get_or_init(parse_roman),
|
||||
Cmr10Metrics::MathCalligraphic => CMSY10_METRICS.get_or_init(parse_math_symbol),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +142,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.is_math() && character.is_ascii_alphabetic() {
|
||||
let width = math_italic_metrics().width(character);
|
||||
if width > 0 {
|
||||
@@ -164,6 +173,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.is_math() && character.is_ascii_alphabetic() {
|
||||
let height = math_italic_metrics().height(character);
|
||||
if height > 0 {
|
||||
@@ -182,6 +197,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.is_math() && character.is_ascii_alphabetic() {
|
||||
let depth = math_italic_metrics().depth(character);
|
||||
if depth > 0 {
|
||||
@@ -200,6 +221,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.is_math() && character.is_ascii_alphabetic() {
|
||||
return math_italic_metrics().italic(character);
|
||||
}
|
||||
@@ -298,6 +325,26 @@ pub fn math_extension_slot(character: char) -> Option<u8> {
|
||||
Some(slot)
|
||||
}
|
||||
|
||||
/// Advance width of a `cmsy10` glyph addressed by a Unicode math character.
|
||||
pub fn math_symbol_width(character: char) -> Option<i64> {
|
||||
if character.is_ascii_uppercase() {
|
||||
let width = math_symbol_metrics().width(character);
|
||||
if width > 0 {
|
||||
return Some(width);
|
||||
}
|
||||
}
|
||||
math_symbol_slot(character)
|
||||
.map(|slot| math_symbol_metrics().width(char::from(slot)))
|
||||
.filter(|width| *width > 0)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
.map(|slot| math_extension_metrics().width(char::from(slot)))
|
||||
.filter(|width| *width > 0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user