0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

🐛 Parametrized render to embed objects. Fix problem with fonts when exporting to SVG

This commit is contained in:
alonso.torres 2022-03-21 21:34:46 +01:00
parent e6f8269c0b
commit 118b4367e7
6 changed files with 17 additions and 9 deletions

View file

@ -26,6 +26,7 @@
(defn- get-mtype
[type]
(case (d/name type)
"zip" "application/zip"
"pdf" "application/pdf"

View file

@ -327,6 +327,7 @@
:page-id page-id
:object-id object-id
:render-texts true
:embed true
:route "render-object"}
uri (-> (or uri (cf/get :public-uri))

View file

@ -226,7 +226,7 @@
font-style: %(style)s;
font-weight: %(weight)s;
font-display: block;
src: url(/fonts/%(family)s-%(suffix)s.woff) format('woff');
src: url(%(baseurl)sfonts/%(family)s-%(suffix)s.woff) format('woff');
}
")
@ -262,7 +262,8 @@
:else
(let [{:keys [weight style suffix] :as variant}
(d/seek #(= (:id %) font-variant-id) variants)
font-data {:family family
font-data {:baseurl (str cf/public-uri)
:family family
:style style
:suffix (or suffix font-variant-id)
:weight weight}]

View file

@ -115,10 +115,12 @@
(let [file-id (uuid (get-in route [:path-params :file-id]))
page-id (uuid (get-in route [:path-params :page-id]))
object-id (uuid (get-in route [:path-params :object-id]))
embed? (= (get-in route [:query-params :embed]) "true")
render-texts (get-in route [:query-params :render-texts])]
[:& render/render-object {:file-id file-id
:page-id page-id
:object-id object-id
:embed? embed?
:render-texts? (and (some? render-texts) (= render-texts "true"))}]))
:render-sprite

View file

@ -52,8 +52,8 @@
(mf/defc object-svg
{::mf/wrap [mf/memo]}
[{:keys [objects object-id zoom render-texts?]
:or {zoom 1}
[{:keys [objects object-id zoom render-texts? embed?]
:or {zoom 1 embed? false}
:as props}]
(let [object (get objects object-id)
frame-id (if (= :frame (:type object))
@ -106,7 +106,7 @@
{:size (str (mth/ceil width) "px "
(mth/ceil height) "px")}))
[:& (mf/provider embed/context) {:value false}
[:& (mf/provider embed/context) {:value embed?}
[:svg {:id "screenshot"
:view-box vbox
:width width
@ -152,7 +152,7 @@
objects))
(mf/defc render-object
[{:keys [file-id page-id object-id render-texts?] :as props}]
[{:keys [file-id page-id object-id render-texts? embed?] :as props}]
(let [objects (mf/use-state nil)]
(mf/with-effect [file-id page-id object-id]
@ -171,6 +171,7 @@
(when @objects
[:& object-svg {:objects @objects
:object-id object-id
:embed? embed?
:render-texts? render-texts?
:zoom 1}])))

View file

@ -60,17 +60,19 @@
(s/def ::file-id ::us/uuid)
(s/def ::object-id ::us/uuid)
(s/def ::render-text ::us/boolean)
(s/def ::embed ::us/boolean)
(s/def ::render-object-params
(s/keys :req-un [::file-id ::page-id ::object-id]
:opt-un [::render-text]))
:opt-un [::render-text ::embed]))
(defn- render-object
[params]
(let [{:keys [page-id file-id object-id render-texts]} (us/conform ::render-object-params params)]
(let [{:keys [page-id file-id object-id render-texts embed]} (us/conform ::render-object-params params)]
(mf/html
[:& render/render-object
{:file-id file-id
:page-id page-id
:object-id object-id
:render-texts? (and (some? render-texts) (= render-texts "true"))}])))
:embed? embed
:render-texts? render-texts}])))