From defc45be6d75aba4a67fa7814b91b73bad953fe6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 May 2011 20:02:49 -0400 Subject: [PATCH] [API] Add hb_font_create_sub_font() and hb_font_get_parent() Not quite useful just yet. --- src/hb-font-private.hh | 1 + src/hb-font.cc | 41 ++++++++++++++++++++++++++++++++++++++--- src/hb-font.h | 5 +++++ src/hb-unicode.h | 2 +- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 3c6cc1c..66ebfd8 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -82,6 +82,7 @@ struct _hb_font_t { hb_bool_t immutable; + hb_font_t *parent; hb_face_t *face; int x_scale; diff --git a/src/hb-font.cc b/src/hb-font.cc index 656b8ad..b189797 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -83,7 +83,7 @@ hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED, static hb_font_funcs_t _hb_font_funcs_nil = { HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + TRUE, /* immutable */ { hb_font_get_glyph_nil, hb_font_get_glyph_advance_nil, @@ -448,8 +448,9 @@ hb_face_get_upem (hb_face_t *face) static hb_font_t _hb_font_nil = { HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + TRUE, /* immutable */ + NULL, /* parent */ &_hb_face_nil, 0, /* x_scale */ @@ -458,7 +459,7 @@ static hb_font_t _hb_font_nil = { 0, /* x_ppem */ 0, /* y_ppem */ - NULL, /* klass */ + &_hb_font_funcs_nil, /* klass */ NULL, /* user_data */ NULL /* destroy */ }; @@ -482,6 +483,34 @@ hb_font_create (hb_face_t *face) } hb_font_t * +hb_font_create_sub_font (hb_font_t *parent) +{ + if (unlikely (!parent)) + return &_hb_font_nil; + + hb_font_t *font = hb_font_create (parent->face); + + if (unlikely (hb_object_is_inert (font))) + return font; + + hb_font_make_immutable (parent); + font->parent = hb_font_reference (parent); + + font->x_scale = parent->x_scale; + font->y_scale = parent->y_scale; + font->x_ppem = parent->x_ppem; + font->y_ppem = parent->y_ppem; + + /* We can safely copy user_data from parent since we hold a reference + * onto it and it's immutable. We should not copy the destroy notifiers + * though. */ + font->klass = hb_font_funcs_reference (parent->klass); + font->user_data = parent->user_data; + + return font; +} + +hb_font_t * hb_font_reference (hb_font_t *font) { return hb_object_reference (font); @@ -492,6 +521,7 @@ hb_font_destroy (hb_font_t *font) { if (!hb_object_destroy (font)) return; + hb_font_destroy (font->parent); hb_face_destroy (font->face); hb_font_funcs_destroy (font->klass); if (font->destroy) @@ -531,6 +561,11 @@ hb_font_is_immutable (hb_font_t *font) return font->immutable; } +hb_font_t * +hb_font_get_parent (hb_font_t *font) +{ + return font->parent; +} hb_face_t * hb_font_get_face (hb_font_t *font) diff --git a/src/hb-font.h b/src/hb-font.h index 358eee2..1ab22ec 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -209,6 +209,9 @@ hb_font_t * hb_font_create (hb_face_t *face); hb_font_t * +hb_font_create_sub_font (hb_font_t *parent); + +hb_font_t * hb_font_reference (hb_font_t *font); void @@ -231,6 +234,8 @@ hb_font_make_immutable (hb_font_t *font); hb_bool_t hb_font_is_immutable (hb_font_t *font); +hb_font_t * +hb_font_get_parent (hb_font_t *font); hb_face_t * hb_font_get_face (hb_font_t *font); diff --git a/src/hb-unicode.h b/src/hb-unicode.h index c7e35ba..388256f 100644 --- a/src/hb-unicode.h +++ b/src/hb-unicode.h @@ -51,7 +51,7 @@ hb_unicode_funcs_get_default (void); hb_unicode_funcs_t * -hb_unicode_funcs_create (hb_unicode_funcs_t *parent_funcs); +hb_unicode_funcs_create (hb_unicode_funcs_t *parent); hb_unicode_funcs_t * hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs); -- 2.7.4