mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 14:21:38 +02:00
✨ Improved text selection
This commit is contained in:
parent
618d22d214
commit
bbf91a8957
6 changed files with 82 additions and 27 deletions
|
@ -70,9 +70,11 @@
|
|||
([points matrix]
|
||||
(transform-points points nil matrix))
|
||||
([points center matrix]
|
||||
(let [prev (if center (gmt/translate-matrix center) (gmt/matrix))
|
||||
post (if center (gmt/translate-matrix (gpt/negate center)) (gmt/matrix))
|
||||
(if (some? matrix)
|
||||
(let [prev (if center (gmt/translate-matrix center) (gmt/matrix))
|
||||
post (if center (gmt/translate-matrix (gpt/negate center)) (gmt/matrix))
|
||||
|
||||
tr-point (fn [point]
|
||||
(gpt/transform point (gmt/multiply prev matrix post)))]
|
||||
(mapv tr-point points))))
|
||||
tr-point (fn [point]
|
||||
(gpt/transform point (gmt/multiply prev matrix post)))]
|
||||
(mapv tr-point points))
|
||||
points)))
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
[app.common.data :as d]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes.common :as gco]
|
||||
[app.common.geom.shapes.path :as gpp]
|
||||
[app.common.geom.shapes.rect :as gpr]
|
||||
[app.common.geom.shapes.text :as gte]
|
||||
[app.common.math :as mth]))
|
||||
|
||||
(defn orientation
|
||||
|
@ -283,6 +285,23 @@
|
|||
(is-point-inside-ellipse? (first rect-points) ellipse-data)
|
||||
(intersects-lines-ellipse? rect-lines ellipse-data))))
|
||||
|
||||
(defn overlaps-text?
|
||||
[{:keys [position-data] :as shape} rect]
|
||||
|
||||
(if (and (some? position-data) (d/not-empty? position-data))
|
||||
(let [center (gco/center-shape shape)
|
||||
|
||||
transform-rect
|
||||
(fn [rect-points]
|
||||
(gco/transform-points rect-points center (:transform shape)))]
|
||||
|
||||
(->> position-data
|
||||
(map (comp transform-rect
|
||||
gpr/rect->points
|
||||
gte/position-data->rect))
|
||||
(some #(overlaps-rect-points? rect %))))
|
||||
(overlaps-rect-points? rect (:points shape))))
|
||||
|
||||
(defn overlaps?
|
||||
"General case to check for overlapping between shapes and a rectangle"
|
||||
[shape rect]
|
||||
|
@ -291,14 +310,25 @@
|
|||
(update :x - stroke-width)
|
||||
(update :y - stroke-width)
|
||||
(update :width + (* 2 stroke-width))
|
||||
(update :height + (* 2 stroke-width))
|
||||
)]
|
||||
(update :height + (* 2 stroke-width)))]
|
||||
(or (not shape)
|
||||
(let [path? (= :path (:type shape))
|
||||
circle? (= :circle (:type shape))]
|
||||
(and (overlaps-rect-points? rect (:points shape))
|
||||
(or (not path?) (overlaps-path? shape rect))
|
||||
(or (not circle?) (overlaps-ellipse? shape rect)))))))
|
||||
circle? (= :circle (:type shape))
|
||||
text? (= :text (:type shape))]
|
||||
(cond
|
||||
path?
|
||||
(and (overlaps-rect-points? rect (:points shape))
|
||||
(overlaps-path? shape rect))
|
||||
|
||||
circle?
|
||||
(and (overlaps-rect-points? rect (:points shape))
|
||||
(overlaps-ellipse? shape rect))
|
||||
|
||||
text?
|
||||
(overlaps-text? shape rect)
|
||||
|
||||
:else
|
||||
(overlaps-rect-points? rect (:points shape)))))))
|
||||
|
||||
(defn has-point-rect?
|
||||
[rect point]
|
||||
|
|
27
common/src/app/common/geom/shapes/text.cljc
Normal file
27
common/src/app/common/geom/shapes/text.cljc
Normal file
|
@ -0,0 +1,27 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) UXBOX Labs SL
|
||||
|
||||
(ns app.common.geom.shapes.text
|
||||
(:require
|
||||
[app.common.geom.shapes.common :as gco]
|
||||
[app.common.geom.shapes.rect :as gpr]
|
||||
[app.common.geom.shapes.transforms :as gtr]))
|
||||
|
||||
(defn position-data->rect
|
||||
[{:keys [x y width height]}]
|
||||
{:x x
|
||||
:y (- y height)
|
||||
:width width
|
||||
:height height})
|
||||
|
||||
(defn position-data-bounding-box
|
||||
[{:keys [position-data] :as shape}]
|
||||
(let [points (->> position-data
|
||||
(mapcat (comp gpr/rect->points position-data->rect)))
|
||||
transform (gtr/transform-matrix shape)
|
||||
points (gco/transform-points points transform)]
|
||||
(gpr/points->selrect points)))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue