only use longchar within fonts

This commit is contained in:
Glenn Maynard
2003-01-28 00:45:01 +00:00
parent 4003ac7ed9
commit ff830fad55
12 changed files with 62 additions and 60 deletions
+3 -3
View File
@@ -163,7 +163,7 @@ void BitmapText::BuildChars()
for( i=0; i<m_szTextLines.size(); i++ ) // foreach line for( i=0; i<m_szTextLines.size(); i++ ) // foreach line
{ {
iY += m_pFont->GetHeight(); iY += m_pFont->GetHeight();
const lstring &szLine = m_szTextLines[i]; const wstring &szLine = m_szTextLines[i];
const int iLineWidth = m_iLineWidths[i]; const int iLineWidth = m_iLineWidths[i];
int iX; int iX;
@@ -232,8 +232,8 @@ void BitmapText::SetText( CString sText )
m_szTextLines.clear(); m_szTextLines.clear();
m_iLineWidths.clear(); m_iLineWidths.clear();
lstring s; s+='\n'; wstring s; s+=L'\n';
split(CStringToLstring(sText), s, m_szTextLines, false); split(CStringToWstring(sText), s, m_szTextLines, false);
BuildChars(); BuildChars();
} }
+1 -1
View File
@@ -47,7 +47,7 @@ protected:
// recalculate the items below on SetText() // recalculate the items below on SetText()
CString m_szText; CString m_szText;
vector<lstring> m_szTextLines; vector<wstring> m_szTextLines;
vector<int> m_iLineWidths; // in source pixels vector<int> m_iLineWidths; // in source pixels
int m_iWidestLineWidth; // in source pixels int m_iWidestLineWidth; // in source pixels
+14 -11
View File
@@ -25,7 +25,8 @@
#include "FontCharmaps.h" #include "FontCharmaps.h"
#include "FontCharAliases.h" #include "FontCharAliases.h"
const longchar Font::DEFAULT_GLYPH = 0xFFFFFF; /* Last private-use Unicode character: */
const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
FontPage::FontPage() FontPage::FontPage()
{ {
@@ -192,7 +193,7 @@ FontPage::~FontPage()
TEXTUREMAN->UnloadTexture( m_pTexture ); TEXTUREMAN->UnloadTexture( m_pTexture );
} }
int Font::GetLineWidthInSourcePixels( const lstring &szLine ) const int Font::GetLineWidthInSourcePixels( const wstring &szLine ) const
{ {
int LineWidth = 0; int LineWidth = 0;
@@ -202,7 +203,7 @@ int Font::GetLineWidthInSourcePixels( const lstring &szLine ) const
return LineWidth; return LineWidth;
} }
int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const int Font::GetLineHeightInSourcePixels( const wstring &szLine ) const
{ {
int iLineHeight = 0; int iLineHeight = 0;
@@ -213,7 +214,7 @@ int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const
return iLineHeight; return iLineHeight;
} }
int Font::GetLineSpacingInSourcePixels( const lstring &szLine ) const int Font::GetLineSpacingInSourcePixels( const wstring &szLine ) const
{ {
int iLineSpacing = 0; int iLineSpacing = 0;
@@ -292,7 +293,7 @@ void Font::MergeFont(Font &f)
f.pages.clear(); f.pages.clear();
} }
const glyph &Font::GetGlyph( longchar c ) const const glyph &Font::GetGlyph( wchar_t c ) const
{ {
ASSERT(c >= 0 && c <= 0xFFFFFF); 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))) if(codepoint.substr(0, 2) == "U+" && IsHexVal(codepoint.substr(2)))
sscanf(codepoint.substr(2).c_str(), "%x", &c); sscanf(codepoint.substr(2).c_str(), "%x", &c);
else else
{
c = FontCharAliases::GetChar(codepoint); c = FontCharAliases::GetChar(codepoint);
if(c == -1) if(c == INVALID_CHAR)
{ {
LOG->Warn("Font definition '%s' has an invalid value '%s'.", LOG->Warn("Font definition '%s' has an invalid value '%s'.",
ini.GetPath().GetString(), val.GetString() ); ini.GetPath().GetString(), val.GetString() );
continue; 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); cfg.CharToGlyphNo[c] = atoi(data);
continue; continue;
+5 -5
View File
@@ -104,11 +104,11 @@ public:
Font(); Font();
~Font(); ~Font();
const glyph &GetGlyph( longchar c ) const; const glyph &GetGlyph( wchar_t c ) const;
int GetLineWidthInSourcePixels( const lstring &szLine ) const; int GetLineWidthInSourcePixels( const wstring &szLine ) const;
int GetLineHeightInSourcePixels( const lstring &szLine ) const; int GetLineHeightInSourcePixels( const wstring &szLine ) const;
int GetLineSpacingInSourcePixels( const lstring &szLine ) const; int GetLineSpacingInSourcePixels( const wstring &szLine ) const;
/* Add a FontPage to this font. */ /* Add a FontPage to this font. */
void AddPage(FontPage *fp); void AddPage(FontPage *fp);
@@ -129,7 +129,7 @@ public:
void SetDefaultGlyph(FontPage *fp); void SetDefaultGlyph(FontPage *fp);
static const longchar DEFAULT_GLYPH; static const wchar_t DEFAULT_GLYPH;
static CString GetFontName(CString FileName); static CString GetFontName(CString FileName);
/* Remove filenames in 'v' that aren't in the same font as "FileName". */ /* Remove filenames in 'v' that aren't in the same font as "FileName". */
+4 -4
View File
@@ -7,7 +7,7 @@
#include <map> #include <map>
/* Map from "&foo;" to a UTF-8 string. */ /* Map from "&foo;" to a UTF-8 string. */
typedef map<CString, longchar, StdStringLessNoCase> aliasmap; typedef map<CString, wchar_t, StdStringLessNoCase> aliasmap;
static aliasmap CharAliases; static aliasmap CharAliases;
static map<CString,CString> CharAliasRepl; static map<CString,CString> CharAliasRepl;
@@ -335,7 +335,7 @@ static void InitCharAliases()
for(aliasmap::const_iterator i = CharAliases.begin(); i != CharAliases.end(); ++i) for(aliasmap::const_iterator i = CharAliases.begin(); i != CharAliases.end(); ++i)
{ {
CString from = ssprintf("&%s;", i->first.GetString()); CString from = ssprintf("&%s;", i->first.GetString());
CString to = LcharToUTF8(i->second); CString to = WcharToUTF8(i->second);
from.MakeUpper(); from.MakeUpper();
CharAliasRepl[from] = to; CharAliasRepl[from] = to;
} }
@@ -350,12 +350,12 @@ void FontCharAliases::ReplaceMarkers( CString &sText )
} }
/* Replace all &markers; and &#NNNN;s with UTF-8. */ /* Replace all &markers; and &#NNNN;s with UTF-8. */
longchar FontCharAliases::GetChar( CString &codepoint ) wchar_t FontCharAliases::GetChar( CString &codepoint )
{ {
InitCharAliases(); InitCharAliases();
aliasmap::const_iterator i = CharAliases.find(codepoint); aliasmap::const_iterator i = CharAliases.find(codepoint);
if(i == CharAliases.end()) if(i == CharAliases.end())
return longchar(-1); return INVALID_CHAR;
return i->second; return i->second;
} }
+1 -1
View File
@@ -5,7 +5,7 @@
namespace FontCharAliases { namespace FontCharAliases {
void ReplaceMarkers( CString &sText ); void ReplaceMarkers( CString &sText );
longchar GetChar( CString &codepoint ); wchar_t GetChar( CString &codepoint );
}; };
#endif #endif
+6 -5
View File
@@ -37,19 +37,20 @@ FontManager::~FontManager()
} }
/* A longchar is at least 32 bits. If c & 0xFF000000, it's a game-custom /* 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. */ * character; game 0 is 0x0100nnnn, game 1 is 0x0200nnnn, and so on. */
longchar FontManager::MakeGameGlyph(longchar c, Game g) 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); 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 */ if((ch & 0xFF000000) == 0) return false; /* not a game glyph */
g = Game((ch >> 24) - 1); g = Game((ch >> 24) - 1);
c = ch & 0xFFFFFF; c = wchar_t(ch & 0xFFFF);
return true; return true;
} }
+2 -2
View File
@@ -36,8 +36,8 @@ public:
* adjustment of fonts in ScreenTestFonts at the moment. */ * adjustment of fonts in ScreenTestFonts at the moment. */
void ReloadFonts(); void ReloadFonts();
static longchar MakeGameGlyph(longchar c, Game g); static longchar MakeGameGlyph(wchar_t c, Game g);
static bool ExtractGameGlyph(longchar ch, int &c, Game &g); static bool ExtractGameGlyph(longchar ch, wchar_t &c, Game &g);
protected: protected:
// map from file name to a texture holder // map from file name to a texture holder
+16 -15
View File
@@ -179,7 +179,7 @@ void split( const CString &Source, const CString &Deliminator, CStringArray &Add
do_split(Source, Deliminator, AddIt, bIgnoreEmpty ); do_split(Source, Deliminator, AddIt, bIgnoreEmpty );
} }
void split( const lstring &Source, const lstring &Deliminator, vector<lstring> &AddIt, const bool bIgnoreEmpty ) void split( const wstring &Source, const wstring &Deliminator, vector<wstring> &AddIt, const bool bIgnoreEmpty )
{ {
do_split(Source, Deliminator, AddIt, bIgnoreEmpty ); do_split(Source, Deliminator, AddIt, bIgnoreEmpty );
} }
@@ -706,18 +706,17 @@ int utf8_get_char_len (const char *pp)
return -1; return -1;
} }
longchar utf8_get_char (const char *p) wchar_t utf8_get_char (const char *p)
{ {
int len = utf8_get_char_len(p); int len = utf8_get_char_len(p);
if(len == -1) if(len == -1)
return 0xFFFF; return INVALID_CHAR;
int mask = masks[len]; int mask = masks[len];
wchar_t result = wchar_t(p[0] & mask);
longchar result = longchar(p[0] & mask);
for (int i = 1; i < len; ++i) { for (int i = 1; i < len; ++i) {
if ((p[i] & 0xc0) != 0x80) if ((p[i] & 0xc0) != 0x80)
return (longchar) -1; return INVALID_CHAR;
result <<= 6; result <<= 6;
result |= p[i] & 0x3f; result |= p[i] & 0x3f;
@@ -726,17 +725,17 @@ longchar utf8_get_char (const char *p)
return result; 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(); const char *ptr = str.c_str(), *end = str.c_str()+str.size();
lstring ret; wstring ret;
while(ptr && ptr != end) while(ptr && ptr != end)
{ {
longchar c = utf8_get_char (ptr); wchar_t c = utf8_get_char (ptr);
if(c == -1) if(c == -1)
ret += INVALID_CHAR; ret += INVALID_CHAR;
else else
@@ -747,17 +746,17 @@ lstring CStringToLstring(const CString &str)
return ret; return ret;
} }
CString LStringToCString(const lstring &str) CString WStringToCString(const wstring &str)
{ {
CString ret; CString ret;
for(unsigned i = 0; i < str.size(); ++i) for(unsigned i = 0; i < str.size(); ++i)
ret.append(LcharToUTF8(str[i])); ret.append(WcharToUTF8(str[i]));
return ret; return ret;
} }
int unichar_to_utf8 (longchar c, char *outbuf) static int unichar_to_utf8 (wchar_t c, char *outbuf)
{ {
unsigned int len = 0; unsigned int len = 0;
int first; int first;
@@ -795,7 +794,7 @@ int unichar_to_utf8 (longchar c, char *outbuf)
return len; return len;
} }
CString LcharToUTF8( longchar c ) CString WcharToUTF8( wchar_t c )
{ {
char buf[6]; char buf[6];
int cnt = unichar_to_utf8(c, buf); int cnt = unichar_to_utf8(c, buf);
@@ -874,8 +873,10 @@ void Replace_Unicode_Markers( CString &Text )
int num; int num;
if(hex) sscanf(Text.c_str()+pos, "&x%x;", &num); if(hex) sscanf(Text.c_str()+pos, "&x%x;", &num);
else sscanf(Text.c_str()+pos, "&#%i;", &num); else sscanf(Text.c_str()+pos, "&#%i;", &num);
if(num > 0xFFFF)
num = INVALID_CHAR;
Text.replace(pos, p-pos, LcharToUTF8(num)); Text.replace(pos, p-pos, WcharToUTF8(wchar_t(num)));
} }
} }
+5 -8
View File
@@ -144,15 +144,12 @@ void splitrelpath(
CString& Ext 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 int longchar;
typedef basic_string<longchar> lstring; extern const wchar_t INVALID_CHAR;
extern const longchar INVALID_CHAR;
lstring CStringToLstring(const CString &str); CString WStringToCString(const wstring &str);
CString LStringToCString(const lstring &str); CString WcharToUTF8( wchar_t c );
CString LcharToUTF8( longchar c ); wstring CStringToWstring(const CString &str);
// Splits a CString into an CStringArray according the Deliminator. // Splits a CString into an CStringArray according the Deliminator.
void split( void split(
@@ -161,7 +158,7 @@ void split(
CStringArray& AddIt, CStringArray& AddIt,
const bool bIgnoreEmpty = true const bool bIgnoreEmpty = true
); );
void split( const lstring &Source, const lstring &Deliminator, vector<lstring> &AddIt, const bool bIgnoreEmpty = true ); void split( const wstring &Source, const wstring &Deliminator, vector<wstring> &AddIt, const bool bIgnoreEmpty = true );
// Joins a CStringArray to create a CString according the Deliminator. // Joins a CStringArray to create a CString according the Deliminator.
CString join(const CString &Deliminator, const CStringArray& Source); CString join(const CString &Deliminator, const CStringArray& Source);
+3 -3
View File
@@ -41,7 +41,7 @@ ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuesti
m_pOnOK = OnOK; m_pOnOK = OnOK;
m_pOnCancel = OnCancel; m_pOnCancel = OnCancel;
m_sAnswer = CStringToLstring(sInitialAnswer); m_sAnswer = CStringToWstring(sInitialAnswer);
m_bCancelled = false; m_bCancelled = false;
m_Fade.SetTransitionTime( 0.5f ); m_Fade.SetTransitionTime( 0.5f );
@@ -73,7 +73,7 @@ ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuesti
void ScreenTextEntry::UpdateText() void ScreenTextEntry::UpdateText()
{ {
CString txt = LStringToCString(m_sAnswer); CString txt = WStringToCString(m_sAnswer);
FontCharAliases::ReplaceMarkers(txt); FontCharAliases::ReplaceMarkers(txt);
m_textAnswer.SetText( txt ); m_textAnswer.SetText( txt );
} }
@@ -205,7 +205,7 @@ void ScreenTextEntry::MenuStart( PlayerNumber pn )
} else { } else {
if( m_pOnOK ) if( m_pOnOK )
{ {
CString ret = LStringToCString(m_sAnswer); CString ret = WStringToCString(m_sAnswer);
FontCharAliases::ReplaceMarkers(ret); FontCharAliases::ReplaceMarkers(ret);
m_pOnOK( ret ); m_pOnOK( ret );
} }
+1 -1
View File
@@ -40,7 +40,7 @@ protected:
TransitionFade m_Fade; TransitionFade m_Fade;
BitmapText m_textQuestion; BitmapText m_textQuestion;
Quad m_rectAnswerBox; Quad m_rectAnswerBox;
lstring m_sAnswer; wstring m_sAnswer;
BitmapText m_textAnswer; BitmapText m_textAnswer;
ScreenMessage m_SMSendWhenDone; ScreenMessage m_SMSendWhenDone;
void(*m_pOnOK)( CString sAnswer ); void(*m_pOnOK)( CString sAnswer );