0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

🐛 Round coordinates in viewport and paths

This commit is contained in:
alonso.torres 2022-07-15 14:33:08 +02:00
parent f89ccac567
commit 48615ca5b2
4 changed files with 57 additions and 15 deletions

View file

@ -14,6 +14,8 @@
[app.common.spec :as us]
[clojure.spec.alpha :as s]))
(def precision 3)
;; --- Matrix Impl
(defrecord Matrix [^double a
@ -24,7 +26,13 @@
^double f]
Object
(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?
"Return true if `v` is Matrix instance."

View file

@ -354,7 +354,7 @@
(assoc :fills []))
bounds (gsb/get-object-bounds objects object)
{:keys [width height] :as bounds} (gsb/get-object-bounds objects object)
vbox (format-viewbox bounds)
fonts (ff/shape->fonts object objects)
@ -366,8 +366,8 @@
[:& (mf/provider embed/context) {:value render-embed?}
[:svg {:id (dm/str "screenshot-" object-id)
:view-box vbox
:width (:width bounds)
:height (:height bounds)
:width (ust/format-precision width viewbox-decimal-precision)
:height (ust/format-precision height viewbox-decimal-precision)
:version "1.1"
:xmlns "http://www.w3.org/2000/svg"
:xmlnsXlink "http://www.w3.org/1999/xlink"

View file

@ -10,13 +10,14 @@
[app.common.data.macros :as dm]
[app.common.geom.point :as gpt]
[app.main.ui.cursors :as cur]
[app.main.ui.formats :refer [format-number]]
[app.util.dom :as dom]))
(defn format-viewbox [vbox]
(dm/str (:x vbox 0) " "
(:y vbox 0) " "
(:width vbox 0) " "
(:height vbox 0)))
(dm/str (format-number(:x vbox 0)) " "
(format-number (:y vbox 0)) " "
(format-number (:width vbox 0)) " "
(format-number (:height vbox 0))))
(defn translate-point-to-viewport [viewport zoom pt]
(let [vbox (.. ^js viewport -viewBox -baseVal)

View file

@ -6,25 +6,58 @@
(ns app.util.path.format
(:require
[app.common.math :as mth]
[app.common.path.commands :as upc]
[app.common.path.subpaths :refer [pt=]]
[app.util.array :as arr]))
(def path-precision 3)
(defn- join-params
([a]
(js* "\"\"+~{}" a))
(js* "\"\"+~{}"
(mth/precision a path-precision)))
([a b]
(js* "\"\"+~{}+\",\"+~{}" a b))
(js* "\"\"+~{}+\",\"+~{}"
(mth/precision a path-precision)
(mth/precision b path-precision)))
([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]
(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]
(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]
(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]
(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
[command {:keys [x y] :as params}]