mirror of
https://github.com/penpot/penpot.git
synced 2025-06-11 14:11:38 +02:00
🔧 Parse text leaves all at once
This commit is contained in:
parent
18dea6c3a3
commit
83f72f3e41
8 changed files with 457 additions and 117 deletions
|
@ -1,6 +1,5 @@
|
|||
use crate::mem;
|
||||
use crate::shapes::FontFamily;
|
||||
use crate::utils::uuid_from_u32_quartet;
|
||||
use crate::shapes::RawTextData;
|
||||
use crate::with_current_shape;
|
||||
use crate::STATE;
|
||||
|
||||
|
@ -12,37 +11,14 @@ pub extern "C" fn clear_shape_text() {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_text_paragraph() {
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
let res = shape.add_text_paragraph();
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_text_leaf(
|
||||
a: u32,
|
||||
b: u32,
|
||||
c: u32,
|
||||
d: u32,
|
||||
weight: u32,
|
||||
style: u8,
|
||||
font_size: f32,
|
||||
) {
|
||||
let font_id = uuid_from_u32_quartet(a, b, c, d);
|
||||
let font_family = FontFamily::new(font_id, weight, style.into());
|
||||
pub extern "C" fn set_shape_text_content() {
|
||||
let bytes = mem::bytes();
|
||||
|
||||
let text = unsafe {
|
||||
String::from_utf8_unchecked(bytes) // TODO: handle this error
|
||||
};
|
||||
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
let res = shape.add_text_leaf(text, font_family, font_size);
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
let raw_text_data = RawTextData::from(&bytes);
|
||||
shape
|
||||
.add_paragraph(raw_text_data.paragraph)
|
||||
.expect("Failed to add paragraph");
|
||||
});
|
||||
|
||||
mem::free_bytes();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue