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:
gloamxun committed 2026-10-24 12:49:30 +08:00
1 parent 03925e3116
commit 9140990a7d
13 files changed
+223 -19

No files matched your search

+23 -3
View File
@@ -1038,6 +1038,8 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
ParagraphFont::BoldItalic => (Family::Roman, true, true),
ParagraphFont::Mono => (Family::Mono, false, false),
ParagraphFont::Sans => (Family::Sans, false, false),
ParagraphFont::SansBold => (Family::Sans, true, false),
ParagraphFont::SansItalic => (Family::Sans, false, true),
};
let mut text = raw.trim_start();
let mut consumed = false;
@@ -1125,7 +1127,11 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
}
let font = match family {
Family::Mono => ParagraphFont::Mono,
Family::Sans => ParagraphFont::Sans,
Family::Sans => match (bold, italic) {
(true, _) => ParagraphFont::SansBold,
(false, true) => ParagraphFont::SansItalic,
(false, false) => ParagraphFont::Sans,
},
Family::Roman => match (bold, italic) {
(true, true) => ParagraphFont::BoldItalic,
(true, false) => ParagraphFont::Bold,
@@ -1212,7 +1218,7 @@ fn inline_wrapper(rest: &str, base: ParagraphFont) -> Option<(ParagraphFont, &st
"\\emph" => base.emphasized(),
"\\textit" | "\\textsl" => base.italicized(),
"\\texttt" => ParagraphFont::Mono,
"\\textsf" => ParagraphFont::Sans,
"\\textsf" => base.sans_family(),
"\\textmd" => base.medium(),
"\\textup" => base.upright(),
"\\textrm" => base.roman_family(),
@@ -2167,6 +2173,14 @@ mod nfss_tests {
#[test]
fn declarations_select_built_in_faces() {
assert_eq!(paragraph_font("\\sffamily Sans text"), ParagraphFont::Sans);
assert_eq!(
paragraph_font("\\sffamily\\bfseries Sans text"),
ParagraphFont::SansBold
);
assert_eq!(
paragraph_font("\\sffamily\\itshape Sans text"),
ParagraphFont::SansItalic
);
assert_eq!(paragraph_font("\\ttfamily Mono text"), ParagraphFont::Mono);
assert_eq!(paragraph_font("\\bfseries Bold text"), ParagraphFont::Bold);
assert_eq!(
@@ -2175,7 +2189,7 @@ mod nfss_tests {
);
assert_eq!(
paragraph_font("\\sffamily\\bfseries Bold sans"),
ParagraphFont::Sans
ParagraphFont::SansBold
);
assert_eq!(
paragraph_font("\\rmfamily\\mdseries\\upshape Roman"),
@@ -2243,6 +2257,12 @@ mod inline_tests {
);
}
#[test]
fn textsf_inside_bold_stays_bold() {
let runs = inline_runs("\\textbf{a \\textsf{b}}", ParagraphFont::Roman).expect("runs");
assert_eq!(runs[1], (ParagraphFont::SansBold, "b".to_string()));
}
#[test]
fn plain_paragraphs_have_no_runs() {
assert!(inline_runs("no commands here", ParagraphFont::Sans).is_none());