[API] Add hb_font_create_sub_font() and hb_font_get_parent()
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 00:02:49 +0000 (20:02 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 00:02:49 +0000 (20:02 -0400)
Not quite useful just yet.

src/hb-font-private.hh
src/hb-font.cc
src/hb-font.h
src/hb-unicode.h

index 3c6cc1c..66ebfd8 100644 (file)
@@ -82,6 +82,7 @@ struct _hb_font_t {
 
   hb_bool_t immutable;
 
+  hb_font_t *parent;
   hb_face_t *face;
 
   int x_scale;
index 656b8ad..b189797 100644 (file)
@@ -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)
index 358eee2..1ab22ec 100644 (file)
@@ -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);
index c7e35ba..388256f 100644 (file)
@@ -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);