Compose nested inline faces relative to the surrounding run

This commit is contained in:
gloamxun committed 2026-10-24 02:15:08 +08:00
1 parent 0e8999671b
commit 4cf64a4d55
6 files changed
+156 -38

No files matched your search

+1
View File
@@ -114,6 +114,7 @@ impl Cmr10Metrics {
ParagraphFont::Roman => Self::Roman,
ParagraphFont::Bold => Self::Bold,
ParagraphFont::Italic => Self::Italic,
ParagraphFont::BoldItalic => Self::BoldItalic,
ParagraphFont::Mono => Self::Mono,
ParagraphFont::Sans => Self::Sans,
}
+58
View File
@@ -290,10 +290,68 @@ pub enum ParagraphFont {
Roman,
Bold,
Italic,
BoldItalic,
Mono,
Sans,
}
impl ParagraphFont {
/// `\emph`: toggles italic, combining with an inherited bold face.
pub const fn emphasized(self) -> Self {
match self {
Self::Roman => Self::Italic,
Self::Italic => Self::Roman,
Self::Bold => Self::BoldItalic,
Self::BoldItalic => Self::Bold,
Self::Mono | Self::Sans => self,
}
}
/// `\textbf`.
pub const fn bolded(self) -> Self {
match self {
Self::Roman | Self::Bold => Self::Bold,
Self::Italic | Self::BoldItalic => Self::BoldItalic,
Self::Mono | Self::Sans => self,
}
}
/// `\mdseries`.
pub const fn medium(self) -> Self {
match self {
Self::Bold | Self::Roman => Self::Roman,
Self::BoldItalic | Self::Italic => Self::Italic,
Self::Mono | Self::Sans => self,
}
}
/// `\textit` / `\textsl`.
pub const fn italicized(self) -> Self {
match self {
Self::Roman | Self::Italic => Self::Italic,
Self::Bold | Self::BoldItalic => Self::BoldItalic,
Self::Mono | Self::Sans => self,
}
}
/// `\textup`.
pub const fn upright(self) -> Self {
match self {
Self::Roman | Self::Italic => Self::Roman,
Self::Bold | Self::BoldItalic => Self::Bold,
Self::Mono | Self::Sans => self,
}
}
/// `\textrm`.
pub const fn roman_family(self) -> Self {
match self {
Self::Mono | Self::Sans => Self::Roman,
other => other,
}
}
}
impl Default for ParagraphFont {
fn default() -> Self {
Self::Roman
+1
View File
@@ -255,6 +255,7 @@ fn paragraph_face(font: ParagraphFont) -> FontFace {
ParagraphFont::Roman => FontFace::Roman,
ParagraphFont::Bold => FontFace::Bold,
ParagraphFont::Italic => FontFace::Italic,
ParagraphFont::BoldItalic => FontFace::BoldItalic,
ParagraphFont::Mono => FontFace::Mono,
ParagraphFont::Sans => FontFace::Sans,
}