main.cc revision 8dd1c8b8d6797d899d0f5b0a8015886bf6520ca2
1#include "hb-ot-layout-open-private.h"
2#include "hb-ot-layout-gdef-private.h"
3
4#include <stdlib.h>
5#include <stdio.h>
6
7int
8main (int argc, char **argv)
9{
10  if (argc != 2) {
11    fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
12    exit (1);
13  }
14
15  GMappedFile *mf = g_mapped_file_new (argv[1], FALSE, NULL);
16  const char *font_data = g_mapped_file_get_contents (mf);
17  int len = g_mapped_file_get_length (mf);
18
19  printf ("Opened font file %s: %d bytes long\n", argv[1], len);
20
21  const OpenTypeFontFile &ot = OpenTypeFontFile::get_for_data (font_data);
22
23  switch (ot.get_tag()) {
24  case OpenTypeFontFile::TrueTypeTag:
25    printf ("OpenType font with TrueType outlines\n");
26    break;
27  case OpenTypeFontFile::CFFTag:
28    printf ("OpenType font with CFF (Type1) outlines\n");
29    break;
30  case OpenTypeFontFile::TTCTag:
31    printf ("TrueType Collection of OpenType fonts\n");
32    break;
33  default:
34    printf ("Unknown font format\n");
35    break;
36  }
37
38  int num_fonts = ot.get_len ();
39  printf ("%d font(s) found in file\n", num_fonts);
40  for (int n_font = 0; n_font < num_fonts; n_font++) {
41    const OpenTypeFontFace &font = ot[n_font];
42    printf ("Font %d of %d:\n", n_font+1, num_fonts);
43
44    int num_tables = font.get_len ();
45    printf ("  %d table(s) found in font\n", num_tables);
46    for (int n_table = 0; n_table < num_tables; n_table++) {
47      const OpenTypeTable &table = font[n_table];
48      printf ("  Table %2d of %2d: %.4s (0x%08lx+0x%08lx)\n", n_table+1, num_tables,
49	      (const char *)table.get_tag(), table.get_offset(), table.get_length());
50
51      if (table.get_tag() == "GSUB" || table.get_tag() == "GPOS") {
52        const GSUBGPOSHeader &g = GSUBGPOSHeader::get_for_data (ot[table]);
53
54	const ScriptList &scripts = g.get_script_list();
55	int num_scripts = scripts.get_len ();
56	printf ("    %d script(s) found in table\n", num_scripts);
57	for (int n_script = 0; n_script < num_scripts; n_script++) {
58	  const Script &script = scripts[n_script];
59	  printf ("    Script %2d of %2d: %.4s\n", n_script+1, num_scripts,
60	          (const char *)scripts.get_tag(n_script));
61
62	  if (!script.has_default_language_system())
63	    printf ("      No default language system\n");
64	  int num_langsys = script.get_len ();
65	  printf ("      %d language system(s) found in script\n", num_langsys);
66	  for (int n_langsys = 0; n_langsys < num_langsys; n_langsys++) {
67	    const LangSys &langsys = script[n_langsys];
68	    printf ("      Language System %2d of %2d: %.4s; %d features\n", n_langsys+1, num_langsys,
69	            (const char *)script.get_tag(n_langsys),
70		    langsys.get_len ());
71	    if (!langsys.get_required_feature_index ())
72	      printf ("        No required feature\n");
73	  }
74	}
75
76	const FeatureList &features = g.get_feature_list();
77	int num_features = features.get_len ();
78	printf ("    %d feature(s) found in table\n", num_features);
79	for (int n_feature = 0; n_feature < num_features; n_feature++) {
80	  const Feature &feature = features[n_feature];
81	  printf ("    Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature+1, num_features,
82	          (const char *)features.get_tag(n_feature),
83		  feature.get_len());
84	}
85
86	const LookupList &lookups = g.get_lookup_list();
87	int num_lookups = lookups.get_len ();
88	printf ("    %d lookup(s) found in table\n", num_lookups);
89	for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
90	  const Lookup &lookup = lookups[n_lookup];
91	  printf ("    Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups,
92	          lookup.get_type(), lookup.get_flag());
93	}
94      } else if (table.get_tag() == "GDEF") {
95        const GDEFHeader &gdef = GDEFHeader::get_for_data (ot[table]);
96
97	for (int glyph = 0; glyph < 1; glyph++)
98	  printf ("    glyph %d has class %d and mark attachment type %d\n",
99		  glyph,
100		  gdef.get_glyph_class (glyph),
101		  gdef.get_mark_attachment_type (glyph));
102      }
103    }
104  }
105
106  return 0;
107}
108