mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
🐛 Fix image loading callback
This commit is contained in:
parent
f00ea8789f
commit
f673b32567
@ -627,6 +627,7 @@
|
||||
(if (empty? fills)
|
||||
(h/call wasm/internal-module "_clear_shape_fills")
|
||||
(let [fills (types.fills/coerce fills)
|
||||
image-ids (types.fills/get-image-ids fills)
|
||||
offset (mem/alloc->offset-32 (types.fills/get-byte-size fills))
|
||||
heap (mem/get-heap-u32)]
|
||||
|
||||
@ -648,7 +649,7 @@
|
||||
(when (zero? cached-image?)
|
||||
(fetch-image shape-id id thumbnail?))))
|
||||
|
||||
(types.fills/get-image-ids fills)))))
|
||||
image-ids))))
|
||||
|
||||
(defn set-shape-strokes
|
||||
[shape-id strokes thumbnail?]
|
||||
@ -675,7 +676,8 @@
|
||||
(some? gradient)
|
||||
(do
|
||||
(types.fills.impl/write-gradient-fill offset dview opacity gradient)
|
||||
(h/call wasm/internal-module "_add_shape_stroke_fill"))
|
||||
(h/call wasm/internal-module "_add_shape_stroke_fill")
|
||||
nil)
|
||||
|
||||
(some? image)
|
||||
(let [image-id (get image :id)
|
||||
@ -692,7 +694,8 @@
|
||||
(some? color)
|
||||
(do
|
||||
(types.fills.impl/write-solid-fill offset dview opacity color)
|
||||
(h/call wasm/internal-module "_add_shape_stroke_fill")))))
|
||||
(h/call wasm/internal-module "_add_shape_stroke_fill")
|
||||
nil))))
|
||||
strokes))
|
||||
|
||||
(defn set-shape-svg-attrs
|
||||
@ -1302,16 +1305,17 @@
|
||||
(when (or (seq pending-thumbnails) (seq pending-full))
|
||||
(->> (rx/concat
|
||||
(->> (rx/from (vals pending-thumbnails))
|
||||
(rx/merge-map (fn [callback] (callback)))
|
||||
(rx/merge-map
|
||||
(fn [callback]
|
||||
(if (fn? callback) (callback) (rx/empty))))
|
||||
(rx/reduce conj []))
|
||||
(->> (rx/from (vals pending-full))
|
||||
(rx/mapcat (fn [callback] (callback)))
|
||||
(rx/mapcat
|
||||
(fn [callback]
|
||||
(if (fn? callback) (callback) (rx/empty))))
|
||||
(rx/reduce conj [])))
|
||||
(rx/subs!
|
||||
(fn [_]
|
||||
;; Fonts are now loaded — recompute text
|
||||
;; layouts so Skia uses the real metrics
|
||||
;; instead of fallback-font estimates.
|
||||
(let [text-ids (into [] (comp (filter cfh/text-shape?) (map :id)) shapes)]
|
||||
(when (seq text-ids)
|
||||
(update-text-layouts text-ids)))
|
||||
|
||||
@ -1,11 +1,34 @@
|
||||
use crate::error::{Error, Result};
|
||||
use crate::mem;
|
||||
use crate::shapes::Fill;
|
||||
use crate::state::State;
|
||||
use crate::uuid::Uuid;
|
||||
use crate::with_state_mut;
|
||||
use crate::STATE;
|
||||
use crate::{shapes::ImageFill, utils::uuid_from_u32_quartet};
|
||||
use macros::wasm_error;
|
||||
|
||||
fn touch_shapes_with_image(state: &mut State, image_id: Uuid) {
|
||||
let ids: Vec<Uuid> = state
|
||||
.shapes
|
||||
.iter()
|
||||
.filter(|shape| {
|
||||
shape
|
||||
.fills()
|
||||
.any(|f| matches!(f, Fill::Image(i) if i.id() == image_id))
|
||||
|| shape
|
||||
.strokes
|
||||
.iter()
|
||||
.any(|s| matches!(&s.fill, Fill::Image(i) if i.id() == image_id))
|
||||
})
|
||||
.map(|shape| shape.id)
|
||||
.collect();
|
||||
|
||||
for id in ids {
|
||||
state.touch_shape(id);
|
||||
}
|
||||
}
|
||||
|
||||
const FLAG_KEEP_ASPECT_RATIO: u8 = 1 << 0;
|
||||
const IMAGE_IDS_SIZE: usize = 32;
|
||||
const IMAGE_HEADER_SIZE: usize = 36; // 32 bytes for IDs + 4 bytes for is_thumbnail flag
|
||||
@ -90,7 +113,7 @@ pub extern "C" fn store_image() -> Result<()> {
|
||||
{
|
||||
eprintln!("{}", msg);
|
||||
}
|
||||
state.touch_shape(ids.shape_id);
|
||||
touch_shapes_with_image(state, ids.image_id);
|
||||
});
|
||||
|
||||
mem::free_bytes()?;
|
||||
@ -167,7 +190,7 @@ pub extern "C" fn store_image_from_texture() -> Result<()> {
|
||||
// FIXME: Review if we should return a RecoverableError
|
||||
eprintln!("store_image_from_texture error: {}", msg);
|
||||
}
|
||||
state.touch_shape(ids.shape_id);
|
||||
touch_shapes_with_image(state, ids.image_id);
|
||||
});
|
||||
|
||||
mem::free_bytes()?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user