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.3  2008/06/25 07:17:00  yoshioka_yasuhiro
15   Added texture tiling functions.
16 
17   Revision 1.2  2008/04/14 04:31:59  yoshioka_yasuhiro
18   Added FNTSetAlternateChar().
19 
20   Revision 1.1  2006/10/18 02:49:26  nishida_yasunari
21   Initial check in.
22 
23   $NoKeywords: $
24  *---------------------------------------------------------------------------*/
25 
26 #ifndef __FNT_H__
27 #define __FNT_H__
28 
29 #include <revolution/types.h>
30 #include <revolution/gx/GXEnum.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define FNT_RESOURCE_HEADER_SIZE    (16 * 1024)
37 
38 typedef enum
39 {
40     FNT_CONSTRUCT_MORE_DATA,
41     FNT_CONSTRUCT_FINISH,
42     FNT_CONSTRUCT_ERROR,
43     FNT_CONSTRUCT_CONTINUE,     // Internal use
44     FNT_MAX_CONSTRUCT_RESULT
45 } FNTConstructResult;
46 
47 typedef enum
48 {
49     FNT_ENCODING_UTF8,          // UTF-8
50     FNT_ENCODING_UTF16,         // UTF-16
51     FNT_ENCODING_SJIS,          // ShiftJIS
52     FNT_ENCODING_CP1252,        // CP1252
53     FNT_MAX_ENCODING
54 } FNTEncoding;
55 
56 typedef struct
57 {
58     void*   buffer;             // Pointer to font buffer
59     void*   info;               // Pointer to font information (in buffer)
60     u16*    adjust;             // Glyph index adjust array (in buffer)
61     u32     bufferSize;         // Font buffer size
62     u8      encoding;           // Encoding for string
63     u8      padding_[1];
64     u16     alterCharIndex;     // Index of alternative character
65     //20B
66     u32     construct[108/4];   // Construct context
67     //128B
68     u8      bufferTop[];        // Font buffer top
69 } FNTHeader;
70 
71 typedef struct
72 {
73     void*       image;      // Pointer to texture image sheet
74     s8          left;       // Left space width
75     u8          glyphWidth; // Glyph width
76     s8          charWidth;  // Character width = left + glyphWidth + right space width
77     u8          charHeight; // Character height
78     GXTexFmt    texFormat;  // Texture image sheet format
79     u16         texWidth;   // Texture image sheet width  (texels)
80     u16         texHeight;  // Texture image sheet height (texels)
81     u16         cellX;      // Horizontal position in texture image
82     u16         cellY;      // Vertical position in texture image
83 } FNTTexture;
84 
85 typedef struct
86 {
87     u8  width;          // Width (for TAB & scale standard)
88     u8  height;         // height
89     u8  maxCharWidth;   // Max character width
90     u8  ascent;         // Ascent
91     u8  descent;        // Descent
92     s8  baselinePos;    // Base line position
93     s8  leading;        // Leading (line feed)
94     u8  cellWidth;      // Cell width (max glyph width)
95     u8  cellHeight;     // Cell height
96     u16 texWidth;       // Texture image sheet width (texels)
97     u16 texHeight;      // Texture image sheet height (texels)
98 } FNTMetrics;
99 
100 // Init functions
101 u32 FNTGetDataSize( void* resource );
102 BOOL FNTConstruct( FNTHeader* font, void* resource );
103 void FNTInitStreamingConstruct( FNTHeader* font, u32 dataSize );
104 FNTConstructResult FNTStreamingConstruct(
105     FNTHeader* font,
106     void* stream,
107     u32 streamSize);
108 
109 // Texture functions
110 char* FNTGetTexture(
111     const FNTHeader* font,
112     const char* string,
113     FNTTexture* tex );
114 GXTexFmt FNTGetTextureFormat( const FNTHeader* font );
115 
116 // Metrics functions
117 char* FNTGetWidth( const FNTHeader* font, const char* string, s32* width );
118 void FNTGetMetrics( const FNTHeader* font, FNTMetrics* metrics );
119 
120 // Encoding functions
121 FNTEncoding FNTGetEncoding( const FNTHeader* font );
122 FNTEncoding FNTSetEncoding( FNTHeader* font, FNTEncoding encoding );
123 
124 // Alternate character function
125 BOOL FNTSetAlternateChar( FNTHeader* font, const char* string );
126 
127 // Texture tiling functions
128 u32 FNTGetTileBufferSize(const FNTHeader* font);
129 void FNTUntileTexture(FNTHeader* font, void* buf);
130 void FNTTileTexture(FNTHeader* font, void* buf);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif // __FNT_H__
137