mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[ot] Add hb_ot_fetch_number()
Similar to hb_ot_fetch_bits() but for signed numbers. The only tags so far are for font bounding box from head table. Fixes https://github.com/harfbuzz/harfbuzz/issues/6110
This commit is contained in:
1 parent
6e67c5feed
commit
86e7473f0d
4 files changed
+88
-2
No files matched your search
@@ -838,6 +838,8 @@ hb_ot_var_axis_info_t
|
||||
<FILE>hb-ot-fetch</FILE>
|
||||
hb_ot_bits_tag_t
|
||||
hb_ot_fetch_bits
|
||||
hb_ot_number_tag_t
|
||||
hb_ot_fetch_number
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
|
||||
+28
-2
@@ -35,10 +35,11 @@
|
||||
/**
|
||||
* SECTION:hb-ot-fetch
|
||||
* @title: hb-ot-fetch
|
||||
* @short_description: OpenType bit fields
|
||||
* @short_description: OpenType bit fields and numbers
|
||||
* @include: hb-ot.h
|
||||
*
|
||||
* Functions for fetching various bit fields scattered around OpenType tables.
|
||||
* Functions for fetching various bit fields and numbers scattered around
|
||||
* OpenType tables.
|
||||
*
|
||||
* These are raw table values, and many of them are legacy or unreliable, but
|
||||
* applications might need them for various legacy reasons.
|
||||
@@ -76,4 +77,29 @@ hb_ot_fetch_bits (hb_face_t *face,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_ot_fetch_number:
|
||||
* @face: #hb_face_t to work upon
|
||||
* @tag: tag of the number to fetch
|
||||
*
|
||||
* Fetches a number of @face in font units.
|
||||
*
|
||||
* Return value: the number, or zero if the font does not have it.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int32_t
|
||||
hb_ot_fetch_number (hb_face_t *face,
|
||||
hb_ot_number_tag_t tag)
|
||||
{
|
||||
switch ((unsigned) tag)
|
||||
{
|
||||
case HB_OT_NUMBER_TAG_FONT_X_MIN: return face->table.head->xMin;
|
||||
case HB_OT_NUMBER_TAG_FONT_Y_MIN: return face->table.head->yMin;
|
||||
case HB_OT_NUMBER_TAG_FONT_X_MAX: return face->table.head->xMax;
|
||||
case HB_OT_NUMBER_TAG_FONT_Y_MAX: return face->table.head->yMax;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -71,6 +71,31 @@ HB_EXTERN uint32_t
|
||||
hb_ot_fetch_bits (hb_face_t *face,
|
||||
hb_ot_bits_tag_t tag);
|
||||
|
||||
/**
|
||||
* hb_ot_number_tag_t:
|
||||
* @HB_OT_NUMBER_TAG_FONT_X_MIN: `xMin` of the `head` table.
|
||||
* @HB_OT_NUMBER_TAG_FONT_Y_MIN: `yMin` of the `head` table.
|
||||
* @HB_OT_NUMBER_TAG_FONT_X_MAX: `xMax` of the `head` table.
|
||||
* @HB_OT_NUMBER_TAG_FONT_Y_MAX: `yMax` of the `head` table.
|
||||
*
|
||||
* Numbers that can be fetched with hb_ot_fetch_number().
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef enum {
|
||||
HB_OT_NUMBER_TAG_FONT_X_MIN = HB_TAG ('x','m','i','n'),
|
||||
HB_OT_NUMBER_TAG_FONT_Y_MIN = HB_TAG ('y','m','i','n'),
|
||||
HB_OT_NUMBER_TAG_FONT_X_MAX = HB_TAG ('x','m','a','x'),
|
||||
HB_OT_NUMBER_TAG_FONT_Y_MAX = HB_TAG ('y','m','a','x'),
|
||||
|
||||
/*< private >*/
|
||||
_HB_OT_NUMBER_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
|
||||
} hb_ot_number_tag_t;
|
||||
|
||||
HB_EXTERN int32_t
|
||||
hb_ot_fetch_number (hb_face_t *face,
|
||||
hb_ot_number_tag_t tag);
|
||||
|
||||
HB_END_DECLS
|
||||
|
||||
#endif /* HB_OT_FETCH_H */
|
||||
@@ -154,6 +154,37 @@ test_ot_bits_invalid (void)
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ot_number_bounding_box (void)
|
||||
{
|
||||
hb_face_t *adwaita = hb_test_open_font_file ("fonts/adwaita.ttf");
|
||||
hb_face_t *abc = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf");
|
||||
|
||||
g_assert_cmpint (hb_ot_fetch_number (adwaita, HB_OT_NUMBER_TAG_FONT_X_MIN), ==, 51);
|
||||
g_assert_cmpint (hb_ot_fetch_number (adwaita, HB_OT_NUMBER_TAG_FONT_Y_MIN), ==, -250);
|
||||
g_assert_cmpint (hb_ot_fetch_number (adwaita, HB_OT_NUMBER_TAG_FONT_X_MAX), ==, 1238);
|
||||
g_assert_cmpint (hb_ot_fetch_number (adwaita, HB_OT_NUMBER_TAG_FONT_Y_MAX), ==, 950);
|
||||
|
||||
g_assert_cmpint (hb_ot_fetch_number (abc, HB_OT_NUMBER_TAG_FONT_X_MIN), ==, -454);
|
||||
g_assert_cmpint (hb_ot_fetch_number (abc, HB_OT_NUMBER_TAG_FONT_Y_MIN), ==, -293);
|
||||
g_assert_cmpint (hb_ot_fetch_number (abc, HB_OT_NUMBER_TAG_FONT_X_MAX), ==, 2159);
|
||||
g_assert_cmpint (hb_ot_fetch_number (abc, HB_OT_NUMBER_TAG_FONT_Y_MAX), ==, 968);
|
||||
|
||||
hb_face_destroy (adwaita);
|
||||
hb_face_destroy (abc);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ot_number_invalid (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/adwaita.ttf");
|
||||
|
||||
g_assert_cmpint (hb_ot_fetch_number (face, (hb_ot_number_tag_t) HB_TAG ('x','x','x','x')), ==, 0);
|
||||
g_assert_cmpint (hb_ot_fetch_number (hb_face_get_empty (), HB_OT_NUMBER_TAG_FONT_X_MIN), ==, 0);
|
||||
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@@ -166,6 +197,8 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_ot_bits_ranges);
|
||||
hb_test_add (test_ot_bits_missing_tables);
|
||||
hb_test_add (test_ot_bits_invalid);
|
||||
hb_test_add (test_ot_number_bounding_box);
|
||||
hb_test_add (test_ot_number_invalid);
|
||||
|
||||
return hb_test_run ();
|
||||
}
|
||||
Reference in new issue
Block a user