mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
🐛 Round coordinates in viewport and paths
This commit is contained in:
parent
f89ccac567
commit
48615ca5b2
4 changed files with 57 additions and 15 deletions
|
@ -14,6 +14,8 @@
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
(def precision 3)
|
||||||
|
|
||||||
;; --- Matrix Impl
|
;; --- Matrix Impl
|
||||||
|
|
||||||
(defrecord Matrix [^double a
|
(defrecord Matrix [^double a
|
||||||
|
@ -24,7 +26,13 @@
|
||||||
^double f]
|
^double f]
|
||||||
Object
|
Object
|
||||||
(toString [_]
|
(toString [_]
|
||||||
(str "matrix(" a "," b "," c "," d "," e "," f ")")))
|
(str "matrix("
|
||||||
|
(mth/precision a precision) ","
|
||||||
|
(mth/precision b precision) ","
|
||||||
|
(mth/precision c precision) ","
|
||||||
|
(mth/precision d precision) ","
|
||||||
|
(mth/precision e precision) ","
|
||||||
|
(mth/precision f precision) ")")))
|
||||||
|
|
||||||
(defn matrix?
|
(defn matrix?
|
||||||
"Return true if `v` is Matrix instance."
|
"Return true if `v` is Matrix instance."
|
||||||
|
|
|
@ -354,7 +354,7 @@
|
||||||
(assoc :fills []))
|
(assoc :fills []))
|
||||||
|
|
||||||
|
|
||||||
bounds (gsb/get-object-bounds objects object)
|
{:keys [width height] :as bounds} (gsb/get-object-bounds objects object)
|
||||||
vbox (format-viewbox bounds)
|
vbox (format-viewbox bounds)
|
||||||
fonts (ff/shape->fonts object objects)
|
fonts (ff/shape->fonts object objects)
|
||||||
|
|
||||||
|
@ -366,8 +366,8 @@
|
||||||
[:& (mf/provider embed/context) {:value render-embed?}
|
[:& (mf/provider embed/context) {:value render-embed?}
|
||||||
[:svg {:id (dm/str "screenshot-" object-id)
|
[:svg {:id (dm/str "screenshot-" object-id)
|
||||||
:view-box vbox
|
:view-box vbox
|
||||||
:width (:width bounds)
|
:width (ust/format-precision width viewbox-decimal-precision)
|
||||||
:height (:height bounds)
|
:height (ust/format-precision height viewbox-decimal-precision)
|
||||||
:version "1.1"
|
:version "1.1"
|
||||||
:xmlns "http://www.w3.org/2000/svg"
|
:xmlns "http://www.w3.org/2000/svg"
|
||||||
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
||||||
|
|
|
@ -10,13 +10,14 @@
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.main.ui.cursors :as cur]
|
[app.main.ui.cursors :as cur]
|
||||||
|
[app.main.ui.formats :refer [format-number]]
|
||||||
[app.util.dom :as dom]))
|
[app.util.dom :as dom]))
|
||||||
|
|
||||||
(defn format-viewbox [vbox]
|
(defn format-viewbox [vbox]
|
||||||
(dm/str (:x vbox 0) " "
|
(dm/str (format-number(:x vbox 0)) " "
|
||||||
(:y vbox 0) " "
|
(format-number (:y vbox 0)) " "
|
||||||
(:width vbox 0) " "
|
(format-number (:width vbox 0)) " "
|
||||||
(:height vbox 0)))
|
(format-number (:height vbox 0))))
|
||||||
|
|
||||||
(defn translate-point-to-viewport [viewport zoom pt]
|
(defn translate-point-to-viewport [viewport zoom pt]
|
||||||
(let [vbox (.. ^js viewport -viewBox -baseVal)
|
(let [vbox (.. ^js viewport -viewBox -baseVal)
|
||||||
|
|
|
@ -6,25 +6,58 @@
|
||||||
|
|
||||||
(ns app.util.path.format
|
(ns app.util.path.format
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.math :as mth]
|
||||||
[app.common.path.commands :as upc]
|
[app.common.path.commands :as upc]
|
||||||
[app.common.path.subpaths :refer [pt=]]
|
[app.common.path.subpaths :refer [pt=]]
|
||||||
[app.util.array :as arr]))
|
[app.util.array :as arr]))
|
||||||
|
|
||||||
|
(def path-precision 3)
|
||||||
|
|
||||||
(defn- join-params
|
(defn- join-params
|
||||||
([a]
|
([a]
|
||||||
(js* "\"\"+~{}" a))
|
(js* "\"\"+~{}"
|
||||||
|
(mth/precision a path-precision)))
|
||||||
([a b]
|
([a b]
|
||||||
(js* "\"\"+~{}+\",\"+~{}" a b))
|
(js* "\"\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)))
|
||||||
([a b c]
|
([a b c]
|
||||||
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}" a b c))
|
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)
|
||||||
|
(mth/precision c path-precision)))
|
||||||
([a b c d]
|
([a b c d]
|
||||||
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d))
|
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)
|
||||||
|
(mth/precision c path-precision)
|
||||||
|
(mth/precision d path-precision)
|
||||||
|
))
|
||||||
([a b c d e]
|
([a b c d e]
|
||||||
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e))
|
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)
|
||||||
|
(mth/precision c path-precision)
|
||||||
|
(mth/precision d path-precision)
|
||||||
|
(mth/precision e path-precision)))
|
||||||
([a b c d e f]
|
([a b c d e f]
|
||||||
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e f))
|
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)
|
||||||
|
(mth/precision c path-precision)
|
||||||
|
(mth/precision d path-precision)
|
||||||
|
(mth/precision e path-precision)
|
||||||
|
(mth/precision f path-precision)
|
||||||
|
))
|
||||||
([a b c d e f g]
|
([a b c d e f g]
|
||||||
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e f g)))
|
(js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}"
|
||||||
|
(mth/precision a path-precision)
|
||||||
|
(mth/precision b path-precision)
|
||||||
|
(mth/precision c path-precision)
|
||||||
|
(mth/precision d path-precision)
|
||||||
|
(mth/precision e path-precision)
|
||||||
|
(mth/precision f path-precision)
|
||||||
|
(mth/precision g path-precision))))
|
||||||
|
|
||||||
(defn- translate-params
|
(defn- translate-params
|
||||||
[command {:keys [x y] :as params}]
|
[command {:keys [x y] :as params}]
|
||||||
|
|
Loading…
Reference in a new issue