1 /*---------------------------------------------------------------------------* 2 Project: font library 3 File: fnt.h 4 5 Copyright (C) 2006 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Log: fnt.h,v $ 14 Revision 1.1 2006/10/18 02:49:26 nishida_yasunari 15 Initial check in. 16 17 $NoKeywords: $ 18 *---------------------------------------------------------------------------*/ 19 20 #ifndef __FNT_H__ 21 #define __FNT_H__ 22 23 #include <revolution/types.h> 24 #include <revolution/gx/GXEnum.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define FNT_RESOURCE_HEADER_SIZE (16 * 1024) 31 32 typedef enum 33 { 34 FNT_CONSTRUCT_MORE_DATA, 35 FNT_CONSTRUCT_FINISH, 36 FNT_CONSTRUCT_ERROR, 37 FNT_CONSTRUCT_CONTINUE, // internal use 38 FNT_MAX_CONSTRUCT_RESULT 39 } FNTConstructResult; 40 41 typedef enum 42 { 43 FNT_ENCODING_UTF8, // UTF-8 44 FNT_ENCODING_UTF16, // UTF-16 45 FNT_ENCODING_SJIS, // ShiftJIS 46 FNT_ENCODING_CP1252, // CP1252 47 FNT_MAX_ENCODING 48 } FNTEncoding; 49 50 typedef struct 51 { 52 void* buffer; // pointer to font buffer 53 void* info; // pointer to font information (in buffer) 54 u16* adjust; // glyph index adjust array (in buffer) 55 u32 bufferSize; // font buffer size 56 u8 encoding; // encoding for string 57 u8 padding_[3]; 58 //20B 59 u32 construct[108/4]; // construct context 60 //128B 61 u8 bufferTop[]; // font buffer top 62 } FNTHeader; 63 64 typedef struct 65 { 66 void* image; // pointer to texture iamge sheet 67 s8 left; // left space width 68 u8 glyphWidth; // glyph width 69 s8 charWidth; // character width = left + glyphWidth + right space wdith 70 u8 charHeight; // character height 71 GXTexFmt texFormat; // texture image sheet format 72 u16 texWidth; // texture image sheet width (texels) 73 u16 texHeight; // texture image sheet height (texels) 74 u16 cellX; // horizontal position in texture image 75 u16 cellY; // vertical position in texture image 76 } FNTTexture; 77 78 typedef struct 79 { 80 u8 width; // width (for TAB & scale standard) 81 u8 height; // height 82 u8 maxCharWidth; // max character width 83 u8 ascent; // ascent 84 u8 descent; // descent 85 s8 baselinePos; // base line position 86 s8 leading; // leading (line feed) 87 u8 cellWidth; // cell width (max glyph wdith) 88 u8 cellHeight; // cell height 89 u16 texWidth; // texture image sheet width (texels) 90 u16 texHeight; // texture image sheet height (texels) 91 } FNTMetrics; 92 93 // init functions 94 u32 FNTGetDataSize( void* resource ); 95 BOOL FNTConstruct( FNTHeader* font, void* resource ); 96 void FNTInitStreamingConstruct( FNTHeader* font, u32 dataSize ); 97 FNTConstructResult FNTStreamingConstruct( 98 FNTHeader* font, 99 void* stream, 100 u32 streamSize); 101 102 // texture functions 103 char* FNTGetTexture( 104 const FNTHeader* font, 105 const char* string, 106 FNTTexture* tex ); 107 GXTexFmt FNTGetTextureFormat( const FNTHeader* font ); 108 109 // metrics functions 110 char* FNTGetWidth( const FNTHeader* font, const char* string, s32* width ); 111 void FNTGetMetrics( const FNTHeader* font, FNTMetrics* metrics ); 112 113 // encoding functions 114 FNTEncoding FNTGetEncoding( const FNTHeader* font ); 115 FNTEncoding FNTSetEncoding( FNTHeader* font, FNTEncoding encoding ); 116 117 #ifdef __cplusplus 118 } 119 #endif 120 121 #endif // __FNT_H__ 122