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