From 035af3c06b0ca707972bbe0d9ce4a46e0013ea7d Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 1 Jul 2026 19:11:08 +0200 Subject: [PATCH] fix(android): fix setting font The previous PR (#16146) introduced a problem with selecting a different font for a keyboard so that we always ended up with not setting the font. This was caused by the font filenames now being a URL (which is necessary because they get processed by the web engine). However, the Android code checks for the existence of the font in order to create the typeface. This only works for local paths. This change checks if a filename is a URL and converts to a local path, thus allowing `File.exists()` to succeed. Follows: #16146 Build-bot: release:android --- .../app/src/main/java/com/keyman/engine/KMManager.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 3ca6f53de0f..dfdd140b69c 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -1637,7 +1637,15 @@ public static Typeface getFontTypeface(Context context, String fontFilename) { return null; } - File file = new File(fontFilename); + // If fontFilename is a URL, replace the asset URL with the app's data directory path + String fontFilePath = fontFilename; + String rootUrl = WebViewUtils.buildAssetUrl(""); + if (fontFilename.startsWith(rootUrl)) { + fontFilePath = fontFilename.replaceFirst(rootUrl, + context.getDir("data", Context.MODE_PRIVATE).toString() + File.separator); + } + + File file = new File(fontFilePath); if (file.exists()) { return Typeface.createFromFile(file); }