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:
gloamxun committed 2026-10-28 00:08:19 +08:00
1 parent e9bbd4bd87
commit fd9ee0740b
12 files changed
+100 -18

No files matched your search

+43
View File
@@ -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;
+31 -4
View File
@@ -370,6 +370,12 @@ pub enum ParagraphFont {
MonoItalic,
/// Times Roman text selected by `\rmdefault{ptm}` (`ptmr8t`).
TimesRoman,
/// Times bold text (`ptmb8t`).
TimesBold,
/// Times italic text (`ptmri8t`).
TimesItalic,
/// Times bold italic text (`ptmbi8t`).
TimesBoldItalic,
}
impl ParagraphFont {
@@ -388,7 +394,10 @@ impl ParagraphFont {
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::Italic,
Self::TimesRoman => Self::TimesItalic,
Self::TimesItalic => Self::TimesRoman,
Self::TimesBold => Self::TimesBoldItalic,
Self::TimesBoldItalic => Self::TimesBold,
}
}
@@ -402,7 +411,10 @@ impl ParagraphFont {
Self::SmallCaps => Self::Bold,
Self::Slanted | Self::BoldSlanted => Self::BoldSlanted,
Self::MonoItalic => Self::MonoItalic,
Self::TimesRoman => Self::Bold,
Self::TimesRoman => Self::TimesBold,
Self::TimesItalic => Self::TimesBoldItalic,
Self::TimesBold => Self::TimesBold,
Self::TimesBoldItalic => Self::TimesBoldItalic,
}
}
@@ -418,6 +430,9 @@ impl ParagraphFont {
Self::Slanted | Self::BoldSlanted => Self::Slanted,
Self::MonoItalic => Self::MonoItalic,
Self::TimesRoman => Self::TimesRoman,
Self::TimesBold => Self::TimesRoman,
Self::TimesItalic => Self::TimesItalic,
Self::TimesBoldItalic => Self::TimesItalic,
}
}
@@ -434,7 +449,10 @@ impl ParagraphFont {
Self::SmallCaps => Self::Italic,
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
Self::TimesRoman => Self::Italic,
Self::TimesRoman => Self::TimesItalic,
Self::TimesItalic => Self::TimesItalic,
Self::TimesBold => Self::TimesBoldItalic,
Self::TimesBoldItalic => Self::TimesBoldItalic,
}
}
@@ -450,7 +468,10 @@ impl ParagraphFont {
Self::Sans | Self::SansItalic => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SmallCaps => Self::Slanted,
Self::TimesRoman => Self::Slanted,
Self::TimesRoman => Self::TimesItalic,
Self::TimesItalic => Self::TimesItalic,
Self::TimesBold => Self::TimesBoldItalic,
Self::TimesBoldItalic => Self::TimesBoldItalic,
}
}
@@ -466,6 +487,9 @@ impl ParagraphFont {
Self::Slanted | Self::BoldSlanted => Self::Roman,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::TimesRoman,
Self::TimesItalic => Self::TimesRoman,
Self::TimesBold => Self::TimesBold,
Self::TimesBoldItalic => Self::TimesBold,
}
}
@@ -492,6 +516,9 @@ impl ParagraphFont {
Self::BoldSlanted => Self::Bold,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::TimesRoman,
Self::TimesItalic => Self::TimesRoman,
Self::TimesBold => Self::TimesBold,
Self::TimesBoldItalic => Self::TimesBold,
}
}
+3
View File
@@ -479,6 +479,9 @@ fn paragraph_face(font: ParagraphFont) -> FontFace {
ParagraphFont::BoldSlanted => FontFace::BoldSlanted,
ParagraphFont::MonoItalic => FontFace::MonoItalic,
ParagraphFont::TimesRoman => FontFace::Roman,
ParagraphFont::TimesBold => FontFace::Bold,
ParagraphFont::TimesItalic => FontFace::Italic,
ParagraphFont::TimesBoldItalic => FontFace::BoldItalic,
}
}