Skip to content

Commit 5650c5b

Browse files
authored
feat(examples): add support for custom fonts directory via JSAR_SYSTEM_FONTS_DIR (#255)
1 parent d88d7ae commit 5650c5b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/common/font/cache.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <unordered_map>
77
#include <filesystem>
8+
#include <cstdlib>
89
#include <assert.h>
910

1011
#include <skia/include/core/SkData.h>
@@ -288,6 +289,18 @@ namespace font
288289
#elif __ANDROID__
289290
addFontsAt("/system/fonts");
290291
#endif
292+
293+
// Check for custom system fonts directory from environment variable
294+
const char *customFontsDir = std::getenv("JSAR_SYSTEM_FONTS_DIR");
295+
if (customFontsDir != nullptr)
296+
{
297+
std::string fontPath(customFontsDir);
298+
if (std::filesystem::exists(fontPath) && std::filesystem::is_directory(fontPath))
299+
{
300+
addFontsAt(fontPath);
301+
}
302+
}
303+
291304
fontCollection_->setDefaultFontManager(fontMgr_);
292305
printSummary();
293306
}

src/examples/desktop_opengl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ namespace jsar::example
152152
printf(" singlepass - Single rendering pass\n");
153153
printf(" --env-map <path> Specify environment map directory path\n");
154154
printf(" --no-env-map Disable environment map rendering\n");
155+
printf(" --system-fonts-dir <dir> Set custom system fonts directory\n");
155156
printf(" --help Show this help\n");
156157
printf("\n");
157158
printf("Examples:\n");
@@ -161,6 +162,7 @@ namespace jsar::example
161162
printf(" %s --stereo singlepass\n", programName);
162163
printf(" %s --env-map /path/to/cubemap # Use custom environment map\n", programName);
163164
printf(" %s --no-env-map # Disable environment map\n", programName);
165+
printf(" %s --system-fonts-dir /usr/share/fonts # Use custom font directory\n", programName);
164166
}
165167

166168
bool init(int argc, char **argv)
@@ -279,6 +281,21 @@ namespace jsar::example
279281
if (samples < 0 || samples > 16)
280282
samples = 4;
281283
}
284+
else if (arg == "--system-fonts-dir")
285+
{
286+
if (i + 1 >= argc)
287+
{
288+
printf("Error: --system-fonts-dir requires a directory path argument\n");
289+
help(argv[0]);
290+
return false;
291+
}
292+
string fontsDir = argv[++i];
293+
if (setenv("JSAR_SYSTEM_FONTS_DIR", fontsDir.c_str(), 1) != 0)
294+
{
295+
printf("Error: Failed to set JSAR_SYSTEM_FONTS_DIR environment variable\n");
296+
return false;
297+
}
298+
}
282299
else if (arg[0] != '-')
283300
{
284301
// This is the URL argument

0 commit comments

Comments
 (0)