about summary refs log tree commit diff
path: root/src/x/text_line.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-22 23:18:13 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-22 23:18:13 -0700
commitb7319af1ed9e5dc3c29d05d6f5de9f325fa64191 (patch)
treed3ce5e3b0f6835e4e8179ab8caf2921c7e4ad295 /src/x/text_line.rs
parent1b24796bb97f64ab2771a884632d4b6f64d86f0f (diff)
new subdirectory src/x/text/
Force-Push: yes
Change-Id: I1c428e1f7b42de263534965422dffe007300082c
Diffstat (limited to 'src/x/text_line.rs')
-rw-r--r--src/x/text_line.rs95
1 files changed, 0 insertions, 95 deletions
diff --git a/src/x/text_line.rs b/src/x/text_line.rs
deleted file mode 100644
index 26ee8bf..0000000
--- a/src/x/text_line.rs
+++ /dev/null
@@ -1,95 +0,0 @@
-use crate::error::Result;
-use crate::geometry::{ Alignment, Point };
-use crate::layout::Parcel;
-use crate::x::{ Color, Font, FontGraphicContext, FontList, TextSpan };
-
-use std::sync::{ Arc, Mutex };
-
-
-pub struct TextLine {
-  fonts: Arc<Mutex<FontList>>,
-  spans: Vec<TextSpan>,
-}
-
-
-impl TextLine {
-  pub fn new(fonts: Arc<Mutex<FontList>>) -> Result<TextLine> {
-    let spans = Vec::new();
-
-    Ok(TextLine { fonts, spans })
-  }
-
-  pub fn append_text(&mut self, text: &str) -> Result<()> {
-    let mut current_span_font: Option<Arc<Font>> = None;
-    let mut current_span_text = String::new();
-
-    for char in text.chars() {
-      let codepoint = char as u32;
-
-      let new_font = &self.fonts.lock()?.find_codepoint(codepoint)?;
-      if let Some(old_font) = &current_span_font {
-        if old_font != new_font {
-          let span = old_font.text_span(&current_span_text)?;
-          self.spans.push(span);
-
-          current_span_font = Some(Arc::clone(new_font));
-          current_span_text = String::new();
-        }
-      } else {
-        current_span_font = Some(Arc::clone(new_font));
-      }
-
-      current_span_text.push(char);
-    }
-
-    if let Some(font) = current_span_font
-       && !current_span_text.is_empty()
-    {
-      let span = font.text_span(&current_span_text)?;
-      self.spans.push(span);
-    }
-
-    Ok(())
-  }
-
-  pub fn spans(&self) -> impl Iterator<Item=&TextSpan> + DoubleEndedIterator {
-    self.spans.iter()
-  }
-
-  pub fn layout_and_draw(&self, open_parcel: &mut Parcel,
-                         alignment: Alignment, context: &FontGraphicContext,
-                         color: &Color, baseline_position: i16)
-    -> Result<()>
-  {
-    let mut location = Point::<i32>::zero();
-    location.y += baseline_position as i32;
-
-    match alignment {
-      Alignment::Left => {
-        location.x += open_parcel.left as i32;
-      }
-      Alignment::Right => {
-        location.x += open_parcel.right as i32;
-      }
-    }
-
-    /* A reversed iterator is a different type, so we need two of this loop. */
-    match alignment {
-      Alignment::Left => {
-        for span in self.spans() {
-          span.layout_and_draw(open_parcel, &mut location,
-                               alignment, context, color)?;
-        }
-      }
-      Alignment::Right => {
-        for span in self.spans().rev() {
-          span.layout_and_draw(open_parcel, &mut location,
-                                    alignment, context, color)?;
-        }
-      }
-    }
-
-    Ok(())
-  }
-}
-