From 9929bc12ef68fccdd1972724f14bc1a4cc15d321 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Mon, 29 Sep 2025 12:01:44 +0200 Subject: [PATCH] WIP --- frontend/src/app/render_wasm/api.cljs | 3 +- frontend/src/app/render_wasm/api/fonts.cljs | 8 ++++- render-wasm/src/render/fonts.rs | 13 ++++++++ render-wasm/src/state.rs | 34 +++++++++++++++++++-- render-wasm/src/wasm/text.rs | 30 +++++++++++++++++- 5 files changed, 81 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 4f8e84e645..2c361a43b8 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -641,8 +641,6 @@ (f/add-noto-fonts langs)) result (f/store-fonts shape-id updated-fonts)] - (h/call wasm/internal-module "_update_shape_text_layout") - result))))) (defn set-shape-text @@ -760,6 +758,7 @@ [pending] (let [event (js/CustomEvent. "wasm:set-objects-finished") pending (-> (d/index-by :key :callback pending) vals)] + (prn "pending" pending) (if (not-empty? pending) (->> (rx/from pending) (rx/merge-map (fn [callback] (callback))) diff --git a/frontend/src/app/render_wasm/api/fonts.cljs b/frontend/src/app/render_wasm/api/fonts.cljs index 7bcb176d06..03218dae36 100644 --- a/frontend/src/app/render_wasm/api/fonts.cljs +++ b/frontend/src/app/render_wasm/api/fonts.cljs @@ -84,6 +84,7 @@ ptr (h/call wasm/internal-module "_alloc_bytes" size) heap (gobj/get ^js wasm/internal-module "HEAPU8") mem (js/Uint8Array. (.-buffer heap) ptr size)] + (.set mem (js/Uint8Array. font-array-buffer)) (h/call wasm/internal-module "_store_font" (aget shape-id-buffer 0) @@ -131,6 +132,7 @@ (when asset-id (let [uri (font-id->ttf-url (:font-id font-data) asset-id (:font-variant-id font-data)) id-buffer (uuid/get-u32 (:wasm-id font-data)) + shape-id-buffer (uuid/get-u32 shape-id) font-data (assoc font-data :family-id-buffer id-buffer) font-stored? (not= 0 (h/call wasm/internal-module "_is_font_uploaded" (aget id-buffer 0) @@ -141,6 +143,11 @@ (:style font-data) emoji?))] (when-not font-stored? + (h/call wasm/internal-module "_mark_shape" + (aget shape-id-buffer 0) + (aget shape-id-buffer 1) + (aget shape-id-buffer 2) + (aget shape-id-buffer 3)) (fetch-font shape-id font-data uri emoji? fallback?))))) (defn serialize-font-style @@ -217,7 +224,6 @@ [shape-id fonts] (keep (fn [font] (store-font shape-id font)) fonts)) - (defn add-emoji-font [fonts] (conj fonts {:font-id "gfont-noto-color-emoji" diff --git a/render-wasm/src/render/fonts.rs b/render-wasm/src/render/fonts.rs index 917fe134a8..baf3810c55 100644 --- a/render-wasm/src/render/fonts.rs +++ b/render-wasm/src/render/fonts.rs @@ -52,6 +52,19 @@ impl FontStore { self.debug_font = debug_font; } + pub fn list_registered_fonts(&self) { + println!("fontmgrs {}", self.font_collection.font_managers_count()); + if let Some(fallback_font_mgr) = self.font_collection.fallback_manager() { + for font in fallback_font_mgr { + println!("{:?}", font); + } + } + println!("families {}", self.font_mgr.count_families()); + for font in self.font_mgr.family_names() { + println!("{:?}", font); + } + } + pub fn font_provider(&self) -> &textlayout::TypefaceFontProvider { &self.font_provider } diff --git a/render-wasm/src/state.rs b/render-wasm/src/state.rs index bab9e60add..b0ab5df08b 100644 --- a/render-wasm/src/state.rs +++ b/render-wasm/src/state.rs @@ -5,8 +5,7 @@ mod shapes_pool; pub use shapes_pool::*; use crate::render::RenderState; -use crate::shapes::Shape; -use crate::shapes::StructureEntry; +use crate::shapes::{Shape, Type, StructureEntry}; use crate::tiles; use crate::uuid::Uuid; @@ -24,17 +23,19 @@ pub(crate) struct State { pub modifiers: HashMap, pub scale_content: HashMap, pub structure: HashMap>, + pub marked_shapes: Vec, } impl State { pub fn new(width: i32, height: i32) -> Self { - State { + Self { render_state: RenderState::new(width, height), current_id: None, shapes: ShapesPool::new(), modifiers: HashMap::new(), scale_content: HashMap::new(), structure: HashMap::new(), + marked_shapes: Vec::new(), } } @@ -56,6 +57,7 @@ impl State { } pub fn start_render_loop(&mut self, timestamp: i32) -> Result<(), String> { + self.update_marked_shapes(); self.render_state.start_render_loop( &self.shapes, &self.modifiers, @@ -220,4 +222,30 @@ impl State { None } + + pub fn mark_shape(&mut self, shape_id: Uuid) { + println!("mark_shape {}", shape_id); + self.marked_shapes.push(shape_id); + } + + pub fn has_marked_shapes(&self) -> bool { + !self.marked_shapes.is_empty() + } + + pub fn update_marked_shapes(&mut self) -> bool { + self.render_state.fonts.list_registered_fonts(); + if !self.has_marked_shapes() { + println!("update_marked_shapes -> false"); + return false; + } + while let Some(shape_id) = self.marked_shapes.pop() { + if let Some(shape) = self.shapes.get_mut(&shape_id) { + if let Type::Text(text_content) = &mut shape.shape_type { + text_content.update_layout(shape.selrect); + } + } + } + println!("update_marked_shapes -> true"); + true + } } diff --git a/render-wasm/src/wasm/text.rs b/render-wasm/src/wasm/text.rs index 1d69ad70c0..ab28fd3775 100644 --- a/render-wasm/src/wasm/text.rs +++ b/render-wasm/src/wasm/text.rs @@ -2,7 +2,8 @@ use macros::ToJs; use crate::mem; use crate::shapes::{GrowType, RawTextData, Type}; -use crate::{with_current_shape_mut, STATE}; +use crate::{with_state_mut, with_current_shape_mut, STATE}; +use crate::utils::uuid_from_u32_quartet; #[derive(Debug, PartialEq, Clone, Copy, ToJs)] #[repr(u8)] @@ -89,3 +90,30 @@ pub extern "C" fn update_shape_text_layout() { } }); } + +#[no_mangle] +pub extern "C" fn mark_shape(a: u32, b: u32, c: u32, d: u32) { + with_state_mut!(state, { + let shape_id = uuid_from_u32_quartet(a, b, c, d); + state.mark_shape(shape_id); + }); +} + +#[no_mangle] +pub extern "C" fn update_marked_shapes() { + with_state_mut!(state, { + state.update_marked_shapes(); + }); +} + +#[no_mangle] +pub extern "C" fn update_shape_text_layout_for(a: u32, b: u32, c: u32, d: u32) { + with_state_mut!(state, { + let shape_id = uuid_from_u32_quartet(a, b, c, d); + if let Some(shape) = state.shapes.get_mut(&shape_id) { + if let Type::Text(text_content) = &mut shape.shape_type { + text_content.update_layout(shape.selrect); + } + } + }); +}