mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 04:11:44 +02:00
Add font rendering to text shape.
This commit is contained in:
parent
22060dbe76
commit
4499dfc787
5 changed files with 99 additions and 46 deletions
|
@ -52,6 +52,12 @@
|
||||||
:x2 [sc/integer]
|
:x2 [sc/integer]
|
||||||
:y2 [sc/integer]})
|
:y2 [sc/integer]})
|
||||||
|
|
||||||
|
(def ^:static +shape-font-attrs-schema+
|
||||||
|
{:family [sc/string]
|
||||||
|
:style [sc/string]
|
||||||
|
:weight [sc/string]
|
||||||
|
:size [sc/number]})
|
||||||
|
|
||||||
(def ^:static +shape-radius-attrs-schema+
|
(def ^:static +shape-radius-attrs-schema+
|
||||||
{:rx [sc/integer]
|
{:rx [sc/integer]
|
||||||
:ry [sc/integer]})
|
:ry [sc/integer]})
|
||||||
|
@ -159,6 +165,19 @@
|
||||||
(when color {:fill color})
|
(when color {:fill color})
|
||||||
(when opacity {:opacity opacity})))))
|
(when opacity {:opacity opacity})))))
|
||||||
|
|
||||||
|
(defn update-font-attrs
|
||||||
|
[sid {:keys [family style weight size] :as opts}]
|
||||||
|
(sc/validate! +shape-font-attrs-schema+ opts)
|
||||||
|
(reify
|
||||||
|
rs/UpdateEvent
|
||||||
|
(-apply-update [_ state]
|
||||||
|
(update-in state [:shapes-by-id sid :font]
|
||||||
|
merge
|
||||||
|
(when family {:family family})
|
||||||
|
(when style {:style style})
|
||||||
|
(when weight {:weight weight})
|
||||||
|
(when size {:size size})))))
|
||||||
|
|
||||||
(defn update-stroke-attrs
|
(defn update-stroke-attrs
|
||||||
[sid {:keys [color opacity type width] :as opts}]
|
[sid {:keys [color opacity type width] :as opts}]
|
||||||
(sc/validate! +shape-stroke-attrs-schema+ opts)
|
(sc/validate! +shape-stroke-attrs-schema+ opts)
|
||||||
|
|
|
@ -8,24 +8,35 @@
|
||||||
(ns uxbox.library
|
(ns uxbox.library
|
||||||
(:require [uxbox.library.colors :as colors]
|
(:require [uxbox.library.colors :as colors]
|
||||||
[uxbox.library.icons :as icons]
|
[uxbox.library.icons :as icons]
|
||||||
|
[uxbox.library.fonts :as fonts]
|
||||||
[uxbox.util.data :refer (index-by-id)]))
|
[uxbox.util.data :refer (index-by-id)]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Colors
|
;; Colors
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:static +color-collections+
|
(def ^:const +color-collections+
|
||||||
colors/+collections+)
|
colors/+collections+)
|
||||||
|
|
||||||
(def ^:static +color-collections-by-id+
|
(def ^:const +color-collections-by-id+
|
||||||
(index-by-id colors/+collections+))
|
(index-by-id colors/+collections+))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Icons
|
;; Icons
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:static +icon-collections+
|
(def ^:const +icon-collections+
|
||||||
icons/+collections+)
|
icons/+collections+)
|
||||||
|
|
||||||
(def ^:static +icon-collections-by-id+
|
(def ^:const +icon-collections-by-id+
|
||||||
(index-by-id icons/+collections+))
|
(index-by-id icons/+collections+))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Fonts
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(def ^:const +fonts+
|
||||||
|
fonts/+collections+)
|
||||||
|
|
||||||
|
(def ^:const +fonts-by-id+
|
||||||
|
(index-by-id fonts/+collections+))
|
||||||
|
|
|
@ -105,7 +105,6 @@
|
||||||
local (:rum/local own)]
|
local (:rum/local own)]
|
||||||
(html
|
(html
|
||||||
[:g.shape {:class (when selected? "selected")
|
[:g.shape {:class (when selected? "selected")
|
||||||
;; :on-double-click #(on-double-click own %)
|
|
||||||
:ref "main"
|
:ref "main"
|
||||||
:on-mouse-down on-mouse-down
|
:on-mouse-down on-mouse-down
|
||||||
:on-mouse-up on-mouse-up}
|
:on-mouse-up on-mouse-up}
|
||||||
|
@ -135,8 +134,16 @@
|
||||||
[:font-size])
|
[:font-size])
|
||||||
|
|
||||||
(defn- build-style
|
(defn- build-style
|
||||||
[{:keys [font-size]}]
|
[{:keys [font]}]
|
||||||
(merge {} (when font-size {:fontSize (str font-size "px")})))
|
(let [{:keys [family weight style size]
|
||||||
|
:or {family "sourcesanspro"
|
||||||
|
weight "normal"
|
||||||
|
style "normal"
|
||||||
|
size 16}} font]
|
||||||
|
{:fontSize (str size "px")
|
||||||
|
:fontFamily family
|
||||||
|
:fontWeight weight
|
||||||
|
:fontStyle style}))
|
||||||
|
|
||||||
(defmethod uusc/render-shape :builtin/text
|
(defmethod uusc/render-shape :builtin/text
|
||||||
[{:keys [id x1 y1 x2 y2 content drawing? editing?] :as shape}]
|
[{:keys [id x1 y1 x2 y2 content drawing? editing?] :as shape}]
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
;; Lenses
|
;; Lenses
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;; TODO: move this lense under library ns.
|
||||||
|
|
||||||
(def ^:static ^:private collections-by-id-l
|
(def ^:static ^:private collections-by-id-l
|
||||||
(-> (comp (l/in [:colors-by-id])
|
(-> (comp (l/in [:colors-by-id])
|
||||||
(ul/merge library/+color-collections-by-id+))
|
(ul/merge library/+color-collections-by-id+))
|
||||||
|
|
|
@ -498,32 +498,43 @@
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(defmethod -render-menu :menu/text
|
(defmethod -render-menu :menu/text
|
||||||
[menu own shape]
|
[menu own {:keys [font] :as shape}]
|
||||||
(letfn [(on-font-family-change [event]
|
(letfn [(on-font-family-change [event]
|
||||||
(let [value (dom/event->value event)
|
(let [value (dom/event->value event)
|
||||||
sid (:id shape)]
|
sid (:id shape)
|
||||||
(println "on-font-family-change" value)))
|
params {:family (read-string value)
|
||||||
|
:weight "normal"
|
||||||
|
:style "normal"}]
|
||||||
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
(on-font-size-change [event]
|
(on-font-size-change [event]
|
||||||
(let [value (dom/event->value event)
|
(let [value (dom/event->value event)
|
||||||
value (parse-int value)
|
params {:size (parse-int value)}
|
||||||
sid (:id shape)]
|
sid (:id shape)]
|
||||||
(println "on-font-size-change" value)))
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
(on-font-weight-change [event]
|
(on-font-style-change [event]
|
||||||
(let [value (dom/event->value event)
|
(let [value (dom/event->value event)
|
||||||
value (read-string value)
|
[weight style] (read-string value)
|
||||||
sid (:id shape)]
|
sid (:id shape)
|
||||||
(println "on-font-size-change" value)))]
|
params {:style style
|
||||||
|
:weight weight}]
|
||||||
|
(rs/emit! (uds/update-font-attrs sid params))))]
|
||||||
|
(let [{:keys [family style weight size]
|
||||||
|
:or {family "sourcesanspro"
|
||||||
|
style "normal"
|
||||||
|
weight "normal"
|
||||||
|
size 16}} font
|
||||||
|
styles (:styles (first (filter #(= (:id %) family) library/+fonts+)))]
|
||||||
(html
|
(html
|
||||||
[:div.element-set {:key (str (:id menu))}
|
[:div.element-set {:key (str (:id menu))}
|
||||||
[:div.element-set-title (:name menu)]
|
[:div.element-set-title (:name menu)]
|
||||||
[:div.element-set-content
|
[:div.element-set-content
|
||||||
[:span "Font family"]
|
[:span "Font family"]
|
||||||
[:div.row-flex
|
[:div.row-flex
|
||||||
[:select.input-select {:value (:font-family shape "sans-serif")
|
[:select.input-select {:value (pr-str family)
|
||||||
:on-change on-font-family-change}
|
:on-change on-font-family-change}
|
||||||
[:option {:value "sans-serif"} "Sans Serif"]
|
(for [font library/+fonts+]
|
||||||
[:option {:value "monospace"} "Monospace"]]]
|
[:option {:value (pr-str (:id font))
|
||||||
|
:key (:id font)} (:name font)])]]
|
||||||
[:span "Size and Weight"]
|
[:span "Size and Weight"]
|
||||||
[:div.row-flex
|
[:div.row-flex
|
||||||
[:input.input-text
|
[:input.input-text
|
||||||
|
@ -531,19 +542,22 @@
|
||||||
:type "number"
|
:type "number"
|
||||||
:min "0"
|
:min "0"
|
||||||
:max "200"
|
:max "200"
|
||||||
:value (:font-size shape "16")
|
:value size
|
||||||
:on-change on-font-size-change}]
|
:on-change on-font-size-change}]
|
||||||
[:select.input-select {:value (:font-weight shape ":normal")
|
[:select.input-select {:value (pr-str [weight style])
|
||||||
:on-change on-font-weight-change}
|
:on-change on-font-style-change}
|
||||||
[:option {:value ":normal"} "Normal"]
|
(for [style styles
|
||||||
[:option {:value ":bold"} "Solid"]]]
|
:let [data (mapv #(get style %) [:weight :style])]]
|
||||||
|
[:option {:value (pr-str data)
|
||||||
|
:key (:name style)} (:name style)])]]
|
||||||
|
|
||||||
[:span "Text align"]
|
[:span "Text align"]
|
||||||
[:div.row-flex.align-icons
|
[:div.row-flex.align-icons
|
||||||
[:span.current i/align-left]
|
[:span.current i/align-left]
|
||||||
[:span i/align-right]
|
[:span i/align-right]
|
||||||
[:span i/align-center]
|
[:span i/align-center]
|
||||||
[:span i/align-justify]
|
[:span i/align-justify]
|
||||||
]]])))
|
]]]))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Components
|
;; Components
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue