summaryrefslogtreecommitdiff
path: root/src/style/mod.rs
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2021-10-28 21:25:03 +0200
committerLaurenz <laurmaedje@gmail.com>2021-11-02 10:39:45 +0100
commit8ccb7d6f15a2fbb44247c143b3dd821e44e0d6eb (patch)
treea58b538e34418c035b55e880eaf5a1ffc146a6da /src/style/mod.rs
parent5b344b663a3d224134923eea0d67ebf44c069b07 (diff)
Smallcaps, sub- and superscript, ligature ctrls...
Diffstat (limited to 'src/style/mod.rs')
-rw-r--r--src/style/mod.rs122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/style/mod.rs b/src/style/mod.rs
index 755fb3e5..cb27181f 100644
--- a/src/style/mod.rs
+++ b/src/style/mod.rs
@@ -136,6 +136,8 @@ pub struct TextStyle {
/// A list of font families with generic class definitions (the final
/// family list also depends on `monospace`).
pub families: Rc<FamilyStyle>,
+ /// OpenType features.
+ pub features: Rc<FontFeatures>,
/// Whether 300 extra font weight should be added to what is defined by the
/// `variant`.
pub strong: bool,
@@ -197,6 +199,11 @@ impl TextStyle {
pub fn families_mut(&mut self) -> &mut FamilyStyle {
Rc::make_mut(&mut self.families)
}
+
+ /// Access the font `features` mutably.
+ pub fn features_mut(&mut self) -> &mut FontFeatures {
+ Rc::make_mut(&mut self.features)
+ }
}
impl Default for TextStyle {
@@ -212,6 +219,7 @@ impl Default for TextStyle {
bottom_edge: VerticalFontMetric::Baseline,
fill: Paint::Color(Color::Rgba(RgbaColor::BLACK)),
families: Rc::new(FamilyStyle::default()),
+ features: Rc::new(FontFeatures::default()),
strong: false,
emph: false,
monospace: false,
@@ -250,3 +258,117 @@ impl Default for FamilyStyle {
}
}
}
+
+/// Whether various kinds of ligatures should appear.
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
+pub struct FontFeatures {
+ /// Whether to apply kerning ("kern").
+ pub kerning: bool,
+ /// Whether the text should use small caps. ("smcp")
+ pub smallcaps: bool,
+ /// Whether to apply stylistic alternates. ("salt")
+ pub alternates: bool,
+ /// Which stylistic set to apply. ("ss00" - "ss20")
+ pub stylistic_set: Option<u8>,
+ /// Configuration of ligature features.
+ pub ligatures: LigatureFeatures,
+ /// Configuration of numbers features.
+ pub numbers: NumberFeatures,
+ /// Raw OpenType features to apply.
+ pub raw: Vec<(String, u32)>,
+}
+
+impl Default for FontFeatures {
+ fn default() -> Self {
+ Self {
+ kerning: true,
+ smallcaps: false,
+ alternates: false,
+ stylistic_set: None,
+ ligatures: LigatureFeatures::default(),
+ numbers: NumberFeatures::default(),
+ raw: vec![],
+ }
+ }
+}
+
+/// Whether various kinds of ligatures should appear.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub struct LigatureFeatures {
+ /// Standard ligatures. ("liga", "clig")
+ pub standard: bool,
+ /// Ligatures that should be used sparringly. ("dlig")
+ pub discretionary: bool,
+ /// Historical ligatures. ("hlig")
+ pub historical: bool,
+}
+
+impl Default for LigatureFeatures {
+ fn default() -> Self {
+ Self {
+ standard: true,
+ discretionary: false,
+ historical: false,
+ }
+ }
+}
+
+/// Defines the style of numbers.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub struct NumberFeatures {
+ /// Whether to use lining or old-style numbers.
+ pub style: NumberStyle,
+ /// Whether to use proportional or tabular numbers.
+ pub width: NumberWidth,
+ /// How to position numbers vertically.
+ pub position: NumberPosition,
+ /// Whether to have a slash through the zero glyph. ("zero")
+ pub slashed_zero: bool,
+ /// Whether to convert fractions. ("frac")
+ pub fractions: bool,
+}
+
+impl Default for NumberFeatures {
+ fn default() -> Self {
+ Self {
+ style: NumberStyle::Auto,
+ width: NumberWidth::Auto,
+ position: NumberPosition::Normal,
+ slashed_zero: false,
+ fractions: false,
+ }
+ }
+}
+
+/// How numbers / figures look.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub enum NumberStyle {
+ /// Select the font's preference.
+ Auto,
+ /// Numbers that fit well with capital text. ("lnum")
+ Lining,
+ /// Numbers that fit well into flow of upper- and lowercase text. ("onum")
+ OldStyle,
+}
+
+/// The width of numbers / figures.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub enum NumberWidth {
+ /// Select the font's preference.
+ Auto,
+ /// Number widths are glyph specific. ("pnum")
+ Proportional,
+ /// All numbers are of equal width / monospaced. ("tnum")
+ Tabular,
+}
+
+/// How to position numbers.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub enum NumberPosition {
+ /// Numbers are positioned on the same baseline as text.
+ Normal,
+ /// Numbers are smaller and placed at the bottom. ("subs")
+ Subscript,
+ /// Numbers are smaller and placed at the top. ("sups")
+ Superscript,
+}