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