summaryrefslogtreecommitdiff
path: root/src/d/d_font_manager.cpp
diff options
context:
space:
mode:
authorrobojumper <robojumper@gmail.com>2024-06-15 19:21:54 +0200
committerrobojumper <robojumper@gmail.com>2024-06-21 00:36:10 +0200
commitb3e23c3f94c9a928a42db8d924f85c6daca1f0de (patch)
tree125007ccb40ff24cee91be454a0f68c4d9aeff01 /src/d/d_font_manager.cpp
parent20ed99353a8ae7a6277dc4fc6eb1c55a0bf7e642 (diff)
d_font_manager
Diffstat (limited to 'src/d/d_font_manager.cpp')
-rw-r--r--src/d/d_font_manager.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/d/d_font_manager.cpp b/src/d/d_font_manager.cpp
new file mode 100644
index 00000000..653370a2
--- /dev/null
+++ b/src/d/d_font_manager.cpp
@@ -0,0 +1,77 @@
+#include <d/d_font_manager.h>
+#include <d/d_heap.h>
+#include <sized_string.h>
+
+static dFontMng_c l_dFontMng_obj[3];
+
+static char *systemFonts[] = {"normal_00.brfnt", "special_00.brfnt", "picture_00.brfnt"};
+static char *fonts[] = {"normal_00.brfnt", "normal_01.brfnt", "special_00.brfnt", "special_01.brfnt",
+ "picture_00.brfnt"};
+
+// TODO What's up with these?
+char dFontMng_c::normal_01[] = "normal_01.brfnt";
+char dFontMng_c::normal_00[] = "normal_00.brfnt";
+char dFontMng_c::special_01[] = "special_01.brfnt";
+char dFontMng_c::special_00[] = "special_00.brfnt";
+
+const u32 fontMgrIndex[] = {0, 0, 1, 1, 2};
+
+dFontMng_c::dFontMng_c() {
+ l_dFontMng_obj[0].mpFileData = nullptr;
+ l_dFontMng_obj[1].mpFileData = nullptr;
+ l_dFontMng_obj[2].mpFileData = nullptr;
+}
+
+dFontMng_c::~dFontMng_c() {}
+
+nw4r::ut::ResFont *dFontMng_c::getFont(u8 type) {
+ u8 index = getFontMgrIdx(type);
+ return &l_dFontMng_obj[index].mFont;
+}
+
+char *getFontName(u8 type) {
+ return fonts[type];
+}
+
+dFontMng_c *dFontMng_c::getFontManager(int idx) {
+ return &l_dFontMng_obj[idx];
+}
+
+u8 dFontMng_c::getFontMgrIdx(u8 type) {
+ return fontMgrIndex[type];
+}
+
+void dFontMng_c::setFontFile(int idx, void *fileData) {
+ l_dFontMng_obj[idx].mpFileData = fileData;
+}
+
+// getUsedLanguageString
+extern "C" const char *fn_801B2DB0();
+
+const char *dFontMng_c::getFontPath(u8 idx) {
+ static SizedString<128> TEMP_FONT_NAME;
+ if (idx == 2) {
+ TEMP_FONT_NAME.sprintf("/Font/%s", systemFonts[idx]);
+ } else {
+ TEMP_FONT_NAME.sprintf("/US/Font/%s/%s", fn_801B2DB0(), systemFonts[idx]);
+ }
+ return &TEMP_FONT_NAME;
+}
+
+bool dFontMng_c::create() {
+ for (u8 i = 0; i < 3; i++) {
+ if (l_dFontMng_obj[i].mpFontFile == nullptr) {
+ const char *path = getFontPath(i);
+ nw4r::ut::BinaryFileHeader *file = static_cast<nw4r::ut::BinaryFileHeader *>(
+ l_dFontMng_obj[i].mLoader.request(path, 0, dHeap::fontHeap.heap));
+ if (file == nullptr) {
+ return false;
+ }
+ l_dFontMng_obj[i].mpFontFile = file;
+ getFontManager(i)->setFontFile(i, l_dFontMng_obj[i].mpFontFile);
+ l_dFontMng_obj[i].mFont.SetResource(l_dFontMng_obj[i].mpFontFile);
+ }
+ }
+
+ return true;
+}