mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-24 03:39:07 +02:00
UI: Correct text wrap with shy or Unicode spaces.
This commit is contained in:
1 parent
7d730f2a8b
commit
bbc83bcdab
3 files changed
+49
-19
No files matched your search
+13
-2
@@ -671,12 +671,16 @@ protected:
|
||||
float MeasureWidth(const char *str, size_t bytes) override {
|
||||
// Simple case for unit testing.
|
||||
int w = 0;
|
||||
for (size_t i = 0; i < bytes; ++i) {
|
||||
switch (str[i]) {
|
||||
for (UTF8 utf(str); !utf.end() && utf.byteIndex() < bytes; ) {
|
||||
uint32_t c = utf.next();
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '.':
|
||||
w += 1;
|
||||
break;
|
||||
case 0x00AD:
|
||||
// No width for soft hyphens.
|
||||
break;
|
||||
default:
|
||||
w += 2;
|
||||
break;
|
||||
@@ -714,6 +718,13 @@ static bool TestWrapText() {
|
||||
EXPECT_WORDWRAP_EQ_STR("Hello goodbye", 10, FLAG_ELLIPSIZE_TEXT, "Hel...");
|
||||
EXPECT_WORDWRAP_EQ_STR("Hello goodbye", 10, FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT, "Hello \ngoo...");
|
||||
|
||||
// How about the shy character?
|
||||
const std::string shyTestString = StringFromFormat("Very%c%clong", 0xC2, 0xAD);
|
||||
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, 0, shyTestString);
|
||||
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, FLAG_WRAP_TEXT, "Very-\nlong");
|
||||
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, FLAG_ELLIPSIZE_TEXT, "Very...");
|
||||
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT, "Very-\nlong");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user