From ca903f7531f71a81c06a4e9fc4f7166af3f04968 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 12:40:27 -0700 Subject: [PATCH 01/33] [hb-info] Start adding --- util/Makefile.am | 3 ++ util/Makefile.sources | 8 ++++ util/hb-info.cc | 108 ++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 13 +++++ 4 files changed, 132 insertions(+) create mode 100644 util/hb-info.cc diff --git a/util/Makefile.am b/util/Makefile.am index 82c14fd65..12041b5ae 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -51,6 +51,9 @@ endif # HAVE_CAIRO hb_shape_SOURCES = $(HB_SHAPE_sources) bin_PROGRAMS += hb-shape +hb_info_SOURCES = $(HB_INFO_sources) +bin_PROGRAMS += hb-info + hb_subset_SOURCES = $(HB_SUBSET_CLI_sources) hb_subset_LDADD = \ $(top_builddir)/src/libharfbuzz-subset.la \ diff --git a/util/Makefile.sources b/util/Makefile.sources index 70b704e1a..a64099e9f 100644 --- a/util/Makefile.sources +++ b/util/Makefile.sources @@ -31,6 +31,14 @@ HB_SHAPE_sources = \ text-options.hh \ $(NULL) +HB_INFO_sources = \ + batch.hh \ + face-options.hh \ + font-options.hh \ + hb-info.cc \ + options.hh \ + $(NULL) + HB_SUBSET_CLI_sources = \ batch.hh \ face-options.hh \ diff --git a/util/hb-info.cc b/util/hb-info.cc new file mode 100644 index 000000000..9bddb998d --- /dev/null +++ b/util/hb-info.cc @@ -0,0 +1,108 @@ +/* + * Copyright © 2010 Behdad Esfahbod + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "batch.hh" +#include "font-options.hh" + +const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM; +const unsigned SUBPIXEL_BITS = 0; + + +struct info_t +{ + void add_options (option_parser_t *parser) + { + } + + void operator () () + { + } +}; + + +template +struct main_font_t : + option_parser_t, + font_options_type, + consumer_t +{ + int operator () (int argc, char **argv) + { + add_options (); + parse (&argc, &argv); + + consumer_t::operator () (); + + return 0; + } + + protected: + + void add_options () + { + font_options_type::add_options (this); + consumer_t::add_options (this); + + GOptionEntry entries[] = + { + {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_CALLBACK, (gpointer) &collect_rest, nullptr, "[FONT-FILE]"}, + {nullptr} + }; + add_main_group (entries, this); + option_parser_t::add_options (); + } + + private: + + static gboolean + collect_rest (const char *name G_GNUC_UNUSED, + const char *arg, + gpointer data, + GError **error) + { + main_font_t *thiz = (main_font_t *) data; + + if (!thiz->font_file) + { + thiz->font_file = g_strdup (arg); + return true; + } + + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, + "Too many arguments on the command line"); + return false; + } +}; + +int +main (int argc, char **argv) +{ + using main_t = main_font_t; + return batch_main (argc, argv); +} diff --git a/util/meson.build b/util/meson.build index df48855a7..ff38bd635 100644 --- a/util/meson.build +++ b/util/meson.build @@ -6,6 +6,10 @@ hb_shape_sources = [ 'hb-shape.cc', ] +hb_info_sources = [ + 'hb-info.cc', +] + hb_ot_shape_closure_sources = [ 'hb-ot-shape-closure.cc', ] @@ -37,6 +41,15 @@ if conf.get('HAVE_GLIB', 0) == 1 ) meson.override_find_program('hb-shape', hb_shape) + hb_info = executable('hb-info', hb_info_sources, + cpp_args: cpp_args, + include_directories: [incconfig, incsrc], + dependencies: util_deps, + link_with: [libharfbuzz], + install: true, + ) + meson.override_find_program('hb-info', hb_info) + hb_subset = executable('hb-subset', hb_subset_cli_sources, cpp_args: cpp_args, include_directories: [incconfig, incsrc], From 1816d3664d52b94547a6f0882173a8d5d7f93d19 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 12:59:26 -0700 Subject: [PATCH 02/33] [hb-info] Flesh out --- util/face-options.hh | 29 ---- util/font-options.hh | 281 -------------------------------------- util/hb-info.cc | 318 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 316 insertions(+), 312 deletions(-) diff --git a/util/face-options.hh b/util/face-options.hh index e193b0000..f680e05cd 100644 --- a/util/face-options.hh +++ b/util/face-options.hh @@ -60,15 +60,12 @@ struct face_options_t char *font_file = nullptr; unsigned face_index = 0; - hb_bool_t list_tables = false; hb_blob_t *blob = nullptr; hb_face_t *face = nullptr; }; -static G_GNUC_NORETURN void _list_tables (hb_face_t *face); - face_options_t::cache_t face_options_t::cache {}; void @@ -124,31 +121,6 @@ face_options_t::post_parse (GError **error) blob = cache.blob; face = cache.face; - - if (list_tables) - _list_tables (face); -} - -static G_GNUC_NORETURN void _list_tables (hb_face_t *face) -{ - unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); - hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t)); - hb_face_get_table_tags (face, 0, &count, tags); - - for (unsigned i = 0; i < count; i++) - { - hb_tag_t tag = tags[i]; - - hb_blob_t *blob = hb_face_reference_table (face, tag); - - printf ("%c%c%c%c: %8u bytes\n", HB_UNTAG (tag), hb_blob_get_length (blob)); - - hb_blob_destroy (blob); - } - - free (tags); - - exit (0); } void @@ -158,7 +130,6 @@ face_options_t::add_options (option_parser_t *parser) { {"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Set font file-name", "filename"}, {"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Set face index (default: 0)", "index"}, - {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List font tables and quit", nullptr}, {nullptr} }; parser->add_group (entries, diff --git a/util/font-options.hh b/util/font-options.hh index ca87e763c..b1a0169c6 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -56,11 +56,7 @@ struct font_options_t : face_options_t void post_parse (GError **error); hb_bool_t sub_font = false; - hb_bool_t list_features = false; - hb_bool_t list_unicodes = false; - hb_bool_t list_glyphs = false; #ifndef HB_NO_VAR - hb_bool_t list_variations = false; hb_variation_t *variations = nullptr; unsigned int num_variations = 0; #endif @@ -92,13 +88,6 @@ static struct supported_font_funcs_t { }; -static G_GNUC_NORETURN void _list_features (hb_face_t *face); -#ifndef HB_NO_VAR -static G_GNUC_NORETURN void _list_variations (hb_face_t *face); -#endif -static G_GNUC_NORETURN void _list_unicodes (hb_font_t *font); -static G_GNUC_NORETURN void _list_glyphs (hb_font_t *font); - void font_options_t::post_parse (GError **error) { @@ -169,199 +158,9 @@ font_options_t::post_parse (GError **error) hb_font_set_scale (old_font, scale_x * 2, scale_y * 2); hb_font_destroy (old_font); } - - if (list_features) - _list_features (face); - -#ifndef HB_NO_VAR - if (list_variations) - _list_variations (face); -#endif - - if (list_unicodes) - _list_unicodes (font); - - if (list_glyphs) - _list_glyphs (font); -} - -static G_GNUC_NORETURN void -_list_features (hb_face_t *face) -{ - hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; - auto language = hb_language_get_default (); - hb_set_t *features = hb_set_create (); - - for (unsigned int i = 0; table_tags[i]; i++) - { - printf ("Table: %c%c%c%c\n", HB_UNTAG (table_tags[i])); - - hb_tag_t script_array[32]; - unsigned script_count = sizeof script_array / sizeof script_array[0]; - unsigned script_offset = 0; - do - { - hb_ot_layout_table_get_script_tags (face, table_tags[i], - script_offset, - &script_count, - script_array); - - for (unsigned script_index = 0; script_index < script_count; script_index++) - { - printf (" Script: %c%c%c%c\n", HB_UNTAG (script_array[script_index])); - - hb_tag_t language_array[32]; - unsigned language_count = sizeof language_array / sizeof language_array[0]; - unsigned language_offset = 0; - do - { - hb_ot_layout_script_get_language_tags (face, table_tags[i], - script_offset + script_index, - language_offset, - &language_count, - language_array); - - for (unsigned language_index = 0; language_index < language_count; language_index++) - { - printf (" Language: %c%c%c%c\n", HB_UNTAG (language_array[language_index])); - } - - language_offset += language_count; - } - while (language_count == sizeof language_array / sizeof language_array[0]); - } - - script_offset += script_count; - } - while (script_count == sizeof script_array / sizeof script_array[0]); - - hb_set_clear (features); - hb_tag_t feature_array[32]; - unsigned feature_count = sizeof feature_array / sizeof feature_array[0]; - unsigned feature_offset = 0; - do - { - hb_ot_layout_table_get_feature_tags (face, table_tags[i], - feature_offset, - &feature_count, - feature_array); - - for (unsigned feature_index = 0; feature_index < feature_count; feature_index++) - { - if (hb_set_has (features, feature_array[feature_index])) - continue; - hb_set_add (features, feature_array[feature_index]); - - hb_ot_name_id_t label_id; - - hb_ot_layout_feature_get_name_ids (face, - table_tags[i], - feature_offset + feature_index, - &label_id, - nullptr, - nullptr, - nullptr, - nullptr); - - char name[64]; - unsigned name_len = sizeof name; - - hb_ot_name_get_utf8 (face, label_id, - language, - &name_len, name); - - printf (" Feature: %c%c%c%c", HB_UNTAG (feature_array[feature_index])); - - if (*name) - printf (" \"%s\"", name); - - printf ("\n"); - } - - feature_offset += feature_count; - } - while (feature_count == sizeof feature_array / sizeof feature_array[0]); - } - - hb_set_destroy (features); - - exit (0); } #ifndef HB_NO_VAR -static G_GNUC_NORETURN void -_list_variations (hb_face_t *face) -{ - hb_ot_var_axis_info_t *axes; - - unsigned count = hb_ot_var_get_axis_infos (face, 0, nullptr, nullptr); - axes = (hb_ot_var_axis_info_t *) calloc (count, sizeof (hb_ot_var_axis_info_t)); - hb_ot_var_get_axis_infos (face, 0, &count, axes); - - auto language = hb_language_get_default (); - bool has_hidden = false; - - printf ("Varitation axes:\n"); - printf ("Tag: Minimum Default Maximum Name\n\n"); - for (unsigned i = 0; i < count; i++) - { - const auto &axis = axes[i]; - if (axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN) - has_hidden = true; - - char name[64]; - unsigned name_len = sizeof name; - - hb_ot_name_get_utf8 (face, axis.name_id, - language, - &name_len, name); - - printf ("%c%c%c%c%s: %g %g %g %s\n", - HB_UNTAG (axis.tag), - axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN ? "*" : "", - (double) axis.min_value, - (double) axis.default_value, - (double) axis.max_value, - name); - } - if (has_hidden) - printf ("\n[*] Hidden axis\n"); - - free (axes); - axes = nullptr; - - count = hb_ot_var_get_named_instance_count (face); - if (count) - { - printf ("\n\nNamed instances: \n\n"); - - for (unsigned i = 0; i < count; i++) - { - char name[64]; - unsigned name_len = sizeof name; - - hb_ot_name_id_t name_id = hb_ot_var_named_instance_get_subfamily_name_id (face, i); - hb_ot_name_get_utf8 (face, name_id, - language, - &name_len, name); - - unsigned coords_count = hb_ot_var_named_instance_get_design_coords (face, i, nullptr, nullptr); - float* coords; - coords = (float *) calloc (coords_count, sizeof (float)); - hb_ot_var_named_instance_get_design_coords (face, i, &coords_count, coords); - - printf ("%u. %-32s", i, name); - for (unsigned j = 0; j < coords_count; j++) - printf ("%g, ", (double) coords[j]); - printf ("\n"); - - free (coords); - } - } - - exit(0); -} - static gboolean parse_variations (const char *name G_GNUC_UNUSED, const char *arg, @@ -406,82 +205,6 @@ parse_variations (const char *name G_GNUC_UNUSED, } #endif -static G_GNUC_NORETURN void -_list_unicodes (hb_font_t *font) -{ - hb_face_t *face = hb_font_get_face (font); - - hb_set_t *unicodes = hb_set_create (); - hb_map_t *cmap = hb_map_create (); - - hb_face_collect_nominal_glyph_mapping (face, cmap, unicodes); - - for (hb_codepoint_t u = HB_SET_VALUE_INVALID; - hb_set_next (unicodes, &u);) - { - hb_codepoint_t gid = hb_map_get (cmap, u); - - char glyphname[64]; - hb_font_glyph_to_string (font, gid, - glyphname, sizeof glyphname); - - printf ("U+%04X %s\n", u, glyphname); - } - - hb_map_destroy (cmap); - - - /* List variation-selector sequences. */ - hb_set_t *vars = hb_set_create (); - - hb_face_collect_variation_selectors (face, vars); - - for (hb_codepoint_t vs = HB_SET_VALUE_INVALID; - hb_set_next (vars, &vs);) - { - hb_set_clear (unicodes); - hb_face_collect_variation_unicodes (face, vs, unicodes); - - for (hb_codepoint_t u = HB_SET_VALUE_INVALID; - hb_set_next (unicodes, &u);) - { - hb_codepoint_t gid = 0; - bool b = hb_font_get_variation_glyph (font, u, vs, &gid); - assert (b); - - char glyphname[64]; - hb_font_glyph_to_string (font, gid, - glyphname, sizeof glyphname); - - printf ("U+%04X,U+%04X %s\n", vs, u, glyphname); - } - } - - hb_set_destroy (vars); - hb_set_destroy (unicodes); - - exit(0); -} - -static G_GNUC_NORETURN void -_list_glyphs (hb_font_t *font) -{ - hb_face_t *face = hb_font_get_face (font); - - unsigned num_glyphs = hb_face_get_glyph_count (face); - - for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++) - { - char glyphname[64]; - hb_font_glyph_to_string (font, gid, - glyphname, sizeof glyphname); - - printf ("%u %s\n", gid, glyphname); - } - - exit(0); -} - static gboolean parse_font_size (const char *name G_GNUC_UNUSED, const char *arg, @@ -571,9 +294,6 @@ font_options_t::add_options (option_parser_t *parser) {"sub-font", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"}, {"ft-load-flags", 0, 0, G_OPTION_ARG_INT, &this->ft_load_flags, "Set FreeType load-flags (default: 2)", "integer"}, - {"list-features", 0, 0, G_OPTION_ARG_NONE, &this->list_features, "List available font features and quit", nullptr}, - {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List available characters in the font and quit", nullptr}, - {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List available glyphs in the font and quit", nullptr}, {nullptr} }; parser->add_group (entries, @@ -598,7 +318,6 @@ font_options_t::add_options (option_parser_t *parser) GOptionEntry entries2[] = { - {"list-variations", 0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List available font variations and quit", nullptr}, {"named-instance", 0, 0, G_OPTION_ARG_INT, &this->named_instance, "Set named-instance index (default: none)", "index"}, {"variations", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_variations, variations_help, "list"}, {nullptr} diff --git a/util/hb-info.cc b/util/hb-info.cc index 9bddb998d..8f9bb7a35 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -36,11 +36,325 @@ struct info_t { void add_options (option_parser_t *parser) { + GOptionEntry entries[] = + { + {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List everything", nullptr}, + {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, + {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, + {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, + {"list-features", 0, 0, G_OPTION_ARG_NONE, &this->list_features, "List layout features", nullptr}, +#ifndef HB_NO_VAR + {"list-variations",0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List variations", nullptr}, +#endif + {nullptr} + }; + parser->add_group (entries, + "query", + "Query options:", + "Options to query the font instance", + this, + false /* We add below. */); } - void operator () () + private: + hb_bool_t list_all; + hb_bool_t list_tables; + hb_bool_t list_unicodes; + hb_bool_t list_glyphs; + hb_bool_t list_features; +#ifndef HB_NO_VAR + hb_bool_t list_variations; +#endif + public: + + void operator () (font_options_t *font_opts) { + if (list_all) + { + list_tables = + list_unicodes = + list_glyphs = + list_features = +#ifndef HB_NO_VAR + list_variations = +#endif + true; + } + + if (list_tables) _list_tables (font_opts->face); + if (list_unicodes) _list_unicodes (font_opts->font); + if (list_glyphs) _list_glyphs (font_opts->font); + if (list_features) _list_features (font_opts->face); +#ifndef HB_NO_VAR + if (list_variations) _list_variations (font_opts->face); +#endif } + + void _list_tables (hb_face_t *face) + { + unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); + hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t)); + hb_face_get_table_tags (face, 0, &count, tags); + + for (unsigned i = 0; i < count; i++) + { + hb_tag_t tag = tags[i]; + + hb_blob_t *blob = hb_face_reference_table (face, tag); + + printf ("%c%c%c%c: %8u bytes\n", HB_UNTAG (tag), hb_blob_get_length (blob)); + + hb_blob_destroy (blob); + } + + free (tags); + } + + void + _list_unicodes (hb_font_t *font) + { + hb_face_t *face = hb_font_get_face (font); + + hb_set_t *unicodes = hb_set_create (); + hb_map_t *cmap = hb_map_create (); + + hb_face_collect_nominal_glyph_mapping (face, cmap, unicodes); + + for (hb_codepoint_t u = HB_SET_VALUE_INVALID; + hb_set_next (unicodes, &u);) + { + hb_codepoint_t gid = hb_map_get (cmap, u); + + char glyphname[64]; + hb_font_glyph_to_string (font, gid, + glyphname, sizeof glyphname); + + printf ("U+%04X %s\n", u, glyphname); + } + + hb_map_destroy (cmap); + + + /* List variation-selector sequences. */ + hb_set_t *vars = hb_set_create (); + + hb_face_collect_variation_selectors (face, vars); + + for (hb_codepoint_t vs = HB_SET_VALUE_INVALID; + hb_set_next (vars, &vs);) + { + hb_set_clear (unicodes); + hb_face_collect_variation_unicodes (face, vs, unicodes); + + for (hb_codepoint_t u = HB_SET_VALUE_INVALID; + hb_set_next (unicodes, &u);) + { + hb_codepoint_t gid = 0; + bool b = hb_font_get_variation_glyph (font, u, vs, &gid); + assert (b); + + char glyphname[64]; + hb_font_glyph_to_string (font, gid, + glyphname, sizeof glyphname); + + printf ("U+%04X,U+%04X %s\n", vs, u, glyphname); + } + } + + hb_set_destroy (vars); + hb_set_destroy (unicodes); + } + + void + _list_glyphs (hb_font_t *font) + { + hb_face_t *face = hb_font_get_face (font); + + unsigned num_glyphs = hb_face_get_glyph_count (face); + + for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++) + { + char glyphname[64]; + hb_font_glyph_to_string (font, gid, + glyphname, sizeof glyphname); + + printf ("%u %s\n", gid, glyphname); + } + } + + void + _list_features (hb_face_t *face) + { + hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; + auto language = hb_language_get_default (); + hb_set_t *features = hb_set_create (); + + for (unsigned int i = 0; table_tags[i]; i++) + { + printf ("Table: %c%c%c%c\n", HB_UNTAG (table_tags[i])); + + hb_tag_t script_array[32]; + unsigned script_count = sizeof script_array / sizeof script_array[0]; + unsigned script_offset = 0; + do + { + hb_ot_layout_table_get_script_tags (face, table_tags[i], + script_offset, + &script_count, + script_array); + + for (unsigned script_index = 0; script_index < script_count; script_index++) + { + printf (" Script: %c%c%c%c\n", HB_UNTAG (script_array[script_index])); + + hb_tag_t language_array[32]; + unsigned language_count = sizeof language_array / sizeof language_array[0]; + unsigned language_offset = 0; + do + { + hb_ot_layout_script_get_language_tags (face, table_tags[i], + script_offset + script_index, + language_offset, + &language_count, + language_array); + + for (unsigned language_index = 0; language_index < language_count; language_index++) + { + printf (" Language: %c%c%c%c\n", HB_UNTAG (language_array[language_index])); + } + + language_offset += language_count; + } + while (language_count == sizeof language_array / sizeof language_array[0]); + } + + script_offset += script_count; + } + while (script_count == sizeof script_array / sizeof script_array[0]); + + hb_set_clear (features); + hb_tag_t feature_array[32]; + unsigned feature_count = sizeof feature_array / sizeof feature_array[0]; + unsigned feature_offset = 0; + do + { + hb_ot_layout_table_get_feature_tags (face, table_tags[i], + feature_offset, + &feature_count, + feature_array); + + for (unsigned feature_index = 0; feature_index < feature_count; feature_index++) + { + if (hb_set_has (features, feature_array[feature_index])) + continue; + hb_set_add (features, feature_array[feature_index]); + + hb_ot_name_id_t label_id; + + hb_ot_layout_feature_get_name_ids (face, + table_tags[i], + feature_offset + feature_index, + &label_id, + nullptr, + nullptr, + nullptr, + nullptr); + + char name[64]; + unsigned name_len = sizeof name; + + hb_ot_name_get_utf8 (face, label_id, + language, + &name_len, name); + + printf (" Feature: %c%c%c%c", HB_UNTAG (feature_array[feature_index])); + + if (*name) + printf (" \"%s\"", name); + + printf ("\n"); + } + + feature_offset += feature_count; + } + while (feature_count == sizeof feature_array / sizeof feature_array[0]); + } + + hb_set_destroy (features); + } + +#ifndef HB_NO_VAR + void + _list_variations (hb_face_t *face) + { + hb_ot_var_axis_info_t *axes; + + unsigned count = hb_ot_var_get_axis_infos (face, 0, nullptr, nullptr); + axes = (hb_ot_var_axis_info_t *) calloc (count, sizeof (hb_ot_var_axis_info_t)); + hb_ot_var_get_axis_infos (face, 0, &count, axes); + + auto language = hb_language_get_default (); + bool has_hidden = false; + + printf ("Varitation axes:\n"); + printf ("Tag: Minimum Default Maximum Name\n\n"); + for (unsigned i = 0; i < count; i++) + { + const auto &axis = axes[i]; + if (axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN) + has_hidden = true; + + char name[64]; + unsigned name_len = sizeof name; + + hb_ot_name_get_utf8 (face, axis.name_id, + language, + &name_len, name); + + printf ("%c%c%c%c%s: %g %g %g %s\n", + HB_UNTAG (axis.tag), + axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN ? "*" : "", + (double) axis.min_value, + (double) axis.default_value, + (double) axis.max_value, + name); + } + if (has_hidden) + printf ("\n[*] Hidden axis\n"); + + free (axes); + axes = nullptr; + + count = hb_ot_var_get_named_instance_count (face); + if (count) + { + printf ("\n\nNamed instances: \n\n"); + + for (unsigned i = 0; i < count; i++) + { + char name[64]; + unsigned name_len = sizeof name; + + hb_ot_name_id_t name_id = hb_ot_var_named_instance_get_subfamily_name_id (face, i); + hb_ot_name_get_utf8 (face, name_id, + language, + &name_len, name); + + unsigned coords_count = hb_ot_var_named_instance_get_design_coords (face, i, nullptr, nullptr); + float* coords; + coords = (float *) calloc (coords_count, sizeof (float)); + hb_ot_var_named_instance_get_design_coords (face, i, &coords_count, coords); + + printf ("%u. %-32s", i, name); + for (unsigned j = 0; j < coords_count; j++) + printf ("%g, ", (double) coords[j]); + printf ("\n"); + + free (coords); + } + } + } +#endif }; @@ -56,7 +370,7 @@ struct main_font_t : add_options (); parse (&argc, &argv); - consumer_t::operator () (); + consumer_t::operator () (this); return 0; } From dc717ced8d378aa455a3ca749b8b932bf2b53b97 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 13:16:34 -0700 Subject: [PATCH 03/33] [hb-info] Simplify --- util/hb-info.cc | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 8f9bb7a35..03ee8e11d 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -57,18 +57,23 @@ struct info_t } private: - hb_bool_t list_all; - hb_bool_t list_tables; - hb_bool_t list_unicodes; - hb_bool_t list_glyphs; - hb_bool_t list_features; + hb_face_t *face = nullptr; + hb_font_t *font = nullptr; + hb_bool_t list_all = false; + hb_bool_t list_tables = false; + hb_bool_t list_unicodes = false; + hb_bool_t list_glyphs = false; + hb_bool_t list_features = false; #ifndef HB_NO_VAR - hb_bool_t list_variations; + hb_bool_t list_variations = false; #endif public: void operator () (font_options_t *font_opts) { + face = hb_face_reference (font_opts->face); + font = hb_font_reference (font_opts->font); + if (list_all) { list_tables = @@ -81,16 +86,21 @@ struct info_t true; } - if (list_tables) _list_tables (font_opts->face); - if (list_unicodes) _list_unicodes (font_opts->font); - if (list_glyphs) _list_glyphs (font_opts->font); - if (list_features) _list_features (font_opts->face); + if (list_tables) _list_tables (); + if (list_unicodes) _list_unicodes (); + if (list_glyphs) _list_glyphs (); + if (list_features) _list_features (); #ifndef HB_NO_VAR - if (list_variations) _list_variations (font_opts->face); + if (list_variations) _list_variations (); #endif + + hb_font_destroy (font); + hb_face_destroy (face); } - void _list_tables (hb_face_t *face) + private: + + void _list_tables () { unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t)); @@ -111,7 +121,7 @@ struct info_t } void - _list_unicodes (hb_font_t *font) + _list_unicodes () { hb_face_t *face = hb_font_get_face (font); @@ -166,7 +176,7 @@ struct info_t } void - _list_glyphs (hb_font_t *font) + _list_glyphs () { hb_face_t *face = hb_font_get_face (font); @@ -183,7 +193,7 @@ struct info_t } void - _list_features (hb_face_t *face) + _list_features () { hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; auto language = hb_language_get_default (); @@ -285,7 +295,7 @@ struct info_t #ifndef HB_NO_VAR void - _list_variations (hb_face_t *face) + _list_variations () { hb_ot_var_axis_info_t *axes; From f514f697246bd9a19429c5e42038532b48bbab4f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 13:35:15 -0700 Subject: [PATCH 04/33] [hb-info] Add --quiet --- util/hb-info.cc | 60 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 03ee8e11d..d49d60410 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -56,9 +56,12 @@ struct info_t false /* We add below. */); } - private: + protected: hb_face_t *face = nullptr; hb_font_t *font = nullptr; + + hb_bool_t verbose = true; + hb_bool_t list_all = false; hb_bool_t list_tables = false; hb_bool_t list_unicodes = false; @@ -67,12 +70,15 @@ struct info_t #ifndef HB_NO_VAR hb_bool_t list_variations = false; #endif + public: - void operator () (font_options_t *font_opts) + template + void operator () (app_t *app) { - face = hb_face_reference (font_opts->face); - font = hb_font_reference (font_opts->font); + face = hb_face_reference (((font_options_t *) app)->face); + font = hb_font_reference (((font_options_t *) app)->font); + verbose = !app->quiet; if (list_all) { @@ -98,10 +104,16 @@ struct info_t hb_face_destroy (face); } - private: + protected: void _list_tables () { + if (verbose) + { + printf ("\nFont table information:"); + printf ("\nTag Size\n"); + } + unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t)); hb_face_get_table_tags (face, 0, &count, tags); @@ -123,6 +135,12 @@ struct info_t void _list_unicodes () { + if (verbose) + { + printf ("\nCharacter-set information:"); + printf ("\nUnicode Glyph name\n"); + } + hb_face_t *face = hb_font_get_face (font); hb_set_t *unicodes = hb_set_create (); @@ -178,6 +196,12 @@ struct info_t void _list_glyphs () { + if (verbose) + { + printf ("\nGlyph-set information:"); + printf ("\nGlyphID Glyph name\n"); + } + hb_face_t *face = hb_font_get_face (font); unsigned num_glyphs = hb_face_get_glyph_count (face); @@ -195,6 +219,11 @@ struct info_t void _list_features () { + if (verbose) + { + printf ("\nLayout features information:\n"); + } + hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; auto language = hb_language_get_default (); hb_set_t *features = hb_set_create (); @@ -297,6 +326,11 @@ struct info_t void _list_variations () { + if (verbose) + { + printf ("\nFace variations information:\n"); + } + hb_ot_var_axis_info_t *axes; unsigned count = hb_ot_var_get_axis_infos (face, 0, nullptr, nullptr); @@ -306,8 +340,11 @@ struct info_t auto language = hb_language_get_default (); bool has_hidden = false; - printf ("Varitation axes:\n"); - printf ("Tag: Minimum Default Maximum Name\n\n"); + if (verbose && count) + { + printf ("Varitation axes:\n"); + printf ("Tag: Minimum Default Maximum Name\n\n"); + } for (unsigned i = 0; i < count; i++) { const auto &axis = axes[i]; @@ -338,7 +375,10 @@ struct info_t count = hb_ot_var_get_named_instance_count (face); if (count) { - printf ("\n\nNamed instances: \n\n"); + if (verbose) + { + printf ("\n\nNamed instances: \n\n"); + } for (unsigned i = 0; i < count; i++) { @@ -394,6 +434,7 @@ struct main_font_t : GOptionEntry entries[] = { + {"quiet", 'q', 0, G_OPTION_ARG_NONE, &this->quiet, "Generate machine-readable output", nullptr}, {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_CALLBACK, (gpointer) &collect_rest, nullptr, "[FONT-FILE]"}, {nullptr} @@ -422,6 +463,9 @@ struct main_font_t : "Too many arguments on the command line"); return false; } + + public: + hb_bool_t quiet = false; }; int From 8921f593f953947760ab97bd844b20b0c9edc1be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 13:49:22 -0700 Subject: [PATCH 05/33] [hb-info] Print "---" separator --- util/hb-info.cc | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index d49d60410..ce467eaf0 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -61,6 +61,7 @@ struct info_t hb_font_t *font = nullptr; hb_bool_t verbose = true; + hb_bool_t first_item = true; hb_bool_t list_all = false; hb_bool_t list_tables = false; @@ -106,12 +107,23 @@ struct info_t protected: + void separator () + { + if (first_item) + { + first_item = false; + return; + } + printf ("\n---\n\n"); + } + void _list_tables () { if (verbose) { - printf ("\nFont table information:"); - printf ("\nTag Size\n"); + separator (); + printf ("Font table information:\n\n"); + printf ("Tag Size\n\n"); } unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); @@ -137,8 +149,9 @@ struct info_t { if (verbose) { - printf ("\nCharacter-set information:"); - printf ("\nUnicode Glyph name\n"); + separator (); + printf ("Character-set information:\n\n"); + printf ("Unicode Glyph name\n\n"); } hb_face_t *face = hb_font_get_face (font); @@ -198,8 +211,9 @@ struct info_t { if (verbose) { - printf ("\nGlyph-set information:"); - printf ("\nGlyphID Glyph name\n"); + separator (); + printf ("Glyph-set information:\n\n"); + printf ("GlyphID Glyph name\n\n"); } hb_face_t *face = hb_font_get_face (font); @@ -221,7 +235,8 @@ struct info_t { if (verbose) { - printf ("\nLayout features information:\n"); + separator (); + printf ("Layout features information:\n\n"); } hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; @@ -328,7 +343,8 @@ struct info_t { if (verbose) { - printf ("\nFace variations information:\n"); + separator (); + printf ("Face variations information:\n\n"); } hb_ot_var_axis_info_t *axes; @@ -342,7 +358,7 @@ struct info_t if (verbose && count) { - printf ("Varitation axes:\n"); + printf ("Varitation axes:\n\n"); printf ("Tag: Minimum Default Maximum Name\n\n"); } for (unsigned i = 0; i < count; i++) @@ -367,7 +383,7 @@ struct info_t name); } if (has_hidden) - printf ("\n[*] Hidden axis\n"); + printf ("\n[*] Hidden axis\n\n"); free (axes); axes = nullptr; @@ -377,7 +393,7 @@ struct info_t { if (verbose) { - printf ("\n\nNamed instances: \n\n"); + printf ("Named instances:\n\n"); } for (unsigned i = 0; i < count; i++) From 9a94c06052e6dd6e752aaac7ce5924f205b73072 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 13:56:36 -0700 Subject: [PATCH 06/33] [hb-info] Minor we have face available --- util/hb-info.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index ce467eaf0..109a2a893 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -154,8 +154,6 @@ struct info_t printf ("Unicode Glyph name\n\n"); } - hb_face_t *face = hb_font_get_face (font); - hb_set_t *unicodes = hb_set_create (); hb_map_t *cmap = hb_map_create (); @@ -216,8 +214,6 @@ struct info_t printf ("GlyphID Glyph name\n\n"); } - hb_face_t *face = hb_font_get_face (font); - unsigned num_glyphs = hb_face_get_glyph_count (face); for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++) From 9ca2f86fe0807c7abf8e967130734be76a25f52d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:04:37 -0700 Subject: [PATCH 07/33] [hb-info] Minor verbose print --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 109a2a893..de51f9968 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -378,7 +378,7 @@ struct info_t (double) axis.max_value, name); } - if (has_hidden) + if (verbose && has_hidden) printf ("\n[*] Hidden axis\n\n"); free (axes); From aee7454d05256b206a4aa5892d9ca6211c7d3189 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:09:45 -0700 Subject: [PATCH 08/33] [hb-info] Add --list-scripts --- util/hb-info.cc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index de51f9968..1c280996a 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -42,6 +42,7 @@ struct info_t {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, + {"list-scripts", 0, 0, G_OPTION_ARG_NONE, &this->list_scripts, "List layout scripts", nullptr}, {"list-features", 0, 0, G_OPTION_ARG_NONE, &this->list_features, "List layout features", nullptr}, #ifndef HB_NO_VAR {"list-variations",0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List variations", nullptr}, @@ -67,6 +68,7 @@ struct info_t hb_bool_t list_tables = false; hb_bool_t list_unicodes = false; hb_bool_t list_glyphs = false; + hb_bool_t list_scripts = false; hb_bool_t list_features = false; #ifndef HB_NO_VAR hb_bool_t list_variations = false; @@ -86,6 +88,7 @@ struct info_t list_tables = list_unicodes = list_glyphs = + list_scripts = list_features = #ifndef HB_NO_VAR list_variations = @@ -96,6 +99,7 @@ struct info_t if (list_tables) _list_tables (); if (list_unicodes) _list_unicodes (); if (list_glyphs) _list_glyphs (); + if (list_scripts) _list_scripts (); if (list_features) _list_features (); #ifndef HB_NO_VAR if (list_variations) _list_variations (); @@ -227,17 +231,15 @@ struct info_t } void - _list_features () + _list_scripts () { if (verbose) { separator (); - printf ("Layout features information:\n\n"); + printf ("Layout script information:\n\n"); } hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; - auto language = hb_language_get_default (); - hb_set_t *features = hb_set_create (); for (unsigned int i = 0; table_tags[i]; i++) { @@ -282,6 +284,27 @@ struct info_t } while (script_count == sizeof script_array / sizeof script_array[0]); + } + + } + + void + _list_features () + { + if (verbose) + { + separator (); + printf ("Layout features information:\n\n"); + } + + hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; + auto language = hb_language_get_default (); + hb_set_t *features = hb_set_create (); + + for (unsigned int i = 0; table_tags[i]; i++) + { + printf ("Table: %c%c%c%c\n", HB_UNTAG (table_tags[i])); + hb_set_clear (features); hb_tag_t feature_array[32]; unsigned feature_count = sizeof feature_array / sizeof feature_array[0]; From 38c71cebd070ee0e1e25836ab1fb485bebfd066e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:19:05 -0700 Subject: [PATCH 09/33] [hb-info] Add --show-upem --show-all --all --- util/hb-info.cc | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 1c280996a..6ab7cc463 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -38,7 +38,12 @@ struct info_t { GOptionEntry entries[] = { - {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List everything", nullptr}, + {"all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show everything", nullptr}, + + {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, + {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "List everything", nullptr}, + + {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long list", nullptr}, {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, @@ -64,6 +69,11 @@ struct info_t hb_bool_t verbose = true; hb_bool_t first_item = true; + hb_bool_t all = false; + + hb_bool_t show_all = false; + hb_bool_t show_upem = false; + hb_bool_t list_all = false; hb_bool_t list_tables = false; hb_bool_t list_unicodes = false; @@ -83,6 +93,19 @@ struct info_t font = hb_font_reference (((font_options_t *) app)->font); verbose = !app->quiet; + if (all) + { + show_all = + list_all = + true; + } + + if (show_all) + { + show_upem = + true; + } + if (list_all) { list_tables = @@ -96,6 +119,8 @@ struct info_t true; } + if (show_upem) _show_upem (); + if (list_tables) _list_tables (); if (list_unicodes) _list_unicodes (); if (list_glyphs) _list_glyphs (); @@ -121,6 +146,17 @@ struct info_t printf ("\n---\n\n"); } + void _show_upem () + { + if (verbose) + { + separator (); + printf ("Font Units-Per-EM: "); + } + + printf ("%u\n", hb_face_get_upem (face)); + } + void _list_tables () { if (verbose) From fd20a7e143e2e2dfa4c13ab255570200510cd508 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:23:36 -0700 Subject: [PATCH 10/33] [hb-info] Add --show-glyph-count --- util/hb-info.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 6ab7cc463..9d31de5f0 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -38,10 +38,11 @@ struct info_t { GOptionEntry entries[] = { - {"all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show everything", nullptr}, + {"all", 0, 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, - {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "List everything", nullptr}, + {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, + {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long list", nullptr}, {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, @@ -73,6 +74,7 @@ struct info_t hb_bool_t show_all = false; hb_bool_t show_upem = false; + hb_bool_t show_glyph_count = false; hb_bool_t list_all = false; hb_bool_t list_tables = false; @@ -98,11 +100,13 @@ struct info_t show_all = list_all = true; + first_item = false; } if (show_all) { show_upem = + show_glyph_count = true; } @@ -120,6 +124,7 @@ struct info_t } if (show_upem) _show_upem (); + if (show_glyph_count) _show_glyph_count (); if (list_tables) _list_tables (); if (list_unicodes) _list_unicodes (); @@ -150,13 +155,22 @@ struct info_t { if (verbose) { - separator (); - printf ("Font Units-Per-EM: "); + printf ("Units-Per-EM: "); } printf ("%u\n", hb_face_get_upem (face)); } + void _show_glyph_count () + { + if (verbose) + { + printf ("Glyph count: "); + } + + printf ("%u\n", hb_face_get_glyph_count (face)); + } + void _list_tables () { if (verbose) From 3189b614b1d3ac3343c17b1b67acadb8d4f4e6e1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:24:26 -0700 Subject: [PATCH 11/33] [hb-info] Format --- util/hb-info.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 9d31de5f0..425e08a47 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -428,7 +428,7 @@ struct info_t if (verbose && count) { printf ("Varitation axes:\n\n"); - printf ("Tag: Minimum Default Maximum Name\n\n"); + printf ("Tag: Minimum Default Maximum Name\n"); } for (unsigned i = 0; i < count; i++) { @@ -462,7 +462,7 @@ struct info_t { if (verbose) { - printf ("Named instances:\n\n"); + printf ("\nNamed instances:\n\n"); } for (unsigned i = 0; i < count; i++) From b215f6a84f38725a628248ea25cbb88e57f2c464 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:31:45 -0700 Subject: [PATCH 12/33] [hb-info] Add --show-unicode-count --- util/hb-info.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index 425e08a47..e1b1120d6 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -42,6 +42,7 @@ struct info_t {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, + {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long list", nullptr}, @@ -74,6 +75,7 @@ struct info_t hb_bool_t show_all = false; hb_bool_t show_upem = false; + hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; hb_bool_t list_all = false; @@ -106,6 +108,7 @@ struct info_t if (show_all) { show_upem = + show_unicode_count = show_glyph_count = true; } @@ -124,6 +127,7 @@ struct info_t } if (show_upem) _show_upem (); + if (show_unicode_count) _show_unicode_count (); if (show_glyph_count) _show_glyph_count (); if (list_tables) _list_tables (); @@ -161,6 +165,21 @@ struct info_t printf ("%u\n", hb_face_get_upem (face)); } + void _show_unicode_count () + { + if (verbose) + { + printf ("Unicode count: "); + } + + hb_set_t *unicodes = hb_set_create (); + hb_face_collect_unicodes (face, unicodes); + + printf ("%u\n", hb_set_get_population (unicodes)); + + hb_set_destroy (unicodes); + } + void _show_glyph_count () { if (verbose) From e5a07c883c90ad8c0108c967f664e7468b4ca14a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:34:32 -0700 Subject: [PATCH 13/33] [hb-info] --help format --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index e1b1120d6..4bbd6ec05 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -45,7 +45,7 @@ struct info_t {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, - {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long list", nullptr}, + {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, From 1eca2c88a29c2a29c6f7687c79f567598ecae869 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:38:12 -0700 Subject: [PATCH 14/33] [hb-info] Add a few short option forms --- util/hb-info.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 4bbd6ec05..e090af133 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -38,14 +38,14 @@ struct info_t { GOptionEntry entries[] = { - {"all", 0, 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, + {"all", 'a', 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, - {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, + {"show-all", 's', 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, - {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, + {"list-all", 'l', 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, From c1679e02662d1589dfcdc8802a8ae7889807405b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:41:13 -0700 Subject: [PATCH 15/33] [hb-info] Default to --show-all --- util/hb-info.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index e090af133..a7198092c 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -522,6 +522,10 @@ struct main_font_t : int operator () (int argc, char **argv) { add_options (); + + if (argc == 2) + consumer_t::show_all = true; + parse (&argc, &argv); consumer_t::operator () (this); From 972e3b76da8330faec20883f978c40d701908d98 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:42:18 -0700 Subject: [PATCH 16/33] [hb-info] Minor formatting --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index a7198092c..dbfffb8db 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -102,7 +102,6 @@ struct info_t show_all = list_all = true; - first_item = false; } if (show_all) @@ -111,6 +110,7 @@ struct info_t show_unicode_count = show_glyph_count = true; + first_item = false; } if (list_all) From 67c9845301a317dae5a33ba0de003ec060427ee4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:45:04 -0700 Subject: [PATCH 17/33] [hb-info] Make -l list tables ala ttx --- util/hb-info.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index dbfffb8db..f09db5632 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -40,13 +40,13 @@ struct info_t { {"all", 'a', 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, - {"show-all", 's', 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, + {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, - {"list-all", 'l', 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, - {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, + {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, + {"list-tables", 'l', 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, {"list-scripts", 0, 0, G_OPTION_ARG_NONE, &this->list_scripts, "List layout scripts", nullptr}, From 5b05edd221d85b9d6c83dfc2d8e0aa32781b8b1f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:57:30 -0700 Subject: [PATCH 18/33] [hb-info] Add --list-names --- util/hb-info.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index f09db5632..261159bd1 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -46,6 +46,7 @@ struct info_t {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, + {"list-names", 'l', 0, G_OPTION_ARG_NONE, &this->list_names, "List names", nullptr}, {"list-tables", 'l', 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, @@ -79,6 +80,7 @@ struct info_t hb_bool_t show_glyph_count = false; hb_bool_t list_all = false; + hb_bool_t list_names = false; hb_bool_t list_tables = false; hb_bool_t list_unicodes = false; hb_bool_t list_glyphs = false; @@ -115,6 +117,7 @@ struct info_t if (list_all) { + list_names = list_tables = list_unicodes = list_glyphs = @@ -130,6 +133,7 @@ struct info_t if (show_unicode_count) _show_unicode_count (); if (show_glyph_count) _show_glyph_count (); + if (list_names) _list_names (); if (list_tables) _list_tables (); if (list_unicodes) _list_unicodes (); if (list_glyphs) _list_glyphs (); @@ -190,12 +194,37 @@ struct info_t printf ("%u\n", hb_face_get_glyph_count (face)); } + void _list_names () + { + if (verbose) + { + separator (); + printf ("Name information:\n\n"); + printf ("Id Text\n\n"); + } + + auto language = hb_language_get_default (); + + unsigned count; + const auto *entries = hb_ot_name_list_names (face, &count); + for (unsigned i = 0; i < count; i++) + { + char name[128]; + unsigned name_len = sizeof name; + hb_ot_name_get_utf8 (face, entries[i].name_id, + language, + &name_len, name); + + printf ("%u %s\n", entries[i].name_id, name); + } + } + void _list_tables () { if (verbose) { separator (); - printf ("Font table information:\n\n"); + printf ("Table information:\n\n"); printf ("Tag Size\n\n"); } From f25c03162b2b6132199712bdd165faee0075b2f6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 14:57:45 -0700 Subject: [PATCH 19/33] [hb-info] Change separator to === --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 261159bd1..b1724c7b8 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -156,7 +156,7 @@ struct info_t first_item = false; return; } - printf ("\n---\n\n"); + printf ("\n===\n\n"); } void _show_upem () From fecb2eeca0120e4cf9d06f3164e38d4daa983bd0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:05:00 -0700 Subject: [PATCH 20/33] [hb-info] Add --show-family --- util/hb-info.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index b1724c7b8..4917b446b 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -41,6 +41,7 @@ struct info_t {"all", 'a', 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, + {"show-family", 0, 0, G_OPTION_ARG_NONE, &this->show_family, "Show family name", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, @@ -75,6 +76,7 @@ struct info_t hb_bool_t all = false; hb_bool_t show_all = false; + hb_bool_t show_family = false; hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; @@ -108,6 +110,7 @@ struct info_t if (show_all) { + show_family = show_upem = show_unicode_count = show_glyph_count = @@ -129,6 +132,7 @@ struct info_t true; } + if (show_family) _show_family (); if (show_upem) _show_upem (); if (show_unicode_count) _show_unicode_count (); if (show_glyph_count) _show_glyph_count (); @@ -159,6 +163,29 @@ struct info_t printf ("\n===\n\n"); } + void _show_name (const char *label, hb_ot_name_id_t name_id) + { + if (verbose) + { + printf ("%s: ", label); + } + + auto language = hb_language_get_default (); + + char name[128]; + unsigned name_len = sizeof name; + hb_ot_name_get_utf8 (face, name_id, + language, + &name_len, name); + + printf ("%s\n", name); + } + + void _show_family () + { + _show_name ("Family", 1); + } + void _show_upem () { if (verbose) From 2d9ba17a535d2c466dce1f09064dfba73a92e387 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:06:21 -0700 Subject: [PATCH 21/33] [hb-info] Add --show-style --- util/hb-info.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index 4917b446b..0dab2593a 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -42,6 +42,7 @@ struct info_t {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, {"show-family", 0, 0, G_OPTION_ARG_NONE, &this->show_family, "Show family name", nullptr}, + {"show-style", 0, 0, G_OPTION_ARG_NONE, &this->show_style, "Show style name", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, @@ -77,6 +78,7 @@ struct info_t hb_bool_t show_all = false; hb_bool_t show_family = false; + hb_bool_t show_style = false; hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; @@ -111,6 +113,7 @@ struct info_t if (show_all) { show_family = + show_style = show_upem = show_unicode_count = show_glyph_count = @@ -133,6 +136,7 @@ struct info_t } if (show_family) _show_family (); + if (show_style) _show_style (); if (show_upem) _show_upem (); if (show_unicode_count) _show_unicode_count (); if (show_glyph_count) _show_glyph_count (); @@ -186,6 +190,11 @@ struct info_t _show_name ("Family", 1); } + void _show_style () + { + _show_name ("Style", 2); + } + void _show_upem () { if (verbose) From 21151401219a4f6b4a907f14b783bc61d397136f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:10:00 -0700 Subject: [PATCH 22/33] [hb-info] Add --show-unique-name and --show-full-name --- util/hb-info.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 0dab2593a..f9ca77757 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -43,6 +43,8 @@ struct info_t {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, {"show-family", 0, 0, G_OPTION_ARG_NONE, &this->show_family, "Show family name", nullptr}, {"show-style", 0, 0, G_OPTION_ARG_NONE, &this->show_style, "Show style name", nullptr}, + {"show-unique-name",0, 0, G_OPTION_ARG_NONE, &this->show_unique_name, "Show unique name", nullptr}, + {"show-full-name",0, 0, G_OPTION_ARG_NONE, &this->show_full_name, "Show full name", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, @@ -79,6 +81,8 @@ struct info_t hb_bool_t show_all = false; hb_bool_t show_family = false; hb_bool_t show_style = false; + hb_bool_t show_unique_name = false; + hb_bool_t show_full_name = false; hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; @@ -114,6 +118,8 @@ struct info_t { show_family = show_style = + show_unique_name = + show_full_name = show_upem = show_unicode_count = show_glyph_count = @@ -137,6 +143,8 @@ struct info_t if (show_family) _show_family (); if (show_style) _show_style (); + if (show_unique_name) _show_unique_name (); + if (show_full_name) _show_full_name (); if (show_upem) _show_upem (); if (show_unicode_count) _show_unicode_count (); if (show_glyph_count) _show_glyph_count (); @@ -184,16 +192,10 @@ struct info_t printf ("%s\n", name); } - - void _show_family () - { - _show_name ("Family", 1); - } - - void _show_style () - { - _show_name ("Style", 2); - } + void _show_family () { _show_name ("Family", 1); } + void _show_style () { _show_name ("Style", 2); } + void _show_unique_name () { _show_name ("Unique name", 3); } + void _show_full_name () { _show_name ("Full name", 4); } void _show_upem () { From 7af0624bdf9d2c8d712eacb5dd46787deeb5cfd6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:11:55 -0700 Subject: [PATCH 23/33] [hb-info] Remove unintended short option --- util/hb-info.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index f9ca77757..bb7e0a3b2 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -50,8 +50,8 @@ struct info_t {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, - {"list-names", 'l', 0, G_OPTION_ARG_NONE, &this->list_names, "List names", nullptr}, - {"list-tables", 'l', 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, + {"list-names", 0, 0, G_OPTION_ARG_NONE, &this->list_names, "List names", nullptr}, + {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, {"list-scripts", 0, 0, G_OPTION_ARG_NONE, &this->list_scripts, "List layout scripts", nullptr}, From d7cf69ede2fe9ad7f1eb9559a4f8638b11c550f2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:15:56 -0700 Subject: [PATCH 24/33] [hb-info] Format --- util/hb-info.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index bb7e0a3b2..7ee6e1edd 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -238,7 +238,7 @@ struct info_t { separator (); printf ("Name information:\n\n"); - printf ("Id Text\n\n"); + printf ("Id Text\n------------\n"); } auto language = hb_language_get_default (); @@ -263,7 +263,7 @@ struct info_t { separator (); printf ("Table information:\n\n"); - printf ("Tag Size\n\n"); + printf ("Tag Size\n------------\n"); } unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr); @@ -291,7 +291,7 @@ struct info_t { separator (); printf ("Character-set information:\n\n"); - printf ("Unicode Glyph name\n\n"); + printf ("Unicode Glyph name\n------------------\n"); } hb_set_t *unicodes = hb_set_create (); @@ -351,7 +351,7 @@ struct info_t { separator (); printf ("Glyph-set information:\n\n"); - printf ("GlyphID Glyph name\n\n"); + printf ("GlyphID Glyph name\n------------------\n"); } unsigned num_glyphs = hb_face_get_glyph_count (face); @@ -514,7 +514,7 @@ struct info_t if (verbose && count) { printf ("Varitation axes:\n\n"); - printf ("Tag: Minimum Default Maximum Name\n"); + printf ("Tag Minimum Default Maximum Name\n------------------------------------\n"); } for (unsigned i = 0; i < count; i++) { @@ -529,7 +529,7 @@ struct info_t language, &name_len, name); - printf ("%c%c%c%c%s: %g %g %g %s\n", + printf ("%c%c%c%c%s %g %g %g %s\n", HB_UNTAG (axis.tag), axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN ? "*" : "", (double) axis.min_value, From 9395bbaa6710ad3b7c8415340d068c467cc31f8f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:17:33 -0700 Subject: [PATCH 25/33] [hb-info] Format --- util/hb-info.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 7ee6e1edd..6ffd6e184 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -514,7 +514,7 @@ struct info_t if (verbose && count) { printf ("Varitation axes:\n\n"); - printf ("Tag Minimum Default Maximum Name\n------------------------------------\n"); + printf ("Tag Minimum Default Maximum Name\n------------------------------------\n"); } for (unsigned i = 0; i < count; i++) { @@ -549,6 +549,7 @@ struct info_t if (verbose) { printf ("\nNamed instances:\n\n"); + printf ("Index Name Position\n------------------------------------------------\n"); } for (unsigned i = 0; i < count; i++) @@ -566,7 +567,7 @@ struct info_t coords = (float *) calloc (coords_count, sizeof (float)); hb_ot_var_named_instance_get_design_coords (face, i, &coords_count, coords); - printf ("%u. %-32s", i, name); + printf ("%u %-32s", i, name); for (unsigned j = 0; j < coords_count; j++) printf ("%g, ", (double) coords[j]); printf ("\n"); From dec320a4630a1d71f94d6e81ea95b5c855dfe01a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:18:06 -0700 Subject: [PATCH 26/33] [hb-info] Put back -l for --list-tables --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 6ffd6e184..27af87fd7 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -51,7 +51,7 @@ struct info_t {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, {"list-names", 0, 0, G_OPTION_ARG_NONE, &this->list_names, "List names", nullptr}, - {"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, + {"list-tables", 'l', 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr}, {"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr}, {"list-scripts", 0, 0, G_OPTION_ARG_NONE, &this->list_scripts, "List layout scripts", nullptr}, From 895d3f9e3e146e0f185000962f0897c1fc693dac Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:24:32 -0700 Subject: [PATCH 27/33] [hb-info] Mark --show-all as default --- util/hb-info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 27af87fd7..9ffd87cfb 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -40,7 +40,7 @@ struct info_t { {"all", 'a', 0, G_OPTION_ARG_NONE, &this->all, "Show everything", nullptr}, - {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information", nullptr}, + {"show-all", 0, 0, G_OPTION_ARG_NONE, &this->show_all, "Show all short information (default)", nullptr}, {"show-family", 0, 0, G_OPTION_ARG_NONE, &this->show_family, "Show family name", nullptr}, {"show-style", 0, 0, G_OPTION_ARG_NONE, &this->show_style, "Show style name", nullptr}, {"show-unique-name",0, 0, G_OPTION_ARG_NONE, &this->show_unique_name, "Show unique name", nullptr}, From 3c734f4479068c0b9a6a768ff55d9ecd0d73d6f7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:27:13 -0700 Subject: [PATCH 28/33] [hb-info] Add --show-postscript-name --- util/hb-info.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 9ffd87cfb..26dd64982 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -45,6 +45,7 @@ struct info_t {"show-style", 0, 0, G_OPTION_ARG_NONE, &this->show_style, "Show style name", nullptr}, {"show-unique-name",0, 0, G_OPTION_ARG_NONE, &this->show_unique_name, "Show unique name", nullptr}, {"show-full-name",0, 0, G_OPTION_ARG_NONE, &this->show_full_name, "Show full name", nullptr}, + {"show-postscript-name",0, 0, G_OPTION_ARG_NONE, &this->show_postscript_name, "Show Postscript name", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, @@ -83,6 +84,7 @@ struct info_t hb_bool_t show_style = false; hb_bool_t show_unique_name = false; hb_bool_t show_full_name = false; + hb_bool_t show_postscript_name = false; hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; @@ -120,6 +122,7 @@ struct info_t show_style = show_unique_name = show_full_name = + show_postscript_name = show_upem = show_unicode_count = show_glyph_count = @@ -145,8 +148,9 @@ struct info_t if (show_style) _show_style (); if (show_unique_name) _show_unique_name (); if (show_full_name) _show_full_name (); + if (show_postscript_name)_show_postscript_name (); if (show_upem) _show_upem (); - if (show_unicode_count) _show_unicode_count (); + if (show_unicode_count)_show_unicode_count (); if (show_glyph_count) _show_glyph_count (); if (list_names) _list_names (); @@ -196,6 +200,7 @@ struct info_t void _show_style () { _show_name ("Style", 2); } void _show_unique_name () { _show_name ("Unique name", 3); } void _show_full_name () { _show_name ("Full name", 4); } + void _show_postscript_name () { _show_name ("Postscript name", 6); } void _show_upem () { From 5540367ee2e0be55b782bb6ff33df48613c4d904 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:30:27 -0700 Subject: [PATCH 29/33] [hb-info] Add --show-version --- util/hb-info.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index 26dd64982..35077f87e 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -46,6 +46,7 @@ struct info_t {"show-unique-name",0, 0, G_OPTION_ARG_NONE, &this->show_unique_name, "Show unique name", nullptr}, {"show-full-name",0, 0, G_OPTION_ARG_NONE, &this->show_full_name, "Show full name", nullptr}, {"show-postscript-name",0, 0, G_OPTION_ARG_NONE, &this->show_postscript_name, "Show Postscript name", nullptr}, + {"show-version", 0, 0, G_OPTION_ARG_NONE, &this->show_version, "Show version", nullptr}, {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, @@ -85,6 +86,7 @@ struct info_t hb_bool_t show_unique_name = false; hb_bool_t show_full_name = false; hb_bool_t show_postscript_name = false; + hb_bool_t show_version = false; hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; @@ -123,6 +125,7 @@ struct info_t show_unique_name = show_full_name = show_postscript_name = + show_version = show_upem = show_unicode_count = show_glyph_count = @@ -149,6 +152,7 @@ struct info_t if (show_unique_name) _show_unique_name (); if (show_full_name) _show_full_name (); if (show_postscript_name)_show_postscript_name (); + if (show_version) _show_version (); if (show_upem) _show_upem (); if (show_unicode_count)_show_unicode_count (); if (show_glyph_count) _show_glyph_count (); @@ -201,6 +205,7 @@ struct info_t void _show_unique_name () { _show_name ("Unique name", 3); } void _show_full_name () { _show_name ("Full name", 4); } void _show_postscript_name () { _show_name ("Postscript name", 6); } + void _show_version () { _show_name ("Version", 5); } void _show_upem () { From 2a3903b37fbfdf49e56ba6a343f98b4f60a0196e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:34:14 -0700 Subject: [PATCH 30/33] [hb-info] TODO items --- util/hb-info.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 35077f87e..8f503c940 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -201,10 +201,10 @@ struct info_t printf ("%s\n", name); } void _show_family () { _show_name ("Family", 1); } - void _show_style () { _show_name ("Style", 2); } + void _show_style () { _show_name ("Style", 2); /* TODO Check named-instance. */ } void _show_unique_name () { _show_name ("Unique name", 3); } void _show_full_name () { _show_name ("Full name", 4); } - void _show_postscript_name () { _show_name ("Postscript name", 6); } + void _show_postscript_name () { _show_name ("Postscript name", 6); /* TODO Check named-instance. */ } void _show_version () { _show_name ("Version", 5); } void _show_upem () From 148ee3e0c73dd9c00988ad46b01fcd18ef5f5cc4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:41:13 -0700 Subject: [PATCH 31/33] [hb-info] Make --show-style and --show-postscript-name show named-instance --- util/hb-info.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 8f503c940..4c5b978c4 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -201,10 +201,29 @@ struct info_t printf ("%s\n", name); } void _show_family () { _show_name ("Family", 1); } - void _show_style () { _show_name ("Style", 2); /* TODO Check named-instance. */ } + void _show_style () + { + hb_ot_name_id_t name_id = 2; + + unsigned named_instance = hb_font_get_var_named_instance (font); + if (named_instance != HB_FONT_NO_VAR_NAMED_INSTANCE) + name_id = hb_ot_var_named_instance_get_subfamily_name_id (face, named_instance); + + _show_name ("Style", name_id); + } void _show_unique_name () { _show_name ("Unique name", 3); } void _show_full_name () { _show_name ("Full name", 4); } - void _show_postscript_name () { _show_name ("Postscript name", 6); /* TODO Check named-instance. */ } + void _show_postscript_name () + { + hb_ot_name_id_t name_id = 6; + + unsigned named_instance = hb_font_get_var_named_instance (font); + if (named_instance != HB_FONT_NO_VAR_NAMED_INSTANCE) + name_id = hb_ot_var_named_instance_get_postscript_name_id (face, named_instance); + + + _show_name ("Postscript name", name_id); + } void _show_version () { _show_name ("Version", 5); } void _show_upem () From 1302a88b25f38dfb0cf463ed0cbb3bb21811f590 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 15:51:46 -0700 Subject: [PATCH 32/33] [hb-info] Add --dump-table --- util/hb-info.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/util/hb-info.cc b/util/hb-info.cc index 4c5b978c4..95e29f3af 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -61,6 +61,9 @@ struct info_t #ifndef HB_NO_VAR {"list-variations",0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List variations", nullptr}, #endif + + {"dump-table", 0, 0, G_OPTION_ARG_STRING, &this->dump_table, "Dump font table", "TABLE-TAG"}, + {nullptr} }; parser->add_group (entries, @@ -102,6 +105,8 @@ struct info_t hb_bool_t list_variations = false; #endif + char *dump_table = nullptr; + public: template @@ -167,6 +172,8 @@ struct info_t if (list_variations) _list_variations (); #endif + if (dump_table) _dump_table (); + hb_font_destroy (font); hb_face_destroy (face); } @@ -606,6 +613,16 @@ struct info_t } } #endif + + void + _dump_table () + { + hb_blob_t *blob = hb_face_reference_table (face, hb_tag_from_string (dump_table, -1)); + unsigned count = 0; + const char *data = hb_blob_get_data (blob, &count); + fwrite (data, 1, count, stdout); + hb_blob_destroy (blob); + } }; From e52a23c5f8d25441bf164b4e63b28aae8082acfb Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Jan 2023 16:01:29 -0700 Subject: [PATCH 33/33] [hb-info] Add --show-extents --- util/hb-info.cc | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/util/hb-info.cc b/util/hb-info.cc index 95e29f3af..eddaead56 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -50,6 +50,7 @@ struct info_t {"show-upem", 0, 0, G_OPTION_ARG_NONE, &this->show_upem, "Show Units-Per-EM", nullptr}, {"show-unicode-count",0, 0, G_OPTION_ARG_NONE, &this->show_unicode_count, "Show Unicode count", nullptr}, {"show-glyph-count",0, 0, G_OPTION_ARG_NONE, &this->show_glyph_count, "Show glyph count", nullptr}, + {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Show extents", nullptr}, {"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List all long information", nullptr}, {"list-names", 0, 0, G_OPTION_ARG_NONE, &this->list_names, "List names", nullptr}, @@ -93,6 +94,7 @@ struct info_t hb_bool_t show_upem = false; hb_bool_t show_unicode_count = false; hb_bool_t show_glyph_count = false; + hb_bool_t show_extents = false; hb_bool_t list_all = false; hb_bool_t list_names = false; @@ -134,6 +136,7 @@ struct info_t show_upem = show_unicode_count = show_glyph_count = + show_extents = true; first_item = false; } @@ -161,6 +164,7 @@ struct info_t if (show_upem) _show_upem (); if (show_unicode_count)_show_unicode_count (); if (show_glyph_count) _show_glyph_count (); + if (show_extents) _show_extents (); if (list_names) _list_names (); if (list_tables) _list_tables (); @@ -197,7 +201,7 @@ struct info_t printf ("%s: ", label); } - auto language = hb_language_get_default (); + auto language = hb_language_get_default (); // TODO char name[128]; unsigned name_len = sizeof name; @@ -268,6 +272,23 @@ struct info_t printf ("%u\n", hb_face_get_glyph_count (face)); } + void _show_extents () + { + hb_direction_t direction = HB_DIRECTION_LTR; // TODO + + hb_font_extents_t extents; + hb_font_get_extents_for_direction (font, direction, &extents); + + if (verbose) printf ("Ascender: "); + printf ("%d\n", extents.ascender); + + if (verbose) printf ("Descender: "); + printf ("%d\n", extents.descender); + + if (verbose) printf ("Line gap: "); + printf ("%d\n", extents.line_gap); + } + void _list_names () { if (verbose) @@ -277,7 +298,7 @@ struct info_t printf ("Id Text\n------------\n"); } - auto language = hb_language_get_default (); + auto language = hb_language_get_default (); // TODO unsigned count; const auto *entries = hb_ot_name_list_names (face, &count); @@ -470,7 +491,7 @@ struct info_t } hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE}; - auto language = hb_language_get_default (); + auto language = hb_language_get_default (); // TODO hb_set_t *features = hb_set_create (); for (unsigned int i = 0; table_tags[i]; i++) @@ -544,7 +565,7 @@ struct info_t axes = (hb_ot_var_axis_info_t *) calloc (count, sizeof (hb_ot_var_axis_info_t)); hb_ot_var_get_axis_infos (face, 0, &count, axes); - auto language = hb_language_get_default (); + auto language = hb_language_get_default (); // TODO bool has_hidden = false; if (verbose && count)