diff --git a/asm/Kyoto/Text/CFontRenderState.s b/asm/Kyoto/Text/CFontRenderState.s index 6e142af6..2931b71e 100644 --- a/asm/Kyoto/Text/CFontRenderState.s +++ b/asm/Kyoto/Text/CFontRenderState.s @@ -234,8 +234,8 @@ lbl_802FEFC0: /* 802FEFD0 002FBF30 38 21 00 20 */ addi r1, r1, 0x20 /* 802FEFD4 002FBF34 4E 80 00 20 */ blr -.global sub_802fefd8 -sub_802fefd8: +.global PushState__16CFontRenderStateFv +PushState__16CFontRenderStateFv: /* 802FEFD8 002FBF38 94 21 FF F0 */ stwu r1, -0x10(r1) /* 802FEFDC 002FBF3C 7C 08 02 A6 */ mflr r0 /* 802FEFE0 002FBF40 7C 64 1B 78 */ mr r4, r3 @@ -851,4 +851,3 @@ lbl_803D6E60: # ROM: 0x3D3E60 .asciz "??(??)" .balign 4 - diff --git a/asm/Kyoto/Text/CPopStateInstruction.s b/asm/Kyoto/Text/CPopStateInstruction.s index eb15038a..fc13fec4 100644 --- a/asm/Kyoto/Text/CPopStateInstruction.s +++ b/asm/Kyoto/Text/CPopStateInstruction.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803ED698 -lbl_803ED698: +.global __vt__20CPopStateInstruction +__vt__20CPopStateInstruction: # ROM: 0x3EA698 .4byte 0 .4byte 0 @@ -25,8 +25,8 @@ __dt__20CPopStateInstructionFv: /* 802FFD4C 002FCCAC 93 E1 00 0C */ stw r31, 0xc(r1) /* 802FFD50 002FCCB0 7C 7F 1B 79 */ or. r31, r3, r3 /* 802FFD54 002FCCB4 41 82 00 30 */ beq lbl_802FFD84 -/* 802FFD58 002FCCB8 3C 60 80 3F */ lis r3, lbl_803ED698@ha -/* 802FFD5C 002FCCBC 38 03 D6 98 */ addi r0, r3, lbl_803ED698@l +/* 802FFD58 002FCCB8 3C 60 80 3F */ lis r3, __vt__20CPopStateInstruction@ha +/* 802FFD5C 002FCCBC 38 03 D6 98 */ addi r0, r3, __vt__20CPopStateInstruction@l /* 802FFD60 002FCCC0 90 1F 00 00 */ stw r0, 0(r31) /* 802FFD64 002FCCC4 41 82 00 10 */ beq lbl_802FFD74 /* 802FFD68 002FCCC8 3C 60 80 3E */ lis r3, __vt__12CInstruction@ha diff --git a/asm/Kyoto/Text/CPushStateInstruction.s b/asm/Kyoto/Text/CPushStateInstruction.s index 9a917203..b7fea1df 100644 --- a/asm/Kyoto/Text/CPushStateInstruction.s +++ b/asm/Kyoto/Text/CPushStateInstruction.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803ED6B8 -lbl_803ED6B8: +.global __vt__21CPushStateInstruction +__vt__21CPushStateInstruction: # ROM: 0x3EA6B8 .4byte 0 .4byte 0 @@ -25,8 +25,8 @@ __dt__21CPushStateInstructionFv: /* 802FFE34 002FCD94 93 E1 00 0C */ stw r31, 0xc(r1) /* 802FFE38 002FCD98 7C 7F 1B 79 */ or. r31, r3, r3 /* 802FFE3C 002FCD9C 41 82 00 30 */ beq lbl_802FFE6C -/* 802FFE40 002FCDA0 3C 60 80 3F */ lis r3, lbl_803ED6B8@ha -/* 802FFE44 002FCDA4 38 03 D6 B8 */ addi r0, r3, lbl_803ED6B8@l +/* 802FFE40 002FCDA0 3C 60 80 3F */ lis r3, __vt__21CPushStateInstruction@ha +/* 802FFE44 002FCDA4 38 03 D6 B8 */ addi r0, r3, __vt__21CPushStateInstruction@l /* 802FFE48 002FCDA8 90 1F 00 00 */ stw r0, 0(r31) /* 802FFE4C 002FCDAC 41 82 00 10 */ beq lbl_802FFE5C /* 802FFE50 002FCDB0 3C 60 80 3E */ lis r3, __vt__12CInstruction@ha @@ -65,7 +65,7 @@ Invoke__21CPushStateInstructionCFR16CFontRenderStateP17CTextRenderBuffer: /* 802FFEB4 002FCE14 7C 08 02 A6 */ mflr r0 /* 802FFEB8 002FCE18 7C 83 23 78 */ mr r3, r4 /* 802FFEBC 002FCE1C 90 01 00 14 */ stw r0, 0x14(r1) -/* 802FFEC0 002FCE20 4B FF F1 19 */ bl sub_802fefd8 +/* 802FFEC0 002FCE20 4B FF F1 19 */ bl PushState__16CFontRenderStateFv /* 802FFEC4 002FCE24 80 01 00 14 */ lwz r0, 0x14(r1) /* 802FFEC8 002FCE28 7C 08 03 A6 */ mtlr r0 /* 802FFECC 002FCE2C 38 21 00 10 */ addi r1, r1, 0x10 diff --git a/asm/Kyoto/Text/CTextExecuteBuffer.s b/asm/Kyoto/Text/CTextExecuteBuffer.s index 7921000e..ff8e58d1 100644 --- a/asm/Kyoto/Text/CTextExecuteBuffer.s +++ b/asm/Kyoto/Text/CTextExecuteBuffer.s @@ -1493,10 +1493,10 @@ AddPopState__18CTextExecuteBufferFv: /* 80302FEC 002FFF4C 7C 7F 1B 79 */ or. r31, r3, r3 /* 80302FF0 002FFF50 41 82 00 1C */ beq lbl_8030300C /* 80302FF4 002FFF54 3C 80 80 3E */ lis r4, __vt__12CInstruction@ha -/* 80302FF8 002FFF58 3C 60 80 3F */ lis r3, lbl_803ED698@ha +/* 80302FF8 002FFF58 3C 60 80 3F */ lis r3, __vt__20CPopStateInstruction@ha /* 80302FFC 002FFF5C 38 04 9A 6C */ addi r0, r4, __vt__12CInstruction@l /* 80303000 002FFF60 90 1F 00 00 */ stw r0, 0(r31) -/* 80303004 002FFF64 38 03 D6 98 */ addi r0, r3, lbl_803ED698@l +/* 80303004 002FFF64 38 03 D6 98 */ addi r0, r3, __vt__20CPopStateInstruction@l /* 80303008 002FFF68 90 1F 00 00 */ stw r0, 0(r31) lbl_8030300C: /* 8030300C 002FFF6C 3C 80 80 3D */ lis r4, lbl_803D6E90@ha @@ -1557,10 +1557,10 @@ AddPushState__18CTextExecuteBufferFv: /* 803030D4 00300034 7C 7F 1B 79 */ or. r31, r3, r3 /* 803030D8 00300038 41 82 00 1C */ beq lbl_803030F4 /* 803030DC 0030003C 3C 80 80 3E */ lis r4, __vt__12CInstruction@ha -/* 803030E0 00300040 3C 60 80 3F */ lis r3, lbl_803ED6B8@ha +/* 803030E0 00300040 3C 60 80 3F */ lis r3, __vt__21CPushStateInstruction@ha /* 803030E4 00300044 38 04 9A 6C */ addi r0, r4, __vt__12CInstruction@l /* 803030E8 00300048 90 1F 00 00 */ stw r0, 0(r31) -/* 803030EC 0030004C 38 03 D6 B8 */ addi r0, r3, lbl_803ED6B8@l +/* 803030EC 0030004C 38 03 D6 B8 */ addi r0, r3, __vt__21CPushStateInstruction@l /* 803030F0 00300050 90 1F 00 00 */ stw r0, 0(r31) lbl_803030F4: /* 803030F4 00300054 3C 80 80 3D */ lis r4, lbl_803D6E90@ha diff --git a/asm/Kyoto/Text/CWordBreakTables.s b/asm/Kyoto/Text/CWordBreakTables.s index 1ed9399f..71d95cc7 100644 --- a/asm/Kyoto/Text/CWordBreakTables.s +++ b/asm/Kyoto/Text/CWordBreakTables.s @@ -16,9 +16,9 @@ lbl_805A933C: GetEndRank__16CWordBreakTablesFw: /* 803059A0 00302900 94 21 FF E0 */ stwu r1, -0x20(r1) /* 803059A4 00302904 7C 08 02 A6 */ mflr r0 -/* 803059A8 00302908 3C 80 80 3D */ lis r4, lbl_803D70C0@ha +/* 803059A8 00302908 3C 80 80 3D */ lis r4, gCantEndChars@ha /* 803059AC 0030290C 90 01 00 24 */ stw r0, 0x24(r1) -/* 803059B0 00302910 38 84 70 C0 */ addi r4, r4, lbl_803D70C0@l +/* 803059B0 00302910 38 84 70 C0 */ addi r4, r4, gCantEndChars@l /* 803059B4 00302914 38 A1 00 08 */ addi r5, r1, 8 /* 803059B8 00302918 38 C1 00 0C */ addi r6, r1, 0xc /* 803059BC 0030291C 93 E1 00 1C */ stw r31, 0x1c(r1) @@ -61,9 +61,9 @@ lbl_80305A20: GetBeginRank__16CWordBreakTablesFw: /* 80305A34 00302994 94 21 FF E0 */ stwu r1, -0x20(r1) /* 80305A38 00302998 7C 08 02 A6 */ mflr r0 -/* 80305A3C 0030299C 3C 80 80 3D */ lis r4, lbl_803D6EC8@ha +/* 80305A3C 0030299C 3C 80 80 3D */ lis r4, gCantBeginChars@ha /* 80305A40 003029A0 90 01 00 24 */ stw r0, 0x24(r1) -/* 80305A44 003029A4 38 84 6E C8 */ addi r4, r4, lbl_803D6EC8@l +/* 80305A44 003029A4 38 84 6E C8 */ addi r4, r4, gCantBeginChars@l /* 80305A48 003029A8 38 A1 00 08 */ addi r5, r1, 8 /* 80305A4C 003029AC 38 C1 00 0C */ addi r6, r1, 0xc /* 80305A50 003029B0 93 E1 00 1C */ stw r31, 0x1c(r1) @@ -194,8 +194,8 @@ lbl_80305B40: .section .rodata .balign 8 -.global lbl_803D6EC8 -lbl_803D6EC8: +.global gCantBeginChars +gCantBeginChars: # ROM: 0x3D3EC8 .4byte 0x00210000 .4byte 0x00000001 @@ -324,8 +324,8 @@ lbl_803D6EC8: .4byte 0xFF1F0000 .4byte 0x00000001 -.global lbl_803D70C0 -lbl_803D70C0: +.global gCantEndChars +gCantEndChars: # ROM: 0x3D40C0 .4byte 0x00230000 .4byte 0x00000002 @@ -505,4 +505,3 @@ lbl_803D70C0: .4byte 0x00000002 .4byte 0xFFEF0000 .4byte 0x00000002 - diff --git a/configure.py b/configure.py index b143b7ff..35a96249 100755 --- a/configure.py +++ b/configure.py @@ -542,15 +542,15 @@ LIBS = [ ["Kyoto/Text/CLineExtraSpaceInstruction", True], "Kyoto/Text/CLineInstruction", ["Kyoto/Text/CLineSpacingInstruction", True], - "Kyoto/Text/CPopStateInstruction", - "Kyoto/Text/CPushStateInstruction", + ["Kyoto/Text/CPopStateInstruction", True], + ["Kyoto/Text/CPushStateInstruction", True], ["Kyoto/Text/CRasterFont", False], "Kyoto/Text/CRemoveColorOverrideInstruction", ["Kyoto/Text/CSaveableState", True], "Kyoto/Text/CTextExecuteBuffer", "Kyoto/Text/CTextInstruction", ["Kyoto/Text/CTextParser", False], - "Kyoto/Text/CWordBreakTables", + ["Kyoto/Text/CWordBreakTables", False], "Kyoto/Text/CWordInstruction", "Kyoto/Text/CBlockInstruction", ["Kyoto/Text/CFont", True], diff --git a/include/Kyoto/CToken.hpp b/include/Kyoto/CToken.hpp index 7509dc40..d55b572c 100644 --- a/include/Kyoto/CToken.hpp +++ b/include/Kyoto/CToken.hpp @@ -28,6 +28,8 @@ public: bool HasLock() { return x4_lockHeld; } + const CObjectReference* GetRef() const { return x0_objRef; } + private: CObjectReference* x0_objRef; bool x4_lockHeld; diff --git a/include/Kyoto/Text/CFontRenderState.hpp b/include/Kyoto/Text/CFontRenderState.hpp index 3128132c..e308edce 100644 --- a/include/Kyoto/Text/CFontRenderState.hpp +++ b/include/Kyoto/Text/CFontRenderState.hpp @@ -6,12 +6,16 @@ class CBlockInstruction; -class CFontRenderState : private CSaveableState { +class CFontRenderState { public: - void SetLineSpacing(float spacing) { CSaveableState::SetLineSpacing(spacing); } - void SetExtraLineSpace(int spacing) { CSaveableState::SetLineExtraSpace(spacing); } + void PushState(); + void PopState(); + const TToken& GetFont() { return x0_state.GetFont(); } + void SetLineSpacing(float spacing) { x0_state.SetLineSpacing(spacing); } + void SetExtraLineSpace(int spacing) { x0_state.SetLineExtraSpace(spacing); } private: + CSaveableState x0_state; CBlockInstruction* x88_curBlock; CDrawStringOptions x8c_drawOpts; int xd4_curX; diff --git a/include/Kyoto/Text/CPopStateInstruction.hpp b/include/Kyoto/Text/CPopStateInstruction.hpp new file mode 100644 index 00000000..faf97ec4 --- /dev/null +++ b/include/Kyoto/Text/CPopStateInstruction.hpp @@ -0,0 +1,16 @@ +#ifndef _CPOPSTATEINSTRUCTION +#define _CPOPSTATEINSTRUCTION + +#include "Kyoto/Text/CInstruction.hpp" + +class CPopStateInstruction : public CInstruction { +public: + CPopStateInstruction() {} + ~CPopStateInstruction() {} + + void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const; + void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const; +}; + + +#endif // _CPOPSTATEINSTRUCTION diff --git a/include/Kyoto/Text/CPushStateInstruction.hpp b/include/Kyoto/Text/CPushStateInstruction.hpp new file mode 100644 index 00000000..7c3b9b8f --- /dev/null +++ b/include/Kyoto/Text/CPushStateInstruction.hpp @@ -0,0 +1,16 @@ +#ifndef _CPUSHSTATEINSTRUCTION +#define _CPUSHSTATEINSTRUCTION + +#include "Kyoto/Text/CInstruction.hpp" + +class CPushStateInstruction : public CInstruction { +public: + CPushStateInstruction() {} + ~CPushStateInstruction() {} + + void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const; + void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const; +}; + + +#endif // _CPUSHSTATEINSTRUCTION diff --git a/include/Kyoto/Text/CSaveableState.hpp b/include/Kyoto/Text/CSaveableState.hpp index 9e7272f4..0cf847f2 100644 --- a/include/Kyoto/Text/CSaveableState.hpp +++ b/include/Kyoto/Text/CSaveableState.hpp @@ -12,6 +12,8 @@ class CSaveableState { public: CSaveableState(); + const TToken& GetFont() const { return *x48_font; } + bool IsFinishedLoading(); void SetLineSpacing(float spacing) { x74_lineSpacing = spacing; } diff --git a/include/Kyoto/Text/CTextRenderBuffer.hpp b/include/Kyoto/Text/CTextRenderBuffer.hpp new file mode 100644 index 00000000..843d596d --- /dev/null +++ b/include/Kyoto/Text/CTextRenderBuffer.hpp @@ -0,0 +1,12 @@ +#ifndef _CTEXTRENDERBUFFER +#define _CTEXTRENDERBUFFER + +#include "Kyoto/TToken.hpp" + +class CRasterFont; +class CTextRenderBuffer { +public: + void AddFontChange(const TToken< CRasterFont >& font); +}; + +#endif // _CTEXTRENDERBUFFER diff --git a/include/Kyoto/Text/CWordBreakTables.hpp b/include/Kyoto/Text/CWordBreakTables.hpp new file mode 100644 index 00000000..ff69aa5f --- /dev/null +++ b/include/Kyoto/Text/CWordBreakTables.hpp @@ -0,0 +1,13 @@ +#ifndef _CWORDBREAKTABLES +#define _CWORDBREAKTABLES + +#include + +class CWordBreakTables { +public: + static int GetBeginRank(wchar_t ch); + static int GetEndRank(wchar_t ch); +}; + + +#endif // _CWORDBREAKTABLES diff --git a/src/Kyoto/Text/CPopStateInstruction.cpp b/src/Kyoto/Text/CPopStateInstruction.cpp new file mode 100644 index 00000000..2d0af02b --- /dev/null +++ b/src/Kyoto/Text/CPopStateInstruction.cpp @@ -0,0 +1,16 @@ +#include "Kyoto/Text/CPopStateInstruction.hpp" + +#include "Kyoto/Text/CFontRenderState.hpp" +#include "Kyoto/Text/CTextRenderBuffer.hpp" + +void CPopStateInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + const CObjectReference* font = state.GetFont().GetRef(); + state.PopState(); + if (state.GetFont().GetRef() != font) { + buf->AddFontChange(state.GetFont()); + } +} + +void CPopStateInstruction::PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + Invoke(state, buf); +} diff --git a/src/Kyoto/Text/CPushStateInstruction.cpp b/src/Kyoto/Text/CPushStateInstruction.cpp new file mode 100644 index 00000000..dbd4f9f4 --- /dev/null +++ b/src/Kyoto/Text/CPushStateInstruction.cpp @@ -0,0 +1,11 @@ +#include "Kyoto/Text/CPushStateInstruction.hpp" + +#include "Kyoto/Text/CFontRenderState.hpp" + +void CPushStateInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + state.PushState(); +} + +void CPushStateInstruction::PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + Invoke(state, buf); +} diff --git a/src/Kyoto/Text/CWordBreakTables.cpp b/src/Kyoto/Text/CWordBreakTables.cpp new file mode 100644 index 00000000..fc82f5b6 --- /dev/null +++ b/src/Kyoto/Text/CWordBreakTables.cpp @@ -0,0 +1,39 @@ +#include "Kyoto/Text/CWordBreakTables.hpp" + +#include "rstl/algorithm.hpp" + +struct CCharacterIdentifier { + wchar_t chr; + uint rank; +}; + +const CCharacterIdentifier gCantBeginChars[63] = { + {L'!', 1}, {L')', 1}, {L',', 1}, {L'-', 1}, {L'.', 1}, {L':', 1}, {L';', 1}, + {L'?', 1}, {L']', 1}, {L'}', 1}, {0x92, 1}, {0x94, 1}, {0xBB, 1}, {0x3001, 1}, + {0x3002, 1}, {0x3005, 1}, {0x300D, 1}, {0x300F, 1}, {0x3011, 1}, {0x3015, 1}, {0x3017, 1}, + {0x3019, 1}, {0x301B, 1}, {0x301C, 3}, {0x301E, 1}, {0x302B, 3}, {0x3041, 2}, {0x3043, 2}, + {0x3045, 2}, {0x3047, 2}, {0x3049, 2}, {0x3063, 2}, {0x3083, 2}, {0x3085, 2}, {0x3087, 2}, + {0x308E, 2}, {0x309D, 3}, {0x309E, 3}, {0x30A1, 2}, {0x30A3, 2}, {0x30A5, 2}, {0x30A7, 2}, + {0x30A9, 2}, {0x30C3, 2}, {0x30E3, 2}, {0x30E5, 2}, {0x30E7, 2}, {0x30EE, 2}, {0x30F5, 2}, + {0x30F6, 2}, {0x30FC, 2}, {0x30FD, 3}, {0x30FE, 3}, {0xFF01, 1}, {0xFF05, 3}, {0xFF09, 1}, + {0xFF0D, 1}, {0xFF3D, 1}, {0xFF5D, 1}, {0xFF61, 1}, {0xFF63, 1}, {0xFF64, 1}, {0xFF1F, 1}, +}; + +const CCharacterIdentifier gCantEndChars[89] = { + {L'#', 2}, {L'$', 2}, {L'(', 1}, {L'@', 2}, {L'B', 4}, {L'C', 4}, {L'D', 4}, + {L'E', 4}, {L'F', 4}, {L'G', 4}, {L'J', 4}, {L'K', 4}, {L'L', 4}, {L'M', 4}, + {L'N', 4}, {L'P', 4}, {L'Q', 4}, {L'R', 4}, {L'S', 4}, {L'T', 4}, {L'V', 4}, + {L'W', 4}, {L'X', 4}, {L'Y', 4}, {L'Z', 4}, {L'b', 4}, {L'c', 4}, {L'd', 4}, + {L'f', 4}, {L'g', 4}, {L'h', 4}, {L'j', 4}, {L'k', 4}, {L'l', 4}, {L'm', 4}, + {L'n', 4}, {L'p', 4}, {L'q', 4}, {L'r', 4}, {L's', 4}, {L't', 4}, {L'v', 4}, + {L'w', 4}, {L'x', 4}, {L'y', 4}, {L'z', 4}, {0xD1, 4}, {0xF1, 4}, {L'[', 1}, + {L'{', 1}, {0x91, 1}, {0x93, 1}, {0x91, 1}, {0x93, 1}, {0xA2, 2}, {0xA3, 2}, + {0xA5, 2}, {0xA7, 2}, {0xA9, 2}, {0xAB, 1}, {0x20A0, 2}, {0x20A1, 2}, {0x20A2, 2}, + {0x20A3, 2}, {0x20A4, 2}, {0x20A5, 2}, {0x20A6, 2}, {0x20A7, 2}, {0x20A8, 2}, {0x20A9, 2}, + {0x20AA, 2}, {0x20AB, 2}, {0x20AC, 2}, {0x300C, 1}, {0x300E, 1}, {0x3010, 1}, {0x3012, 2}, + {0x3014, 1}, {0x3016, 1}, {0x3018, 1}, {0x301A, 1}, {0xFF03, 2}, {0xFF04, 2}, {0xFF20, 2}, + {0xFF3C, 1}, {0xFF5C, 1}, {0xFFE0, 2}, {0xFFE1, 2}, {0xFFEF, 2}, +}; + +int CWordBreakTables::GetBeginRank(wchar_t chr) { +}