diff --git a/src/Makefile.am b/src/Makefile.am index 52bd92b79..56dc32d9a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -382,6 +382,7 @@ noinst_PROGRAMS = \ test-ot-name \ test-ot-glyphname \ test-gpos-size-params \ + test-gsub-get-alternates \ test-gsub-would-substitute \ test-use-table \ $(NULL) @@ -419,6 +420,10 @@ test_gpos_size_params_SOURCES = test-gpos-size-params.cc test_gpos_size_params_CPPFLAGS = $(HBCFLAGS) test_gpos_size_params_LDADD = libharfbuzz.la $(HBLIBS) +test_gsub_get_alternates_SOURCES = test-gsub-get-alternates.cc +test_gsub_get_alternates_CPPFLAGS = $(HBCFLAGS) +test_gsub_get_alternates_LDADD = libharfbuzz.la $(HBLIBS) + test_gsub_would_substitute_SOURCES = test-gsub-would-substitute.cc test_gsub_would_substitute_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) test_gsub_would_substitute_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) diff --git a/src/meson.build b/src/meson.build index 93991abd9..30b99cf34 100644 --- a/src/meson.build +++ b/src/meson.build @@ -668,6 +668,7 @@ if get_option('tests').enabled() 'test-ot-name': 'test-ot-name.cc', 'test-ot-glyphname': 'test-ot-glyphname.cc', 'test-ot-gpos-size-params': 'test-gpos-size-params.cc', + 'test-ot-gsub-get-alternates': 'test-gsub-get-alternates.cc', 'test-ot-gsub-would-substitute': 'test-gsub-would-substitute.cc', 'test-use-table': 'test-use-table.cc', } diff --git a/src/test-gsub-get-alternates.cc b/src/test-gsub-get-alternates.cc new file mode 100644 index 000000000..c9f3b4edb --- /dev/null +++ b/src/test-gsub-get-alternates.cc @@ -0,0 +1,86 @@ +/* + * Copyright © 2010,2011 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 +#include + +#include +#include + +int +main (int argc, char **argv) +{ + if (argc != 3) { + fprintf (stderr, "usage: %s font-file text\n", argv[0]); + exit (1); + } + + /* Create the face */ + hb_blob_t *blob = hb_blob_create_from_file_or_fail (argv[1]); + hb_face_t *face = hb_face_create (blob, 0 /* first face */); + hb_blob_destroy (blob); + blob = nullptr; + + hb_font_t *font = hb_font_create (face); + hb_buffer_t *buffer = hb_buffer_create (); + + hb_buffer_add_utf8 (buffer, argv[2], -1, 0, -1); + hb_buffer_guess_segment_properties (buffer); + hb_shape (font, buffer, NULL, 0); + + hb_tag_t features[] = {HB_TAG('a','a','l','t'), HB_TAG_NONE}; + hb_set_t *lookup_indexes = hb_set_create (); + hb_ot_layout_collect_lookups (face, + HB_OT_TAG_GSUB, + NULL, NULL, + features, + lookup_indexes); + printf ("lookups %u\n", hb_set_get_population (lookup_indexes)); + + unsigned count; + hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, &count); + for (unsigned i = 0; i < count; i++) + { + unsigned alt_count = 0; + for (unsigned lookup_index = HB_SET_VALUE_INVALID; + hb_set_next (lookup_indexes, &lookup_index);) + if ((alt_count = hb_ot_layout_lookup_get_glyph_alternates (face, + lookup_index, + info[i].codepoint, + 0, + NULL, + NULL))) + break; + printf ("glyph %u alt count %u\n", info[i].codepoint, alt_count); + } + + hb_set_destroy (lookup_indexes); + hb_buffer_destroy (buffer); + hb_font_destroy (font); + hb_face_destroy (face); + + return 0; +}