diff options
| author | Martin <mhaug@live.de> | 2021-03-19 22:36:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-19 22:36:13 +0100 |
| commit | 6cb9fe9064a037224b6560b69b441b72e787fa94 (patch) | |
| tree | 9a5474758e37199c7a01c6d22383ede225deab4d /src/layout | |
| parent | 898dc38ec153709929d2513fb9d040dd2c1ce0fe (diff) | |
Text colors 🦩 (#18)
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/shaping.rs | 12 | ||||
| -rw-r--r-- | src/layout/text.rs | 3 |
2 files changed, 11 insertions, 4 deletions
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<Length>, /// 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, |
