summaryrefslogtreecommitdiff
path: root/src/exec/state.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-25 01:16:38 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-25 01:16:38 +0200
commitec5384c97f24c3e6d8284926fd3e415f47fe2b04 (patch)
treeae95815628fd9ae9f765453a6a4b8729b26943ab /src/exec/state.rs
parentdcfbf95220300a7866b6d03953fb4d29511cd6fa (diff)
State-based monospace handling
Diffstat (limited to 'src/exec/state.rs')
-rw-r--r--src/exec/state.rs48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/exec/state.rs b/src/exec/state.rs
index f99a8901..624394ba 100644
--- a/src/exec/state.rs
+++ b/src/exec/state.rs
@@ -111,6 +111,14 @@ pub struct FontState {
pub families: Rc<FamilyList>,
/// The selected font variant.
pub variant: FontVariant,
+ /// Whether the strong toggle is active or inactive. This determines
+ /// whether the next `*` adds or removes font weight.
+ pub strong: bool,
+ /// Whether the emphasis toggle is active or inactive. This determines
+ /// whether the next `_` makes italic or non-italic.
+ pub emph: bool,
+ /// Whether the monospace toggle is active or inactive.
+ pub monospace: bool,
/// The font size.
pub size: Length,
/// The top end of the text bounding box.
@@ -119,12 +127,6 @@ pub struct FontState {
pub bottom_edge: VerticalFontMetric,
/// Glyph color.
pub fill: Paint,
- /// Whether the strong toggle is active or inactive. This determines
- /// whether the next `*` adds or removes font weight.
- pub strong: bool,
- /// Whether the emphasis toggle is active or inactive. This determines
- /// whether the next `_` makes italic or non-italic.
- pub emph: bool,
/// The specifications for a strikethrough line, if any.
pub strikethrough: Option<Rc<LineState>>,
/// The specifications for a underline, if any.
@@ -138,6 +140,35 @@ impl FontState {
pub fn families_mut(&mut self) -> &mut FamilyList {
Rc::make_mut(&mut self.families)
}
+
+ /// The canonical family iterator.
+ pub fn families(&self) -> impl Iterator<Item = &str> + Clone {
+ let head = if self.monospace {
+ self.families.monospace.as_slice()
+ } else {
+ &[]
+ };
+ head.iter().map(String::as_str).chain(self.families.iter())
+ }
+
+ /// The canonical variant with `strong` and `emph` factored in.
+ pub fn variant(&self) -> FontVariant {
+ let mut variant = self.variant;
+
+ if self.strong {
+ variant.weight = variant.weight.thicken(300);
+ }
+
+ if self.emph {
+ variant.style = match variant.style {
+ FontStyle::Normal => FontStyle::Italic,
+ FontStyle::Italic => FontStyle::Normal,
+ FontStyle::Oblique => FontStyle::Normal,
+ }
+ }
+
+ variant
+ }
}
impl Default for FontState {
@@ -149,12 +180,13 @@ impl Default for FontState {
weight: FontWeight::REGULAR,
stretch: FontStretch::NORMAL,
},
+ strong: false,
+ emph: false,
+ monospace: false,
size: Length::pt(11.0),
top_edge: VerticalFontMetric::CapHeight,
bottom_edge: VerticalFontMetric::Baseline,
fill: Paint::Color(Color::Rgba(RgbaColor::BLACK)),
- strong: false,
- emph: false,
strikethrough: None,
underline: None,
overline: None,