♻️ Create type alias for ParagraphBuilderGroup

This commit is contained in:
Belén Albeza 2025-09-02 15:32:10 +02:00
parent 1cf0de395c
commit 3e02dc550f
6 changed files with 29 additions and 23 deletions

View File

@ -24,7 +24,9 @@ pub use surfaces::{SurfaceId, Surfaces};
use crate::performance; use crate::performance;
use crate::shapes::{Blur, BlurType, Corners, Fill, Shape, StructureEntry, Type}; use crate::shapes::{Blur, BlurType, Corners, Fill, Shape, StructureEntry, Type};
use crate::state::ShapesPool; 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::tiles::{self, PendingTiles, TileRect};
use crate::uuid::Uuid; use crate::uuid::Uuid;
use crate::view::Viewbox; use crate::view::Viewbox;
@ -542,7 +544,7 @@ impl RenderState {
let inner_shadows = shape.inner_shadow_paints(); let inner_shadows = shape.inner_shadow_paints();
let blur_filter = shape.image_filter(1.); let blur_filter = shape.image_filter(1.);
let blur_mask = shape.mask_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, &text_content,
blur_filter.as_ref(), blur_filter.as_ref(),
blur_mask.as_ref(), blur_mask.as_ref(),
@ -552,7 +554,7 @@ impl RenderState {
// Render all drop shadows if there are no visible strokes // Render all drop shadows if there are no visible strokes
if !shape.has_visible_strokes() && !drop_shadows.is_empty() { if !shape.has_visible_strokes() && !drop_shadows.is_empty() {
for drop_shadow in &drop_shadows { 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, &text_content,
blur_filter.as_ref(), blur_filter.as_ref(),
blur_mask.as_ref(), blur_mask.as_ref(),
@ -571,7 +573,7 @@ impl RenderState {
for stroke in shape.visible_strokes().rev() { for stroke in shape.visible_strokes().rev() {
for drop_shadow in &drop_shadows { for drop_shadow in &drop_shadows {
let mut stroke_paragraphs_with_drop_shadows = let mut stroke_paragraphs_with_drop_shadows =
stroke_paragraph_builders_from_text( stroke_paragraph_builder_group_from_text(
&text_content, &text_content,
stroke, stroke,
&shape.selrect(), &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, &text_content,
stroke, stroke,
&shape.selrect(), &shape.selrect(),
@ -609,7 +611,7 @@ impl RenderState {
for inner_shadow in &inner_shadows { for inner_shadow in &inner_shadows {
let mut stroke_paragraphs_with_inner_shadows = let mut stroke_paragraphs_with_inner_shadows =
stroke_paragraph_builders_from_text( stroke_paragraph_builder_group_from_text(
&text_content, &text_content,
stroke, stroke,
&shape.selrect(), &shape.selrect(),
@ -627,7 +629,7 @@ impl RenderState {
} }
for inner_shadow in &inner_shadows { 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, &text_content,
blur_filter.as_ref(), blur_filter.as_ref(),
blur_mask.as_ref(), blur_mask.as_ref(),

View File

@ -14,7 +14,7 @@ use crate::shapes::{
TransformEntry, Type, TransformEntry, Type,
}; };
use crate::state::{ShapesPool, State}; 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; use crate::uuid::Uuid;
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -200,7 +200,7 @@ fn propagate_transform(
match content.grow_type() { match content.grow_type() {
GrowType::AutoHeight => { GrowType::AutoHeight => {
let paragraph_width = shape_bounds_after.width(); 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 height = auto_height(&mut paragraphs, paragraph_width);
let resize_transform = math::resize_matrix( let resize_transform = math::resize_matrix(
&shape_bounds_after, &shape_bounds_after,
@ -213,7 +213,7 @@ fn propagate_transform(
} }
GrowType::AutoWidth => { GrowType::AutoWidth => {
let paragraph_width = content.width(); 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 height = auto_height(&mut paragraphs, paragraph_width);
let resize_transform = math::resize_matrix( let resize_transform = math::resize_matrix(
&shape_bounds_after, &shape_bounds_after,

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
math::{Matrix, Rect}, math::{Matrix, Rect},
render::{default_font, DEFAULT_EMOJI_FONT}, 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}; use skia_safe::{self as skia, paint::Paint, textlayout::ParagraphStyle, ImageFilter, MaskFilter};
@ -86,7 +86,7 @@ impl TextContent {
pub fn width(&self) -> f32 { pub fn width(&self) -> f32 {
if self.grow_type() == GrowType::AutoWidth { 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; let mut temp_paragraphs = temp_paragraphs;
auto_width(&mut temp_paragraphs, f32::MAX).ceil() auto_width(&mut temp_paragraphs, f32::MAX).ceil()
} else { } else {
@ -104,7 +104,7 @@ impl TextContent {
pub fn visual_bounds(&self) -> (f32, f32) { pub fn visual_bounds(&self) -> (f32, f32) {
let paragraph_width = self.width(); 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); let paragraph_height = auto_height(&mut paragraphs, paragraph_width);
(paragraph_width, paragraph_height) (paragraph_width, paragraph_height)
} }

View File

@ -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::{ use skia_safe::{
self as skia, textlayout::Paragraph as SkiaParagraph, FontMetrics, Point, Rect, TextBlob, self as skia, textlayout::Paragraph as SkiaParagraph, FontMetrics, Point, Rect, TextBlob,
}; };
@ -20,7 +20,7 @@ impl TextPaths {
let mut paths = Vec::new(); let mut paths = Vec::new();
let mut offset_y = self.bounds.y(); 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 paragraphs in paragraphs.iter_mut() {
for paragraph_builder in paragraphs.iter_mut() { for paragraph_builder in paragraphs.iter_mut() {

View File

@ -51,12 +51,14 @@ pub fn build_paragraphs_with_width(
.collect() .collect()
} }
pub fn paragraph_builders_from_text( type ParagraphBuilderGroup = Vec<ParagraphBuilder>;
pub fn paragraph_builder_group_from_text(
text_content: &TextContent, text_content: &TextContent,
blur: Option<&ImageFilter>, blur: Option<&ImageFilter>,
blur_mask: Option<&MaskFilter>, blur_mask: Option<&MaskFilter>,
shadow: Option<&Paint>, shadow: Option<&Paint>,
) -> Vec<Vec<ParagraphBuilder>> { ) -> Vec<ParagraphBuilderGroup> {
let fonts = get_font_collection(); let fonts = get_font_collection();
let fallback_fonts = get_fallback_fonts(); let fallback_fonts = get_fallback_fonts();
let mut paragraph_group = Vec::new(); let mut paragraph_group = Vec::new();
@ -82,7 +84,7 @@ pub fn paragraph_builders_from_text(
paragraph_group paragraph_group
} }
pub fn stroke_paragraph_builders_from_text( pub fn stroke_paragraph_builder_group_from_text(
text_content: &TextContent, text_content: &TextContent,
stroke: &Stroke, stroke: &Stroke,
bounds: &Rect, bounds: &Rect,
@ -90,7 +92,7 @@ pub fn stroke_paragraph_builders_from_text(
blur_mask: Option<&MaskFilter>, blur_mask: Option<&MaskFilter>,
shadow: Option<&Paint>, shadow: Option<&Paint>,
count_inner_strokes: usize, count_inner_strokes: usize,
) -> Vec<Vec<ParagraphBuilder>> { ) -> Vec<ParagraphBuilderGroup> {
let fallback_fonts = get_fallback_fonts(); let fallback_fonts = get_fallback_fonts();
let fonts = get_font_collection(); let fonts = get_font_collection();
let mut paragraph_group = Vec::new(); let mut paragraph_group = Vec::new();

View File

@ -1,6 +1,8 @@
use crate::mem; use crate::mem;
use crate::shapes::{GrowType, RawTextData, Type}; 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}; use crate::{with_current_shape, with_current_shape_mut, STATE};
#[no_mangle] #[no_mangle]
@ -44,7 +46,7 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 {
if let Type::Text(content) = &shape.shape_type { if let Type::Text(content) = &shape.shape_type {
// 1. Reset Paragraphs // 1. Reset Paragraphs
let paragraph_width = content.width(); 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); let built_paragraphs = build_paragraphs_with_width(&mut paragraphs, paragraph_width);
// 2. Max Width Calculation // 2. Max Width Calculation
@ -57,13 +59,13 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 {
match content.grow_type() { match content.grow_type() {
GrowType::AutoHeight => { GrowType::AutoHeight => {
let mut paragraph_height = 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(); height = auto_height(&mut paragraph_height, paragraph_width).ceil();
} }
GrowType::AutoWidth => { GrowType::AutoWidth => {
width = paragraph_width; width = paragraph_width;
let mut paragraph_height = 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(); height = auto_height(&mut paragraph_height, paragraph_width).ceil();
} }
GrowType::Fixed => {} GrowType::Fixed => {}