Select real Computer Modern small caps
Add the cmcsc10 face for \scshape and \textsc, including its Type1 outline, and compose the sc shape with the surrounding family and series. Bold small caps substitute cmbx10 and a later shape command wins, matching NFSS.
This commit is contained in:
1 parent
9140990a7d
commit
e303f7852f
11 files changed
+150
-13
No files matched your search
+49
-5
@@ -1040,7 +1040,9 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
ParagraphFont::Sans => (Family::Sans, false, false),
|
||||
ParagraphFont::SansBold => (Family::Sans, true, false),
|
||||
ParagraphFont::SansItalic => (Family::Sans, false, true),
|
||||
ParagraphFont::SmallCaps => (Family::Roman, false, false),
|
||||
};
|
||||
let mut small_caps = base == ParagraphFont::SmallCaps;
|
||||
let mut text = raw.trim_start();
|
||||
let mut consumed = false;
|
||||
loop {
|
||||
@@ -1054,6 +1056,7 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
text = rest;
|
||||
} else if let Some((name, rest)) = nfss_braced(text, "\\fontshape") {
|
||||
italic = name == "it" || name == "sl";
|
||||
small_caps = name == "sc";
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_braced(text, "\\fontencoding").map(|(_, rest)| rest) {
|
||||
text = rest;
|
||||
@@ -1061,6 +1064,7 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
family = Family::Roman;
|
||||
bold = false;
|
||||
italic = false;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\rm") {
|
||||
family = Family::Roman;
|
||||
@@ -1079,14 +1083,19 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\it") {
|
||||
italic = true;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\sl") {
|
||||
italic = true;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\up") {
|
||||
italic = false;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\sc") {
|
||||
small_caps = true;
|
||||
italic = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\rmfamily") {
|
||||
family = Family::Roman;
|
||||
@@ -1105,14 +1114,19 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\itshape") {
|
||||
italic = true;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\slshape") {
|
||||
italic = true;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\upshape") {
|
||||
italic = false;
|
||||
small_caps = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\scshape") {
|
||||
small_caps = true;
|
||||
italic = false;
|
||||
text = rest;
|
||||
} else if let Some(rest) = nfss_declaration(text, "\\selectfont") {
|
||||
text = rest;
|
||||
@@ -1132,11 +1146,12 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)>
|
||||
(false, true) => ParagraphFont::SansItalic,
|
||||
(false, false) => ParagraphFont::Sans,
|
||||
},
|
||||
Family::Roman => match (bold, italic) {
|
||||
(true, true) => ParagraphFont::BoldItalic,
|
||||
(true, false) => ParagraphFont::Bold,
|
||||
(false, true) => ParagraphFont::Italic,
|
||||
(false, false) => ParagraphFont::Roman,
|
||||
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,
|
||||
},
|
||||
};
|
||||
Some((font, text.to_string()))
|
||||
@@ -1222,6 +1237,7 @@ fn inline_wrapper(rest: &str, base: ParagraphFont) -> Option<(ParagraphFont, &st
|
||||
"\\textmd" => base.medium(),
|
||||
"\\textup" => base.upright(),
|
||||
"\\textrm" => base.roman_family(),
|
||||
"\\textsc" => base.small_caps(),
|
||||
"\\textnormal" => ParagraphFont::Roman,
|
||||
_ => base,
|
||||
};
|
||||
@@ -2181,6 +2197,26 @@ mod nfss_tests {
|
||||
paragraph_font("\\sffamily\\itshape Sans text"),
|
||||
ParagraphFont::SansItalic
|
||||
);
|
||||
assert_eq!(
|
||||
paragraph_font("\\scshape Small text"),
|
||||
ParagraphFont::SmallCaps
|
||||
);
|
||||
assert_eq!(
|
||||
paragraph_font("\\sffamily\\scshape Small text"),
|
||||
ParagraphFont::Sans
|
||||
);
|
||||
assert_eq!(
|
||||
paragraph_font("\\bfseries\\scshape Small text"),
|
||||
ParagraphFont::Bold
|
||||
);
|
||||
assert_eq!(
|
||||
paragraph_font("\\scshape\\itshape Small text"),
|
||||
ParagraphFont::Italic
|
||||
);
|
||||
assert_eq!(
|
||||
paragraph_font("\\itshape\\scshape Small text"),
|
||||
ParagraphFont::SmallCaps
|
||||
);
|
||||
assert_eq!(paragraph_font("\\ttfamily Mono text"), ParagraphFont::Mono);
|
||||
assert_eq!(paragraph_font("\\bfseries Bold text"), ParagraphFont::Bold);
|
||||
assert_eq!(
|
||||
@@ -2257,6 +2293,14 @@ mod inline_tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn textsc_composes_with_the_surrounding_face() {
|
||||
let runs = inline_runs("\\textsc{small}", ParagraphFont::Roman).expect("runs");
|
||||
assert_eq!(runs[0], (ParagraphFont::SmallCaps, "small".to_string()));
|
||||
let runs = inline_runs("\\textbf{\\textsc{small}}", ParagraphFont::Roman).expect("runs");
|
||||
assert_eq!(runs[0], (ParagraphFont::Bold, "small".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn textsf_inside_bold_stays_bold() {
|
||||
let runs = inline_runs("\\textbf{a \\textsf{b}}", ParagraphFont::Roman).expect("runs");
|
||||
|
||||
Reference in new issue
Block a user