🐛 Fix asynchronous content dependant rendering (#6142)

* 🐛 Fix custom fonts rendering

* 🐛 Fix asynchronous content dependant rendering

* 🎉 Renaming clear_cache to clear_drawing_cache
This commit is contained in:
Alejandro 2025-03-25 09:49:47 +01:00 committed by GitHub
parent 9653e72e47
commit 065b50f5a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 10 deletions

View file

@ -777,8 +777,8 @@
(h/call internal-module "_set_view" zoom (- (:x vbox)) (- (:y vbox)))
(render nil))
(defn clear-cache []
(h/call internal-module "_clear_cache"))
(defn clear-drawing-cache []
(h/call internal-module "_clear_drawing_cache"))
(defn- store-all-fonts
[fonts]
@ -803,7 +803,9 @@
(->> (rx/from pending)
(rx/mapcat identity)
(rx/reduce conj [])
(rx/subs! request-render))))
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-fonts"))))))
(defn set-objects
[objects]
@ -886,13 +888,15 @@
(let [pending' (concat (set-shape-fills fills) (set-shape-strokes strokes))]
(recur (inc index) (into pending pending'))))
pending))]
(clear-cache)
(clear-drawing-cache)
(request-render "set-objects")
(when-let [pending (seq pending)]
(->> (rx/from pending)
(rx/mapcat identity)
(rx/reduce conj [])
(rx/subs! request-render)))))
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects")))))))
(defn uuid->u8
[id]

View file

@ -145,7 +145,7 @@
;; when something synced with wasm
;; is modified, we need to request
;; a new render.
(api/clear-cache)
(api/clear-drawing-cache)
(api/request-render "set-wasm-attrs")))
(defn- impl-assoc

View file

@ -61,7 +61,7 @@ pub extern "C" fn clean_up() {
}
#[no_mangle]
pub extern "C" fn clear_cache() {
pub extern "C" fn clear_drawing_cache() {
with_state!(state, {
state.rebuild_tiles();
});

View file

@ -1,4 +1,4 @@
use skia_safe::{self as skia, textlayout, Font};
use skia_safe::{self as skia, textlayout, Font, FontMgr};
use crate::shapes::FontFamily;
@ -31,8 +31,8 @@ impl FontStore {
font_provider.register_typeface(emoji_font, DEFAULT_EMOJI_FONT);
let mut font_collection = skia::textlayout::FontCollection::new();
font_collection.set_default_font_manager(Some(font_provider.clone().into()), None);
font_collection.set_dynamic_font_manager(Some(font_provider.clone().into()));
font_collection.set_default_font_manager(FontMgr::default(), None);
font_collection.set_dynamic_font_manager(FontMgr::from(font_provider.clone()));
let debug_typeface = font_provider
.match_family_style("robotomono-regular", skia::FontStyle::default())
@ -72,6 +72,8 @@ impl FontStore {
self.font_provider
.register_typeface(typeface, alias.as_str());
self.refresh_font_collection();
Ok(())
}
@ -79,4 +81,12 @@ impl FontStore {
let serialized = format!("{}", family);
self.font_provider.family_names().any(|x| x == serialized)
}
fn refresh_font_collection(&mut self) {
self.font_collection = skia::textlayout::FontCollection::new();
self.font_collection
.set_default_font_manager(FontMgr::default(), None);
self.font_collection
.set_dynamic_font_manager(FontMgr::from(self.font_provider.clone()));
}
}