[base] Add hb_ot_layout_get_baseline API

This commit is contained in:
Ebrahim Byagowi 2019-07-30 04:42:51 +04:30 committed by GitHub
parent 40a4b6ddbd
commit 9f2b4956b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 68 deletions

View File

@ -548,6 +548,7 @@ HB_OT_TAG_GDEF
HB_OT_TAG_GPOS
HB_OT_TAG_GSUB
HB_OT_TAG_JSTF
hb_ot_layout_baseline_tag_t
hb_ot_layout_collect_lookups
hb_ot_layout_collect_features
hb_ot_layout_feature_get_characters
@ -555,6 +556,7 @@ hb_ot_layout_feature_get_lookups
hb_ot_layout_feature_get_name_ids
hb_ot_layout_feature_with_variations_get_lookups
hb_ot_layout_get_attach_points
hb_ot_layout_get_baseline
hb_ot_layout_get_glyph_class
hb_ot_layout_get_glyphs_in_class
hb_ot_layout_get_ligature_carets

View File

@ -97,10 +97,14 @@ HB_OT_TABLE (OT, kern)
HB_OT_ACCELERATOR (OT, GDEF)
HB_OT_ACCELERATOR (OT, GSUB)
HB_OT_ACCELERATOR (OT, GPOS)
//HB_OT_TABLE (OT, BASE)
//HB_OT_TABLE (OT, JSTF)
#endif
/* OpenType baseline. */
#ifndef HB_NO_BASE
HB_OT_TABLE (OT, BASE)
#endif
/* AAT shaping. */
#ifndef HB_NO_AAT
HB_OT_TABLE (AAT, morx)

View File

@ -1940,75 +1940,34 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
apply_string<GSUBProxy> (c, lookup, accel);
}
#if 0
#ifndef HB_NO_BASE
/**
* hb_ot_layout_get_baseline:
* @font: a font
* @baseline: a baseline tag
* @direction: text direction.
* @script_tag: script tag.
* @language_tag: language tag.
* @coord: (out): baseline value if found.
*
* Fetches a baseline value from the face.
*
* Return value: if found baseline value in the the font.
**/
hb_bool_t
hb_ot_layout_get_baseline (hb_font_t *font,
hb_ot_layout_baseline_t baseline,
hb_direction_t direction,
hb_tag_t script_tag,
hb_tag_t language_tag,
hb_position_t *coord /* OUT. May be NULL. */)
hb_ot_layout_get_baseline (hb_font_t *font,
hb_ot_layout_baseline_tag_t baseline_tag,
hb_direction_t direction,
hb_tag_t script_tag,
hb_tag_t language_tag,
hb_position_t *coord /* OUT. May be NULL. */)
{
bool result = font->face->table.BASE->get_baseline (font, baseline, direction, script_tag,
language_tag, coord);
bool result = font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
/* TODO: Simulate https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags#ideographic-em-box */
if (!result && coord) *coord = 0;
if (coord) *coord = font->em_scale_dir (*coord, direction);
if (result && coord)
*coord = HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_y (*coord) : font->em_scale_x (*coord);
return result;
}
/* To be moved to public header */
/*
* BASE
*/
/**
* hb_ot_layout_baseline_t:
*
* https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
*
* Since: DONTREPLACEME
*/
typedef enum {
HB_OT_LAYOUT_BASELINE_HANG = HB_TAG('h','a','n','g'),
HB_OT_LAYOUT_BASELINE_ICFB = HB_TAG('i','c','f','b'),
HB_OT_LAYOUT_BASELINE_ICFT = HB_TAG('i','c','f','t'),
HB_OT_LAYOUT_BASELINE_IDEO = HB_TAG('i','d','e','o'),
HB_OT_LAYOUT_BASELINE_IDTB = HB_TAG('i','d','t','b'),
HB_OT_LAYOUT_BASELINE_MATH = HB_TAG('m','a','t','h'),
HB_OT_LAYOUT_BASELINE_ROMN = HB_TAG('r','o','m','n'),
_HB_OT_LAYOUT_BASELINE_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
} hb_ot_layout_baseline_t;
/**
* hb_ot_layout_get_baseline:
* @font: The #hb_font_t to work upon
* @baseline: The #hb_ot_layout_baseline_t to query
* @direction: The #hb_direction_t text direction to use (horizontal or vertical)
* @script_tag: #hb_tag_t of the script to use
* @language_tag: #hb_tag_t of the language to use
* @coord: (out): The position of the requested baseline
*
* Fetches the coordinates of the specified baseline in the face, underneath
* the specified script and language and in the specified text direction.
*
* Return value: true if the baseline is found for the settings queried, false otherwise
*
**/
HB_EXTERN hb_bool_t
hb_ot_layout_get_baseline (hb_font_t *font,
hb_ot_layout_baseline_t baseline,
hb_direction_t direction,
hb_tag_t script_tag,
hb_tag_t language_tag,
hb_position_t *coord /* OUT. May be NULL. */);
#endif
#endif

View File

@ -402,6 +402,38 @@ hb_ot_layout_feature_get_characters (hb_face_t *face,
unsigned int *char_count /* IN/OUT. May be NULL */,
hb_codepoint_t *characters /* OUT. May be NULL */);
/*
* BASE
*/
/**
* hb_ot_layout_baseline_tag_t:
*
* https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
*
* Since: REPLACEME
*/
typedef enum {
HB_OT_LAYOUT_BASELINE_TAG_ROMAN = HB_TAG ('r','o','m','n'),
HB_OT_LAYOUT_BASELINE_TAG_HANGING = HB_TAG ('h','a','n','g'),
HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT = HB_TAG ('i','c','f','b'),
HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT = HB_TAG ('i','c','f','t'),
HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT = HB_TAG ('i','d','e','o'),
HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT = HB_TAG ('i','d','t','p'),
HB_OT_LAYOUT_BASELINE_TAG_MATH = HB_TAG ('m','a','t','h'),
_HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
} hb_ot_layout_baseline_tag_t;
HB_EXTERN hb_bool_t
hb_ot_layout_get_baseline (hb_font_t *font,
hb_ot_layout_baseline_tag_t baseline_tag,
hb_direction_t direction,
hb_tag_t script_tag,
hb_tag_t language_tag,
hb_position_t *coord /* OUT. May be NULL. */);
HB_END_DECLS
#endif /* HB_OT_LAYOUT_H */

View File

@ -34,14 +34,12 @@ test_ot_layout_base (void)
hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf");
hb_font_t *font = hb_font_create (face);
#if 0
hb_position_t position;
g_assert (hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_ICFB, HB_DIRECTION_TTB,
g_assert (hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
HB_TAG ('h','a','n','i'),
HB_TAG ('E','N','G',' '),
&position));
g_assert_cmpint (46, ==, position);
#endif
hb_font_destroy (font);
hb_face_destroy (face);