penpot/common/test/common_tests/fonts_test.cljs
Belén Albeza 41d95abc5c
🐛 Fix math symbols rendered as boxes in the new render engine (#12471)
Noto Sans Symbols lacks most arrows and math operators. Fall back to
Noto Sans Math for them, and to Noto Sans for letterlike symbols.

Closes #12469

AI-assisted-by: claude-opus-5-5
2026-10-20 14:09:01 +02:00

38 lines
1.6 KiB
Clojure
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;; 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) KALEIDOS SUBSIDIARY SL
(ns common-tests.fonts-test
(:require
[app.common.fonts :as cfnt]
[clojure.test :as t]))
(defn- fallback-font-ids
[text]
(->> (cfnt/collect-used-languages #{} text)
(cfnt/add-noto-fonts #{})
(into #{} (map :font-id))))
(t/deftest math-symbols-use-noto-sans-math
(t/testing "arrows"
(t/is (contains? (fallback-font-ids "↳") "gfont-noto-sans-math"))
(t/is (contains? (fallback-font-ids "⇒") "gfont-noto-sans-math")))
(t/testing "mathematical operators"
(t/is (contains? (fallback-font-ids "∀x ∈ A") "gfont-noto-sans-math"))
(t/is (contains? (fallback-font-ids "a ≠ b") "gfont-noto-sans-math")))
(t/testing "supplemental arrows and operators"
(t/is (contains? (fallback-font-ids "⟹") "gfont-noto-sans-math"))
(t/is (contains? (fallback-font-ids "⤴") "gfont-noto-sans-math"))
(t/is (contains? (fallback-font-ids "⨁") "gfont-noto-sans-math"))))
(t/deftest letterlike-symbols-use-noto-sans
(t/is (contains? (fallback-font-ids "x ∈ ℝ") "gfont-noto-sans"))
(t/is (contains? (fallback-font-ids "20 ℃") "gfont-noto-sans"))
(t/is (contains? (fallback-font-ids "Penpot™") "gfont-noto-sans")))
(t/deftest plain-text-does-not-use-noto-sans-math
(t/is (not (contains? (fallback-font-ids "Hello world") "gfont-noto-sans-math")))
(t/is (not (contains? (fallback-font-ids "★ ☀") "gfont-noto-sans-math"))))