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

Color fonts support #1799

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
ec36776
Colored and non scalable fonts support.
saurtron Dec 4, 2024
d7ef8e6
Recreate texture at UploadGlyphAtlasTextureImpl and change internal
saurtron Dec 4, 2024
7ab66c9
re-add missing y parameter to shadow atlas alloc.
saurtron Dec 5, 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
8ba3987
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
saurtron Dec 7, 2024
8cf8cc3
Refactor atlas clearing into a separate method and don't use
saurtron Dec 7, 2024
12c432e
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
saurtron Dec 7, 2024
f85dff1
Realloc before dispose.
saurtron Dec 7, 2024
48bef3a
also notify channels when pitch doesn't match
saurtron Dec 7, 2024
07758f5
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
saurtron Dec 9, 2024
eb21526
Alloc with the right channel number when doing ClearAtlases.
saurtron Dec 9, 2024
36783c9
Make CFontTexture::ClearGlyphs return the changed status instead of
saurtron Dec 9, 2024
5cb9407
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
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
c9b82d6
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
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
d1e7ab4
Merge branch 'lua-fallback-fonts-with-atlasclear' into colored-fonts
saurtron Dec 14, 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". Uses VFS.RAW_FIRST access mode.
* @treturn bool success
*/
int LuaFonts::AddFallbackFont(lua_State* L)
{
RECOIL_DETAILED_TRACY_ZONE;

const auto font = luaL_checkstring(L, 1);

const bool res = CFontTexture::AddFallbackFont(font);
lua_pushboolean(L, res);
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.
*
* @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