Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 3 | * Copyright © 2018,2019,2020 Ebrahim Byagowi |
| 4 | * Copyright © 2018 Khaled Hosny |
Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 5 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 6 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 7 | * |
| 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 Esfahbod | fd3d004 | 2018-05-24 15:58:26 -0700 | [diff] [blame] | 29 | #include "hb-static.cc" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 30 | #include "hb-open-file.hh" |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 31 | #include "hb-ot-layout-gdef-table.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 32 | #include "hb-ot-layout-gsubgpos.hh" |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 33 | |
Behdad Esfahbod | bdd0ff5 | 2009-12-15 04:07:40 -0500 | [diff] [blame] | 34 | #ifdef HAVE_GLIB |
Behdad Esfahbod | baec684 | 2009-08-01 21:06:11 -0400 | [diff] [blame] | 35 | #include <glib.h> |
Behdad Esfahbod | bdd0ff5 | 2009-12-15 04:07:40 -0500 | [diff] [blame] | 36 | #endif |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 37 | #include <stdlib.h> |
| 38 | #include <stdio.h> |
| 39 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 40 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 41 | using namespace OT; |
| 42 | |
Ebrahim Byagowi | bb4cdf8 | 2019-06-25 01:42:42 +0430 | [diff] [blame] | 43 | #ifdef HB_NO_OPEN |
| 44 | #define hb_blob_create_from_file(x) hb_blob_get_empty () |
| 45 | #endif |
| 46 | |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 47 | static void |
| 48 | svg_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 */ |
| 77 | static void |
| 78 | png_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 | |
| 133 | struct user_data_t |
| 134 | { |
| 135 | FILE *f; |
| 136 | hb_position_t ascender; |
| 137 | }; |
| 138 | |
| 139 | static void |
| 140 | move_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 | |
| 145 | static void |
| 146 | line_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 | |
| 151 | static void |
| 152 | conic_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 | |
| 160 | static void |
| 161 | cubic_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 | |
| 171 | static void |
| 172 | close_path (user_data_t &user_data) |
| 173 | { |
| 174 | fprintf (user_data.f, "Z"); |
| 175 | } |
| 176 | |
| 177 | static void |
| 178 | layered_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 | |
| 250 | static void |
| 251 | dump_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 Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 282 | int |
| 283 | main (int argc, char **argv) |
| 284 | { |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 285 | if (argc != 2) |
| 286 | { |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 287 | fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]); |
| 288 | exit (1); |
| 289 | } |
| 290 | |
Ebrahim Byagowi | ce17340 | 2018-04-20 10:29:06 +0430 | [diff] [blame] | 291 | hb_blob_t *blob = hb_blob_create_from_file (argv[1]); |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 292 | unsigned len; |
Ebrahim Byagowi | ce17340 | 2018-04-20 10:29:06 +0430 | [diff] [blame] | 293 | const char *font_data = hb_blob_get_data (blob, &len); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 294 | printf ("Opened font file %s: %d bytes long\n", argv[1], len); |
Behdad Esfahbod | ce48f03 | 2009-11-02 14:35:51 -0500 | [diff] [blame] | 295 | |
Behdad Esfahbod | 8e3e412 | 2018-07-22 22:49:26 -0700 | [diff] [blame] | 296 | hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob<OpenTypeFontFile> (blob); |
Behdad Esfahbod | eba1c16 | 2018-05-08 02:47:42 -0700 | [diff] [blame] | 297 | const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> (); |
Behdad Esfahbod | b912fbe | 2018-08-06 06:30:12 -0700 | [diff] [blame] | 298 | if (!font_blob->data) |
Ebrahim Byagowi | c55aa14 | 2018-04-18 00:01:20 +0430 | [diff] [blame] | 299 | { |
| 300 | printf ("Sanitization of the file wasn't successful. Exit"); |
| 301 | return 1; |
| 302 | } |
| 303 | const OpenTypeFontFile& ot = *sanitized; |
| 304 | |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 305 | |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 306 | switch (ot.get_tag ()) |
| 307 | { |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 308 | 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 Esfahbod | ce5694c | 2010-05-04 14:10:18 -0400 | [diff] [blame] | 317 | 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 Byagowi | 225b92b | 2018-07-01 14:32:00 +0430 | [diff] [blame] | 323 | case OpenTypeFontFile::DFontTag: |
| 324 | printf ("DFont Mac Resource Fork\n"); |
| 325 | break; |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 326 | default: |
| 327 | printf ("Unknown font format\n"); |
| 328 | break; |
| 329 | } |
| 330 | |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 331 | 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 Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 334 | { |
Behdad Esfahbod | 54e5aac | 2008-01-27 21:19:51 -0500 | [diff] [blame] | 335 | const OpenTypeFontFace &font = ot.get_face (n_font); |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 336 | printf ("Font %d of %d:\n", n_font, num_faces); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 337 | |
Behdad Esfahbod | 54e5aac | 2008-01-27 21:19:51 -0500 | [diff] [blame] | 338 | int num_tables = font.get_table_count (); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 339 | printf (" %d table(s) found in font\n", num_tables); |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 340 | for (int n_table = 0; n_table < num_tables; n_table++) |
| 341 | { |
Behdad Esfahbod | 54e5aac | 2008-01-27 21:19:51 -0500 | [diff] [blame] | 342 | const OpenTypeTable &table = font.get_table (n_table); |
Behdad Esfahbod | 15164d9 | 2009-08-04 13:57:41 -0400 | [diff] [blame] | 343 | printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, |
Ebrahim Byagowi | c55aa14 | 2018-04-18 00:01:20 +0430 | [diff] [blame] | 344 | (const char *) table.tag, |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 345 | (unsigned) table.offset, |
| 346 | (unsigned) table.length); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 347 | |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 348 | switch (table.tag) |
| 349 | { |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 350 | |
Behdad Esfahbod | a130ee6 | 2017-11-14 20:30:03 -0800 | [diff] [blame] | 351 | case HB_OT_TAG_GSUB: |
| 352 | case HB_OT_TAG_GPOS: |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 353 | { |
| 354 | |
Behdad Esfahbod | b84ceb2 | 2019-12-10 13:02:48 -0600 | [diff] [blame] | 355 | const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 356 | |
| 357 | int num_scripts = g.get_script_count (); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 358 | printf (" %d script(s) found in table\n", num_scripts); |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 359 | for (int n_script = 0; n_script < num_scripts; n_script++) |
| 360 | { |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 361 | const Script &script = g.get_script (n_script); |
| 362 | printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 363 | (const char *)g.get_script_tag(n_script)); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 364 | |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 365 | if (!script.has_default_lang_sys()) |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 366 | printf (" No default language system\n"); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 367 | int num_langsys = script.get_lang_sys_count (); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 368 | printf (" %d language system(s) found in script\n", num_langsys); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 369 | 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 Esfahbod | 1a2a4a0 | 2012-05-05 22:38:20 +0200 | [diff] [blame] | 373 | 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 Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 377 | (const char *) script.get_lang_sys_tag (n_langsys)); |
Behdad Esfahbod | 0ddecab | 2014-05-01 16:01:40 -0700 | [diff] [blame] | 378 | if (!langsys.has_required_feature ()) |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 379 | printf (" No required feature\n"); |
Behdad Esfahbod | 0ddecab | 2014-05-01 16:01:40 -0700 | [diff] [blame] | 380 | else |
| 381 | printf (" Required feature index: %d\n", |
| 382 | langsys.get_required_feature_index ()); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 383 | |
| 384 | int num_features = langsys.get_feature_count (); |
| 385 | printf (" %d feature(s) found in language system\n", num_features); |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 386 | for (int n_feature = 0; n_feature < num_features; n_feature++) |
| 387 | { |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 388 | printf (" Feature index %2d of %2d: %d\n", n_feature, num_features, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 389 | langsys.get_feature_index (n_feature)); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 390 | } |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 391 | } |
| 392 | } |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 393 | |
| 394 | int num_features = g.get_feature_count (); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 395 | printf (" %d feature(s) found in table\n", num_features); |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 396 | for (int n_feature = 0; n_feature < num_features; n_feature++) |
| 397 | { |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 398 | const Feature &feature = g.get_feature (n_feature); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 399 | int num_lookups = feature.get_lookup_count (); |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 400 | printf (" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 401 | HB_UNTAG(g.get_feature_tag(n_feature))); |
Behdad Esfahbod | 0ddecab | 2014-05-01 16:01:40 -0700 | [diff] [blame] | 402 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 403 | printf (" %d lookup(s) found in feature\n", num_lookups); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 404 | for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 405 | printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 406 | feature.get_lookup_index (n_lookup)); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 407 | } |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 408 | } |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 409 | |
| 410 | int num_lookups = g.get_lookup_count (); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 411 | printf (" %d lookup(s) found in table\n", num_lookups); |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 412 | for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) |
| 413 | { |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 414 | const Lookup &lookup = g.get_lookup (n_lookup); |
Behdad Esfahbod | 8c69e65 | 2010-10-27 22:07:49 -0400 | [diff] [blame] | 415 | printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 416 | lookup.get_type(), lookup.get_props()); |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 417 | } |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 418 | |
| 419 | } |
| 420 | break; |
| 421 | |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 422 | case GDEF::tableTag: |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 423 | { |
| 424 | |
Behdad Esfahbod | b84ceb2 | 2019-12-10 13:02:48 -0600 | [diff] [blame] | 425 | const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 426 | |
| 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 Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 431 | printf (" Has %sattach points\n", |
| 432 | gdef.has_attach_points () ? "" : "no "); |
| 433 | printf (" Has %slig carets\n", |
| 434 | gdef.has_lig_carets () ? "" : "no "); |
Behdad Esfahbod | 67cb811 | 2009-08-09 13:05:08 -0400 | [diff] [blame] | 435 | printf (" Has %smark sets\n", |
| 436 | gdef.has_mark_sets () ? "" : "no "); |
Behdad Esfahbod | 40a8131 | 2008-01-28 02:30:48 -0500 | [diff] [blame] | 437 | break; |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 438 | } |
Behdad Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
Ebrahim Byagowi | 23277be | 2020-01-24 18:49:48 +0330 | [diff] [blame^] | 443 | /* 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 Esfahbod | 12c4568 | 2006-12-28 06:10:59 -0500 | [diff] [blame] | 495 | return 0; |
| 496 | } |