/*---------------------------------------------------------------------------* Project: Horizon File: font_ResourceFormat.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 28630 $ *---------------------------------------------------------------------------*/ #ifndef NN_FONT_FONT_RESOURCE_FORMAT_H_ #define NN_FONT_FONT_RESOURCE_FORMAT_H_ #include #include namespace nn { namespace font { const int GlyphDataAlignment = 128; /* ------------------------------------------------------------------------ シグネチャ定義 ------------------------------------------------------------------------ */ // 通常フォントリソースファイルシグネチャ const detail::SigWord BINFILE_SIG_FONT = NN_FONT_MAKE_SIGWORD('C','F','N','T'); // オフセット解決済みバイナリファイルシグネチャ const detail::SigWord BINFILE_SIG_FONT_RESOLEVED = NN_FONT_MAKE_SIGWORD('C','F','N','U'); // アーカイブフォントリソースファイルシグネチャ const detail::SigWord BINFILE_SIG_FONTA = NN_FONT_MAKE_SIGWORD('C','F','N','A'); // バイナリブロックシグネチャ const detail::SigWord BINBLOCK_SIG_FINF = NN_FONT_MAKE_SIGWORD('F','I','N','F'); const detail::SigWord BINBLOCK_SIG_CGLP = NN_FONT_MAKE_SIGWORD('C','G','L','P'); const detail::SigWord BINBLOCK_SIG_TGLP = NN_FONT_MAKE_SIGWORD('T','G','L','P'); const detail::SigWord BINBLOCK_SIG_CWDH = NN_FONT_MAKE_SIGWORD('C','W','D','H'); const detail::SigWord BINBLOCK_SIG_CMAP = NN_FONT_MAKE_SIGWORD('C','M','A','P'); const detail::SigWord BINBLOCK_SIG_GLGR = NN_FONT_MAKE_SIGWORD('G','L','G','R'); const detail::SigWord BINBLOCK_SIG_HTGL = NN_FONT_MAKE_SIGWORD('H','T','G','L'); /* ------------------------------------------------------------------------ リリースバージョン定義 ------------------------------------------------------------------------ */ const u32 FONT_FILE_VERSION = NN_FONT_MAKE_VERSION(3, 0, 0, 0); /* ------------------------------------------------------------------------ 定数定義 ------------------------------------------------------------------------ */ const u16 INVALID_CHAR_CODE = 0xFFFF; const u16 INVALID_GLYPH_INDEX = 0xFFFF; /* ------------------------------------------------------------------------ enum定義 ------------------------------------------------------------------------ */ /*---------------------------------------------------------------------------* Name: FontType Description: フォントタイプ *---------------------------------------------------------------------------*/ enum FontType { FONT_TYPE_GLYPH, // BMP FONT_TYPE_TEXTURE, // Texture NUM_OF_FONT_TYPE }; //--------------------------------------------------------------------------- //! @brief 文字コード //--------------------------------------------------------------------------- enum CharacterCode { CHARACTER_CODE_UNICODE = 1, //!< Unicode CHARACTER_CODE_SJIS, //!< ShiftJIS CHARACTER_CODE_CP1252, //!< CP1252 CHARACTER_CODE_MAX }; /*---------------------------------------------------------------------------* Name: FontMapMethod Description: 文字コードマッピングタイプ *---------------------------------------------------------------------------*/ enum FontMapMethod { FONT_MAPMETHOD_DIRECT, // インデックス = 文字コード - オフセット FONT_MAPMETHOD_TABLE, // インデックス = mapInfo[文字コード - オフセット] FONT_MAPMETHOD_SCAN, // インデックス = search(mapInfo, 文字コード) NUM_OF_FONT_MAPMETHOD }; /*---------------------------------------------------------------------------* Name: FontSheetFormat Description: シートの形式 (テクスチャフォーマット) *---------------------------------------------------------------------------*/ enum FontSheetFormat { FONT_SHEET_FORMAT_RGBA8, FONT_SHEET_FORMAT_RGB8, FONT_SHEET_FORMAT_RGB5A1, FONT_SHEET_FORMAT_RGB565, FONT_SHEET_FORMAT_RGBA4, FONT_SHEET_FORMAT_LA8, FONT_SHEET_FORMAT_A8 = 8, FONT_SHEET_FORMAT_LA4, FONT_SHEET_FORMAT_A4 = 11, FONT_SHEET_FORMAT_MASK = 0x7FFF, FONT_SHEET_FORMAT_COMPRESSED_FLAG = 0x8000 // 1 なら圧縮されている }; /* ------------------------------------------------------------------------ 構造体定義 ------------------------------------------------------------------------ */ //--------------------------------------------------------------------------- //! @brief 文字の各種幅を保持する構造体です。 //--------------------------------------------------------------------------- struct CharWidths { s8 left; //!< 文字の左スペースの幅 u8 glyphWidth; //!< 文字のグリフ幅 s8 charWidth; //!< 文字の幅 = 左スペース幅 + グリフ幅 + 右スペース幅 }; /*---------------------------------------------------------------------------* Name: CMapScanEntry Description: 文字コードとグリフインデックスペア *---------------------------------------------------------------------------*/ struct CMapScanEntry { u16 ccode; // 文字コード u16 index; // グリフインデックス }; /*---------------------------------------------------------------------------* Name: CMapInfoScan Description: MAPMETHOD_SCAN の場合の FontCodeMap.mapInfo *---------------------------------------------------------------------------*/ struct CMapInfoScan { u16 num; // entries の要素数 CMapScanEntry* GetEntries() const // 文字コードからグリフインデックスへのマッピングリスト { return reinterpret_cast( reinterpret_cast(this) + sizeof(*this) ); } }; /* ------------------------------------------------------------------------ ブロック本体定義 ------------------------------------------------------------------------ */ /*---------------------------------------------------------------------------* Name: FontGlyphGroups Description: フォントを部分ロードするための情報を格納します。 *---------------------------------------------------------------------------*/ struct FontGlyphGroups { u32 sheetSize; u16 glyphsPerSheet; u16 numSet; u16 numSheet; u16 numCWDH; u16 numCMAP; u16 nameOffsets[1]; // numSet /* 以下は可変長データが続きます (4 byte align) u32 sizeSheets[numSheet]; // 圧縮済みシートのサイズ u32 sizeCWDH[numCWDH]; // CWDH ブロックのサイズ u32 sizeCMAP[numCMAP]; // CMAP ブロックのサイズ u32 useSheets[numSet][numSheet/32]; u32 useCWDH[numSet][numCWDH/32]; u32 useCMAP[numSet][numCMAP/32]; char names[numSet][name length]; */ }; /*---------------------------------------------------------------------------* Name: FontTextureGlyph Description: フォントのグリフテクスチャを格納します。 *---------------------------------------------------------------------------*/ struct FontTextureGlyph { u8 cellWidth; // セル幅=最大グリフ幅 u8 cellHeight; // セル高さ s8 baselinePos; // ベースライン位置 u8 maxCharWidth; // 最大文字幅 u32 sheetSize; // テクスチャシートデータサイズ(byte単位) u16 sheetNum; // シート数 u16 sheetFormat; // FontSheetFormat u16 sheetRow; // シート内の横方向セル数 u16 sheetLine; // シート内の縦方向セル数 u16 sheetWidth; // シート幅(ピクセル単位) u16 sheetHeight; // シート高さ(ピクセル単位) u8* sheetImage; // テクスチャデータへのポインタ }; /*---------------------------------------------------------------------------* Name: FontWidth Description: 各文字の文字幅情報を格納します。 *---------------------------------------------------------------------------*/ struct FontWidth { u16 indexBegin; // widthTable の最初のエントリが対応するグリフインデックス u16 indexEnd; // widthTable の最後のエントリが対応するグリフインデックス FontWidth* pNext; // 次の FontWidth へのポインタ CharWidths* GetWidthTable() const // 幅情報の配列 { return reinterpret_cast( reinterpret_cast(this) + sizeof(*this) ); } }; /*---------------------------------------------------------------------------* Name: FontCodeMap Description: 文字コードから、文字コードに対応するグリフの グリフイメージ配列中のインデックスへのマッピングを規定します。 *---------------------------------------------------------------------------*/ struct FontCodeMap { u16 ccodeBegin; // このブロックが担当する文字コード範囲の最初の文字コード u16 ccodeEnd; // このブロックが担当する文字コード範囲の最後の文字コード u16 mappingMethod; // マッピング方法 (FontMappingMethod型) u16 reserved; // 予約 FontCodeMap* pNext; // 次の FontCodeMap へのポインタ u16* GetMapInfo() const // 文字コードマッピング情報 具体的な内容は mappingMethod に依る { return reinterpret_cast( reinterpret_cast(this) + sizeof(*this) ); } }; /*---------------------------------------------------------------------------* Name: FontInformation Description: フォント全体に渡る情報を格納します。 *---------------------------------------------------------------------------*/ struct FontInformation { u8 fontType; // グリフデータタイプ (FontType型) s8 linefeed; // (*)== leading u16 alterCharIndex; // (*)フォントに含まれない文字用のグリフのグリフインデックス CharWidths defaultWidth; // (*)文字幅情報を持たないグリフ用の文字幅情報 u8 characterCode; // 対応する文字コード (CharacterCode型) FontTextureGlyph* pGlyph; // 唯一の FontGlyph へのポインタ FontWidth* pWidth; // 最初の FontWidth へのポインタ FontCodeMap* pMap; // 最初の FontCodeMap へのポインタ u8 height; // フォントの高さ u8 width; // フォントの幅 u8 ascent; // アセント u8 padding_[1]; }; /* ------------------------------------------------------------------------ ブロック定義 ------------------------------------------------------------------------ */ /*---------------------------------------------------------------------------* Name: BinaryBlock Description: NintendoWare 標準バイナリブロック *---------------------------------------------------------------------------*/ template struct BinaryBlock { detail::BinaryBlockHeader header; // ブロックヘッダ BlockBodyType body; // ブロック本体 }; typedef BinaryBlock FontGlyphGroupsBlock; typedef BinaryBlock FontInformationBlock; typedef BinaryBlock FontTextureGlyphBlock; typedef BinaryBlock FontWidthBlock; typedef BinaryBlock FontCodeMapBlock; } // namespace font } // namespace nn #endif // NN_FONT_FONT_RESOURCE_FORMAT_H_