blob: 54442295228269370d5b174f06d298120e80a524 [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
Behdad Esfahbodfd3d0042018-05-24 15:58:26 -070029#include "hb-static.cc"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070030#include "hb-open-file.hh"
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020031#include "hb-ot-layout-gdef-table.hh"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070032#include "hb-ot-layout-gsubgpos.hh"
Behdad Esfahbod12c45682006-12-28 06:10:59 -050033
Behdad Esfahbodbdd0ff52009-12-15 04:07:40 -050034#ifdef HAVE_GLIB
Behdad Esfahbodbaec6842009-08-01 21:06:11 -040035#include <glib.h>
Behdad Esfahbodbdd0ff52009-12-15 04:07:40 -050036#endif
Behdad Esfahbod12c45682006-12-28 06:10:59 -050037#include <stdlib.h>
38#include <stdio.h>
39
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040040
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040041using namespace OT;
42
Ebrahim Byagowibb4cdf82019-06-25 01:42:42 +043043#ifdef HB_NO_OPEN
44#define hb_blob_create_from_file(x) hb_blob_get_empty ()
45#endif
46
Ebrahim Byagowi23277be2020-01-24 18:49:48 +033047static void
48svg_dump (hb_face_t *face, unsigned face_index)
49{
50 unsigned glyph_count = hb_face_get_glyph_count (face);
51
52 for (unsigned glyph_id = 0; glyph_id < glyph_count; glyph_id++)
53 {
54 hb_blob_t *blob = hb_ot_color_glyph_reference_svg (face, glyph_id);
55
56 if (hb_blob_get_length (blob) == 0) continue;
57
58 unsigned length;
59 const char *data = hb_blob_get_data (blob, &length);
60
61 char output_path[255];
62 sprintf (output_path, "out/svg-%u-%u.svg%s",
63 glyph_id,
64 face_index,
65 // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
66 (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
67
68 FILE *f = fopen (output_path, "wb");
69 fwrite (data, 1, length, f);
70 fclose (f);
71
72 hb_blob_destroy (blob);
73 }
74}
75
76/* _png API is so easy to use unlike the below code, don't get confused */
77static void
78png_dump (hb_face_t *face, unsigned face_index)
79{
80 unsigned glyph_count = hb_face_get_glyph_count (face);
81 hb_font_t *font = hb_font_create (face);
82
83 /* scans the font for strikes */
84 unsigned sample_glyph_id;
85 /* we don't care about different strikes for different glyphs at this point */
86 for (sample_glyph_id = 0; sample_glyph_id < glyph_count; sample_glyph_id++)
87 {
88 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
89 unsigned blob_length = hb_blob_get_length (blob);
90 hb_blob_destroy (blob);
91 if (blob_length != 0)
92 break;
93 }
94
95 unsigned upem = hb_face_get_upem (face);
96 unsigned blob_length = 0;
97 unsigned strike = 0;
98 for (unsigned ppem = 1; ppem < upem; ppem++)
99 {
100 hb_font_set_ppem (font, ppem, ppem);
101 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, sample_glyph_id);
102 unsigned new_blob_length = hb_blob_get_length (blob);
103 hb_blob_destroy (blob);
104 if (new_blob_length != blob_length)
105 {
106 for (unsigned glyph_id = 0; glyph_id < glyph_count; glyph_id++)
107 {
108 hb_blob_t *blob = hb_ot_color_glyph_reference_png (font, glyph_id);
109
110 if (hb_blob_get_length (blob) == 0) continue;
111
112 unsigned length;
113 const char *data = hb_blob_get_data (blob, &length);
114
115 char output_path[255];
116 sprintf (output_path, "out/png-%u-%u-%u.png", glyph_id, strike, face_index);
117
118 FILE *f = fopen (output_path, "wb");
119 fwrite (data, 1, length, f);
120 fclose (f);
121
122 hb_blob_destroy (blob);
123 }
124
125 strike++;
126 blob_length = new_blob_length;
127 }
128 }
129
130 hb_font_destroy (font);
131}
132
133struct user_data_t
134{
135 FILE *f;
136 hb_position_t ascender;
137};
138
139static void
140move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
141{
142 fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
143}
144
145static void
146line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
147{
148 fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
149}
150
151static void
152conic_to (hb_position_t control_x, hb_position_t control_y,
153 hb_position_t to_x, hb_position_t to_y,
154 user_data_t &user_data)
155{
156 fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
157 to_x, user_data.ascender - to_y);
158}
159
160static void
161cubic_to (hb_position_t control1_x, hb_position_t control1_y,
162 hb_position_t control2_x, hb_position_t control2_y,
163 hb_position_t to_x, hb_position_t to_y,
164 user_data_t &user_data)
165{
166 fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
167 control2_x, user_data.ascender - control2_y,
168 to_x, user_data.ascender - to_y);
169}
170
171static void
172close_path (user_data_t &user_data)
173{
174 fprintf (user_data.f, "Z");
175}
176
177static void
178layered_glyph_dump (hb_font_t *font, hb_ot_glyph_decompose_funcs_t *funcs, unsigned face_index)
179{
180 hb_face_t *face = hb_font_get_face (font);
181 unsigned num_glyphs = hb_face_get_glyph_count (face);
182 for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
183 {
184 unsigned num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
185 if (!num_layers) continue;
186
187 hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
188
189 hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
190 if (num_layers)
191 {
192 hb_font_extents_t font_extents;
193 hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
194 hb_glyph_extents_t extents = {0};
195 if (!hb_font_get_glyph_extents (font, gid, &extents))
196 {
197 printf ("Skip gid: %d\n", gid);
198 continue;
199 }
200
201 unsigned palette_count = hb_ot_color_palette_get_count (face);
202 for (unsigned palette = 0; palette < palette_count; ++palette)
203 {
204 unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
205 if (!num_colors)
206 continue;
207
208 char output_path[255];
209 sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
210 FILE *f = fopen (output_path, "wb");
211 fprintf (f, "<svg xmlns=\"http://www.w3.org/2000/svg\""
212 " viewBox=\"%d %d %d %d\">\n",
213 extents.x_bearing, 0,
214 extents.x_bearing + extents.width, -extents.height);
215 user_data_t user_data;
216 user_data.ascender = extents.y_bearing;
217 user_data.f = f;
218
219 hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
220 hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
221 if (num_colors)
222 {
223 for (unsigned layer = 0; layer < num_layers; ++layer)
224 {
225 hb_color_t color = 0x000000FF;
226 if (layers[layer].color_index != 0xFFFF)
227 color = colors[layers[layer].color_index];
228 fprintf (f, "<path fill=\"#%02X%02X%02X\" ",
229 hb_color_get_red (color), hb_color_get_green (color), hb_color_get_green (color));
230 if (hb_color_get_alpha (color) != 255)
231 fprintf (f, "fill-opacity=\"%.3f\"", (double) hb_color_get_alpha (color) / 255.);
232 fprintf (f, "d=\"");
233 if (!hb_ot_glyph_decompose (font, layers[layer].glyph, funcs, &user_data))
234 printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
235 fprintf (f, "\"/>\n");
236 }
237 }
238 free (colors);
239
240 fprintf (f, "</svg>");
241 fclose (f);
242 }
243 }
244
245
246 free (layers);
247 }
248}
249
250static void
251dump_glyphs (hb_font_t *font, hb_ot_glyph_decompose_funcs_t *funcs, unsigned face_index)
252{
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;
275 if (!hb_ot_glyph_decompose (font, gid, funcs, &user_data))
276 printf ("Failed to decompose gid: %d\n", gid);
277 fprintf (f, "\"/></svg>");
278 fclose (f);
279 }
280}
281
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500282int
283main (int argc, char **argv)
284{
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330285 if (argc != 2)
286 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500287 fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
288 exit (1);
289 }
290
Ebrahim Byagowice173402018-04-20 10:29:06 +0430291 hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330292 unsigned len;
Ebrahim Byagowice173402018-04-20 10:29:06 +0430293 const char *font_data = hb_blob_get_data (blob, &len);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500294 printf ("Opened font file %s: %d bytes long\n", argv[1], len);
Behdad Esfahbodce48f032009-11-02 14:35:51 -0500295
Behdad Esfahbod8e3e4122018-07-22 22:49:26 -0700296 hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob<OpenTypeFontFile> (blob);
Behdad Esfahbodeba1c162018-05-08 02:47:42 -0700297 const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
Behdad Esfahbodb912fbe2018-08-06 06:30:12 -0700298 if (!font_blob->data)
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430299 {
300 printf ("Sanitization of the file wasn't successful. Exit");
301 return 1;
302 }
303 const OpenTypeFontFile& ot = *sanitized;
304
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500305
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330306 switch (ot.get_tag ())
307 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500308 case OpenTypeFontFile::TrueTypeTag:
309 printf ("OpenType font with TrueType outlines\n");
310 break;
311 case OpenTypeFontFile::CFFTag:
312 printf ("OpenType font with CFF (Type1) outlines\n");
313 break;
314 case OpenTypeFontFile::TTCTag:
315 printf ("TrueType Collection of OpenType fonts\n");
316 break;
Behdad Esfahbodce5694c2010-05-04 14:10:18 -0400317 case OpenTypeFontFile::TrueTag:
318 printf ("Obsolete Apple TrueType font\n");
319 break;
320 case OpenTypeFontFile::Typ1Tag:
321 printf ("Obsolete Apple Type1 font in SFNT container\n");
322 break;
Ebrahim Byagowi225b92b2018-07-01 14:32:00 +0430323 case OpenTypeFontFile::DFontTag:
324 printf ("DFont Mac Resource Fork\n");
325 break;
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500326 default:
327 printf ("Unknown font format\n");
328 break;
329 }
330
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330331 unsigned num_faces = hb_face_count (blob);
332 printf ("%d font(s) found in file\n", num_faces);
333 for (int n_font = 0; n_font < num_faces; n_font++)
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330334 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500335 const OpenTypeFontFace &font = ot.get_face (n_font);
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330336 printf ("Font %d of %d:\n", n_font, num_faces);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500337
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500338 int num_tables = font.get_table_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500339 printf (" %d table(s) found in font\n", num_tables);
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330340 for (int n_table = 0; n_table < num_tables; n_table++)
341 {
Behdad Esfahbod54e5aac2008-01-27 21:19:51 -0500342 const OpenTypeTable &table = font.get_table (n_table);
Behdad Esfahbod15164d92009-08-04 13:57:41 -0400343 printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Ebrahim Byagowic55aa142018-04-18 00:01:20 +0430344 (const char *) table.tag,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330345 (unsigned) table.offset,
346 (unsigned) table.length);
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500347
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330348 switch (table.tag)
349 {
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500350
Behdad Esfahboda130ee62017-11-14 20:30:03 -0800351 case HB_OT_TAG_GSUB:
352 case HB_OT_TAG_GPOS:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500353 {
354
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600355 const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500356
357 int num_scripts = g.get_script_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500358 printf (" %d script(s) found in table\n", num_scripts);
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330359 for (int n_script = 0; n_script < num_scripts; n_script++)
360 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500361 const Script &script = g.get_script (n_script);
362 printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330363 (const char *)g.get_script_tag(n_script));
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500364
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500365 if (!script.has_default_lang_sys())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500366 printf (" No default language system\n");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500367 int num_langsys = script.get_lang_sys_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500368 printf (" %d language system(s) found in script\n", num_langsys);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500369 for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) {
370 const LangSys &langsys = n_langsys == -1
371 ? script.get_default_lang_sys ()
372 : script.get_lang_sys (n_langsys);
Behdad Esfahbod1a2a4a02012-05-05 22:38:20 +0200373 if (n_langsys == -1)
374 printf (" Default Language System\n");
375 else
376 printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330377 (const char *) script.get_lang_sys_tag (n_langsys));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700378 if (!langsys.has_required_feature ())
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500379 printf (" No required feature\n");
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700380 else
381 printf (" Required feature index: %d\n",
382 langsys.get_required_feature_index ());
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500383
384 int num_features = langsys.get_feature_count ();
385 printf (" %d feature(s) found in language system\n", num_features);
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330386 for (int n_feature = 0; n_feature < num_features; n_feature++)
387 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500388 printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330389 langsys.get_feature_index (n_feature));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500390 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500391 }
392 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500393
394 int num_features = g.get_feature_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500395 printf (" %d feature(s) found in table\n", num_features);
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330396 for (int n_feature = 0; n_feature < num_features; n_feature++)
397 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500398 const Feature &feature = g.get_feature (n_feature);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500399 int num_lookups = feature.get_lookup_count ();
Jonathan Kewda132932014-04-27 14:05:24 +0100400 printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330401 HB_UNTAG(g.get_feature_tag(n_feature)));
Behdad Esfahbod0ddecab2014-05-01 16:01:40 -0700402
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400403 printf (" %d lookup(s) found in feature\n", num_lookups);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500404 for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400405 printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330406 feature.get_lookup_index (n_lookup));
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500407 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500408 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500409
410 int num_lookups = g.get_lookup_count ();
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500411 printf (" %d lookup(s) found in table\n", num_lookups);
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330412 for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++)
413 {
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500414 const Lookup &lookup = g.get_lookup (n_lookup);
Behdad Esfahbod8c69e652010-10-27 22:07:49 -0400415 printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330416 lookup.get_type(), lookup.get_props());
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500417 }
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500418
419 }
420 break;
421
Behdad Esfahbod6c48f202013-09-09 15:43:10 -0400422 case GDEF::tableTag:
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500423 {
424
Behdad Esfahbodb84ceb22019-12-10 13:02:48 -0600425 const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500426
427 printf (" Has %sglyph classes\n",
428 gdef.has_glyph_classes () ? "" : "no ");
429 printf (" Has %smark attachment types\n",
430 gdef.has_mark_attachment_types () ? "" : "no ");
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400431 printf (" Has %sattach points\n",
432 gdef.has_attach_points () ? "" : "no ");
433 printf (" Has %slig carets\n",
434 gdef.has_lig_carets () ? "" : "no ");
Behdad Esfahbod67cb8112009-08-09 13:05:08 -0400435 printf (" Has %smark sets\n",
436 gdef.has_mark_sets () ? "" : "no ");
Behdad Esfahbod40a81312008-01-28 02:30:48 -0500437 break;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400438 }
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500439 }
440 }
441 }
442
Ebrahim Byagowi23277be2020-01-24 18:49:48 +0330443 /* Dump glyphs */
444 FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
445 if (font_name_file != nullptr)
446 {
447 fprintf (stderr, "Purge or move ./out folder in order to run a new glyph dump,\n"
448 "run it like `rm -rf out && mkdir out && %s font-file.ttf`\n",
449 argv[0]);
450 return 0;
451 }
452
453 font_name_file = fopen ("out/.dumped_font_name", "w");
454 if (font_name_file == nullptr)
455 {
456 fprintf (stderr, "./out is not accessible as a folder, create it please\n");
457 return 0;
458 }
459 fwrite (argv[1], 1, strlen (argv[1]), font_name_file);
460 fclose (font_name_file);
461
462 hb_ot_glyph_decompose_funcs_t *funcs = hb_ot_glyph_decompose_funcs_create ();
463 hb_ot_glyph_decompose_funcs_set_move_to_func (funcs, (hb_ot_glyph_decompose_move_to_func_t) move_to);
464 hb_ot_glyph_decompose_funcs_set_line_to_func (funcs, (hb_ot_glyph_decompose_line_to_func_t) line_to);
465 hb_ot_glyph_decompose_funcs_set_conic_to_func (funcs, (hb_ot_glyph_decompose_conic_to_func_t) conic_to);
466 hb_ot_glyph_decompose_funcs_set_cubic_to_func (funcs, (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to);
467 hb_ot_glyph_decompose_funcs_set_close_path_func (funcs, (hb_ot_glyph_decompose_close_path_func_t) close_path);
468
469 for (unsigned face_index = 0; face_index < num_faces; ++face_index)
470 {
471 hb_face_t *face = hb_face_create (blob, face_index);
472 hb_font_t *font = hb_font_create (face);
473
474 if (hb_ot_color_has_png (face))
475 printf ("Dumping png (CBDT/sbix)...\n");
476 png_dump (face, face_index);
477
478 if (hb_ot_color_has_svg (face))
479 printf ("Dumping svg (SVG )...\n");
480 svg_dump (face, face_index);
481
482 if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
483 printf ("Dumping layered color glyphs (COLR/CPAL)...\n");
484 layered_glyph_dump (font, funcs, face_index);
485
486 dump_glyphs (font, funcs, face_index);
487
488 hb_font_destroy (font);
489 hb_face_destroy (face);
490 }
491
492 hb_ot_glyph_decompose_funcs_destroy (funcs);
493 hb_blob_destroy (blob);
494
Behdad Esfahbod12c45682006-12-28 06:10:59 -0500495 return 0;
496}