mirror of
https://github.com/penpot/penpot.git
synced 2025-06-14 07:31:38 +02:00
🎉 Store custom fonts (ttfs) and use them to write texts (wasm) (#6050)
This commit is contained in:
parent
e4c9b736f7
commit
eb6d2fb0eb
14 changed files with 386 additions and 140 deletions
|
@ -1,4 +1,6 @@
|
|||
use crate::mem;
|
||||
use crate::shapes::FontFamily;
|
||||
use crate::utils::uuid_from_u32_quartet;
|
||||
use crate::with_current_shape;
|
||||
use crate::STATE;
|
||||
|
||||
|
@ -20,14 +22,25 @@ pub extern "C" fn add_text_paragraph() {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_text_leaf() {
|
||||
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());
|
||||
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);
|
||||
let res = shape.add_text_leaf(text, font_family, font_size);
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue