提交 4009a05c 编写于 作者: E Ebrahim Byagowi 提交者: Behdad Esfahbod

[feat] Address Behdad comments

上级 19b60255
......@@ -45,6 +45,13 @@ struct SettingName
return_trace (likely (c->check_struct (this)));
}
inline hb_aat_layout_feature_setting_t get_setting () const
{ return (hb_aat_layout_feature_setting_t) (unsigned int) setting; }
inline hb_ot_name_id_t get_name_id () const
{ return (hb_ot_name_id_t) nameIndex; }
protected:
HBUINT16 setting; /* The setting. */
NameID nameIndex; /* The name table index for the setting's name. */
public:
......@@ -57,10 +64,10 @@ struct FeatureName
{
static int cmp (const void *key_, const void *entry_)
{
hb_aat_feature_type_t key = * (hb_aat_feature_type_t *) key_;
hb_aat_layout_feature_setting_t key = * (hb_aat_layout_feature_setting_t *) key_;
const FeatureName * entry = (const FeatureName *) entry_;
return key < entry->feature ? -1 :
key > entry->feature ? 1 :
key > entry->feature ? +1 :
0;
}
......@@ -78,48 +85,59 @@ struct FeatureName
* as the default. */
};
inline unsigned int get_settings (const feat *feat,
hb_bool_t *is_exclusive,
unsigned int start_offset,
unsigned int *records_count,
hb_aat_feature_option_record_t *records_buffer) const
inline unsigned int get_settings (const feat *feat,
hb_aat_layout_feature_setting_t *default_setting,
unsigned int start_offset,
unsigned int *count,
hb_aat_layout_feature_setting_t *settings) const
{
bool exclusive = featureFlags & Exclusive;
bool not_default = featureFlags & NotDefault;
if (is_exclusive) *is_exclusive = exclusive;
const UnsizedArrayOf<SettingName>& settings = feat+settingTable;
unsigned int len = 0;
const UnsizedArrayOf<SettingName>& settings_table = feat+settingTableZ;
unsigned int settings_count = nSettings;
if (records_count && records_buffer)
if (count && *count)
{
len = MIN (settings_count - start_offset, *records_count);
unsigned int len = MIN (settings_count - start_offset, *count);
for (unsigned int i = 0; i < len; i++)
{
records_buffer[i].is_default = exclusive && not_default &&
i + start_offset == (featureFlags & IndexMask);
records_buffer[i].name_id = settings[start_offset + i].nameIndex;
records_buffer[i].setting = settings[start_offset + i].setting;
}
if (exclusive && !not_default && start_offset == 0 && len != 0)
records_buffer[0].is_default = true;
settings[i] = settings_table[start_offset + i].get_setting ();
*count = len;
}
if (default_setting)
{
unsigned int index = (featureFlags & NotDefault) ? featureFlags & IndexMask : 0;
*default_setting = ((featureFlags & Exclusive) && index < settings_count)
? settings_table[index].get_setting ()
: HB_AAT_LAYOUT_SELECTOR_INVALID;
}
if (is_exclusive) *is_exclusive = exclusive;
if (records_count) *records_count = len;
return settings_count;
}
inline hb_aat_layout_feature_type_t get_feature_type () const
{ return (hb_aat_layout_feature_type_t) (unsigned int) feature; }
inline hb_ot_name_id_t get_feature_name_id () const
{ return (hb_ot_name_id_t) nameIndex; }
inline hb_ot_name_id_t get_feature_setting_name_id (const feat *feat,
hb_aat_layout_feature_setting_t setting) const
{
const UnsizedArrayOf<SettingName>& settings_table = feat+settingTableZ;
for (unsigned int i = 0; i < nSettings; i++)
if (settings_table[i].get_setting () == setting)
return settings_table[i].get_name_id ();
return HB_OT_NAME_ID_INVALID;
}
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
{
TRACE_SANITIZE (this);
return_trace (likely (c->check_struct (this) &&
(base+settingTable).sanitize (c, nSettings)));
(base+settingTableZ).sanitize (c, nSettings)));
}
protected:
HBUINT16 feature; /* Feature type. */
HBUINT16 nSettings; /* The number of records in the setting name array. */
LOffsetTo<UnsizedArrayOf<SettingName>, false>
settingTable; /* Offset in bytes from the beginning of this table to
settingTableZ; /* Offset in bytes from the beginning of this table to
* this feature's setting name array. The actual type of
* record this offset refers to will depend on the
* exclusivity value, as described below. */
......@@ -135,9 +153,24 @@ struct feat
{
static const hb_tag_t tableTag = HB_AAT_TAG_feat;
inline const FeatureName& get_feature (hb_aat_feature_type_t key) const
inline unsigned int get_features (unsigned int start_offset,
unsigned int *count,
hb_aat_layout_feature_type_t *features) const
{
const FeatureName* feature = (FeatureName*) hb_bsearch (&key, &names,
unsigned int feature_count = featureNameCount;
if (count && *count)
{
unsigned int len = MIN (feature_count - start_offset, *count);
for (unsigned int i = 0; i < len; i++)
features[i] = namesZ[i + start_offset].get_feature_type ();
*count = len;
}
return featureNameCount;
}
inline const FeatureName& get_feature (hb_aat_layout_feature_type_t key) const
{
const FeatureName* feature = (FeatureName*) hb_bsearch (&key, &namesZ,
FeatureName::static_size,
sizeof (FeatureName),
FeatureName::cmp);
......@@ -145,21 +178,28 @@ struct feat
return feature ? *feature : Null (FeatureName);
}
inline unsigned int get_settings (hb_aat_feature_type_t key,
hb_bool_t *is_exclusive,
unsigned int start_offset,
unsigned int *records_count,
hb_aat_feature_option_record_t *records_buffer) const
inline hb_ot_name_id_t get_feature_name_id (hb_aat_layout_feature_type_t feature) const
{ return get_feature (feature).get_feature_name_id (); }
inline hb_ot_name_id_t get_feature_setting_name_id (hb_aat_layout_feature_type_t feature,
hb_aat_layout_feature_setting_t setting) const
{ return get_feature (feature).get_feature_setting_name_id (this, setting); }
inline unsigned int get_settings (hb_aat_layout_feature_type_t key,
hb_aat_layout_feature_setting_t *default_setting,
unsigned int start_offset,
unsigned int *count,
hb_aat_layout_feature_setting_t *settings) const
{
return get_feature (key).get_settings (this, is_exclusive, start_offset,
records_count, records_buffer);
return get_feature (key).get_settings (this, default_setting, start_offset,
count, settings);
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (likely (c->check_struct (this) &&
names.sanitize (c, featureNameCount, this)));
namesZ.sanitize (c, featureNameCount, this)));
}
protected:
......@@ -170,7 +210,7 @@ struct feat
HBUINT16 reserved1; /* Reserved (set to zero). */
HBUINT32 reserved2; /* Reserved (set to zero). */
UnsizedArrayOf<FeatureName>
names; /* The feature name array. */
namesZ; /* The feature name array. */
public:
DEFINE_SIZE_STATIC (24);
};
......
......@@ -314,10 +314,15 @@ hb_aat_layout_get_features (hb_face_t *face,
return face->table.feat->get_features (start_offset, count, features);
}
/**
* hb_aat_layout_get_feature_name_id:
*
* Since: REPLACEME
*/
hb_ot_name_id_t
hb_aat_layout_get_feature_name_id (hb_face_t *face,
hb_aat_layout_feature_type_t feature)
{ return HB_OT_NAME_ID_INVALID; }
{ return face->table.feat->get_feature_name_id (feature); }
/**
* hb_aat_layout_get_feature_settings:
......@@ -336,8 +341,13 @@ hb_aat_layout_get_feature_settings (hb_face_t *face,
start_offset, count, settings);
}
/**
* hb_aat_layout_get_feature_setting_name_id:
*
* Since: REPLACEME
*/
hb_ot_name_id_t
hb_aat_layout_get_feature_setting_name_id (hb_face_t *face,
hb_aat_layout_feature_type_t feature,
hb_aat_layout_feature_setting_t setting)
{ return HB_OT_NAME_ID_INVALID; }
{ return face->table.feat->get_feature_setting_name_id (feature, setting); }
此差异已折叠。
......@@ -36,65 +36,67 @@ static hb_face_t *sbix;
static void
test_aat_get_features (void)
{
// hb_aat_layout_feature_record_t records[3];
// unsigned int record_count = 3;
// g_assert_cmpuint (11, ==, hb_aat_layout_get_features (face, 0, &record_count, records));
// g_assert_cmpuint (1, ==, records[0].feature);
// g_assert_cmpuint (258, ==, records[0].name_id);
// g_assert_cmpuint (3, ==, records[1].feature);
// g_assert_cmpuint (261, ==, records[1].name_id);
// g_assert_cmpuint (6, ==, records[2].feature);
// g_assert_cmpuint (265, ==, records[2].name_id);
hb_aat_layout_feature_type_t features[3];
unsigned int count = 3;
g_assert_cmpuint (11, ==, hb_aat_layout_get_features (face, 0, &count, features));
g_assert_cmpuint (1, ==, features[0]);
g_assert_cmpuint (3, ==, features[1]);
g_assert_cmpuint (6, ==, features[2]);
g_assert_cmpuint (258, ==, hb_aat_layout_get_feature_name_id (face, features[0]));
g_assert_cmpuint (261, ==, hb_aat_layout_get_feature_name_id (face, features[1]));
g_assert_cmpuint (265, ==, hb_aat_layout_get_feature_name_id (face, features[2]));
}
static void
test_aat_get_feature_settings (void)
{
// hb_aat_layout_feature_setting_t default_setting;
// hb_aat_layout_feature_type_selector_t records[3];
// unsigned int count = 3;
// g_assert_cmpuint (4, ==, hb_aat_layout_get_feature_settings (face, (hb_aat_layout_feature_type_t) 18,
// &default_setting, 0, &count, records));
// g_assert_cmpuint (3, ==, count);
// g_assert_cmpuint (0, ==, default_setting);
hb_aat_layout_feature_setting_t default_setting;
hb_aat_layout_feature_setting_t settings[3];
unsigned int count = 3;
// g_assert_cmpuint (0, ==, records[0].setting);
// g_assert_cmpuint (294, ==, records[0].name_id);
g_assert_cmpuint (4, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
&default_setting, 0, &count, settings));
g_assert_cmpuint (3, ==, count);
g_assert_cmpuint (0, ==, default_setting);
// g_assert_cmpuint (1, ==, records[1].setting);
// g_assert_cmpuint (295, ==, records[1].name_id);
g_assert_cmpuint (0, ==, settings[0]);
g_assert_cmpuint (294, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, settings[0]));
// g_assert_cmpuint (2, ==, records[2].setting);
// g_assert_cmpuint (296, ==, records[2].name_id);
g_assert_cmpuint (1, ==, settings[1]);
g_assert_cmpuint (295, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, settings[1]));
// count = 3;
// g_assert_cmpuint (4, ==, hb_aat_layout_get_feature_settings (face, (hb_aat_layout_feature_type_t) 18,
// &default_setting, 3, &count, records));
// g_assert_cmpuint (1, ==, count);
// g_assert_cmpuint (0, ==, default_setting);
g_assert_cmpuint (2, ==, settings[2]);
g_assert_cmpuint (296, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, settings[2]));
// g_assert_cmpuint (3, ==, records[0].setting);
// g_assert_cmpuint (297, ==, records[0].name_id);
g_assert_cmpuint (HB_OT_NAME_ID_INVALID, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, HB_AAT_LAYOUT_SELECTOR_INVALID));
count = 3;
g_assert_cmpuint (4, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
&default_setting, 3, &count, settings));
g_assert_cmpuint (1, ==, count);
g_assert_cmpuint (0, ==, default_setting);
// count = 1;
// g_assert_cmpuint (1, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS,
// &default_setting, 0, &count, records));
// g_assert_cmpuint (1, ==, count);
// g_assert_cmpuint (HB_AAT_LAYOUT_FEATURE_TYPE_UNDEFINED, ==, default_setting);
g_assert_cmpuint (3, ==, settings[0]);
g_assert_cmpuint (297, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, settings[0]));
// g_assert_cmpuint (8, ==, records[0].setting);
// g_assert_cmpuint (308, ==, records[0].name_id);
count = 1;
g_assert_cmpuint (1, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS,
&default_setting, 0, &count, settings));
g_assert_cmpuint (1, ==, count);
g_assert_cmpuint (HB_AAT_LAYOUT_FEATURE_TYPE_INVALID, ==, default_setting);
g_assert_cmpuint (8, ==, settings[0]);
g_assert_cmpuint (308, ==, hb_aat_layout_get_feature_setting_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS, settings[0]));
// count = 100;
// g_assert_cmpuint (0, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_UNDEFINED,
// NULL, 0, &count, records));
// g_assert_cmpuint (0, ==, count);
count = 100;
g_assert_cmpuint (0, ==, hb_aat_layout_get_feature_settings (face, HB_AAT_LAYOUT_FEATURE_TYPE_INVALID,
NULL, 0, &count, settings));
g_assert_cmpuint (0, ==, count);
// g_assert_cmpuint (0, ==, hb_aat_layout_get_feature_settings (sbix, HB_AAT_LAYOUT_FEATURE_TYPE_UNDEFINED, NULL,
// 0, &count, records));
g_assert_cmpuint (HB_OT_NAME_ID_INVALID, ==, hb_aat_layout_get_feature_setting_name_id (sbix, HB_AAT_LAYOUT_FEATURE_TYPE_INVALID,
(hb_aat_layout_feature_setting_t) 0));
}
int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册