1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: font_ResourceFormat.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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 $Revision: 23012 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_FONT_RESOURCEFORMAT_H_ 17 #define NW_FONT_RESOURCEFORMAT_H_ 18 19 #if defined(_MSC_VER) && _MSC_VER >= 1500 20 #pragma once 21 #endif 22 23 #include <nn/types.h> 24 #include <nw/ut/ut_BinaryFileFormat.h> 25 26 27 #ifdef _MSC_VER // for VC 28 #pragma warning( disable: 4200 ) 29 #pragma warning( disable: 4201 ) 30 #endif //_MSC_VER 31 32 33 34 namespace nw { 35 namespace font { 36 37 38 const int GlyphDataAlignment = 128; 39 40 41 /* ------------------------------------------------------------------------ 42 シグネチャ定義 43 ------------------------------------------------------------------------ */ 44 45 // 通常フォントリソースファイルシグネチャ 46 const ut::SigWord BINFILE_SIG_FONT = NW_UT_MAKE_SIGWORD('C','F','N','T'); 47 48 // オフセット解決済みバイナリファイルシグネチャ 49 const ut::SigWord BINFILE_SIG_FONT_RESOLEVED = NW_UT_MAKE_SIGWORD('C','F','N','U'); 50 51 // アーカイブフォントリソースファイルシグネチャ 52 const ut::SigWord BINFILE_SIG_FONTA = NW_UT_MAKE_SIGWORD('C','F','N','A'); 53 54 // バイナリブロックシグネチャ 55 const ut::SigWord BINBLOCK_SIG_FINF = NW_UT_MAKE_SIGWORD('F','I','N','F'); 56 const ut::SigWord BINBLOCK_SIG_CGLP = NW_UT_MAKE_SIGWORD('C','G','L','P'); 57 const ut::SigWord BINBLOCK_SIG_TGLP = NW_UT_MAKE_SIGWORD('T','G','L','P'); 58 const ut::SigWord BINBLOCK_SIG_CWDH = NW_UT_MAKE_SIGWORD('C','W','D','H'); 59 const ut::SigWord BINBLOCK_SIG_CMAP = NW_UT_MAKE_SIGWORD('C','M','A','P'); 60 61 const ut::SigWord BINBLOCK_SIG_GLGR = NW_UT_MAKE_SIGWORD('G','L','G','R'); 62 const ut::SigWord BINBLOCK_SIG_HTGL = NW_UT_MAKE_SIGWORD('H','T','G','L'); 63 64 65 66 67 68 /* ------------------------------------------------------------------------ 69 リリースバージョン定義 70 ------------------------------------------------------------------------ */ 71 72 const u32 FONT_FILE_VERSION = NW_UT_MAKE_VERSION(3, 0, 0, 0); 73 74 75 76 /* ------------------------------------------------------------------------ 77 定数定義 78 ------------------------------------------------------------------------ */ 79 const u16 INVALID_CHAR_CODE = 0xFFFF; 80 const u16 INVALID_GLYPH_INDEX = 0xFFFF; 81 82 83 84 85 86 /* ------------------------------------------------------------------------ 87 enum定義 88 ------------------------------------------------------------------------ */ 89 90 /*---------------------------------------------------------------------------* 91 Name: FontType 92 93 Description: フォントタイプ 94 *---------------------------------------------------------------------------*/ 95 enum FontType 96 { 97 FONT_TYPE_GLYPH, // BMP 98 FONT_TYPE_TEXTURE, // Texture 99 NUM_OF_FONT_TYPE 100 }; 101 102 //--------------------------------------------------------------------------- 103 //! @brief 文字コード 104 //--------------------------------------------------------------------------- 105 enum CharacterCode 106 { 107 CHARACTER_CODE_UNICODE = 1, //!< Unicode 108 CHARACTER_CODE_SJIS, //!< ShiftJIS 109 CHARACTER_CODE_CP1252, //!< CP1252 110 111 CHARACTER_CODE_MAX 112 }; 113 114 /*---------------------------------------------------------------------------* 115 Name: FontMapMethod 116 117 Description: 文字コードマッピングタイプ 118 *---------------------------------------------------------------------------*/ 119 enum FontMapMethod 120 { 121 FONT_MAPMETHOD_DIRECT, // インデックス = 文字コード - オフセット 122 FONT_MAPMETHOD_TABLE, // インデックス = mapInfo[文字コード - オフセット] 123 FONT_MAPMETHOD_SCAN, // インデックス = search(mapInfo, 文字コード) 124 NUM_OF_FONT_MAPMETHOD 125 }; 126 127 128 /*---------------------------------------------------------------------------* 129 Name: FontSheetFormat 130 131 Description: シートの形式 (テクスチャフォーマット) 132 *---------------------------------------------------------------------------*/ 133 enum FontSheetFormat 134 { 135 FONT_SHEET_FORMAT_RGBA8, 136 FONT_SHEET_FORMAT_RGB8, 137 FONT_SHEET_FORMAT_RGB5A1, 138 FONT_SHEET_FORMAT_RGB565, 139 FONT_SHEET_FORMAT_RGBA4, 140 FONT_SHEET_FORMAT_LA8, 141 142 143 FONT_SHEET_FORMAT_A8 = 8, 144 FONT_SHEET_FORMAT_LA4, 145 146 FONT_SHEET_FORMAT_A4 = 11, 147 148 149 150 FONT_SHEET_FORMAT_MASK = 0x7FFF, 151 FONT_SHEET_FORMAT_COMPRESSED_FLAG = 0x8000 // 1 なら圧縮されている 152 }; 153 154 155 156 157 /* ------------------------------------------------------------------------ 158 構造体定義 159 ------------------------------------------------------------------------ */ 160 161 //--------------------------------------------------------------------------- 162 //! @brief 文字の各種幅を保持する構造体です。 163 //--------------------------------------------------------------------------- 164 struct CharWidths 165 { 166 s8 left; //!< 文字の左スペースの幅 167 u8 glyphWidth; //!< 文字のグリフ幅 168 s8 charWidth; //!< 文字の幅 = 左スペース幅 + グリフ幅 + 右スペース幅 169 }; 170 171 /*---------------------------------------------------------------------------* 172 Name: CMapScanEntry 173 174 Description: 文字コードとグリフインデックスペア 175 *---------------------------------------------------------------------------*/ 176 struct CMapScanEntry 177 { 178 u16 ccode; // 文字コード 179 u16 index; // グリフインデックス 180 }; 181 182 /*---------------------------------------------------------------------------* 183 Name: CMapInfoScan 184 185 Description: MAPMETHOD_SCAN の場合の FontCodeMap.mapInfo 186 *---------------------------------------------------------------------------*/ 187 struct CMapInfoScan 188 { 189 u16 num; // entries の要素数 GetEntriesCMapInfoScan190 CMapScanEntry* GetEntries() const // 文字コードからグリフインデックスへのマッピングリスト 191 { 192 return reinterpret_cast<CMapScanEntry*>( reinterpret_cast<uptr>(this) + sizeof(*this) ); 193 } 194 }; 195 196 197 198 199 200 /* ------------------------------------------------------------------------ 201 ブロック本体定義 202 ------------------------------------------------------------------------ */ 203 204 /*---------------------------------------------------------------------------* 205 Name: FontGlyphGroups 206 207 Description: フォントを部分ロードするための情報を格納します。 208 *---------------------------------------------------------------------------*/ 209 struct FontGlyphGroups 210 { 211 u32 sheetSize; 212 u16 glyphsPerSheet; 213 u16 numSet; 214 u16 numSheet; 215 u16 numCWDH; 216 u16 numCMAP; 217 218 u16 nameOffsets[1]; // numSet 219 /* 220 以下は可変長データが続きます 221 222 (4 byte align) 223 224 u32 sizeSheets[numSheet]; // 圧縮済みシートのサイズ 225 u32 sizeCWDH[numCWDH]; // CWDH ブロックのサイズ 226 u32 sizeCMAP[numCMAP]; // CMAP ブロックのサイズ 227 u32 useSheets[numSet][numSheet/32]; 228 u32 useCWDH[numSet][numCWDH/32]; 229 u32 useCMAP[numSet][numCMAP/32]; 230 231 char names[numSet][name length]; 232 */ 233 }; 234 235 236 237 /*---------------------------------------------------------------------------* 238 Name: FontTextureGlyph 239 240 Description: フォントのグリフテクスチャを格納します。 241 *---------------------------------------------------------------------------*/ 242 struct FontTextureGlyph 243 { 244 u8 cellWidth; // セル幅=最大グリフ幅 245 u8 cellHeight; // セル高さ 246 s8 baselinePos; // ベースライン位置 247 u8 maxCharWidth; // 最大文字幅 248 u32 sheetSize; // テクスチャシートデータサイズ(byte単位) 249 u16 sheetNum; // シート数 250 u16 sheetFormat; // FontSheetFormat 251 u16 sheetRow; // シート内の横方向セル数 252 u16 sheetLine; // シート内の縦方向セル数 253 u16 sheetWidth; // シート幅(ピクセル単位) 254 u16 sheetHeight; // シート高さ(ピクセル単位) 255 u8* sheetImage; // テクスチャデータへのポインタ 256 }; 257 258 259 260 /*---------------------------------------------------------------------------* 261 Name: FontWidth 262 263 Description: 各文字の文字幅情報を格納します。 264 *---------------------------------------------------------------------------*/ 265 struct FontWidth 266 { 267 u16 indexBegin; // widthTable の最初のエントリが対応するグリフインデックス 268 u16 indexEnd; // widthTable の最後のエントリが対応するグリフインデックス 269 FontWidth* pNext; // 次の FontWidth へのポインタ GetWidthTableFontWidth270 CharWidths* GetWidthTable() const // 幅情報の配列 271 { 272 return reinterpret_cast<CharWidths*>( reinterpret_cast<uptr>(this) + sizeof(*this) ); 273 } 274 }; 275 276 277 278 /*---------------------------------------------------------------------------* 279 Name: FontCodeMap 280 281 Description: 文字コードから、文字コードに対応するグリフの 282 グリフイメージ配列中のインデックスへのマッピングを規定します。 283 *---------------------------------------------------------------------------*/ 284 struct FontCodeMap 285 { 286 u16 ccodeBegin; // このブロックが担当する文字コード範囲の最初の文字コード 287 u16 ccodeEnd; // このブロックが担当する文字コード範囲の最後の文字コード 288 u16 mappingMethod; // マッピング方法 (FontMappingMethod型) 289 u16 reserved; // 予約 290 FontCodeMap* pNext; // 次の FontCodeMap へのポインタ GetMapInfoFontCodeMap291 u16* GetMapInfo() const // 文字コードマッピング情報 具体的な内容は mappingMethod に依る 292 { 293 return reinterpret_cast<u16*>( reinterpret_cast<uptr>(this) + sizeof(*this) ); 294 } 295 }; 296 297 298 299 /*---------------------------------------------------------------------------* 300 Name: FontInformation 301 302 Description: フォント全体に渡る情報を格納します。 303 *---------------------------------------------------------------------------*/ 304 struct FontInformation 305 { 306 u8 fontType; // グリフデータタイプ (FontType型) 307 s8 linefeed; // (*)== leading 308 u16 alterCharIndex; // (*)フォントに含まれない文字用のグリフのグリフインデックス 309 CharWidths defaultWidth; // (*)文字幅情報を持たないグリフ用の文字幅情報 310 u8 characterCode; // 対応する文字コード (CharacterCode型) 311 FontTextureGlyph* pGlyph; // 唯一の FontGlyph へのポインタ 312 FontWidth* pWidth; // 最初の FontWidth へのポインタ 313 FontCodeMap* pMap; // 最初の FontCodeMap へのポインタ 314 u8 height; // フォントの高さ 315 u8 width; // フォントの幅 316 u8 ascent; // アセント 317 u8 padding_[1]; 318 }; 319 320 321 322 /* ------------------------------------------------------------------------ 323 ブロック定義 324 ------------------------------------------------------------------------ */ 325 326 /*---------------------------------------------------------------------------* 327 Name: BinaryBlock 328 329 Description: NintendoWare 標準バイナリブロック 330 *---------------------------------------------------------------------------*/ 331 template <typename BlockBodyType> 332 struct BinaryBlock 333 { 334 ut::BinaryBlockHeader header; // ブロックヘッダ 335 BlockBodyType body; // ブロック本体 336 }; 337 338 typedef BinaryBlock<FontGlyphGroups> FontGlyphGroupsBlock; 339 typedef BinaryBlock<FontInformation> FontInformationBlock; 340 typedef BinaryBlock<FontTextureGlyph> FontTextureGlyphBlock; 341 typedef BinaryBlock<FontWidth> FontWidthBlock; 342 typedef BinaryBlock<FontCodeMap> FontCodeMapBlock; 343 344 345 346 } // namespace font 347 } // namespace nw 348 349 350 #ifdef _MSC_VER 351 #pragma warning( default: 4200 ) 352 #pragma warning( default: 4201 ) 353 #endif //_MSC_VER 354 355 356 #endif // NW_FONT_RESOURCEFORMAT_H_ 357