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

+58 -5
View File
@@ -293,6 +293,8 @@ pub enum ParagraphFont {
BoldItalic,
Mono,
Sans,
SansBold,
SansItalic,
}
impl ParagraphFont {
@@ -303,7 +305,10 @@ impl ParagraphFont {
Self::Italic => Self::Roman,
Self::Bold => Self::BoldItalic,
Self::BoldItalic => Self::Bold,
Self::Mono | Self::Sans => self,
Self::Mono => self,
Self::Sans => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SansItalic => Self::Sans,
}
}
@@ -312,7 +317,8 @@ impl ParagraphFont {
match self {
Self::Roman | Self::Bold => Self::Bold,
Self::Italic | Self::BoldItalic => Self::BoldItalic,
Self::Mono | Self::Sans => self,
Self::Mono => self,
Self::Sans | Self::SansBold | Self::SansItalic => Self::SansBold,
}
}
@@ -321,7 +327,9 @@ impl ParagraphFont {
match self {
Self::Bold | Self::Roman => Self::Roman,
Self::BoldItalic | Self::Italic => Self::Italic,
Self::Mono | Self::Sans => self,
Self::Mono => self,
Self::Sans | Self::SansItalic => self,
Self::SansBold => Self::Sans,
}
}
@@ -330,7 +338,10 @@ impl ParagraphFont {
match self {
Self::Roman | Self::Italic => Self::Italic,
Self::Bold | Self::BoldItalic => Self::BoldItalic,
Self::Mono | Self::Sans => self,
Self::Mono => self,
Self::Sans => Self::SansItalic,
Self::SansBold => Self::SansBold,
Self::SansItalic => Self::SansItalic,
}
}
@@ -339,7 +350,9 @@ impl ParagraphFont {
match self {
Self::Roman | Self::Italic => Self::Roman,
Self::Bold | Self::BoldItalic => Self::Bold,
Self::Mono | Self::Sans => self,
Self::Mono => self,
Self::Sans | Self::SansItalic => Self::Sans,
Self::SansBold => Self::SansBold,
}
}
@@ -347,9 +360,20 @@ impl ParagraphFont {
pub const fn roman_family(self) -> Self {
match self {
Self::Mono | Self::Sans => Self::Roman,
Self::SansBold => Self::Bold,
Self::SansItalic => Self::Italic,
other => other,
}
}
/// `\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::Sans,
}
}
}
impl Default for ParagraphFont {
@@ -2309,3 +2333,32 @@ mod tests {
assert_eq!(measured(1), 6, "looser paragraph");
}
}
#[cfg(test)]
mod font_tests {
use super::ParagraphFont;
#[test]
fn sans_faces_compose_with_weight_and_shape() {
assert_eq!(ParagraphFont::Sans.bolded(), ParagraphFont::SansBold);
assert_eq!(ParagraphFont::Sans.emphasized(), ParagraphFont::SansItalic);
assert_eq!(ParagraphFont::SansItalic.emphasized(), ParagraphFont::Sans);
assert_eq!(
ParagraphFont::SansBold.emphasized(),
ParagraphFont::SansBold
);
assert_eq!(ParagraphFont::SansBold.medium(), ParagraphFont::Sans);
assert_eq!(ParagraphFont::SansItalic.upright(), ParagraphFont::Sans);
assert_eq!(ParagraphFont::SansBold.roman_family(), ParagraphFont::Bold);
assert_eq!(
ParagraphFont::SansItalic.roman_family(),
ParagraphFont::Italic
);
assert_eq!(ParagraphFont::Bold.sans_family(), ParagraphFont::SansBold);
assert_eq!(
ParagraphFont::Italic.sans_family(),
ParagraphFont::SansItalic
);
assert_eq!(ParagraphFont::Mono.sans_family(), ParagraphFont::Sans);
}
}