mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 22:53:02 +00:00
🔧 WIP
This commit is contained in:
@@ -648,20 +648,26 @@ impl Shape {
|
||||
|
||||
// TODO: Maybe store this inside the shape
|
||||
pub fn bounds(&self) -> Bounds {
|
||||
let (x, y, mut width, mut height) = (
|
||||
self.selrect.x(),
|
||||
self.selrect.y(),
|
||||
self.selrect.width(),
|
||||
self.selrect.height(),
|
||||
);
|
||||
|
||||
if let Type::Text(text_content) = &self.shape_type {
|
||||
width = text_content.size.width;
|
||||
height = text_content.size.height
|
||||
}
|
||||
|
||||
let mut bounds = Bounds::new(
|
||||
Point::new(self.selrect.x(), self.selrect.y()),
|
||||
Point::new(self.selrect.x() + self.selrect.width(), self.selrect.y()),
|
||||
Point::new(
|
||||
self.selrect.x() + self.selrect.width(),
|
||||
self.selrect.y() + self.selrect.height(),
|
||||
),
|
||||
Point::new(self.selrect.x(), self.selrect.y() + self.selrect.height()),
|
||||
Point::new(x, y),
|
||||
Point::new(x + width, y),
|
||||
Point::new(x + width, y + height),
|
||||
Point::new(x, y + height),
|
||||
);
|
||||
|
||||
// Apply this transformation only when self.transform
|
||||
// is not the identity matrix because if it is,
|
||||
// the result of applying this transformations would be
|
||||
// the same identity matrix.
|
||||
if !self.transform.is_identity() {
|
||||
let mut matrix = self.transform;
|
||||
let center = self.center();
|
||||
@@ -823,10 +829,10 @@ impl Shape {
|
||||
shapes_pool: &ShapesPool,
|
||||
modifiers: &HashMap<Uuid, Matrix>,
|
||||
) -> math::Rect {
|
||||
let mut shape = self.transformed(modifiers.get(&self.id));
|
||||
let shape = self.transformed(modifiers.get(&self.id));
|
||||
let max_stroke = Stroke::max_bounds_width(shape.strokes.iter(), shape.is_open());
|
||||
|
||||
let mut rect = match &mut shape.shape_type {
|
||||
let mut rect = match &shape.shape_type {
|
||||
Type::Path(_) | Type::Bool(_) => {
|
||||
if let Some(path) = shape.get_skia_path() {
|
||||
return path
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
math::{Matrix, Rect},
|
||||
render::{default_font, DEFAULT_EMOJI_FONT},
|
||||
};
|
||||
use crate::render::{default_font, DEFAULT_EMOJI_FONT};
|
||||
|
||||
use crate::math::{Matrix, Point, Rect};
|
||||
|
||||
use core::f32;
|
||||
use macros::ToJs;
|
||||
@@ -15,7 +14,6 @@ use skia_safe::{
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::FontFamily;
|
||||
use crate::math::Point;
|
||||
use crate::shapes::{self, merge_fills};
|
||||
use crate::utils::{get_fallback_fonts, get_font_collection};
|
||||
use crate::Uuid;
|
||||
@@ -397,8 +395,21 @@ impl TextContent {
|
||||
self.size.copy_finite_size(result.2);
|
||||
}
|
||||
|
||||
pub fn get_height(&self, width: f32) -> f32 {
|
||||
let mut paragraph_builders = self.paragraph_builder_group_from_text(None);
|
||||
let paragraphs =
|
||||
self.build_paragraphs_from_paragraph_builders(&mut paragraph_builders, width);
|
||||
paragraphs
|
||||
.iter()
|
||||
.flatten()
|
||||
.fold(0.0, |auto_height, paragraph| {
|
||||
auto_height + paragraph.height()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_layout(&mut self, selrect: Rect) -> TextContentSize {
|
||||
self.size.set_size(selrect.width(), selrect.height());
|
||||
let height = self.get_height(selrect.width());
|
||||
self.size.set_size(selrect.width(), height);
|
||||
|
||||
match self.grow_type() {
|
||||
GrowType::AutoHeight => {
|
||||
|
||||
@@ -317,10 +317,9 @@ pub extern "C" fn set_shape_grow_type(grow_type: u8) {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_text_dimensions() -> *mut u8 {
|
||||
let mut ptr = std::ptr::null_mut();
|
||||
println!("@@@ get_text_dimensions called");
|
||||
with_current_shape_mut!(state, |shape: &mut Shape| {
|
||||
shape.invalidate_extrect();
|
||||
if let Type::Text(content) = &mut shape.shape_type {
|
||||
// FIXME: can we use content.size here?
|
||||
let text_content_size = content.update_layout(shape.selrect);
|
||||
|
||||
let mut bytes = vec![0; 12];
|
||||
|
||||
Reference in New Issue
Block a user