mirror of
https://github.com/penpot/penpot.git
synced 2025-02-11 01:28:30 -05:00
🐛 Fix custom fonts loading on dashboard thumbnails
This commit is contained in:
parent
05c8ad8bf9
commit
2b70331630
2 changed files with 40 additions and 31 deletions
|
@ -40,6 +40,9 @@
|
|||
- Support for import/export binary format [Taiga #2991](https://tree.taiga.io/project/penpot/us/2991)
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
- Fix font rendering on grid thumbnails [Taiga #3473](https://tree.taiga.io/project/penpot/issue/3473)
|
||||
|
||||
### :arrow_up: Deps updates
|
||||
### :heart: Community contributions by (Thank you!)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
[okulary.core :as l]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(log/set-level! :warn)
|
||||
(log/set-level! :info)
|
||||
|
||||
(def google-fonts
|
||||
(preload-gfonts "fonts/gfonts.2022.07.11.json"))
|
||||
|
@ -126,8 +126,7 @@
|
|||
|
||||
(defmethod load-font :builtin
|
||||
[{:keys [id ::on-loaded] :as font}]
|
||||
(log/debug :action "load-font" :font-id id :backend "builtin")
|
||||
;; (js/console.log "[debug:fonts]: loading builtin font" id)
|
||||
(log/debug :hint "load-font" :font-id id :backend "builtin")
|
||||
(when (fn? on-loaded)
|
||||
(on-loaded id)))
|
||||
|
||||
|
@ -142,7 +141,7 @@
|
|||
(defmethod load-font :google
|
||||
[{:keys [id ::on-loaded] :as font}]
|
||||
(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)]
|
||||
(load-font-css! url (partial on-loaded id))
|
||||
nil)))
|
||||
|
@ -185,7 +184,7 @@
|
|||
(defmethod load-font :custom
|
||||
[{:keys [id ::on-loaded] :as font}]
|
||||
(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)]
|
||||
(add-font-css! css)
|
||||
(when (fn? on-loaded)
|
||||
|
@ -200,36 +199,43 @@
|
|||
(p/create (fn [resolve]
|
||||
(ensure-loaded! id resolve))))
|
||||
([id on-loaded]
|
||||
(when-let [font (get @fontsdb id)]
|
||||
(log/debug :action "ensure-loaded!" :font-id id :font font)
|
||||
(cond
|
||||
;; Font already loaded, we just continue
|
||||
(contains? @loaded id)
|
||||
(p/do
|
||||
(on-loaded id)
|
||||
id)
|
||||
(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))
|
||||
|
||||
;; Font is currently downloading. We attach the caller to the promise
|
||||
(contains? @loading id)
|
||||
(-> (get @loading id)
|
||||
(p/then #(do (on-loaded id) id)))
|
||||
(when-let [font (get @fontsdb id)]
|
||||
(cond
|
||||
;; Font already loaded, we just continue
|
||||
(contains? @loaded id)
|
||||
(p/do
|
||||
(on-loaded id)
|
||||
id)
|
||||
|
||||
;; First caller, we create the promise and then wait
|
||||
:else
|
||||
(let [on-load (fn [resolve]
|
||||
(swap! loaded conj id)
|
||||
(swap! loading dissoc id)
|
||||
(on-loaded id)
|
||||
(resolve id))
|
||||
;; Font is currently downloading. We attach the caller to the promise
|
||||
(contains? @loading id)
|
||||
(-> (get @loading id)
|
||||
(p/then #(do (on-loaded id) id)))
|
||||
|
||||
load-p (p/create
|
||||
(fn [resolve _]
|
||||
(-> font
|
||||
(assoc ::on-loaded (partial on-load resolve))
|
||||
(load-font))))]
|
||||
;; First caller, we create the promise and then wait
|
||||
:else
|
||||
(let [on-load (fn [resolve]
|
||||
(swap! loaded conj id)
|
||||
(swap! loading dissoc id)
|
||||
(on-loaded id)
|
||||
(resolve id))
|
||||
|
||||
(swap! loading assoc id load-p)
|
||||
load-p)))))
|
||||
load-p (p/create
|
||||
(fn [resolve _]
|
||||
(-> font
|
||||
(assoc ::on-loaded (partial on-load resolve))
|
||||
(load-font))))]
|
||||
|
||||
(swap! loading assoc id load-p)
|
||||
load-p))))))
|
||||
|
||||
(defn ready
|
||||
[cb]
|
||||
|
|
Loading…
Add table
Reference in a new issue