-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback fonts with atlas clearing. #1790
base: master
Are you sure you want to change the base?
Fallback fonts with atlas clearing. #1790
Conversation
and ClearFallbackFonts.
can still sometimes have it's own priorities.
This is only safe to do on recent fontconfig versions.
e3310c2
to
9aaee44
Compare
ReallocAtlases for that since it's aimed at something different.
always true, as intended.
@lhog, @sprunk: Made this the default fallback-fonts PR, and converted the base fallback-fonts to DRAFT to make it more evident. I think the feature is completed only in this branch, so not worth it all the hassle of going through two separate branches. Still, I will be maintaining that one in case you prefer to merge only that for starters. |
Is there a way to tell whether any given string has missing glyphs programmaticaly (after OS and backups are taken into account)? -- OS should have some ascii font even if we clear them all
Spring.ClearFallbackFonts()
assert(false, Spring.AreAnyGlyphsMissing("ASCII"))
-- but other non-latin might be an issue
assert(true, Spring.AreAnyGlyphsMissing("προσταγμα"))
Spring.AddFallbackFont("greek.fnt")
assert(false, Spring.AreAnyGlyphsMissing("προσταγμα"))
assert(true, Spring.AreAnyGlyphsMissing("김정은")) The use case is that I can't really distribute fonts for every random shithole country language in the world, but I can usually assume the people who set that language will have the font: local originalEnglishText = "nuclear launch detected"
local translatedIntoKlingon = Spring.Utilities.I18N(originalEnglishText, "klingon")
local stringToDisplay
if not Spring.AreAnyGlyphsMissing(translatedIntoKlingon) then
-- ok, we didn't distribute the font but presumably klingons have their font installed on their OS
stringToDisplay = translatedIntoKlingon
else
-- otherwise, display something sane (= english) instead of ending up with "���" or "□ □ □"
stringToDisplay = originalEnglishText
end |
Well, yes, sure we could have some code to check that.
The problem with this is then different users will get different fonts selected for that language, and in many cases it won't work good like happening here. Otherwise I believe we can be safe to assume every user will have fonts for their own language. In any case, I'll try to make something, but it likely needs some refactoring as the whole glyph search thing really needs it to be more reusable for cases like that. I'd rather do that reorganization after getting this in, so as to not complicate the PR too much. Also, even if not perfect it would already allow to solve most of the currently pending issues and see what turns out later. If I do see it's feasible without much reorg then I can try to include that asap. |
Nah don't worry about it, there's no hurry. As long as it's feasible and doesn't conflict architecturally with what already exists it's fine. |
rts/Lua/LuaFonts.cpp
Outdated
* but later, on the Update cycle (before other Update and Draw callins). | ||
* | ||
* @function gl.AddFallbackFont | ||
* @string filePath VFS path to the file, for example "fonts/myfont.ttf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean font files not in the VFS (i.e. loose files somewhere on user disk aka VFS.RAW) can't be used? If they can be used, how do I specify which one to use if two are under the same path (one raw and one in the vfs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, tbh I don't know XD. It goes through the same path other fonts use to load as well, basically doing: CFileHandler f(fontPath)
. I'm just reusing that part of the code through CFontTexture::LoadFontFace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not (yet) letting people specify their own VFS mode then add a @remark that it uses the RAW_FIRST vfs mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, didn't use a specific @ tag since I don't see any that can be used here, just added it to the comment for the @param.
Work done
AddFallbackFont(vfspath)
andClearFallbackFonts()
.FontsChanged
callin to signal applications text dlists or other text caches need to be refreshed.Remarks
Added it as DRAFT to avoid accidental merging before #1777. It can be merged at the same time by just merging this PR, or can be merged right after that one.New api
gl.AddFallbackFont(vfspath)
Add a fallback font. First added will have higher priority.
Link to code and inline documentation.
gl.ClearFallbackFonts()
Clear all fallback fonts.
Link to code and inline documentation.
unsynced callin 'FontsChanged'.
This is needed so the game/application can properly react to texture atlases having been changed. Modules usually cook font drawing into display lists, and those need to be cleared when receiving this callin, otherwise previously cooked text fallbacks won't show properly (base glyphs will, since we restore them into the same atlas coordinates).
Testing
You can further play with it by using left mouse button to enable/disable fallback, and writing your own characters into chat.
After
writing with fallback for Noto enabled, then disabling it (note how the fire symbol reverts to the system default), then adding the fallback again. (this uses the new callin to refresh dlists at gui_chat, otherwise it wouldn't refresh properly).