blob: 1ab013cd3a87aa4f2934df265f12e327af78bd70 [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
Behdad Esfahbodbdfed8f2021-06-14 15:46:04 -060036#include <cassert>
37#include <cstdlib>
38#include <cstdio>
39#include <cstring>
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040040
Ebrahim Byagowibb4cdf82019-06-25 01:42:42 +043041#ifdef HB_NO_OPEN
Behdad Esfahbodbdfed8f2021-06-14 15:46:04 -060042#define hb_blob_create_from_file_or_fail(x) hb_blob_get_empty ()
Ebrahim Byagowibb4cdf82019-06-25 01:42:42 +043043#endif
44
Ebrahim Byagowi750bb732020-04-21 01:13:13 +043045#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW) && defined(HB_EXPERIMENTAL_API)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033046static void
47svg_dump (hb_face_t *face, unsigned face_index)
48{
49 unsigned glyph_count = hb_face_get_glyph_count (face);
50
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033051 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033052 {
53 hb_blob_t *blob = hb_ot_color_glyph_reference_svg (face, glyph_id);
54
55 if (hb_blob_get_length (blob) == 0) continue;
56
57 unsigned length;
58 const char *data = hb_blob_get_data (blob, &length);
59
60 char output_path[255];
61 sprintf (output_path, "out/svg-%u-%u.svg%s",
62 glyph_id,
63 face_index,
64 // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
65 (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
66
67 FILE *f = fopen (output_path, "wb");
68 fwrite (data, 1, length, f);
69 fclose (f);
70
71 hb_blob_destroy (blob);
72 }
73}
74
75/* _png API is so easy to use unlike the below code, don't get confused */
76static void
77png_dump (hb_face_t *face, unsigned face_index)
78{
79 unsigned glyph_count = hb_face_get_glyph_count (face);
80 hb_font_t *font = hb_font_create (face);
81
82 /* scans the font for strikes */
83 unsigned sample_glyph_id;
84 /* we don't care about different strikes for different glyphs at this point */
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033085 for (sample_glyph_id = 0; sample_glyph_id < glyph_count; ++sample_glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033086 {
87 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
88 unsigned blob_length = hb_blob_get_length (blob);
89 hb_blob_destroy (blob);
90 if (blob_length != 0)
91 break;
92 }
93
94 unsigned upem = hb_face_get_upem (face);
95 unsigned blob_length = 0;
96 unsigned strike = 0;
Ebrahim Byagowi2d147352020-01-24 19:41:26 +033097 for (unsigned ppem = 1; ppem < upem; ++ppem)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033098 {
99 hb_font_set_ppem (font, ppem, ppem);
100 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
101 unsigned new_blob_length = hb_blob_get_length (blob);
102 hb_blob_destroy (blob);
103 if (new_blob_length != blob_length)
104 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330105 for (unsigned glyph_id = 0; glyph_id < glyph_count; ++glyph_id)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330106 {
107 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, glyph_id);
108
109 if (hb_blob_get_length (blob) == 0) continue;
110
111 unsigned length;
112 const char *data = hb_blob_get_data (blob, &length);
113
114 char output_path[255];
115 sprintf (output_path, "out/png-%u-%u-%u.png", glyph_id, strike, face_index);
116
117 FILE *f = fopen (output_path, "wb");
118 fwrite (data, 1, length, f);
119 fclose (f);
120
121 hb_blob_destroy (blob);
122 }
123
124 strike++;
125 blob_length = new_blob_length;
126 }
127 }
128
129 hb_font_destroy (font);
130}
131
132struct user_data_t
133{
134 FILE *f;
135 hb_position_t ascender;
136};
137
138static void
139move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
140{
141 fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
142}
143
144static void
145line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
146{
147 fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
148}
149
150static void
Ebrahim Byagowi74fdcdc2020-01-28 13:45:22 +0330151quadratic_to (hb_position_t control_x, hb_position_t control_y,
152 hb_position_t to_x, hb_position_t to_y,
153 user_data_t &user_data)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330154{
155 fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
156 to_x, user_data.ascender - to_y);
157}
158
159static void
160cubic_to (hb_position_t control1_x, hb_position_t control1_y,
161 hb_position_t control2_x, hb_position_t control2_y,
162 hb_position_t to_x, hb_position_t to_y,
163 user_data_t &user_data)
164{
165 fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
166 control2_x, user_data.ascender - control2_y,
167 to_x, user_data.ascender - to_y);
168}
169
170static void
171close_path (user_data_t &user_data)
172{
173 fprintf (user_data.f, "Z");
174}
175
176static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330177layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330178{
179 hb_face_t *face = hb_font_get_face (font);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330180 unsigned palette_count = hb_ot_color_palette_get_count (face);
181 for (unsigned palette = 0; palette < palette_count; ++palette)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330182 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330183 unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
184 if (!num_colors) continue;
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330185
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330186 hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
187 hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
188 if (!num_colors)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330189 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330190 free (colors);
191 continue;
192 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330193
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330194 unsigned num_glyphs = hb_face_get_glyph_count (face);
195 for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
196 {
197 unsigned num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
198 if (!num_layers) continue;
199
200 hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
201
202 hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
203 if (num_layers)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330204 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330205 hb_font_extents_t font_extents;
206 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
207 hb_glyph_extents_t extents = {0};
208 if (!hb_font_get_glyph_extents (font, gid, &extents))
209 {
210 printf ("Skip gid: %d\n", gid);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330211 continue;
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330212 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330213
214 char output_path[255];
215 sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330216 FILE *f = fopen (output_path, "wb");
217 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330218 " viewBox=\"%d %d %d %d\">\n",
219 extents.x_bearing, 0,
220 extents.x_bearing + extents.width, -extents.height);
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330221 user_data_t user_data;
222 user_data.ascender = extents.y_bearing;
223 user_data.f = f;
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330224
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330225 for (unsigned layer = 0; layer < num_layers; ++layer)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330226 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330227 hb_color_t color = 0x000000FF;
228 if (layers[layer].color_index != 0xFFFF)
229 color = colors[layers[layer].color_index];
230 fprintf (f, "<path fill=\"#%02X%02X%02X\" ",
231 hb_color_get_red (color), hb_color_get_green (color), hb_color_get_green (color));
232 if (hb_color_get_alpha (color) != 255)
233 fprintf (f, "fill-opacity=\"%.3f\"", (double) hb_color_get_alpha (color) / 255.);
234 fprintf (f, "d=\"");
235 if (!hb_font_draw_glyph (font, layers[layer].glyph, funcs, &user_data))
236 printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
237 fprintf (f, "\"/>\n");
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330238 }
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330239
240 fprintf (f, "</svg>");
241 fclose (f);
242 }
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330243 free (layers);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330244 }
245
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330246 free (colors);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330247 }
248}
249
250static void
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330251dump_glyphs (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330252{
253 unsigned num_glyphs = hb_face_get_glyph_count (hb_font_get_face (font));
254 for (unsigned gid = 0; gid < num_glyphs; ++gid)
255 {
256 hb_font_extents_t font_extents;
257 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
258 hb_glyph_extents_t extents = {0};
259 if (!hb_font_get_glyph_extents (font, gid, &extents))
260 {
261 printf ("Skip gid: %d\n", gid);
262 continue;
263 }
264
265 char output_path[255];
266 sprintf (output_path, "out/%u-%u.svg", face_index, gid);
267 FILE *f = fopen (output_path, "wb");
268 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
269 " viewBox=\"%d %d %d %d\"><path d=\"",
270 extents.x_bearing, 0,
271 extents.x_bearing + extents.width, font_extents.ascender - font_extents.descender);
272 user_data_t user_data;
273 user_data.ascender = font_extents.ascender;
274 user_data.f = f;
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330275 if (!hb_font_draw_glyph (font, gid, funcs, &user_data))
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330276 printf ("Failed to decompose gid: %d\n", gid);
277 fprintf (f, "\"/></svg>");
278 fclose (f);
279 }
280}
281
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330282static void
283dump_glyphs (hb_blob_t *blob, const char *font_name)
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500284{
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330285 FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
Ebrahim Byagowi2be859d2020-04-20 23:48:23 +0430286 if (font_name_file)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330287 {
Ebrahim Byagowi5c1a0232020-02-08 10:57:07 +0330288 fprintf (stderr, "Purge or rename ./out folder if you like to run a glyph dump,\n"
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330289 "run it like `rm -rf out && mkdir out && src/main font-file.ttf`\n");
290 return;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500291 }
292
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330293 font_name_file = fopen ("out/.dumped_font_name", "w");
Ebrahim Byagowi2be859d2020-04-20 23:48:23 +0430294 if (!font_name_file)
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330295 {
296 fprintf (stderr, "./out is not accessible as a folder, create it please\n");
297 return;
298 }
299 fwrite (font_name, 1, strlen (font_name), font_name_file);
300 fclose (font_name_file);
Behdad Esfahbodce48f032009-11-02 14:35:51 -0500301
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330302 hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
303 hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) move_to);
304 hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) line_to);
Ebrahim Byagowi74fdcdc2020-01-28 13:45:22 +0330305 hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) quadratic_to);
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330306 hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) cubic_to);
307 hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) close_path);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330308
309 unsigned num_faces = hb_face_count (blob);
310 for (unsigned face_index = 0; face_index < num_faces; ++face_index)
311 {
312 hb_face_t *face = hb_face_create (blob, face_index);
313 hb_font_t *font = hb_font_create (face);
314
315 if (hb_ot_color_has_png (face))
316 printf ("Dumping png (CBDT/sbix)...\n");
317 png_dump (face, face_index);
318
319 if (hb_ot_color_has_svg (face))
320 printf ("Dumping svg (SVG )...\n");
321 svg_dump (face, face_index);
322
323 if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
324 printf ("Dumping layered color glyphs (COLR/CPAL)...\n");
325 layered_glyph_dump (font, funcs, face_index);
326
327 dump_glyphs (font, funcs, face_index);
328
329 hb_font_destroy (font);
330 hb_face_destroy (face);
331 }
332
Ebrahim Byagowiac81e942020-01-28 12:34:47 +0330333 hb_draw_funcs_destroy (funcs);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330334}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330335#endif
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330336
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430337#ifndef MAIN_CC_NO_PRIVATE_API
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330338/* Only this part of this mini app uses private API */
339#include "hb-static.cc"
340#include "hb-open-file.hh"
341#include "hb-ot-layout-gdef-table.hh"
342#include "hb-ot-layout-gsubgpos.hh"
343
344using namespace OT;
345
346static void
347print_layout_info_using_private_api (hb_blob_t *blob)
348{
349 const char *font_data = hb_blob_get_data (blob, nullptr);
350 hb_blob_t *font_blob = hb_sanitize_context_t ().sanitize_blob<OpenTypeFontFile> (blob);
Behdad Esfahbodeba1c162018-05-08 02:47:42 -0700351 const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
Behdad Esfahbodb912fbe2018-08-06 06:30:12 -0700352 if (!font_blob->data)
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430353 {
354 printf ("Sanitization of the file wasn't successful. Exit");
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330355 exit (1);
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430356 }
357 const OpenTypeFontFile& ot = *sanitized;
358
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330359 switch (ot.get_tag ())
360 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500361 case OpenTypeFontFile::TrueTypeTag:
362 printf ("OpenType font with TrueType outlines\n");
363 break;
364 case OpenTypeFontFile::CFFTag:
365 printf ("OpenType font with CFF (Type1) outlines\n");
366 break;
367 case OpenTypeFontFile::TTCTag:
368 printf ("TrueType Collection of OpenType fonts\n");
369 break;
Behdad Esfahbodce5694c2010-05-04 14:10:18 -0400370 case OpenTypeFontFile::TrueTag:
371 printf ("Obsolete Apple TrueType font\n");
372 break;
373 case OpenTypeFontFile::Typ1Tag:
374 printf ("Obsolete Apple Type1 font in SFNT container\n");
375 break;
Ebrahim Byagowi225b92b2018-07-01 14:32:00 +0430376 case OpenTypeFontFile::DFontTag:
377 printf ("DFont Mac Resource Fork\n");
378 break;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500379 default:
380 printf ("Unknown font format\n");
381 break;
382 }
383
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330384 unsigned num_faces = hb_face_count (blob);
385 printf ("%d font(s) found in file\n", num_faces);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330386 for (unsigned n_font = 0; n_font < num_faces; ++n_font)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330387 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500388 const OpenTypeFontFace &font = ot.get_face (n_font);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330389 printf ("Font %d of %d:\n", n_font, num_faces);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500390
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330391 unsigned num_tables = font.get_table_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500392 printf (" %d table(s) found in font\n", num_tables);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330393 for (unsigned n_table = 0; n_table < num_tables; ++n_table)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330394 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500395 const OpenTypeTable &table = font.get_table (n_table);
Behdad Esfahbod15164d92009-08-04 13:57:41 -0400396 printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430397 (const char *) table.tag,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330398 (unsigned) table.offset,
399 (unsigned) table.length);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500400
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330401 switch (table.tag)
402 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500403
Behdad Esfahboda130ee62017-11-14 20:30:03 -0800404 case HB_OT_TAG_GSUB:
405 case HB_OT_TAG_GPOS:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500406 {
407
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600408 const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500409
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330410 unsigned num_scripts = g.get_script_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500411 printf (" %d script(s) found in table\n", num_scripts);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330412 for (unsigned n_script = 0; n_script < num_scripts; ++n_script)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330413 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500414 const Script &script = g.get_script (n_script);
415 printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330416 (const char *) g.get_script_tag (n_script));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500417
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330418 if (!script.has_default_lang_sys ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500419 printf (" No default language system\n");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500420 int num_langsys = script.get_lang_sys_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500421 printf (" %d language system(s) found in script\n", num_langsys);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330422 for (int n_langsys = script.has_default_lang_sys () ? -1 : 0; n_langsys < num_langsys; ++n_langsys)
423 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500424 const LangSys &langsys = n_langsys == -1
425 ? script.get_default_lang_sys ()
426 : script.get_lang_sys (n_langsys);
Behdad Esfahbod1a2a4a02012-05-05 22:38:20 +0200427 if (n_langsys == -1)
428 printf (" Default Language System\n");
429 else
430 printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330431 (const char *) script.get_lang_sys_tag (n_langsys));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700432 if (!langsys.has_required_feature ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500433 printf (" No required feature\n");
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700434 else
435 printf (" Required feature index: %d\n",
436 langsys.get_required_feature_index ());
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500437
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330438 unsigned num_features = langsys.get_feature_count ();
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500439 printf (" %d feature(s) found in language system\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330440 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330441 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500442 printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330443 langsys.get_feature_index (n_feature));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500444 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500445 }
446 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500447
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330448 unsigned num_features = g.get_feature_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500449 printf (" %d feature(s) found in table\n", num_features);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330450 for (unsigned n_feature = 0; n_feature < num_features; ++n_feature)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330451 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500452 const Feature &feature = g.get_feature (n_feature);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330453 unsigned num_lookups = feature.get_lookup_count ();
Jonathan Kewda132932014-04-27 14:05:24 +0100454 printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330455 HB_UNTAG (g.get_feature_tag (n_feature)));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700456
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400457 printf (" %d lookup(s) found in feature\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330458 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400459 printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330460 feature.get_lookup_index (n_lookup));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500461 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500462 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500463
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330464 unsigned num_lookups = g.get_lookup_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500465 printf (" %d lookup(s) found in table\n", num_lookups);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330466 for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330467 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500468 const Lookup &lookup = g.get_lookup (n_lookup);
Behdad Esfahbod8c69e652010-10-27 22:07:49 -0400469 printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330470 lookup.get_type (), lookup.get_props ());
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500471 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500472
473 }
474 break;
475
Behdad Esfahbod6c48f202013-09-09 15:43:10 -0400476 case GDEF::tableTag:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500477 {
478
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600479 const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500480
481 printf (" Has %sglyph classes\n",
482 gdef.has_glyph_classes () ? "" : "no ");
483 printf (" Has %smark attachment types\n",
484 gdef.has_mark_attachment_types () ? "" : "no ");
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400485 printf (" Has %sattach points\n",
486 gdef.has_attach_points () ? "" : "no ");
487 printf (" Has %slig carets\n",
488 gdef.has_lig_carets () ? "" : "no ");
Behdad Esfahbod67cb8112009-08-09 13:05:08 -0400489 printf (" Has %smark sets\n",
490 gdef.has_mark_sets () ? "" : "no ");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500491 break;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400492 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500493 }
494 }
495 }
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330496}
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330497/* end of private API use */
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430498#endif
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500499
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330500int
501main (int argc, char **argv)
502{
503 if (argc != 2)
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330504 {
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330505 fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
506 exit (1);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330507 }
508
Behdad Esfahbodbdfed8f2021-06-14 15:46:04 -0600509 hb_blob_t *blob = hb_blob_create_from_file_or_fail (argv[1]);
510 assert (blob);
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330511 printf ("Opened font file %s: %d bytes long\n", argv[1], hb_blob_get_length (blob));
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430512#ifndef MAIN_CC_NO_PRIVATE_API
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330513 print_layout_info_using_private_api (blob);
Ebrahim Byagowi19346522020-04-23 14:22:33 +0430514#endif
Ebrahim Byagowi750bb732020-04-21 01:13:13 +0430515#if !defined(HB_NO_COLOR) && !defined(HB_NO_DRAW) && defined(HB_EXPERIMENTAL_API)
Ebrahim Byagowi2d147352020-01-24 19:41:26 +0330516 dump_glyphs (blob, argv[1]);
Ebrahim Byagowib7762c72020-01-24 21:20:07 +0330517#endif
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330518 hb_blob_destroy (blob);
519
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500520 return 0;
521}