upp.src: Various CHARSET_UNICODE->CHARSET_UTF8 changes, FT_fontsys fix, SDL2GL fix

This commit is contained in:
Mirek Fidler 2021-12-05 20:01:27 +01:00
parent d2207cd21f
commit 22cf499432
14 changed files with 44 additions and 53 deletions

View file

@ -146,7 +146,6 @@ CONSOLE_APP_MAIN
LOG("Quick allocator test Passed"); LOG("Quick allocator test Passed");
HeapTest(8192, 100 * 1000000, false); HeapTest(8192, 100 * 1000000, false);
LOG("Allocator test Passed"); LOG("Allocator test Passed");
MemoryFreeThread();
} }
LOG("Used: " << MemoryUsedKb() << " KB"); LOG("Used: " << MemoryUsedKb() << " KB");
LOG("============== OK " << tm); LOG("============== OK " << tm);

View file

@ -9,10 +9,10 @@ CONSOLE_APP_MAIN
dword emoticon = 0x1f60d; // Smiling Face With Heart-shaped Eyes dword emoticon = 0x1f60d; // Smiling Face With Heart-shaped Eyes
String text = "Český 아침글"; String text = "Český 아침글";
Vector<dword> h = ToUtf32(text); WString h = ToUtf32(text);
h.Add('\n'); h.Cat('\n');
h.Add(emoticon); h.Cat(emoticon);
h.Add(31); h.Cat(31);
DUMP(h); DUMP(h);
dword ref[] = { 268, 101, 115, 107, 253, 32, 50500, 52840, 44544, 10, 128525, 31 }; dword ref[] = { 268, 101, 115, 107, 253, 32, 50500, 52840, 44544, 10, 128525, 31 };

View file

@ -15,25 +15,23 @@ CONSOLE_APP_MAIN
DeleteFolderDeep(outdir); DeleteFolderDeep(outdir);
RealizeDirectory(outdir); RealizeDirectory(outdir);
for(FindFile ff(GetDataFile("*.qtf")); ff; ff.Next()) { String qtf = LoadDataFile("test.qtf");
String qtf = LoadFile(ff.GetPath());
LOG(ff.GetName() << ' ' << qtf.GetCount()); DDUMP(qtf.GetCount());
ASSERT(qtf.GetLength() > 10000); ASSERT(qtf.GetLength() > 10000);
RichText txt = ParseQTF(qtf); RichText txt = ParseQTF(qtf);
String qtf2 = AsQTF(txt); String qtf2 = AsQTF(txt);
ASSERT(qtf2 == qtf); ASSERT(qtf2 == qtf);
SaveFile(AppendFileName(outdir, ff.GetName()), qtf2);
String pdf = Pdf(txt);
String pdfname = ForceExt(ff.GetName(), ".pdf"); String pdfpath = AppendFileName(outdir, "test.pdf");
String pdf = Pdf(txt); SaveFile(pdfpath, pdf);
SaveFile(AppendFileName(outdir, pdfname), pdf);
String h = LoadDataFile("test.pdf");
String h = LoadDataFile(pdfname); ASSERT(h.GetCount() == pdf.GetCount());
ASSERT(h.GetCount() == pdf.GetCount()); int q = h.ReverseFind("trailer");
int q = h.ReverseFind("trailer"); ASSERT(pdf.Mid(0, q) == h.Mid(0, q));
ASSERT(pdf.Mid(0, q) == h.Mid(0, q));
}
DeleteFolderDeep(outdir); DeleteFolderDeep(outdir);

View file

