mirror of
https://github.com/penpot/penpot.git
synced 2026-09-04 11:09:23 +00:00
Upload structural shape attrs (base, children, blur, shadows, flex, layout-item) via multi-shape `_set_shapes_batch` FFI in chunks of 512, then apply host attrs with use-shape selection.
74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
use crate::get_resources;
|
|
use crate::skia::textlayout::FontCollection;
|
|
use crate::skia::Image;
|
|
use crate::uuid::Uuid;
|
|
use crate::with_state;
|
|
use std::collections::HashSet;
|
|
|
|
pub fn uuid_from_u32_quartet(a: u32, b: u32, c: u32, d: u32) -> Uuid {
|
|
let hi: u64 = ((a as u64) << 32) | b as u64;
|
|
let lo: u64 = ((c as u64) << 32) | d as u64;
|
|
Uuid::from_u64_pair(hi, lo)
|
|
}
|
|
|
|
pub fn uuid_to_u32_quartet(id: &Uuid) -> (u32, u32, u32, u32) {
|
|
let (hi, lo) = id.as_u64_pair();
|
|
let hihi32 = (hi >> 32) as u32;
|
|
let hilo32 = hi as u32;
|
|
let lohi32 = (lo >> 32) as u32;
|
|
let lolo32 = lo as u32;
|
|
(hihi32, hilo32, lohi32, lolo32)
|
|
}
|
|
|
|
pub fn uuid_from_u32(id: [u32; 4]) -> Uuid {
|
|
uuid_from_u32_quartet(id[0], id[1], id[2], id[3])
|
|
}
|
|
|
|
pub fn get_image(image_id: &Uuid) -> Option<&Image> {
|
|
get_resources().images.get(image_id)
|
|
}
|
|
|
|
// FIXME: move to a different place ?
|
|
pub fn get_fallback_fonts() -> &'static HashSet<String> {
|
|
get_resources().fonts.get_fallback()
|
|
}
|
|
|
|
pub fn get_font_collection() -> &'static FontCollection {
|
|
if crate::globals::has_render_resources() {
|
|
get_resources().fonts.font_collection()
|
|
} else {
|
|
with_state!(state, { state.font_collection() })
|
|
}
|
|
}
|
|
|
|
/// A negative f32 means "unset" — the renderer falls back to its default.
|
|
pub fn decode_optional_f32(value: f32) -> Option<f32> {
|
|
if value.is_finite() && value >= 0.0 {
|
|
Some(value)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
#[repr(u8)]
|
|
pub enum Browser {
|
|
Firefox = 0,
|
|
Chrome = 1,
|
|
Safari = 2,
|
|
Edge = 3,
|
|
Unknown = 4,
|
|
}
|
|
|
|
impl From<u8> for Browser {
|
|
fn from(value: u8) -> Self {
|
|
match value {
|
|
0 => Browser::Firefox,
|
|
1 => Browser::Chrome,
|
|
2 => Browser::Safari,
|
|
3 => Browser::Edge,
|
|
_ => Browser::Unknown,
|
|
}
|
|
}
|
|
}
|