Skip to content

Commit

Permalink
fix editor
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed May 7, 2024
1 parent fed7138 commit 21e1ca4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 17 additions & 11 deletions editor/src/clj/editor/font.clj
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@
:defold)
:distance-field))

(defn- measure-line [is-monospaced glyphs text-tracking ^String line]
(defn- measure-line [is-monospaced padding glyphs text-tracking ^String line]
(let [w (transduce (comp
(map #(:advance (glyphs (int %)) 0.0))
(interpose text-tracking))
+
0.0
line)
len (.length line)]
(if (not is-monospaced)
(if is-monospaced
(+ w padding)
(if-let [last (get glyphs (and (pos? len) (int (.charAt line (dec len)))))]
(- (+ w (:left-bearing last) (:width last)) (:advance last))
w)
w)))
w))))

(defn- split-text [glyphs ^String text line-break? max-width text-tracking]
(if line-break?
Expand Down Expand Up @@ -276,7 +276,7 @@
line-height (+ (:max-descent font-map) (:max-ascent font-map))
text-tracking (* line-height text-tracking)
lines (split-text glyphs text line-break? max-width text-tracking)
line-widths (map (partial measure-line (:is-monospaced font-map) glyphs text-tracking) lines)
line-widths (map (partial measure-line (:is-monospaced font-map) (:padding font-map) glyphs text-tracking) lines)
max-width (reduce max 0 line-widths)]
[max-width (* line-height (+ 1 (* text-leading (dec (count lines)))))]))))

Expand All @@ -303,7 +303,7 @@
line-height (+ (:max-descent font-map) (:max-ascent font-map))
text-tracking (* line-height text-tracking)
lines (split-text glyphs text line-break? max-width text-tracking)
line-widths (mapv (partial measure-line (:is-monospaced font-map) glyphs text-tracking) lines)
line-widths (mapv (partial measure-line (:is-monospaced font-map) (:padding font-map) glyphs text-tracking) lines)
max-width (reduce max 0 line-widths)]
(assoc text-layout
:width max-width
Expand Down Expand Up @@ -406,14 +406,20 @@
face-mask (if layer-mask-enabled
[1 0 0]
[1 1 1])
shadow-offset {:x (:shadow-x font-map), :y (:shadow-y font-map)}
shadow-offset {:x (if (:is-monospaced font-map)
(- (:shadow-x font-map) (* (:padding font-map) 0.5))
(:shadow-x font-map))
:y (:shadow-y font-map)}
alpha (:alpha font-map)
outline-alpha (:outline-alpha font-map)
shadow-alpha (:shadow-alpha font-map)]
;; Output glyphs per layer in back to front, if enabled but always output face layer.
shadow-alpha (:shadow-alpha font-map)
font-offset {:x (if (:is-monospaced font-map)
(- 0 (* (:padding font-map) 0.5))
0)
:y 0}]
(when (and layer-mask-enabled shadow-enabled) (fill-vertex-buffer-quads vbuf text-entries put-pos-uv-fn line-height char->glyph glyph-cache put-glyph-quad-fn [0 0 1] shadow-offset alpha outline-alpha shadow-alpha))
(when (and layer-mask-enabled outline-enabled) (fill-vertex-buffer-quads vbuf text-entries put-pos-uv-fn line-height char->glyph glyph-cache put-glyph-quad-fn [0 1 0] nil alpha outline-alpha shadow-alpha))
(fill-vertex-buffer-quads vbuf text-entries put-pos-uv-fn line-height char->glyph glyph-cache put-glyph-quad-fn face-mask nil alpha outline-alpha shadow-alpha)))
(when (and layer-mask-enabled outline-enabled) (fill-vertex-buffer-quads vbuf text-entries put-pos-uv-fn line-height char->glyph glyph-cache put-glyph-quad-fn [0 1 0] font-offset alpha outline-alpha shadow-alpha))
(fill-vertex-buffer-quads vbuf text-entries put-pos-uv-fn line-height char->glyph glyph-cache put-glyph-quad-fn face-mask font-offset alpha outline-alpha shadow-alpha)))

(defn gen-vertex-buffer
[^GL2 gl {:keys [type font-map] :as font-data} text-entries]
Expand Down
9 changes: 6 additions & 3 deletions editor/src/clj/editor/pipeline/fontc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@
:cache-cell-max-ascent max-ascent
:glyph-channels channel-count
:glyph-data (ByteString/copyFrom glyph-data-bank)
:is-monospaced is-monospaced})))
:is-monospaced is-monospaced
:padding padding})))

(defn- do-blend-rasters [^Raster src ^Raster dst-in ^WritableRaster dst-out]
(let [width (min (.getWidth src) (.getWidth dst-in) (.getWidth dst-out))
Expand Down Expand Up @@ -504,7 +505,8 @@
:alpha (:alpha font-desc)
:outline-alpha (:outline-alpha font-desc)
:shadow-alpha (:shadow-alpha font-desc)
:is-monospaced is-monospaced}))
:is-monospaced is-monospaced
:padding padding}))

(defn- calculate-ttf-distance-field-edge-limit [^double width ^double spread ^double edge]
(let [sdf-limit-value (- (/ width spread))]
Expand Down Expand Up @@ -697,7 +699,8 @@
:alpha (:alpha font-desc)
:outline-alpha (:outline-alpha font-desc)
:shadow-alpha (:shadow-alpha font-desc)
:is-monospaced is-monospaced}))
:is-monospaced is-monospaced
:padding padding}))

(defn compile-font [font-desc font-resource resolver]
(let [font-ext (resource/type-ext font-resource)]
Expand Down

0 comments on commit 21e1ca4

Please sign in to comment.