Hash :
edd5a37e
Author :
Date :
2023-01-19T18:39:32
[hb-info] Implement script/language-sensitive --list-features I'm not very confident in the implementation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
/*
* 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)
{
GOptionEntry misc_entries[] =
{
{"direction", 0, 0, G_OPTION_ARG_STRING, &this->direction_str, "Set direction (default: ltr)", "ltr/rtl/ttb/btt"},
{"language", 0, 0, G_OPTION_ARG_STRING, &this->language_str, "Set language (default: $LANG)", "BCP 47 tag"},
{"script", 0, 0, G_OPTION_ARG_STRING, &this->script_str, "Set script (default: none)", "ISO-15924 tag"},
{nullptr}
};
parser->add_group (misc_entries,
"misc",
"Miscellaneaous options:",
"Miscellaneaous options affecting queries",
this,
false /* We add below. */);
GOptionEntry query_entries[] =
{
{"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 (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},
{"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},
{"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},
{"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},
{"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
{"dump-table", 0, 0, G_OPTION_ARG_STRING, &this->dump_table, "Dump font table", "TABLE-TAG"},
{nullptr}
};
parser->add_group (query_entries,
"query",
"Query options:",
"Options to query the font instance",
this,
false /* We add below. */);
}
protected:
hb_face_t *face = nullptr;
hb_font_t *font = nullptr;
hb_bool_t verbose = true;
hb_bool_t first_item = true;
char *direction_str = nullptr;
char *script_str = nullptr;
char *language_str = nullptr;
hb_direction_t direction = HB_DIRECTION_LTR;
hb_script_t script = HB_SCRIPT_INVALID;
hb_language_t language = HB_LANGUAGE_INVALID;
hb_bool_t all = false;
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_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;
hb_bool_t show_extents = 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;
hb_bool_t list_scripts = false;
hb_bool_t list_features = false;
#ifndef HB_NO_VAR
hb_bool_t list_variations = false;
#endif
char *dump_table = nullptr;
public:
template <typename app_t>
void operator () (app_t *app)
{
face = hb_face_reference (((font_options_t *) app)->face);
font = hb_font_reference (((font_options_t *) app)->font);
verbose = !app->quiet;
if (direction_str)
direction = hb_direction_from_string (direction_str, -1);
if (script_str)
script = hb_script_from_string (script_str, -1);
language = hb_language_get_default ();
if (language_str)
language = hb_language_from_string (language_str, -1);
if (all)
{
show_all =
list_all =
true;
}
if (show_all)
{
show_family =
show_style =
show_unique_name =
show_full_name =
show_postscript_name =
show_version =
show_upem =
show_unicode_count =
show_glyph_count =
show_extents =
true;
first_item = false;
}
if (list_all)
{
list_names =
list_tables =
list_unicodes =
list_glyphs =
list_scripts =
list_features =
#ifndef HB_NO_VAR
list_variations =
#endif
true;
}
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_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 ();
if (show_extents) _show_extents ();
if (list_names) _list_names ();
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 ();
#endif
if (dump_table) _dump_table ();
hb_font_destroy (font);
hb_face_destroy (face);
}
protected:
void separator ()
{
if (first_item)
{
first_item = false;
return;
}
printf ("\n===\n\n");
}
void _show_name (const char *label, hb_ot_name_id_t name_id)
{
if (verbose)
{
printf ("%s: ", label);
}
char name[16384];
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_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 ()
{
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 ()
{
if (verbose)
{
printf ("Units-Per-EM: ");
}
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)
{
printf ("Glyph count: ");
}
printf ("%u\n", hb_face_get_glyph_count (face));
}
void _show_extents ()
{
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)
{
separator ();
printf ("Name information:\n\n");
printf ("Id Text\n------------\n");
}
unsigned count;
const auto *entries = hb_ot_name_list_names (face, &count);
for (unsigned i = 0; i < count; i++)
{
char name[16384];
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 ("Table information:\n\n");
printf ("Tag Size\n------------\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);
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 ()
{
if (verbose)
{
separator ();
printf ("Character-set information:\n\n");
printf ("Unicode Glyph name\n------------------\n");
}
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 ()
{
if (verbose)
{
separator ();
printf ("Glyph-set information:\n\n");
printf ("GlyphID Glyph name\n------------------\n");
}
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_scripts ()
{
if (verbose)
{
separator ();
printf ("Layout script information:\n\n");
}
hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE};
for (unsigned int i = 0; table_tags[i]; i++)
{
if (verbose) printf ("Table: ");
printf ("%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 (" ");
if (verbose) printf ("Script: ");
printf ("%c%c%c%c (%c%c%c%c)\n",
HB_UNTAG (hb_script_to_iso15924_tag (hb_ot_tag_to_script (script_array[script_index]))),
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 (" ");
if (verbose) printf ("Language: ");
printf ("%s (%c%c%c%c)\n",
hb_language_to_string (hb_ot_tag_to_language (language_array[language_index])),
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]);
}
}
void
_list_features_no_script ()
{
hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE};
hb_set_t *features = hb_set_create ();
for (unsigned int i = 0; table_tags[i]; i++)
{
if (verbose) printf ("Table: ");
printf ("%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];
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 (" ");
if (verbose) printf ("Feature: ");
printf ("%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);
}
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};
if (script == HB_SCRIPT_INVALID)
{
_list_features_no_script ();
return;
}
for (unsigned int i = 0; table_tags[i]; i++)
{
if (verbose) printf ("Table: ");
printf ("%c%c%c%c\n", HB_UNTAG (table_tags[i]));
auto table_tag = table_tags[i];
hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
unsigned script_count = HB_OT_MAX_TAGS_PER_SCRIPT;
unsigned language_count = HB_OT_MAX_TAGS_PER_LANGUAGE;
hb_ot_tags_from_script_and_language (script, language,
&script_count, script_tags,
&language_count, language_tags);
unsigned script_index;
hb_ot_layout_table_select_script (face, table_tag,
script_count, script_tags,
&script_index, nullptr);
unsigned language_index;
hb_ot_layout_script_select_language (face, table_tag,
script_index,
language_count, language_tags,
&language_index);
unsigned feature_array[32];
unsigned feature_count = sizeof feature_array / sizeof feature_array[0];
unsigned feature_offset = 0;
do
{
hb_ot_layout_language_get_feature_indexes (face, table_tag,
script_index, language_index,
feature_offset,
&feature_count,
feature_array);
for (unsigned feature_index = 0; feature_index < feature_count; feature_index++)
{
hb_ot_name_id_t label_id;
hb_ot_layout_feature_get_name_ids (face,
table_tags[i],
feature_array[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 (" ");
if (verbose) printf ("Feature: ");
hb_tag_t feature_tag;
unsigned f_count = 1;
hb_ot_layout_table_get_feature_tags (face, table_tag,
feature_array[feature_index],
&f_count, &feature_tag);
printf ("%c%c%c%c", HB_UNTAG (feature_tag));
if (*name)
printf (" %s", name);
printf ("\n");
}
feature_offset += feature_count;
}
while (feature_count == sizeof feature_array / sizeof feature_array[0]);
}
}
#ifndef HB_NO_VAR
void
_list_variations ()
{
if (verbose)
{
separator ();
printf ("Face variations information:\n\n");
}
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);
bool has_hidden = false;
if (verbose && count)
{
printf ("Varitation axes:\n\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 (verbose && has_hidden)
printf ("\n[*] Hidden axis\n\n");
free (axes);
axes = nullptr;
count = hb_ot_var_get_named_instance_count (face);
if (count)
{
if (verbose)
{
printf ("\nNamed instances:\n\n");
printf ("Index Name Position\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
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);
}
};
template <typename consumer_t,
typename font_options_type>
struct main_font_t :
option_parser_t,
font_options_type,
consumer_t
{
int operator () (int argc, char **argv)
{
add_options ();
if (argc == 2)
consumer_t::show_all = true;
parse (&argc, &argv);
consumer_t::operator () (this);
return 0;
}
protected:
void add_options ()
{
font_options_type::add_options (this);
consumer_t::add_options (this);
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}
};
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;
}
public:
hb_bool_t quiet = false;
};
int
main (int argc, char **argv)
{
using main_t = main_font_t<info_t, font_options_t>;
return batch_main<main_t> (argc, argv);
}