/*---------------------------------------------------------------------------* Project: NintendoWare File: font_CharStrmReader.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include namespace nw { namespace font { namespace internal { #if defined(NW_FONT_UNREFERENCE) const u32 SJIS_LOW_WIDTH = 0xBC; const u32 SJIS_LOW_BASE = 0x40; #endif const u32 SJIS_HIGH0_ST = 0x81; #if defined(NW_FONT_UNREFERENCE) const u32 SJIS_HIGH0_ED = 0x85; const u32 SJIS_HIGH1_ST = 0x87; const u32 SJIS_HIGH1_ED = 0x88; const u32 SJIS_HIGH2_ST = 0x88; #endif const u32 SJIS_HIGH2_ED = 0xA0; const u32 SJIS_HIGH3_ST = 0xE0; #if defined(NW_FONT_UNREFERENCE) const u32 SJIS_HIGH3_ED = 0x100; const u32 ASCII_ST = 0x20; const u32 ASCII_ED = 0x80; const u32 SJIS_HANKANA_ST = 0xA0; const u32 SJIS_HANKANA_ED = 0xE0; #endif /*!--------------------------------------------------------------------------* @brief 対象のバイトがSJIS文字のリードバイトがどうか判定します。 @param[in] c 判定対象のバイトデータ。 @return c がリードバイトなら true そうでなければ false。 *---------------------------------------------------------------------------*/ inline bool IsSJISLeadByte(u8 c) { return ((SJIS_HIGH0_ST <= c) && (c < SJIS_HIGH2_ED)) || (SJIS_HIGH3_ST <= c); } } // namespace internal u16 CharStrmReader::ReadNextCharUTF8() { NN_POINTER_ASSERT( this ); NN_POINTER_ASSERT( mCharStrm ); //---- UTF-8 の1バイト目の条件 NN_ASSERT( (GetChar() & 0xC0) != 0x80 ); u16 code; if( (GetChar() & 0x80) == 0x00 ) { //---- 1バイト文字 code = GetChar(); StepStrm(); } else if( (GetChar() & 0xE0) == 0xC0 ) { //---- 2バイト文字 code = static_cast( ((GetChar(0) & 0x1F) << 6) | ((GetChar(1) & 0x3F) << 0) ); StepStrm(2); } else { //---- 4バイト以上には対応しない NN_ASSERT( (GetChar() & 0xF0) == 0xE0 ); //---- 3バイト文字 code = static_cast( ((GetChar(0) & 0x1F) << 12) | ((GetChar(1) & 0x3F) << 6) | ((GetChar(2) & 0x3F) << 0) ); StepStrm(3); } return code; } u16 CharStrmReader::ReadNextCharUTF16() { NN_POINTER_ASSERT( this ); NN_POINTER_ASSERT( mCharStrm ); NN_ALIGN_ASSERT (mCharStrm, 2); u16 code; code = GetChar(); StepStrm(); return code; } u16 CharStrmReader::ReadNextCharCP1252() { NN_POINTER_ASSERT( this ); NN_POINTER_ASSERT( mCharStrm ); u16 code; code = GetChar(); StepStrm(); return code; } u16 CharStrmReader::ReadNextCharSJIS() { NN_POINTER_ASSERT( this ); NN_POINTER_ASSERT( mCharStrm ); u16 code; if (internal::IsSJISLeadByte(GetChar())) { //---- 2バイト文字 code = static_cast((GetChar(0) << 8) | GetChar(1)); StepStrm(2); } else { //---- 1バイト文字 code = GetChar(); StepStrm(); } return code; } } // namespace font } // namespace nw