From 3e110c69c45a0d4d453ca9db74848442b6670671 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 11:06:26 -0600 Subject: [PATCH 1/9] [layout] Add hb_ot_layout_get_font_extents() Untested. Fixes https://github.com/harfbuzz/harfbuzz/issues/3290 --- docs/harfbuzz-sections.txt | 1 + src/hb-ot-layout-base-table.hh | 3 +-- src/hb-ot-layout.cc | 21 +++++++++++++++++++++ src/hb-ot-layout.h | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index d41a8f851..b2743b60e 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -626,6 +626,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_font_extents hb_ot_layout_get_horizontal_baseline_tag_for_script hb_ot_layout_get_baseline hb_ot_layout_get_baseline_with_fallback diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 8179e5acd..07a0a3e54 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -473,14 +473,13 @@ struct BASE return true; } - /* TODO: Expose this separately sometime? */ bool get_min_max (hb_font_t *font, hb_direction_t direction, hb_tag_t script_tag, hb_tag_t language_tag, hb_tag_t feature_tag, hb_position_t *min, - hb_position_t *max) + hb_position_t *max) const { const BaseCoord *min_coord, *max_coord; if (!get_axis (direction).get_min_max (script_tag, language_tag, feature_tag, diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index c66ee8cfd..5cf0cb0a4 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2036,6 +2036,27 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, } #ifndef HB_NO_BASE + +hb_bool_t +hb_ot_layout_get_font_extents (hb_font_t *font, + hb_direction_t direction, + hb_tag_t script_tag, + hb_tag_t language_tag, + hb_font_extents_t *extents) +{ + hb_position_t min, max; + if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE, + &min, &max)) + { + extents->ascender = max; + extents->descender = min; + extents->line_gap = 0; + return true; + } + + return false; +} + /** * hb_ot_layout_get_horizontal_baseline_tag_for_script: * @script: a script tag. diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 10dcc65ac..bc3295eaa 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -447,6 +447,12 @@ hb_ot_layout_feature_get_characters (hb_face_t *face, * BASE */ +HB_EXTERN hb_bool_t +hb_ot_layout_get_font_extents (hb_font_t *font, + hb_direction_t direction, + hb_tag_t script_tag, + hb_tag_t language_tag, + hb_font_extents_t *extents); /** * hb_ot_layout_baseline_tag_t: * @HB_OT_LAYOUT_BASELINE_TAG_ROMAN: The baseline used by alphabetic scripts such as Latin, Cyrillic and Greek. From 0894813a38d7ba7db1e58c829be15fe4149811b3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 11:30:03 -0600 Subject: [PATCH 2/9] [layout] Add "2" version of BASE table API ...that do the script/language resolution. Part of https://github.com/harfbuzz/harfbuzz/pull/4237 Ref https://github.com/harfbuzz/harfbuzz/issues/3439 --- docs/harfbuzz-sections.txt | 3 + src/hb-ot-layout.cc | 109 +++++++++++++++++++++++++++++++++++-- src/hb-ot-layout.h | 32 +++++++++-- 3 files changed, 136 insertions(+), 8 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index b2743b60e..2c36b412c 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -627,9 +627,12 @@ 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_font_extents +hb_ot_layout_get_font_extents2 hb_ot_layout_get_horizontal_baseline_tag_for_script hb_ot_layout_get_baseline +hb_ot_layout_get_baseline2 hb_ot_layout_get_baseline_with_fallback +hb_ot_layout_get_baseline_with_fallback2 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-layout.cc b/src/hb-ot-layout.cc index 5cf0cb0a4..31bd0ea58 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2037,12 +2037,32 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, #ifndef HB_NO_BASE +static void +choose_base_tags (hb_script_t script, + hb_language_t language, + hb_tag_t *script_tag, + hb_tag_t *language_tag) +{ + hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT]; + unsigned script_count = ARRAY_LENGTH (script_tags); + + hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE]; + unsigned language_count = ARRAY_LENGTH (language_tags); + + hb_ot_tags_from_script_and_language (script, language, + &script_count, script_tags, + &language_count, language_tags); + + *script_tag = script_count ? script_tags[script_count - 1] : HB_OT_TAG_DEFAULT_SCRIPT; + *language_tag = language_count ? language_tags[language_count - 1] : HB_OT_TAG_DEFAULT_LANGUAGE; +} + hb_bool_t hb_ot_layout_get_font_extents (hb_font_t *font, - hb_direction_t direction, - hb_tag_t script_tag, - hb_tag_t language_tag, - hb_font_extents_t *extents) + hb_direction_t direction, + hb_tag_t script_tag, + hb_tag_t language_tag, + hb_font_extents_t *extents) { hb_position_t min, max; if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE, @@ -2057,6 +2077,22 @@ hb_ot_layout_get_font_extents (hb_font_t *font, return false; } +hb_bool_t +hb_ot_layout_get_font_extents2 (hb_font_t *font, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_font_extents_t *extents) +{ + hb_tag_t script_tag, language_tag; + choose_base_tags (script, language, &script_tag, &language_tag); + return hb_ot_layout_get_font_extents (font, + direction, + script_tag, + language_tag, + extents); +} + /** * hb_ot_layout_get_horizontal_baseline_tag_for_script: * @script: a script tag. @@ -2154,6 +2190,39 @@ hb_ot_layout_get_baseline (hb_font_t *font, return font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord); } +/** + * hb_ot_layout_get_baseline2: + * @font: a font + * @baseline_tag: a baseline tag + * @direction: text direction. + * @script: script. + * @language: language, currently unused. + * @coord: (out) (nullable): baseline value if found. + * + * Fetches a baseline value from the face. + * + * Return value: `true` if found baseline value in the font. + * + * XSince: REPLACEME + **/ +hb_bool_t +hb_ot_layout_get_baseline2 (hb_font_t *font, + hb_ot_layout_baseline_tag_t baseline_tag, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_position_t *coord /* OUT. May be NULL. */) +{ + hb_tag_t script_tag, language_tag; + choose_base_tags (script, language, &script_tag, &language_tag); + return hb_ot_layout_get_baseline (font, + baseline_tag, + direction, + script_tag, + language_tag, + coord); +} + /** * hb_ot_layout_get_baseline_with_fallback: * @font: a font @@ -2376,6 +2445,38 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, } } +/** + * hb_ot_layout_get_baseline_with_fallback2: + * @font: a font + * @baseline_tag: a baseline tag + * @direction: text direction. + * @script: script. + * @language: language, currently unused. + * @coord: (out): baseline value if found. + * + * Fetches a baseline value from the face, and synthesizes + * it if the font does not have it. + * + * XSince: REPLACEME + **/ +void +hb_ot_layout_get_baseline_with_fallback2 (hb_font_t *font, + hb_ot_layout_baseline_tag_t baseline_tag, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_position_t *coord /* OUT */) +{ + hb_tag_t script_tag, language_tag; + choose_base_tags (script, language, &script_tag, &language_tag); + hb_ot_layout_get_baseline_with_fallback (font, + baseline_tag, + direction, + script_tag, + language_tag, + coord); +} + #endif diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index bc3295eaa..b0fae3707 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -449,10 +449,18 @@ hb_ot_layout_feature_get_characters (hb_face_t *face, HB_EXTERN hb_bool_t hb_ot_layout_get_font_extents (hb_font_t *font, - hb_direction_t direction, - hb_tag_t script_tag, - hb_tag_t language_tag, - hb_font_extents_t *extents); + hb_direction_t direction, + hb_tag_t script_tag, + hb_tag_t language_tag, + hb_font_extents_t *extents); + +HB_EXTERN hb_bool_t +hb_ot_layout_get_font_extents2 (hb_font_t *font, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_font_extents_t *extents); + /** * hb_ot_layout_baseline_tag_t: * @HB_OT_LAYOUT_BASELINE_TAG_ROMAN: The baseline used by alphabetic scripts such as Latin, Cyrillic and Greek. @@ -505,6 +513,14 @@ hb_ot_layout_get_baseline (hb_font_t *font, hb_tag_t language_tag, hb_position_t *coord /* OUT. May be NULL. */); +HB_EXTERN hb_bool_t +hb_ot_layout_get_baseline2 (hb_font_t *font, + hb_ot_layout_baseline_tag_t baseline_tag, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_position_t *coord /* OUT. May be NULL. */); + HB_EXTERN void hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, hb_ot_layout_baseline_tag_t baseline_tag, @@ -513,6 +529,14 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, hb_tag_t language_tag, hb_position_t *coord /* OUT */); +HB_EXTERN void +hb_ot_layout_get_baseline_with_fallback2 (hb_font_t *font, + hb_ot_layout_baseline_tag_t baseline_tag, + hb_direction_t direction, + hb_script_t script, + hb_language_t language, + hb_position_t *coord /* OUT */); + HB_END_DECLS #endif /* HB_OT_LAYOUT_H */ From 792ca22ca3212dc5f69f3c85901f63b538ae00b5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 11:42:20 -0600 Subject: [PATCH 3/9] [layout] Document new API --- src/hb-ot-layout.cc | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 31bd0ea58..dd52699ff 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2057,6 +2057,21 @@ choose_base_tags (hb_script_t script, *language_tag = language_count ? language_tags[language_count - 1] : HB_OT_TAG_DEFAULT_LANGUAGE; } +/** + * hb_ot_layout_get_font_extents: + * @font: a font + * @direction: text direction. + * @script_tag: script tag. + * @language_tag: language tag. + * @extents: (out) (nullable): font extents if found. + * + * Fetches script/language-specific font extents. These values are + * looked up in the `BASE` table's `MinMax` records. + * + * Return value: `true` if found script/language-specific font extents. + * + * XSince: REPLACEME + **/ hb_bool_t hb_ot_layout_get_font_extents (hb_font_t *font, hb_direction_t direction, @@ -2068,15 +2083,33 @@ hb_ot_layout_get_font_extents (hb_font_t *font, if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE, &min, &max)) { - extents->ascender = max; - extents->descender = min; - extents->line_gap = 0; + if (extents) + { + extents->ascender = max; + extents->descender = min; + extents->line_gap = 0; + } return true; } return false; } +/** + * hb_ot_layout_get_font_extents2: + * @font: a font + * @direction: text direction. + * @script: script. + * @language: language. + * @extents: (out) (nullable): font extents if found. + * + * Fetches script/language-specific font extents. These values are + * looked up in the `BASE` table's `MinMax` records. + * + * Return value: `true` if found script/language-specific font extents. + * + * XSince: REPLACEME + **/ hb_bool_t hb_ot_layout_get_font_extents2 (hb_font_t *font, hb_direction_t direction, From 8ccc1ff21e404ab02f673a0727af58cbadc822a9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 13:14:57 -0600 Subject: [PATCH 4/9] [layout] Mark language as nullable GI needs it apparently. --- src/hb-ot-layout.cc | 6 +++--- src/hb-ot-tag.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index dd52699ff..1ef9ac50f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2100,7 +2100,7 @@ hb_ot_layout_get_font_extents (hb_font_t *font, * @font: a font * @direction: text direction. * @script: script. - * @language: language. + * @language: (nullable): language. * @extents: (out) (nullable): font extents if found. * * Fetches script/language-specific font extents. These values are @@ -2229,7 +2229,7 @@ hb_ot_layout_get_baseline (hb_font_t *font, * @baseline_tag: a baseline tag * @direction: text direction. * @script: script. - * @language: language, currently unused. + * @language: (nullable): language, currently unused. * @coord: (out) (nullable): baseline value if found. * * Fetches a baseline value from the face. @@ -2484,7 +2484,7 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, * @baseline_tag: a baseline tag * @direction: text direction. * @script: script. - * @language: language, currently unused. + * @language: (nullable): language, currently unused. * @coord: (out): baseline value if found. * * Fetches a baseline value from the face, and synthesizes diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 547f9573d..53b6b38f6 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -412,7 +412,7 @@ parse_private_use_subtag (const char *private_use_subtag, /** * hb_ot_tags_from_script_and_language: * @script: an #hb_script_t to convert. - * @language: an #hb_language_t to convert. + * @language: (nullable): an #hb_language_t to convert. * @script_count: (inout) (optional): maximum number of script tags to retrieve (IN) * and actual number of script tags retrieved (OUT) * @script_tags: (out) (optional): array of size at least @script_count to store the From 02e0e9394b42d8f5290a2e9699890b180c09d151 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 13:18:06 -0600 Subject: [PATCH 5/9] [layout] Fetch default font extents if localized extents not found --- src/hb-ot-layout.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 1ef9ac50f..bc0937e6b 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2068,6 +2068,12 @@ choose_base_tags (hb_script_t script, * Fetches script/language-specific font extents. These values are * looked up in the `BASE` table's `MinMax` records. * + * If no such extents are found, the default extents for the font are + * fetched. As such, the return value of this function can for the + * most part be ignored. Note that the per-script/language extents + * do not have a line-gap value, and the line-gap is set to zero in + * that case. + * * Return value: `true` if found script/language-specific font extents. * * XSince: REPLACEME @@ -2092,6 +2098,7 @@ hb_ot_layout_get_font_extents (hb_font_t *font, return true; } + hb_font_get_extents_for_direction (font, direction, extents); return false; } @@ -2106,6 +2113,12 @@ hb_ot_layout_get_font_extents (hb_font_t *font, * Fetches script/language-specific font extents. These values are * looked up in the `BASE` table's `MinMax` records. * + * If no such extents are found, the default extents for the font are + * fetched. As such, the return value of this function can for the + * most part be ignored. Note that the per-script/language extents + * do not have a line-gap value, and the line-gap is set to zero in + * that case. + * * Return value: `true` if found script/language-specific font extents. * * XSince: REPLACEME From 6996e64f72896ee1d210f5fdc5fea143590f9f3f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 14:22:13 -0600 Subject: [PATCH 6/9] [BASE] Sanitize and get_min_max fixups Seems to work now. --- src/hb-ot-layout-base-table.hh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 07a0a3e54..2b7e9e4b1 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -170,8 +170,8 @@ struct FeatMinMaxRecord { TRACE_SANITIZE (this); return_trace (likely (c->check_struct (this) && - minCoord.sanitize (c, this) && - maxCoord.sanitize (c, this))); + minCoord.sanitize (c, base) && + maxCoord.sanitize (c, base))); } protected: @@ -187,7 +187,6 @@ struct FeatMinMaxRecord * of MinMax table (may be NULL) */ public: DEFINE_SIZE_STATIC (8); - }; struct MinMax @@ -274,7 +273,7 @@ struct BaseLangSysRecord { TRACE_SANITIZE (this); return_trace (likely (c->check_struct (this) && - minMax.sanitize (c, this))); + minMax.sanitize (c, base))); } protected: @@ -297,7 +296,8 @@ struct BaseScript const BaseCoord &get_base_coord (int baseline_tag_index) const { return (this+baseValues).get_base_coord (baseline_tag_index); } - bool has_data () const { return baseValues; } + bool has_values () const { return baseValues; } + bool has_min_max () const { return defaultMinMax; /* TODO What if only per-language is present? */ } bool sanitize (hb_sanitize_context_t *c) const { @@ -383,7 +383,7 @@ struct Axis const BaseCoord **coord) const { const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag); - if (!base_script.has_data ()) + if (!base_script.has_values ()) { *coord = nullptr; return false; @@ -410,7 +410,7 @@ struct Axis const BaseCoord **max_coord) const { const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag); - if (!base_script.has_data ()) + if (!base_script.has_min_max ()) { *min_coord = *max_coord = nullptr; return false; @@ -425,8 +425,8 @@ struct Axis { TRACE_SANITIZE (this); return_trace (likely (c->check_struct (this) && - (this+baseTagList).sanitize (c) && - (this+baseScriptList).sanitize (c))); + baseTagList.sanitize (c, this) && + baseScriptList.sanitize (c, this))); } protected: From 132391ad62b90c27a95429b81a27febf4b183a37 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 19 May 2023 15:01:49 -0600 Subject: [PATCH 7/9] [layout] Add test for font_extents --- test/api/Makefile.am | 1 + test/api/fonts/base-minmax.ttf | Bin 0 -> 352 bytes test/api/meson.build | 1 + test/api/test-base-minmax.c | 66 +++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 test/api/fonts/base-minmax.ttf create mode 100644 test/api/test-base-minmax.c diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 950b738a0..efeecb4e0 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -33,6 +33,7 @@ noinst_PROGRAMS = $(TEST_PROGS) TEST_PROGS = \ test-aat-layout \ test-baseline \ + test-base-minmax \ test-be-glyph-advance \ test-be-num-glyphs \ test-blob \ diff --git a/test/api/fonts/base-minmax.ttf b/test/api/fonts/base-minmax.ttf new file mode 100644 index 0000000000000000000000000000000000000000..9661b59ad4a3e58bd83baa64152701062ef3f724 GIT binary patch literal 352 zcmZQzWME)mWpH3%Vi0h040bJPEed5|V6*^=YWN518wqUteF(_D0mKOzsfj7FhI<@= z>=+<6%K!=}TC%+cvZnyCN^W9B0rMFi8z6fJ5Gyc%%w}S63i_AF7SC_>MDRR= zn9VqYL4eVofgR*}pdT_B7?{mCl^B?Tvdk<^j1z!9V_==dY78_|6+$yFVlZO(#R1g7 z$_zA!iGjJ1K`Z|PLxLBO2X>x^Z?FQ;EQSAnAa3B^!TC*rk@3HR2GH~<);~aX3P61z fmqNV5!oZl5Sds_ku>nQd7`T8W<3An-M)nH;&wxIc literal 0 HcmV?d00001 diff --git a/test/api/meson.build b/test/api/meson.build index ab2ab1e1d..64d7797ef 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -6,6 +6,7 @@ endif tests = [ 'test-aat-layout.c', 'test-baseline.c', + 'test-base-minmax.c', 'test-be-glyph-advance.c', 'test-be-num-glyphs.c', 'test-blob.c', diff --git a/test/api/test-base-minmax.c b/test/api/test-base-minmax.c new file mode 100644 index 000000000..332c2668d --- /dev/null +++ b/test/api/test-base-minmax.c @@ -0,0 +1,66 @@ +/* + * Copyright © 2023 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#include "hb-test.h" + +#include + +/* Unit tests for hb-ot-layout.h font extents */ + +static void +test_ot_layout_font_extents (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/base-minmax.ttf"); + hb_font_t *font = hb_font_create (face); + + hb_font_extents_t extents; + + g_assert (hb_ot_layout_get_font_extents2 (font, HB_DIRECTION_LTR, + HB_SCRIPT_LATIN, HB_LANGUAGE_INVALID, + &extents)); + g_assert_cmpint (extents.ascender, ==, 2000); + + g_assert (hb_ot_layout_get_font_extents2 (font, HB_DIRECTION_LTR, + HB_SCRIPT_LATIN, hb_language_from_string ("xx", -1), + &extents)); + g_assert_cmpint (extents.ascender, ==, 2000); + + g_assert (!hb_ot_layout_get_font_extents2 (font, HB_DIRECTION_LTR, + HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, + &extents)); + g_assert_cmpint (extents.ascender, ==, 3000); + + hb_font_destroy (font); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_ot_layout_font_extents); + + return hb_test_run(); +} From e047b1abbcb7edc9c4a5263b524a9a52f6a6198d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 20 May 2023 10:27:31 -0600 Subject: [PATCH 8/9] [layout] Improve docs --- src/hb-ot-layout.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index bc0937e6b..cbc694ef9 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2119,6 +2119,9 @@ hb_ot_layout_get_font_extents (hb_font_t *font, * do not have a line-gap value, and the line-gap is set to zero in * that case. * + * This function is like hb_ot_layout_get_font_extents() but takes + * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. + * * Return value: `true` if found script/language-specific font extents. * * XSince: REPLACEME @@ -2247,6 +2250,9 @@ hb_ot_layout_get_baseline (hb_font_t *font, * * Fetches a baseline value from the face. * + * This function is like hb_ot_layout_get_baseline() but takes + * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. + * * Return value: `true` if found baseline value in the font. * * XSince: REPLACEME @@ -2503,6 +2509,9 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, * Fetches a baseline value from the face, and synthesizes * it if the font does not have it. * + * This function is like hb_ot_layout_get_baseline_with_fallback() but takes + * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. + * * XSince: REPLACEME **/ void From 0d354e0442d12b71aec58ac83e7b6ede377c263e Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 21 May 2023 19:01:04 +0300 Subject: [PATCH 9/9] [layout] Add tests for baseline 2 APIs --- test/api/test-baseline.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/api/test-baseline.c b/test/api/test-baseline.c index 9f9542ea4..4e02cd0e2 100644 --- a/test/api/test-baseline.c +++ b/test/api/test-baseline.c @@ -41,6 +41,12 @@ test_ot_layout_base (void) &position)); g_assert_cmpint (46, ==, position); + g_assert (hb_ot_layout_get_baseline2 (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB, + HB_SCRIPT_HAN, + hb_language_from_string ("en", -1), + &position)); + g_assert_cmpint (46, ==, position); + g_assert (!hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, HB_DIRECTION_TTB, HB_TAG ('h','a','n','i'), HB_TAG ('E','N','G',' '), @@ -63,6 +69,12 @@ test_ot_layout_base_with_fallback (void) &position); g_assert_cmpint (46, ==, position); + hb_ot_layout_get_baseline_with_fallback2 (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB, + HB_SCRIPT_HAN, + hb_language_from_string ("en", -1), + &position); + g_assert_cmpint (46, ==, position); + hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, HB_DIRECTION_TTB, HB_TAG ('h','a','n','i'), HB_TAG ('E','N','G',' '),