From 9518d099621b242e341c20394de3006d1cd9e092 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Mon, 13 Dec 2021 23:05:14 +0100 Subject: [PATCH] Draw: Fixed charset conversion in DrawText --- uppsrc/Draw/DrawText.cpp | 4 +++- upptst/azbuka/azbuka.upp | 9 +++++++++ upptst/azbuka/main.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 upptst/azbuka/azbuka.upp create mode 100644 upptst/azbuka/main.cpp diff --git a/uppsrc/Draw/DrawText.cpp b/uppsrc/Draw/DrawText.cpp index 99dca08ee..54ea39a43 100644 --- a/uppsrc/Draw/DrawText.cpp +++ b/uppsrc/Draw/DrawText.cpp @@ -20,7 +20,9 @@ WString TextUnicode(const char *s, int n, byte cs, Font font) return WString(b); } #endif - return ToUtf32(s, n); + if(cs == CHARSET_UTF8) + return ToUtf32(s, n); + return ToUnicode(s, n, cs); } void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, diff --git a/upptst/azbuka/azbuka.upp b/upptst/azbuka/azbuka.upp new file mode 100644 index 000000000..5c4f53e15 --- /dev/null +++ b/upptst/azbuka/azbuka.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI"; + diff --git a/upptst/azbuka/main.cpp b/upptst/azbuka/main.cpp new file mode 100644 index 000000000..41a9897cd --- /dev/null +++ b/upptst/azbuka/main.cpp @@ -0,0 +1,24 @@ +#include + +using namespace Upp; + +struct MyApp : TopWindow { + void Paint(Draw& w) { + ImagePainter ip(GetSize()); + ip.DrawRect(GetSize(), White()); + + String s = "Абвгдежз"; // some cyrillic text + ip.DrawText(10, 10, s); // OK + + String s2 = ToCharset(CHARSET_WIN1251, s); + ip.DrawText(10, 50, s2, CHARSET_WIN1251); // draws rectangles instead of letters + + Image im = ip; + w.DrawImage(0, 0, im); + } +}; + +GUI_APP_MAIN +{ + MyApp().Run(); +}