diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 22e41e24a..45a47842b 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2197,16 +2197,16 @@ hb_ot_layout_get_font_extents (hb_font_t *font, hb_tag_t language_tag, hb_font_extents_t *extents) { + hb_font_extents_t unused; + if (!extents) extents = &unused; + hb_position_t min = 0, max = 0; if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE, &min, &max)) { - if (extents) - { - extents->ascender = max; - extents->descender = min; - extents->line_gap = 0; - } + extents->ascender = max; + extents->descender = min; + extents->line_gap = 0; return true; } diff --git a/src/hb-ot-metrics.cc b/src/hb-ot-metrics.cc index d2bfa0294..69196e3c8 100644 --- a/src/hb-ot-metrics.cc +++ b/src/hb-ot-metrics.cc @@ -266,12 +266,15 @@ hb_ot_metrics_get_position (hb_font_t *font, void hb_ot_metrics_get_position_with_fallback (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag, - hb_position_t *position /* OUT */) + hb_position_t *position /* OUT. May be NULL. */) { hb_font_extents_t font_extents; hb_codepoint_t glyph; hb_glyph_extents_t extents; + hb_position_t unused; + if (!position) position = &unused; + if (hb_ot_metrics_get_position (font, metrics_tag, position)) { if ((metrics_tag != HB_OT_METRICS_TAG_STRIKEOUT_SIZE && diff --git a/src/hb-ot-metrics.h b/src/hb-ot-metrics.h index 30de50008..9c938b67d 100644 --- a/src/hb-ot-metrics.h +++ b/src/hb-ot-metrics.h @@ -113,7 +113,7 @@ hb_ot_metrics_get_position (hb_font_t *font, HB_EXTERN void hb_ot_metrics_get_position_with_fallback (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag, - hb_position_t *position /* OUT */); + hb_position_t *position /* OUT. May be NULL. */); HB_EXTERN float hb_ot_metrics_get_variation (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag); diff --git a/test/api/test-base-minmax.c b/test/api/test-base-minmax.c index c5632ca73..d9651a50f 100644 --- a/test/api/test-base-minmax.c +++ b/test/api/test-base-minmax.c @@ -51,6 +51,14 @@ test_ot_layout_font_extents (void) &extents)); g_assert_cmpint (extents.ascender, ==, 3000); + /* NULL extents is allowed on both the hit and the miss path. */ + g_assert_true (hb_ot_layout_get_font_extents2 (font, HB_DIRECTION_LTR, + HB_SCRIPT_LATIN, HB_LANGUAGE_INVALID, + NULL)); + g_assert_true (!hb_ot_layout_get_font_extents2 (font, HB_DIRECTION_LTR, + HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, + NULL)); + hb_font_destroy (font); hb_face_destroy (face); } diff --git a/test/api/test-ot-metrics.c b/test/api/test-ot-metrics.c index 675f588de..0df8ead94 100644 --- a/test/api/test-ot-metrics.c +++ b/test/api/test-ot-metrics.c @@ -94,6 +94,27 @@ test_ot_metrics_get_with_fallback (void) hb_face_destroy (face); } +static void +test_ot_metrics_get_position_with_fallback_null (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v0.ttf"); + hb_font_t *font = hb_font_create (face); + hb_position_t value; + + /* position may be NULL whether the metric is found, found but zero, or synthesized. */ + g_assert_true (hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, NULL)); + hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, NULL); + hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_UNDERLINE_SIZE, NULL); + hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_VERTICAL_ASCENDER, NULL); + hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_X_HEIGHT, NULL); + + hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, &value); + g_assert_cmpint (value, ==, 1000); + + hb_font_destroy (font); + hb_face_destroy (face); +} + int main (int argc, char **argv) { @@ -101,5 +122,6 @@ main (int argc, char **argv) hb_test_add (test_ot_metrics_get_no_var); hb_test_add (test_ot_metrics_get_var); hb_test_add (test_ot_metrics_get_with_fallback); + hb_test_add (test_ot_metrics_get_position_with_fallback_null); return hb_test_run (); }