diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-04 19:57:39 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-04 19:57:39 +0200 |
| commit | c1dd872b34507a9f45b39a8a6ac70606b642a19d (patch) | |
| tree | e3afa36228321f7b0680d8c989818f306b80d43e /src/layout/elements.rs | |
| parent | 105f70867ddcb2c73860bf0c55f1380eda2437ca (diff) | |
Remove unncessary wrappers and typedefs 🛑
Diffstat (limited to 'src/layout/elements.rs')
| -rw-r--r-- | src/layout/elements.rs | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/src/layout/elements.rs b/src/layout/elements.rs deleted file mode 100644 index b5f83bfe..00000000 --- a/src/layout/elements.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! Basic building blocks of layouts. - -use std::fmt::{self, Debug, Formatter}; - -use fontdock::FaceId; -use ttf_parser::GlyphId; - -use crate::geom::Point; - -/// A collection of absolutely positioned layout elements. -#[derive(Debug, Default, Clone, PartialEq)] -pub struct LayoutElements(pub Vec<(Point, LayoutElement)>); - -impl LayoutElements { - /// Create an new empty collection. - pub fn new() -> Self { - Self(vec![]) - } - - /// Add an element at a position. - pub fn push(&mut self, pos: Point, element: LayoutElement) { - self.0.push((pos, element)); - } - - /// Add all elements of another collection, placing them relative to the - /// given position. - pub fn push_elements(&mut self, pos: Point, more: Self) { - for (subpos, element) in more.0 { - self.0.push((pos + subpos.to_vec2(), element)); - } - } -} - -/// A layout element, the basic building block layouts are composed of. -#[derive(Debug, Clone, PartialEq)] -pub enum LayoutElement { - Text(Shaped), -} - -/// A shaped run of text. -#[derive(Clone, PartialEq)] -pub struct Shaped { - /// The shaped text. - pub text: String, - /// The font face the text was shaped with. - pub face: FaceId, - /// The shaped glyphs. - pub glyphs: Vec<GlyphId>, - /// The horizontal offsets of the glyphs. This is indexed parallel to `glyphs`. - /// Vertical offets are not yet supported. - pub offsets: Vec<f64>, - /// The font size. - pub size: f64, -} - -impl Shaped { - /// Create a new shape run with empty `text`, `glyphs` and `offsets`. - pub fn new(face: FaceId, size: f64) -> Self { - Self { - text: String::new(), - face, - glyphs: vec![], - offsets: vec![], - size, - } - } - - /// 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 - } -} - -impl Debug for Shaped { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "Shaped({})", self.text) - } -} |
