mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
♻️ Create type alias for ParagraphBuilderGroup
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -51,12 +51,14 @@ pub fn build_paragraphs_with_width(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn paragraph_builders_from_text(
|
||||
type ParagraphBuilderGroup = Vec<ParagraphBuilder>;
|
||||
|
||||
pub fn paragraph_builder_group_from_text(
|
||||
text_content: &TextContent,
|
||||
blur: Option<&ImageFilter>,
|
||||
blur_mask: Option<&MaskFilter>,
|
||||
shadow: Option<&Paint>,
|
||||
) -> Vec<Vec<ParagraphBuilder>> {
|
||||
) -> Vec<ParagraphBuilderGroup> {
|
||||
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<ParagraphBuilder>> {
|
||||
) -> Vec<ParagraphBuilderGroup> {
|
||||
let fallback_fonts = get_fallback_fonts();
|
||||
let fonts = get_font_collection();
|
||||
let mut paragraph_group = Vec::new();
|
||||
|
||||
@@ -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 => {}
|
||||
|
||||
Reference in New Issue
Block a user