summaryrefslogtreecommitdiff
path: root/src/style.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-01 19:15:55 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-01 19:15:55 +0200
commit659248d52ff9e6be4dad7c4555bd62899671ad55 (patch)
tree610f382adc09524a08c5cbb941e46103117a88e5 /src/style.rs
parent04c05502bee50f7657dc2d88c60eb935b068a284 (diff)
Raw lengths 🚲
Replace unitless length with raw f64 and introduce length type with unit.
Diffstat (limited to 'src/style.rs')
-rw-r--r--src/style.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/style.rs b/src/style.rs
index ca05d68f..0490ef07 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -1,7 +1,8 @@
//! Styles for text and pages.
use fontdock::{fallback, FallbackTree, FontVariant, FontStyle, FontWeight, FontWidth};
-use crate::length::{Length, Size, Margins, Value4, ScaleLength};
+use crate::geom::{Size, Margins, Value4};
+use crate::length::{Length, ScaleLength};
use crate::paper::{Paper, PaperClass, PAPER_A4};
/// Defines properties of pages and text.
@@ -27,7 +28,7 @@ pub struct TextStyle {
/// whether the next `_` makes italic or non-italic.
pub italic: bool,
/// The base font size.
- pub base_font_size: Length,
+ pub base_font_size: f64,
/// The font scale to apply on the base font size.
pub font_scale: f64,
/// The word spacing (as a multiple of the font size).
@@ -40,22 +41,22 @@ pub struct TextStyle {
impl TextStyle {
/// The scaled font size.
- pub fn font_size(&self) -> Length {
+ pub fn font_size(&self) -> f64 {
self.base_font_size * self.font_scale
}
/// The absolute word spacing.
- pub fn word_spacing(&self) -> Length {
+ pub fn word_spacing(&self) -> f64 {
self.word_spacing_scale * self.font_size()
}
/// The absolute line spacing.
- pub fn line_spacing(&self) -> Length {
+ pub fn line_spacing(&self) -> f64 {
(self.line_spacing_scale - 1.0) * self.font_size()
}
/// The absolute paragraph spacing.
- pub fn paragraph_spacing(&self) -> Length {
+ pub fn paragraph_spacing(&self) -> f64 {
(self.paragraph_spacing_scale - 1.0) * self.font_size()
}
}
@@ -81,7 +82,7 @@ impl Default for TextStyle {
},
bolder: false,
italic: false,
- base_font_size: Length::pt(11.0),
+ base_font_size: Length::pt(11.0).as_raw(),
font_scale: 1.0,
word_spacing_scale: 0.25,
line_spacing_scale: 1.2,
@@ -118,10 +119,10 @@ impl PageStyle {
let default = self.class.default_margins();
Margins {
- left: self.margins.left.unwrap_or(default.left).scaled(dims.x),
- top: self.margins.top.unwrap_or(default.top).scaled(dims.y),
- right: self.margins.right.unwrap_or(default.right).scaled(dims.x),
- bottom: self.margins.bottom.unwrap_or(default.bottom).scaled(dims.y),
+ left: self.margins.left.unwrap_or(default.left).raw_scaled(dims.x),
+ top: self.margins.top.unwrap_or(default.top).raw_scaled(dims.y),
+ right: self.margins.right.unwrap_or(default.right).raw_scaled(dims.x),
+ bottom: self.margins.bottom.unwrap_or(default.bottom).raw_scaled(dims.y),
}
}
}