@ -54,7 +54,7 @@ CONSOLE_APP_MAIN
DLOG("===== Decompose"); DLOG("===== Decompose");
for(int i = 0; i < 0x110000; i++) { for(int i = 0; i < 0x110000; i++) {
Vector<dword> dc = UnicodeDecompose(i, true); WString dc = UnicodeDecompose(i, true);
if(dc.GetCount()) { if(dc.GetCount()) {
VppLog() << Format64Hex(i) << "->"; VppLog() << Format64Hex(i) << "->";
for(int c : dc) for(int c : dc)

View file

@ -60,7 +60,7 @@ bool Ctrl::DispatchKey(dword keycode, int count)
return true; return true;
dword k = keycode; dword k = keycode;
word l = LOWORD(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)); k = MAKELONG((word)FromUnicode(l, CHARSET_DEFAULT), HIWORD(keycode));
if(!focusCtrl) if(!focusCtrl)
return false; return false;

View file

@ -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 >= ' ' && key < K_CHAR_LIM || key == '\n' || key == '\t' || key == K_SHIFT_SPACE) {
if(key == K_TAB && !processtab) if(key == K_TAB && !processtab)
return false; 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) && FromUnicode((wchar)key, charset) == DEFAULTCHAR)
return true; return true;
RemoveSelection(); RemoveSelection();

View file

@ -624,7 +624,7 @@ int EditField::Insert(int pos, const WString& itext)
chr = (*filter)(chr); chr = (*filter)(chr);
if(chr) { if(chr) {
chr = convert->Filter(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); ins.Cat(chr, count);
} }
} }
@ -1015,7 +1015,7 @@ void EditField::Reset()
autosize = false; autosize = false;
keep_selection = false; keep_selection = false;
errorbg = nobg = false; errorbg = nobg = false;
charset = CHARSET_UNICODE; charset = CHARSET_UTF8;
alignright = false; alignright = false;
SetStyle(StyleDefault()); SetStyle(StyleDefault());
SetFrame(edge); SetFrame(edge);

View file

