void StyledTTFont::drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align) { if (_font) { Common::U32String u32str = convertUtf8ToUtf32(str); _font->drawString(dst, u32str, x, y, w, color, align); if (_style & STTF_UNDERLINE) { int16 pos = floor(_font->getFontHeight() * 0.87); int16 wd = MIN(_font->getStringWidth(u32str), w); int16 stX = x; if (align == Graphics::kTextAlignCenter) stX += (w - wd) / 2; else if (align == Graphics::kTextAlignRight) stX += (w - wd); int thk = MAX((int)(_font->getFontHeight() * 0.05), 1); dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color); } if (_style & STTF_STRIKEOUT) { int16 pos = floor(_font->getFontHeight() * 0.60); int16 wd = MIN(_font->getStringWidth(u32str), w); int16 stX = x; if (align == Graphics::kTextAlignCenter) stX += (w - wd) / 2; else if (align == Graphics::kTextAlignRight) stX += (w - wd); int thk = MAX((int)(_font->getFontHeight() * 0.05), 1); dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color); } } }
U32String convertToU32String(const char *str, CodePage page) { const String string(str); if (page == kUtf8) { return convertUtf8ToUtf32(string); } U32String unicodeString; for (uint i = 0; i < string.size(); ++i) { if ((byte)string[i] <= 0x7F) { unicodeString += string[i]; continue; } byte index = string[i] - 0x80; switch (page) { case kWindows1250: unicodeString += g_windows1250ConversionTable[index]; break; case kWindows1251: unicodeString += g_windows1251ConversionTable[index]; break; case kWindows1252: unicodeString += g_windows1252ConversionTable[index]; break; case kWindows1255: unicodeString += g_windows1255ConversionTable[index]; break; default: break; } } return unicodeString; }
/** set a utf8 string to convert */ void UTF8Converter::setUTF8String(Common::String str) { _str32.clear(); _str32 = convertUtf8ToUtf32(str); _str.clear(); _str = str; }