From ea0198a1de96fb6db9b59704e192ca79d2ca4150 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 23 Dec 2022 20:27:33 -0800 Subject: [PATCH] Add CRasterFont --- asm/Kyoto/Text/CRasterFont.s | 34 ++++++------ configure.py | 2 +- include/Kyoto/Text/CRasterFont.hpp | 89 ++++++++++++++++++++++++++++-- src/Kyoto/Text/CRasterFont.cpp | 72 ++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 24 deletions(-) create mode 100644 src/Kyoto/Text/CRasterFont.cpp diff --git a/asm/Kyoto/Text/CRasterFont.s b/asm/Kyoto/Text/CRasterFont.s index 4475c310..db53bf1d 100644 --- a/asm/Kyoto/Text/CRasterFont.s +++ b/asm/Kyoto/Text/CRasterFont.s @@ -155,7 +155,7 @@ FRasterFontFactory__FRC10SObjectTagR12CInputStreamRC15CVParamTransfer: /* 803000D8 002FD038 41 82 00 14 */ beq lbl_803000EC /* 803000DC 002FD03C 7F C4 F3 78 */ mr r4, r30 /* 803000E0 002FD040 7F E5 FB 78 */ mr r5, r31 -/* 803000E4 002FD044 48 00 07 41 */ bl __ct__11CRasterFontFR12CInputStreamR12IObjectStore +/* 803000E4 002FD044 48 00 07 41 */ bl __ct__11CRasterFontFR12CInputStreamP12IObjectStore /* 803000E8 002FD048 7C 64 1B 78 */ mr r4, r3 lbl_803000EC: /* 803000EC 002FD04C 7F A3 EB 78 */ mr r3, r29 @@ -327,7 +327,7 @@ InternalGetGlyph__11CRasterFontCFw: /* 80300338 002FD298 99 21 00 0C */ stb r9, 0xc(r1) /* 8030033C 002FD29C 90 01 00 24 */ stw r0, 0x24(r1) /* 80300340 002FD2A0 91 01 00 20 */ stw r8, 0x20(r1) -/* 80300344 002FD2A4 48 00 0D 39 */ bl "lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17r" +/* 80300344 002FD2A4 48 00 0D 39 */ bl "lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>RCwQ24rstl60pair_sorter_finder,Q24rstl7less>" /* 80300348 002FD2A8 80 A1 00 1C */ lwz r5, 0x1c(r1) /* 8030034C 002FD2AC 38 80 00 00 */ li r4, 0 /* 80300350 002FD2B0 80 01 00 2C */ lwz r0, 0x2c(r1) @@ -694,8 +694,8 @@ GetMode__11CRasterFontCFv: /* 8030081C 002FD77C 80 63 00 2C */ lwz r3, 0x2c(r3) /* 80300820 002FD780 4E 80 00 20 */ blr -.global __ct__11CRasterFontFR12CInputStreamR12IObjectStore -__ct__11CRasterFontFR12CInputStreamR12IObjectStore: +.global __ct__11CRasterFontFR12CInputStreamP12IObjectStore +__ct__11CRasterFontFR12CInputStreamP12IObjectStore: /* 80300824 002FD784 94 21 FF 10 */ stwu r1, -0xf0(r1) /* 80300828 002FD788 7C 08 02 A6 */ mflr r0 /* 8030082C 002FD78C 90 01 00 F4 */ stw r0, 0xf4(r1) @@ -1030,7 +1030,7 @@ lbl_80300CD0: /* 80300D08 002FDC68 90 C1 00 24 */ stw r6, 0x24(r1) /* 80300D0C 002FDC6C 90 01 00 1C */ stw r0, 0x1c(r1) /* 80300D10 002FDC70 90 01 00 18 */ stw r0, 0x18(r1) -/* 80300D14 002FDC74 48 00 00 E1 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17" +/* 80300D14 002FDC74 48 00 00 E1 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" /* 80300D18 002FDC78 7F E3 FB 78 */ mr r3, r31 /* 80300D1C 002FDC7C 48 03 DF 69 */ bl ReadLong__12CInputStreamFv /* 80300D20 002FDC80 7C 78 1B 78 */ mr r24, r3 @@ -1093,8 +1093,8 @@ lbl_80300DD4: /* 80300DEC 002FDD4C 38 21 00 F0 */ addi r1, r1, 0xf0 /* 80300DF0 002FDD50 4E 80 00 20 */ blr -.global "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17" -"sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17": +.global "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" +"sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>": /* 80300DF4 002FDD54 94 21 FF 70 */ stwu r1, -0x90(r1) /* 80300DF8 002FDD58 7C 08 02 A6 */ mflr r0 /* 80300DFC 002FDD5C 90 01 00 94 */ stw r0, 0x94(r1) @@ -1124,7 +1124,7 @@ lbl_80300DD4: /* 80300E5C 002FDDBC 98 E1 00 14 */ stb r7, 0x14(r1) /* 80300E60 002FDDC0 90 C1 00 30 */ stw r6, 0x30(r1) /* 80300E64 002FDDC4 90 01 00 34 */ stw r0, 0x34(r1) -/* 80300E68 002FDDC8 48 00 08 75 */ bl "__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocato" +/* 80300E68 002FDDC8 48 00 08 75 */ bl "__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" /* 80300E6C 002FDDCC 48 00 01 FC */ b lbl_80301068 lbl_80300E70: /* 80300E70 002FDDD0 54 80 0F FE */ srwi r0, r4, 0x1f @@ -1247,7 +1247,7 @@ lbl_80301018: /* 80301030 002FDF90 98 E1 00 0C */ stb r7, 0xc(r1) /* 80301034 002FDF94 90 C1 00 20 */ stw r6, 0x20(r1) /* 80301038 002FDF98 90 01 00 24 */ stw r0, 0x24(r1) -/* 8030103C 002FDF9C 4B FF FD B9 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17" +/* 8030103C 002FDF9C 4B FF FD B9 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" /* 80301040 002FDFA0 88 FF 00 00 */ lbz r7, 0(r31) /* 80301044 002FDFA4 38 61 00 1C */ addi r3, r1, 0x1c /* 80301048 002FDFA8 80 DE 00 00 */ lwz r6, 0(r30) @@ -1257,7 +1257,7 @@ lbl_80301018: /* 80301058 002FDFB8 98 E1 00 08 */ stb r7, 8(r1) /* 8030105C 002FDFBC 90 C1 00 18 */ stw r6, 0x18(r1) /* 80301060 002FDFC0 90 01 00 1C */ stw r0, 0x1c(r1) -/* 80301064 002FDFC4 4B FF FD 91 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17" +/* 80301064 002FDFC4 4B FF FD 91 */ bl "sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" lbl_80301068: /* 80301068 002FDFC8 BA E1 00 6C */ lmw r23, 0x6c(r1) /* 8030106C 002FDFCC 80 01 00 94 */ lwz r0, 0x94(r1) @@ -1265,8 +1265,8 @@ lbl_80301068: /* 80301074 002FDFD4 38 21 00 90 */ addi r1, r1, 0x90 /* 80301078 002FDFD8 4E 80 00 20 */ blr -.global "lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17r" -"lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17r": +.global "lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>RCwQ24rstl60pair_sorter_finder,Q24rstl7less>" +"lower_bound,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,w,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>RCwQ24rstl60pair_sorter_finder,Q24rstl7less>": /* 8030107C 002FDFDC 94 21 FF D0 */ stwu r1, -0x30(r1) /* 80301080 002FDFE0 7C 08 02 A6 */ mflr r0 /* 80301084 002FDFE4 90 01 00 34 */ stw r0, 0x34(r1) @@ -1524,14 +1524,14 @@ lbl_80301364: /* 803013E4 002FE344 90 C1 00 10 */ stw r6, 0x10(r1) /* 803013E8 002FE348 98 E1 00 0C */ stb r7, 0xc(r1) /* 803013EC 002FE34C 90 01 00 14 */ stw r0, 0x14(r1) -/* 803013F0 002FE350 48 00 00 15 */ bl "__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_itera" +/* 803013F0 002FE350 48 00 00 15 */ bl "__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_iterator_tag" /* 803013F4 002FE354 80 01 00 24 */ lwz r0, 0x24(r1) /* 803013F8 002FE358 7C 08 03 A6 */ mtlr r0 /* 803013FC 002FE35C 38 21 00 20 */ addi r1, r1, 0x20 /* 80301400 002FE360 4E 80 00 20 */ blr -.global "__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_itera" -"__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_itera": +.global "__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_iterator_tag" +"__distance,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>>__4rstlFQ24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl144const_pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl26random_access_iterator_tag": /* 80301404 002FE364 80 A3 00 00 */ lwz r5, 0(r3) /* 80301408 002FE368 3C 60 38 E4 */ lis r3, 0x38E38E39@ha /* 8030140C 002FE36C 80 04 00 00 */ lwz r0, 0(r4) @@ -1721,8 +1721,8 @@ lbl_803016C4: /* 803016D4 002FE634 38 21 00 60 */ addi r1, r1, 0x60 /* 803016D8 002FE638 4E 80 00 20 */ blr -.global "__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocato" -"__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocato": +.global "__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>" +"__insertion_sort,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q24rstl60pair_sorter_finder,Q24rstl7less>>__4rstlFQ24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl138pointer_iterator,Q24rstl59vector,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl60pair_sorter_finder,Q24rstl7less>": /* 803016DC 002FE63C 94 21 FF C0 */ stwu r1, -0x40(r1) /* 803016E0 002FE640 93 E1 00 3C */ stw r31, 0x3c(r1) /* 803016E4 002FE644 93 C1 00 38 */ stw r30, 0x38(r1) diff --git a/configure.py b/configure.py index de83c2ba..e5d1bfd4 100755 --- a/configure.py +++ b/configure.py @@ -544,7 +544,7 @@ LIBS = [ "Kyoto/Text/CLineSpacingInstruction", "Kyoto/Text/CPopStateInstruction", "Kyoto/Text/CPushStateInstruction", - "Kyoto/Text/CRasterFont", + ["Kyoto/Text/CRasterFont", False], "Kyoto/Text/CRemoveColorOverrideInstruction", ["Kyoto/Text/CSaveableState", True], "Kyoto/Text/CTextExecuteBuffer", diff --git a/include/Kyoto/Text/CRasterFont.hpp b/include/Kyoto/Text/CRasterFont.hpp index 0a79a60f..5c0406dc 100644 --- a/include/Kyoto/Text/CRasterFont.hpp +++ b/include/Kyoto/Text/CRasterFont.hpp @@ -4,15 +4,24 @@ #include "types.h" #include "Kyoto/TToken.hpp" +#include "rstl/optional_object.hpp" #include "rstl/pair.hpp" #include "rstl/vector.hpp" +#include "string.h" + class CGlyph; class CKernPair; class CTexture; class IObjectStore; class CFontInfo { +public: + CFontInfo(bool a, bool b, int c, int fontSize, const char* name) + : x0_(a), x1_(b), x4_(c), x8_fontSize(fontSize) { + strcpy(xc_name, name); + } + private: bool x0_; bool x1_; @@ -21,12 +30,81 @@ private: char xc_name[64]; }; +class CKernPair { +public: + CKernPair(wchar_t first, wchar_t second, int howMuch) + : x0_first(first), x2_second(second), x4_howMuch(howMuch) {} + + wchar_t GetFirst() const { return x0_first; } + wchar_t GetSecond() const { return x2_second; } + int GetHowMuch() const { return x4_howMuch; } + +private: + wchar_t x0_first; + wchar_t x2_second; + int x4_howMuch; +}; + +class CGlyph { +public: + CGlyph(int a, int b, int c, float startU, float startV, float endU, float endV, int cellWidth, + int cellHeight, int baseline, int kernStart) + : x0_a(a) + , x2_b(b) + , x4_c(c) + , x8_startU(startU) + , xc_startV(startV) + , x10_endU(endU) + , x14_endV(endV) + , x18_cellWidth(cellWidth) + , x1a_cellHeight(cellHeight) + , x1c_baseline(baseline) + , x1e_kernStart(kernStart) + {} + + short GetA() const { return x0_a; } + short GetB() const { return x2_b; } + short GetC() const { return x4_c; } + float GetStartU() const { return x8_startU; } + float GetStartV() const { return xc_startV; } + float GetEndU() const { return x10_endU; } + float GetEndV() const { return x14_endV; } + short GetCellWidth() const { return x18_cellWidth; } + short GetCellHeight() const { return x1a_cellHeight; } + short GetBaseline() const { return x1c_baseline; } + short GetKernStart() const { return x1e_kernStart; } + //short GetLayer() const { return x20_layer; } + +private: + short x0_a; + short x2_b; + short x4_c; + float x8_startU; + float xc_startV; + float x10_endU; + float x14_endV; + short x18_cellWidth; + short x1a_cellHeight; + short x1c_baseline; + short x1e_kernStart; + //short x20_layer; +}; + +enum EFontMode { + kFM_None = -1, + kFM_OneLayer, + kFM_OneLayerOutline, + kFM_FourLayers, + kFM_TwoLayersOutline, + kFM_TwoLayers, +}; + class CRasterFont { public: - CRasterFont(CInputStream&, IObjectStore*); + CRasterFont(CInputStream& in, IObjectStore* store); ~CRasterFont(); - void SetTexture(TToken< CTexture > token) { x7c_texture = token; } + void SetTexture(TToken< CTexture > token) { x80_texture = token; } bool IsFinishedLoading(); private: @@ -35,10 +113,9 @@ private: int x8_monoHeight; rstl::vector< rstl::pair< wchar_t, CGlyph > > xc_glyphs; rstl::vector< CKernPair > x1c_kerning; - int mode; - CFontInfo x30_fontInfo; - TLockedToken< CTexture > x7c_texture; - int x88_; + EFontMode x2c_mode; + rstl::optional_object< CFontInfo > x30_fontInfo; + rstl::optional_object< TToken< CTexture > > x80_texture; int x8c_baseline; int x90_lineMargin; }; diff --git a/src/Kyoto/Text/CRasterFont.cpp b/src/Kyoto/Text/CRasterFont.cpp new file mode 100644 index 00000000..f08d3985 --- /dev/null +++ b/src/Kyoto/Text/CRasterFont.cpp @@ -0,0 +1,72 @@ +#include "Kyoto/Text/CRasterFont.hpp" + +#include "Kyoto/Streams/CInputStream.hpp" + +#include "rstl/algorithm.hpp" +#include "rstl/string.hpp" + +CRasterFont::CRasterFont(CInputStream& in, IObjectStore* store) +: x0_initialized(false) +, x4_monoWidth(16) +, x8_monoHeight(16) +, x2c_mode(kFM_OneLayer) +, x90_lineMargin(0) { + if (in.ReadInt32() == 'FONT') { + int version = in.ReadInt32(); + if (version >= 0 && version <= 2) { + x4_monoWidth = in.ReadInt32(); + x8_monoHeight = in.ReadInt32(); + x8c_baseline = version >= 1 ? in.ReadInt32() : x8_monoHeight; + if (version >= 2) { + x90_lineMargin = in.ReadInt32(); + } + + bool fInfoA = in.ReadBool(); + bool fInfoB = in.ReadBool(); + int fInfoC = in.ReadInt32(); + int fontSize = in.ReadInt32(); + rstl::string fontName(in); + CAssetId fontId = in.ReadInt32(); + + if (store != nullptr) { + x80_texture = store->GetObj(SObjectTag('TXTR', fontId)); + x80_texture->Lock(); + } + + x30_fontInfo = CFontInfo(fInfoA, fInfoB, fInfoC, fontSize, fontName.data()); + + int mode = in.ReadInt32(); + switch (mode) { + case 0: + x2c_mode = kFM_OneLayer; + break; + case 1: + x2c_mode = kFM_OneLayerOutline; + break; + } + + int glyphCount = in.ReadInt32(); + xc_glyphs.reserve(glyphCount); + + for (int i = 0; i < glyphCount; ++i) { + short chr = in.ReadShort(); + float startU = in.ReadFloat(); + float startV = in.ReadFloat(); + float endU = in.ReadFloat(); + float endV = in.ReadFloat(); + int a = in.ReadInt32(); + int b = in.ReadInt32(); + int c = in.ReadInt32(); + int cellWidth = in.ReadInt32(); + int cellHeight = in.ReadInt32(); + int baseline = in.ReadInt32(); + int kernStart = in.ReadInt32(); + xc_glyphs.push_back( + rstl::pair< wchar_t, CGlyph >(chr, CGlyph(a, b, c, startU, startV, endU, endV, + cellWidth, cellHeight, baseline, kernStart))); + } + //rstl::sort(xc_glyphs.begin(), xc_glyphs.end(), + // rstl::pair_sorter_finder< wchar_t, CGlyph, rstl::less< wchar_t > >()); + } + } +}