From 9f2b4956b484b802eb37f36974c11785c90493ce Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 30 Jul 2019 04:42:51 +0430 Subject: [PATCH] [base] Add hb_ot_layout_get_baseline API --- docs/harfbuzz-sections.txt | 2 + src/hb-ot-face-table-list.hh | 6 ++- src/hb-ot-layout.cc | 87 ++++++++++-------------------------- src/hb-ot-layout.h | 32 +++++++++++++ test/api/test-baseline.c | 4 +- 5 files changed, 63 insertions(+), 68 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 0bc2a2c9a..f8650b076 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -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 diff --git a/src/hb-ot-face-table-list.hh b/src/hb-ot-face-table-list.hh index 97fb765a2..9799eddb0 100644 --- a/src/hb-ot-face-table-list.hh +++ b/src/hb-ot-face-table-list.hh @@ -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) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 4cd65b4a9..666e1623e 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1940,75 +1940,34 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, apply_string (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 diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 3b9a78eaf..73254aa4e 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -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 */ diff --git a/test/api/test-baseline.c b/test/api/test-baseline.c index a120e14f3..982c68311 100644 --- a/test/api/test-baseline.c +++ b/test/api/test-baseline.c @@ -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);