1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin OS ROM font API
3   File:     OSFont.h
4 
5   Copyright 2001, 2002, 2004 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: OSFont.h,v $
14   Revision 1.2  2006/02/04 11:56:47  hashida
15   (none)
16 
17   Revision 1.1.1.1  2005/12/29 06:53:28  hiratsu
18   Initial import.
19 
20   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
21   transitioned from the Dolphin source tree
22 
23 
24     5     3/11/04 14:52 Shiki
25     Added OSANSItoUTF32() and OSSJIStoUTF32().
26 
27     4     3/10/04 17:51:00 Shiki
28     Added support for UTF code.
29 
30     3     8/05/02 18:04:00 Shiki
31     Added const keywords to relevant function prototypes.
32 
33     2     4/25/01 14:25 Shiki
34     Modified OSGetFontWidth() interface.
35 
36     1     4/19/01 13:27 Shiki
37     Initial check-in.
38   $NoKeywords: $
39  *---------------------------------------------------------------------------*/
40 
41 #ifndef __OSFONT_H__
42 #define __OSFONT_H__
43 
44 #include <revolution/types.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 typedef struct OSFontHeader
51 {
52     u16 fontType;       // font type
53     u16 firstChar;      // the first character code defined in the font
54     u16 lastChar;       // the last character code defined in the font
55     u16 invalChar;      // the font code to be substituted for invalid characters
56     u16 ascent;         // the ascent (units above the base line) of characters
57     u16 descent;        // the descent (units below the base line) of characters
58     u16 width;          // the width of the widest character
59     u16 leading;        // the leading (space) between rows
60 
61     u16 cellWidth;      // the cell (a single character) width in a sheet
62     u16 cellHeight;     // the cell (a single character) height in a sheet
63     u32 sheetSize;      // the size of a sheet in bytes
64     u16 sheetFormat;    // the texture format of a sheet (GX_TF_*)
65     u16 sheetColumn;    // the number of characters in a row
66     u16 sheetRow;       // the number of lines in a sheet
67     u16 sheetWidth;     // the sheet width (texture width)
68     //32B
69 
70     u16 sheetHeight;    // the sheet height (texture height)
71     u16 widthTable;     // offset to character width table (const)
72 
73     u32 sheetImage;     // offset to sheet image
74     u32 sheetFullSize;  // the size of all sheets
75 
76     u8  c0;             // font color table
77     u8  c1;
78     u8  c2;
79     u8  c3;
80     // 48B
81 } OSFontHeader;
82 
83 //
84 // Common functions
85 //
86 
87 // For OSGetFontEncode()
88 #define OS_FONT_ENCODE_ANSI     0u
89 #define OS_FONT_ENCODE_SJIS     1u
90 #define OS_FONT_ENCODE_UTF8     3u  // UTF-8 [RFC 3629]
91 #define OS_FONT_ENCODE_UTF16    4u  // UTF-16BE [RFC 2781]
92 #define OS_FONT_ENCODE_UTF32    5u  // UTF-32
93 #define OS_FONT_ENCODE_MAX      5u
94 #define OS_FONT_ENCODE_VOID     0xffffu
95 
96 #define OS_FONT_PROPORTIONAL    FALSE
97 #define OS_FONT_FIXED           TRUE
98 
99 u16   OSGetFontEncode ( void );
100 u16   OSSetFontEncode ( u16 encode );
101 
102 char* OSGetFontWidth  ( const char* string, s32* width );
103 
104 //
105 // High level functions
106 //
107 
108 // For OSInitFont(fontData)
109 #define OS_FONT_SIZE_ANSI       ( 288 +  131072)    // 1 sheet
110 #define OS_FONT_SIZE_SJIS       (3840 + 1179648)    // 9 sheets
111 #define OS_FONT_SIZE_UTF        (OS_FONT_SIZE_ANSI + OS_FONT_SIZE_SJIS)
112 
113 BOOL  OSInitFont      ( OSFontHeader* fontData );
114 char* OSGetFontTexture( const char* string, void** image, s32 *x, s32 *y, s32* width );
115 
116 //
117 // Low level functions
118 //
119 
120 // For OSLoadFont(*, temp)
121 #define OS_FONT_ROM_SIZE_ANSI   12288   // 0x03000
122 #define OS_FONT_ROM_SIZE_SJIS   315392  // 0x4D000
123 #define OS_FONT_ROM_SIZE_UTF    OS_FONT_ROM_SIZE_SJIS
124 
125 // For OSLoadFont(fontData, *)
126 #define OS_FONT_DATA_SIZE_ANSI  65824
127 #define OS_FONT_DATA_SIZE_SJIS  593636
128 #define OS_FONT_DATA_SIZE_UTF   (OS_FONT_DATA_SIZE_ANSI + OS_FONT_DATA_SIZE_SJIS)
129 
130 u32   OSLoadFont      ( OSFontHeader* fontData, void* temp );
131 char* OSGetFontTexel  ( const char* string, void* image, s32 pos, s32 stride, s32* width );
132 
133 //
134 // UTF functions
135 //
136 char* OSUTF32to8   ( u32 utf32, char* utf8 );
137 char* OSUTF8to32   ( const char* utf8, u32* utf32 );
138 
139 u16*  OSUTF32to16  ( u32 utf32, u16* utf16 );
140 u16*  OSUTF16to32  ( const u16* utf16, u32* utf32 );
141 
142 u8    OSUTF32toANSI( u32 utf32 );
143 u32   OSANSItoUTF32( u8 ansi );
144 
145 u16   OSUTF32toSJIS( u32 utf32 );
146 u32   OSSJIStoUTF32( u16 sjis );
147 
148 BOOL  OSSetFontWidth( BOOL fixed );
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif // __OSFONT_H__
155