Add sans-serif bold and italic faces
Map \sffamily with \bfseries or \itshape onto the bundled cmssbx10 and cmssi10 metrics, with their Type1 outlines embedded alongside the other Computer Modern faces. Bold italic sans substitutes cmssbx10, matching the OT1 fallback in TeX.
This commit is contained in:
1 parent
03925e3116
commit
9140990a7d
13 files changed
+223
-19
No files matched your search
@@ -15,6 +15,8 @@ pub enum Cmr10Metrics {
|
||||
BoldItalic,
|
||||
Mono,
|
||||
Sans,
|
||||
SansBold,
|
||||
SansItalic,
|
||||
/// Calligraphic capitals from cmsy10 (`\mathcal`).
|
||||
MathCalligraphic,
|
||||
/// Blackboard-bold capitals from msbm10 (`\mathbb`).
|
||||
@@ -31,6 +33,8 @@ static CMTI10_TFM: &[u8] = include_bytes!("../assets/cmti10.tfm");
|
||||
static CMBXTI10_TFM: &[u8] = include_bytes!("../assets/cmbxti10.tfm");
|
||||
static CMTT10_TFM: &[u8] = include_bytes!("../assets/cmtt10.tfm");
|
||||
static CMSS10_TFM: &[u8] = include_bytes!("../assets/cmss10.tfm");
|
||||
static CMSSBX10_TFM: &[u8] = include_bytes!("../assets/cmssbx10.tfm");
|
||||
static CMSSI10_TFM: &[u8] = include_bytes!("../assets/cmssi10.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");
|
||||
@@ -43,6 +47,8 @@ static CMTI10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMBXTI10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMTT10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMSS10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMSSBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMSSI10_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();
|
||||
@@ -77,6 +83,14 @@ fn parse_sans() -> TfmMetrics {
|
||||
parse(CMSS10_TFM)
|
||||
}
|
||||
|
||||
fn parse_sans_bold() -> TfmMetrics {
|
||||
parse(CMSSBX10_TFM)
|
||||
}
|
||||
|
||||
fn parse_sans_italic() -> TfmMetrics {
|
||||
parse(CMSSI10_TFM)
|
||||
}
|
||||
|
||||
fn parse_math_italic() -> TfmMetrics {
|
||||
parse(CMMI10_TFM)
|
||||
}
|
||||
@@ -125,6 +139,8 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
Cmr10Metrics::BoldItalic => CMBXTI10_METRICS.get_or_init(parse_bold_italic),
|
||||
Cmr10Metrics::Mono => CMTT10_METRICS.get_or_init(parse_mono),
|
||||
Cmr10Metrics::Sans => CMSS10_METRICS.get_or_init(parse_sans),
|
||||
Cmr10Metrics::SansBold => CMSSBX10_METRICS.get_or_init(parse_sans_bold),
|
||||
Cmr10Metrics::SansItalic => CMSSI10_METRICS.get_or_init(parse_sans_italic),
|
||||
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),
|
||||
@@ -146,6 +162,8 @@ impl Cmr10Metrics {
|
||||
ParagraphFont::BoldItalic => Self::BoldItalic,
|
||||
ParagraphFont::Mono => Self::Mono,
|
||||
ParagraphFont::Sans => Self::Sans,
|
||||
ParagraphFont::SansBold => Self::SansBold,
|
||||
ParagraphFont::SansItalic => Self::SansItalic,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +180,8 @@ impl Cmr10Metrics {
|
||||
8 => Self::Math,
|
||||
9 => Self::MathBlackboard,
|
||||
10 => Self::MathFraktur,
|
||||
11 => Self::SansBold,
|
||||
12 => Self::SansItalic,
|
||||
_ => Self::Roman,
|
||||
}
|
||||
}
|
||||
@@ -660,4 +680,18 @@ mod cmex_delimiter_tests {
|
||||
assert!(cmex_delimiter('.', 1).is_none());
|
||||
assert!(cmex_delimiter('x', 1).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sans_bold_and_italic_use_their_own_metrics() {
|
||||
let regular = Cmr10Metrics::Sans.width('A');
|
||||
let bold = Cmr10Metrics::SansBold.width('A');
|
||||
let italic = Cmr10Metrics::SansItalic.width('A');
|
||||
assert_eq!(bold, metrics_for(Cmr10Metrics::SansBold).width('A'));
|
||||
assert_eq!(italic, metrics_for(Cmr10Metrics::SansItalic).width('A'));
|
||||
assert_ne!(regular, bold);
|
||||
assert_ne!(Cmr10Metrics::Sans.space(), Cmr10Metrics::SansBold.space());
|
||||
assert!(italic > 0);
|
||||
assert_eq!(Cmr10Metrics::for_pdf_slot(11), Cmr10Metrics::SansBold);
|
||||
assert_eq!(Cmr10Metrics::for_pdf_slot(12), Cmr10Metrics::SansItalic);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user