@ -1022,7 +1022,7 @@ bool LineEdit::InsertChar(dword key, int count, bool canow) {
key = (*filter)(key); key = (*filter)(key);
if(!IsReadOnly() && (key >= 32 && key < K_CHAR_LIM || key == '\t' || key == '\n' || if(!IsReadOnly() && (key >= 32 && key < K_CHAR_LIM || key == '\t' || key == '\n' ||
key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { 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) && FromUnicode((wchar)key, charset) == DEFAULTCHAR)
return true; return true;
if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) {

View file

@ -13,7 +13,7 @@ TextCtrl::TextCtrl()
incundoserial = false; incundoserial = false;
undo_op = false; undo_op = false;
WhenBar = THISBACK(StdBar); WhenBar = THISBACK(StdBar);
charset = CHARSET_UNICODE; charset = CHARSET_UTF8;
color[INK_NORMAL] = SColorText; color[INK_NORMAL] = SColorText;
color[INK_DISABLED] = SColorDisabled; color[INK_DISABLED] = SColorDisabled;
color[INK_SELECTED] = SColorHighlightText; color[INK_SELECTED] = SColorHighlightText;

View file

@ -249,6 +249,8 @@ Vector<FaceInfo> GetAllFacesSys()
String GetFontDataSys(Font font, const char *table, int offset, int size) String GetFontDataSys(Font font, const char *table, int offset, int size)
{ // read truetype or opentype table { // read truetype or opentype table
if(!table)
return LoadFile(font.Fi().path);
FileIn in(font.Fi().path); FileIn in(font.Fi().path);
int q = in.Get32be(); int q = in.Get32be();
if(q == 0x74746366) { // font collection if(q == 0x74746366) { // font collection

View file

@ -492,7 +492,7 @@ bool OCI8Connection::BulkExecute(const char *stmt, const Vector< Vector<Value> >
sql_type = SQLT_STR; sql_type = SQLT_STR;
if(session->utf8_session) { if(session->utf8_session) {
WString wstr(v); WString wstr(v);
len = 1 + lenAsUtf8(wstr, wstr.GetLength()); len = 1 + Utf8Len(wstr, wstr.GetLength());
} }
else else
len = 1 + String(v).GetLength(); len = 1 + String(v).GetLength();
@ -910,7 +910,7 @@ void OCI8Connection::GetColumn(int i, WString& ws) const {
s = (char *) c.Data(); s = (char *) c.Data();
} }
if(session->utf8_session) if(session->utf8_session)
ws = FromUtf8(s); ws = ToUtf32(s);
else else
ws = s.ToWString(); ws = s.ToWString();
} }
@ -1610,13 +1610,9 @@ dword OracleClob::Read(int64 at, void *ptr, dword size) {
return full_bytes; return full_bytes;
WString unibuf; WString unibuf;
if(utf8) if(utf8)
unibuf = FromUtf8(charbuf, nchars); unibuf = ToUtf32(charbuf, nchars);
else { else
WStringBuffer tmp; unibuf = ToUnicode(charbuf, nchars, CHARSET_DEFAULT);
tmp.SetLength(nchars);
ToUnicode(tmp, charbuf, nchars, CHARSET_DEFAULT);
unibuf = tmp;
}
int ulen = unibuf.GetLength(); int ulen = unibuf.GetLength();
int uoff = (int)(at & 1); int uoff = (int)(at & 1);
int upart = min((int)size, 2 * ulen - uoff); int upart = min((int)size, 2 * ulen - uoff);
@ -1663,12 +1659,8 @@ void OracleClob::Write(int64 at, const void *ptr, dword size) {
String chrbuf; String chrbuf;
if(utf8) if(utf8)
chrbuf = ToUtf8((const wchar *)ptr, nchars); chrbuf = ToUtf8((const wchar *)ptr, nchars);
else { else
StringBuffer tmp; chrbuf = FromUnicode((const wchar *)ptr, nchars, CHARSET_DEFAULT);
tmp.SetLength(nchars);
FromUnicode(tmp, (const wchar *)ptr, nchars, CHARSET_DEFAULT);
chrbuf = tmp;
}
ub4 n = chrbuf.GetLength(); ub4 n = chrbuf.GetLength();
sword res = session->oci8.OCILobWrite(session->svchp, session->errhp, locp, sword res = session->oci8.OCILobWrite(session->svchp, session->errhp, locp,
&n, (dword)(at >> 1) + 1, (dvoid *)chrbuf.Begin(), chrbuf.GetLength(), &n, (dword)(at >> 1) + 1, (dvoid *)chrbuf.Begin(), chrbuf.GetLength(),

View file

@ -53,7 +53,7 @@ void AppendClipboardText(const String& s)
void AppendClipboardUnicodeText(const WString& s) void AppendClipboardUnicodeText(const WString& s)
{ {
AppendClipboard("wtext", (byte *)~s, 2 * s.GetLength()); AppendClipboard("wtext", (byte *)~s, sizeof(wchar) * s.GetLength());
} }
const char *ClipFmtsText() const char *ClipFmtsText()
@ -66,7 +66,7 @@ String GetString(PasteClip& clip)
GuiLock __; GuiLock __;
if(clip.Accept("wtext")) { if(clip.Accept("wtext")) {
String s = ~clip; 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")) if(clip.IsAvailable("text"))
return ~clip; return ~clip;
@ -78,7 +78,7 @@ WString GetWString(PasteClip& clip)
GuiLock __; GuiLock __;
if(clip.Accept("wtext")) { if(clip.Accept("wtext")) {
String s = ~clip; 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")) if(clip.IsAvailable("text"))
return (~clip).ToWString(); return (~clip).ToWString();

View file

@ -38,7 +38,7 @@ void SDL2GUI::HandleSDLEvent(SDL_Event* event)
// break; // break;
case SDL_TEXTINPUT: { case SDL_TEXTINPUT: {
//send respective keyup things as char events as well //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++) { for(int i = 0; i < text.GetCount(); i++) {
int c = text[i]; int c = text[i];
if(c != 127) if(c != 127)

View file

@ -72,9 +72,9 @@ FtFontStyle GetFontStyle(Font font)
return fd.At(0).style[0]; return fd.At(0).style[0];
} }
String GetFontDataSys(Font font) String GetFontDataSys(Font font, const char *table, int offset, int size)
{ { // TODO: Finish this!
return LoadFile(font.Fi().path); return Null;
} }
static FT_Library sFTlib; static FT_Library sFTlib;