🐛 Fix custom fonts loading on dashboard thumbnails

This commit is contained in:
Andrey Antukh 2022-07-12 09:50:27 +02:00 committed by Alonso Torres
parent 05c8ad8bf9
commit 2b70331630
2 changed files with 40 additions and 31 deletions

View file

@ -40,6 +40,9 @@
- Support for import/export binary format [Taiga #2991](https://tree.taiga.io/project/penpot/us/2991) - Support for import/export binary format [Taiga #2991](https://tree.taiga.io/project/penpot/us/2991)
### :bug: Bugs fixed ### :bug: Bugs fixed
- Fix font rendering on grid thumbnails [Taiga #3473](https://tree.taiga.io/project/penpot/issue/3473)
### :arrow_up: Deps updates ### :arrow_up: Deps updates
### :heart: Community contributions by (Thank you!) ### :heart: Community contributions by (Thank you!)

View file

@ -23,7 +23,7 @@
[okulary.core :as l] [okulary.core :as l]
[promesa.core :as p])) [promesa.core :as p]))
(log/set-level! :warn) (log/set-level! :info)
(def google-fonts (def google-fonts
(preload-gfonts "fonts/gfonts.2022.07.11.json")) (preload-gfonts "fonts/gfonts.2022.07.11.json"))
@ -126,8 +126,7 @@
(defmethod load-font :builtin (defmethod load-font :builtin
[{:keys [id ::on-loaded] :as font}] [{:keys [id ::on-loaded] :as font}]
(log/debug :action "load-font" :font-id id :backend "builtin") (log/debug :hint "load-font" :font-id id :backend "builtin")
;; (js/console.log "[debug:fonts]: loading builtin font" id)
(when (fn? on-loaded) (when (fn? on-loaded)
(on-loaded id))) (on-loaded id)))
@ -142,7 +141,7 @@
(defmethod load-font :google (defmethod load-font :google
[{:keys [id ::on-loaded] :as font}] [{:keys [id ::on-loaded] :as font}]
(when (exists? js/window) (when (exists? js/window)
(log/debug :action "load-font" :font-id id :backend "google") (log/info :hint "load-font" :font-id id :backend "google")
(let [url (generate-gfonts-url font)] (let [url (generate-gfonts-url font)]
(load-font-css! url (partial on-loaded id)) (load-font-css! url (partial on-loaded id))
nil))) nil)))
@ -185,7 +184,7 @@
(defmethod load-font :custom (defmethod load-font :custom
[{:keys [id ::on-loaded] :as font}] [{:keys [id ::on-loaded] :as font}]
(when (exists? js/window) (when (exists? js/window)
(js/console.log "[debug:fonts]: loading custom font" id) (log/info :hint "load-font" :font-id id :backend "custom")
(let [css (generate-custom-font-css font)] (let [css (generate-custom-font-css font)]
(add-font-css! css) (add-font-css! css)
(when (fn? on-loaded) (when (fn? on-loaded)
@ -200,8 +199,15 @@
(p/create (fn [resolve] (p/create (fn [resolve]
(ensure-loaded! id resolve)))) (ensure-loaded! id resolve))))
([id on-loaded] ([id on-loaded]
(log/debug :action "try-ensure-loaded!" :font-id id)
(if-not (exists? js/window)
;; If we are in the worker environment, we just mark it as loaded
;; without really loading it.
(do
(swap! loaded conj id)
(p/resolved id))
(when-let [font (get @fontsdb id)] (when-let [font (get @fontsdb id)]
(log/debug :action "ensure-loaded!" :font-id id :font font)
(cond (cond
;; Font already loaded, we just continue ;; Font already loaded, we just continue
(contains? @loaded id) (contains? @loaded id)
@ -229,7 +235,7 @@
(load-font))))] (load-font))))]
(swap! loading assoc id load-p) (swap! loading assoc id load-p)
load-p))))) load-p))))))
(defn ready (defn ready
[cb] [cb]