Use Times metrics for bold and italic text
Add ptmb8t/ptmri8t/ptmbi8t metrics and TimesBold/TimesItalic/TimesBoldItalic paragraph faces. A ptm document now maps Roman, bold, italic and bold-italic base faces to the Times family, so headings and emphasised runs use Times widths while the PDF backend continues to embed Liberation Serif. The arXiv output is unchanged at 3 pages; previews measured 12.5-17.5 ms warm and 191 ms cold. Test count is 1076.
This commit is contained in:
1 parent
e9bbd4bd87
commit
fd9ee0740b
12 files changed
+100
-18
No files matched your search
@@ -35,6 +35,12 @@ pub enum Cmr10Metrics {
|
||||
Math,
|
||||
/// Times Roman text metrics (`ptmr8t.tfm`).
|
||||
TimesRoman,
|
||||
/// Times bold text metrics (`ptmb8t.tfm`).
|
||||
TimesBold,
|
||||
/// Times italic text metrics (`ptmri8t.tfm`).
|
||||
TimesItalic,
|
||||
/// Times bold italic text metrics (`ptmbi8t.tfm`).
|
||||
TimesBoldItalic,
|
||||
}
|
||||
|
||||
static CMR10_TFM: &[u8] = include_bytes!("../assets/cmr10.tfm");
|
||||
@@ -55,6 +61,9 @@ 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 PTMR8T_TFM: &[u8] = include_bytes!("../assets/ptmr8t.tfm");
|
||||
static PTMB8T_TFM: &[u8] = include_bytes!("../assets/ptmb8t.tfm");
|
||||
static PTMRI8T_TFM: &[u8] = include_bytes!("../assets/ptmri8t.tfm");
|
||||
static PTMBI8T_TFM: &[u8] = include_bytes!("../assets/ptmbi8t.tfm");
|
||||
|
||||
static CMR10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static CMBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
@@ -74,6 +83,9 @@ static CMSY10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static MSBM10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static EUFM10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static PTMR8T_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static PTMB8T_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static PTMRI8T_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
static PTMBI8T_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
|
||||
|
||||
fn parse(bytes: &[u8]) -> TfmMetrics {
|
||||
TfmMetrics::parse(bytes).expect("embedded TFM must be valid")
|
||||
@@ -167,6 +179,18 @@ fn parse_times_roman() -> TfmMetrics {
|
||||
parse(PTMR8T_TFM)
|
||||
}
|
||||
|
||||
fn parse_times_bold() -> TfmMetrics {
|
||||
parse(PTMB8T_TFM)
|
||||
}
|
||||
|
||||
fn parse_times_italic() -> TfmMetrics {
|
||||
parse(PTMRI8T_TFM)
|
||||
}
|
||||
|
||||
fn parse_times_bold_italic() -> TfmMetrics {
|
||||
parse(PTMBI8T_TFM)
|
||||
}
|
||||
|
||||
fn math_fraktur_metrics() -> &'static TfmMetrics {
|
||||
EUFM10_METRICS.get_or_init(parse_fraktur)
|
||||
}
|
||||
@@ -190,6 +214,9 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
|
||||
Cmr10Metrics::MathBlackboard => MSBM10_METRICS.get_or_init(parse_blackboard),
|
||||
Cmr10Metrics::MathFraktur => EUFM10_METRICS.get_or_init(parse_fraktur),
|
||||
Cmr10Metrics::TimesRoman => PTMR8T_METRICS.get_or_init(parse_times_roman),
|
||||
Cmr10Metrics::TimesBold => PTMB8T_METRICS.get_or_init(parse_times_bold),
|
||||
Cmr10Metrics::TimesItalic => PTMRI8T_METRICS.get_or_init(parse_times_italic),
|
||||
Cmr10Metrics::TimesBoldItalic => PTMBI8T_METRICS.get_or_init(parse_times_bold_italic),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +241,9 @@ impl Cmr10Metrics {
|
||||
ParagraphFont::BoldSlanted => Self::BoldSlanted,
|
||||
ParagraphFont::MonoItalic => Self::MonoItalic,
|
||||
ParagraphFont::TimesRoman => Self::TimesRoman,
|
||||
ParagraphFont::TimesBold => Self::TimesBold,
|
||||
ParagraphFont::TimesItalic => Self::TimesItalic,
|
||||
ParagraphFont::TimesBoldItalic => Self::TimesBoldItalic,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,6 +532,19 @@ mod tests {
|
||||
assert!(font.depth('g') > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn times_bold_and_italic_tfms_differ_from_roman() {
|
||||
let roman = Cmr10Metrics::TimesRoman;
|
||||
let differs = |face: Cmr10Metrics| {
|
||||
['A', 'm', 'W', 'f']
|
||||
.iter()
|
||||
.any(|character| face.width(*character) != roman.width(*character))
|
||||
};
|
||||
assert!(differs(Cmr10Metrics::TimesBold));
|
||||
assert!(differs(Cmr10Metrics::TimesItalic));
|
||||
assert!(differs(Cmr10Metrics::TimesBoldItalic));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn times_roman_tfm_differs_from_cmr() {
|
||||
let roman = Cmr10Metrics::Roman;
|
||||
|
||||
Reference in new issue
Block a user