mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix emoji font not being used as fallback in text editor dom
This commit is contained in:
@@ -269,6 +269,11 @@
|
|||||||
"bottom" "flex-end"
|
"bottom" "flex-end"
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
|
(defn- font-family-from-font-id [font-id]
|
||||||
|
(if (str/includes? font-id "gfont-noto-sans")
|
||||||
|
(let [lang (str/replace font-id #"gfont\-noto\-sans\-" "")]
|
||||||
|
(if (>= (count lang) 3) (str/capital lang) (str/upper lang)))
|
||||||
|
"Noto Color Emoji"))
|
||||||
|
|
||||||
;; Text Editor Wrapper
|
;; Text Editor Wrapper
|
||||||
;; This is an SVG element that wraps the HTML editor.
|
;; This is an SVG element that wraps the HTML editor.
|
||||||
@@ -281,11 +286,10 @@
|
|||||||
[{:keys [shape modifiers canvas-ref] :as props} _]
|
[{:keys [shape modifiers canvas-ref] :as props} _]
|
||||||
(let [shape-id (dm/get-prop shape :id)
|
(let [shape-id (dm/get-prop shape :id)
|
||||||
modifiers (dm/get-in modifiers [shape-id :modifiers])
|
modifiers (dm/get-in modifiers [shape-id :modifiers])
|
||||||
fallback-fonts (wasm.api/get-fallback-fonts (:content shape) false)
|
|
||||||
|
fallback-fonts (wasm.api/fonts-from-text-content (:content shape) false)
|
||||||
fallback-families (map (fn [font]
|
fallback-families (map (fn [font]
|
||||||
(let [lang (str/replace (:font-id font) #"gfont\-noto\-sans\-" "")
|
(font-family-from-font-id (:font-id font))) fallback-fonts)
|
||||||
lang (if (>= (count lang) 3) (str/capital lang) (str/upper lang))]
|
|
||||||
(str/concat "\"Noto Sans " lang "\""))) fallback-fonts)
|
|
||||||
|
|
||||||
clip-id (dm/str "text-edition-clip" shape-id)
|
clip-id (dm/str "text-edition-clip" shape-id)
|
||||||
|
|
||||||
|
|||||||
@@ -785,7 +785,7 @@
|
|||||||
hidden)))
|
hidden)))
|
||||||
shadows))
|
shadows))
|
||||||
|
|
||||||
(defn get-fallback-fonts [content write-text-content?]
|
(defn fonts-from-text-content [content fallback-fonts-only?]
|
||||||
(let [paragraph-set (first (get content :children))
|
(let [paragraph-set (first (get content :children))
|
||||||
paragraphs (get paragraph-set :children)
|
paragraphs (get paragraph-set :children)
|
||||||
total (count paragraphs)]
|
total (count paragraphs)]
|
||||||
@@ -806,7 +806,7 @@
|
|||||||
langs (t/collect-used-languages langs text)]
|
langs (t/collect-used-languages langs text)]
|
||||||
|
|
||||||
;; FIXME: this should probably be somewhere else
|
;; FIXME: this should probably be somewhere else
|
||||||
(when write-text-content? (t/write-shape-text spans paragraph text))
|
(when fallback-fonts-only? (t/write-shape-text spans paragraph text))
|
||||||
|
|
||||||
(recur (inc index)
|
(recur (inc index)
|
||||||
emoji?
|
emoji?
|
||||||
@@ -818,7 +818,7 @@
|
|||||||
(f/add-noto-fonts langs))
|
(f/add-noto-fonts langs))
|
||||||
fallback-fonts (filter #(get % :is-fallback) updated-fonts)]
|
fallback-fonts (filter #(get % :is-fallback) updated-fonts)]
|
||||||
|
|
||||||
fallback-fonts)))))
|
(if fallback-fonts-only? updated-fonts fallback-fonts))))))
|
||||||
|
|
||||||
(defn set-shape-text-content
|
(defn set-shape-text-content
|
||||||
"This function sets shape text content and returns a stream that loads the needed fonts asynchronously"
|
"This function sets shape text content and returns a stream that loads the needed fonts asynchronously"
|
||||||
@@ -829,7 +829,7 @@
|
|||||||
(set-shape-vertical-align (get content :vertical-align))
|
(set-shape-vertical-align (get content :vertical-align))
|
||||||
|
|
||||||
(let [fonts (fonts/get-content-fonts content)
|
(let [fonts (fonts/get-content-fonts content)
|
||||||
fallback-fonts (get-fallback-fonts content true)
|
fallback-fonts (fonts-from-text-content content true)
|
||||||
all-fonts (concat fonts fallback-fonts)
|
all-fonts (concat fonts fallback-fonts)
|
||||||
result (f/store-fonts shape-id all-fonts)]
|
result (f/store-fonts shape-id all-fonts)]
|
||||||
(f/load-fallback-fonts-for-editor! fallback-fonts)
|
(f/load-fallback-fonts-for-editor! fallback-fonts)
|
||||||
|
|||||||
@@ -283,7 +283,8 @@
|
|||||||
:font-variant-id "regular"
|
:font-variant-id "regular"
|
||||||
:style 0
|
:style 0
|
||||||
:weight 400
|
:weight 400
|
||||||
:is-emoji true}))
|
:is-emoji true
|
||||||
|
:is-fallback true}))
|
||||||
|
|
||||||
(def noto-fonts
|
(def noto-fonts
|
||||||
{:japanese {:font-id "gfont-noto-sans-jp" :font-variant-id "regular" :style 0 :weight 400 :is-fallback true}
|
{:japanese {:font-id "gfont-noto-sans-jp" :font-variant-id "regular" :style 0 :weight 400 :is-fallback true}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@
|
|||||||
(str v "px")
|
(str v "px")
|
||||||
|
|
||||||
(and (= k :font-family) (seq v))
|
(and (= k :font-family) (seq v))
|
||||||
(str/concat (str/quote v) ", var(--fallback-families)")
|
;; pick just first family, avoid quoting twice, and add var(--fallback-families)
|
||||||
|
(str/concat (str/quote (str/unquote (first (str/split v ",")))) ", var(--fallback-families)")
|
||||||
|
|
||||||
:else
|
:else
|
||||||
v))
|
v))
|
||||||
|
|||||||
@@ -19,6 +19,23 @@ const DEFAULT_FONT_WEIGHT = "400";
|
|||||||
* @param {string} value
|
* @param {string} value
|
||||||
*/
|
*/
|
||||||
export function sanitizeFontFamily(value) {
|
export function sanitizeFontFamily(value) {
|
||||||
|
// NOTE: This is a fix for a bug introduced earlier that have might modified the font-family in the model
|
||||||
|
// adding extra double quotes.
|
||||||
|
if (value && value.startsWith('""')) {
|
||||||
|
//remove the first and last quotes
|
||||||
|
value = value.slice(1).replace(/"([^"]*)$/, "$1");
|
||||||
|
|
||||||
|
// remove quotes from font-family in 1-word font-families
|
||||||
|
// and repeated values
|
||||||
|
value = [
|
||||||
|
...new Set(
|
||||||
|
value
|
||||||
|
.split(", ")
|
||||||
|
.map((x) => (x.includes(" ") ? x : x.replace(/"/g, ""))),
|
||||||
|
),
|
||||||
|
].join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
if (!value || value === "") {
|
if (!value || value === "") {
|
||||||
return "var(--fallback-families)";
|
return "var(--fallback-families)";
|
||||||
} else if (value.endsWith(" var(--fallback-families)")) {
|
} else if (value.endsWith(" var(--fallback-families)")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user