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
{
iY += m_pFont->GetHeight();
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();
}
+1 -1
View File
@@ -47,7 +47,7 @@ protected:
// recalculate the items below on SetText()
CString m_szText;
vector<lstring> m_szTextLines;
vector<wstring> m_szTextLines;
vector<int> m_iLineWidths; // in source pixels
int m_iWidestLineWidth; // in source pixels
+14 -11
View File
@@ -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;
+5 -5
View File
@@ -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". */
+4 -4
View File
@@ -7,7 +7,7 @@
#include <map>
/* 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 map<CString,CString> 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;
}
+1 -1
View File
@@ -5,7 +5,7 @@
namespace FontCharAliases {
void ReplaceMarkers( CString &sText );
longchar GetChar( CString &codepoint );
wchar_t GetChar( CString &codepoint );
};
#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
* 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;
}
+2 -2
View File
@@ -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
+16 -15
View File
@@ -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<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 );
}
@@ -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);
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
);
/* 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<longchar> 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<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.
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_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 );
}
+1 -1
View File
@@ -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 );