diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-19 13:20:58 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-19 13:20:58 +0100 |
| commit | 54a9ccb1a5e9f1f1e5d2538d2f4ce3d4f7afc4ae (patch) | |
| tree | 3a0f45af5d1cd6d65420887f8412a5594b6300bd /src/exec/state.rs | |
| parent | bd12d135cab32d61b32945433e77579d04298d52 (diff) | |
Configurable font edges ⚙
Adds top-edge and bottom-edge parameters to the font function. These define how
the box around a word is computed. The possible values are:
- ascender
- cap-height (default top edge)
- x-height
- baseline (default bottom edge)
- descender
The defaults are chosen so that it's easy to create good-looking designs with
vertical alignment. Since they are much tighter than what most other software
uses by default, the default leading had to be increased to 50% of the font size
and paragraph spacing to 100% of the font size.
The values cap-height and x-height fall back to ascender in case they are zero
because this value may occur in fonts that don't have glyphs with cap- or
x-height (like Twitter Color Emoji). Since cap-height is the default top edge,
doing no fallback would break things badly.
Removes softness in favor of a simple boolean for pages and a more finegread u8
for spacing. This is needed to make paragraph spacing consume line spacing
created by hard line breaks.
Diffstat (limited to 'src/exec/state.rs')
| -rw-r--r-- | src/exec/state.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/exec/state.rs b/src/exec/state.rs index 65f26439..aa2dde1c 100644 --- a/src/exec/state.rs +++ b/src/exec/state.rs @@ -2,10 +2,9 @@ use std::rc::Rc; use fontdock::{fallback, FallbackTree, FontStretch, FontStyle, FontVariant, FontWeight}; -use crate::geom::{ - Align, Dir, LayoutAligns, LayoutDirs, Length, Linear, Relative, Sides, Size, -}; +use crate::geom::*; use crate::paper::{Paper, PaperClass, PAPER_A4}; +use crate::shaping::VerticalFontMetric; /// The evaluation state. #[derive(Debug, Clone, PartialEq)] @@ -77,20 +76,20 @@ impl Default for PageState { /// Defines paragraph properties. #[derive(Debug, Copy, Clone, PartialEq)] pub struct ParState { + /// The spacing between paragraphs (dependent on scaled font size). + pub spacing: Linear, + /// The spacing between lines (dependent on scaled font size). + pub leading: Linear, /// The spacing between words (dependent on scaled font size). pub word_spacing: Linear, - /// The spacing between lines (dependent on scaled font size). - pub line_spacing: Linear, - /// The spacing between paragraphs (dependent on scaled font size). - pub par_spacing: Linear, } impl Default for ParState { fn default() -> Self { Self { + spacing: Relative::new(1.0).into(), + leading: Relative::new(0.5).into(), word_spacing: Relative::new(0.25).into(), - line_spacing: Linear::ZERO, - par_spacing: Relative::new(0.5).into(), } } } @@ -106,6 +105,10 @@ pub struct FontState { pub size: Length, /// The linear to apply on the base font size. pub scale: Linear, + /// The top end of the text bounding box. + pub top_edge: VerticalFontMetric, + /// The bottom end of the text bounding box. + pub bottom_edge: VerticalFontMetric, /// Whether the strong toggle is active or inactive. This determines /// whether the next `*` adds or removes font weight. pub strong: bool, @@ -141,6 +144,8 @@ impl Default for FontState { stretch: FontStretch::Normal, }, size: Length::pt(11.0), + top_edge: VerticalFontMetric::CapHeight, + bottom_edge: VerticalFontMetric::Baseline, scale: Linear::ONE, strong: false, emph: false, |
