fix(android): differentiate between fontPath and fontUrl in Keyman Engine for Android#16188
Conversation
92edddc to
a26d081
Compare
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
a26d081 to
1191e43
Compare
| /** | ||
| * Returns the filename without path of the display font of the current keyboard. | ||
| */ | ||
| private String getKeyboardTextFontFilename() { |
There was a problem hiding this comment.
Should we call this getKeyboardTextFontFilenameOnly() because of the legacy of KMManager.getKeyboardTextFontFilename() returning a full path?
| // REVIEW: Do we have to do anything if font is a JSONObject? | ||
| // See makeFontObj. | ||
|
|
There was a problem hiding this comment.
I don't really understand this question
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
After some spelunking, came to the conclusion that the input parameter is always a filename, not a JSON object. So we can hopefully clean that up a bit.
| // 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); |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
LogInfo() calls Sentry.captureMessage, so I think it should end up on Sentry.
There was a problem hiding this comment.
I think we concluded that this code path is not relevant, so we should clean up in a follow-up PR. We can run a set of user tests to verify that this doesn't break existing users.
Co-authored-by: Marc Durdin <marc@durdin.net> Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
This addresses a code review comment.
mcdurdin
left a comment
There was a problem hiding this comment.
LGTM, with some cleanup as a follow-up PR or two
| JSONObject jDisplayFont = makeFontObject(kFont, packageID); | ||
| JSONObject jOskFont = makeFontObject(kOskFont, packageID); | ||
|
|
||
| txtFont = getFontFilename(jDisplayFont); | ||
| oskFont = getFontFilename(jOskFont); | ||
| txtFontPath = getFontFilename(kFont, packageID); | ||
| oskFontPath = getFontFilename(kOskFont, packageID); |
There was a problem hiding this comment.
Let's try and make these font names consistent - we have font, displayfont, txtfont, oskfont, textfont -- but only two conceptual fonts -- TextFont and OskFont. For a follow-up cleanup PR.
| private String getPackageRootUrl(String packageID) { | ||
| if (packageID.equals(KMManager.KMDefault_UndefinedPackageID)) { | ||
| return getDataRootUrl() + KMManager.KMDefault_UndefinedPackageID + "/"; | ||
| } | ||
| return getDataRootUrl() + KMManager.KMDefault_AssetPackages + "/" + packageID + "/"; | ||
| } | ||
|
|
||
| private String getPackageRootPath(String packageID) { |
There was a problem hiding this comment.
Can we add comments on the difference between RootUrl and RootPath for future maintainers?
| if (FileUtils.hasFontExtension(font)) { | ||
| String fontRoot = KMManager.isDefaultFont(font) ? getDataRootPath() : getPackageRootPath(packageID); | ||
| return fontRoot + font; | ||
| } |
There was a problem hiding this comment.
Can we reverse this, so it becomes a validation precondition instead?
| if (FileUtils.hasFontExtension(font)) { | |
| String fontRoot = KMManager.isDefaultFont(font) ? getDataRootPath() : getPackageRootPath(packageID); | |
| return fontRoot + font; | |
| } | |
| if (!FileUtils.hasFontExtension(font)) { | |
| // QUESTION: do we log this? | |
| return ""; | |
| } | |
| String fontRoot = KMManager.isDefaultFont(font) ? getDataRootPath() : getPackageRootPath(packageID); | |
| return fontRoot + font; |
| // REVIEW: Do we have to do anything if font is a JSONObject? | ||
| // See makeFontObj. | ||
|
|
There was a problem hiding this comment.
After some spelunking, came to the conclusion that the input parameter is always a filename, not a JSON object. So we can hopefully clean that up a bit.
| // 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); |
There was a problem hiding this comment.
I think we concluded that this code path is not relevant, so we should clean up in a follow-up PR. We can run a set of user tests to verify that this doesn't break existing users.
Test Specs
Test Results
|
Co-authored-by: Marc Durdin <marc@durdin.net>
|
Follow-up-PR: #16211 |
This change renames the font variable names so that they match the two conceptual fonts we have. Also remove obsolete code that dealt with the `font` parameter being a JSON object instead of a string containing the font filename. Having the `font` parameter containing a JSON object was legacy code that won't happen with current Keyman versions. Follow-up-of: #16188 Build-bot: release:android
|
TEST_KEYBOARDHARNESS SKIP blocked because keyboardharness does not install |
This change renames the font variable names so that they match the two conceptual fonts we have. Also remove obsolete code that dealt with the `font` parameter being a JSON object instead of a string containing the font filename. Having the `font` parameter containing a JSON object was legacy code that won't happen with current Keyman versions. Follow-up-of: #16188 Build-bot: release:android
|
Changes in this pull request will be available for download in Keyman version 19.0.252-alpha |
chore(android): cleanup font variable names, remove obsolete code This change renames the font variable names so that they match the two conceptual fonts we have. Also remove obsolete code that dealt with the `font` parameter being a JSON object instead of a string containing the font filename. Having the `font` parameter containing a JSON object was legacy code that won't happen with current Keyman versions. Follow-up-of: #16188
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.getFontFilenameto return the full path, renamesKMKeyboard.txtFontandKMKeyboard.oskFontto make it clearer that they contain a path and not a URL.Also initialize
KMKeyboard.oskFontPathwith empty string instead ofnull. This makes it consistent withtxtFontPathand with the documented behavior ofKMManager.getKeyboardOskFontFilename()(which returnsKMKeyboard.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% +keyboardverify that the OSK uses the Code2001 font (compare with screenshot below)
type gbqJ and verify that the Code2001 font is used (compare with screenshot)
TEST_KEYMAN:
TEST_FV:
.