blob: dae32a360756ff958ec11e72d9678f6f3656504d [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 Byagowi2d147352020-01-24 19:41:26 +033029#include "hb.h"
30#include "hb-ot.h"
Behdad Esfahbod12c45682006-12-28 06:10:59 -050031
32#include <stdlib.h>
33#include <stdio.h>
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033034#include <string.h>
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040035
Ebrahim Byagowibb4cdf82019-06-25 01:42:42 +043036#ifdef HB_NO_OPEN
37#define hb_blob_create_from_file(x) hb_blob_get_empty ()
38#endif
39
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033040static void
41svg_dump (hb_face_t *face, unsigned face_index)
42{
43 unsigned glyph_count = hb_face_get_glyph_count (face);
44
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033045 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033046 {
47 hb_blob_t *blob = hb_ot_color_glyph_reference_svg (face, glyph_id);
48
49 if (hb_blob_get_length (blob) == 0) continue;
50
51 unsigned length;
52 const char *data = hb_blob_get_data (blob, &length);
53
54 char output_path[255];
55 sprintf (output_path, "out/svg-%u-%u.svg%s",
56 glyph_id,
57 face_index,
58 // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
59 (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
60
61 FILE *f = fopen (output_path, "wb");
62 fwrite (data, 1, length, f);
63 fclose (f);
64
65 hb_blob_destroy (blob);
66 }
67}
68
69/* _png API is so easy to use unlike the below code, don't get confused */
70static void
71png_dump (hb_face_t *face, unsigned face_index)
72{
73 unsigned glyph_count = hb_face_get_glyph_count (face);
74 hb_font_t *font = hb_font_create (face);
75
76 /* scans the font for strikes */
77 unsigned sample_glyph_id;
78 /* we don't care about different strikes for different glyphs at this point */
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033079 for (sample_glyph_id = 0; sample_glyph_id < glyph_count; ++sample_glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033080 {
81 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
82 unsigned blob_length = hb_blob_get_length (blob);
83 hb_blob_destroy (blob);
84 if (blob_length != 0)
85 break;
86 }
87
88 unsigned upem = hb_face_get_upem (face);
89 unsigned blob_length = 0;
90 unsigned strike = 0;
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033091 for (unsigned ppem = 1; ppem < upem; ++ppem)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033092 {
93 hb_font_set_ppem (font, ppem, ppem);
94 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
95 unsigned new_blob_length = hb_blob_get_length (blob);
96 hb_blob_destroy (blob);
97 if (new_blob_length != blob_length)
98 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033099 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330100 {
101 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, glyph_id);
102
103 if (hb_blob_get_length (blob) == 0) continue;
104
105 unsigned length;
106 const char *data = hb_blob_get_data (blob, &length);
107
108 char output_path[255];
109 sprintf (output_path, "out/png-%u-%u-%u.png", glyph_id, strike, face_index);
110
111 FILE *f = fopen (output_path, "wb");
112 fwrite (data, 1, length, f);
113 fclose (f);
114
115 hb_blob_destroy (blob);
116 }
117
118 strike++;
119 blob_length = new_blob_length;
120 }
121 }
122
123 hb_font_destroy (font);
124}
125
126struct user_data_t
127{
128 FILE *f;
129 hb_position_t ascender;
130};
131
132static void
133move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
134{
135 fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
136}
137
138static void
139line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
140{
141 fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
142}
143
144static void
145conic_to (hb_position_t control_x, hb_position_t control_y,
146 hb_position_t to_x, hb_position_t to_y,
147 user_data_t &user_data)
148{
149 fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
150 to_x, user_data.ascender - to_y);
151}
152
153static void
154cubic_to (hb_position_t control1_x, hb_position_t control1_y,
155 hb_position_t control2_x, hb_position_t control2_y,
156 hb_position_t to_x, hb_position_t to_y,
157 user_data_t &user_data)
158{
159 fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
160 control2_x, user_data.ascender - control2_y,
161 to_x, user_data.ascender - to_y);
162}
163
164static void
165close_path (user_data_t &user_data)
166{
167 fprintf (user_data.f, "Z");
168}
169
170static void
171layered_glyph_dump (hb_font_t *font, hb_ot_glyph_decompose_funcs_t *funcs, unsigned face_index)
172{
173 hb_face_t *face = hb_font_get_face (font);
174 unsigned num_glyphs = hb_face_get_glyph_count (face);
175 for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
176 {
177 unsigned num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
178 if (!num_layers) continue;
179
180 hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
181
182 hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
183 if (num_layers)
184 {
185 hb_font_extents_t font_extents;
186 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
187 hb_glyph_extents_t extents = {0};
188 if (!hb_font_get_glyph_extents (font, gid, &extents))
189 {
190 printf ("Skip gid: %d\n", gid);
191 continue;
192 }
193
194 unsigned palette_count = hb_ot_color_palette_get_count (face);
195 for (unsigned palette = 0; palette < palette_count; ++palette)
196 {
197 unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
198 if (!num_colors)
199 continue;
200
201 char output_path[255];
202 sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
203 FILE *f = fopen (output_path, "wb");
204 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
205 " viewBox=\"%d %d %d %d\">\n",
206 extents.x_bearing, 0,
207 extents.x_bearing + extents.width, -extents.height);
208 user_data_t user_data;
209 user_data.ascender = extents.y_bearing;
210 user_data.f = f;
211
212 hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
213 hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
214 if (num_colors)
215 {
216 for (unsigned layer = 0; layer < num_layers; ++layer)
217 {
218 hb_color_t color = 0x000000FF;
219 if (layers[layer].color_index != 0xFFFF)
220 color = colors[layers[layer].color_index];
221 fprintf (f, "<path fill=\"#%02X%02X%02X\" ",
222 hb_color_get_red (color), hb_color_get_green (color), hb_color_get_green (color));
223 if (hb_color_get_alpha (color) != 255)
224 fprintf (f, "fill-opacity=\"%.3f\"", (double) hb_color_get_alpha (color) / 255.);
225 fprintf (f, "d=\"");
226 if (!hb_ot_glyph_decompose (font, layers[layer].glyph, funcs, &user_data))
227 printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
228 fprintf (f, "\"/>\n");
229 }
230 }
231 free (colors);
232
233 fprintf (f, "</svg>");
234 fclose (f);
235 }
236 }
237
238
239 free (layers);
240 }
241}
242
243static void
244dump_glyphs (hb_font_t *font, hb_ot_glyph_decompose_funcs_t *funcs, unsigned face_index)
245{
246 unsigned num_glyphs = hb_face_get_glyph_count (hb_font_get_face (font));
247 for (unsigned gid = 0; gid < num_glyphs; ++gid)
248 {
249 hb_font_extents_t font_extents;
250 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
251 hb_glyph_extents_t extents = {0};
252 if (!hb_font_get_glyph_extents (font, gid, &extents))
253 {
254 printf ("Skip gid: %d\n", gid);
255 continue;
256 }
257
258 char output_path[255];
259 sprintf (output_path, "out/%u-%u.svg", face_index, gid);
260 FILE *f = fopen (output_path, "wb");
261 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
262 " viewBox=\"%d %d %d %d\"><path d=\"",
263 extents.x_bearing, 0,
264 extents.x_bearing + extents.width, font_extents.ascender - font_extents.descender);
265 user_data_t user_data;
266 user_data.ascender = font_extents.ascender;
267 user_data.f = f;
268 if (!hb_ot_glyph_decompose (font, gid, funcs, &user_data))
269 printf ("Failed to decompose gid: %d\n", gid);
270 fprintf (f, "\"/></svg>");
271 fclose (f);
272 }
273}
274
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330275static void
276dump_glyphs (hb_blob_t *blob, const char *font_name)
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500277{
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330278 FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
279 if (font_name_file != nullptr)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330280 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330281 fprintf (stderr, "Purge or move ./out folder in order to run a new glyph dump,\n"
282 "run it like `rm -rf out && mkdir out && src/main font-file.ttf`\n");
283 return;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500284 }
285
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330286 font_name_file = fopen ("out/.dumped_font_name", "w");
287 if (font_name_file == nullptr)
288 {
289 fprintf (stderr, "./out is not accessible as a folder, create it please\n");
290 return;
291 }
292 fwrite (font_name, 1, strlen (font_name), font_name_file);
293 fclose (font_name_file);
Behdad Esfahbodce48f032009-11-02 14:35:51 -0500294
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330295 hb_ot_glyph_decompose_funcs_t *funcs = hb_ot_glyph_decompose_funcs_create ();
296 hb_ot_glyph_decompose_funcs_set_move_to_func (funcs, (hb_ot_glyph_decompose_move_to_func_t) move_to);
297 hb_ot_glyph_decompose_funcs_set_line_to_func (funcs, (hb_ot_glyph_decompose_line_to_func_t) line_to);
298 hb_ot_glyph_decompose_funcs_set_conic_to_func (funcs, (hb_ot_glyph_decompose_conic_to_func_t) conic_to);
299 hb_ot_glyph_decompose_funcs_set_cubic_to_func (funcs, (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to);
300 hb_ot_glyph_decompose_funcs_set_close_path_func (funcs, (hb_ot_glyph_decompose_close_path_func_t) close_path);
301
302 unsigned num_faces = hb_face_count (blob);
303 for (unsigned face_index = 0; face_index < num_faces; ++face_index)
304 {
305 hb_face_t *face = hb_face_create (blob, face_index);
306 hb_font_t *font = hb_font_create (face);
307
308 if (hb_ot_color_has_png (face))
309 printf ("Dumping png (CBDT/sbix)...\n");
310 png_dump (face, face_index);
311
312 if (hb_ot_color_has_svg (face))
313 printf ("Dumping svg (SVG )...\n");
314 svg_dump (face, face_index);
315
316 if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
317 printf ("Dumping layered color glyphs (COLR/CPAL)...\n");
318 layered_glyph_dump (font, funcs, face_index);
319
320 dump_glyphs (font, funcs, face_index);
321
322 hb_font_destroy (font);
323 hb_face_destroy (face);
324 }
325
326 hb_ot_glyph_decompose_funcs_destroy (funcs);
327}
328
329/* Only this part of this mini app uses private API */
330#include "hb-static.cc"
331#include "hb-open-file.hh"
332#include "hb-ot-layout-gdef-table.hh"
333#include "hb-ot-layout-gsubgpos.hh"
334
335using namespace OT;
336
337static void
338print_layout_info_using_private_api (hb_blob_t *blob)
339{
340 const char *font_data = hb_blob_get_data (blob, nullptr);
341 hb_blob_t *font_blob = hb_sanitize_context_t ().sanitize_blob<OpenTypeFontFile> (blob);
Behdad Esfahbodeba1c162018-05-08 02:47:42 -0700342 const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
Behdad Esfahbodb912fbe2018-08-06 06:30:12 -0700343 if (!font_blob->data)
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430344 {
345 printf ("Sanitization of the file wasn't successful. Exit");
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330346 exit (1);
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430347 }
348 const OpenTypeFontFile& ot = *sanitized;
349
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330350 switch (ot.get_tag ())
351 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500352 case OpenTypeFontFile::TrueTypeTag:
353 printf ("OpenType font with TrueType outlines\n");
354 break;
355 case OpenTypeFontFile::CFFTag:
356 printf ("OpenType font with CFF (Type1) outlines\n");
357 break;
358 case OpenTypeFontFile::TTCTag:
359 printf ("TrueType Collection of OpenType fonts\n");
360 break;
Behdad Esfahbodce5694c2010-05-04 14:10:18 -0400361 case OpenTypeFontFile::TrueTag:
362 printf ("Obsolete Apple TrueType font\n");
363 break;
364 case OpenTypeFontFile::Typ1Tag:
365 printf ("Obsolete Apple Type1 font in SFNT container\n");
366 break;
Ebrahim Byagowi225b92b2018-07-01 14:32:00 +0430367 case OpenTypeFontFile::DFontTag:
368 printf ("DFont Mac Resource Fork\n");
369 break;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500370 default:
371 printf ("Unknown font format\n");
372 break;
373 }
374
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330375 unsigned num_faces = hb_face_count (blob);
376 printf ("%d font(s) found in file\n", num_faces);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330377 for (unsigned n_font = 0; n_font < num_faces; ++n_font)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330378 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500379 const OpenTypeFontFace &font = ot.get_face (n_font);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330380 printf ("Font %d of %d:\n", n_font, num_faces);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500381
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330382 unsigned num_tables = font.get_table_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500383 printf (" %d table(s) found in font\n", num_tables);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330384 for (unsigned n_table = 0; n_table < num_tables; ++n_table)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330385 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500386 const OpenTypeTable &table = font.get_table (n_table);
Behdad Esfahbod15164d92009-08-04 13:57:41 -0400387 printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430388 (const char *) table.tag,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330389 (unsigned) table.offset,
390 (unsigned) table.length);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500391
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330392 switch (table.tag)
393 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500394
Behdad Esfahboda130ee62017-11-14 20:30:03 -0800395 case HB_OT_TAG_GSUB:
396 case HB_OT_TAG_GPOS:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500397 {
398
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600399 const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500400
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330401 unsigned num_scripts = g.get_script_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500402 printf (" %d script(s) found in table\n", num_scripts);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330403 for (unsigned n_script = 0; n_script < num_scripts; ++n_script)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330404 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500405 const Script &script = g.get_script (n_script);
406 printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330407 (const char *) g.get_script_tag (n_script));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500408
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330409 if (!script.has_default_lang_sys ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500410 printf (" No default language system\n");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500411 int num_langsys = script.get_lang_sys_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500412 printf (" %d language system(s) found in script\n", num_langsys);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330413 for (int n_langsys = script.has_default_lang_sys () ? -1 : 0; n_langsys < num_langsys; ++n_langsys)
414 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500415 const LangSys &langsys = n_langsys == -1
416 ? script.get_default_lang_sys ()
417 : script.get_lang_sys (n_langsys);
Behdad Esfahbod1a2a4a02012-05-05 22:38:20 +0200418 if (n_langsys == -1)
419 printf (" Default Language System\n");
420 else
421 printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330422 (const char *) script.get_lang_sys_tag (n_langsys));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700423 if (!langsys.has_required_feature ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500424 printf (" No required feature\n");
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700425 else
426 printf (" Required feature index: %d\n",
427 langsys.get_required_feature_index ());
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500428
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330429 unsigned num_features = langsys.get_feature_count ();
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500430 printf (" %d feature(s) found in language system\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330431 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330432 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500433 printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330434 langsys.get_feature_index (n_feature));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500435 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500436 }
437 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500438
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330439 unsigned num_features = g.get_feature_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500440 printf (" %d feature(s) found in table\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330441 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330442 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500443 const Feature &feature = g.get_feature (n_feature);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330444 unsigned num_lookups = feature.get_lookup_count ();
Jonathan Kewda132932014-04-27 14:05:24 +0100445 printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330446 HB_UNTAG (g.get_feature_tag (n_feature)));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700447
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400448 printf (" %d lookup(s) found in feature\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330449 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400450 printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330451 feature.get_lookup_index (n_lookup));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500452 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500453 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500454
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330455 unsigned num_lookups = g.get_lookup_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500456 printf (" %d lookup(s) found in table\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330457 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330458 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500459 const Lookup &lookup = g.get_lookup (n_lookup);
Behdad Esfahbod8c69e652010-10-27 22:07:49 -0400460 printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330461 lookup.get_type (), lookup.get_props ());
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500462 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500463
464 }
465 break;
466
Behdad Esfahbod6c48f202013-09-09 15:43:10 -0400467 case GDEF::tableTag:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500468 {
469
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600470 const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500471
472 printf (" Has %sglyph classes\n",
473 gdef.has_glyph_classes () ? "" : "no ");
474 printf (" Has %smark attachment types\n",
475 gdef.has_mark_attachment_types () ? "" : "no ");
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400476 printf (" Has %sattach points\n",
477 gdef.has_attach_points () ? "" : "no ");
478 printf (" Has %slig carets\n",
479 gdef.has_lig_carets () ? "" : "no ");
Behdad Esfahbod67cb8112009-08-09 13:05:08 -0400480 printf (" Has %smark sets\n",
481 gdef.has_mark_sets () ? "" : "no ");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500482 break;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400483 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500484 }
485 }
486 }
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330487}
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500488
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330489int
490main (int argc, char **argv)
491{
492 if (argc != 2)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330493 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330494 fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
495 exit (1);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330496 }
497
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330498 hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
499 printf ("Opened font file %s: %d bytes long\n", argv[1], hb_blob_get_length (blob));
500 print_layout_info_using_private_api (blob);
501 dump_glyphs (blob, argv[1]);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330502 hb_blob_destroy (blob);
503
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500504 return 0;
505}