🎉 Render plain text

* 🎉 Serialize text content (wasm)

* ♻️ Refactor functions in main to wasm module

* 🎉 Stub rendering of paragraph text (wasm)

* 📎 Clean up commented code
This commit is contained in:
Belén Albeza 2025-03-04 11:54:52 +01:00 committed by GitHub
parent 9e5de82967
commit aa468e2153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 256 additions and 9 deletions

View file

@ -18,6 +18,7 @@ mod rects;
mod shadows;
mod strokes;
mod svgraw;
mod text;
mod transform;
pub use blurs::*;
@ -33,6 +34,7 @@ pub use rects::*;
pub use shadows::*;
pub use strokes::*;
pub use svgraw::*;
pub use text::*;
pub use transform::*;
use crate::math;
@ -45,9 +47,9 @@ pub enum Type {
Bool(Bool),
Rect(Rect),
Path(Path),
Text,
Circle,
SVGRaw(SVGRaw),
Text(TextContent),
}
impl Type {
@ -58,7 +60,7 @@ impl Type {
2 => Type::Bool(Bool::default()),
3 => Type::Rect(Rect::default()),
4 => Type::Path(Path::default()),
5 => Type::Text,
5 => Type::Text(TextContent::default()),
6 => Type::Circle,
7 => Type::SVGRaw(SVGRaw::default()),
_ => Type::Rect(Rect::default()),
@ -207,6 +209,12 @@ impl Shape {
pub fn set_selrect(&mut self, left: f32, top: f32, right: f32, bottom: f32) {
self.selrect.set_ltrb(left, top, right, bottom);
match self.shape_type {
Type::Text(ref mut text) => {
text.set_xywh(left, top, right - left, bottom - top);
}
_ => {}
}
}
pub fn set_masked(&mut self, masked: bool) {
@ -343,7 +351,7 @@ impl Shape {
}
pub fn add_fill(&mut self, f: Fill) {
self.fills.push(f)
self.fills.push(f);
}
pub fn clear_fills(&mut self) {
@ -580,6 +588,36 @@ impl Shape {
}
}
pub fn add_text_leaf(&mut self, text_str: &str) -> Result<(), String> {
match self.shape_type {
Type::Text(ref mut text) => {
text.add_leaf(text_str)?;
Ok(())
}
_ => Err("Shape is not a text".to_string()),
}
}
pub fn add_text_paragraph(&mut self) -> Result<(), String> {
match self.shape_type {
Type::Text(ref mut text) => {
text.add_paragraph();
Ok(())
}
_ => Err("Shape is not a text".to_string()),
}
}
pub fn clear_text(&mut self) {
match self.shape_type {
Type::Text(_) => {
let new_text_content = TextContent::new(self.selrect);
self.shape_type = Type::Text(new_text_content);
}
_ => {}
}
}
fn transform_selrect(&mut self, transform: &Matrix) {
let mut center = self.selrect.center();
center = transform.map_point(center);