Merge pull request #6652 from penpot/elenatorro-fix-load-fonts

🐛 Fix fonts initialization
This commit is contained in:
Alejandro Alonso 2025-06-09 09:31:00 +02:00 committed by GitHub
commit d008ea9edd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 67 additions and 54 deletions

View file

@ -189,27 +189,28 @@
(defn- get-string-length [string] (+ (count string) 1))
(defn- store-image
(defn- fetch-image
[id]
(let [buffer (uuid/get-u32 id)
url (cf/resolve-file-media {:id id})]
(->> (http/send! {:method :get
:uri url
:response-type :blob})
(rx/map :body)
(rx/mapcat wapi/read-file-as-array-buffer)
(rx/map (fn [image]
(let [size (.-byteLength image)
offset (mem/alloc-bytes size)
heap (mem/get-heap-u8)
data (js/Uint8Array. image)]
(.set heap data offset)
(h/call wasm/internal-module "_store_image"
(aget buffer 0)
(aget buffer 1)
(aget buffer 2)
(aget buffer 3))
true))))))
{:key url
:callback #(->> (http/send! {:method :get
:uri url
:response-type :blob})
(rx/map :body)
(rx/mapcat wapi/read-file-as-array-buffer)
(rx/map (fn [image]
(let [size (.-byteLength image)
offset (mem/alloc-bytes size)
heap (mem/get-heap-u8)
data (js/Uint8Array. image)]
(.set heap data offset)
(h/call wasm/internal-module "_store_image"
(aget buffer 0)
(aget buffer 1)
(aget buffer 2)
(aget buffer 3))
true))))}))
(defn- get-fill-images
[leaf]
@ -227,7 +228,7 @@
(aget buffer 2)
(aget buffer 3))]
(when (zero? cached-image?)
(store-image id))))))
(fetch-image id))))))
(defn set-shape-text-images
[content]
@ -269,7 +270,7 @@
(aget buffer 2)
(aget buffer 3))]
(when (zero? cached-image?)
(store-image id))))
(fetch-image id))))
image-fills))))
(defn set-shape-strokes
@ -308,7 +309,7 @@
(dm/get-prop image :height))
(h/call wasm/internal-module "_add_shape_stroke_fill")
(when (== cached-image? 0)
(store-image id)))
(fetch-image id)))
(some? color)
(do
@ -640,9 +641,10 @@
(swap! languages into (t/get-languages text))
(t/write-shape-text leaves paragraph text))
(recur (inc index))))))
(let [updated-fonts
(-> fonts
(cond-> emoji? (f/add-emoji-font))
(cond-> @emoji? (f/add-emoji-font))
(f/add-noto-fonts @languages))]
(f/store-fonts updated-fonts))))
@ -742,8 +744,6 @@
(set-shape-svg-raw-content (get-static-markup shape)))
(when (some? corners) (set-shape-corners corners))
(when (some? shadows) (set-shape-shadows shadows))
(when (and (= type :text) (some? content))
(set-shape-text content))
(when (= type :text)
(set-shape-grow-type grow-type))
(when (or (ctl/any-layout? shape)
@ -764,16 +764,20 @@
pending)))
(defn process-pending
[pending]
(when-let [pending (-> (d/index-by :key :callback pending) vals)]
(->> (rx/from pending)
(rx/mapcat (fn [callback] (callback)))
(rx/reduce conj [])
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects"))))))
(defn process-object
[shape]
(let [pending (set-object [] shape)]
(when-let [pending (seq pending)]
(->> (rx/from pending)
(rx/mapcat identity)
(rx/reduce conj [])
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects")))))))
(process-pending pending)))
(defn set-objects
[objects]
@ -790,13 +794,7 @@
(perf/end-measure "set-objects")
(clear-drawing-cache)
(request-render "set-objects")
(when-let [pending (seq pending)]
(->> (rx/from pending)
(rx/mapcat identity)
(rx/reduce conj [])
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects")))))))
(process-pending pending)))
(defn set-structure-modifiers
[entries]

View file

@ -94,13 +94,14 @@
fallback?)
true))
(defn- store-font-url
(defn- fetch-font
[font-data font-url emoji? fallback?]
(->> (http/send! {:method :get
:uri font-url
:response-type :buffer})
(rx/map (fn [{:keys [body]}]
(store-font-buffer font-data body emoji? fallback?)))))
{:key font-url
:callback #(->> (http/send! {:method :get
:uri font-url
:response-type :buffer})
(rx/map (fn [{:keys [body]}]
(store-font-buffer font-data body emoji? fallback?))))})
(defn- google-font-ttf-url
[font-id font-variant-id]
@ -131,9 +132,10 @@
(aget id-buffer 2)
(aget id-buffer 3)
(:weight font-data)
(:style font-data)))]
(:style font-data)
emoji?))]
(when-not font-stored?
(store-font-url font-data uri emoji? fallback?)))))
(fetch-font font-data uri emoji? fallback?)))))
(defn serialize-font-style
[font-style]

View file

@ -148,7 +148,7 @@
(h/call wasm/internal-module "_set_shape_text_content"))
(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]")
(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]|[\u2600-\u27BF]")
(def ^:private unicode-ranges
{:japanese #"[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]"
@ -198,7 +198,7 @@
(defn contains-emoji? [text]
(boolean (re-find emoji-pattern text)))
(boolean (some #(re-find emoji-pattern %) (seq text))))
(defn get-languages [text]
(reduce-kv (fn [result lang pattern]