From ff830fad556e78e7eb927d19e96fd024224551c4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 28 Jan 2003 00:45:01 +0000 Subject: [PATCH] only use longchar within fonts --- stepmania/src/BitmapText.cpp | 6 +++--- stepmania/src/BitmapText.h | 2 +- stepmania/src/Font.cpp | 25 ++++++++++++----------- stepmania/src/Font.h | 10 +++++----- stepmania/src/FontCharAliases.cpp | 8 ++++---- stepmania/src/FontCharAliases.h | 2 +- stepmania/src/FontManager.cpp | 11 ++++++----- stepmania/src/FontManager.h | 4 ++-- stepmania/src/RageUtil.cpp | 33 ++++++++++++++++--------------- stepmania/src/RageUtil.h | 13 +++++------- stepmania/src/ScreenTextEntry.cpp | 6 +++--- stepmania/src/ScreenTextEntry.h | 2 +- 12 files changed, 62 insertions(+), 60 deletions(-) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index fae4b6820b..cab53330f9 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -163,7 +163,7 @@ void BitmapText::BuildChars() for( i=0; iGetHeight(); - const lstring &szLine = m_szTextLines[i]; + const wstring &szLine = m_szTextLines[i]; const int iLineWidth = m_iLineWidths[i]; int iX; @@ -232,8 +232,8 @@ void BitmapText::SetText( CString sText ) m_szTextLines.clear(); m_iLineWidths.clear(); - lstring s; s+='\n'; - split(CStringToLstring(sText), s, m_szTextLines, false); + wstring s; s+=L'\n'; + split(CStringToWstring(sText), s, m_szTextLines, false); BuildChars(); } diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index e0e9681987..87d44b99b2 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -47,7 +47,7 @@ protected: // recalculate the items below on SetText() CString m_szText; - vector m_szTextLines; + vector m_szTextLines; vector m_iLineWidths; // in source pixels int m_iWidestLineWidth; // in source pixels diff --git a/stepmania/src/Font.cpp b/stepmania/src/Font.cpp index 0f8698c3bf..ef6179d97f 100644 --- a/stepmania/src/Font.cpp +++ b/stepmania/src/Font.cpp @@ -25,7 +25,8 @@ #include "FontCharmaps.h" #include "FontCharAliases.h" -const longchar Font::DEFAULT_GLYPH = 0xFFFFFF; +/* Last private-use Unicode character: */ +const wchar_t Font::DEFAULT_GLYPH = 0xF8FF; FontPage::FontPage() { @@ -192,7 +193,7 @@ FontPage::~FontPage() TEXTUREMAN->UnloadTexture( m_pTexture ); } -int Font::GetLineWidthInSourcePixels( const lstring &szLine ) const +int Font::GetLineWidthInSourcePixels( const wstring &szLine ) const { int LineWidth = 0; @@ -202,7 +203,7 @@ int Font::GetLineWidthInSourcePixels( const lstring &szLine ) const return LineWidth; } -int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const +int Font::GetLineHeightInSourcePixels( const wstring &szLine ) const { int iLineHeight = 0; @@ -213,7 +214,7 @@ int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const return iLineHeight; } -int Font::GetLineSpacingInSourcePixels( const lstring &szLine ) const +int Font::GetLineSpacingInSourcePixels( const wstring &szLine ) const { int iLineSpacing = 0; @@ -292,7 +293,7 @@ void Font::MergeFont(Font &f) f.pages.clear(); } -const glyph &Font::GetGlyph( longchar c ) const +const glyph &Font::GetGlyph( wchar_t c ) const { ASSERT(c >= 0 && c <= 0xFFFFFF); @@ -523,16 +524,18 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri if(codepoint.substr(0, 2) == "U+" && IsHexVal(codepoint.substr(2))) sscanf(codepoint.substr(2).c_str(), "%x", &c); else + { c = FontCharAliases::GetChar(codepoint); - if(c == -1) - { - LOG->Warn("Font definition '%s' has an invalid value '%s'.", - ini.GetPath().GetString(), val.GetString() ); - continue; + if(c == INVALID_CHAR) + { + LOG->Warn("Font definition '%s' has an invalid value '%s'.", + ini.GetPath().GetString(), val.GetString() ); + continue; + } } - if(game != GAME_INVALID) c = FontManager::MakeGameGlyph(c, game); + if(game != GAME_INVALID) c = FontManager::MakeGameGlyph(wchar_t(c), game); cfg.CharToGlyphNo[c] = atoi(data); continue; diff --git a/stepmania/src/Font.h b/stepmania/src/Font.h index ab874438a1..fb37e1bee6 100644 --- a/stepmania/src/Font.h +++ b/stepmania/src/Font.h @@ -104,11 +104,11 @@ public: Font(); ~Font(); - const glyph &GetGlyph( longchar c ) const; + const glyph &GetGlyph( wchar_t c ) const; - int GetLineWidthInSourcePixels( const lstring &szLine ) const; - int GetLineHeightInSourcePixels( const lstring &szLine ) const; - int GetLineSpacingInSourcePixels( const lstring &szLine ) const; + int GetLineWidthInSourcePixels( const wstring &szLine ) const; + int GetLineHeightInSourcePixels( const wstring &szLine ) const; + int GetLineSpacingInSourcePixels( const wstring &szLine ) const; /* Add a FontPage to this font. */ void AddPage(FontPage *fp); @@ -129,7 +129,7 @@ public: void SetDefaultGlyph(FontPage *fp); - static const longchar DEFAULT_GLYPH; + static const wchar_t DEFAULT_GLYPH; static CString GetFontName(CString FileName); /* Remove filenames in 'v' that aren't in the same font as "FileName". */ diff --git a/stepmania/src/FontCharAliases.cpp b/stepmania/src/FontCharAliases.cpp index d90d0be097..39d4833f01 100644 --- a/stepmania/src/FontCharAliases.cpp +++ b/stepmania/src/FontCharAliases.cpp @@ -7,7 +7,7 @@ #include /* Map from "&foo;" to a UTF-8 string. */ -typedef map aliasmap; +typedef map aliasmap; static aliasmap CharAliases; static map CharAliasRepl; @@ -335,7 +335,7 @@ static void InitCharAliases() for(aliasmap::const_iterator i = CharAliases.begin(); i != CharAliases.end(); ++i) { CString from = ssprintf("&%s;", i->first.GetString()); - CString to = LcharToUTF8(i->second); + CString to = WcharToUTF8(i->second); from.MakeUpper(); CharAliasRepl[from] = to; } @@ -350,12 +350,12 @@ void FontCharAliases::ReplaceMarkers( CString &sText ) } /* Replace all &markers; and &#NNNN;s with UTF-8. */ -longchar FontCharAliases::GetChar( CString &codepoint ) +wchar_t FontCharAliases::GetChar( CString &codepoint ) { InitCharAliases(); aliasmap::const_iterator i = CharAliases.find(codepoint); if(i == CharAliases.end()) - return longchar(-1); + return INVALID_CHAR; return i->second; } diff --git a/stepmania/src/FontCharAliases.h b/stepmania/src/FontCharAliases.h index 8040d13fab..d91df44dd2 100644 --- a/stepmania/src/FontCharAliases.h +++ b/stepmania/src/FontCharAliases.h @@ -5,7 +5,7 @@ namespace FontCharAliases { void ReplaceMarkers( CString &sText ); - longchar GetChar( CString &codepoint ); + wchar_t GetChar( CString &codepoint ); }; #endif diff --git a/stepmania/src/FontManager.cpp b/stepmania/src/FontManager.cpp index d5241b7428..6f510beccf 100644 --- a/stepmania/src/FontManager.cpp +++ b/stepmania/src/FontManager.cpp @@ -37,19 +37,20 @@ FontManager::~FontManager() } /* A longchar is at least 32 bits. If c & 0xFF000000, it's a game-custom - * character; game 0 is 0x01nnnnnn, game 1 is 0x02nnnnnn, and so on. */ -longchar FontManager::MakeGameGlyph(longchar c, Game g) + * character; game 0 is 0x0100nnnn, game 1 is 0x0200nnnn, and so on. */ +longchar FontManager::MakeGameGlyph(wchar_t c, Game g) { - ASSERT(g >= 0 && g <= 0xFF && c >= 0 && c <= 0xFFFF); + ASSERT(c >= 0 && c <= 0xFFFF); + ASSERT(g >= 0 && g <= 0xFF); return longchar (((g+1) << 24) + c); } -bool FontManager::ExtractGameGlyph(longchar ch, int &c, Game &g) +bool FontManager::ExtractGameGlyph(longchar ch, wchar_t &c, Game &g) { if((ch & 0xFF000000) == 0) return false; /* not a game glyph */ g = Game((ch >> 24) - 1); - c = ch & 0xFFFFFF; + c = wchar_t(ch & 0xFFFF); return true; } diff --git a/stepmania/src/FontManager.h b/stepmania/src/FontManager.h index ef207d91a5..9656590ca3 100644 --- a/stepmania/src/FontManager.h +++ b/stepmania/src/FontManager.h @@ -36,8 +36,8 @@ public: * adjustment of fonts in ScreenTestFonts at the moment. */ void ReloadFonts(); - static longchar MakeGameGlyph(longchar c, Game g); - static bool ExtractGameGlyph(longchar ch, int &c, Game &g); + static longchar MakeGameGlyph(wchar_t c, Game g); + static bool ExtractGameGlyph(longchar ch, wchar_t &c, Game &g); protected: // map from file name to a texture holder diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 465fe9bf5e..0b50cd5bb4 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -179,7 +179,7 @@ void split( const CString &Source, const CString &Deliminator, CStringArray &Add do_split(Source, Deliminator, AddIt, bIgnoreEmpty ); } -void split( const lstring &Source, const lstring &Deliminator, vector &AddIt, const bool bIgnoreEmpty ) +void split( const wstring &Source, const wstring &Deliminator, vector &AddIt, const bool bIgnoreEmpty ) { do_split(Source, Deliminator, AddIt, bIgnoreEmpty ); } @@ -706,18 +706,17 @@ int utf8_get_char_len (const char *pp) return -1; } -longchar utf8_get_char (const char *p) +wchar_t utf8_get_char (const char *p) { int len = utf8_get_char_len(p); if(len == -1) - return 0xFFFF; + return INVALID_CHAR; int mask = masks[len]; - - longchar result = longchar(p[0] & mask); + wchar_t result = wchar_t(p[0] & mask); for (int i = 1; i < len; ++i) { if ((p[i] & 0xc0) != 0x80) - return (longchar) -1; + return INVALID_CHAR; result <<= 6; result |= p[i] & 0x3f; @@ -726,17 +725,17 @@ longchar utf8_get_char (const char *p) return result; } -const longchar INVALID_CHAR = 0xFFFF; +const wchar_t INVALID_CHAR = 0xFFFF; -lstring CStringToLstring(const CString &str) +wstring CStringToWstring(const CString &str) { const char *ptr = str.c_str(), *end = str.c_str()+str.size(); - lstring ret; + wstring ret; while(ptr && ptr != end) { - longchar c = utf8_get_char (ptr); + wchar_t c = utf8_get_char (ptr); if(c == -1) ret += INVALID_CHAR; else @@ -747,17 +746,17 @@ lstring CStringToLstring(const CString &str) return ret; } -CString LStringToCString(const lstring &str) +CString WStringToCString(const wstring &str) { CString ret; for(unsigned i = 0; i < str.size(); ++i) - ret.append(LcharToUTF8(str[i])); + ret.append(WcharToUTF8(str[i])); return ret; } -int unichar_to_utf8 (longchar c, char *outbuf) +static int unichar_to_utf8 (wchar_t c, char *outbuf) { unsigned int len = 0; int first; @@ -795,7 +794,7 @@ int unichar_to_utf8 (longchar c, char *outbuf) return len; } -CString LcharToUTF8( longchar c ) +CString WcharToUTF8( wchar_t c ) { char buf[6]; int cnt = unichar_to_utf8(c, buf); @@ -874,8 +873,10 @@ void Replace_Unicode_Markers( CString &Text ) int num; if(hex) sscanf(Text.c_str()+pos, "&x%x;", &num); else sscanf(Text.c_str()+pos, "&#%i;", &num); - - Text.replace(pos, p-pos, LcharToUTF8(num)); + if(num > 0xFFFF) + num = INVALID_CHAR; + + Text.replace(pos, p-pos, WcharToUTF8(wchar_t(num))); } } diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 546ce9187c..37c4efc3dd 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -144,15 +144,12 @@ void splitrelpath( CString& Ext ); -/* This is our version of wchar_t. We work in UCS4, and wchar_t may only - * be 16-bit. This is mostly used within the font and text system. */ typedef int longchar; -typedef basic_string lstring; -extern const longchar INVALID_CHAR; +extern const wchar_t INVALID_CHAR; -lstring CStringToLstring(const CString &str); -CString LStringToCString(const lstring &str); -CString LcharToUTF8( longchar c ); +CString WStringToCString(const wstring &str); +CString WcharToUTF8( wchar_t c ); +wstring CStringToWstring(const CString &str); // Splits a CString into an CStringArray according the Deliminator. void split( @@ -161,7 +158,7 @@ void split( CStringArray& AddIt, const bool bIgnoreEmpty = true ); -void split( const lstring &Source, const lstring &Deliminator, vector &AddIt, const bool bIgnoreEmpty = true ); +void split( const wstring &Source, const wstring &Deliminator, vector &AddIt, const bool bIgnoreEmpty = true ); // Joins a CStringArray to create a CString according the Deliminator. CString join(const CString &Deliminator, const CStringArray& Source); diff --git a/stepmania/src/ScreenTextEntry.cpp b/stepmania/src/ScreenTextEntry.cpp index f016d23f21..543d75039b 100644 --- a/stepmania/src/ScreenTextEntry.cpp +++ b/stepmania/src/ScreenTextEntry.cpp @@ -41,7 +41,7 @@ ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuesti m_pOnOK = OnOK; m_pOnCancel = OnCancel; - m_sAnswer = CStringToLstring(sInitialAnswer); + m_sAnswer = CStringToWstring(sInitialAnswer); m_bCancelled = false; m_Fade.SetTransitionTime( 0.5f ); @@ -73,7 +73,7 @@ ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuesti void ScreenTextEntry::UpdateText() { - CString txt = LStringToCString(m_sAnswer); + CString txt = WStringToCString(m_sAnswer); FontCharAliases::ReplaceMarkers(txt); m_textAnswer.SetText( txt ); } @@ -205,7 +205,7 @@ void ScreenTextEntry::MenuStart( PlayerNumber pn ) } else { if( m_pOnOK ) { - CString ret = LStringToCString(m_sAnswer); + CString ret = WStringToCString(m_sAnswer); FontCharAliases::ReplaceMarkers(ret); m_pOnOK( ret ); } diff --git a/stepmania/src/ScreenTextEntry.h b/stepmania/src/ScreenTextEntry.h index abb8a5fc36..c744a87d51 100644 --- a/stepmania/src/ScreenTextEntry.h +++ b/stepmania/src/ScreenTextEntry.h @@ -40,7 +40,7 @@ protected: TransitionFade m_Fade; BitmapText m_textQuestion; Quad m_rectAnswerBox; - lstring m_sAnswer; + wstring m_sAnswer; BitmapText m_textAnswer; ScreenMessage m_SMSendWhenDone; void(*m_pOnOK)( CString sAnswer );