From 6e076327756dcb6af4f525b3b0590e3090759af5 Mon Sep 17 00:00:00 2001 From: Gee Date: Mon, 6 Sep 2004 02:24:34 +0000 Subject: [PATCH] Changed a function that the GUI uses to Unicode. This was SVN commit r1127. --- source/lib/res/unifont.cpp | 36 ++++++++++++++++++++++++++++++++++-- source/lib/res/unifont.h | 6 +++--- source/ps/Font.cpp | 6 +++--- source/ps/Font.h | 2 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/source/lib/res/unifont.cpp b/source/lib/res/unifont.cpp index be9d90e228..3a82764ad1 100755 --- a/source/lib/res/unifont.cpp +++ b/source/lib/res/unifont.cpp @@ -1,5 +1,5 @@ /* -$Id: unifont.cpp,v 1.15 2004/09/04 20:34:57 philip Exp $ +$Id: unifont.cpp,v 1.16 2004/09/06 02:24:05 gee Exp $ Unicode OpenGL texture font @@ -248,7 +248,7 @@ void glwprintf(const wchar_t* fmt, ...) glCallLists((GLsizei)len, sizeof(wchar_t)==4 ? GL_INT : GL_UNSIGNED_SHORT, buf); } - +#if 0 // Replaced by the unicode version, this can be removed /Gee int unifont_stringsize(const Handle h, const char* text, int& width, int& height) { H_DEREF(h, UniFont, f); @@ -276,3 +276,35 @@ int unifont_stringsize(const Handle h, const char* text, int& width, int& height return 0; } +#endif + +int unifont_stringsize(const Handle h, const wchar_t* text, int& width, int& height) +{ + H_DEREF(h, UniFont, f); + + width = 0; + height = f->Height; + + size_t len = wcslen(text); + + for (size_t i = 0; i < len; ++i) + { + glyphmap_size::iterator it = f->glyphs_size->find(text[i]); + + if (it == f->glyphs_size->end()) + it = f->glyphs_size->find(0xFFFD); // Use the missing glyph symbol + + if (it == f->glyphs_size->end()) // Missing the missing glyph symbol - give up + { + debug_warn("Missing the missing glyph in a unifont!\n"); + return 0; + } + + width += it->second; // Add the character's advance distance + } + + LOG_ONCE(ERROR, LOG_CATEGORY, "%d %d", width, height); + + return 0; +} +// -- GL \ No newline at end of file diff --git a/source/lib/res/unifont.h b/source/lib/res/unifont.h index eb3077af35..cb5808597f 100755 --- a/source/lib/res/unifont.h +++ b/source/lib/res/unifont.h @@ -1,4 +1,4 @@ -// $Id: unifont.h,v 1.5 2004/09/04 20:34:57 philip Exp $ +// $Id: unifont.h,v 1.6 2004/09/06 02:24:05 gee Exp $ #ifndef __UNIFONT_H__ #define __UNIFONT_H__ @@ -34,9 +34,9 @@ void glwprintf(const wchar_t* fmt, ...); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */ -// Intended for the GUI (hence ASCIIness). 'height' is roughly the height of +// Intended for the GUI (hence Unicode). 'height' is roughly the height of // a capital letter, for use when aligning text in an aesthetically pleasing way. -int unifont_stringsize(const Handle h, const char* text, int& width, int& height); +int unifont_stringsize(const Handle h, const wchar_t* text, int& width, int& height); // Return spacing in pixels from one line of text to the next int unifont_linespacing(const Handle h); diff --git a/source/ps/Font.cpp b/source/ps/Font.cpp index dab49b016e..21e7612bb8 100755 --- a/source/ps/Font.cpp +++ b/source/ps/Font.cpp @@ -66,7 +66,7 @@ int CFont::GetLineSpacing() return unifont_linespacing(h); } -void CFont::CalculateStringSize(const CStr& string, int& width, int& height) +void CFont::CalculateStringSize(const CStrW& string, int& width, int& height) { - unifont_stringsize(h, string.c_str(), width, height); -} + unifont_stringsize(h, (const wchar_t*)string, width, height); +} \ No newline at end of file diff --git a/source/ps/Font.h b/source/ps/Font.h index 76e9570a1f..8c2253a212 100755 --- a/source/ps/Font.h +++ b/source/ps/Font.h @@ -29,7 +29,7 @@ public: void Bind(); int GetLineSpacing(); - void CalculateStringSize(const CStr& string, int& w, int& h); + void CalculateStringSize(const CStrW& string, int& w, int& h); private: Handle h;