blob: 313723e9bedb3ac106f126f6f6dc142d168ac509 [file] [log] [blame]
Behdad Esfahbod12c45682006-12-28 06:10:59 -05001#include "harfbuzz-open-private.h"
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -05002#include "harfbuzz-gdef-private.h"
Behdad Esfahbod12c45682006-12-28 06:10:59 -05003
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
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -050021 const OpenTypeFontFile &ot = OpenTypeFontFile::get_for_data (font_data);
Behdad Esfahbod12c45682006-12-28 06:10:59 -050022
Behdad Esfahbod303fe622008-01-23 00:20:48 -050023 switch (ot.get_tag()) {
Behdad Esfahbod12c45682006-12-28 06:10:59 -050024 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];
Behdad Esfahbod303fe622008-01-23 00:20:48 -050048 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());
Behdad Esfahbod12c45682006-12-28 06:10:59 -050050
Behdad Esfahbod303fe622008-01-23 00:20:48 -050051 if (table.get_tag() == "GSUB" || table.get_tag() == "GPOS") {
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -050052 const GSUBGPOSHeader &g = GSUBGPOSHeader::get_for_data (ot[table]);
Behdad Esfahbod12c45682006-12-28 06:10:59 -050053
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.get_default_language_system () == NULL)
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),
Behdad Esfahbod303fe622008-01-23 00:20:48 -050083 feature.get_len());
Behdad Esfahbod12c45682006-12-28 06:10:59 -050084 }
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,
Behdad Esfahbod303fe622008-01-23 00:20:48 -050092 lookup.get_type(), lookup.get_flag());
Behdad Esfahbod12c45682006-12-28 06:10:59 -050093 }
Behdad Esfahbodb9d76882008-01-23 01:38:10 -050094 } else if (table.get_tag() == "GDEF") {
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -050095 const GDEFHeader &gdef = GDEFHeader::get_for_data (ot[table]);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -050096
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -050097 for (int glyph = 0; glyph < 1; glyph++)
Behdad Esfahbodb9d76882008-01-23 01:38:10 -050098 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));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500102 }
103 }
104 }
105
106 return 0;
107}