[Scummvm-git-logs] scummvm branch-2-8 -> d56f3a9c501190e5cd1a79befc98ce8adcc2f510
sev-
noreply at scummvm.org
Sat Jan 6 23:43:28 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
d56f3a9c50 GRAPHICS: MACGUI: Fix links with Unicode characters
Commit: d56f3a9c501190e5cd1a79befc98ce8adcc2f510
https://github.com/scummvm/scummvm/commit/d56f3a9c501190e5cd1a79befc98ce8adcc2f510
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2024-01-07T00:43:12+01:00
Commit Message:
GRAPHICS: MACGUI: Fix links with Unicode characters
If there are unicode characters in the link, it was leading to
wrong length calculation.
Example of such link:
{w=10em}
The problem is that for simplicity, we are working with UTF8 in
Markdown, but still with U32String in MacTextCanvas. This led to
the string length be calculated for UTF8, which is a multibyte
encoding. As a result, we were overshooting the link parsing
and reading texts as numbers.
This is kind of a hacky solution: we convert text to U32 before
caluclating the string length
Changed paths:
graphics/macgui/mactext-md.cpp
diff --git a/graphics/macgui/mactext-md.cpp b/graphics/macgui/mactext-md.cpp
index f2988293bbb..98dd3861921 100644
--- a/graphics/macgui/mactext-md.cpp
+++ b/graphics/macgui/mactext-md.cpp
@@ -233,20 +233,26 @@ int render_image(Common::SDDataBuffer *ob, const Common::SDDataBuffer *link, con
Common::String res = Common::String::format("\001" "\016i%02x" "%02x%s",
80, (uint)link->size, Common::String((const char *)link->data, link->size).c_str());
- if (alt)
- res += Common::String::format("%02x%s", (uint)alt->size, Common::String((const char *)alt->data, alt->size).c_str());
- else
+ if (alt) {
+ uint32 len = Common::U32String((const char *)alt->data, alt->size).size();
+ res += Common::String::format("%02x%s", len, Common::String((const char *)alt->data, alt->size).c_str());
+ } else {
res += "00";
+ }
- if (title)
- res += Common::String::format("%02x%s", (uint)title->size, Common::String((const char *)title->data, title->size).c_str());
- else
+ if (title) {
+ uint32 len = Common::U32String((const char *)title->data, title->size).size();
+ res += Common::String::format("%02x%s", len, Common::String((const char *)title->data, title->size).c_str());
+ } else {
res += "00";
+ }
- if (ext)
- res += Common::String::format("%02x%s", (uint)ext->size, Common::String((const char *)ext->data, ext->size).c_str());
- else
+ if (ext) {
+ uint32 len = Common::U32String((const char *)ext->data, ext->size).size();
+ res += Common::String::format("%02x%s", len, Common::String((const char *)ext->data, ext->size).c_str());
+ } else {
res += "00";
+ }
res += "\n";
@@ -270,10 +276,12 @@ int render_link(Common::SDDataBuffer *ob, const Common::SDDataBuffer *link, cons
MDState *mdstate = (MDState *)opaque;
const Common::SDDataBuffer *text = content ? content : link;
+ uint32 linklen = Common::U32String((const char *)link->data, link->size).size();
+
Common::String res = Common::String::format("\001" "\016+%02x00" "\001\016[%04x%04x%04x"
"\001\016l%02x%s" "%s" "\001\016l00" "\001\016]" "\001\016-%02x00", kMacFontUnderline,
mdstate->linkr, mdstate->linkg, mdstate->linkb,
- (uint)link->size, Common::String((const char *)link->data , link->size).c_str(),
+ linklen, Common::String((const char *)link->data , link->size).c_str(),
Common::String((const char *)text->data , text->size).c_str(), kMacFontUnderline);
sd_bufput(ob, res.c_str(), res.size());
More information about the Scummvm-git-logs
mailing list