blob: e898e6e4b60557975e6779e8202f2f5c9aa896ae [file] [log] [blame]
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009 Red Hat, Inc.
Ebrahim Byagowi23277be2020-01-24 18:49:48 +03303 * Copyright © 2018,2019,2020 Ebrahim Byagowi
4 * Copyright © 2018 Khaled Hosny
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05005 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04006 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05007 *
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Behdad Esfahbod
27 */
28
Ebrahim Byagowi750bb732020-04-21 01:13:13 +043029#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033033#include "hb.h"
34#include "hb-ot.h"
Behdad Esfahbod12c45682006-12-28 06:10:59 -050035
36#include <stdlib.h>
37#include <stdio.h>
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033038#include <string.h>
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040039
Ebrahim Byagowibb4cdf82019-06-25 01:42:42 +043040#ifdef HB_NO_OPEN
41#define hb_blob_create_from_file(x) hb_blob_get_empty ()
42#endif
43
Ebrahim Byagowi750bb732020-04-21 01:13:13 +043044#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW) && defined(HB_EXPERIMENTAL_API)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033045static void
46svg_dump (hb_face_t *face, unsigned face_index)
47{
48 unsigned glyph_count = hb_face_get_glyph_count (face);
49
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033050 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033051 {
52 hb_blob_t *blob = hb_ot_color_glyph_reference_svg (face, glyph_id);
53
54 if (hb_blob_get_length (blob) == 0) continue;
55
56 unsigned length;
57 const char *data = hb_blob_get_data (blob, &length);
58
59 char output_path[255];
60 sprintf (output_path, "out/svg-%u-%u.svg%s",
61 glyph_id,
62 face_index,
63 // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
64 (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
65
66 FILE *f = fopen (output_path, "wb");
67 fwrite (data, 1, length, f);
68 fclose (f);
69
70 hb_blob_destroy (blob);
71 }
72}
73
74/* _png API is so easy to use unlike the below code, don't get confused */
75static void
76png_dump (hb_face_t *face, unsigned face_index)
77{
78 unsigned glyph_count = hb_face_get_glyph_count (face);
79 hb_font_t *font = hb_font_create (face);
80
81 /* scans the font for strikes */
82 unsigned sample_glyph_id;
83 /* we don't care about different strikes for different glyphs at this point */
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033084 for (sample_glyph_id = 0; sample_glyph_id < glyph_count; ++sample_glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033085 {
86 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
87 unsigned blob_length = hb_blob_get_length (blob);
88 hb_blob_destroy (blob);
89 if (blob_length != 0)
90 break;
91 }
92
93 unsigned upem = hb_face_get_upem (face);
94 unsigned blob_length = 0;
95 unsigned strike = 0;
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033096 for (unsigned ppem = 1; ppem < upem; ++ppem)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033097 {
98 hb_font_set_ppem (font, ppem, ppem);
99 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
100 unsigned new_blob_length = hb_blob_get_length (blob);
101 hb_blob_destroy (blob);
102 if (new_blob_length != blob_length)
103 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330104 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330105 {
106 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, glyph_id);
107
108 if (hb_blob_get_length (blob) == 0) continue;
109
110 unsigned length;
111 const char *data = hb_blob_get_data (blob, &length);
112
113 char output_path[255];
114 sprintf (output_path, "out/png-%u-%u-%u.png", glyph_id, strike, face_index);
115
116 FILE *f = fopen (output_path, "wb");
117 fwrite (data, 1, length, f);
118 fclose (f);
119
120 hb_blob_destroy (blob);
121 }
122
123 strike++;
124 blob_length = new_blob_length;
125 }
126 }
127
128 hb_font_destroy (font);
129}
130
131struct user_data_t
132{
133 FILE *f;
134 hb_position_t ascender;
135};
136
137static void
138move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
139{
140 fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
141}
142
143static void
144line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
145{
146 fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
147}
148
149static void
Ebrahim Byagowi74fdcdc2020-01-28 13:45:22 +0330150quadratic_to (hb_position_t control_x, hb_position_t control_y,
151 hb_position_t to_x, hb_position_t to_y,
152 user_data_t &user_data)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330153{
154 fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
155 to_x, user_data.ascender - to_y);
156}
157
158static void
159cubic_to (hb_position_t control1_x, hb_position_t control1_y,
160 hb_position_t control2_x, hb_position_t control2_y,
161 hb_position_t to_x, hb_position_t to_y,
162 user_data_t &user_data)
163{
164 fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
165 control2_x, user_data.ascender - control2_y,
166 to_x, user_data.ascender - to_y);
167}
168
169static void
170close_path (user_data_t &user_data)
171{
172 fprintf (user_data.f, "Z");
173}
174
175static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330176layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330177{
178 hb_face_t *face = hb_font_get_face (font);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330179 unsigned palette_count = hb_ot_color_palette_get_count (face);
180 for (unsigned palette = 0; palette < palette_count; ++palette)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330181 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330182 unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
183 if (!num_colors) continue;
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330184
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330185 hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
186 hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
187 if (!num_colors)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330188 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330189 free (colors);
190 continue;
191 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330192
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330193 unsigned num_glyphs = hb_face_get_glyph_count (face);
194 for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
195 {
196 unsigned num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
197 if (!num_layers) continue;
198
199 hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
200
201 hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
202 if (num_layers)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330203 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330204 hb_font_extents_t font_extents;
205 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
206 hb_glyph_extents_t extents = {0};
207 if (!hb_font_get_glyph_extents (font, gid, &extents))
208 {
209 printf ("Skip gid: %d\n", gid);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330210 continue;
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330211 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330212
213 char output_path[255];
214 sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330215 FILE *f = fopen (output_path, "wb");
216 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330217 " viewBox=\"%d %d %d %d\">\n",
218 extents.x_bearing, 0,
219 extents.x_bearing + extents.width, -extents.height);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330220 user_data_t user_data;
221 user_data.ascender = extents.y_bearing;
222 user_data.f = f;
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330223
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330224 for (unsigned layer = 0; layer < num_layers; ++layer)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330225 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330226 hb_color_t color = 0x000000FF;
227 if (layers[layer].color_index != 0xFFFF)
228 color = colors[layers[layer].color_index];
229 fprintf (f, "<path fill=\"#%02X%02X%02X\" ",
230 hb_color_get_red (color), hb_color_get_green (color), hb_color_get_green (color));
231 if (hb_color_get_alpha (color) != 255)
232 fprintf (f, "fill-opacity=\"%.3f\"", (double) hb_color_get_alpha (color) / 255.);
233 fprintf (f, "d=\"");
234 if (!hb_font_draw_glyph (font, layers[layer].glyph, funcs, &user_data))
235 printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
236 fprintf (f, "\"/>\n");
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330237 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330238
239 fprintf (f, "</svg>");
240 fclose (f);
241 }
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330242 free (layers);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330243 }
244
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330245 free (colors);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330246 }
247}
248
249static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330250dump_glyphs (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330251{
252 unsigned num_glyphs = hb_face_get_glyph_count (hb_font_get_face (font));
253 for (unsigned gid = 0; gid < num_glyphs; ++gid)
254 {
255 hb_font_extents_t font_extents;
256 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
257 hb_glyph_extents_t extents = {0};
258 if (!hb_font_get_glyph_extents (font, gid, &extents))
259 {
260 printf ("Skip gid: %d\n", gid);
261 continue;
262 }
263
264 char output_path[255];
265 sprintf (output_path, "out/%u-%u.svg", face_index, gid);
266 FILE *f = fopen (output_path, "wb");
267 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
268 " viewBox=\"%d %d %d %d\"><path d=\"",
269 extents.x_bearing, 0,
270 extents.x_bearing + extents.width, font_extents.ascender - font_extents.descender);
271 user_data_t user_data;
272 user_data.ascender = font_extents.ascender;
273 user_data.f = f;
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330274 if (!hb_font_draw_glyph (font, gid, funcs, &user_data))
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330275 printf ("Failed to decompose gid: %d\n", gid);
276 fprintf (f, "\"/></svg>");
277 fclose (f);
278 }
279}
280
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330281static void
282dump_glyphs (hb_blob_t *blob, const char *font_name)
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500283{
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330284 FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
Ebrahim Byagowi2be859d2020-04-20 23:48:23 +0430285 if (font_name_file)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330286 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330287 fprintf (stderr, "Purge or rename ./out folder if you like to run a glyph dump,\n"
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330288 "run it like `rm -rf out && mkdir out && src/main font-file.ttf`\n");
289 return;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500290 }
291
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330292 font_name_file = fopen ("out/.dumped_font_name", "w");
Ebrahim Byagowi2be859d2020-04-20 23:48:23 +0430293 if (!font_name_file)
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330294 {
295 fprintf (stderr, "./out is not accessible as a folder, create it please\n");
296 return;
297 }
298 fwrite (font_name, 1, strlen (font_name), font_name_file);
299 fclose (font_name_file);
Behdad Esfahbodce48f032009-11-02 14:35:51 -0500300
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330301 hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
302 hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) move_to);
303 hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) line_to);
Ebrahim Byagowi74fdcdc2020-01-28 13:45:22 +0330304 hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) quadratic_to);
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330305 hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) cubic_to);
306 hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) close_path);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330307
308 unsigned num_faces = hb_face_count (blob);
309 for (unsigned face_index = 0; face_index < num_faces; ++face_index)
310 {
311 hb_face_t *face = hb_face_create (blob, face_index);
312 hb_font_t *font = hb_font_create (face);
313
314 if (hb_ot_color_has_png (face))
315 printf ("Dumping png (CBDT/sbix)...\n");
316 png_dump (face, face_index);
317
318 if (hb_ot_color_has_svg (face))
319 printf ("Dumping svg (SVG )...\n");
320 svg_dump (face, face_index);
321
322 if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
323 printf ("Dumping layered color glyphs (COLR/CPAL)...\n");
324 layered_glyph_dump (font, funcs, face_index);
325
326 dump_glyphs (font, funcs, face_index);
327
328 hb_font_destroy (font);
329 hb_face_destroy (face);
330 }
331
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330332 hb_draw_funcs_destroy (funcs);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330333}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330334#endif
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330335
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430336#ifndef MAIN_CC_NO_PRIVATE_API
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330337/* Only this part of this mini app uses private API */
338#include "hb-static.cc"
339#include "hb-open-file.hh"
340#include "hb-ot-layout-gdef-table.hh"
341#include "hb-ot-layout-gsubgpos.hh"
342
343using namespace OT;
344
345static void
346print_layout_info_using_private_api (hb_blob_t *blob)
347{
348 const char *font_data = hb_blob_get_data (blob, nullptr);
349 hb_blob_t *font_blob = hb_sanitize_context_t ().sanitize_blob<OpenTypeFontFile> (blob);
Behdad Esfahbodeba1c162018-05-08 02:47:42 -0700350 const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
Behdad Esfahbodb912fbe2018-08-06 06:30:12 -0700351 if (!font_blob->data)
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430352 {
353 printf ("Sanitization of the file wasn't successful. Exit");
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330354 exit (1);
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430355 }
356 const OpenTypeFontFile& ot = *sanitized;
357
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330358 switch (ot.get_tag ())
359 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500360 case OpenTypeFontFile::TrueTypeTag:
361 printf ("OpenType font with TrueType outlines\n");
362 break;
363 case OpenTypeFontFile::CFFTag:
364 printf ("OpenType font with CFF (Type1) outlines\n");
365 break;
366 case OpenTypeFontFile::TTCTag:
367 printf ("TrueType Collection of OpenType fonts\n");
368 break;
Behdad Esfahbodce5694c2010-05-04 14:10:18 -0400369 case OpenTypeFontFile::TrueTag:
370 printf ("Obsolete Apple TrueType font\n");
371 break;
372 case OpenTypeFontFile::Typ1Tag:
373 printf ("Obsolete Apple Type1 font in SFNT container\n");
374 break;
Ebrahim Byagowi225b92b2018-07-01 14:32:00 +0430375 case OpenTypeFontFile::DFontTag:
376 printf ("DFont Mac Resource Fork\n");
377 break;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500378 default:
379 printf ("Unknown font format\n");
380 break;
381 }
382
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330383 unsigned num_faces = hb_face_count (blob);
384 printf ("%d font(s) found in file\n", num_faces);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330385 for (unsigned n_font = 0; n_font < num_faces; ++n_font)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330386 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500387 const OpenTypeFontFace &font = ot.get_face (n_font);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330388 printf ("Font %d of %d:\n", n_font, num_faces);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500389
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330390 unsigned num_tables = font.get_table_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500391 printf (" %d table(s) found in font\n", num_tables);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330392 for (unsigned n_table = 0; n_table < num_tables; ++n_table)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330393 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500394 const OpenTypeTable &table = font.get_table (n_table);
Behdad Esfahbod15164d92009-08-04 13:57:41 -0400395 printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430396 (const char *) table.tag,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330397 (unsigned) table.offset,
398 (unsigned) table.length);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500399
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330400 switch (table.tag)
401 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500402
Behdad Esfahboda130ee62017-11-14 20:30:03 -0800403 case HB_OT_TAG_GSUB:
404 case HB_OT_TAG_GPOS:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500405 {
406
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600407 const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500408
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330409 unsigned num_scripts = g.get_script_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500410 printf (" %d script(s) found in table\n", num_scripts);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330411 for (unsigned n_script = 0; n_script < num_scripts; ++n_script)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330412 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500413 const Script &script = g.get_script (n_script);
414 printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330415 (const char *) g.get_script_tag (n_script));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500416
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330417 if (!script.has_default_lang_sys ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500418 printf (" No default language system\n");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500419 int num_langsys = script.get_lang_sys_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500420 printf (" %d language system(s) found in script\n", num_langsys);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330421 for (int n_langsys = script.has_default_lang_sys () ? -1 : 0; n_langsys < num_langsys; ++n_langsys)
422 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500423 const LangSys &langsys = n_langsys == -1
424 ? script.get_default_lang_sys ()
425 : script.get_lang_sys (n_langsys);
Behdad Esfahbod1a2a4a02012-05-05 22:38:20 +0200426 if (n_langsys == -1)
427 printf (" Default Language System\n");
428 else
429 printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330430 (const char *) script.get_lang_sys_tag (n_langsys));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700431 if (!langsys.has_required_feature ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500432 printf (" No required feature\n");
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700433 else
434 printf (" Required feature index: %d\n",
435 langsys.get_required_feature_index ());
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500436
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330437 unsigned num_features = langsys.get_feature_count ();
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500438 printf (" %d feature(s) found in language system\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330439 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330440 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500441 printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330442 langsys.get_feature_index (n_feature));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500443 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500444 }
445 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500446
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330447 unsigned num_features = g.get_feature_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500448 printf (" %d feature(s) found in table\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330449 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330450 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500451 const Feature &feature = g.get_feature (n_feature);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330452 unsigned num_lookups = feature.get_lookup_count ();
Jonathan Kewda132932014-04-27 14:05:24 +0100453 printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330454 HB_UNTAG (g.get_feature_tag (n_feature)));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700455
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400456 printf (" %d lookup(s) found in feature\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330457 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400458 printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330459 feature.get_lookup_index (n_lookup));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500460 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500461 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500462
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330463 unsigned num_lookups = g.get_lookup_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500464 printf (" %d lookup(s) found in table\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330465 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330466 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500467 const Lookup &lookup = g.get_lookup (n_lookup);
Behdad Esfahbod8c69e652010-10-27 22:07:49 -0400468 printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330469 lookup.get_type (), lookup.get_props ());
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500470 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500471
472 }
473 break;
474
Behdad Esfahbod6c48f202013-09-09 15:43:10 -0400475 case GDEF::tableTag:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500476 {
477
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600478 const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500479
480 printf (" Has %sglyph classes\n",
481 gdef.has_glyph_classes () ? "" : "no ");
482 printf (" Has %smark attachment types\n",
483 gdef.has_mark_attachment_types () ? "" : "no ");
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400484 printf (" Has %sattach points\n",
485 gdef.has_attach_points () ? "" : "no ");
486 printf (" Has %slig carets\n",
487 gdef.has_lig_carets () ? "" : "no ");
Behdad Esfahbod67cb8112009-08-09 13:05:08 -0400488 printf (" Has %smark sets\n",
489 gdef.has_mark_sets () ? "" : "no ");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500490 break;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400491 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500492 }
493 }
494 }
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330495}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330496/* end of private API use */
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430497#endif
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500498
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330499int
500main (int argc, char **argv)
501{
502 if (argc != 2)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330503 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330504 fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
505 exit (1);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330506 }
507
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330508 hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
509 printf ("Opened font file %s: %d bytes long\n", argv[1], hb_blob_get_length (blob));
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430510#ifndef MAIN_CC_NO_PRIVATE_API
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330511 print_layout_info_using_private_api (blob);
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430512#endif
Ebrahim Byagowi750bb732020-04-21 01:13:13 +0430513#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW) && defined(HB_EXPERIMENTAL_API)
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330514 dump_glyphs (blob, argv[1]);
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330515#endif
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330516 hb_blob_destroy (blob);
517
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500518 return 0;
519}