mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
🐛 Fix problems with strange file
This commit is contained in:
parent
028c084b22
commit
1a2a90f829
4 changed files with 31 additions and 29 deletions
|
@ -43,13 +43,13 @@
|
||||||
(defn bounding-box
|
(defn bounding-box
|
||||||
"Returns a rect that wraps the shape after all transformations applied."
|
"Returns a rect that wraps the shape after all transformations applied."
|
||||||
[shape]
|
[shape]
|
||||||
; TODO: perhaps we need to store this calculation in a shape attribute
|
;; TODO: perhaps we need to store this calculation in a shape attribute
|
||||||
(gpr/points->rect (:points shape)))
|
(gpr/points->rect (:points shape)))
|
||||||
|
|
||||||
(defn left-bound
|
(defn left-bound
|
||||||
"Returns the lowest x coord of the shape BEFORE applying transformations."
|
"Returns the lowest x coord of the shape BEFORE applying transformations."
|
||||||
; TODO: perhaps some day we want after transformations, but for the
|
;; TODO: perhaps some day we want after transformations, but for the
|
||||||
; moment it's enough as is now.
|
;; moment it's enough as is now.
|
||||||
[shape]
|
[shape]
|
||||||
(or (:x shape) (:x (:selrect shape)))) ; Paths don't have :x attribute
|
(or (:x shape) (:x (:selrect shape)))) ; Paths don't have :x attribute
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@
|
||||||
|
|
||||||
([attr val1 val2 precision]
|
([attr val1 val2 precision]
|
||||||
(let [close-val? (fn [num1 num2]
|
(let [close-val? (fn [num1 num2]
|
||||||
(when (and (number? num1) (number? num2))
|
(when (and (number? num1) (number? num2))
|
||||||
(< (mth/abs (- num1 num2)) precision)))]
|
(< (mth/abs (- num1 num2)) precision)))]
|
||||||
(cond
|
(cond
|
||||||
(and (number? val1) (number? val2))
|
(and (number? val1) (number? val2))
|
||||||
(close-val? val1 val2)
|
(close-val? val1 val2)
|
||||||
|
|
|
@ -210,7 +210,7 @@
|
||||||
;; after-vec will contain the side length of the grown side
|
;; after-vec will contain the side length of the grown side
|
||||||
;; we scale the shape by the diference and translate it by the start
|
;; we scale the shape by the diference and translate it by the start
|
||||||
;; displacement (so its left+top position is constant)
|
;; displacement (so its left+top position is constant)
|
||||||
scale (/ (gpt/length after-vec) (gpt/length before-vec))
|
scale (/ (gpt/length after-vec) (max 0.01 (gpt/length before-vec)))
|
||||||
|
|
||||||
resize-origin (gpo/origin child-points-after)
|
resize-origin (gpo/origin child-points-after)
|
||||||
|
|
||||||
|
@ -268,11 +268,11 @@
|
||||||
|
|
||||||
scale-x (if (= :scale constraints-h)
|
scale-x (if (= :scale constraints-h)
|
||||||
1
|
1
|
||||||
(/ (gpo/width-points child-bb-before) (gpo/width-points child-bb-after)))
|
(/ (gpo/width-points child-bb-before) (max 0.01 (gpo/width-points child-bb-after))))
|
||||||
|
|
||||||
scale-y (if (= :scale constraints-v)
|
scale-y (if (= :scale constraints-v)
|
||||||
1
|
1
|
||||||
(/ (gpo/height-points child-bb-before) (gpo/height-points child-bb-after)))
|
(/ (gpo/height-points child-bb-before) (max 0.01 (gpo/height-points child-bb-after))))
|
||||||
|
|
||||||
resize-vector (gpt/point scale-x scale-y)
|
resize-vector (gpt/point scale-x scale-y)
|
||||||
resize-origin (gpo/origin transformed-child-bounds)
|
resize-origin (gpo/origin transformed-child-bounds)
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
(defn abs
|
(defn abs
|
||||||
[v]
|
[v]
|
||||||
#?(:cljs (js/Math.abs v)
|
#?(:cljs (js/Math.abs v)
|
||||||
:clj (Math/abs v)))
|
:clj (Math/abs (double v))))
|
||||||
|
|
||||||
(defn sin
|
(defn sin
|
||||||
"Returns the sine of a number"
|
"Returns the sine of a number"
|
||||||
|
|
|
@ -27,23 +27,21 @@
|
||||||
|
|
||||||
(defn- draw-thumbnail-canvas!
|
(defn- draw-thumbnail-canvas!
|
||||||
[canvas-node img-node]
|
[canvas-node img-node]
|
||||||
(ts/raf
|
(try
|
||||||
(fn []
|
(when (and (some? canvas-node) (some? img-node))
|
||||||
(try
|
(let [canvas-context (.getContext canvas-node "2d")
|
||||||
(when (and (some? canvas-node) (some? img-node))
|
canvas-width (.-width canvas-node)
|
||||||
(let [canvas-context (.getContext canvas-node "2d")
|
canvas-height (.-height canvas-node)]
|
||||||
canvas-width (.-width canvas-node)
|
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
||||||
canvas-height (.-height canvas-node)]
|
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
||||||
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
|
||||||
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
|
||||||
|
|
||||||
;; Set a true on the next animation frame, we make sure the drawImage is completed
|
;; Set a true on the next animation frame, we make sure the drawImage is completed
|
||||||
(ts/raf
|
(ts/raf
|
||||||
#(dom/set-data! canvas-node "ready" "true"))
|
#(dom/set-data! canvas-node "ready" "true"))
|
||||||
true))
|
true))
|
||||||
(catch :default err
|
(catch :default err
|
||||||
(.error js/console err)
|
(.error js/console err)
|
||||||
false)))))
|
false)))
|
||||||
|
|
||||||
(defn- remove-image-loading
|
(defn- remove-image-loading
|
||||||
"Remove the changes related to change a url for its embed value. This is necessary
|
"Remove the changes related to change a url for its embed value. This is necessary
|
||||||
|
@ -78,8 +76,12 @@
|
||||||
(gsh/selection-rect (concat [shape] all-children))
|
(gsh/selection-rect (concat [shape] all-children))
|
||||||
(-> shape :points gsh/points->selrect))
|
(-> shape :points gsh/points->selrect))
|
||||||
|
|
||||||
fixed-width (mth/clamp width 250 2000)
|
[fixed-width fixed-height]
|
||||||
fixed-height (/ (* height fixed-width) width)
|
(if (> width height)
|
||||||
|
[(mth/clamp width 250 2000)
|
||||||
|
(/ (* height (mth/clamp width 250 2000)) width)]
|
||||||
|
[(/ (* width (mth/clamp height 250 2000)) height)
|
||||||
|
(mth/clamp height 250 2000)])
|
||||||
|
|
||||||
image-url (mf/use-state nil)
|
image-url (mf/use-state nil)
|
||||||
observer-ref (mf/use-var nil)
|
observer-ref (mf/use-var nil)
|
||||||
|
@ -289,6 +291,6 @@
|
||||||
:height height}
|
:height height}
|
||||||
[:img {:ref frame-image-ref
|
[:img {:ref frame-image-ref
|
||||||
:src @image-url
|
:src @image-url
|
||||||
:width width
|
:width fixed-width
|
||||||
:height height
|
:height fixed-height
|
||||||
:on-load on-image-load}]])])]))
|
:on-load on-image-load}]])])]))
|
||||||
|
|
Loading…
Add table
Reference in a new issue