Imported Upstream version 1.8.1
[platform/upstream/harfbuzz.git] / src / main.cc
index d221e9d..ca0fcc5 100644 (file)
@@ -24,6 +24,7 @@
  * Red Hat Author(s): Behdad Esfahbod
  */
 
+#include "hb-static.cc"
 #include "hb-open-file-private.hh"
 #include "hb-ot-layout-gdef-table.hh"
 #include "hb-ot-layout-gsubgpos-private.hh"
 
 using namespace OT;
 
-#ifndef HB_NO_VISIBILITY
-const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-#endif
-
 int
 main (int argc, char **argv)
 {
@@ -49,25 +46,21 @@ main (int argc, char **argv)
     exit (1);
   }
 
-  const char *font_data = nullptr;
-  int len = 0;
-
-#ifdef HAVE_GLIB
-  GMappedFile *mf = g_mapped_file_new (argv[1], false, nullptr);
-  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:
@@ -101,7 +94,7 @@ 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);
 
@@ -197,5 +190,3 @@ main (int argc, char **argv)
 
   return 0;
 }
-
-