mirror of
https://github.com/pret/pokeheartgold.git
synced 2025-03-03 02:26:33 +00:00
font_data.c, 1
This commit is contained in:
parent
0094a464a7
commit
b33dcc36d3
@ -1,472 +1,8 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "global.inc"
|
||||
|
||||
.rodata
|
||||
|
||||
_020F6324:
|
||||
.byte 0x00, 0x01, 0x02, 0x03
|
||||
_020F6328:
|
||||
.word InitFontResources_FromPreloaded
|
||||
.word InitFontResources_LazyFromNarc
|
||||
_020F6330:
|
||||
.word FreeLoadedFontResources_FromPreloaded
|
||||
.word FreeLoadedFontResources_LazyFromNarc
|
||||
|
||||
.text
|
||||
|
||||
thumb_func_start FontData_new
|
||||
FontData_new: ; 0x02025E88
|
||||
push {r3, r4, r5, r6, r7, lr}
|
||||
sub sp, #8
|
||||
add r5, r0, #0
|
||||
add r6, r1, #0
|
||||
ldr r0, [sp, #0x20]
|
||||
mov r1, #0x7c
|
||||
add r7, r2, #0
|
||||
str r3, [sp, #4]
|
||||
bl AllocFromHeap
|
||||
add r4, r0, #0
|
||||
beq _02025EB8
|
||||
ldr r1, [sp, #0x20]
|
||||
ldr r3, [sp, #4]
|
||||
str r1, [sp]
|
||||
add r1, r5, #0
|
||||
add r2, r6, #0
|
||||
bl FontData_Init
|
||||
ldr r2, [sp, #0x20]
|
||||
add r0, r4, #0
|
||||
add r1, r7, #0
|
||||
bl InitFontResources
|
||||
_02025EB8:
|
||||
add r0, r4, #0
|
||||
add sp, #8
|
||||
pop {r3, r4, r5, r6, r7, pc}
|
||||
.balign 4, 0
|
||||
thumb_func_end FontData_new
|
||||
|
||||
thumb_func_start FontData_delete
|
||||
FontData_delete: ; 0x02025EC0
|
||||
push {r4, lr}
|
||||
add r4, r0, #0
|
||||
bl FreeLoadedFontResources
|
||||
add r0, r4, #0
|
||||
bl FontData_FreeWidthsAndNarc
|
||||
add r0, r4, #0
|
||||
bl FreeToHeap
|
||||
pop {r4, pc}
|
||||
.balign 4, 0
|
||||
thumb_func_end FontData_delete
|
||||
|
||||
thumb_func_start FontData_ModeSwitch
|
||||
FontData_ModeSwitch: ; 0x02025ED8
|
||||
push {r4, r5, r6, lr}
|
||||
add r5, r0, #0
|
||||
add r4, r1, #0
|
||||
ldr r1, [r5]
|
||||
add r6, r2, #0
|
||||
cmp r1, r4
|
||||
beq _02025EF4
|
||||
bl FreeLoadedFontResources
|
||||
add r0, r5, #0
|
||||
add r1, r4, #0
|
||||
add r2, r6, #0
|
||||
bl InitFontResources
|
||||
_02025EF4:
|
||||
pop {r4, r5, r6, pc}
|
||||
.balign 4, 0
|
||||
thumb_func_end FontData_ModeSwitch
|
||||
|
||||
thumb_func_start FontData_Init
|
||||
FontData_Init: ; 0x02025EF8
|
||||
push {r4, r5, r6, lr}
|
||||
add r5, r0, #0
|
||||
add r0, r1, #0
|
||||
ldr r1, [sp, #0x10]
|
||||
add r4, r2, #0
|
||||
add r6, r3, #0
|
||||
bl NARC_ctor
|
||||
str r0, [r5, #0x54]
|
||||
cmp r0, #0
|
||||
beq _02025FA4
|
||||
add r2, r5, #0
|
||||
add r1, r4, #0
|
||||
add r2, #0x78
|
||||
bl NARC_GetMemberImageStartOffset
|
||||
add r3, r5, #0
|
||||
ldr r0, [r5, #0x54]
|
||||
ldr r1, [r5, #0x78]
|
||||
mov r2, #0x10
|
||||
add r3, #0x5c
|
||||
bl NARC_ReadFromAbsolutePos
|
||||
str r6, [r5, #0x6c]
|
||||
cmp r6, #0
|
||||
beq _02025F36
|
||||
mov r0, #0
|
||||
str r0, [r5, #0x74]
|
||||
ldr r0, _02025FA8 ; =GetGlyphWidth_FixedWidth
|
||||
str r0, [r5, #0x70]
|
||||
b _02025F5E
|
||||
_02025F36:
|
||||
ldr r0, [r5, #0x60]
|
||||
cmp r0, #0
|
||||
bne _02025F40
|
||||
bl GF_AssertFail
|
||||
_02025F40:
|
||||
ldr r0, [sp, #0x10]
|
||||
ldr r1, [r5, #0x64]
|
||||
bl AllocFromHeap
|
||||
str r0, [r5, #0x74]
|
||||
ldr r0, _02025FAC ; =GetGlyphWidth_VariableWidth
|
||||
str r0, [r5, #0x70]
|
||||
ldr r2, [r5, #0x78]
|
||||
ldr r1, [r5, #0x60]
|
||||
ldr r0, [r5, #0x54]
|
||||
add r1, r2, r1
|
||||
ldr r2, [r5, #0x64]
|
||||
ldr r3, [r5, #0x74]
|
||||
bl NARC_ReadFromAbsolutePos
|
||||
_02025F5E:
|
||||
add r0, r5, #0
|
||||
add r0, #0x6a
|
||||
ldrb r0, [r0]
|
||||
cmp r0, #2
|
||||
bhi _02025F72
|
||||
add r0, r5, #0
|
||||
add r0, #0x6b
|
||||
ldrb r0, [r0]
|
||||
cmp r0, #2
|
||||
bls _02025F76
|
||||
_02025F72:
|
||||
bl GF_AssertFail
|
||||
_02025F76:
|
||||
add r0, r5, #0
|
||||
add r0, #0x6a
|
||||
ldrb r0, [r0]
|
||||
ldr r2, _02025FB0 ; =_020F6324
|
||||
sub r0, r0, #1
|
||||
lsl r3, r0, #1
|
||||
add r0, r5, #0
|
||||
add r0, #0x6b
|
||||
ldrb r0, [r0]
|
||||
sub r1, r0, #1
|
||||
add r0, r2, r3
|
||||
ldrb r0, [r1, r0]
|
||||
str r0, [r5, #8]
|
||||
add r0, r5, #0
|
||||
add r0, #0x6b
|
||||
ldrb r1, [r0]
|
||||
add r0, r5, #0
|
||||
add r0, #0x6a
|
||||
ldrb r0, [r0]
|
||||
lsl r0, r0, #4
|
||||
mul r0, r1
|
||||
str r0, [r5, #0xc]
|
||||
str r4, [r5, #0x58]
|
||||
_02025FA4:
|
||||
pop {r4, r5, r6, pc}
|
||||
nop
|
||||
_02025FA8: .word GetGlyphWidth_FixedWidth
|
||||
_02025FAC: .word GetGlyphWidth_VariableWidth
|
||||
_02025FB0: .word _020F6324
|
||||
thumb_func_end FontData_Init
|
||||
|
||||
thumb_func_start FontData_FreeWidthsAndNarc
|
||||
FontData_FreeWidthsAndNarc: ; 0x02025FB4
|
||||
push {r4, lr}
|
||||
add r4, r0, #0
|
||||
ldr r0, [r4, #0x74]
|
||||
cmp r0, #0
|
||||
beq _02025FC2
|
||||
bl FreeToHeap
|
||||
_02025FC2:
|
||||
ldr r0, [r4, #0x54]
|
||||
cmp r0, #0
|
||||
beq _02025FCC
|
||||
bl NARC_dtor
|
||||
_02025FCC:
|
||||
pop {r4, pc}
|
||||
.balign 4, 0
|
||||
thumb_func_end FontData_FreeWidthsAndNarc
|
||||
|
||||
thumb_func_start InitFontResources
|
||||
InitFontResources: ; 0x02025FD0
|
||||
push {r3, lr}
|
||||
add r3, r1, #0
|
||||
add r1, r2, #0
|
||||
str r3, [r0]
|
||||
ldr r2, _02025FE4 ; =_020F6328
|
||||
lsl r3, r3, #2
|
||||
ldr r2, [r2, r3]
|
||||
blx r2
|
||||
pop {r3, pc}
|
||||
nop
|
||||
_02025FE4: .word _020F6328
|
||||
thumb_func_end InitFontResources
|
||||
|
||||
thumb_func_start InitFontResources_FromPreloaded
|
||||
InitFontResources_FromPreloaded: ; 0x02025FE8
|
||||
push {r3, r4, r5, lr}
|
||||
add r5, r0, #0
|
||||
ldr r2, [r5, #0xc]
|
||||
ldr r0, [r5, #0x64]
|
||||
add r4, r2, #0
|
||||
mul r4, r0
|
||||
add r0, r1, #0
|
||||
add r1, r4, #0
|
||||
bl AllocFromHeap
|
||||
str r0, [r5, #0x10]
|
||||
ldr r0, _02026014 ; =DecompressGlyphTiles_FromPreloaded
|
||||
add r3, r4, #0
|
||||
str r0, [r5, #4]
|
||||
ldr r0, [r5, #0x10]
|
||||
str r0, [sp]
|
||||
ldr r0, [r5, #0x54]
|
||||
ldr r1, [r5, #0x58]
|
||||
ldr r2, [r5, #0x5c]
|
||||
bl NARC_ReadFromMember
|
||||
pop {r3, r4, r5, pc}
|
||||
.balign 4, 0
|
||||
_02026014: .word DecompressGlyphTiles_FromPreloaded
|
||||
thumb_func_end InitFontResources_FromPreloaded
|
||||
|
||||
thumb_func_start InitFontResources_LazyFromNarc
|
||||
InitFontResources_LazyFromNarc: ; 0x02026018
|
||||
ldr r1, _02026020 ; =DecompressGlyphTiles_LazyFromNarc
|
||||
str r1, [r0, #4]
|
||||
bx lr
|
||||
nop
|
||||
_02026020: .word DecompressGlyphTiles_LazyFromNarc
|
||||
thumb_func_end InitFontResources_LazyFromNarc
|
||||
|
||||
thumb_func_start FreeLoadedFontResources
|
||||
FreeLoadedFontResources: ; 0x02026024
|
||||
push {r3, lr}
|
||||
ldr r1, [r0]
|
||||
lsl r2, r1, #2
|
||||
ldr r1, _02026034 ; =_020F6330
|
||||
ldr r1, [r1, r2]
|
||||
blx r1
|
||||
pop {r3, pc}
|
||||
nop
|
||||
_02026034: .word _020F6330
|
||||
thumb_func_end FreeLoadedFontResources
|
||||
|
||||
thumb_func_start FreeLoadedFontResources_FromPreloaded
|
||||
FreeLoadedFontResources_FromPreloaded: ; 0x02026038
|
||||
push {r4, lr}
|
||||
add r4, r0, #0
|
||||
ldr r0, [r4, #0x10]
|
||||
bl FreeToHeap
|
||||
mov r0, #0
|
||||
str r0, [r4, #0x10]
|
||||
pop {r4, pc}
|
||||
thumb_func_end FreeLoadedFontResources_FromPreloaded
|
||||
|
||||
thumb_func_start FreeLoadedFontResources_LazyFromNarc
|
||||
FreeLoadedFontResources_LazyFromNarc: ; 0x02026048
|
||||
bx lr
|
||||
.balign 4, 0
|
||||
thumb_func_end FreeLoadedFontResources_LazyFromNarc
|
||||
|
||||
thumb_func_start TryLoadGlyph
|
||||
TryLoadGlyph: ; 0x0202604C
|
||||
push {r3, lr}
|
||||
ldr r3, [r0, #0x64]
|
||||
cmp r1, r3
|
||||
bhi _0202605C
|
||||
sub r1, r1, #1
|
||||
lsl r1, r1, #0x10
|
||||
lsr r1, r1, #0x10
|
||||
b _0202605E
|
||||
_0202605C:
|
||||
ldr r1, _02026064 ; =0x000001AB
|
||||
_0202605E:
|
||||
ldr r3, [r0, #4]
|
||||
blx r3
|
||||
pop {r3, pc}
|
||||
.balign 4, 0
|
||||
_02026064: .word 0x000001AB
|
||||
thumb_func_end TryLoadGlyph
|
||||
|
||||
thumb_func_start DecompressGlyphTiles_FromPreloaded
|
||||
DecompressGlyphTiles_FromPreloaded: ; 0x02026068
|
||||
push {r3, r4, r5, r6, r7, lr}
|
||||
str r1, [sp]
|
||||
add r7, r0, #0
|
||||
ldr r0, [sp]
|
||||
ldr r1, [r7, #0xc]
|
||||
add r5, r0, #0
|
||||
ldr r0, [r7, #8]
|
||||
add r6, r2, #0
|
||||
mul r5, r1
|
||||
ldr r4, [r7, #0x10]
|
||||
cmp r0, #3
|
||||
bhi _020260F6
|
||||
add r0, r0, r0
|
||||
add r0, pc
|
||||
ldrh r0, [r0, #6]
|
||||
lsl r0, r0, #0x10
|
||||
asr r0, r0, #0x10
|
||||
add pc, r0
|
||||
_0202608C: ; jump table
|
||||
.short _02026094 - _0202608C - 2 ; case 0
|
||||
.short _0202609E - _0202608C - 2 ; case 1
|
||||
.short _020260B4 - _0202608C - 2 ; case 2
|
||||
.short _020260CA - _0202608C - 2 ; case 3
|
||||
_02026094:
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
bl DecompressGlyphTile
|
||||
b _020260F6
|
||||
_0202609E:
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
add r0, #0x10
|
||||
add r1, #0x40
|
||||
bl DecompressGlyphTile
|
||||
b _020260F6
|
||||
_020260B4:
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
add r0, #0x10
|
||||
add r1, #0x20
|
||||
bl DecompressGlyphTile
|
||||
b _020260F6
|
||||
_020260CA:
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
add r0, #0x10
|
||||
add r1, #0x20
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
add r0, #0x20
|
||||
add r1, #0x40
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, r5
|
||||
add r1, r6, #0
|
||||
add r0, #0x30
|
||||
add r1, #0x60
|
||||
bl DecompressGlyphTile
|
||||
_020260F6:
|
||||
ldr r1, [sp]
|
||||
ldr r2, [r7, #0x70]
|
||||
add r0, r7, #0
|
||||
blx r2
|
||||
add r1, r6, #0
|
||||
add r1, #0x80
|
||||
add r7, #0x69
|
||||
strb r0, [r1]
|
||||
ldrb r0, [r7]
|
||||
add r6, #0x81
|
||||
strb r0, [r6]
|
||||
pop {r3, r4, r5, r6, r7, pc}
|
||||
.balign 4, 0
|
||||
thumb_func_end DecompressGlyphTiles_FromPreloaded
|
||||
|
||||
thumb_func_start DecompressGlyphTiles_LazyFromNarc
|
||||
DecompressGlyphTiles_LazyFromNarc: ; 0x02026110
|
||||
push {r4, r5, r6, lr}
|
||||
add r4, r0, #0
|
||||
add r6, r1, #0
|
||||
add r5, r2, #0
|
||||
ldr r3, [r4, #0x78]
|
||||
ldr r1, [r4, #0x5c]
|
||||
ldr r2, [r4, #0xc]
|
||||
add r3, r3, r1
|
||||
add r1, r6, #0
|
||||
mul r1, r2
|
||||
add r1, r3, r1
|
||||
add r3, r4, #0
|
||||
ldr r0, [r4, #0x54]
|
||||
add r3, #0x14
|
||||
bl NARC_ReadFromAbsolutePos
|
||||
ldr r0, [r4, #8]
|
||||
cmp r0, #3
|
||||
bhi _020261B4
|
||||
add r0, r0, r0
|
||||
add r0, pc
|
||||
ldrh r0, [r0, #6]
|
||||
lsl r0, r0, #0x10
|
||||
asr r0, r0, #0x10
|
||||
add pc, r0
|
||||
_02026142: ; jump table
|
||||
.short _0202614A - _02026142 - 2 ; case 0
|
||||
.short _02026156 - _02026142 - 2 ; case 1
|
||||
.short _0202616E - _02026142 - 2 ; case 2
|
||||
.short _02026186 - _02026142 - 2 ; case 3
|
||||
_0202614A:
|
||||
add r0, r4, #0
|
||||
add r0, #0x14
|
||||
add r1, r5, #0
|
||||
bl DecompressGlyphTile
|
||||
b _020261B4
|
||||
_02026156:
|
||||
add r0, r4, #0
|
||||
add r0, #0x14
|
||||
add r1, r5, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, #0
|
||||
add r1, r5, #0
|
||||
add r0, #0x24
|
||||
add r1, #0x40
|
||||
bl DecompressGlyphTile
|
||||
b _020261B4
|
||||
_0202616E:
|
||||
add r0, r4, #0
|
||||
add r0, #0x14
|
||||
add r1, r5, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, #0
|
||||
add r1, r5, #0
|
||||
add r0, #0x24
|
||||
add r1, #0x20
|
||||
bl DecompressGlyphTile
|
||||
b _020261B4
|
||||
_02026186:
|
||||
add r0, r4, #0
|
||||
add r0, #0x14
|
||||
add r1, r5, #0
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, #0
|
||||
add r1, r5, #0
|
||||
add r0, #0x24
|
||||
add r1, #0x20
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, #0
|
||||
add r1, r5, #0
|
||||
add r0, #0x34
|
||||
add r1, #0x40
|
||||
bl DecompressGlyphTile
|
||||
add r0, r4, #0
|
||||
add r1, r5, #0
|
||||
add r0, #0x44
|
||||
add r1, #0x60
|
||||
bl DecompressGlyphTile
|
||||
_020261B4:
|
||||
ldr r2, [r4, #0x70]
|
||||
add r0, r4, #0
|
||||
add r1, r6, #0
|
||||
blx r2
|
||||
add r1, r5, #0
|
||||
add r1, #0x80
|
||||
add r4, #0x69
|
||||
strb r0, [r1]
|
||||
ldrb r0, [r4]
|
||||
add r5, #0x81
|
||||
strb r0, [r5]
|
||||
pop {r4, r5, r6, pc}
|
||||
thumb_func_end DecompressGlyphTiles_LazyFromNarc
|
||||
|
||||
thumb_func_start GetStringWidth
|
||||
GetStringWidth: ; 0x020261CC
|
||||
push {r3, r4, r5, r6, r7, lr}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef POKEHEARTGOLD_UNK_02025E88_H
|
||||
#define POKEHEARTGOLD_UNK_02025E88_H
|
||||
#ifndef POKEHEARTGOLD_FONT_DATA_H
|
||||
#define POKEHEARTGOLD_FONT_DATA_H
|
||||
|
||||
#include "filesystem.h"
|
||||
#include "font_types_def.h"
|
||||
@ -7,7 +7,7 @@
|
||||
#define FONTARC_MODE_DIRECT 0
|
||||
#define FONTARC_MODE_LAZY 1
|
||||
|
||||
struct FontData *FontData_new(NarcId narcId, int fileId, int mode, int vwf, HeapID heapId);
|
||||
struct FontData *FontData_new(NarcId narcId, int fileId, int mode, BOOL isFixedWidth, HeapID heapId);
|
||||
void FontData_ModeSwitch(struct FontData *fontData, int mode, HeapID heapId);
|
||||
void FontData_delete(struct FontData *fontData);
|
||||
void TryLoadGlyph(struct FontData *fontData, u16 glyphId, struct GlyphInfo *dest);
|
||||
@ -17,4 +17,4 @@ u32 GetStringWidthMultiline(struct FontData *fontData, const u16 *string, u32 le
|
||||
u32 GetGlyphWidth(struct FontData *fontData, u16 glyph);
|
||||
BOOL StringAllCharsValid(struct FontData *fontData, const u16 *string);
|
||||
|
||||
#endif //POKEHEARTGOLD_UNK_02025E88_H
|
||||
#endif //POKEHEARTGOLD_FONT_DATA_H
|
1
main.lsf
1
main.lsf
@ -79,6 +79,7 @@ Static main
|
||||
Object src/error_handling.o
|
||||
Object asm/unk_02025534.o
|
||||
Object asm/unk_02025C44.o
|
||||
Object src/font_data.o
|
||||
Object asm/unk_02025E88.o
|
||||
Object src/pm_string.o
|
||||
Object asm/unk_02026C44.o
|
||||
|
14
src/font.c
14
src/font.c
@ -1,7 +1,7 @@
|
||||
#include "font.h"
|
||||
#include "text.h"
|
||||
#include "gf_gfx_loader.h"
|
||||
#include "unk_02025E88.h"
|
||||
#include "font_data.h"
|
||||
#include "render_text.h"
|
||||
|
||||
struct FontWork {
|
||||
@ -14,12 +14,12 @@ struct FontWork {
|
||||
static struct FontWork *_0211188C = NULL;
|
||||
|
||||
static const u16 _020F56C0[][2] = {
|
||||
{0x0000, 0x0000},
|
||||
{0x0001, 0x0000},
|
||||
{0x0002, 0x0000},
|
||||
{0x0003, 0x0000},
|
||||
{0x0004, 0x0000},
|
||||
{0x000A, 0x0000},
|
||||
{0x0000, FALSE},
|
||||
{0x0001, FALSE},
|
||||
{0x0002, FALSE},
|
||||
{0x0003, FALSE},
|
||||
{0x0004, FALSE},
|
||||
{0x000A, FALSE},
|
||||
};
|
||||
|
||||
static const struct FontInfo _020F56D8[] = {
|
||||
|
204
src/font_data.c
Normal file
204
src/font_data.c
Normal file
@ -0,0 +1,204 @@
|
||||
#include "font_data.h"
|
||||
|
||||
enum GlyphShape {
|
||||
GLYPHSHAPE_8x8,
|
||||
GLYPHSHAPE_8x16,
|
||||
GLYPHSHAPE_16x8,
|
||||
GLYPHSHAPE_16x16,
|
||||
};
|
||||
|
||||
struct FontHeader {
|
||||
u32 headerSize;
|
||||
u32 widthDataStart;
|
||||
u32 numGlyphs;
|
||||
u8 fixedWidth;
|
||||
u8 fixedHeight;
|
||||
u8 glyphWidth;
|
||||
u8 glyphHeight;
|
||||
};
|
||||
|
||||
struct FontData {
|
||||
u32 glyphAccessMode;
|
||||
void (*uncompGlyphFunc)(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret);
|
||||
enum GlyphShape glyphShape;
|
||||
u32 glyphSize;
|
||||
void *narcReadBuf;
|
||||
u8 glyphReadBuf[0x40];
|
||||
NARC *narc;
|
||||
u32 fileId;
|
||||
struct FontHeader header;
|
||||
BOOL isFixedWidthFont;
|
||||
u32 (*glyphWidthFunc)(struct FontData *fontData, int glyphId);
|
||||
u8 *glyphWidths;
|
||||
u32 gmifOffset;
|
||||
};
|
||||
|
||||
void FontData_Init(struct FontData *fontData, NarcId narcId, int fileId, BOOL isFixedWidth, HeapID heapId);
|
||||
void FontData_FreeWidthsAndNarc(struct FontData *fontData);
|
||||
void InitFontResources(struct FontData *fontData, int mode, HeapID heapId);
|
||||
void InitFontResources_FromPreloaded(struct FontData *fontData, HeapID heapId);
|
||||
void InitFontResources_LazyFromNarc(struct FontData *fontData, HeapID heapId);
|
||||
void FreeLoadedFontResources(struct FontData *fontData);
|
||||
void FreeLoadedFontResources_FromPreloaded(struct FontData *fontData);
|
||||
void FreeLoadedFontResources_LazyFromNarc(struct FontData *fontData);
|
||||
void DecompressGlyphTiles_FromPreloaded(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret);
|
||||
void DecompressGlyphTile(const u8 *src, u8 *dest);
|
||||
u32 GetGlyphWidth_FixedWidth(struct FontData *fontData, int glyphId);
|
||||
u32 GetGlyphWidth_VariableWidth(struct FontData *fontData, int glyphId);
|
||||
void DecompressGlyphTiles_LazyFromNarc(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret);
|
||||
|
||||
struct FontData *FontData_new(NarcId narcId, int fileId, int mode, BOOL isFixedWidth, HeapID heapId) {
|
||||
struct FontData *ret;
|
||||
|
||||
ret = AllocFromHeap(heapId, sizeof(struct FontData));
|
||||
if (ret != NULL) {
|
||||
FontData_Init(ret, narcId, fileId, isFixedWidth, heapId);
|
||||
InitFontResources(ret, mode, heapId);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FontData_delete(struct FontData *fontData) {
|
||||
FreeLoadedFontResources(fontData);
|
||||
FontData_FreeWidthsAndNarc(fontData);
|
||||
FreeToHeap(fontData);
|
||||
}
|
||||
|
||||
void FontData_ModeSwitch(struct FontData *fontData, int mode, HeapID heapId) {
|
||||
if (fontData->glyphAccessMode != mode) {
|
||||
FreeLoadedFontResources(fontData);
|
||||
InitFontResources(fontData, mode, heapId);
|
||||
}
|
||||
}
|
||||
|
||||
void FontData_Init(struct FontData *fontData, NarcId narcId, int fileId, BOOL isFixedWidth, HeapID heapId) {
|
||||
static const u8 _020F6324[][2] = {
|
||||
{0, 1},
|
||||
{2, 3}
|
||||
};
|
||||
fontData->narc = NARC_ctor(narcId, heapId);
|
||||
if (fontData->narc != NULL) {
|
||||
NARC_GetMemberImageStartOffset(fontData->narc, fileId, &fontData->gmifOffset);
|
||||
NARC_ReadFromAbsolutePos(fontData->narc, fontData->gmifOffset, sizeof(struct FontHeader), &fontData->header);
|
||||
fontData->isFixedWidthFont = isFixedWidth;
|
||||
if (isFixedWidth) {
|
||||
fontData->glyphWidths = NULL;
|
||||
fontData->glyphWidthFunc = GetGlyphWidth_FixedWidth;
|
||||
} else {
|
||||
GF_ASSERT(fontData->header.widthDataStart != 0);
|
||||
fontData->glyphWidths = AllocFromHeap(heapId, fontData->header.numGlyphs);
|
||||
fontData->glyphWidthFunc = GetGlyphWidth_VariableWidth;
|
||||
NARC_ReadFromAbsolutePos(fontData->narc, fontData->gmifOffset + fontData->header.widthDataStart, fontData->header.numGlyphs, fontData->glyphWidths);
|
||||
}
|
||||
GF_ASSERT(fontData->header.glyphWidth <= 2 && fontData->header.glyphHeight <= 2);
|
||||
fontData->glyphShape = _020F6324[fontData->header.glyphWidth - 1][fontData->header.glyphHeight - 1];
|
||||
fontData->glyphSize = 16 * fontData->header.glyphWidth * fontData->header.glyphHeight;
|
||||
fontData->fileId = fileId;
|
||||
}
|
||||
}
|
||||
|
||||
void FontData_FreeWidthsAndNarc(struct FontData *fontData) {
|
||||
if (fontData->glyphWidths != NULL) {
|
||||
FreeToHeap(fontData->glyphWidths);
|
||||
}
|
||||
if (fontData->narc != NULL) {
|
||||
NARC_dtor(fontData->narc);
|
||||
}
|
||||
}
|
||||
|
||||
void InitFontResources(struct FontData *fontData, int mode, HeapID heapId) {
|
||||
static void (*const _020F6328[])(struct FontData *fontData, HeapID heapId) = {
|
||||
InitFontResources_FromPreloaded,
|
||||
InitFontResources_LazyFromNarc,
|
||||
};
|
||||
fontData->glyphAccessMode = mode;
|
||||
_020F6328[mode](fontData, heapId);
|
||||
}
|
||||
|
||||
void InitFontResources_FromPreloaded(struct FontData *fontData, HeapID heapId) {
|
||||
u32 size = fontData->glyphSize * fontData->header.numGlyphs;
|
||||
fontData->narcReadBuf = AllocFromHeap(heapId, size);
|
||||
fontData->uncompGlyphFunc = DecompressGlyphTiles_FromPreloaded;
|
||||
NARC_ReadFromMember(fontData->narc, fontData->fileId, fontData->header.headerSize, size, fontData->narcReadBuf);
|
||||
}
|
||||
|
||||
void InitFontResources_LazyFromNarc(struct FontData *fontData, HeapID heapId) {
|
||||
fontData->uncompGlyphFunc = DecompressGlyphTiles_LazyFromNarc;
|
||||
}
|
||||
|
||||
void FreeLoadedFontResources(struct FontData *fontData) {
|
||||
static void (*const _020F6330[])(struct FontData *fontData) = {
|
||||
FreeLoadedFontResources_FromPreloaded,
|
||||
FreeLoadedFontResources_LazyFromNarc,
|
||||
};
|
||||
_020F6330[fontData->glyphAccessMode](fontData);
|
||||
}
|
||||
|
||||
void FreeLoadedFontResources_FromPreloaded(struct FontData *fontData) {
|
||||
FreeToHeap(fontData->narcReadBuf);
|
||||
fontData->narcReadBuf = NULL;
|
||||
}
|
||||
|
||||
void FreeLoadedFontResources_LazyFromNarc(struct FontData *fontData) {
|
||||
#pragma unused(fontData)
|
||||
}
|
||||
|
||||
void TryLoadGlyph(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret) {
|
||||
if (glyphId <= fontData->header.numGlyphs) {
|
||||
glyphId--;
|
||||
} else {
|
||||
glyphId = 428 - 1;
|
||||
}
|
||||
fontData->uncompGlyphFunc(fontData, glyphId, ret);
|
||||
}
|
||||
|
||||
void DecompressGlyphTiles_FromPreloaded(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret) {
|
||||
u32 offset = glyphId * fontData->glyphSize;
|
||||
u8 *tileData = fontData->narcReadBuf;
|
||||
switch (fontData->glyphShape) {
|
||||
case GLYPHSHAPE_8x8:
|
||||
DecompressGlyphTile(tileData + offset + 0, ret->data + 0);
|
||||
break;
|
||||
case GLYPHSHAPE_8x16:
|
||||
DecompressGlyphTile(tileData + offset + 0, ret->data + 0);
|
||||
DecompressGlyphTile(tileData + offset + 0x10, ret->data + 0x40);
|
||||
break;
|
||||
case GLYPHSHAPE_16x8:
|
||||
DecompressGlyphTile(tileData + offset + 0, ret->data + 0);
|
||||
DecompressGlyphTile(tileData + offset + 0x10, ret->data + 0x20);
|
||||
break;
|
||||
case GLYPHSHAPE_16x16:
|
||||
DecompressGlyphTile(tileData + offset + 0, ret->data + 0);
|
||||
DecompressGlyphTile(tileData + offset + 0x10, ret->data + 0x20);
|
||||
DecompressGlyphTile(tileData + offset + 0x20, ret->data + 0x40);
|
||||
DecompressGlyphTile(tileData + offset + 0x30, ret->data + 0x60);
|
||||
break;
|
||||
}
|
||||
ret->width = fontData->glyphWidthFunc(fontData, glyphId);
|
||||
ret->height = fontData->header.fixedHeight;
|
||||
}
|
||||
|
||||
void DecompressGlyphTiles_LazyFromNarc(struct FontData *fontData, u16 glyphId, struct GlyphInfo *ret) {
|
||||
NARC_ReadFromAbsolutePos(fontData->narc, fontData->gmifOffset + fontData->header.headerSize + glyphId * fontData->glyphSize, fontData->glyphSize, fontData->glyphReadBuf);
|
||||
switch (fontData->glyphShape) {
|
||||
case GLYPHSHAPE_8x8:
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0, ret->data + 0);
|
||||
break;
|
||||
case GLYPHSHAPE_8x16:
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0, ret->data + 0);
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0x10, ret->data + 0x40);
|
||||
break;
|
||||
case GLYPHSHAPE_16x8:
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0, ret->data + 0);
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0x10, ret->data + 0x20);
|
||||
break;
|
||||
case GLYPHSHAPE_16x16:
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0, ret->data + 0);
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0x10, ret->data + 0x20);
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0x20, ret->data + 0x40);
|
||||
DecompressGlyphTile(fontData->glyphReadBuf + 0x30, ret->data + 0x60);
|
||||
break;
|
||||
}
|
||||
ret->width = fontData->glyphWidthFunc(fontData, glyphId);
|
||||
ret->height = fontData->header.fixedHeight;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user