Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd9790b
Mechanism to define priority fallback fonts through lua AddFallbackFont
saurtron Nov 18, 2024
3a65eee
LDoc documentation for AddFallbackFont and ClearFallbackFonts.
saurtron Nov 18, 2024
a67a9fd
First search game fonts and then system fonts as otherwise fontconfig
saurtron Nov 19, 2024
1241ccc
Don't add or clear fallback fonts if fontconfig is disabled for any
saurtron Nov 27, 2024
a3d0cfa
Don't return false on a void function.
saurtron Nov 27, 2024
2e4fb11
Merge branch 'master' into lua-fallback-fonts
saurtron Dec 2, 2024
a1c7135
Don't try to destroy gameFontSet and fallbackPattern if null.
saurtron Dec 2, 2024
74ff5f4
Call CanUseFontConfig instead of UseFontConfig inside new methods.
saurtron Dec 2, 2024
b6352a2
Refresh glyph atlases after adding or clearing fallback fonts.
saurtron Nov 30, 2024
0fe6786
Remove some extraneous extra lines.
saurtron Nov 30, 2024
7e30cae
Clear kerning precached information too.
saurtron Nov 30, 2024
8be1855
Remove fast glyph cache clear mode, and all clearMode control from lua.
saurtron Dec 1, 2024
9aaee44
Remove clearGlyphs parameter also from ClearGlyphMode.
saurtron Dec 1, 2024
5713e71
return after #endif so HEADLESS doesn't have a warning.
saurtron Dec 2, 2024
51c3aef
FontsUpdated was renamed to FontsChanged, update comments.
saurtron Dec 2, 2024
2d88bf6
Merge branch 'master' into lua-fallback-fonts
saurtron Dec 7, 2024
e31eb5d
Merge branch 'lua-fallback-fonts' into lua-fallback-fonts-with-atlasc…
saurtron Dec 7, 2024
8cf8cc3
Refactor atlas clearing into a separate method and don't use
saurtron Dec 7, 2024
f85dff1
Realloc before dispose.
saurtron Dec 7, 2024
36783c9
Make CFontTexture::ClearGlyphs return the changed status instead of
saurtron Dec 9, 2024
2a11114
Add comment about vfs access use in use by AddFallbackFont.
saurtron Dec 12, 2024
6f5da57
Rename fallbackPattern to basePattern.
saurtron Dec 14, 2024
2fc1dbc
Merge branch 'lua-fallback-fonts' into lua-fallback-fonts-with-atlasc…
saurtron Dec 14, 2024
dfba0b2
Rename badly named variable.
saurtron Dec 14, 2024
3fcc1a4
Merge branch 'lua-fallback-fonts' into lua-fallback-fonts-with-atlasc…
saurtron Dec 14, 2024
d9ce3a1
Merge branch 'master' into lua-fallback-fonts-with-atlasclear
saurtron Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cont/LuaUI/callins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ CallInsList = {
"DrawScreen",
"DrawInMiniMap",

"FontsChanged",

"SunChanged",

"Explosion",
Expand Down
13 changes: 13 additions & 0 deletions cont/LuaUI/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ local flexCallIns = {
'DrawScreenEffects',
'DrawScreenPost',
'DrawInMiniMap',
'FontsChanged',
'SunChanged',
'RecvSkirmishAIMessage',
}
Expand Down Expand Up @@ -2167,6 +2168,18 @@ function widgetHandler:DownloadProgress(id, downloaded, total)
end
end


--------------------------------------------------------------------------------
--
-- Font call-ins
--

function widgetHandler:FontsChaged()
for _,w in ripairs(self.FontsChangedList) do
w:FontsChanged()
end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions cont/base/springcontent/LuaGadgets/callins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ CALLIN_LIST = {
"DrawProjectile",
"DrawMaterial",

"FontsChanged",

"SunChanged",

-- unsynced message callins
Expand Down
9 changes: 9 additions & 0 deletions cont/base/springcontent/LuaGadgets/gadgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,15 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadgetHandler:FontsChanged()
for _,g in r_ipairs(self.FontsChangedList) do
g:FontsChanged()
end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

gadgetHandler:Initialize()

--------------------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions rts/Lua/LuaFonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ bool LuaFonts::PushEntries(lua_State* L)

REGISTER_LUA_CFUNC(LoadFont);
REGISTER_LUA_CFUNC(DeleteFont);
REGISTER_LUA_CFUNC(AddFallbackFont);
REGISTER_LUA_CFUNC(ClearFallbackFonts);

return true;
}
Expand Down Expand Up @@ -205,6 +207,49 @@ int LuaFonts::DeleteFont(lua_State* L)
return meta_gc(L);
}

/*** Adds a fallback font for the font rendering engine.
*
* Fonts added first will have higher priority.
* When a glyph isn't found when rendering a font, the fallback fonts
* will be searched first, otherwise os fonts will be used.
*
* The application should listen for the unsynced 'FontsChanged' callin so
* modules can clear any already reserved display lists or other relevant
* caches.
*
* Note the callin won't be executed at the time of calling this method,
* 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"
Copy link
Collaborator

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)?

Copy link
Collaborator Author

@saurtron saurtron Dec 11, 2024

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

Copy link
Collaborator Author

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.

* @treturn bool success
*/
int LuaFonts::AddFallbackFont(lua_State* L)
{
RECOIL_DETAILED_TRACY_ZONE;

const auto font = luaL_checkstring(L, 1);

const bool f = CFontTexture::AddFallbackFont(font);
sprunk marked this conversation as resolved.
Show resolved Hide resolved
lua_pushboolean(L, f);
return 1;
}

/*** Clears all fallback fonts.
*
* See the note at 'AddFallbackFont' about the 'FontsChanged' callin,
* it also applies when calling this method.
*
* @function gl.ClearFallbackFonts
* @treturn nil
*/
int LuaFonts::ClearFallbackFonts(lua_State* L)
{
RECOIL_DETAILED_TRACY_ZONE;

CFontTexture::ClearFallbackFonts();
return 0;
}

/******************************************************************************/
/******************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaFonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class LuaFonts {
private: // call-outs
static int LoadFont(lua_State* L);
static int DeleteFont(lua_State* L);
static int AddFallbackFont(lua_State* L);
static int ClearFallbackFonts(lua_State* L);

private: // userdata call-outs
static int Print(lua_State* L);
Expand Down
21 changes: 21 additions & 0 deletions rts/Lua/LuaHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,27 @@ void CLuaHandle::ViewResize()
RunCallIn(L, cmdStr, 1, 0);
}

/*** Called whenever fonts are updated. Signals the game display lists
* and other caches should be discarded.
*
* Gets called before other Update and Draw callins.
saurtron marked this conversation as resolved.
Show resolved Hide resolved
*
* @function FontsChanged
*/
void CLuaHandle::FontsChanged()
{
RECOIL_DETAILED_TRACY_ZONE;
LUA_CALL_IN_CHECK(L);
luaL_checkstack(L, 2, __func__);

static const LuaHashString cmdStr(__func__);

if (!cmdStr.GetGlobalFunc(L))
return;

RunCallIn(L, cmdStr, 0, 0);
}

/***
* @function SunChanged
*/
Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class CLuaHandle : public CEventClient

void ViewResize() override;

void FontsChanged() override;

void SunChanged() override;

void DrawGenesis() override;
Expand Down
Loading