mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 06:36:11 +02:00
* 🔧 Fix lint script (rust) * 🔧 Temporarily add clippy rules to ignore so lint script passes * 💄 Fix clippy rule crate_in_macro_def * 💄 Fix clippy rule redundant-static-lifetimes * 💄 Fix clippy rule unnecessary_cast * 💄 Fix clippy rule nonminimal_bool * 💄 Fix clippy rule redundant_pattern_matching * 💄 Fix clippy rule assign_op_pattern * 💄 Fix clippy rule needless_lifetimes * 💄 Fix clippy rule for_kv_map * 💄 Fix clippy rule ptr_arg * 💄 Fix clippy rule match_like_matches_macro * 💄 Fix clippy rule macro_metavars_in_unsafe * 💄 Fix clippy rule map_clone * 💄 Fix clippy rule wrong_self_convention * 💄 Fix clippy rule vec_box * 💄 Fix clippy rule useless_format * 💄 Fix clippy rule unwrap_or_default * 💄 Fix clippy rule unused_unit * 💄 Fix clippy rule unnecessary_to_owned * 💄 Fix clippy rule too_many_arguments * 💄 Fix clippy rule slow_vector_initialization * 💄 Fix clippy rule single_match * 💄 Fix clippy rule redundant_field_names * 💄 Fix clippy rule rendudant_closure * 💄 Fix clippy rule needless_return * 💄 Fix clippy rule needless_range_loop * 💄 Fix clippy rule needless_borrows_for_generic_args * 💄 Fix clippy rule needless-borrow * 💄 Fix clippy rule missing_transmute_annotations * 💄 Fix clippy rule map_entry * 💄 Fix clippy rule manual_map * 💄 Fix clippy rule len_zero * 💄 Fix clippy rule from_over_into * 💄 Fix clippy rule field_reassign_with_default * 💄 Fix clippy rule enum_variant_names * 💄 Fix clippy rule derivable_impls * 💄 Fix clippy rule clone_on_copy * 💄 Fix clippy rule box_collection * 🔧 Make lint script also check test config target * 🔧 Remove cargo-watch as a lib dependency * 💄 Fix clippy rule for join_bounds * 🔧 Fix lint script return code --------- Co-authored-by: alonso.torres <alonso.torres@kaleidos.net>
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use crate::mem;
|
|
use crate::shapes::{auto_height, auto_width, GrowType, RawTextData, Type};
|
|
|
|
use crate::STATE;
|
|
use crate::{with_current_shape, with_state};
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn clear_shape_text() {
|
|
with_current_shape!(state, |shape: &mut Shape| {
|
|
shape.clear_text();
|
|
});
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn set_shape_text_content() {
|
|
let bytes = mem::bytes();
|
|
with_current_shape!(state, |shape: &mut Shape| {
|
|
let raw_text_data = RawTextData::from(&bytes);
|
|
shape
|
|
.add_paragraph(raw_text_data.paragraph)
|
|
.expect("Failed to add paragraph");
|
|
});
|
|
|
|
mem::free_bytes();
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn set_shape_grow_type(grow_type: u8) {
|
|
with_current_shape!(state, |shape: &mut Shape| {
|
|
if let Type::Text(text_content) = &mut shape.shape_type {
|
|
text_content.set_grow_type(GrowType::from(grow_type));
|
|
}
|
|
});
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn get_text_dimensions() -> *mut u8 {
|
|
let font_col;
|
|
with_state!(state, {
|
|
font_col = state.render_state.fonts.font_collection();
|
|
});
|
|
|
|
let mut width = 0.01;
|
|
let mut height = 0.01;
|
|
with_current_shape!(state, |shape: &mut Shape| {
|
|
width = shape.selrect.width();
|
|
height = shape.selrect.height();
|
|
|
|
if let Type::Text(content) = &shape.shape_type {
|
|
let paragraphs = content.get_skia_paragraphs(font_col);
|
|
height = auto_height(¶graphs).ceil();
|
|
if content.grow_type() == GrowType::AutoWidth {
|
|
width = auto_width(¶graphs).ceil();
|
|
}
|
|
}
|
|
});
|
|
|
|
let mut bytes = vec![0; 8];
|
|
bytes[0..4].clone_from_slice(&width.to_le_bytes());
|
|
bytes[4..8].clone_from_slice(&height.to_le_bytes());
|
|
mem::write_bytes(bytes)
|
|
}
|