Distinguish slanted from italic and add italic typewriter

Add cmsl10/cmbxsl10/cmitt10 faces so \slshape and \textsl no longer reuse the italic cmti10 and \ttfamily\itshape reaches cmitt10. The NFSS state tracks italic, slanted and small caps separately, with last-shape-wins semantics for \em and the shape commands.
This commit is contained in:
gloamxun committed 2026-10-24 12:58:41 +08:00
1 parent 6df38ced25
commit aa4d86d735
15 files changed
+328 -34

No files matched your search

+1 -1
View File
@@ -467,7 +467,7 @@ from the font's MATH assembly parts. `\\left...\\right` target sizing follows
the assignable TeX parameters `\\delimiterfactor` (default 901) and
`\\delimitershortfall` (default 5pt), including local and global assignments.
Route-D text faces follow the NFSS declarations and compose with the surrounding run: `\sffamily\bfseries` selects cmssbx10, `\sffamily\itshape` selects cmssi10, and bold italic sans substitutes cmssbx10 because Computer Modern has no sans bold italic. `\scshape`/`\textsc` select the real cmcsc10 small-caps face, and all nine text programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10, cmssbx10, cmssi10, cmcsc10) are embedded as Type1 outlines. Because Computer Modern has no bold small caps, a bold small-caps request falls back to cmbx10. Section-wide declarations such as `\bfseries` apply from where they appear to the end of their group, and `\em` toggles emphasis relative to the surrounding face. In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts.
Route-D text faces follow the NFSS declarations and compose with the surrounding run: `\sffamily\bfseries` selects cmssbx10, `\sffamily\itshape` selects cmssi10, and bold italic sans substitutes cmssbx10 because Computer Modern has no sans bold italic. `\scshape`/`\textsc` select the real cmcsc10 small-caps face, `\slshape`/`\textsl` use cmsl10 (or cmbxsl10 when bold) rather than the italic cmti10, and `\ttfamily\itshape` reaches cmitt10. All twelve text programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10, cmssbx10, cmssi10, cmcsc10, cmsl10, cmbxsl10, cmitt10) are embedded as Type1 outlines. Because Computer Modern has no bold small caps, a bold small-caps request falls back to cmbx10. Section-wide declarations such as `\bfseries` apply from where they appear to the end of their group, and `\em` toggles emphasis relative to the surrounding face. In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts.
Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX Letter page at the same scaled-point geometry, rasterizes both with `pdftoppm`, and compares ink line count plus left, right, and bottom edges. It is skipped when `pdflatex`/`pdftoppm` are unavailable. `route_d_multiline_bands_track_pdftex` extends that check to a wrapped paragraph: the pixel rows that carry ink form one band per TeX line, and every band top, bottom, left edge and (except for the last line, whose width follows the break point) right edge must land within a couple of pixels of the pdfTeX page.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+47
View File
@@ -19,6 +19,12 @@ pub enum Cmr10Metrics {
SansItalic,
/// Roman small caps (cmcsc10).
SmallCaps,
/// Roman slanted (cmsl10).
Slanted,
/// Bold extended slanted (cmbxsl10).
BoldSlanted,
/// Italic typewriter (cmitt10).
MonoItalic,
/// Calligraphic capitals from cmsy10 (`\mathcal`).
MathCalligraphic,
/// Blackboard-bold capitals from msbm10 (`\mathbb`).
@@ -38,6 +44,9 @@ 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 CMCSC10_TFM: &[u8] = include_bytes!("../assets/cmcsc10.tfm");
static CMSL10_TFM: &[u8] = include_bytes!("../assets/cmsl10.tfm");
static CMBXSL10_TFM: &[u8] = include_bytes!("../assets/cmbxsl10.tfm");
static CMITT10_TFM: &[u8] = include_bytes!("../assets/cmitt10.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");
@@ -53,6 +62,9 @@ static CMSS10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMSSBX10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMSSI10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMCSC10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMSL10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMBXSL10_METRICS: OnceLock<TfmMetrics> = OnceLock::new();
static CMITT10_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();
@@ -99,6 +111,18 @@ fn parse_small_caps() -> TfmMetrics {
parse(CMCSC10_TFM)
}
fn parse_slanted() -> TfmMetrics {
parse(CMSL10_TFM)
}
fn parse_bold_slanted() -> TfmMetrics {
parse(CMBXSL10_TFM)
}
fn parse_mono_italic() -> TfmMetrics {
parse(CMITT10_TFM)
}
fn parse_math_italic() -> TfmMetrics {
parse(CMMI10_TFM)
}
@@ -150,6 +174,9 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics {
Cmr10Metrics::SansBold => CMSSBX10_METRICS.get_or_init(parse_sans_bold),
Cmr10Metrics::SansItalic => CMSSI10_METRICS.get_or_init(parse_sans_italic),
Cmr10Metrics::SmallCaps => CMCSC10_METRICS.get_or_init(parse_small_caps),
Cmr10Metrics::Slanted => CMSL10_METRICS.get_or_init(parse_slanted),
Cmr10Metrics::BoldSlanted => CMBXSL10_METRICS.get_or_init(parse_bold_slanted),
Cmr10Metrics::MonoItalic => CMITT10_METRICS.get_or_init(parse_mono_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),
@@ -174,6 +201,9 @@ impl Cmr10Metrics {
ParagraphFont::SansBold => Self::SansBold,
ParagraphFont::SansItalic => Self::SansItalic,
ParagraphFont::SmallCaps => Self::SmallCaps,
ParagraphFont::Slanted => Self::Slanted,
ParagraphFont::BoldSlanted => Self::BoldSlanted,
ParagraphFont::MonoItalic => Self::MonoItalic,
}
}
@@ -193,6 +223,9 @@ impl Cmr10Metrics {
11 => Self::SansBold,
12 => Self::SansItalic,
13 => Self::SmallCaps,
14 => Self::Slanted,
15 => Self::BoldSlanted,
16 => Self::MonoItalic,
_ => Self::Roman,
}
}
@@ -708,5 +741,19 @@ mod cmex_delimiter_tests {
let small_caps = Cmr10Metrics::SmallCaps.width('a');
assert_eq!(small_caps, metrics_for(Cmr10Metrics::SmallCaps).width('a'));
assert_ne!(small_caps, Cmr10Metrics::Roman.width('a'));
assert_eq!(Cmr10Metrics::for_pdf_slot(14), Cmr10Metrics::Slanted);
assert_eq!(Cmr10Metrics::for_pdf_slot(15), Cmr10Metrics::BoldSlanted);
assert_eq!(Cmr10Metrics::for_pdf_slot(16), Cmr10Metrics::MonoItalic);
let slanted = Cmr10Metrics::Slanted.width('a');
assert_eq!(slanted, metrics_for(Cmr10Metrics::Slanted).width('a'));
assert_ne!(slanted, Cmr10Metrics::Italic.width('a'));
assert_eq!(
Cmr10Metrics::BoldSlanted.width('a'),
metrics_for(Cmr10Metrics::BoldSlanted).width('a')
);
assert_eq!(
Cmr10Metrics::MonoItalic.width('a'),
metrics_for(Cmr10Metrics::MonoItalic).width('a')
);
}
}
+23
View File
@@ -6283,6 +6283,29 @@ mod tests {
assert!(svg.contains("font-family=\"serif\""));
}
#[test]
fn slanted_paragraph_paints_with_the_slanted_face() {
let unit = Unit::paragraph_with_face(1, "slanted text", ParagraphFont::Slanted);
let page = Page {
items: unit.items,
insertions: Vec::new(),
marks: Vec::new(),
floats: Vec::new(),
sources: Vec::new(),
hash: 0,
};
let list = page.display_list();
assert!(list.items.iter().any(|item| matches!(
item,
crate::render::DisplayItem::Text {
font: crate::render::FontFace::Slanted,
..
}
)));
let svg = list.to_svg();
assert!(svg.contains("font-style=\"italic\""));
}
#[test]
fn mono_paragraph_paints_with_a_mono_face() {
let unit = Unit::paragraph_with_face(1, "code 123", ParagraphFont::Mono);
+58 -4
View File
@@ -297,6 +297,12 @@ pub enum ParagraphFont {
SansItalic,
/// Roman small caps (`cmcsc10`, TeX `\scshape`).
SmallCaps,
/// Roman slanted (`cmsl10`, TeX `\slshape`).
Slanted,
/// Bold extended slanted (`cmbxsl10`).
BoldSlanted,
/// Italic typewriter (`cmitt10`, TeX `\ttfamily\itshape`).
MonoItalic,
}
impl ParagraphFont {
@@ -312,6 +318,9 @@ impl ParagraphFont {
Self::SansBold => Self::SansBold,
Self::SansItalic => Self::Sans,
Self::SmallCaps => Self::Italic,
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
Self::MonoItalic => Self::Mono,
}
}
@@ -323,6 +332,8 @@ impl ParagraphFont {
Self::Mono => self,
Self::Sans | Self::SansBold | Self::SansItalic => Self::SansBold,
Self::SmallCaps => Self::Bold,
Self::Slanted | Self::BoldSlanted => Self::BoldSlanted,
Self::MonoItalic => Self::MonoItalic,
}
}
@@ -335,19 +346,39 @@ impl ParagraphFont {
Self::Sans | Self::SansItalic => self,
Self::SansBold => Self::Sans,
Self::SmallCaps => Self::SmallCaps,
Self::Slanted | Self::BoldSlanted => Self::Slanted,
Self::MonoItalic => Self::MonoItalic,
}
}
/// `\textit` / `\textsl`.
/// `\textit`.
pub const fn italicized(self) -> Self {
match self {
Self::Roman | Self::Italic => Self::Italic,
Self::Bold | Self::BoldItalic => Self::BoldItalic,
Self::Mono => self,
Self::Mono => Self::MonoItalic,
Self::MonoItalic => Self::MonoItalic,
Self::Sans => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SansItalic => Self::SansItalic,
Self::SmallCaps => Self::Italic,
Self::Slanted => Self::Italic,
Self::BoldSlanted => Self::BoldItalic,
}
}
/// `\textsl`.
pub const fn slanted(self) -> Self {
match self {
Self::Roman | Self::Slanted => Self::Slanted,
Self::Bold | Self::BoldSlanted => Self::BoldSlanted,
Self::Italic => Self::Slanted,
Self::BoldItalic => Self::BoldSlanted,
Self::Mono => Self::MonoItalic,
Self::MonoItalic => Self::MonoItalic,
Self::Sans | Self::SansItalic => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SmallCaps => Self::Slanted,
}
}
@@ -360,6 +391,8 @@ impl ParagraphFont {
Self::Sans | Self::SansItalic => Self::Sans,
Self::SansBold => Self::SansBold,
Self::SmallCaps => Self::SmallCaps,
Self::Slanted | Self::BoldSlanted => Self::Roman,
Self::MonoItalic => Self::Mono,
}
}
@@ -382,14 +415,17 @@ impl ParagraphFont {
Self::SmallCaps => Self::SmallCaps,
Self::Mono => Self::Mono,
Self::Sans | Self::SansBold | Self::SansItalic => self,
Self::Slanted => Self::SmallCaps,
Self::BoldSlanted => Self::Bold,
Self::MonoItalic => Self::Mono,
}
}
/// `\textsf`: change family, keeping the inherited weight and shape.
pub const fn sans_family(self) -> Self {
match self {
Self::Bold | Self::BoldItalic => Self::SansBold,
Self::Italic => Self::SansItalic,
Self::Bold | Self::BoldItalic | Self::BoldSlanted => Self::SansBold,
Self::Italic | Self::Slanted | Self::MonoItalic => Self::SansItalic,
_ => Self::Sans,
}
}
@@ -2383,5 +2419,23 @@ mod font_tests {
assert_eq!(ParagraphFont::Bold.small_caps(), ParagraphFont::Bold);
assert_eq!(ParagraphFont::Italic.small_caps(), ParagraphFont::SmallCaps);
assert_eq!(ParagraphFont::SmallCaps.upright(), ParagraphFont::SmallCaps);
assert_eq!(ParagraphFont::Slanted.italicized(), ParagraphFont::Italic);
assert_eq!(ParagraphFont::Italic.slanted(), ParagraphFont::Slanted);
assert_eq!(ParagraphFont::Bold.slanted(), ParagraphFont::BoldSlanted);
assert_eq!(ParagraphFont::BoldSlanted.medium(), ParagraphFont::Slanted);
assert_eq!(ParagraphFont::Slanted.upright(), ParagraphFont::Roman);
assert_eq!(ParagraphFont::Slanted.emphasized(), ParagraphFont::Italic);
assert_eq!(ParagraphFont::Mono.italicized(), ParagraphFont::MonoItalic);
assert_eq!(ParagraphFont::MonoItalic.upright(), ParagraphFont::Mono);
assert_eq!(ParagraphFont::Mono.slanted(), ParagraphFont::MonoItalic);
assert_eq!(
ParagraphFont::Slanted.small_caps(),
ParagraphFont::SmallCaps
);
assert_eq!(ParagraphFont::BoldSlanted.small_caps(), ParagraphFont::Bold);
assert_eq!(
ParagraphFont::Slanted.sans_family(),
ParagraphFont::SansItalic
);
}
}
+88 -1
View File
@@ -16,7 +16,7 @@ use crate::cmr10::Cmr10Metrics;
use crate::render::{DisplayItem, DisplayList, FontFace};
use crate::type1::Type1Font;
const FACE_COUNT: usize = 14;
const FACE_COUNT: usize = 17;
fn deflate(bytes: &[u8]) -> Vec<u8> {
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default());
@@ -116,6 +116,24 @@ static FULL_FACES: [PdfFace; FACE_COUNT] = [
italic_angle: 0,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationSerif-Italic.ttf"),
base: "LiberationSerif-Slanted",
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationSerif-BoldItalic.ttf"),
base: "LiberationSerif-BoldSlanted",
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationMono-Italic.ttf"),
base: "LiberationMono-Italic",
italic_angle: -12,
font: OnceLock::new(),
},
];
static MIN_FACES: [PdfFace; FACE_COUNT] = [
@@ -203,6 +221,24 @@ static MIN_FACES: [PdfFace; FACE_COUNT] = [
italic_angle: 0,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSerif-Italic.ttf"),
base: "LiberationSerif-Slanted",
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSerif-BoldItalic.ttf"),
base: "LiberationSerif-BoldSlanted",
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationMono-Italic.ttf"),
base: "LiberationMono-Italic",
italic_angle: -12,
font: OnceLock::new(),
},
];
fn minimal_text_char(ch: char) -> bool {
@@ -339,6 +375,9 @@ fn font_resource(font: FontFace) -> &'static str {
FontFace::SansBold => "F12",
FontFace::SansItalic => "F13",
FontFace::SmallCaps => "F14",
FontFace::Slanted => "F15",
FontFace::BoldSlanted => "F16",
FontFace::MonoItalic => "F17",
}
}
@@ -368,6 +407,9 @@ fn type1_bytes(slot: usize) -> Option<&'static [u8]> {
Some(include_bytes!("../../../assets/fonts/cmssbx10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmssi10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmcsc10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmsl10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmbxsl10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmitt10.pfb")),
];
PFBS[slot]
}
@@ -1018,6 +1060,51 @@ mod type1_pdf_tests {
assert!(text.contains("/BaseFont /CMCSC10"), "{text}");
}
#[test]
fn slanted_text_embeds_cmsl10() {
let mut list = hello_list();
list.items[0] = DisplayItem::Text {
x: 0,
y: 800_000,
size: 655_360,
text: "Slanted".to_string(),
font: FontFace::Slanted,
};
let pdf = write(&[list]);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/BaseFont /CMSL10"), "{text}");
}
#[test]
fn bold_slanted_text_embeds_cmbxsl10() {
let mut list = hello_list();
list.items[0] = DisplayItem::Text {
x: 0,
y: 800_000,
size: 655_360,
text: "Slanted".to_string(),
font: FontFace::BoldSlanted,
};
let pdf = write(&[list]);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/BaseFont /CMBXSL10"), "{text}");
}
#[test]
fn mono_italic_text_embeds_cmitt10() {
let mut list = hello_list();
list.items[0] = DisplayItem::Text {
x: 0,
y: 800_000,
size: 655_360,
text: "Mono".to_string(),
font: FontFace::MonoItalic,
};
let pdf = write(&[list]);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/BaseFont /CMITT10"), "{text}");
}
#[test]
fn math_italic_text_embeds_cmmi10() {
let mut list = hello_list();
+14 -2
View File
@@ -35,6 +35,9 @@ pub enum FontFace {
SansItalic,
/// Computer Modern roman small caps (`cmcsc10`).
SmallCaps,
Slanted,
BoldSlanted,
MonoItalic,
}
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -163,7 +166,7 @@ impl DisplayList {
let x = *x as f64 / 65_536.0;
let y = *y as f64 / 65_536.0;
let size = *size as f64 / 65_536.0;
let family = if matches!(font, FontFace::Mono) {
let family = if matches!(font, FontFace::Mono | FontFace::MonoItalic) {
"monospace"
} else if matches!(
font,
@@ -175,7 +178,10 @@ impl DisplayList {
};
let weight = if matches!(
font,
FontFace::Bold | FontFace::BoldItalic | FontFace::SansBold
FontFace::Bold
| FontFace::BoldItalic
| FontFace::SansBold
| FontFace::BoldSlanted
) {
" font-weight=\"bold\""
} else {
@@ -187,6 +193,9 @@ impl DisplayList {
| FontFace::BoldItalic
| FontFace::MathItalic
| FontFace::SansItalic
| FontFace::Slanted
| FontFace::BoldSlanted
| FontFace::MonoItalic
) {
" font-style=\"italic\""
} else {
@@ -289,6 +298,9 @@ fn paragraph_face(font: ParagraphFont) -> FontFace {
ParagraphFont::SansBold => FontFace::SansBold,
ParagraphFont::SansItalic => FontFace::SansItalic,
ParagraphFont::SmallCaps => FontFace::SmallCaps,
ParagraphFont::Slanted => FontFace::Slanted,
ParagraphFont::BoldSlanted => FontFace::BoldSlanted,
ParagraphFont::MonoItalic => FontFace::MonoItalic,
}
}
+1 -1
View File
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
PDF opt-in with `?engine=route-d`). 583 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 589 workspace tests are green and no oracle
fixture is ignored.
Status after G1 (P0-P2): the paragraph model reproduces TeX's passes,
+4 -4
View File
@@ -132,7 +132,7 @@ and justification.
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions, bottom floats or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset, and `\mark{...}`/`\marks<n>{...}` writes inside the routine are carried to the following page's mark list with their class; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets the pages the routine has not seen yet, even when the document raises insertion material; only a document that defers bottom floats keeps its initial goal, because the carried queue cannot be rebuilt after a retarget), `\ht255`, `\dp255` and `\wd255` expose the page box height, depth and width to the routine, and `\hsize` is readable (and assignable for the rest of the run) while `\wd255` tracks it; route-D sets `\hsize` from its 480pt text measure, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments that outlive the routine (the paged builder runs the routine after each page, so an assigned `\dimen<n>` or `\count<n>` changes the insertion capacity and reservation of later pages); the configured `\skip<n>` also reserves space above its class once per page in the paged builder, and a `\skip<n>` assignment rebuilds the pages the routine has not seen yet with the new reservation, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `PageFragment::penalty` carries the break penalty (`\outputpenalty`: the penalty value when the break landed on a penalty, otherwise 10000, as TeX reports for glue breaks, goal overflow and the final page), and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine; `\vbadness` reports the badness of the break that produced the page and `\insertpenalties` the number of insertion items held over from it |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; the paged builder splits a tall alignment into page-sized row chunks that keep the table's column widths, so long tables continue across pages; `p{width}` paragraph columns wrap cell text and grow row heights, wrapped rows participate in row-level splitting, explicit per-column `\tabskip` glue is honoured through layout, painting and page chunks, and booktabs rules carry their own weights and spans (`\toprule`/`\bottomrule` 0.8pt, `\midrule`/`\cmidrule` 0.5pt, with `\cmidrule(lr){a-b}` trimming and column ranges), `@{}` / `@{\hspace{...}}` column expressions override the inter-column glue, and row-boundary `\noalign{\vskip ...}` glue is honoured by layout, painting and page chunks; longtable head/foot sections (`\endfirsthead`/`\endhead`/`\endfoot`/`\endlastfoot`) are parsed, continuation chunks repeat the head rows and the foot block paints once at the end, LaTeX `tabular` environments are captured and laid out through the same `\halign` path (rules are stripped from the column spec, `p{...}`/`m{...}`/`b{...}` become wrapping columns, `@{}` expressions are ignored for spacing), though `\valign`, nested tables and full tabular parity remain open |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with Computer Modern metrics (italic letters from the bundled `cmmi10`, big operators from `cmex10`, symbols such as `\times`/`\leq`/`\infty` from `cmsy10`, with `cmmi10`, `cmsy10` and `cmex10` glyphs embedded as Type1 outlines), `\left...\right` delimiter selection through CMEX size variants using TeX's delimiterfactor and shortfall, accents and a display-list painter; display formulas wider than the measure are split at top-level binary/relation operators into multiple lines (an approximation of TeX's `\split` behaviour; `align`/`align*` displays share column widths and number each row, while `gather`/`gather*` centre every row); CMEX delimiter size variants back `\big`/`\Big`/`\bigg`/`\Bigg`; inter-atom spacing uses TeX's full atom-class table with binary-operator normalisation, with `1mu` = `1/18em` (a thin space is 3mu = 1.67pt at 10pt); `\mid` is a relation while `\colon` is punctuation; `\mskip`, `\mkern`, `\mspace`, `\hskip`, `\kern` and `\hspace` scan TeX dimensions (`mu`, `pt`, `em`, ...) and contribute their natural width, accepting `plus`/`minus` parts even though math boxes are not glue lists; route-D numbers `equation` environments and resolves `\eqref`/`\ref` through their labels; `\tag` overrides the number and `\notag`/`\nonumber` suppress it; math italic letters are embedded as Computer Modern Type1 outlines (`cmmi10`), and math alphabets map `\\mathbf`/`\\mathit`/`\\mathsf`/`\\mathtt` onto the bold, math-italic, sans and mono faces with their TFMs and `\\mathcal` onto the cmsy10 calligraphic capitals; `\mathfrak` maps onto the bundled eufm10 Fraktur letters (embedded as Type1 outlines); infix fractions `\over`, `\atop`, `\choose`, `\brace`, `\brack` and their `withdelims` forms build fractions from the current row, with the bar only for the `\over` forms; `\middle` delimiters are sized with their enclosing `\left`/`\right` group and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size |
| M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/Sans/SansBold/SansItalic/SmallCaps faces (CM has no sans bold-italic, so `cmss/bx/it` substitutes `cmss/bx/n`; `\scshape` selects cmcsc10 and a bold small caps request falls back to cmbx10), per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open |
| M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/MonoItalic/Sans/SansBold/SansItalic/SmallCaps/Slanted/BoldSlanted faces (CM has no sans bold-italic, so `cmss/bx/it` substitutes `cmss/bx/n`; `\scshape` selects cmcsc10 and a bold small caps request falls back to cmbx10; `\slshape` uses the slanted cmsl10 rather than the italic cmti10 and `\ttfamily\itshape` reaches cmitt10), per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open |
| M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity |
| M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity |
@@ -331,7 +331,7 @@ for a later overlaid slash.
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, Rust output hook, top/bottom floats, float-page/text fractions, rules, vskip, penalties; `page::PageBuilder` scores breakpoints with page badness and penalties and models `\topskip`/`\maxdepth`; `Engine::layout_paged` builds pages through it for documents made of box/glue/penalty/mark vertical material (a unit may span pages), while in-text floats flow inline through the page builder; paged layouts replay edits from the edited page (insertions, bottom floats and interpreted `\output` force a full rebuild), and insertions are placed through the builder too; `\output` interpreted for a `\shipout`/`\ifdim`/`\ifnum` register subset over page globals and `\outputpenalty`/`\pageno`/`\deadcycles` |
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
| M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`), `align`/`gather` rows with per-row tags; no math painter/shrink wrapping |
| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10/cmcsc10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character |
| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10/cmcsc10/cmsl10/cmbxsl10/cmitt10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character |
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in `?engine=route-d` project preview, content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor toggle in `texrra-web`; inline math pending |
@@ -353,7 +353,7 @@ M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute
PDF writer: `crates/texrra-tex-core/src/pdf.rs` writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + `/W` arrays), filled rectangles, diagonal rules, raw-RGB `/XObject` images, `/Annots` URI links and arbitrary `/special` operators. Ligature substitution and line-end italic correction are implemented; full NFSS family switching remains open.
M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; paragraph-level NFSS declarations (`\rmfamily`, `\sffamily`, `\ttfamily`, `\bfseries`, `\itshape`, `\texttt`, `\textsf`) select those faces and the `\fontfamily`/`\fontseries`/`\fontshape`/`\fontencoding`/`\selectfont` command forms plus legacy `\rm`/`\sf`/`\tt`/`\bf`/`\it`/`\sl`/`\up`/`\normalfont` declarations are parsed; inline `\textbf`/`\emph`/`\textit`/`\texttt`/`\textsf` groups and `{\bfseries ...}` declaration groups (including nesting) split a paragraph into styled runs, each shaped by its own TFM and painted with its own face; nested faces compose relatively (`\emph` inside bold yields bold italic via cmbxti10, `\emph` inside italic returns upright, `\sffamily\bfseries` yields cmssbx10 and `\sffamily\itshape` cmssi10, while bold-italic sans falls back to cmssbx10 as TeX's OT1 substitution does; `\scshape`/`\textsc` select cmcsc10, with the last shape command winning and bold small caps substituting cmbx10; declarations such as `\bfseries` also switch the face for the rest of their group, and `\em` toggles emphasis relative to the current run); styled runs are stored on the paragraph unit, so incremental edits rebuild them through `Engine::edit_runs` instead of flattening the paragraph back to one face; true family/series/shape switching remains open; route-D PDFs now embed all six Knuth Computer Modern Type1 programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10) as simple fonts (PFB `Length1/2/3`, `/Encoding /Differences` from each program's built-in encoding, `/Widths` in 1000-unit text space from that face's TFM advances) whenever the program covers every character of that face on the page, and fall back per face to the Liberation Type0 subset otherwise; `pdffonts` reports `Type 1` faces (CMR10, CMBX10, ...) and `pdftotext` still extracts the text. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters.
M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono,MonoItalic,Sans,SansBold,SansItalic,SmallCaps,Slanted,BoldSlanted}` plus the math faces. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; paragraph-level NFSS declarations (`\rmfamily`, `\sffamily`, `\ttfamily`, `\bfseries`, `\itshape`, `\texttt`, `\textsf`) select those faces and the `\fontfamily`/`\fontseries`/`\fontshape`/`\fontencoding`/`\selectfont` command forms plus legacy `\rm`/`\sf`/`\tt`/`\bf`/`\it`/`\sl`/`\up`/`\normalfont` declarations are parsed; inline `\textbf`/`\emph`/`\textit`/`\texttt`/`\textsf` groups and `{\bfseries ...}` declaration groups (including nesting) split a paragraph into styled runs, each shaped by its own TFM and painted with its own face; nested faces compose relatively (`\emph` inside bold yields bold italic via cmbxti10, `\emph` inside italic returns upright, `\sffamily\bfseries` yields cmssbx10 and `\sffamily\itshape` cmssi10, while bold-italic sans falls back to cmssbx10 as TeX's OT1 substitution does; `\scshape`/`\textsc` select cmcsc10, with the last shape command winning and bold small caps substituting cmbx10; `\slshape`/`\textsl` select cmsl10 (or cmbxsl10 with a bold series) instead of the italic cmti10, and `\ttfamily\itshape` selects cmitt10; declarations such as `\bfseries` also switch the face for the rest of their group, and `\em` toggles emphasis relative to the current run); styled runs are stored on the paragraph unit, so incremental edits rebuild them through `Engine::edit_runs` instead of flattening the paragraph back to one face; true family/series/shape switching remains open; route-D PDFs now embed all twelve Knuth Computer Modern Type1 programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10, cmssbx10, cmssi10, cmcsc10, cmsl10, cmbxsl10, cmitt10) as simple fonts (PFB `Length1/2/3`, `/Encoding /Differences` from each program's built-in encoding, `/Widths` in 1000-unit text space from that face's TFM advances) whenever the program covers every character of that face on the page, and fall back per face to the Liberation Type0 subset otherwise; `pdffonts` reports `Type 1` faces (CMR10, CMBX10, ...) and `pdftotext` still extracts the text. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters.
M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
@@ -367,7 +367,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 395 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 583 tests (395 route-D unit, 42 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
The crate currently has 395 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 589 tests (399 route-D unit, 44 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
### M0 incremental demo
+92 -21
View File
@@ -1041,8 +1041,12 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
ParagraphFont::SansBold => (Family::Sans, true, false),
ParagraphFont::SansItalic => (Family::Sans, false, true),
ParagraphFont::SmallCaps => (Family::Roman, false, false),
ParagraphFont::Slanted => (Family::Roman, false, false),
ParagraphFont::BoldSlanted => (Family::Roman, true, false),
ParagraphFont::MonoItalic => (Family::Mono, false, true),
};
let mut small_caps = base == ParagraphFont::SmallCaps;
let mut slanted = matches!(base, ParagraphFont::Slanted | ParagraphFont::BoldSlanted);
let mut text = raw.trim_start();
let mut consumed = false;
loop {
@@ -1055,7 +1059,8 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|| name.contains('s') && name.contains('b');
text = rest;
} else if let Some((name, rest)) = nfss_braced(text, "\\fontshape") {
italic = name == "it" || name == "sl";
italic = name == "it";
slanted = name == "sl";
small_caps = name == "sc";
text = rest;
} else if let Some(rest) = nfss_braced(text, "\\fontencoding").map(|(_, rest)| rest) {
@@ -1064,14 +1069,17 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
family = Family::Roman;
bold = false;
italic = false;
slanted = false;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\em") {
if small_caps {
small_caps = false;
italic = true;
if italic || slanted {
italic = false;
slanted = false;
} else {
italic = !italic;
italic = true;
slanted = false;
small_caps = false;
}
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\rm") {
@@ -1091,19 +1099,23 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\it") {
italic = true;
slanted = false;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\sl") {
italic = true;
italic = false;
slanted = true;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\up") {
italic = false;
slanted = false;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\sc") {
small_caps = true;
italic = false;
slanted = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\rmfamily") {
family = Family::Roman;
@@ -1122,19 +1134,23 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\itshape") {
italic = true;
slanted = false;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\slshape") {
italic = true;
italic = false;
slanted = true;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\upshape") {
italic = false;
slanted = false;
small_caps = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\scshape") {
small_caps = true;
italic = false;
slanted = false;
text = rest;
} else if let Some(rest) = nfss_declaration(text, "\\selectfont") {
text = rest;
@@ -1148,19 +1164,43 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
return None;
}
let font = match family {
Family::Mono => ParagraphFont::Mono,
Family::Sans => match (bold, italic) {
(true, _) => ParagraphFont::SansBold,
(false, true) => ParagraphFont::SansItalic,
(false, false) => ParagraphFont::Sans,
},
Family::Roman => match (bold, italic, small_caps) {
(_, true, _) if bold => ParagraphFont::BoldItalic,
(_, true, _) => ParagraphFont::Italic,
(true, false, _) => ParagraphFont::Bold,
(false, false, true) => ParagraphFont::SmallCaps,
(false, false, false) => ParagraphFont::Roman,
},
Family::Mono => {
if italic || slanted {
ParagraphFont::MonoItalic
} else {
ParagraphFont::Mono
}
}
Family::Sans => {
if bold {
ParagraphFont::SansBold
} else if italic || slanted {
ParagraphFont::SansItalic
} else {
ParagraphFont::Sans
}
}
Family::Roman => {
if italic {
if bold {
ParagraphFont::BoldItalic
} else {
ParagraphFont::Italic
}
} else if slanted {
if bold {
ParagraphFont::BoldSlanted
} else {
ParagraphFont::Slanted
}
} else if bold {
ParagraphFont::Bold
} else if small_caps {
ParagraphFont::SmallCaps
} else {
ParagraphFont::Roman
}
}
};
Some((font, text.to_string()))
}
@@ -1239,7 +1279,8 @@ fn inline_wrapper(rest: &str, base: ParagraphFont) -> Option<(ParagraphFont, &st
let font = match command {
"\\textbf" => base.bolded(),
"\\emph" => base.emphasized(),
"\\textit" | "\\textsl" => base.italicized(),
"\\textit" => base.italicized(),
"\\textsl" => base.slanted(),
"\\texttt" => ParagraphFont::Mono,
"\\textsf" => base.sans_family(),
"\\textmd" => base.medium(),
@@ -2273,6 +2314,28 @@ mod nfss_tests {
assert_eq!(paragraph_font("\\normalfont Reset"), ParagraphFont::Roman);
}
#[test]
fn slanted_and_italic_shapes_stay_distinct() {
assert_eq!(paragraph_font("\\slshape slanted"), ParagraphFont::Slanted);
assert_eq!(paragraph_font("\\itshape italic"), ParagraphFont::Italic);
assert_eq!(
paragraph_font("\\bfseries\\slshape bold slanted"),
ParagraphFont::BoldSlanted
);
assert_eq!(
paragraph_font("\\ttfamily\\itshape tt italic"),
ParagraphFont::MonoItalic
);
assert_eq!(
paragraph_font("\\slshape\\itshape italic"),
ParagraphFont::Italic
);
assert_eq!(
paragraph_font("\\ttfamily\\slshape tt slanted"),
ParagraphFont::MonoItalic
);
}
#[test]
fn legacy_declarations_stay_bounded() {
assert_eq!(paragraph_font("\\tt Legacy mono"), ParagraphFont::Mono);
@@ -2306,6 +2369,14 @@ mod inline_tests {
);
}
#[test]
fn textsl_selects_the_slanted_shape() {
let runs = inline_runs("\\textsl{slanted}", ParagraphFont::Roman).expect("runs");
assert_eq!(runs[0], (ParagraphFont::Slanted, "slanted".to_string()));
let runs = inline_runs("\\textbf{\\textsl{slanted}}", ParagraphFont::Roman).expect("runs");
assert_eq!(runs[0], (ParagraphFont::BoldSlanted, "slanted".to_string()));
}
#[test]
fn textsc_composes_with_the_surrounding_face() {
let runs = inline_runs("\\textsc{small}", ParagraphFont::Roman).expect("runs");