michael@0: /* michael@0: * Copyright © 2007,2008,2009 Red Hat, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Red Hat Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #include "hb-mutex-private.hh" michael@0: #include "hb-open-file-private.hh" michael@0: #include "hb-ot-layout-gdef-table.hh" michael@0: #include "hb-ot-layout-gsubgpos-private.hh" michael@0: michael@0: #ifdef HAVE_GLIB michael@0: #include michael@0: #endif michael@0: #include michael@0: #include michael@0: michael@0: michael@0: using namespace OT; michael@0: michael@0: michael@0: int michael@0: main (int argc, char **argv) michael@0: { michael@0: if (argc != 2) { michael@0: fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]); michael@0: exit (1); michael@0: } michael@0: michael@0: const char *font_data = NULL; michael@0: int len = 0; michael@0: michael@0: #ifdef HAVE_GLIB michael@0: GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); michael@0: font_data = g_mapped_file_get_contents (mf); michael@0: len = g_mapped_file_get_length (mf); michael@0: #else michael@0: FILE *f = fopen (argv[1], "rb"); michael@0: fseek (f, 0, SEEK_END); michael@0: len = ftell (f); michael@0: fseek (f, 0, SEEK_SET); michael@0: font_data = (const char *) malloc (len); michael@0: len = fread ((char *) font_data, 1, len, f); michael@0: #endif michael@0: michael@0: printf ("Opened font file %s: %d bytes long\n", argv[1], len); michael@0: michael@0: const OpenTypeFontFile &ot = *CastP (font_data); michael@0: michael@0: switch (ot.get_tag ()) { michael@0: case OpenTypeFontFile::TrueTypeTag: michael@0: printf ("OpenType font with TrueType outlines\n"); michael@0: break; michael@0: case OpenTypeFontFile::CFFTag: michael@0: printf ("OpenType font with CFF (Type1) outlines\n"); michael@0: break; michael@0: case OpenTypeFontFile::TTCTag: michael@0: printf ("TrueType Collection of OpenType fonts\n"); michael@0: break; michael@0: case OpenTypeFontFile::TrueTag: michael@0: printf ("Obsolete Apple TrueType font\n"); michael@0: break; michael@0: case OpenTypeFontFile::Typ1Tag: michael@0: printf ("Obsolete Apple Type1 font in SFNT container\n"); michael@0: break; michael@0: default: michael@0: printf ("Unknown font format\n"); michael@0: break; michael@0: } michael@0: michael@0: int num_fonts = ot.get_face_count (); michael@0: printf ("%d font(s) found in file\n", num_fonts); michael@0: for (int n_font = 0; n_font < num_fonts; n_font++) { michael@0: const OpenTypeFontFace &font = ot.get_face (n_font); michael@0: printf ("Font %d of %d:\n", n_font, num_fonts); michael@0: michael@0: int num_tables = font.get_table_count (); michael@0: printf (" %d table(s) found in font\n", num_tables); michael@0: for (int n_table = 0; n_table < num_tables; n_table++) { michael@0: const OpenTypeTable &table = font.get_table (n_table); michael@0: printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, michael@0: (const char *)table.tag, michael@0: (unsigned int) table.offset, michael@0: (unsigned int) table.length); michael@0: michael@0: switch (table.tag) { michael@0: michael@0: case GSUBGPOS::GSUBTag: michael@0: case GSUBGPOS::GPOSTag: michael@0: { michael@0: michael@0: const GSUBGPOS &g = *CastP (font_data + table.offset); michael@0: michael@0: int num_scripts = g.get_script_count (); michael@0: printf (" %d script(s) found in table\n", num_scripts); michael@0: for (int n_script = 0; n_script < num_scripts; n_script++) { michael@0: const Script &script = g.get_script (n_script); michael@0: printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts, michael@0: (const char *)g.get_script_tag(n_script)); michael@0: michael@0: if (!script.has_default_lang_sys()) michael@0: printf (" No default language system\n"); michael@0: int num_langsys = script.get_lang_sys_count (); michael@0: printf (" %d language system(s) found in script\n", num_langsys); michael@0: for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) { michael@0: const LangSys &langsys = n_langsys == -1 michael@0: ? script.get_default_lang_sys () michael@0: : script.get_lang_sys (n_langsys); michael@0: if (n_langsys == -1) michael@0: printf (" Default Language System\n"); michael@0: else michael@0: printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys, michael@0: (const char *)script.get_lang_sys_tag (n_langsys)); michael@0: if (langsys.get_required_feature_index () == Index::NOT_FOUND_INDEX) michael@0: printf (" No required feature\n"); michael@0: michael@0: int num_features = langsys.get_feature_count (); michael@0: printf (" %d feature(s) found in language system\n", num_features); michael@0: for (int n_feature = 0; n_feature < num_features; n_feature++) { michael@0: printf (" Feature index %2d of %2d: %d\n", n_feature, num_features, michael@0: langsys.get_feature_index (n_feature)); michael@0: } michael@0: } michael@0: } michael@0: michael@0: int num_features = g.get_feature_count (); michael@0: printf (" %d feature(s) found in table\n", num_features); michael@0: for (int n_feature = 0; n_feature < num_features; n_feature++) { michael@0: const Feature &feature = g.get_feature (n_feature); michael@0: printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature, num_features, michael@0: (const char *)g.get_feature_tag(n_feature), michael@0: feature.get_lookup_count()); michael@0: michael@0: int num_lookups = feature.get_lookup_count (); michael@0: printf (" %d lookup(s) found in feature\n", num_lookups); michael@0: for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { michael@0: printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups, michael@0: feature.get_lookup_index (n_lookup)); michael@0: } michael@0: } michael@0: michael@0: int num_lookups = g.get_lookup_count (); michael@0: printf (" %d lookup(s) found in table\n", num_lookups); michael@0: for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { michael@0: const Lookup &lookup = g.get_lookup (n_lookup); michael@0: printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups, michael@0: lookup.get_type(), lookup.get_props()); michael@0: } michael@0: michael@0: } michael@0: break; michael@0: michael@0: case GDEF::tableTag: michael@0: { michael@0: michael@0: const GDEF &gdef = *CastP (font_data + table.offset); michael@0: michael@0: printf (" Has %sglyph classes\n", michael@0: gdef.has_glyph_classes () ? "" : "no "); michael@0: printf (" Has %smark attachment types\n", michael@0: gdef.has_mark_attachment_types () ? "" : "no "); michael@0: printf (" Has %sattach points\n", michael@0: gdef.has_attach_points () ? "" : "no "); michael@0: printf (" Has %slig carets\n", michael@0: gdef.has_lig_carets () ? "" : "no "); michael@0: printf (" Has %smark sets\n", michael@0: gdef.has_mark_sets () ? "" : "no "); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: