[Scummvm-git-logs] scummvm master -> 0e55160cd032eb91da1f5e1f0694903bc52cf8aa

sev- sev at scummvm.org
Mon Jun 18 00:09:37 CEST 2018


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
79e158671e COMMON: Add simplistic UTF8->UTF32 converter
0e55160cd0 ZVISION: Reuse UTF8->UTF32 converter from Common


Commit: 79e158671e84b532687637184ecfbd65b827a81d
    https://github.com/scummvm/scummvm/commit/79e158671e84b532687637184ecfbd65b827a81d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2018-06-18T00:08:01+02:00

Commit Message:
COMMON: Add simplistic UTF8->UTF32 converter

Changed paths:
    common/ustr.cpp
    common/ustr.h


diff --git a/common/ustr.cpp b/common/ustr.cpp
index 85946cd..cddfda7 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -327,4 +327,37 @@ void U32String::initWithCStr(const value_type *str, uint32 len) {
 	_str[len] = 0;
 }
 
+// This is a quick and dirty converter.
+//
+// More comprehensive one lives in wintermute/utils/convert_utf.cpp
+U32String convertUtf8ToUtf32(const String &str) {
+	// The String class, and therefore the Font class as well, assume one
+	// character is one byte, but in this case it's actually an UTF-8
+	// string with up to 4 bytes per character. To work around this,
+	// convert it to an U32String before drawing it, because our Font class
+	// can handle that.
+	Common::U32String u32str;
+	uint i = 0;
+	while (i < str.size()) {
+		uint32 chr = 0;
+		if ((str[i] & 0xF8) == 0xF0) {
+			chr |= (str[i++] & 0x07) << 18;
+			chr |= (str[i++] & 0x3F) << 12;
+			chr |= (str[i++] & 0x3F) << 6;
+			chr |= (str[i++] & 0x3F);
+		} else if ((str[i] & 0xF0) == 0xE0) {
+			chr |= (str[i++] & 0x0F) << 12;
+			chr |= (str[i++] & 0x3F) << 6;
+			chr |= (str[i++] & 0x3F);
+		} else if ((str[i] & 0xE0) == 0xC0) {
+			chr |= (str[i++] & 0x1F) << 6;
+			chr |= (str[i++] & 0x3F);
+		} else {
+			chr = (str[i++] & 0x7F);
+		}
+		u32str += chr;
+	}
+	return u32str;
+}
+
 } // End of namespace Common
diff --git a/common/ustr.h b/common/ustr.h
index 0059a1e..5be3c8b 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -27,6 +27,8 @@
 
 namespace Common {
 
+class String;
+
 /**
  * Very simple string class for UTF-32 strings in ScummVM. The main intention
  * behind this class is to feature a simple way of displaying UTF-32 strings
@@ -182,6 +184,7 @@ public:
 	const_iterator end() const {
 		return begin() + size();
 	}
+
 private:
 	void makeUnique();
 	void ensureCapacity(uint32 new_size, bool keep_old);
@@ -190,6 +193,8 @@ private:
 	void initWithCStr(const value_type *str, uint32 len);
 };
 
+U32String convertUtf8ToUtf32(const String &str);
+
 } // End of namespace Common
 
 #endif


Commit: 0e55160cd032eb91da1f5e1f0694903bc52cf8aa
    https://github.com/scummvm/scummvm/commit/0e55160cd032eb91da1f5e1f0694903bc52cf8aa
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2018-06-18T00:08:11+02:00

Commit Message:
ZVISION: Reuse UTF8->UTF32 converter from Common

Changed paths:
    engines/zvision/text/truetype_font.cpp
    engines/zvision/text/truetype_font.h


diff --git a/engines/zvision/text/truetype_font.cpp b/engines/zvision/text/truetype_font.cpp
index 7848de5..2bbfe8a 100644
--- a/engines/zvision/text/truetype_font.cpp
+++ b/engines/zvision/text/truetype_font.cpp
@@ -165,36 +165,6 @@ int StyledTTFont::getKerningOffset(byte left, byte right) {
 	return 0;
 }
 
-Common::U32String StyledTTFont::convertUtf8ToUtf32(const Common::String &str) {
-	// The String class, and therefore the Font class as well, assume one
-	// character is one byte, but in this case it's actually an UTF-8
-	// string with up to 4 bytes per character. To work around this,
-	// convert it to an U32String before drawing it, because our Font class
-	// can handle that.
-	Common::U32String u32str;
-	uint i = 0;
-	while (i < str.size()) {
-		uint32 chr = 0;
-		if ((str[i] & 0xF8) == 0xF0) {
-			chr |= (str[i++] & 0x07) << 18;
-			chr |= (str[i++] & 0x3F) << 12;
-			chr |= (str[i++] & 0x3F) << 6;
-			chr |= (str[i++] & 0x3F);
-		} else if ((str[i] & 0xF0) == 0xE0) {
-			chr |= (str[i++] & 0x0F) << 12;
-			chr |= (str[i++] & 0x3F) << 6;
-			chr |= (str[i++] & 0x3F);
-		} else if ((str[i] & 0xE0) == 0xC0) {
-			chr |= (str[i++] & 0x1F) << 6;
-			chr |= (str[i++] & 0x3F);
-		} else {
-			chr = (str[i++] & 0x7F);
-		}
-		u32str += chr;
-	}
-	return u32str;
-}
-
 void StyledTTFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) {
 	if (_font) {
 		_font->drawChar(dst, chr, x, y, color);
@@ -213,7 +183,7 @@ void StyledTTFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint
 
 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);
+		Common::U32String u32str = Common::convertUtf8ToUtf32(str);
 		_font->drawString(dst, u32str, x, y, w, color, align);
 		if (_style & TTF_STYLE_UNDERLINE) {
 			int16 pos = (int16)floor(_font->getFontHeight() * 0.87);
diff --git a/engines/zvision/text/truetype_font.h b/engines/zvision/text/truetype_font.h
index 6abe05c..9ef0d39 100644
--- a/engines/zvision/text/truetype_font.h
+++ b/engines/zvision/text/truetype_font.h
@@ -75,8 +75,6 @@ public:
 	int getCharWidth(byte chr);
 	int getKerningOffset(byte left, byte right);
 
-	Common::U32String convertUtf8ToUtf32(const Common::String &str);
-
 	void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color);
 
 	void drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align = Graphics::kTextAlignLeft);





More information about the Scummvm-git-logs mailing list