From 6cb9fe9064a037224b6560b69b441b72e787fa94 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 19 Mar 2021 22:36:13 +0100 Subject: =?UTF-8?q?Text=20colors=20=F0=9F=A6=A9=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/shaping.rs | 12 ++++++++---- src/layout/text.rs | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/layout') diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index 1b769db7..df27e287 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -11,7 +11,7 @@ use ttf_parser::{Face, GlyphId}; use crate::env::FontLoader; use crate::geom::{Dir, Length, Point, Size}; -use crate::layout::{Element, Frame}; +use crate::layout::{Element, Fill, Frame}; /// A shaped run of text. #[derive(Clone, PartialEq)] @@ -27,17 +27,20 @@ pub struct Shaped { pub offsets: Vec, /// The font size. pub font_size: Length, + /// The glyph fill color / texture. + pub color: Fill, } impl Shaped { /// Create a new shape run with empty `text`, `glyphs` and `offsets`. - pub fn new(face: FaceId, font_size: Length) -> Self { + pub fn new(face: FaceId, font_size: Length, color: Fill) -> Self { Self { text: String::new(), face, glyphs: vec![], offsets: vec![], font_size, + color: color, } } @@ -100,10 +103,11 @@ pub fn shape( font_size: Length, top_edge: VerticalFontMetric, bottom_edge: VerticalFontMetric, + color: Fill, loader: &mut FontLoader, ) -> Frame { let mut frame = Frame::new(Size::new(Length::ZERO, Length::ZERO)); - let mut shaped = Shaped::new(FaceId::MAX, font_size); + let mut shaped = Shaped::new(FaceId::MAX, font_size, color); let mut width = Length::ZERO; let mut top = Length::ZERO; let mut bottom = Length::ZERO; @@ -133,7 +137,7 @@ pub fn shape( if shaped.face != id { place(&mut frame, shaped, width, top, bottom); - shaped = Shaped::new(id, font_size); + shaped = Shaped::new(id, font_size, color); width = Length::ZERO; top = convert(f64::from(lookup_metric(face, top_edge))); bottom = convert(f64::from(lookup_metric(face, bottom_edge))); diff --git a/src/layout/text.rs b/src/layout/text.rs index 7faefa0d..7f8f97cc 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -24,6 +24,8 @@ pub struct TextNode { pub top_edge: VerticalFontMetric, /// The bottom end of the text bounding box. pub bottom_edge: VerticalFontMetric, + /// The glyph fill. + pub color: Fill, } impl Layout for TextNode { @@ -37,6 +39,7 @@ impl Layout for TextNode { self.font_size, self.top_edge, self.bottom_edge, + self.color, &mut ctx.env.fonts, ), self.aligns, -- cgit v1.2.3