Use Times metrics for ptm documents

Add a merged ptmr8t TFM asset, a TimesRoman paragraph face and Cmr10Metrics
entry, map a ptm Roman paragraph to it, and select the Liberation Serif
TrueType PDF backend for those projects. The title is uppercased rather than
small-capped so its widths use Times metrics.

The arXiv PDF now embeds Liberation Serif for body text; title/author/abstract
land at y=88/173/277pt with three pages and all references. Headings and bold/
italic Times faces still use CMR metrics.

Test count is 1075.
This commit is contained in:
gloamxun committed 2026-10-28 00:00:34 +08:00
1 parent 2ef5e29329
commit e9bbd4bd87
11 files changed
+108 -29

No files matched your search

Binary file not shown.
+20
View File
@@ -33,6 +33,8 @@ pub enum Cmr10Metrics {
MathFraktur,
/// Math face: italic letters from cmmi10, big operators from cmex10.
Math,
/// Times Roman text metrics (`ptmr8t.tfm`).
TimesRoman,
}
static CMR10_TFM: &[u8] = include_bytes!("../assets/cmr10.tfm");
@@ -52,6 +54,7 @@ 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 EUFM10_TFM: &[u8] = include_bytes!("../assets/eufm10.tfm");
static PTMR8T_TFM: &[u8] = include_bytes!("../assets/ptmr8t.tfm");
static CMR10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
@@ -70,6 +73,7 @@ static CMEX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
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();
fn parse(bytes: &[u8]) -> TfmMetrics {
TfmMetrics::parse(bytes).expect("embedded TFM must be valid")
@@ -159,6 +163,10 @@ fn parse_fraktur() -> TfmMetrics {
parse(EUFM10_TFM)
}
fn parse_times_roman() -> TfmMetrics {
parse(PTMR8T_TFM)
}
fn math_fraktur_metrics() -> &'static TfmMetrics {
EUFM10_METRICS.get_or_init(parse_fraktur)
}
@@ -181,6 +189,7 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
Cmr10Metrics::MathCalligraphic => CMSY10_METRICS.get_or_init(parse_math_symbol),
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),
}
}
@@ -204,6 +213,7 @@ impl Cmr10Metrics {
ParagraphFont::Slanted => Self::Slanted,
ParagraphFont::BoldSlanted => Self::BoldSlanted,
ParagraphFont::MonoItalic => Self::MonoItalic,
ParagraphFont::TimesRoman => Self::TimesRoman,
}
}
@@ -492,6 +502,16 @@ mod tests {
assert!(font.depth('g') > 0);
}
#[test]
fn times_roman_tfm_differs_from_cmr() {
let roman = Cmr10Metrics::Roman;
let times = Cmr10Metrics::TimesRoman;
assert_ne!(times.width('A'), roman.width('A'));
assert_ne!(times.width('m'), roman.width('m'));
assert!(times.height('A') > 0);
assert!(times.depth('g') > 0);
}
#[test]
fn bold_and_italic_tfms_differ_from_roman() {
let roman = Cmr10Metrics::Roman;
+9
View File
@@ -368,6 +368,8 @@ pub enum ParagraphFont {
BoldSlanted,
/// Italic typewriter (`cmitt10`, TeX `\ttfamily\itshape`).
MonoItalic,
/// Times Roman text selected by `\rmdefault{ptm}` (`ptmr8t`).
TimesRoman,
}
impl ParagraphFont {
@@ -386,6 +388,7 @@ impl ParagraphFont {
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::Italic,
}
}
@@ -399,6 +402,7 @@ impl ParagraphFont {
Self::SmallCaps => Self::Bold,
Self::Slanted | Self::BoldSlanted => Self::BoldSlanted,
Self::MonoItalic => Self::MonoItalic,
Self::TimesRoman => Self::Bold,
}
}
@@ -413,6 +417,7 @@ impl ParagraphFont {
Self::SmallCaps => Self::SmallCaps,
Self::Slanted | Self::BoldSlanted => Self::Slanted,
Self::MonoItalic => Self::MonoItalic,
Self::TimesRoman => Self::TimesRoman,
}
}
@@ -429,6 +434,7 @@ impl ParagraphFont {
Self::SmallCaps => Self::Italic,
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
Self::TimesRoman => Self::Italic,
}
}
@@ -444,6 +450,7 @@ impl ParagraphFont {
Self::Sans | Self::SansItalic => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SmallCaps => Self::Slanted,
Self::TimesRoman => Self::Slanted,
}
}
@@ -458,6 +465,7 @@ impl ParagraphFont {
Self::SmallCaps => Self::SmallCaps,
Self::Slanted | Self::BoldSlanted => Self::Roman,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::TimesRoman,
}
}
@@ -483,6 +491,7 @@ impl ParagraphFont {
Self::Slanted => Self::SmallCaps,
Self::BoldSlanted => Self::Bold,
Self::MonoItalic => Self::Mono,
Self::TimesRoman => Self::TimesRoman,
}
}
+18
View File
@@ -810,6 +810,24 @@ pub fn display_lists_to_pdf_with_cm_type1(
)
}
/// Write PDFs with Liberation TrueType outlines and a document Info dictionary.
pub fn display_lists_to_pdf_with_truetype_and_metadata(
pages: &[DisplayList],
page_width: i64,
page_height: i64,
origin: PageOrigin,
metadata: &PdfMetadata,
) -> Vec<u8> {
write_pdf(
pages,
page_width,
page_height,
origin,
FontBackend::TrueType,
metadata,
)
}
/// Write PDFs with Computer Modern Type1 outlines and a document Info dictionary.
pub fn display_lists_to_pdf_with_cm_type1_and_metadata(
pages: &[DisplayList],
+1
View File
@@ -478,6 +478,7 @@ fn paragraph_face(font: ParagraphFont) -> FontFace {
ParagraphFont::Slanted => FontFace::Slanted,
ParagraphFont::BoldSlanted => FontFace::BoldSlanted,
ParagraphFont::MonoItalic => FontFace::MonoItalic,
ParagraphFont::TimesRoman => FontFace::Roman,
}
}