Skip to content

fix(android): fix setting font#16188

Open
ermshiperete wants to merge 3 commits into
masterfrom
fix/android/16187_font
Open

fix(android): fix setting font#16188
ermshiperete wants to merge 3 commits into
masterfrom
fix/android/16187_font

Conversation

@ermshiperete

@ermshiperete ermshiperete commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

PR #16146 introduced a problem with selecting a different font as display font 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, which only works for local paths.

This PR modifies and simplifies KMKeyboard.getFontFilename to return the full path, renames KMKeyboard.txtFont and KMKeyboard.oskFont to make it clearer that they contain a path and not a URL.

Also initialize KMKeyboard.oskFontPath with empty string instead of null. This makes it consistent with txtFontPath and with the documented behavior of KMManager.getKeyboardOskFontFilename() (which returns KMKeyboard.oskFontPath).

Follows: #16146
Replaces: #16178
Fixes: #16187
Build-bot: release:android

User Testing

TEST_KEYBOARDHARNESS:

  • install the KeyboardHarness apk from this PR

  • Switch to the longpress '"|5% + keyboard

  • verify that the OSK uses the Code2001 font (compare with screenshot below)

  • type gbqJ and verify that the Code2001 font is used (compare with screenshot)

    image

TEST_KEYMAN:

  • install Keyman for Android apk
  • try different keyboards, verify that the OSK and displayed text look correct

TEST_FV:

  • install FirstVoices Keyboards for Android apk
  • try different keyboards, verify that the OSK and displayed text look correct

@keymanapp-test-bot

keymanapp-test-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

User Test Results

Test specification and instructions

  • TEST_KEYBOARDHARNESS (OPEN)
  • TEST_KEYMAN (OPEN)
  • TEST_FV (OPEN)
Results Template
# Test Results

* **TEST_KEYBOARDHARNESS (OPEN):** notes
* **TEST_KEYMAN (OPEN):** notes
* **TEST_FV (OPEN):** notes

@keymanapp-test-bot keymanapp-test-bot Bot added this to the A19S32 milestone Jul 2, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels Jul 2, 2026
@ermshiperete ermshiperete force-pushed the fix/android/16187_font branch 2 times, most recently from 92edddc to a26d081 Compare July 2, 2026 17:49
@ermshiperete ermshiperete requested review from jahorton and mcdurdin July 2, 2026 17:49
PR #16146 introduced a problem with selecting a different font as
display font 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,
which only works for local paths.

This PR modifies and simplifies `KMKeyboard.getFontFilename` to return the
full path, renames `KMKeyboard.txtFont` and `KMKeyboard.oskFont` to make
it clearer that they contain a path and not a URL.

Also initialize `KMKeyboard.oskFontPath` with empty string instead of
`null`. This makes it consistent with` txtFontPath` and with the
documented behavior of `KMManager.getKeyboardOskFontFilename()` (which
returns `KMKeyboard.oskFontPath`).

Follows: #16146
Fixes: #16187
Build-bot: release:android
@ermshiperete ermshiperete force-pushed the fix/android/16187_font branch from a26d081 to 1191e43 Compare July 2, 2026 17:53
@ermshiperete ermshiperete marked this pull request as ready for review July 2, 2026 17:54
Comment thread android/docs/engine/KMManager/getFontTypeface.md Outdated
Comment thread android/docs/engine/KMManager/getKeyboardOskFontFilename.md Outdated
/**
* Returns the filename without path of the display font of the current keyboard.
*/
private String getKeyboardTextFontFilename() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this getKeyboardTextFontFilenameOnly() because of the legacy of KMManager.getKeyboardTextFontFilename() returning a full path?

Comment on lines +933 to +935
// REVIEW: Do we have to do anything if font is a JSONObject?
// See makeFontObj.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand this question

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In makeFontObj we have this questionable block of code that deals with a font as JSONObject. If that is still needed, then we'll likely have to do something here with a JSONObject as well.

Any suggestion for a better review or todo comment?

Comment on lines +1069 to +1071
// REVIEW: Why do we need the complicated code below? Can this still
// happen, or can we remove it? (see also getFontFilename)
KMLog.LogInfo(TAG, "Got font without font extension: " + font);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue on this to follow up in the future once we have some logging. (Note that LogInfo doesn't go to Sentry though? Can we capture a Sentry event?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogInfo() calls Sentry.captureMessage, so I think it should end up on Sentry.

if (fontFilename.startsWith("http://") || fontFilename.startsWith("https://")
|| fontFilename.startsWith("file://")) {
// Font file is not local, so cannot load Typeface
KMLog.LogError(TAG, "Font file is not local: " + fontFilename);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does LogError log to Sentry?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, also has a Sentry.captureMessage call.

ermshiperete and others added 2 commits July 3, 2026 17:23
Co-authored-by: Marc Durdin <marc@durdin.net>
Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
@keyman-server keyman-server modified the milestones: A19S32, A19S33 Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

bug(android): KeyboardHarness uses wrong font after #16146

3 participants