🐛 Fix problem with embed fonts

This commit is contained in:
alonso.torres 2021-05-06 11:04:53 +02:00 committed by Andrey Antukh
parent 4bf0ae0a9d
commit 2c3a3845ac
5 changed files with 35 additions and 38 deletions

View file

@ -10,7 +10,6 @@
[app.common.geom.shapes :as geom]
[app.main.ui.context :as muc]
[app.main.ui.shapes.attrs :as attrs]
[app.main.ui.shapes.text.embed :as ste]
[app.main.ui.shapes.text.styles :as sts]
[app.util.color :as uc]
[app.util.object :as obj]
@ -30,15 +29,12 @@
{::mf/wrap-props false}
[props]
(let [node (obj/get props "node")
embed? (obj/get props "embed-fonts?")
children (obj/get props "children")
shape (obj/get props "shape")
style (sts/generate-root-styles shape node)]
[:div.root.rich-text
{:style style
:xmlns "http://www.w3.org/1999/xhtml"}
(when embed?
[:& ste/embed-fontfaces-style {:node node}])
children]))
(mf/defc render-paragraph-set
@ -94,7 +90,6 @@
[props ref]
(let [{:keys [id x y width height content] :as shape} (obj/get props "shape")
grow-type (obj/get props "grow-type") ;; This is only needed in workspace
embed-fonts? (mf/use-ctx muc/embed-ctx)
;; We add 8px to add a padding for the exporter
;; width (+ width 8)
]
@ -109,5 +104,4 @@
:ref ref}
[:& render-node {:index 0
:shape shape
:node content
:embed-fonts? embed-fonts?}]]))
:node content}]]))

View file

@ -62,12 +62,14 @@
"Given a font and the variant-id, retrieves the style CSS for it."
[{:keys [id backend family variants] :as font} font-variant-id]
(if (= :google backend)
(->> (http/send! {:method :get
:mode :no-cors
:uri (fonts/gfont-url family [{:id font-variant-id}])
:response-type :text})
(rx/map :body)
(http/as-promise))
(let [uri (fonts/gfont-url family [{:id font-variant-id}])]
(->> (http/send! {:method :get
:mode :cors
:omit-default-headers true
:uri uri
:response-type :text})
(rx/map :body)
(http/as-promise)))
(let [{:keys [name weight style suffix] :as variant} (d/seek #(= (:id %) font-variant-id) variants)
result (str/fmt font-face-template {:family family
:style style
@ -89,7 +91,7 @@
(with-cache {:key uris :max-age (dt/duration {:hours 4})}
(->> (rx/from (seq uris))
(rx/mapcat (fn [uri]
(->> (http/send! {:method :get :uri uri :response-type :blob})
(->> (http/send! {:method :get :uri uri :response-type :blob :omit-default-headers true})
(rx/map :body)
(rx/mapcat wapi/read-file-as-data-url)
(rx/map #(vector uri %)))))
@ -124,9 +126,10 @@
(mf/defc embed-fontfaces-style
{::mf/wrap-props false
::mf/wrap [mf/memo]}
::mf/wrap [#(mf/memo' % (mf/check-props ["shapes"]))]}
[props]
(let [node (obj/get props "node")
(let [shapes (obj/get props "shapes")
node {:children (->> shapes (map :content))}
fonts (-> node get-node-fonts memoize)
style (mf/use-state nil)]