mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 16:17:20 +02:00
🎉 Render plain text
* 🎉 Serialize text content (wasm) * ♻️ Refactor functions in main to wasm module * 🎉 Stub rendering of paragraph text (wasm) * 📎 Clean up commented code
This commit is contained in:
parent
9e5de82967
commit
aa468e2153
9 changed files with 256 additions and 9 deletions
37
render-wasm/src/wasm/text.rs
Normal file
37
render-wasm/src/wasm/text.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use crate::mem;
|
||||
use crate::STATE;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn clear_shape_text() {
|
||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
shape.clear_text();
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_text_paragraph() {
|
||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
let res = shape.add_text_paragraph();
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_text_leaf() {
|
||||
let bytes = mem::bytes();
|
||||
let text = unsafe {
|
||||
String::from_utf8_unchecked(bytes) // TODO: handle this error
|
||||
};
|
||||
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
let res = shape.add_text_leaf(&text);
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue