diff options
author | Einar Johan Trøan Sømåen | 2012-06-03 23:57:31 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-06-03 23:57:31 +0200 |
commit | 70427e6d7e0e06e0559aed167e86784a9c176f34 (patch) | |
tree | 67ce0152c20a788752d2bb737070a82201dede0a /engines/wintermute | |
parent | a3901c76fdea01f40b0941d46bd2eb538d89341d (diff) | |
download | scummvm-rg350-70427e6d7e0e06e0559aed167e86784a9c176f34.tar.gz scummvm-rg350-70427e6d7e0e06e0559aed167e86784a9c176f34.tar.bz2 scummvm-rg350-70427e6d7e0e06e0559aed167e86784a9c176f34.zip |
WINTERMUTE: Make text-measuring work without FreeType2.
Diffstat (limited to 'engines/wintermute')
-rw-r--r-- | engines/wintermute/Base/BFontTT.cpp | 39 | ||||
-rw-r--r-- | engines/wintermute/Base/BFontTT.h | 3 | ||||
-rw-r--r-- | engines/wintermute/utils/StringUtil.cpp | 8 |
3 files changed, 33 insertions, 17 deletions
diff --git a/engines/wintermute/Base/BFontTT.cpp b/engines/wintermute/Base/BFontTT.cpp index 2c062e6d91..7b28c9fd93 100644 --- a/engines/wintermute/Base/BFontTT.cpp +++ b/engines/wintermute/Base/BFontTT.cpp @@ -58,6 +58,7 @@ CBFontTT::CBFontTT(CBGame *inGame): CBFont(inGame) { _fontFile = NULL;
_font = NULL;
_fallbackFont = NULL;
+ _deletableFont = NULL;
for (int i = 0; i < NUM_CACHED_TEXTS; i++) _cachedTexts[i] = NULL;
@@ -84,7 +85,7 @@ CBFontTT::~CBFontTT(void) { delete[] _fontFile;
_fontFile = NULL;
- delete _font;
+ delete _deletableFont;
_font = NULL;
delete _glyphCache;
@@ -129,8 +130,8 @@ void CBFontTT::InitLoop() { int CBFontTT::GetTextWidth(byte *Text, int MaxLength) {
WideString text;
- /* if (Game->_textEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
- else text = StringUtil::AnsiToWide((char *)Text);*/
+ if (Game->_textEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
+ else text = StringUtil::AnsiToWide((char *)Text);
if (MaxLength >= 0 && text.size() > MaxLength)
text = Common::String(text.c_str(), MaxLength);
@@ -146,8 +147,8 @@ int CBFontTT::GetTextWidth(byte *Text, int MaxLength) { int CBFontTT::GetTextHeight(byte *Text, int Width) {
WideString text;
- /* if (Game->_textEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
- else text = StringUtil::AnsiToWide((char *)Text);*/
+ if (Game->_textEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
+ else text = StringUtil::AnsiToWide((char *)Text);
int textWidth, textHeight;
@@ -636,9 +637,10 @@ HRESULT CBFontTT::InitFont() { #endif
}
if (!_font) {
- _fallbackFont = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+ _font = _fallbackFont = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
warning("BFontTT::InitFont - Couldn't load %s", _fontFile);
}
+ _lineHeight = _font->getFontHeight();
return S_OK;
#if 0
FT_Error error;
@@ -814,19 +816,32 @@ void CBFontTT::WrapText(const WideString &text, int maxWidth, int maxHeight, Tex //////////////////////////////////////////////////////////////////////////
void CBFontTT::MeasureText(const WideString &text, int maxWidth, int maxHeight, int &textWidth, int &textHeight) {
- TextLineList lines;
- WrapText(text, maxWidth, maxHeight, lines);
-
- textHeight = (int)(lines.size() * GetLineHeight());
- textWidth = 0;
+ //TextLineList lines;
+ warning("Todo: Test Mesuretext");
+ if (maxWidth >= 0) {
+ Common::Array<Common::String> lines;
+ _font->wordWrapText(text, maxWidth, lines);
+ Common::Array<Common::String>::iterator it;
+ textWidth = 0;
+ for (it = lines.begin(); it != lines.end(); it++) {
+ textWidth = MAX(textWidth, _font->getStringWidth(*it));
+ }
+
+ //WrapText(text, maxWidth, maxHeight, lines);
+ textHeight = (int)(lines.size() * GetLineHeight());
+ } else {
+ textWidth = _font->getStringWidth(text);
+ textHeight = _fontHeight;
+ }
+/*
TextLineList::iterator it;
for (it = lines.begin(); it != lines.end(); ++it) {
TextLine *line = (*it);
textWidth = MAX(textWidth, line->GetWidth());
delete line;
line = NULL;
- }
+ }*/
}
diff --git a/engines/wintermute/Base/BFontTT.h b/engines/wintermute/Base/BFontTT.h index 22630a7444..d21729369b 100644 --- a/engines/wintermute/Base/BFontTT.h +++ b/engines/wintermute/Base/BFontTT.h @@ -160,7 +160,8 @@ private: HRESULT InitFont();
//FT_Stream _fTStream;
//FT_Face _fTFace;
- Graphics::Font *_font;
+ Graphics::Font *_deletableFont;
+ const Graphics::Font *_font;
const Graphics::Font *_fallbackFont;
FontGlyphCache *_glyphCache;
diff --git a/engines/wintermute/utils/StringUtil.cpp b/engines/wintermute/utils/StringUtil.cpp index cd4f99e034..8ca2ed8c07 100644 --- a/engines/wintermute/utils/StringUtil.cpp +++ b/engines/wintermute/utils/StringUtil.cpp @@ -179,7 +179,7 @@ Utf8String StringUtil::WideToUtf8(const WideString &WideStr) { //////////////////////////////////////////////////////////////////////////
WideString StringUtil::AnsiToWide(const AnsiString &str) {
// using default os locale!
- error("StringUtil::AnsiToWide - WideString not supported yet");
+ warning("StringUtil::AnsiToWide - WideString not supported yet");
/* setlocale(LC_CTYPE, "");
size_t WideSize = mbstowcs(NULL, str.c_str(), 0) + 1;
wchar_t *wstr = new wchar_t[WideSize];
@@ -187,13 +187,13 @@ WideString StringUtil::AnsiToWide(const AnsiString &str) { WideString ResultString(wstr);
delete [] wstr;
return ResultString;*/
- return "";
+ return WideString(str);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::WideToAnsi(const WideString &wstr) {
// using default os locale!
- error("StringUtil::WideToAnsi - WideString not supported yet");
+ warning("StringUtil::WideToAnsi - WideString not supported yet");
/* setlocale(LC_CTYPE, "");
size_t WideSize = wcstombs(NULL, wstr.c_str(), 0) + 1;
char *str = new char[WideSize];
@@ -201,7 +201,7 @@ AnsiString StringUtil::WideToAnsi(const WideString &wstr) { AnsiString ResultString(str);
delete [] str;
return ResultString;*/
- return "";
+ return AnsiString(wstr);
}
//////////////////////////////////////////////////////////////////////////
|