Add sans family and true small caps
This commit is contained in:
1 parent
e44d4c8669
commit
337eaa1778
15 files changed
+628
-122
No files matched your search
@@ -219,6 +219,8 @@ pub struct Run {
|
||||
pub bold: bool,
|
||||
pub italic: bool,
|
||||
pub monospace: bool,
|
||||
pub sans: bool,
|
||||
pub small_caps: bool,
|
||||
/// True for the synthetic kern that carries paragraph indentation.
|
||||
pub paragraph_indent: bool,
|
||||
}
|
||||
@@ -237,6 +239,8 @@ impl Run {
|
||||
bold: false,
|
||||
italic: false,
|
||||
monospace: false,
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
paragraph_indent: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,8 +384,9 @@ struct Parser {
|
||||
bold: bool,
|
||||
italic: bool,
|
||||
monospace: bool,
|
||||
sans: bool,
|
||||
small_caps: bool,
|
||||
text_style_stack: Vec<(expanded::TextStyle, bool, bool, bool, bool)>,
|
||||
text_style_stack: Vec<(expanded::TextStyle, bool, bool, bool, bool, bool)>,
|
||||
style_declarations: Vec<(usize, expanded::TextStyle)>,
|
||||
group_depth: usize,
|
||||
section_numbers: [u32; 3],
|
||||
@@ -423,6 +424,7 @@ impl Parser {
|
||||
bold: false,
|
||||
italic: false,
|
||||
monospace: false,
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
text_style_stack: Vec::new(),
|
||||
style_declarations: Vec::new(),
|
||||
@@ -596,6 +598,7 @@ impl Parser {
|
||||
&& !self.bold
|
||||
&& !self.italic
|
||||
&& !self.monospace
|
||||
&& !self.sans
|
||||
&& self.text_style_stack.is_empty()
|
||||
}
|
||||
|
||||
@@ -621,17 +624,20 @@ impl Parser {
|
||||
self.bold,
|
||||
self.italic,
|
||||
self.monospace,
|
||||
self.sans,
|
||||
self.small_caps,
|
||||
));
|
||||
match style {
|
||||
expanded::TextStyle::Bold => self.bold = true,
|
||||
expanded::TextStyle::Italic => self.italic = true,
|
||||
expanded::TextStyle::Monospace => self.monospace = true,
|
||||
expanded::TextStyle::Sans => self.sans = true,
|
||||
expanded::TextStyle::SmallCaps => self.small_caps = true,
|
||||
expanded::TextStyle::Normal => {
|
||||
self.bold = false;
|
||||
self.italic = false;
|
||||
self.monospace = false;
|
||||
self.sans = false;
|
||||
self.small_caps = false;
|
||||
}
|
||||
}
|
||||
@@ -641,12 +647,14 @@ impl Parser {
|
||||
if self
|
||||
.text_style_stack
|
||||
.last()
|
||||
.is_some_and(|(active_style, _, _, _, _)| *active_style == style)
|
||||
&& let Some((_, bold, italic, monospace, small_caps)) = self.text_style_stack.pop()
|
||||
.is_some_and(|(active_style, _, _, _, _, _)| *active_style == style)
|
||||
&& let Some((_, bold, italic, monospace, sans, small_caps)) =
|
||||
self.text_style_stack.pop()
|
||||
{
|
||||
self.bold = bold;
|
||||
self.italic = italic;
|
||||
self.monospace = monospace;
|
||||
self.sans = sans;
|
||||
self.small_caps = small_caps;
|
||||
}
|
||||
}
|
||||
@@ -693,6 +701,9 @@ impl Parser {
|
||||
monospace: false,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
};
|
||||
self.target_runs().push(run);
|
||||
}
|
||||
@@ -959,6 +970,9 @@ impl Parser {
|
||||
monospace: false,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1008,16 +1022,11 @@ impl Parser {
|
||||
{
|
||||
self.paragraph_source = self.current_source.clone();
|
||||
}
|
||||
let uppercased;
|
||||
let text: &str = if self.small_caps {
|
||||
uppercased = text.to_uppercase();
|
||||
uppercased.as_str()
|
||||
} else {
|
||||
text
|
||||
};
|
||||
let bold = self.bold;
|
||||
let italic = self.italic;
|
||||
let monospace = self.monospace;
|
||||
let sans = self.sans;
|
||||
let small_caps = self.small_caps;
|
||||
if self.table.is_some() {
|
||||
let mut pieces = text.split('&').peekable();
|
||||
while let Some(piece) = pieces.next() {
|
||||
@@ -1027,6 +1036,8 @@ impl Parser {
|
||||
bold,
|
||||
italic,
|
||||
monospace,
|
||||
sans,
|
||||
small_caps,
|
||||
);
|
||||
if pieces.peek().is_some() {
|
||||
self.finish_table_cell();
|
||||
@@ -1039,6 +1050,8 @@ impl Parser {
|
||||
bold,
|
||||
italic,
|
||||
monospace,
|
||||
sans,
|
||||
small_caps,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1077,6 +1090,9 @@ impl Parser {
|
||||
monospace,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1107,6 +1123,9 @@ impl Parser {
|
||||
monospace,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1142,6 +1161,9 @@ impl Parser {
|
||||
monospace,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1187,6 +1209,9 @@ impl Parser {
|
||||
monospace,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1254,7 +1279,17 @@ impl Parser {
|
||||
let bold = self.bold;
|
||||
let italic = self.italic;
|
||||
let monospace = self.monospace;
|
||||
append_run(self.target_runs(), "&".to_string(), bold, italic, monospace);
|
||||
let sans = self.sans;
|
||||
let small_caps = self.small_caps;
|
||||
append_run(
|
||||
self.target_runs(),
|
||||
"&".to_string(),
|
||||
bold,
|
||||
italic,
|
||||
monospace,
|
||||
sans,
|
||||
small_caps,
|
||||
);
|
||||
}
|
||||
|
||||
fn append_reference(&mut self, reference: UnresolvedReference) {
|
||||
@@ -1288,6 +1323,9 @@ impl Parser {
|
||||
monospace,
|
||||
|
||||
paragraph_indent: false,
|
||||
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1612,6 +1650,8 @@ fn indent_run(indent: common::Scaled) -> Run {
|
||||
bold: false,
|
||||
italic: false,
|
||||
monospace: false,
|
||||
sans: false,
|
||||
small_caps: false,
|
||||
paragraph_indent: true,
|
||||
}
|
||||
}
|
||||
@@ -1628,7 +1668,15 @@ fn strip_paragraph_indent(runs: &mut Vec<Run>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn append_run(runs: &mut Vec<Run>, mut text: String, bold: bool, italic: bool, monospace: bool) {
|
||||
fn append_run(
|
||||
runs: &mut Vec<Run>,
|
||||
mut text: String,
|
||||
bold: bool,
|
||||
italic: bool,
|
||||
monospace: bool,
|
||||
sans: bool,
|
||||
small_caps: bool,
|
||||
) {
|
||||
if text.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -1649,6 +1697,8 @@ fn append_run(runs: &mut Vec<Run>, mut text: String, bold: bool, italic: bool, m
|
||||
&& last.bold == bold
|
||||
&& last.italic == italic
|
||||
&& last.monospace == monospace
|
||||
&& last.sans == sans
|
||||
&& last.small_caps == small_caps
|
||||
{
|
||||
last.text.push_str(&text);
|
||||
return;
|
||||
@@ -1665,7 +1715,8 @@ fn append_run(runs: &mut Vec<Run>, mut text: String, bold: bool, italic: bool, m
|
||||
bold,
|
||||
italic,
|
||||
monospace,
|
||||
|
||||
sans,
|
||||
small_caps,
|
||||
paragraph_indent: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::{
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum TextStyle {
|
||||
Sans,
|
||||
Bold,
|
||||
Italic,
|
||||
Monospace,
|
||||
|
||||
@@ -867,7 +867,7 @@ fn parse_math_text_group(
|
||||
TextStyle::Bold => bold = true,
|
||||
TextStyle::Italic => italic = true,
|
||||
TextStyle::Monospace => monospace = true,
|
||||
TextStyle::SmallCaps => {}
|
||||
TextStyle::SmallCaps | TextStyle::Sans => {}
|
||||
TextStyle::Normal => {
|
||||
bold = false;
|
||||
italic = false;
|
||||
|
||||
Reference in new issue
Block a user