Merge pull request #6652 from penpot/elenatorro-fix-load-fonts

🐛 Fix fonts initialization
This commit is contained in:
Alejandro Alonso 2025-06-09 09:31:00 +02:00 committed by GitHub
commit d008ea9edd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 67 additions and 54 deletions

View file

@ -189,11 +189,12 @@
(defn- get-string-length [string] (+ (count string) 1))
(defn- store-image
(defn- fetch-image
[id]
(let [buffer (uuid/get-u32 id)
url (cf/resolve-file-media {:id id})]
(->> (http/send! {:method :get
{:key url
:callback #(->> (http/send! {:method :get
:uri url
:response-type :blob})
(rx/map :body)
@ -209,7 +210,7 @@
(aget buffer 1)
(aget buffer 2)
(aget buffer 3))
true))))))
true))))}))
(defn- get-fill-images
[leaf]
@ -227,7 +228,7 @@
(aget buffer 2)
(aget buffer 3))]
(when (zero? cached-image?)
(store-image id))))))
(fetch-image id))))))
(defn set-shape-text-images
[content]
@ -269,7 +270,7 @@
(aget buffer 2)
(aget buffer 3))]
(when (zero? cached-image?)
(store-image id))))
(fetch-image id))))
image-fills))))
(defn set-shape-strokes
@ -308,7 +309,7 @@
(dm/get-prop image :height))
(h/call wasm/internal-module "_add_shape_stroke_fill")
(when (== cached-image? 0)
(store-image id)))
(fetch-image id)))
(some? color)
(do
@ -640,9 +641,10 @@
(swap! languages into (t/get-languages text))
(t/write-shape-text leaves paragraph text))
(recur (inc index))))))
(let [updated-fonts
(-> fonts
(cond-> emoji? (f/add-emoji-font))
(cond-> @emoji? (f/add-emoji-font))
(f/add-noto-fonts @languages))]
(f/store-fonts updated-fonts))))
@ -742,8 +744,6 @@
(set-shape-svg-raw-content (get-static-markup shape)))
(when (some? corners) (set-shape-corners corners))
(when (some? shadows) (set-shape-shadows shadows))
(when (and (= type :text) (some? content))
(set-shape-text content))
(when (= type :text)
(set-shape-grow-type grow-type))
(when (or (ctl/any-layout? shape)
@ -764,16 +764,20 @@
pending)))
(defn process-object
[shape]
(let [pending (set-object [] shape)]
(when-let [pending (seq pending)]
(defn process-pending
[pending]
(when-let [pending (-> (d/index-by :key :callback pending) vals)]
(->> (rx/from pending)
(rx/mapcat identity)
(rx/mapcat (fn [callback] (callback)))
(rx/reduce conj [])
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects")))))))
(request-render "set-objects"))))))
(defn process-object
[shape]
(let [pending (set-object [] shape)]
(process-pending pending)))
(defn set-objects
[objects]
@ -790,13 +794,7 @@
(perf/end-measure "set-objects")
(clear-drawing-cache)
(request-render "set-objects")
(when-let [pending (seq pending)]
(->> (rx/from pending)
(rx/mapcat identity)
(rx/reduce conj [])
(rx/subs! (fn [_]
(clear-drawing-cache)
(request-render "set-objects")))))))
(process-pending pending)))
(defn set-structure-modifiers
[entries]

View file

@ -94,13 +94,14 @@
fallback?)
true))
(defn- store-font-url
(defn- fetch-font
[font-data font-url emoji? fallback?]
(->> (http/send! {:method :get
{:key font-url
:callback #(->> (http/send! {:method :get
:uri font-url
:response-type :buffer})
(rx/map (fn [{:keys [body]}]
(store-font-buffer font-data body emoji? fallback?)))))
(store-font-buffer font-data body emoji? fallback?))))})
(defn- google-font-ttf-url
[font-id font-variant-id]
@ -131,9 +132,10 @@
(aget id-buffer 2)
(aget id-buffer 3)
(:weight font-data)
(:style font-data)))]
(:style font-data)
emoji?))]
(when-not font-stored?
(store-font-url font-data uri emoji? fallback?)))))
(fetch-font font-data uri emoji? fallback?)))))
(defn serialize-font-style
[font-style]

View file

@ -148,7 +148,7 @@
(h/call wasm/internal-module "_set_shape_text_content"))
(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]")
(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]|[\u2600-\u27BF]")
(def ^:private unicode-ranges
{:japanese #"[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]"
@ -198,7 +198,7 @@
(defn contains-emoji? [text]
(boolean (re-find emoji-pattern text)))
(boolean (some #(re-find emoji-pattern %) (seq text))))
(defn get-languages [text]
(reduce-kv (fn [result lang pattern]

View file

@ -66,7 +66,7 @@ impl FontStore {
is_emoji: bool,
is_fallback: bool,
) -> Result<(), String> {
if self.has_family(&family) {
if self.has_family(&family, is_emoji) {
return Ok(());
}
@ -92,9 +92,14 @@ impl FontStore {
Ok(())
}
pub fn has_family(&self, family: &FontFamily) -> bool {
let serialized = format!("{}", family);
self.font_provider.family_names().any(|x| x == serialized)
pub fn has_family(&self, family: &FontFamily, is_emoji: bool) -> bool {
let alias = format!("{}", family);
let font_name = if is_emoji {
DEFAULT_EMOJI_FONT
} else {
alias.as_str()
};
self.font_provider.family_names().any(|x| x == font_name)
}
pub fn get_fallback(&self) -> &HashSet<String> {

View file

@ -31,11 +31,19 @@ pub extern "C" fn store_font(
}
#[no_mangle]
pub extern "C" fn is_font_uploaded(a: u32, b: u32, c: u32, d: u32, weight: u32, style: u8) -> bool {
pub extern "C" fn is_font_uploaded(
a: u32,
b: u32,
c: u32,
d: u32,
weight: u32,
style: u8,
is_emoji: bool,
) -> bool {
with_state!(state, {
let id = uuid_from_u32_quartet(a, b, c, d);
let family = FontFamily::new(id, weight, style.into());
let res = state.render_state().fonts().has_family(&family);
let res = state.render_state().fonts().has_family(&family, is_emoji);
res
})