public static byte[] ReadProgram(DataReader reader, TableRecord[] tables, FourCC tag) { var index = FindTable(tables, tag); if (index == -1) { return(null); } reader.Seek(tables[index].Offset); return(reader.ReadBytes((int)tables[index].Length)); }
public static int FindTable(TableRecord[] tables, FourCC tag) { var index = -1; for (var i = 0; i < tables.Length; i++) { if (tables[i].Tag == tag) { index = i; break; } } return(index); }
public static bool SeekToTable(DataReader reader, TableRecord[] tables, FourCC tag, bool required = false) { // check if we have the desired table and that it's not empty var index = FindTable(tables, tag); if (index == -1 || tables[index].Length == 0) { if (required) { throw new InvalidFontException($"Missing or empty '{tag}' table."); } return(false); } // seek to the appropriate offset reader.Seek(tables[index].Offset); return(true); }