Draw mathbb letters from msbm10
This commit is contained in:
1 parent
e229809581
commit
cb40cc4634
7 files changed
+122
-1
No files matched your search
@@ -17,6 +17,8 @@ pub enum Cmr10Metrics {
|
||||
Sans,
|
||||
/// Calligraphic capitals from cmsy10 (`\mathcal`).
|
||||
MathCalligraphic,
|
||||
/// Blackboard-bold capitals from msbm10 (`\mathbb`).
|
||||
MathBlackboard,
|
||||
/// Math face: italic letters from cmmi10, big operators from cmex10.
|
||||
Math,
|
||||
}
|
||||
@@ -30,6 +32,7 @@ static CMSS10_TFM: &[u8] = include_bytes!("../assets/cmss10.tfm");
|
||||
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 CMR10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
@@ -40,6 +43,7 @@ static CMSS10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
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();
|
||||
|
||||
fn parse(bytes: &[u8]) -> TfmMetrics {
|
||||
TfmMetrics::parse(bytes).expect("embedded TFM must be valid")
|
||||
@@ -93,6 +97,14 @@ fn math_symbol_metrics() -> &'static TfmMetrics {
|
||||
CMSY10_METRICS.get_or_init(parse_math_symbol)
|
||||
}
|
||||
|
||||
fn parse_blackboard() -> TfmMetrics {
|
||||
parse(MSBM10_TFM)
|
||||
}
|
||||
|
||||
fn math_blackboard_metrics() -> &'static TfmMetrics {
|
||||
MSBM10_METRICS.get_or_init(parse_blackboard)
|
||||
}
|
||||
|
||||
fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
match font {
|
||||
Cmr10Metrics::Roman => CMR10_METRICS.get_or_init(parse_roman),
|
||||
@@ -103,6 +115,7 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
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),
|
||||
Cmr10Metrics::MathBlackboard => MSBM10_METRICS.get_or_init(parse_blackboard),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +146,8 @@ impl Cmr10Metrics {
|
||||
5 => Self::Sans,
|
||||
6 => Self::Math,
|
||||
7 => Self::Math,
|
||||
8 => Self::Math,
|
||||
9 => Self::MathBlackboard,
|
||||
_ => Self::Roman,
|
||||
}
|
||||
}
|
||||
@@ -148,6 +163,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
return Self::Math.width(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
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 {
|
||||
@@ -179,6 +200,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
return Self::Math.height(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
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 {
|
||||
@@ -203,6 +230,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
return Self::Math.depth(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
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 {
|
||||
@@ -227,6 +260,12 @@ impl Cmr10Metrics {
|
||||
}
|
||||
return Self::Math.italic(character);
|
||||
}
|
||||
if *self == Self::MathBlackboard {
|
||||
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);
|
||||
}
|
||||
@@ -338,6 +377,17 @@ pub fn math_symbol_width(character: char) -> Option<i64> {
|
||||
.filter(|width| *width > 0)
|
||||
}
|
||||
|
||||
/// Advance width of a `msbm10` blackboard-bold capital.
|
||||
pub fn math_blackboard_width(character: char) -> Option<i64> {
|
||||
if character.is_ascii_uppercase() {
|
||||
let width = math_blackboard_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