Merge pull request #2476 from ebraminio/cv-get-chars

[layout] Use dagger in hb_ot_layout_feature_get_characters
This commit is contained in:
Ebrahim Byagowi 2020-06-20 01:24:41 +04:30 committed by GitHub
commit dce4353f86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 28 deletions

View File

@ -805,11 +805,16 @@ struct FeatureParamsStylisticSet
/* https://docs.microsoft.com/en-us/typography/opentype/spec/features_ae#cv01-cv99 */
struct FeatureParamsCharacterVariants
{
bool sanitize (hb_sanitize_context_t *c) const
unsigned
get_characters (unsigned start_offset, unsigned *char_count, hb_codepoint_t *chars) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
characters.sanitize (c));
if (char_count)
{
+ characters.sub_array (start_offset, char_count)
| hb_sink (hb_array (chars, *char_count))
;
}
return characters.len;
}
unsigned get_size () const
@ -821,6 +826,13 @@ struct FeatureParamsCharacterVariants
return_trace ((bool) c->serializer->embed (*this));
}
bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
characters.sanitize (c));
}
HBUINT16 format; /* Format number is set to 0. */
NameID featUILableNameID; /* The name table name ID that
* specifies a string (or strings,

View File

@ -1710,12 +1710,6 @@ hb_ot_layout_feature_get_name_ids (hb_face_t *face,
* Fetches a list of the characters defined as having a variant under the specified
* "Character Variant" ("cvXX") feature tag.
*
* <note>Note: If the char_count output value is equal to its input value, then there
* is a chance there were more characters defined under the feature tag than were
* returned. This function can be called with incrementally larger start_offset
* until the char_count output value is lower than its input value, or the size
* of the characters array can be increased.</note>
*
* Return value: Number of total sample characters in the cvXX feature.
*
* Since: 2.0.0
@ -1729,24 +1723,10 @@ hb_ot_layout_feature_get_characters (hb_face_t *face,
hb_codepoint_t *characters /* OUT. May be NULL */)
{
const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
hb_tag_t feature_tag = g.get_feature_tag (feature_index);
const OT::Feature &f = g.get_feature (feature_index);
const OT::FeatureParams &feature_params = f.get_feature_params ();
const OT::FeatureParamsCharacterVariants& cv_params =
feature_params.get_character_variants_params(feature_tag);
unsigned int len = 0;
if (char_count && characters && start_offset < cv_params.characters.len)
{
len = hb_min (cv_params.characters.len - start_offset, *char_count);
for (unsigned int i = 0; i < len; ++i)
characters[i] = cv_params.characters[start_offset + i];
}
if (char_count) *char_count = len;
return cv_params.characters.len;
return g.get_feature (feature_index)
.get_feature_params ()
.get_character_variants_params(g.get_feature_tag (feature_index))
.get_characters (start_offset, char_count, characters);
}
#endif

View File

@ -68,6 +68,15 @@ test_ot_layout_feature_get_name_ids_and_characters (void)
g_assert_cmpint (char_count, ==, 2);
g_assert_cmpint (characters[0], ==, 10);
g_assert_cmpint (characters[1], ==, 24030);
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);
}
static void