blob: 1310a7c2e1c2a943a061ccc861c6333d868b8f3a [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 Byagowiac81e942020-01-28 12:34:47 +033040#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033041static void
42svg_dump (hb_face_t *face, unsigned face_index)
43{
44 unsigned glyph_count = hb_face_get_glyph_count (face);
45
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033046 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033047 {
48 hb_blob_t *blob = hb_ot_color_glyph_reference_svg (face, glyph_id);
49
50 if (hb_blob_get_length (blob) == 0) continue;
51
52 unsigned length;
53 const char *data = hb_blob_get_data (blob, &length);
54
55 char output_path[255];
56 sprintf (output_path, "out/svg-%u-%u.svg%s",
57 glyph_id,
58 face_index,
59 // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
60 (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
61
62 FILE *f = fopen (output_path, "wb");
63 fwrite (data, 1, length, f);
64 fclose (f);
65
66 hb_blob_destroy (blob);
67 }
68}
69
70/* _png API is so easy to use unlike the below code, don't get confused */
71static void
72png_dump (hb_face_t *face, unsigned face_index)
73{
74 unsigned glyph_count = hb_face_get_glyph_count (face);
75 hb_font_t *font = hb_font_create (face);
76
77 /* scans the font for strikes */
78 unsigned sample_glyph_id;
79 /* we don't care about different strikes for different glyphs at this point */
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033080 for (sample_glyph_id = 0; sample_glyph_id < glyph_count; ++sample_glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033081 {
82 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
83 unsigned blob_length = hb_blob_get_length (blob);
84 hb_blob_destroy (blob);
85 if (blob_length != 0)
86 break;
87 }
88
89 unsigned upem = hb_face_get_upem (face);
90 unsigned blob_length = 0;
91 unsigned strike = 0;
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033092 for (unsigned ppem = 1; ppem < upem; ++ppem)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033093 {
94 hb_font_set_ppem (font, ppem, ppem);
95 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
96 unsigned new_blob_length = hb_blob_get_length (blob);
97 hb_blob_destroy (blob);
98 if (new_blob_length != blob_length)
99 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330100 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330101 {
102 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, glyph_id);
103
104 if (hb_blob_get_length (blob) == 0) continue;
105
106 unsigned length;
107 const char *data = hb_blob_get_data (blob, &length);
108
109 char output_path[255];
110 sprintf (output_path, "out/png-%u-%u-%u.png", glyph_id, strike, face_index);
111
112 FILE *f = fopen (output_path, "wb");
113 fwrite (data, 1, length, f);
114 fclose (f);
115
116 hb_blob_destroy (blob);
117 }
118
119 strike++;
120 blob_length = new_blob_length;
121 }
122 }
123
124 hb_font_destroy (font);
125}
126
127struct user_data_t
128{
129 FILE *f;
130 hb_position_t ascender;
131};
132
133static void
134move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
135{
136 fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
137}
138
139static void
140line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
141{
142 fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
143}
144
145static void
146conic_to (hb_position_t control_x, hb_position_t control_y,
147 hb_position_t to_x, hb_position_t to_y,
148 user_data_t &user_data)
149{
150 fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
151 to_x, user_data.ascender - to_y);
152}
153
154static void
155cubic_to (hb_position_t control1_x, hb_position_t control1_y,
156 hb_position_t control2_x, hb_position_t control2_y,
157 hb_position_t to_x, hb_position_t to_y,
158 user_data_t &user_data)
159{
160 fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
161 control2_x, user_data.ascender - control2_y,
162 to_x, user_data.ascender - to_y);
163}
164
165static void
166close_path (user_data_t &user_data)
167{
168 fprintf (user_data.f, "Z");
169}
170
171static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330172layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330173{
174 hb_face_t *face = hb_font_get_face (font);
175 unsigned num_glyphs = hb_face_get_glyph_count (face);
176 for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
177 {
178 unsigned num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
179 if (!num_layers) continue;
180
181 hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
182
183 hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
184 if (num_layers)
185 {
186 hb_font_extents_t font_extents;
187 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
188 hb_glyph_extents_t extents = {0};
189 if (!hb_font_get_glyph_extents (font, gid, &extents))
190 {
191 printf ("Skip gid: %d\n", gid);
192 continue;
193 }
194
195 unsigned palette_count = hb_ot_color_palette_get_count (face);
196 for (unsigned palette = 0; palette < palette_count; ++palette)
197 {
198 unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
199 if (!num_colors)
200 continue;
201
202 char output_path[255];
203 sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
204 FILE *f = fopen (output_path, "wb");
205 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
206 " viewBox=\"%d %d %d %d\">\n",
207 extents.x_bearing, 0,
208 extents.x_bearing + extents.width, -extents.height);
209 user_data_t user_data;
210 user_data.ascender = extents.y_bearing;
211 user_data.f = f;
212
213 hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
214 hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
215 if (num_colors)
216 {
217 for (unsigned layer = 0; layer < num_layers; ++layer)
218 {
219 hb_color_t color = 0x000000FF;
220 if (layers[layer].color_index != 0xFFFF)
221 color = colors[layers[layer].color_index];
222 fprintf (f, "<path fill=\"#%02X%02X%02X\" ",
223 hb_color_get_red (color), hb_color_get_green (color), hb_color_get_green (color));
224 if (hb_color_get_alpha (color) != 255)
225 fprintf (f, "fill-opacity=\"%.3f\"", (double) hb_color_get_alpha (color) / 255.);
226 fprintf (f, "d=\"");
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330227 if (!hb_font_draw_glyph (font, layers[layer].glyph, funcs, &user_data))
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330228 printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
229 fprintf (f, "\"/>\n");
230 }
231 }
232 free (colors);
233
234 fprintf (f, "</svg>");
235 fclose (f);
236 }
237 }
238
239
240 free (layers);
241 }
242}
243
244static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330245dump_glyphs (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330246{
247 unsigned num_glyphs = hb_face_get_glyph_count (hb_font_get_face (font));
248 for (unsigned gid = 0; gid < num_glyphs; ++gid)
249 {
250 hb_font_extents_t font_extents;
251 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
252 hb_glyph_extents_t extents = {0};
253 if (!hb_font_get_glyph_extents (font, gid, &extents))
254 {
255 printf ("Skip gid: %d\n", gid);
256 continue;
257 }
258
259 char output_path[255];
260 sprintf (output_path, "out/%u-%u.svg", face_index, gid);
261 FILE *f = fopen (output_path, "wb");
262 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
263 " viewBox=\"%d %d %d %d\"><path d=\"",
264 extents.x_bearing, 0,
265 extents.x_bearing + extents.width, font_extents.ascender - font_extents.descender);
266 user_data_t user_data;
267 user_data.ascender = font_extents.ascender;
268 user_data.f = f;
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330269 if (!hb_font_draw_glyph (font, gid, funcs, &user_data))
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330270 printf ("Failed to decompose gid: %d\n", gid);
271 fprintf (f, "\"/></svg>");
272 fclose (f);
273 }
274}
275
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330276static void
277dump_glyphs (hb_blob_t *blob, const char *font_name)
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500278{
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330279 FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
280 if (font_name_file != nullptr)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330281 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330282 fprintf (stderr, "Purge or move ./out folder in order to run a new glyph dump,\n"
283 "run it like `rm -rf out && mkdir out && src/main font-file.ttf`\n");
284 return;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500285 }
286
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330287 font_name_file = fopen ("out/.dumped_font_name", "w");
288 if (font_name_file == nullptr)
289 {
290 fprintf (stderr, "./out is not accessible as a folder, create it please\n");
291 return;
292 }
293 fwrite (font_name, 1, strlen (font_name), font_name_file);
294 fclose (font_name_file);
Behdad Esfahbodce48f032009-11-02 14:35:51 -0500295
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330296 hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
297 hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) move_to);
298 hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) line_to);
299 hb_draw_funcs_set_conic_to_func (funcs, (hb_draw_conic_to_func_t) conic_to);
300 hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) cubic_to);
301 hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) close_path);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330302
303 unsigned num_faces = hb_face_count (blob);
304 for (unsigned face_index = 0; face_index < num_faces; ++face_index)
305 {
306 hb_face_t *face = hb_face_create (blob, face_index);
307 hb_font_t *font = hb_font_create (face);
308
309 if (hb_ot_color_has_png (face))
310 printf ("Dumping png (CBDT/sbix)...\n");
311 png_dump (face, face_index);
312
313 if (hb_ot_color_has_svg (face))
314 printf ("Dumping svg (SVG )...\n");
315 svg_dump (face, face_index);
316
317 if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
318 printf ("Dumping layered color glyphs (COLR/CPAL)...\n");
319 layered_glyph_dump (font, funcs, face_index);
320
321 dump_glyphs (font, funcs, face_index);
322
323 hb_font_destroy (font);
324 hb_face_destroy (face);
325 }
326
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330327 hb_draw_funcs_destroy (funcs);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330328}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330329#endif
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330330
331/* Only this part of this mini app uses private API */
332#include "hb-static.cc"
333#include "hb-open-file.hh"
334#include "hb-ot-layout-gdef-table.hh"
335#include "hb-ot-layout-gsubgpos.hh"
336
337using namespace OT;
338
339static void
340print_layout_info_using_private_api (hb_blob_t *blob)
341{
342 const char *font_data = hb_blob_get_data (blob, nullptr);
343 hb_blob_t *font_blob = hb_sanitize_context_t ().sanitize_blob<OpenTypeFontFile> (blob);
Behdad Esfahbodeba1c162018-05-08 02:47:42 -0700344 const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
Behdad Esfahbodb912fbe2018-08-06 06:30:12 -0700345 if (!font_blob->data)
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430346 {
347 printf ("Sanitization of the file wasn't successful. Exit");
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330348 exit (1);
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430349 }
350 const OpenTypeFontFile& ot = *sanitized;
351
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330352 switch (ot.get_tag ())
353 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500354 case OpenTypeFontFile::TrueTypeTag:
355 printf ("OpenType font with TrueType outlines\n");
356 break;
357 case OpenTypeFontFile::CFFTag:
358 printf ("OpenType font with CFF (Type1) outlines\n");
359 break;
360 case OpenTypeFontFile::TTCTag:
361 printf ("TrueType Collection of OpenType fonts\n");
362 break;
Behdad Esfahbodce5694c2010-05-04 14:10:18 -0400363 case OpenTypeFontFile::TrueTag:
364 printf ("Obsolete Apple TrueType font\n");
365 break;
366 case OpenTypeFontFile::Typ1Tag:
367 printf ("Obsolete Apple Type1 font in SFNT container\n");
368 break;
Ebrahim Byagowi225b92b2018-07-01 14:32:00 +0430369 case OpenTypeFontFile::DFontTag:
370 printf ("DFont Mac Resource Fork\n");
371 break;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500372 default:
373 printf ("Unknown font format\n");
374 break;
375 }
376
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330377 unsigned num_faces = hb_face_count (blob);
378 printf ("%d font(s) found in file\n", num_faces);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330379 for (unsigned n_font = 0; n_font < num_faces; ++n_font)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330380 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500381 const OpenTypeFontFace &font = ot.get_face (n_font);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330382 printf ("Font %d of %d:\n", n_font, num_faces);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500383
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330384 unsigned num_tables = font.get_table_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500385 printf (" %d table(s) found in font\n", num_tables);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330386 for (unsigned n_table = 0; n_table < num_tables; ++n_table)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330387 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500388 const OpenTypeTable &table = font.get_table (n_table);
Behdad Esfahbod15164d92009-08-04 13:57:41 -0400389 printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430390 (const char *) table.tag,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330391 (unsigned) table.offset,
392 (unsigned) table.length);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500393
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330394 switch (table.tag)
395 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500396
Behdad Esfahboda130ee62017-11-14 20:30:03 -0800397 case HB_OT_TAG_GSUB:
398 case HB_OT_TAG_GPOS:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500399 {
400
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600401 const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500402
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330403 unsigned num_scripts = g.get_script_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500404 printf (" %d script(s) found in table\n", num_scripts);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330405 for (unsigned n_script = 0; n_script < num_scripts; ++n_script)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330406 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500407 const Script &script = g.get_script (n_script);
408 printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330409 (const char *) g.get_script_tag (n_script));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500410
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330411 if (!script.has_default_lang_sys ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500412 printf (" No default language system\n");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500413 int num_langsys = script.get_lang_sys_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500414 printf (" %d language system(s) found in script\n", num_langsys);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330415 for (int n_langsys = script.has_default_lang_sys () ? -1 : 0; n_langsys < num_langsys; ++n_langsys)
416 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500417 const LangSys &langsys = n_langsys == -1
418 ? script.get_default_lang_sys ()
419 : script.get_lang_sys (n_langsys);
Behdad Esfahbod1a2a4a02012-05-05 22:38:20 +0200420 if (n_langsys == -1)
421 printf (" Default Language System\n");
422 else
423 printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330424 (const char *) script.get_lang_sys_tag (n_langsys));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700425 if (!langsys.has_required_feature ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500426 printf (" No required feature\n");
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700427 else
428 printf (" Required feature index: %d\n",
429 langsys.get_required_feature_index ());
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500430
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330431 unsigned num_features = langsys.get_feature_count ();
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500432 printf (" %d feature(s) found in language system\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330433 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330434 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500435 printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330436 langsys.get_feature_index (n_feature));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500437 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500438 }
439 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500440
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330441 unsigned num_features = g.get_feature_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500442 printf (" %d feature(s) found in table\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330443 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330444 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500445 const Feature &feature = g.get_feature (n_feature);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330446 unsigned num_lookups = feature.get_lookup_count ();
Jonathan Kewda132932014-04-27 14:05:24 +0100447 printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330448 HB_UNTAG (g.get_feature_tag (n_feature)));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700449
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400450 printf (" %d lookup(s) found in feature\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330451 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400452 printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330453 feature.get_lookup_index (n_lookup));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500454 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500455 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500456
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330457 unsigned num_lookups = g.get_lookup_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500458 printf (" %d lookup(s) found in table\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330459 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330460 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500461 const Lookup &lookup = g.get_lookup (n_lookup);
Behdad Esfahbod8c69e652010-10-27 22:07:49 -0400462 printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330463 lookup.get_type (), lookup.get_props ());
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500464 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500465
466 }
467 break;
468
Behdad Esfahbod6c48f202013-09-09 15:43:10 -0400469 case GDEF::tableTag:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500470 {
471
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600472 const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500473
474 printf (" Has %sglyph classes\n",
475 gdef.has_glyph_classes () ? "" : "no ");
476 printf (" Has %smark attachment types\n",
477 gdef.has_mark_attachment_types () ? "" : "no ");
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400478 printf (" Has %sattach points\n",
479 gdef.has_attach_points () ? "" : "no ");
480 printf (" Has %slig carets\n",
481 gdef.has_lig_carets () ? "" : "no ");
Behdad Esfahbod67cb8112009-08-09 13:05:08 -0400482 printf (" Has %smark sets\n",
483 gdef.has_mark_sets () ? "" : "no ");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500484 break;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400485 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500486 }
487 }
488 }
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330489}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330490/* end of private API use */
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500491
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330492int
493main (int argc, char **argv)
494{
495 if (argc != 2)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330496 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330497 fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
498 exit (1);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330499 }
500
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330501 hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
502 printf ("Opened font file %s: %d bytes long\n", argv[1], hb_blob_get_length (blob));
503 print_layout_info_using_private_api (blob);
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330504#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW)
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330505 dump_glyphs (blob, argv[1]);
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330506#endif
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330507 hb_blob_destroy (blob);
508
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500509 return 0;
510}