From 22cf499432322623a6a0bf0048b12cb043a70741 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Sun, 5 Dec 2021 20:01:27 +0100 Subject: [PATCH] upp.src: Various CHARSET_UNICODE->CHARSET_UTF8 changes, FT_fontsys fix, SDL2GL fix --- autotest/Heap/Heap.cpp | 1 - autotest/JsonEmoticon/JsonEmoticon.cpp | 8 +++--- autotest/Qtf/Qtf.cpp | 36 ++++++++++++------------- autotest/Unicode/Unicode.cpp | 2 +- uppsrc/CtrlCore/CtrlKbd.cpp | 2 +- uppsrc/CtrlLib/DocEdit.cpp | 2 +- uppsrc/CtrlLib/EditField.cpp | 4 +-- uppsrc/CtrlLib/LineEdit.cpp | 2 +- uppsrc/CtrlLib/Text.cpp | 2 +- uppsrc/Draw/FontFc.cpp | 2 ++ uppsrc/Oracle/Oci8.cpp | 22 +++++---------- uppsrc/VirtualGui/Clip.cpp | 6 ++--- uppsrc/VirtualGui/SDL2GL/Event.cpp | 2 +- uppsrc/plugin/FT_fontsys/FT_fontsys.cpp | 6 ++--- 14 files changed, 44 insertions(+), 53 deletions(-) diff --git a/autotest/Heap/Heap.cpp b/autotest/Heap/Heap.cpp index b68b0c5d4..ef5fe53c0 100644 --- a/autotest/Heap/Heap.cpp +++ b/autotest/Heap/Heap.cpp @@ -146,7 +146,6 @@ CONSOLE_APP_MAIN LOG("Quick allocator test Passed"); HeapTest(8192, 100 * 1000000, false); LOG("Allocator test Passed"); - MemoryFreeThread(); } LOG("Used: " << MemoryUsedKb() << " KB"); LOG("============== OK " << tm); diff --git a/autotest/JsonEmoticon/JsonEmoticon.cpp b/autotest/JsonEmoticon/JsonEmoticon.cpp index 1f4c769fe..af2526494 100644 --- a/autotest/JsonEmoticon/JsonEmoticon.cpp +++ b/autotest/JsonEmoticon/JsonEmoticon.cpp @@ -9,10 +9,10 @@ CONSOLE_APP_MAIN dword emoticon = 0x1f60d; // Smiling Face With Heart-shaped Eyes String text = "Český 아침글"; - Vector h = ToUtf32(text); - h.Add('\n'); - h.Add(emoticon); - h.Add(31); + WString h = ToUtf32(text); + h.Cat('\n'); + h.Cat(emoticon); + h.Cat(31); DUMP(h); dword ref[] = { 268, 101, 115, 107, 253, 32, 50500, 52840, 44544, 10, 128525, 31 }; diff --git a/autotest/Qtf/Qtf.cpp b/autotest/Qtf/Qtf.cpp index f92091f12..09bd1ea56 100644 --- a/autotest/Qtf/Qtf.cpp +++ b/autotest/Qtf/Qtf.cpp @@ -15,25 +15,23 @@ CONSOLE_APP_MAIN DeleteFolderDeep(outdir); RealizeDirectory(outdir); - for(FindFile ff(GetDataFile("*.qtf")); ff; ff.Next()) { - String qtf = LoadFile(ff.GetPath()); - LOG(ff.GetName() << ' ' << qtf.GetCount()); - - ASSERT(qtf.GetLength() > 10000); - RichText txt = ParseQTF(qtf); - String qtf2 = AsQTF(txt); - ASSERT(qtf2 == qtf); - SaveFile(AppendFileName(outdir, ff.GetName()), qtf2); - - String pdfname = ForceExt(ff.GetName(), ".pdf"); - String pdf = Pdf(txt); - SaveFile(AppendFileName(outdir, pdfname), pdf); - - String h = LoadDataFile(pdfname); - ASSERT(h.GetCount() == pdf.GetCount()); - int q = h.ReverseFind("trailer"); - ASSERT(pdf.Mid(0, q) == h.Mid(0, q)); - } + String qtf = LoadDataFile("test.qtf"); + + DDUMP(qtf.GetCount()); + + ASSERT(qtf.GetLength() > 10000); + RichText txt = ParseQTF(qtf); + String qtf2 = AsQTF(txt); + ASSERT(qtf2 == qtf); + + String pdf = Pdf(txt); + String pdfpath = AppendFileName(outdir, "test.pdf"); + SaveFile(pdfpath, pdf); + + String h = LoadDataFile("test.pdf"); + ASSERT(h.GetCount() == pdf.GetCount()); + int q = h.ReverseFind("trailer"); + ASSERT(pdf.Mid(0, q) == h.Mid(0, q)); DeleteFolderDeep(outdir); diff --git a/autotest/Unicode/Unicode.cpp b/autotest/Unicode/Unicode.cpp index e8b7e747d..4c55c57c0 100644 --- a/autotest/Unicode/Unicode.cpp +++ b/autotest/Unicode/Unicode.cpp @@ -54,7 +54,7 @@ CONSOLE_APP_MAIN DLOG("===== Decompose"); for(int i = 0; i < 0x110000; i++) { - Vector dc = UnicodeDecompose(i, true); + WString dc = UnicodeDecompose(i, true); if(dc.GetCount()) { VppLog() << Format64Hex(i) << "->"; for(int c : dc) diff --git a/uppsrc/CtrlCore/CtrlKbd.cpp b/uppsrc/CtrlCore/CtrlKbd.cpp index aa64c3c75..fab0196d4 100644 --- a/uppsrc/CtrlCore/CtrlKbd.cpp +++ b/uppsrc/CtrlCore/CtrlKbd.cpp @@ -60,7 +60,7 @@ bool Ctrl::DispatchKey(dword keycode, int count) return true; dword k = keycode; word l = LOWORD(keycode); - if(!(k & K_DELTA) && l >= 32 && l != 127 && GetDefaultCharset() != CHARSET_UNICODE) + if(!(k & K_DELTA) && l >= 32 && l != 127 && GetDefaultCharset() != CHARSET_UTF8) k = MAKELONG((word)FromUnicode(l, CHARSET_DEFAULT), HIWORD(keycode)); if(!focusCtrl) return false; diff --git a/uppsrc/CtrlLib/DocEdit.cpp b/uppsrc/CtrlLib/DocEdit.cpp index fa371230a..0fc85fcaa 100644 --- a/uppsrc/CtrlLib/DocEdit.cpp +++ b/uppsrc/CtrlLib/DocEdit.cpp @@ -441,7 +441,7 @@ bool DocEdit::Key(dword key, int cnt) if(key >= ' ' && key < K_CHAR_LIM || key == '\n' || key == '\t' || key == K_SHIFT_SPACE) { if(key == K_TAB && !processtab) return false; - if(key >= 128 && key < K_CHAR_LIM && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) + if(key >= 128 && key < K_CHAR_LIM && (charset != CHARSET_UTF8 && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; RemoveSelection(); diff --git a/uppsrc/CtrlLib/EditField.cpp b/uppsrc/CtrlLib/EditField.cpp index adb9ba553..c7277f5d7 100644 --- a/uppsrc/CtrlLib/EditField.cpp +++ b/uppsrc/CtrlLib/EditField.cpp @@ -624,7 +624,7 @@ int EditField::Insert(int pos, const WString& itext) chr = (*filter)(chr); if(chr) { chr = convert->Filter(chr); - if(chr && (charset == CHARSET_UNICODE || FromUnicode(chr, charset, 0))) + if(chr && (charset == CHARSET_UTF8 || FromUnicode(chr, charset, 0))) ins.Cat(chr, count); } } @@ -1015,7 +1015,7 @@ void EditField::Reset() autosize = false; keep_selection = false; errorbg = nobg = false; - charset = CHARSET_UNICODE; + charset = CHARSET_UTF8; alignright = false; SetStyle(StyleDefault()); SetFrame(edge); diff --git a/uppsrc/CtrlLib/LineEdit.cpp b/uppsrc/CtrlLib/LineEdit.cpp index b17f9d6b1..efa771ff1 100644 --- a/uppsrc/CtrlLib/LineEdit.cpp +++ b/uppsrc/CtrlLib/LineEdit.cpp @@ -1022,7 +1022,7 @@ bool LineEdit::InsertChar(dword key, int count, bool canow) { key = (*filter)(key); if(!IsReadOnly() && (key >= 32 && key < K_CHAR_LIM || key == '\t' || key == '\n' || key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { - if(key >= 128 && key < K_CHAR_LIM && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) + if(key >= 128 && key < K_CHAR_LIM && (charset != CHARSET_UTF8 && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { diff --git a/uppsrc/CtrlLib/Text.cpp b/uppsrc/CtrlLib/Text.cpp index 09cc0574b..fa1a8e2cf 100644 --- a/uppsrc/CtrlLib/Text.cpp +++ b/uppsrc/CtrlLib/Text.cpp @@ -13,7 +13,7 @@ TextCtrl::TextCtrl() incundoserial = false; undo_op = false; WhenBar = THISBACK(StdBar); - charset = CHARSET_UNICODE; + charset = CHARSET_UTF8; color[INK_NORMAL] = SColorText; color[INK_DISABLED] = SColorDisabled; color[INK_SELECTED] = SColorHighlightText; diff --git a/uppsrc/Draw/FontFc.cpp b/uppsrc/Draw/FontFc.cpp index b839e4f29..2543d500c 100644 --- a/uppsrc/Draw/FontFc.cpp +++ b/uppsrc/Draw/FontFc.cpp @@ -249,6 +249,8 @@ Vector GetAllFacesSys() String GetFontDataSys(Font font, const char *table, int offset, int size) { // read truetype or opentype table + if(!table) + return LoadFile(font.Fi().path); FileIn in(font.Fi().path); int q = in.Get32be(); if(q == 0x74746366) { // font collection diff --git a/uppsrc/Oracle/Oci8.cpp b/uppsrc/Oracle/Oci8.cpp index f3fbce94b..f116a385c 100644 --- a/uppsrc/Oracle/Oci8.cpp +++ b/uppsrc/Oracle/Oci8.cpp @@ -492,7 +492,7 @@ bool OCI8Connection::BulkExecute(const char *stmt, const Vector< Vector > sql_type = SQLT_STR; if(session->utf8_session) { WString wstr(v); - len = 1 + lenAsUtf8(wstr, wstr.GetLength()); + len = 1 + Utf8Len(wstr, wstr.GetLength()); } else len = 1 + String(v).GetLength(); @@ -910,7 +910,7 @@ void OCI8Connection::GetColumn(int i, WString& ws) const { s = (char *) c.Data(); } if(session->utf8_session) - ws = FromUtf8(s); + ws = ToUtf32(s); else ws = s.ToWString(); } @@ -1610,13 +1610,9 @@ dword OracleClob::Read(int64 at, void *ptr, dword size) { return full_bytes; WString unibuf; if(utf8) - unibuf = FromUtf8(charbuf, nchars); - else { - WStringBuffer tmp; - tmp.SetLength(nchars); - ToUnicode(tmp, charbuf, nchars, CHARSET_DEFAULT); - unibuf = tmp; - } + unibuf = ToUtf32(charbuf, nchars); + else + unibuf = ToUnicode(charbuf, nchars, CHARSET_DEFAULT); int ulen = unibuf.GetLength(); int uoff = (int)(at & 1); int upart = min((int)size, 2 * ulen - uoff); @@ -1663,12 +1659,8 @@ void OracleClob::Write(int64 at, const void *ptr, dword size) { String chrbuf; if(utf8) chrbuf = ToUtf8((const wchar *)ptr, nchars); - else { - StringBuffer tmp; - tmp.SetLength(nchars); - FromUnicode(tmp, (const wchar *)ptr, nchars, CHARSET_DEFAULT); - chrbuf = tmp; - } + else + chrbuf = FromUnicode((const wchar *)ptr, nchars, CHARSET_DEFAULT); ub4 n = chrbuf.GetLength(); sword res = session->oci8.OCILobWrite(session->svchp, session->errhp, locp, &n, (dword)(at >> 1) + 1, (dvoid *)chrbuf.Begin(), chrbuf.GetLength(), diff --git a/uppsrc/VirtualGui/Clip.cpp b/uppsrc/VirtualGui/Clip.cpp index 980e81e24..4cca6d2a7 100644 --- a/uppsrc/VirtualGui/Clip.cpp +++ b/uppsrc/VirtualGui/Clip.cpp @@ -53,7 +53,7 @@ void AppendClipboardText(const String& s) void AppendClipboardUnicodeText(const WString& s) { - AppendClipboard("wtext", (byte *)~s, 2 * s.GetLength()); + AppendClipboard("wtext", (byte *)~s, sizeof(wchar) * s.GetLength()); } const char *ClipFmtsText() @@ -66,7 +66,7 @@ String GetString(PasteClip& clip) GuiLock __; if(clip.Accept("wtext")) { String s = ~clip; - return WString((const wchar *)~s, wstrlen((const wchar *)~s)).ToString(); + return WString((const wchar *)~s, strlen__((const wchar *)~s)).ToString(); } if(clip.IsAvailable("text")) return ~clip; @@ -78,7 +78,7 @@ WString GetWString(PasteClip& clip) GuiLock __; if(clip.Accept("wtext")) { String s = ~clip; - return WString((const wchar *)~s, wstrlen((const wchar *)~s)); + return WString((const wchar *)~s, strlen__((const wchar *)~s)); } if(clip.IsAvailable("text")) return (~clip).ToWString(); diff --git a/uppsrc/VirtualGui/SDL2GL/Event.cpp b/uppsrc/VirtualGui/SDL2GL/Event.cpp index cc8f1dee4..fea475a33 100644 --- a/uppsrc/VirtualGui/SDL2GL/Event.cpp +++ b/uppsrc/VirtualGui/SDL2GL/Event.cpp @@ -38,7 +38,7 @@ void SDL2GUI::HandleSDLEvent(SDL_Event* event) // break; case SDL_TEXTINPUT: { //send respective keyup things as char events as well - WString text = FromUtf8(event->text.text); + WString text = event->text.text; for(int i = 0; i < text.GetCount(); i++) { int c = text[i]; if(c != 127) diff --git a/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp b/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp index 5a31c7f0a..ccf467da5 100644 --- a/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp +++ b/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp @@ -72,9 +72,9 @@ FtFontStyle GetFontStyle(Font font) return fd.At(0).style[0]; } -String GetFontDataSys(Font font) -{ - return LoadFile(font.Fi().path); +String GetFontDataSys(Font font, const char *table, int offset, int size) +{ // TODO: Finish this! + return Null; } static FT_Library sFTlib;