mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 06:05:58 -06:00
FT_fontsys: Add missing GetFontDataSys implementation
This commit is contained in:
parent
8337e7c250
commit
8826daf070
4 changed files with 63 additions and 41 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,46 +259,14 @@ Vector<FaceInfo> 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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue