From bbcdeb128cce04cd95714b7bc7af5a23a7e38bd2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 29 Jul 2020 18:09:51 +0200 Subject: =?UTF-8?q?Move,=20rename=20and=20switch=20some=20things=20(boring?= =?UTF-8?q?)=20=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Problems -> Diagnostics - Position -> Pos - offset_spans -> Offset trait - Size -> Length (and some more size types renamed) - Paper into its own module - scope::Parser -> parsing::CallParser - Create `Decorations` alias - Remove lots of double newlines - Switch from f32 to f64 --- src/layout/text.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/layout/text.rs') diff --git a/src/layout/text.rs b/src/layout/text.rs index 286ccc68..cbe40214 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -8,11 +8,10 @@ use toddle::query::{FontQuery, FontIndex}; use toddle::tables::{CharMap, Header, HorizontalMetrics}; use crate::GlobalFontLoader; -use crate::size::{Size, Size2D}; +use crate::length::{Length, Size}; use crate::style::TextStyle; use super::*; - /// Performs the text layouting. #[derive(Debug)] struct TextLayouter<'a> { @@ -21,7 +20,7 @@ struct TextLayouter<'a> { actions: LayoutActions, buffer: String, active_font: FontIndex, - width: Size, + width: Length, } /// The context for text layouting. @@ -54,7 +53,7 @@ impl<'a> TextLayouter<'a> { actions: LayoutActions::new(), buffer: String::new(), active_font: FontIndex::MAX, - width: Size::ZERO, + width: Length::ZERO, } } @@ -77,7 +76,7 @@ impl<'a> TextLayouter<'a> { } Layout { - dimensions: Size2D::new(self.width, self.ctx.style.font_size()), + dimensions: Size::new(self.width, self.ctx.style.font_size()), alignment: self.ctx.alignment, actions: self.actions.into_vec(), } @@ -110,7 +109,7 @@ impl<'a> TextLayouter<'a> { /// Select the best font for a character and return its index along with /// the width of the char in the font. - async fn select_font(&mut self, c: char) -> Option<(FontIndex, Size)> { + async fn select_font(&mut self, c: char) -> Option<(FontIndex, Length)> { let mut loader = self.ctx.loader.borrow_mut(); let mut variant = self.ctx.style.variant; @@ -127,8 +126,8 @@ impl<'a> TextLayouter<'a> { if let Some((font, index)) = loader.get(query).await { // Determine the width of the char. let header = font.read_table::
().ok()?; - let font_unit_ratio = 1.0 / (header.units_per_em as f32); - let font_unit_to_size = |x| Size::pt(font_unit_ratio * x); + let font_unit_ratio = 1.0 / (header.units_per_em as f64); + let font_unit_to_size = |x| Length::pt(font_unit_ratio * x); let glyph = font .read_table::() @@ -139,7 +138,7 @@ impl<'a> TextLayouter<'a> { .read_table::() .ok()? .get(glyph)? - .advance_width as f32; + .advance_width as f64; let char_width = font_unit_to_size(glyph_width) * self.ctx.style.font_size().to_pt(); -- cgit v1.2.3