diff options
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/main.cc b/src/main.cc index f9708cc..ca0fcc5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -24,7 +24,7 @@ * Red Hat Author(s): Behdad Esfahbod */ -#include "hb-mutex-private.hh" +#include "hb-static.cc" #include "hb-open-file-private.hh" #include "hb-ot-layout-gdef-table.hh" #include "hb-ot-layout-gsubgpos-private.hh" @@ -38,7 +38,6 @@ using namespace OT; - int main (int argc, char **argv) { @@ -47,25 +46,21 @@ main (int argc, char **argv) exit (1); } - const char *font_data = NULL; - int len = 0; - -#ifdef HAVE_GLIB - GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); - font_data = g_mapped_file_get_contents (mf); - len = g_mapped_file_get_length (mf); -#else - FILE *f = fopen (argv[1], "rb"); - fseek (f, 0, SEEK_END); - len = ftell (f); - fseek (f, 0, SEEK_SET); - font_data = (const char *) malloc (len); - len = fread ((char *) font_data, 1, len, f); -#endif - + hb_blob_t *blob = hb_blob_create_from_file (argv[1]); + unsigned int len; + const char *font_data = hb_blob_get_data (blob, &len); printf ("Opened font file %s: %d bytes long\n", argv[1], len); - const OpenTypeFontFile &ot = *CastP<OpenTypeFontFile> (font_data); + Sanitizer<OpenTypeFontFile> sanitizer; + hb_blob_t *font_blob = sanitizer.sanitize (blob); + const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> (); + if (sanitized == &Null(OpenTypeFontFile)) + { + printf ("Sanitization of the file wasn't successful. Exit"); + return 1; + } + const OpenTypeFontFile& ot = *sanitized; + switch (ot.get_tag ()) { case OpenTypeFontFile::TrueTypeTag: @@ -99,14 +94,14 @@ main (int argc, char **argv) for (int n_table = 0; n_table < num_tables; n_table++) { const OpenTypeTable &table = font.get_table (n_table); printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, - (const char *)table.tag, + (const char *) table.tag, (unsigned int) table.offset, (unsigned int) table.length); switch (table.tag) { - case GSUBGPOS::GSUBTag: - case GSUBGPOS::GPOSTag: + case HB_OT_TAG_GSUB: + case HB_OT_TAG_GPOS: { const GSUBGPOS &g = *CastP<GSUBGPOS> (font_data + table.offset); @@ -195,5 +190,3 @@ main (int argc, char **argv) return 0; } - - |