2018-10-12 01:30:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Ebrahim Byagowi
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-16 12:47:21 +02:00
|
|
|
#include "hb-test.h"
|
|
|
|
|
2018-10-12 01:30:59 +02:00
|
|
|
#include <hb-ot.h>
|
|
|
|
|
2018-11-06 09:12:47 +01:00
|
|
|
static hb_face_t *face;
|
2018-11-06 08:56:30 +01:00
|
|
|
|
2018-10-16 12:47:21 +02:00
|
|
|
static void
|
2018-10-20 05:00:36 +02:00
|
|
|
test_ot_layout_feature_get_name_ids_and_characters (void)
|
2018-10-12 01:30:59 +02:00
|
|
|
{
|
|
|
|
hb_tag_t cv01 = HB_TAG ('c','v','0','1');
|
2018-10-12 22:05:56 +02:00
|
|
|
unsigned int feature_index;
|
2018-12-11 18:32:01 +01:00
|
|
|
unsigned int num_named_parameters;
|
|
|
|
hb_ot_name_id_t label_id;
|
|
|
|
hb_ot_name_id_t tooltip_id;
|
|
|
|
hb_ot_name_id_t sample_id;
|
|
|
|
hb_ot_name_id_t first_param_id;
|
|
|
|
hb_codepoint_t characters[100];
|
|
|
|
unsigned int char_count = 100;
|
|
|
|
unsigned int all_chars;
|
2018-10-12 22:05:56 +02:00
|
|
|
if (!hb_ot_layout_language_find_feature (face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
0,
|
|
|
|
HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
|
|
|
|
cv01,
|
|
|
|
&feature_index))
|
|
|
|
g_error ("Failed to find feature index");
|
2018-10-12 01:30:59 +02:00
|
|
|
|
|
|
|
if (!hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index,
|
2018-10-12 22:05:56 +02:00
|
|
|
&label_id, &tooltip_id, &sample_id,
|
2018-10-12 01:30:59 +02:00
|
|
|
&num_named_parameters, &first_param_id))
|
|
|
|
g_error ("Failed to get name ids");
|
|
|
|
|
2018-10-19 08:50:16 +02:00
|
|
|
g_assert_cmpint (label_id, ==, 256);
|
|
|
|
g_assert_cmpint (tooltip_id, ==, 257);
|
|
|
|
g_assert_cmpint (sample_id, ==, 258);
|
|
|
|
g_assert_cmpint (num_named_parameters, ==, 2);
|
|
|
|
g_assert_cmpint (first_param_id, ==, 259);
|
2018-10-12 01:30:59 +02:00
|
|
|
|
|
|
|
all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
|
2018-10-12 22:05:56 +02:00
|
|
|
0, &char_count, characters);
|
2018-10-12 01:30:59 +02:00
|
|
|
|
2018-10-19 08:50:16 +02:00
|
|
|
g_assert_cmpint (all_chars, ==, 2);
|
|
|
|
g_assert_cmpint (char_count, ==, 2);
|
|
|
|
g_assert_cmpint (characters[0], ==, 10);
|
|
|
|
g_assert_cmpint (characters[1], ==, 24030);
|
2020-06-19 20:57:39 +02:00
|
|
|
|
|
|
|
char_count = 100;
|
|
|
|
characters[1] = 1234;
|
|
|
|
all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
|
|
|
|
1, &char_count, characters);
|
|
|
|
g_assert_cmpint (all_chars, ==, 2);
|
|
|
|
g_assert_cmpint (char_count, ==, 1);
|
|
|
|
g_assert_cmpint (characters[0], ==, 24030);
|
|
|
|
g_assert_cmpint (characters[1], ==, 1234);
|
2018-11-06 08:56:30 +01:00
|
|
|
}
|
2018-10-21 09:37:17 +02:00
|
|
|
|
2018-11-06 08:56:30 +01:00
|
|
|
static void
|
|
|
|
test_ot_name (void)
|
|
|
|
{
|
|
|
|
unsigned int num_entries;
|
|
|
|
const hb_ot_name_entry_t *entries;
|
2018-12-11 18:32:01 +01:00
|
|
|
hb_ot_name_id_t name_id;
|
|
|
|
hb_language_t lang;
|
|
|
|
char text[10];
|
|
|
|
unsigned int text_size = 10;
|
2018-11-06 08:56:30 +01:00
|
|
|
entries = hb_ot_name_list_names (face, &num_entries);
|
|
|
|
g_assert_cmpuint (12, ==, num_entries);
|
2018-12-11 18:32:01 +01:00
|
|
|
name_id = entries[3].name_id;
|
2018-11-06 08:56:30 +01:00
|
|
|
g_assert_cmpuint (3, ==, name_id);
|
2018-12-11 18:32:01 +01:00
|
|
|
lang = entries[3].language;
|
2018-11-20 07:16:08 +01:00
|
|
|
g_assert_cmpstr (hb_language_to_string (lang), ==, "en");
|
2018-11-06 08:56:30 +01:00
|
|
|
g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, lang, &text_size, text));
|
|
|
|
g_assert_cmpuint (9, ==, text_size);
|
|
|
|
g_assert_cmpstr (text, ==, "FontForge");
|
2018-10-16 12:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2018-12-11 18:32:01 +01:00
|
|
|
unsigned int status;
|
2018-10-16 12:47:21 +02:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
|
|
|
hb_test_add (test_ot_layout_feature_get_name_ids_and_characters);
|
2018-11-06 08:56:30 +01:00
|
|
|
hb_test_add (test_ot_name);
|
2018-10-16 12:47:21 +02:00
|
|
|
|
2018-11-06 08:56:30 +01:00
|
|
|
face = hb_test_open_font_file ("fonts/cv01.otf");
|
2018-12-11 18:32:01 +01:00
|
|
|
status = hb_test_run ();
|
2018-11-06 08:56:30 +01:00
|
|
|
hb_face_destroy (face);
|
|
|
|
return status;
|
2018-10-12 01:30:59 +02:00
|
|
|
}
|