🎉 Export shapes to pdf

This commit is contained in:
Andrés Moya 2021-07-02 13:19:04 +02:00 committed by Alonso Torres
parent e9945235ed
commit 1ee14a76f4
8 changed files with 146 additions and 19 deletions

View file

@ -9,6 +9,7 @@
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[app.main.data.fonts :as df]
@ -18,6 +19,7 @@
[app.main.ui.shapes.embed :as embed]
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.shape :refer [shape-container]]
[app.util.dom :as dom]
[beicon.core :as rx]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
@ -68,6 +70,11 @@
#(exports/shape-wrapper-factory objects))
]
(mf/use-effect
(mf/deps width height)
#(dom/set-page-style {:size (str (mth/round width) "px "
(mth/round height) "px")}))
[:& (mf/provider embed/context) {:value true}
[:svg {:id "screenshot"
:view-box vbox

View file

@ -36,6 +36,11 @@
(not (empty (:suffix (first exports)))))
(str (:suffix (first exports))))
scale-enabled?
(mf/use-callback
(fn [export]
(#{:png :jpeg} (:type export))))
on-download
(mf/use-callback
(mf/deps shape)
@ -111,15 +116,16 @@
(for [[index export] (d/enumerate exports)]
[:div.element-set-options-group
{:key index}
[:select.input-select {:on-change (partial on-scale-change index)
:value (:scale export)}
[:option {:value "0.5"} "0.5x"]
[:option {:value "0.75"} "0.75x"]
[:option {:value "1"} "1x"]
[:option {:value "1.5"} "1.5x"]
[:option {:value "2"} "2x"]
[:option {:value "4"} "4x"]
[:option {:value "6"} "6x"]]
(when (scale-enabled? export)
[:select.input-select {:on-change (partial on-scale-change index)
:value (:scale export)}
[:option {:value "0.5"} "0.5x"]
[:option {:value "0.75"} "0.75x"]
[:option {:value "1"} "1x"]
[:option {:value "1.5"} "1.5x"]
[:option {:value "2"} "2x"]
[:option {:value "4"} "4x"]
[:option {:value "6"} "6x"]])
[:input.input-text {:value (:suffix export)
:placeholder (tr "workspace.options.export.suffix")
:on-change (partial on-suffix-change index)}]
@ -127,7 +133,8 @@
:on-change (partial on-type-change index)}
[:option {:value "png"} "PNG"]
[:option {:value "jpeg"} "JPEG"]
[:option {:value "svg"} "SVG"]]
[:option {:value "svg"} "SVG"]
[:option {:value "pdf"} "PDF"]]
[:div.delete-icon {:on-click (partial delete-export index)}
i/minus]])

View file

@ -6,13 +6,13 @@
(ns app.util.dom
(:require
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]
[app.util.object :as obj]
[cuerdas.core :as str]
[goog.dom :as dom]
[promesa.core :as p]))
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]
[app.util.object :as obj]
[cuerdas.core :as str]
[goog.dom :as dom]
[promesa.core :as p]))
;; --- Deprecated methods
@ -45,6 +45,18 @@
[title]
(set! (.-title globals/document) title))
(defn set-page-style
[style]
(let [head (first (.getElementsByTagName ^js globals/document "head"))
style-str (str/join "\n"
(map (fn [[k v]]
(str (name k) ": " v ";"))
style))]
(.insertAdjacentHTML head "beforeend"
(str "<style>"
" @page {" style-str "}"
"</style>"))))
(defn get-element-by-class
([classname]
(dom/getElementByClass classname))