From 3e905e396bcd745bda88e751998a76556c5cb8c6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 8 Oct 2015 12:51:02 -0400 Subject: [PATCH] Add hb_font_set_parent() No reason to not have it. Makes life easier later. We (hb-ft, hb-ot-font, etc) can use this API to inject new parent into a font... --- src/hb-font.cc | 26 ++++++++++++++++++++++++++ src/hb-font.h | 4 ++++ test/api/test-font.c | 12 ++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/hb-font.cc b/src/hb-font.cc index 058d7ec..6a69cae 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1059,6 +1059,32 @@ hb_font_is_immutable (hb_font_t *font) } /** + * hb_font_set_parent: + * @font: a font. + * @parent: new parent. + * + * Sets parent font of @font. + * + * Since: 1.0.5 + **/ +void +hb_font_set_parent (hb_font_t *font, + hb_font_t *parent) +{ + if (font->immutable) + return; + + if (!parent) + parent = hb_font_get_empty (); + + hb_font_t *old = font->parent; + + font->parent = hb_font_reference (parent); + + hb_font_destroy (old); +} + +/** * hb_font_get_parent: * @font: a font. * diff --git a/src/hb-font.h b/src/hb-font.h index ffb2010..fb4a0ea 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -459,6 +459,10 @@ hb_font_make_immutable (hb_font_t *font); hb_bool_t hb_font_is_immutable (hb_font_t *font); +void +hb_font_set_parent (hb_font_t *font, + hb_font_t *parent); + hb_font_t * hb_font_get_parent (hb_font_t *font); diff --git a/test/api/test-font.c b/test/api/test-font.c index 5afc885..ef5b08f 100644 --- a/test/api/test-font.c +++ b/test/api/test-font.c @@ -387,6 +387,18 @@ test_font_properties (void) g_assert (hb_font_get_face (font) == face); g_assert (hb_font_get_parent (font) == NULL); + subfont = hb_font_create_sub_font (font); + g_assert (hb_font_get_parent (subfont) == font); + hb_font_set_parent(subfont, NULL); + g_assert (hb_font_get_parent (subfont) == hb_font_get_empty()); + hb_font_set_parent(subfont, font); + g_assert (hb_font_get_parent (subfont) == font); + hb_font_set_parent(subfont, NULL); + hb_font_make_immutable (subfont); + g_assert (hb_font_get_parent (subfont) == hb_font_get_empty()); + hb_font_set_parent(subfont, font); + g_assert (hb_font_get_parent (subfont) == hb_font_get_empty()); + hb_font_destroy (subfont); /* Check scale */ -- 2.7.4