From 8826daf07046348837a57795aafb523af662b764 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Sat, 15 Jan 2022 14:42:23 +0100 Subject: [PATCH] FT_fontsys: Add missing GetFontDataSys implementation --- reference/SDL2Uword/main.cpp | 2 +- uppsrc/Draw/FontCR.cpp | 39 ++++++++++++++++++++++++ uppsrc/Draw/FontFc.cpp | 40 +++---------------------- uppsrc/plugin/FT_fontsys/FT_fontsys.cpp | 23 +++++++++++--- 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/reference/SDL2Uword/main.cpp b/reference/SDL2Uword/main.cpp index 6b0ee2a7d..396266b83 100644 --- a/reference/SDL2Uword/main.cpp +++ b/reference/SDL2Uword/main.cpp @@ -241,7 +241,7 @@ CONSOLE_APP_MAIN { SDL2GUI gui; gui.Create(RectC(100, 100, 1024, 768), "SDL2GL Virtual Gui Test"); - + RunVirtualGui(gui, [] { SetLanguage(LNG_ENGLISH); SetDefaultCharset(CHARSET_UTF8); diff --git a/uppsrc/Draw/FontCR.cpp b/uppsrc/Draw/FontCR.cpp index 2e9de474e..1a4377514 100644 --- a/uppsrc/Draw/FontCR.cpp +++ b/uppsrc/Draw/FontCR.cpp @@ -481,4 +481,43 @@ bool Replace(Font fnt, int chr, Font& rfnt) return false; } +String GetFontDataSysSys(Stream& in, int fonti, const char *table, int offset, int size) +{ // read truetype or opentype table from file - common implementation + int q = in.Get32be(); + if(q == 0x74746366) { // font collection + in.Get32(); // skip major/minor version + int nfonts = in.Get32be(); + if(fonti >= nfonts) + return Null; + in.SeekCur(fonti * 4); + int offset = in.Get32be(); + if(offset < 0 || offset >= in.GetSize()) + return Null; + in.Seek(offset); + q = in.Get32be(); + } + if(q != 0x74727565 && q != 0x00010000 && q != 0x4f54544f) // 0x4f54544f means CCF font! + return Null; + int n = in.Get16be(); + in.Get32(); + in.Get16(); + while(n--) { + if(in.IsError() || in.IsEof()) return Null; + String tab = in.Get(4); + in.Get32(); + int off = in.Get32be(); + int len = in.Get32be(); + if(tab == table) { + if(off < 0 || len < 0 || off + len > in.GetSize()) + return Null; + len = min(len - offset, size); + if(len < 0) + return Null; + in.Seek(off + offset); + return in.Get(len); + } + } + return Null; +} + } diff --git a/uppsrc/Draw/FontFc.cpp b/uppsrc/Draw/FontFc.cpp index b8f01ea4a..c0d37b590 100644 --- a/uppsrc/Draw/FontFc.cpp +++ b/uppsrc/Draw/FontFc.cpp @@ -259,46 +259,14 @@ Vector GetAllFacesSys() return list.PickValues(); } +extern String GetFontDataSysSys(Stream& in, int fonti, const char *table, int offset, int size); + 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 - in.Get32(); // skip major/minor version - int nfonts = in.Get32be(); - if(font.Fi().fonti >= nfonts) - return Null; - in.SeekCur(font.Fi().fonti * 4); - int offset = in.Get32be(); - if(offset < 0 || offset >= in.GetSize()) - return Null; - in.Seek(offset); - q = in.Get32be(); - } - if(q != 0x74727565 && q != 0x00010000 && q != 0x4f54544f) // 0x4f54544f means CCF font! - return Null; - int n = in.Get16be(); - in.Get32(); - in.Get16(); - while(n--) { - if(in.IsError() || in.IsEof()) return Null; - String tab = in.Get(4); - in.Get32(); - int off = in.Get32be(); - int len = in.Get32be(); - if(tab == table) { - if(off < 0 || len < 0 || off + len > in.GetSize()) - return Null; - len = min(len - offset, size); - if(len < 0) - return Null; - in.Seek(off + offset); - return in.Get(len); - } - } - return Null; + return GetFontDataSysSys(in, font.Fi().fonti, table, offset, size); } static inline double ft_dbl(int p) diff --git a/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp b/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp index ccf467da5..a25cde6db 100644 --- a/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp +++ b/uppsrc/plugin/FT_fontsys/FT_fontsys.cpp @@ -72,14 +72,29 @@ FtFontStyle GetFontStyle(Font font) return fd.At(0).style[0]; } +extern String GetFontDataSysSys(Stream& in, int fonti, const char *table, int offset, int size); + String GetFontDataSys(Font font, const char *table, int offset, int size) -{ // TODO: Finish this! - return Null; +{ + FtFontStyle f = GetFontStyle(font); + + if(IsNull(f.path)) { + if(table) { + MemReadStream in(f.data, f.size); + return GetFontDataSysSys(in, 0, table, offset, size); + } + return String(f.data, min((int)f.size, 100*1024*1024)); + } + if(table) { + FileIn in(f.path); + return GetFontDataSysSys(in, 0, table, offset, size); + } + return LoadFile(f.path); } static FT_Library sFTlib; -EXITBLOCK +EXITBLOCK { if(sFTlib) FT_Done_FreeType(sFTlib); @@ -404,7 +419,7 @@ bool RenderOutline(const FT_Outline& outline, FontGlyphConsumer& path, double xx } Close: path.Close(); - first = last + 1; + first = last + 1; } return true; }