diff options
Diffstat (limited to 'src/layout/frame.rs')
| -rw-r--r-- | src/layout/frame.rs | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/src/layout/frame.rs b/src/layout/frame.rs index 6e876151..d3276e99 100644 --- a/src/layout/frame.rs +++ b/src/layout/frame.rs @@ -1,7 +1,9 @@ -use super::Shaped; +use fontdock::FaceId; +use ttf_parser::GlyphId; + use crate::color::Color; use crate::env::ResourceId; -use crate::geom::{Path, Point, Size}; +use crate::geom::{Length, Path, Point, Size}; /// A finished layout with elements at fixed positions. #[derive(Debug, Clone, PartialEq)] @@ -36,13 +38,67 @@ impl Frame { #[derive(Debug, Clone, PartialEq)] pub enum Element { /// Shaped text. - Text(Shaped), + Text(ShapedText), /// A geometric shape. Geometry(Geometry), /// A raster image. Image(Image), } +/// A shaped run of text. +#[derive(Debug, Clone, PartialEq)] +pub struct ShapedText { + /// The font face the text was shaped with. + pub face: FaceId, + /// The font size. + pub size: Length, + /// The width. + pub width: Length, + /// The extent to the top. + pub top: Length, + /// The extent to the bottom. + pub bottom: Length, + /// The glyph fill color / texture. + pub color: Fill, + /// The shaped glyphs. + pub glyphs: Vec<GlyphId>, + /// The horizontal offsets of the glyphs. This is indexed parallel to + /// `glyphs`. Vertical offsets are not yet supported. + pub offsets: Vec<Length>, +} + +impl ShapedText { + /// Create a new shape run with `width` zero and empty `glyphs` and `offsets`. + pub fn new( + face: FaceId, + size: Length, + top: Length, + bottom: Length, + color: Fill, + ) -> Self { + Self { + face, + size, + width: Length::ZERO, + top, + bottom, + glyphs: vec![], + offsets: vec![], + color, + } + } + + /// Encode the glyph ids into a big-endian byte buffer. + pub fn encode_glyphs_be(&self) -> Vec<u8> { + let mut bytes = Vec::with_capacity(2 * self.glyphs.len()); + for &GlyphId(g) in &self.glyphs { + bytes.push((g >> 8) as u8); + bytes.push((g & 0xff) as u8); + } + bytes + } +} + /// A shape with some kind of fill. #[derive(Debug, Clone, PartialEq)] pub struct Geometry { |
