From 3e02dc550fb289793106d3d2c833779f71cd2367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Tue, 2 Sep 2025 15:32:10 +0200 Subject: [PATCH] :recycle: Create type alias for ParagraphBuilderGroup --- render-wasm/src/render.rs | 16 +++++++++------- render-wasm/src/shapes/modifiers.rs | 6 +++--- render-wasm/src/shapes/text.rs | 6 +++--- render-wasm/src/shapes/text_paths.rs | 4 ++-- render-wasm/src/textlayout.rs | 10 ++++++---- render-wasm/src/wasm/text.rs | 10 ++++++---- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index ca176758eb..8ab8338cbd 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -24,7 +24,9 @@ pub use surfaces::{SurfaceId, Surfaces}; use crate::performance; use crate::shapes::{Blur, BlurType, Corners, Fill, Shape, StructureEntry, Type}; use crate::state::ShapesPool; -use crate::textlayout::{paragraph_builders_from_text, stroke_paragraph_builders_from_text}; +use crate::textlayout::{ + paragraph_builder_group_from_text, stroke_paragraph_builder_group_from_text, +}; use crate::tiles::{self, PendingTiles, TileRect}; use crate::uuid::Uuid; use crate::view::Viewbox; @@ -542,7 +544,7 @@ impl RenderState { let inner_shadows = shape.inner_shadow_paints(); let blur_filter = shape.image_filter(1.); let blur_mask = shape.mask_filter(1.); - let mut paragraphs = paragraph_builders_from_text( + let mut paragraphs = paragraph_builder_group_from_text( &text_content, blur_filter.as_ref(), blur_mask.as_ref(), @@ -552,7 +554,7 @@ impl RenderState { // Render all drop shadows if there are no visible strokes if !shape.has_visible_strokes() && !drop_shadows.is_empty() { for drop_shadow in &drop_shadows { - let mut paragraphs_with_drop_shadows = paragraph_builders_from_text( + let mut paragraphs_with_drop_shadows = paragraph_builder_group_from_text( &text_content, blur_filter.as_ref(), blur_mask.as_ref(), @@ -571,7 +573,7 @@ impl RenderState { for stroke in shape.visible_strokes().rev() { for drop_shadow in &drop_shadows { let mut stroke_paragraphs_with_drop_shadows = - stroke_paragraph_builders_from_text( + stroke_paragraph_builder_group_from_text( &text_content, stroke, &shape.selrect(), @@ -587,7 +589,7 @@ impl RenderState { ); } - let mut stroke_paragraphs = stroke_paragraph_builders_from_text( + let mut stroke_paragraphs = stroke_paragraph_builder_group_from_text( &text_content, stroke, &shape.selrect(), @@ -609,7 +611,7 @@ impl RenderState { for inner_shadow in &inner_shadows { let mut stroke_paragraphs_with_inner_shadows = - stroke_paragraph_builders_from_text( + stroke_paragraph_builder_group_from_text( &text_content, stroke, &shape.selrect(), @@ -627,7 +629,7 @@ impl RenderState { } for inner_shadow in &inner_shadows { - let mut paragraphs_with_inner_shadows = paragraph_builders_from_text( + let mut paragraphs_with_inner_shadows = paragraph_builder_group_from_text( &text_content, blur_filter.as_ref(), blur_mask.as_ref(), diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index c150e4ba61..a74f201c3e 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -14,7 +14,7 @@ use crate::shapes::{ TransformEntry, Type, }; use crate::state::{ShapesPool, State}; -use crate::textlayout::{auto_height, paragraph_builders_from_text}; +use crate::textlayout::{auto_height, paragraph_builder_group_from_text}; use crate::uuid::Uuid; #[allow(clippy::too_many_arguments)] @@ -200,7 +200,7 @@ fn propagate_transform( match content.grow_type() { GrowType::AutoHeight => { let paragraph_width = shape_bounds_after.width(); - let mut paragraphs = paragraph_builders_from_text(content, None, None, None); + let mut paragraphs = paragraph_builder_group_from_text(content, None, None, None); let height = auto_height(&mut paragraphs, paragraph_width); let resize_transform = math::resize_matrix( &shape_bounds_after, @@ -213,7 +213,7 @@ fn propagate_transform( } GrowType::AutoWidth => { let paragraph_width = content.width(); - let mut paragraphs = paragraph_builders_from_text(content, None, None, None); + let mut paragraphs = paragraph_builder_group_from_text(content, None, None, None); let height = auto_height(&mut paragraphs, paragraph_width); let resize_transform = math::resize_matrix( &shape_bounds_after, diff --git a/render-wasm/src/shapes/text.rs b/render-wasm/src/shapes/text.rs index d56d2e6f28..35fb4b42a8 100644 --- a/render-wasm/src/shapes/text.rs +++ b/render-wasm/src/shapes/text.rs @@ -1,7 +1,7 @@ use crate::{ math::{Matrix, Rect}, render::{default_font, DEFAULT_EMOJI_FONT}, - textlayout::paragraph_builders_from_text, + textlayout::paragraph_builder_group_from_text, }; use skia_safe::{self as skia, paint::Paint, textlayout::ParagraphStyle, ImageFilter, MaskFilter}; @@ -86,7 +86,7 @@ impl TextContent { pub fn width(&self) -> f32 { if self.grow_type() == GrowType::AutoWidth { - let temp_paragraphs = paragraph_builders_from_text(self, None, None, None); + let temp_paragraphs = paragraph_builder_group_from_text(self, None, None, None); let mut temp_paragraphs = temp_paragraphs; auto_width(&mut temp_paragraphs, f32::MAX).ceil() } else { @@ -104,7 +104,7 @@ impl TextContent { pub fn visual_bounds(&self) -> (f32, f32) { let paragraph_width = self.width(); - let mut paragraphs = paragraph_builders_from_text(self, None, None, None); + let mut paragraphs = paragraph_builder_group_from_text(self, None, None, None); let paragraph_height = auto_height(&mut paragraphs, paragraph_width); (paragraph_width, paragraph_height) } diff --git a/render-wasm/src/shapes/text_paths.rs b/render-wasm/src/shapes/text_paths.rs index 7749313d77..0cf874cdb2 100644 --- a/render-wasm/src/shapes/text_paths.rs +++ b/render-wasm/src/shapes/text_paths.rs @@ -1,4 +1,4 @@ -use crate::{shapes::text::TextContent, textlayout::paragraph_builders_from_text}; +use crate::{shapes::text::TextContent, textlayout::paragraph_builder_group_from_text}; use skia_safe::{ self as skia, textlayout::Paragraph as SkiaParagraph, FontMetrics, Point, Rect, TextBlob, }; @@ -20,7 +20,7 @@ impl TextPaths { let mut paths = Vec::new(); let mut offset_y = self.bounds.y(); - let mut paragraphs = paragraph_builders_from_text(&self.0, None, None, None); + let mut paragraphs = paragraph_builder_group_from_text(&self.0, None, None, None); for paragraphs in paragraphs.iter_mut() { for paragraph_builder in paragraphs.iter_mut() { diff --git a/render-wasm/src/textlayout.rs b/render-wasm/src/textlayout.rs index 3be44c1d85..fc69b4cc6e 100644 --- a/render-wasm/src/textlayout.rs +++ b/render-wasm/src/textlayout.rs @@ -51,12 +51,14 @@ pub fn build_paragraphs_with_width( .collect() } -pub fn paragraph_builders_from_text( +type ParagraphBuilderGroup = Vec; + +pub fn paragraph_builder_group_from_text( text_content: &TextContent, blur: Option<&ImageFilter>, blur_mask: Option<&MaskFilter>, shadow: Option<&Paint>, -) -> Vec> { +) -> Vec { let fonts = get_font_collection(); let fallback_fonts = get_fallback_fonts(); let mut paragraph_group = Vec::new(); @@ -82,7 +84,7 @@ pub fn paragraph_builders_from_text( paragraph_group } -pub fn stroke_paragraph_builders_from_text( +pub fn stroke_paragraph_builder_group_from_text( text_content: &TextContent, stroke: &Stroke, bounds: &Rect, @@ -90,7 +92,7 @@ pub fn stroke_paragraph_builders_from_text( blur_mask: Option<&MaskFilter>, shadow: Option<&Paint>, count_inner_strokes: usize, -) -> Vec> { +) -> Vec { let fallback_fonts = get_fallback_fonts(); let fonts = get_font_collection(); let mut paragraph_group = Vec::new(); diff --git a/render-wasm/src/wasm/text.rs b/render-wasm/src/wasm/text.rs index 5c075573d1..e6cd77ded5 100644 --- a/render-wasm/src/wasm/text.rs +++ b/render-wasm/src/wasm/text.rs @@ -1,6 +1,8 @@ use crate::mem; use crate::shapes::{GrowType, RawTextData, Type}; -use crate::textlayout::{auto_height, build_paragraphs_with_width, paragraph_builders_from_text}; +use crate::textlayout::{ + auto_height, build_paragraphs_with_width, paragraph_builder_group_from_text, +}; use crate::{with_current_shape, with_current_shape_mut, STATE}; #[no_mangle] @@ -44,7 +46,7 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 { if let Type::Text(content) = &shape.shape_type { // 1. Reset Paragraphs let paragraph_width = content.width(); - let mut paragraphs = paragraph_builders_from_text(content, None, None, None); + let mut paragraphs = paragraph_builder_group_from_text(content, None, None, None); let built_paragraphs = build_paragraphs_with_width(&mut paragraphs, paragraph_width); // 2. Max Width Calculation @@ -57,13 +59,13 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 { match content.grow_type() { GrowType::AutoHeight => { let mut paragraph_height = - paragraph_builders_from_text(content, None, None, None); + paragraph_builder_group_from_text(content, None, None, None); height = auto_height(&mut paragraph_height, paragraph_width).ceil(); } GrowType::AutoWidth => { width = paragraph_width; let mut paragraph_height = - paragraph_builders_from_text(content, None, None, None); + paragraph_builder_group_from_text(content, None, None, None); height = auto_height(&mut paragraph_height, paragraph_width).ceil(); } GrowType::Fixed => {}