diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2018-04-20 10:29:06 +0430 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-04-20 07:59:06 +0200 |
commit | ce17340b23d96f543cd88e400e631bdb5656331c (patch) | |
tree | 29a64fa87fd95854b21190d18eccc07db346e7c8 /src/main.cc | |
parent | 4fa1c6705a1bc5299adb5a848ceaf6ac8f33c0ba (diff) |
Add hb_blob_create_from_file, a new API (#926)
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/src/main.cc b/src/main.cc index 9423a728..935fa392 100644 --- a/src/main.cc +++ b/src/main.cc @@ -49,32 +49,12 @@ main (int argc, char **argv) exit (1); } - const char *font_data = nullptr; - int len = 0; - hb_destroy_func_t destroy; - hb_memory_mode_t mm; - -#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); - destroy = (hb_destroy_func_t) g_mapped_file_unref; - mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; -#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); - destroy = free; - mm = HB_MEMORY_MODE_WRITABLE; -#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); Sanitizer<OpenTypeFontFile> sanitizer; - hb_blob_t *blob = hb_blob_create (font_data, len, mm, (void *) font_data, destroy); hb_blob_t *font_blob = sanitizer.sanitize (blob); const OpenTypeFontFile* sanitized = Sanitizer<OpenTypeFontFile>::lock_instance (font_blob); if (sanitized == &Null (OpenTypeFontFile)) |