Start adding a unified shaper access infrastructure
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 26 Jul 2012 21:34:25 +0000 (17:34 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 27 Jul 2012 01:14:02 +0000 (21:14 -0400)
Add global shape_plan.  Unused so far.

17 files changed:
src/Makefile.am
src/hb-coretext-private.hh [deleted file]
src/hb-coretext.cc
src/hb-fallback-shape.cc
src/hb-font-private.hh
src/hb-font.cc
src/hb-old.cc
src/hb-ot-shape-private.hh
src/hb-ot-shape.cc
src/hb-shape-plan-private.hh [moved from src/hb-graphite2-private.hh with 71% similarity]
src/hb-shape-plan.cc [new file with mode: 0644]
src/hb-shape-plan.h [moved from src/hb-fallback-shape-private.hh with 58% similarity]
src/hb-shape.cc
src/hb-shaper-impl-private.hh [moved from src/hb-uniscribe-private.hh with 74% similarity]
src/hb-shaper-list.hh [moved from src/hb-old-private.hh with 67% similarity]
src/hb-shaper-private.hh [new file with mode: 0644]
src/hb-uniscribe.cc

index b1255fa..847c9e7 100644 (file)
@@ -24,7 +24,6 @@ HBSOURCES =  \
        hb-buffer.cc \
        hb-cache-private.hh \
        hb-common.cc \
-       hb-fallback-shape-private.hh \
        hb-fallback-shape.cc \
        hb-font-private.hh \
        hb-font.cc \
@@ -42,6 +41,12 @@ HBSOURCES =  \
        hb-set-private.hh \
        hb-set.cc \
        hb-shape.cc \
+       hb-shape-plan-private.hh \
+       hb-shape-plan.cc \
+       hb-shape-plan.h \
+       hb-shaper-list.hh \
+       hb-shaper-impl-private.hh \
+       hb-shaper-private.hh \
        hb-tt-font.cc \
        hb-unicode-private.hh \
        hb-unicode.cc \
@@ -129,21 +134,21 @@ endif
 if HAVE_GRAPHITE2
 HBCFLAGS += $(GRAPHITE2_CFLAGS)
 HBLIBS   += $(GRAPHITE2_LIBS)
-HBSOURCES += hb-graphite2.cc hb-graphite2-private.hh
+HBSOURCES += hb-graphite2.cc
 HBHEADERS += hb-graphite2.h
 endif
 
 if HAVE_UNISCRIBE
 HBCFLAGS += $(UNISCRIBE_CFLAGS)
 HBLIBS   += $(UNISCRIBE_LIBS)
-HBSOURCES += hb-uniscribe.cc hb-uniscribe-private.hh
+HBSOURCES += hb-uniscribe.cc
 HBHEADERS += hb-uniscribe.h
 endif
 
 if HAVE_CORETEXT
 HBCFLAGS += $(CORETEXT_CFLAGS)
 HBLIBS   += $(CORETEXT_LIBS)
-HBSOURCES += hb-coretext.cc hb-coretext-private.hh
+HBSOURCES += hb-coretext.cc
 HBHEADERS += hb-coretext.h
 endif
 
@@ -151,7 +156,7 @@ if HAVE_HB_OLD
 SUBDIRS += hb-old
 HBCFLAGS += -I$(srcdir)/hb-old
 HBLIBS   += hb-old/libhb-old.la
-HBSOURCES += hb-old.cc hb-old-private.hh
+HBSOURCES += hb-old.cc
 endif
 DIST_SUBDIRS += hb-old
 
diff --git a/src/hb-coretext-private.hh b/src/hb-coretext-private.hh
deleted file mode 100644 (file)
index 153106c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2012  Mozilla Foundation.
- *
- *  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.
- *
- * Mozilla Author(s): Jonathan Kew
- */
-
-#ifndef HB_CORETEXT_PRIVATE_HH
-#define HB_CORETEXT_PRIVATE_HH
-
-#include "hb-private.hh"
-
-#include "hb-coretext.h"
-
-
-HB_INTERNAL hb_bool_t
-_hb_coretext_shape (hb_font_t          *font,
-                    hb_buffer_t        *buffer,
-                    const hb_feature_t *features,
-                    unsigned int        num_features);
-
-
-#endif /* HB_CORETEXT_PRIVATE_HH */
index c99ffc4..6e09c5e 100644 (file)
@@ -24,7 +24,8 @@
  * Mozilla Author(s): Jonathan Kew
  */
 
-#include "hb-private.hh"
+#define HB_SHAPER coretext
+#include "hb-shaper-private.hh"
 
 #define GlyphID GlyphID_mac
 #include <ApplicationServices/ApplicationServices.h>
@@ -32,9 +33,6 @@
 
 #include "hb-coretext.h"
 
-#include "hb-ot-name-table.hh"
-#include "hb-ot-tag.h"
-
 #include "hb-font-private.hh"
 #include "hb-buffer-private.hh"
 
index b9480e6..4c9a3b3 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
-#include "hb-fallback-shape-private.hh"
+#define HB_SHAPER fallback
+#include "hb-shaper-impl-private.hh"
 
-#include "hb-buffer-private.hh"
+
+/*
+ * shaper face data
+ */
+
+struct hb_fallback_shaper_face_data_t {};
+
+hb_fallback_shaper_face_data_t *
+_hb_fallback_shaper_face_data_create (hb_face_t *face)
+{
+  return (hb_fallback_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_fallback_shaper_face_data_destroy (hb_fallback_shaper_face_data_t *data)
+{
+}
+
+
+/*
+ * shaper font data
+ */
+
+struct hb_fallback_shaper_font_data_t {};
+
+hb_fallback_shaper_font_data_t *
+_hb_fallback_shaper_font_data_create (hb_font_t *font)
+{
+  return (hb_fallback_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_fallback_shaper_font_data_destroy (hb_fallback_shaper_font_data_t *data)
+{
+}
+
+
+/*
+ * shaper shape_plan data
+ */
+
+struct hb_fallback_shaper_shape_plan_data_t {};
+
+hb_fallback_shaper_shape_plan_data_t *
+_hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan)
+{
+  return (hb_fallback_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shaper_shape_plan_data_t *data)
+{
+}
+
+
+/*
+ * shaper
+ */
 
 hb_bool_t
 _hb_fallback_shape (hb_font_t          *font,
index 2f74cfa..97a86d5 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "hb-font.h"
 #include "hb-object-private.hh"
+#include "hb-shaper-private.hh"
 
 
 
@@ -100,8 +101,14 @@ struct hb_face_t {
 
   unsigned int index;
   unsigned int upem;
+
+  struct hb_shaper_data_t shaper_data;
 };
 
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
 
 /*
  * hb_font_t
@@ -126,6 +133,8 @@ struct hb_font_t {
   void              *user_data;
   hb_destroy_func_t  destroy;
 
+  struct hb_shaper_data_t shaper_data;
+
 
   /* Convert from font-space to user-space */
   inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
@@ -163,6 +172,9 @@ struct hb_font_t {
   inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / hb_face_get_upem (this->face); }
 };
 
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
 
 
 #endif /* HB_FONT_PRIVATE_HH */
index 7c62fbe..1261077 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2009  Red Hat, Inc.
+ * Copyright © 2012  Google, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -22,6 +23,7 @@
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  *
  * Red Hat Author(s): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod
  */
 
 #include "hb-private.hh"
@@ -707,6 +709,10 @@ hb_face_destroy (hb_face_t *face)
 
   _hb_ot_layout_destroy (face->ot_layout);
 
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, face);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
   if (face->destroy)
     face->destroy (face->user_data);
 
@@ -888,11 +894,16 @@ hb_font_destroy (hb_font_t *font)
 {
   if (!hb_object_destroy (font)) return;
 
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
+  if (font->destroy)
+    font->destroy (font->user_data);
+
   hb_font_destroy (font->parent);
   hb_face_destroy (font->face);
   hb_font_funcs_destroy (font->klass);
-  if (font->destroy)
-    font->destroy (font->user_data);
 
   free (font);
 }
index be0187f..b898b3f 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
-#include "hb-private.hh"
-
-#include "hb-old-private.hh"
-
-#include "hb-font-private.hh"
-#include "hb-buffer-private.hh"
+#define HB_SHAPER old
+#define hb_old_shaper_face_data_t HB_FaceRec_
+#define hb_old_shaper_font_data_t HB_Font_
+#include "hb-shaper-impl-private.hh"
 
 #include <harfbuzz.h>
 
@@ -166,8 +164,6 @@ static const HB_FontClass hb_old_font_class = {
 
 
 
-static hb_user_data_key_t hb_old_data_key;
-
 static HB_Error
 table_func (void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length)
 {
@@ -180,13 +176,86 @@ table_func (void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length)
  return HB_Err_Ok;
 }
 
+
+/*
+ * shaper face data
+ */
+
+hb_old_shaper_face_data_t *
+_hb_old_shaper_face_data_create (hb_face_t *face)
+{
+  return HB_NewFace (face, table_func);
+}
+
+void
+_hb_old_shaper_face_data_destroy (hb_old_shaper_face_data_t *data)
+{
+  HB_FreeFace (data);
+}
+
+
+/*
+ * shaper font data
+ */
+
+hb_old_shaper_font_data_t *
+_hb_old_shaper_font_data_create (hb_font_t *font)
+{
+  HB_FontRec *data = (HB_FontRec *) calloc (1, sizeof (HB_FontRec));
+  if (unlikely (!data)) {
+    DEBUG_MSG (OLD, font, "malloc()ing HB_Font failed");
+    return NULL;
+  }
+
+  data->klass = &hb_old_font_class;
+  data->x_ppem = font->x_ppem;
+  data->y_ppem = font->y_ppem;
+  data->x_scale = font->x_scale; // XXX
+  data->y_scale = font->y_scale; // XXX
+  data->userData = font;
+
+  return data;
+}
+
+void
+_hb_old_shaper_font_data_destroy (hb_old_shaper_font_data_t *data)
+{
+  free (data);
+}
+
+
+/*
+ * shaper shape_plan data
+ */
+
+struct hb_old_shaper_shape_plan_data_t {};
+
+hb_old_shaper_shape_plan_data_t *
+_hb_old_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan)
+{
+  return (hb_old_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_old_shaper_shape_plan_data_destroy (hb_old_shaper_shape_plan_data_t *data)
+{
+}
+
+
+/*
+ * shaper
+ */
+
+
+static hb_user_data_key_t hb_old_data_key;
+
 static HB_Face
 _hb_old_face_get (hb_face_t *face)
 {
   HB_Face data = (HB_Face) hb_face_get_user_data (face, &hb_old_data_key);
   if (likely (data)) return data;
 
-  data = HB_NewFace (face, table_func);
+  data = _hb_old_shaper_face_data_create (face);
 
   if (unlikely (!data)) {
     DEBUG_MSG (OLD, face, "HB_NewFace failed");
@@ -194,10 +263,10 @@ _hb_old_face_get (hb_face_t *face)
   }
 
   if (unlikely (!hb_face_set_user_data (face, &hb_old_data_key, data,
-                                        (hb_destroy_func_t) HB_FreeFace,
+                                        (hb_destroy_func_t) _hb_old_shaper_face_data_destroy,
                                         false)))
   {
-    HB_FreeFace (data);
+    _hb_old_shaper_face_data_destroy (data);
     data = (HB_Face) hb_face_get_user_data (face, &hb_old_data_key);
     if (data)
       return data;
@@ -212,24 +281,16 @@ _hb_old_face_get (hb_face_t *face)
 static HB_Font
 _hb_old_font_get (hb_font_t *font)
 {
-  HB_Font data = (HB_Font) calloc (1, sizeof (HB_FontRec));
-  if (unlikely (!data)) {
-    DEBUG_MSG (OLD, font, "malloc()ing HB_Font failed");
+  /* Ouch, check user_data! */
+  HB_Font data = _hb_old_shaper_font_data_create (font);
+  if (!data)
     return NULL;
-  }
-
-  data->klass = &hb_old_font_class;
-  data->x_ppem = font->x_ppem;
-  data->y_ppem = font->y_ppem;
-  data->x_scale = font->x_scale; // XXX
-  data->y_scale = font->y_scale; // XXX
-  data->userData = font;
 
   if (unlikely (!hb_font_set_user_data (font, &hb_old_data_key, data,
-                                        (hb_destroy_func_t) free,
+                                        (hb_destroy_func_t) _hb_old_shaper_font_data_destroy,
                                         false)))
   {
-    free (data);
+    _hb_old_shaper_font_data_destroy (data);
     data = (HB_Font) hb_font_get_user_data (font, &hb_old_data_key);
     if (data)
       return data;
index df0c705..8c8876a 100644 (file)
@@ -46,14 +46,6 @@ struct hb_ot_shape_plan_t
 };
 
 
-
-HB_INTERNAL hb_bool_t
-_hb_ot_shape (hb_font_t          *font,
-             hb_buffer_t        *buffer,
-             const hb_feature_t *features,
-             unsigned int        num_features);
-
-
 inline void
 _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode)
 {
index 3b1c1d7..512ffa5 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
+#define HB_SHAPER ot
+#define hb_ot_shaper_face_data_t hb_ot_layout_t
+#include "hb-shaper-impl-private.hh"
+
 #include "hb-ot-shape-private.hh"
 #include "hb-ot-shape-normalize-private.hh"
 
 #include "hb-ot-layout-private.hh"
-#include "hb-font-private.hh"
 #include "hb-set-private.hh"
 
 
+/*
+ * shaper face data
+ */
+
+hb_ot_shaper_face_data_t *
+_hb_ot_shaper_face_data_create (hb_face_t *face)
+{
+  return (hb_ot_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
+{
+}
+
+
+/*
+ * shaper font data
+ */
+
+struct hb_ot_shaper_font_data_t {};
+
+hb_ot_shaper_font_data_t *
+_hb_ot_shaper_font_data_create (hb_font_t *font)
+{
+  return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data)
+{
+}
+
+
+/*
+ * shaper shape_plan data
+ */
+
+struct hb_ot_shaper_shape_plan_data_t {};
+
+hb_ot_shaper_shape_plan_data_t *
+_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan)
+{
+  return (hb_ot_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *data)
+{
+}
+
+
+/*
+ * shaper
+ */
 
 hb_tag_t common_features[] = {
   HB_TAG('c','c','m','p'),
similarity index 71%
rename from src/hb-graphite2-private.hh
rename to src/hb-shape-plan-private.hh
index 644ea75..1f54608 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
-#ifndef HB_GRAPHITE2_PRIVATE_HH
-#define HB_GRAPHITE2_PRIVATE_HH
+#ifndef HB_SHAPE_PLAN_PRIVATE_HH
+#define HB_SHAPE_PLAN_PRIVATE_HH
 
 #include "hb-private.hh"
 
-#include "hb-graphite2.h"
+#include "hb-shape-plan.h"
 
+#include "hb-shaper-private.hh"
 
-HB_INTERNAL hb_bool_t
-_hb_graphite2_shape (hb_font_t          *font,
-                    hb_buffer_t        *buffer,
-                    const hb_feature_t *features,
-                    unsigned int        num_features);
 
+struct hb_shape_plan_t
+{
+  hb_object_header_t header;
+  ASSERT_POD ();
 
-#endif /* HB_GRAPHITE2_PRIVATE_HH */
+  hb_shape_func_t *shapers[HB_NUM_SHAPERS];
+
+  struct hb_shaper_data_t shaper_data;
+};
+
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, shape_plan);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
+
+#endif /* HB_SHAPE_PLAN_PRIVATE_HH */
diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc
new file mode 100644 (file)
index 0000000..b96d5f2
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2012  Google, Inc.
+ *
+ *  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.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#include "hb-private.hh"
+
+#include "hb-shape-plan-private.hh"
+
+#include "hb-font-private.hh"
+
+
+/*
+ * hb_shape_plan_t
+ */
+
+hb_shape_plan_t *
+hb_shape_plan_create (hb_face_t                     *face,
+                     const hb_segment_properties_t *props,
+                     const hb_feature_t            *user_features,
+                     unsigned int                   num_user_features,
+                     const char * const            *shaper_list)
+{
+  hb_shape_plan_t *shape_plan;
+
+  if (unlikely (!face))
+    face = hb_face_get_empty ();
+  if (unlikely (!props || hb_object_is_inert (face)))
+    return hb_shape_plan_get_empty ();
+  if (!(shape_plan = hb_object_create<hb_shape_plan_t> ()))
+    return hb_shape_plan_get_empty ();
+
+  hb_face_make_immutable (face);
+
+  return shape_plan;
+}
+
+hb_shape_plan_t *
+hb_shape_plan_get_empty (void)
+{
+  static const hb_shape_plan_t _hb_shape_plan_nil = {
+    HB_OBJECT_HEADER_STATIC,
+  };
+
+  return const_cast<hb_shape_plan_t *> (&_hb_shape_plan_nil);
+}
+
+hb_shape_plan_t *
+hb_shape_plan_reference (hb_shape_plan_t *shape_plan)
+{
+  return hb_object_reference (shape_plan);
+}
+
+void
+hb_shape_plan_destroy (hb_shape_plan_t *shape_plan)
+{
+  if (!hb_object_destroy (shape_plan)) return;
+
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, shape_plan);
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
+  free (shape_plan);
+}
similarity index 58%
rename from src/hb-fallback-shape-private.hh
rename to src/hb-shape-plan.h
index 0ef155c..5160b95 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2011  Google, Inc.
+ * Copyright © 2012  Google, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
  * Google Author(s): Behdad Esfahbod
  */
 
-#ifndef HB_FALLBACK_SHAPE_PRIVATE_HH
-#define HB_FALLBACK_SHAPE_PRIVATE_HH
+#ifndef HB_SHAPE_PLAN_H
+#define HB_SHAPE_PLAN_H
+
+/* TODO To become public one day */
 
 #include "hb-private.hh"
 
-#include "hb-shape.h"
+#include "hb-buffer-private.hh"
+
+
+typedef struct hb_shape_plan_t hb_shape_plan;
+
+/*
+ * hb_shape_plan_t
+ */
+
+HB_INTERNAL hb_shape_plan_t *
+hb_shape_plan_create (hb_face_t                     *face,
+                     const hb_segment_properties_t *props,
+                     const hb_feature_t            *user_features,
+                     unsigned int                   num_user_features,
+                     const char * const            *shaper_list);
+
+HB_INTERNAL hb_shape_plan_t *
+hb_shape_plan_get_empty (void);
+
+HB_INTERNAL hb_shape_plan_t *
+hb_shape_plan_reference (hb_shape_plan_t *shape_plan);
 
+HB_INTERNAL void
+hb_shape_plan_destroy (hb_shape_plan_t *shape_plan);
 
-HB_INTERNAL hb_bool_t
-_hb_fallback_shape (hb_font_t          *font,
-                   hb_buffer_t        *buffer,
-                   const hb_feature_t *features,
-                   unsigned int        num_features);
 
-#endif /* HB_FALLBACK_SHAPE_PRIVATE_HH */
+#endif /* HB_SHAPE_PLAN_H */
index da7d9e0..a1f3402 100644 (file)
 
 #include "hb-private.hh"
 
-#include "hb-shape.h"
-
+#include "hb-shaper-private.hh"
 #include "hb-buffer-private.hh"
 
-#ifdef HAVE_GRAPHITE
-#include "hb-graphite2-private.hh"
-#endif
-#ifdef HAVE_UNISCRIBE
-# include "hb-uniscribe-private.hh"
-#endif
-#ifdef HAVE_CORETEXT
-# include "hb-coretext-private.hh"
-#endif
-#ifdef HAVE_HB_OLD
-# include "hb-old-private.hh"
-#endif
-#ifdef HAVE_OT
-# include "hb-ot-shape-private.hh"
-#endif
-#include "hb-fallback-shape-private.hh"
-
-typedef hb_bool_t (*hb_shape_func_t) (hb_font_t          *font,
-                                     hb_buffer_t        *buffer,
-                                     const hb_feature_t *features,
-                                     unsigned int        num_features);
 
-#define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape}
 static const struct hb_shaper_pair_t {
   char name[16];
-  hb_shape_func_t func;
+  hb_shape_func_t *func;
 } all_shapers[] = {
-  /* v--- Add new shapers in the right place here */
-#ifdef HAVE_GRAPHITE
-  HB_SHAPER_IMPLEMENT (graphite2),
-#endif
-#ifdef HAVE_UNISCRIBE
-  HB_SHAPER_IMPLEMENT (uniscribe),
-#endif
-#ifdef HAVE_CORETEXT
-  HB_SHAPER_IMPLEMENT (coretext),
-#endif
-#ifdef HAVE_OT
-  HB_SHAPER_IMPLEMENT (ot),
-#endif
-#ifdef HAVE_HB_OLD
-  HB_SHAPER_IMPLEMENT (old),
-#endif
-  HB_SHAPER_IMPLEMENT (fallback), /* This should be last. */
-};
+#define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape},
+#include "hb-shaper-list.hh"
 #undef HB_SHAPER_IMPLEMENT
+};
 
 
 /* Thread-safe, lock-free, shapers */
similarity index 74%
rename from src/hb-uniscribe-private.hh
rename to src/hb-shaper-impl-private.hh
index 239ab0c..91ee14f 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
-#ifndef HB_UNISCRIBE_PRIVATE_HH
-#define HB_UNISCRIBE_PRIVATE_HH
+#ifndef HB_SHAPER_IMPL_PRIVATE_HH
+#define HB_SHAPER_IMPL_PRIVATE_HH
 
 #include "hb-private.hh"
 
-#include "hb-uniscribe.h"
+#include "hb-shaper-private.hh"
+#include "hb-shape-plan-private.hh"
+#include "hb-font-private.hh"
+#include "hb-buffer-private.hh"
 
 
-HB_INTERNAL hb_bool_t
-_hb_uniscribe_shape (hb_font_t          *font,
-                    hb_buffer_t        *buffer,
-                    const hb_feature_t *features,
-                    unsigned int        num_features);
+#ifdef HB_SHAPER
+/* For use in things like font->shaper_data() in the shaper implementations. */
+#define shaper_data() shaper_data.HB_SHAPER
+#endif
 
 
-#endif /* HB_UNISCRIBE_PRIVATE_HH */
+#endif /* HB_SHAPER_IMPL_PRIVATE_HH */
similarity index 67%
rename from src/hb-old-private.hh
rename to src/hb-shaper-list.hh
index 7c51321..ff1fdfd 100644 (file)
  * Google Author(s): Behdad Esfahbod
  */
 
-#ifndef HB_OLD_PRIVATE_HH
-#define HB_OLD_PRIVATE_HH
+#ifndef HB_SHAPER_LIST_HH
+#define HB_SHAPER_LIST_HH
+#endif /* HB_SHAPER_LIST_HH */ /* Dummy header guards */
 
-#include "hb-private.hh"
+/* v--- Add new shapers in the right place here. */
+#ifdef HAVE_GRAPHITE
+HB_SHAPER_IMPLEMENT (graphite2)
+#endif
+#ifdef HAVE_UNISCRIBE
+HB_SHAPER_IMPLEMENT (uniscribe)
+#endif
+#ifdef HAVE_CORETEXT
+HB_SHAPER_IMPLEMENT (coretext)
+#endif
 
+#ifdef HAVE_OT
+HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
+#endif
 
-HB_INTERNAL hb_bool_t
-_hb_old_shape (hb_font_t          *font,
-              hb_buffer_t        *buffer,
-              const hb_feature_t *features,
-              unsigned int        num_features);
+#ifdef HAVE_HB_OLD
+HB_SHAPER_IMPLEMENT (old)
+#endif
 
-
-#endif /* HB_OLD_PRIVATE_HH */
+HB_SHAPER_IMPLEMENT (fallback) /* <--- This should be last. */
diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh
new file mode 100644 (file)
index 0000000..88be96c
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright © 2012  Google, Inc.
+ *
+ *  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.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#ifndef HB_SHAPER_PRIVATE_HH
+#define HB_SHAPER_PRIVATE_HH
+
+#include "hb-private.hh"
+
+typedef hb_bool_t hb_shape_func_t (hb_font_t          *font,
+                                  hb_buffer_t        *buffer,
+                                  const hb_feature_t *features,
+                                  unsigned int        num_features);
+
+#define HB_SHAPER_IMPLEMENT(name) \
+       extern "C" HB_INTERNAL hb_shape_func_t _hb_##name##_shape;
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+
+/* For embedding in face / font / ... */
+struct hb_shaper_data_t {
+#define HB_SHAPER_IMPLEMENT(shaper) void *shaper;
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+};
+
+#define HB_NUM_SHAPERS (sizeof (hb_shaper_data_t) / sizeof (void *))
+
+/* Means: succeeded, but don't need to keep any data. */
+#define HB_SHAPER_DATA_SUCCEEDED ((void *) +1)
+
+/* Means: tried but failed to create. */
+#define HB_SHAPER_DATA_INVALID ((void *) -1)
+#define HB_SHAPER_DATA_IS_INVALID(data) ((void *) (data) == HB_SHAPER_DATA_INVALID)
+
+#define HB_SHAPER_DATA_TYPE(shaper, object)            struct hb_##shaper##_shaper_##object##_data_t
+#define HB_SHAPER_DATA(shaper, object)                 ((HB_SHAPER_DATA_TYPE(shaper, object) *) (object)->shaper_data.shaper)
+#define HB_SHAPER_DATA_GET_FUNC(shaper, object)                _hb_##shaper##_shaper_get_##object##_data
+#define HB_SHAPER_DATA_CREATE_FUNC(shaper, object)     _hb_##shaper##_shaper_##object##_data_create
+#define HB_SHAPER_DATA_DESTROY_FUNC(shaper, object)    _hb_##shaper##_shaper_##object##_data_destroy
+
+#define HB_SHAPER_DATA_PROTOTYPE(shaper, object) \
+       HB_SHAPER_DATA_TYPE (shaper, object); /* Type forward declaration. */ \
+       static inline HB_SHAPER_DATA_TYPE (shaper, object) * \
+       HB_SHAPER_DATA_GET_FUNC (shaper, object) (hb_##object##_t *object) \
+       { return HB_SHAPER_DATA (shaper, object); } \
+       extern "C" HB_INTERNAL HB_SHAPER_DATA_TYPE (shaper, object) * \
+       HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (hb_##object##_t *object); \
+       extern "C" HB_INTERNAL void \
+       HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA_TYPE (shaper, object) *data)
+
+#define HB_SHAPER_DATA_DESTROY(shaper, object) \
+       if (object->shaper_data.shaper && \
+           object->shaper_data.shaper != HB_SHAPER_DATA_INVALID && \
+           object->shaper_data.shaper != HB_SHAPER_DATA_SUCCEEDED) \
+         HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA (shaper, object));
+
+
+#endif /* HB_SHAPER_PRIVATE_HH */
index 6b9a261..fe7be70 100644 (file)
@@ -26,7 +26,8 @@
 
 #define _WIN32_WINNT 0x0600
 
-#include "hb-private.hh"
+#define HB_SHAPER uniscribe
+#include "hb-shaper-impl-private.hh"
 
 #include <windows.h>
 #include <usp10.h>
@@ -38,10 +39,6 @@ typedef ULONG WIN_ULONG;
 #include "hb-ot-name-table.hh"
 #include "hb-ot-tag.h"
 
-#include "hb-font-private.hh"
-#include "hb-buffer-private.hh"
-
-
 
 #ifndef HB_DEBUG_UNISCRIBE
 #define HB_DEBUG_UNISCRIBE (HB_DEBUG+0)
@@ -91,31 +88,20 @@ populate_log_font (LOGFONTW  *lf,
 }
 
 
-static hb_user_data_key_t hb_uniscribe_data_key;
-
+/*
+ * shaper face data
+ */
 
-static struct hb_uniscribe_face_data_t {
+struct hb_uniscribe_shaper_face_data_t {
   HANDLE fh;
-} _hb_uniscribe_face_data_nil = {0};
-
-static void
-_hb_uniscribe_face_data_destroy (hb_uniscribe_face_data_t *data)
-{
-  if (data->fh)
-    RemoveFontMemResourceEx (data->fh);
-  free (data);
-}
+};
 
-static hb_uniscribe_face_data_t *
-_hb_uniscribe_face_get_data (hb_face_t *face)
+hb_uniscribe_shaper_face_data_t *
+_hb_uniscribe_shaper_face_data_create (hb_face_t *face)
 {
-  hb_uniscribe_face_data_t *data = (hb_uniscribe_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
-  if (likely (data)) return data;
-
-  data = (hb_uniscribe_face_data_t *) calloc (1, sizeof (hb_uniscribe_face_data_t));
+  hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_face_data_t));
   if (unlikely (!data))
-    return &_hb_uniscribe_face_data_nil;
-
+    return NULL;
 
   hb_blob_t *blob = hb_face_reference_blob (face);
   unsigned int blob_length;
@@ -126,35 +112,68 @@ _hb_uniscribe_face_get_data (hb_face_t *face)
   DWORD num_fonts_installed;
   data->fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed);
   hb_blob_destroy (blob);
-  if (unlikely (!data->fh))
+  if (unlikely (!data->fh)) {
     DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
-
-
-  if (unlikely (!hb_face_set_user_data (face, &hb_uniscribe_data_key, data,
-                                       (hb_destroy_func_t) _hb_uniscribe_face_data_destroy,
-                                       false)))
-  {
-    _hb_uniscribe_face_data_destroy (data);
-    data = (hb_uniscribe_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
-    if (data)
-      return data;
-    else
-      return &_hb_uniscribe_face_data_nil;
+    free (data);
+    return NULL;
   }
 
   return data;
 }
 
+void
+_hb_uniscribe_shaper_face_data_destroy (hb_uniscribe_shaper_face_data_t *data)
+{
+  if (data->fh)
+    RemoveFontMemResourceEx (data->fh);
+  free (data);
+}
 
-static struct hb_uniscribe_font_data_t {
+
+/*
+ * shaper font data
+ */
+
+struct hb_uniscribe_shaper_font_data_t {
   HDC hdc;
   LOGFONTW log_font;
   HFONT hfont;
   SCRIPT_CACHE script_cache;
-} _hb_uniscribe_font_data_nil = {NULL, NULL, NULL};
+};
 
-static void
-_hb_uniscribe_font_data_destroy (hb_uniscribe_font_data_t *data)
+hb_uniscribe_shaper_font_data_t *
+_hb_uniscribe_shaper_font_data_create (hb_font_t *font)
+{
+  hb_uniscribe_shaper_font_data_t * data = (hb_uniscribe_shaper_font_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_font_data_t));
+  if (unlikely (!data))
+    return NULL;
+
+  data->hdc = GetDC (NULL);
+
+  if (unlikely (!populate_log_font (&data->log_font, font))) {
+    DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed");
+    _hb_uniscribe_shaper_font_data_destroy (data);
+    return NULL;
+  }
+
+  data->hfont = CreateFontIndirectW (&data->log_font);
+  if (unlikely (!data->hfont)) {
+    DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed");
+    _hb_uniscribe_shaper_font_data_destroy (data);
+     return NULL;
+  }
+
+  if (!SelectObject (data->hdc, data->hfont)) {
+    DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed");
+    _hb_uniscribe_shaper_font_data_destroy (data);
+     return NULL;
+  }
+
+  return data;
+}
+
+void
+_hb_uniscribe_shaper_font_data_destroy (hb_uniscribe_shaper_font_data_t *data)
 {
   if (data->hdc)
     ReleaseDC (NULL, data->hdc);
@@ -165,38 +184,67 @@ _hb_uniscribe_font_data_destroy (hb_uniscribe_font_data_t *data)
   free (data);
 }
 
-static hb_uniscribe_font_data_t *
-_hb_uniscribe_font_get_data (hb_font_t *font)
+
+/*
+ * shaper shape_plan data
+ */
+
+struct hb_uniscribe_shaper_shape_plan_data_t {};
+
+hb_uniscribe_shaper_shape_plan_data_t *
+_hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan)
 {
-  hb_uniscribe_font_data_t *data = (hb_uniscribe_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
-  if (likely (data)) return data;
+  return (hb_uniscribe_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
 
-  data = (hb_uniscribe_font_data_t *) calloc (1, sizeof (hb_uniscribe_font_data_t));
-  if (unlikely (!data))
-    return &_hb_uniscribe_font_data_nil;
+void
+_hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shaper_shape_plan_data_t *data)
+{
+}
 
-  data->hdc = GetDC (NULL);
 
-  if (unlikely (!populate_log_font (&data->log_font, font)))
-    DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed");
-  else {
-    data->hfont = CreateFontIndirectW (&data->log_font);
-    if (unlikely (!data->hfont))
-      DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed");
-    if (!SelectObject (data->hdc, data->hfont))
-      DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed");
+/*
+ * shaper
+ */
+static hb_user_data_key_t hb_uniscribe_data_key;
+
+static hb_uniscribe_shaper_face_data_t *
+_hb_uniscribe_face_get_data (hb_face_t *face)
+{
+  hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
+  if (likely (data)) return data;
+
+  data = _hb_uniscribe_shaper_face_data_create (face);
+  if (!data) return NULL;
+
+  if (unlikely (!hb_face_set_user_data (face, &hb_uniscribe_data_key, data,
+                                       (hb_destroy_func_t) _hb_uniscribe_shaper_face_data_destroy,
+                                       false)))
+  {
+    _hb_uniscribe_shaper_face_data_destroy (data);
+    data = (hb_uniscribe_shaper_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
   }
 
+  return data;
+}
+
+
+static hb_uniscribe_shaper_font_data_t *
+_hb_uniscribe_font_get_data (hb_font_t *font)
+{
+  hb_uniscribe_shaper_font_data_t *data = (hb_uniscribe_shaper_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
+  if (likely (data)) return data;
+
+  data = _hb_uniscribe_shaper_font_data_create (font);
+  if (unlikely (!data))
+    return NULL;
+
   if (unlikely (!hb_font_set_user_data (font, &hb_uniscribe_data_key, data,
-                                       (hb_destroy_func_t) _hb_uniscribe_font_data_destroy,
+                                       (hb_destroy_func_t) _hb_uniscribe_shaper_font_data_destroy,
                                        false)))
   {
-    _hb_uniscribe_font_data_destroy (data);
-    data = (hb_uniscribe_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
-    if (data)
-      return data;
-    else
-      return &_hb_uniscribe_font_data_nil;
+    _hb_uniscribe_shaper_font_data_destroy (data);
+    data = (hb_uniscribe_shaper_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
   }
 
   return data;
@@ -205,7 +253,7 @@ _hb_uniscribe_font_get_data (hb_font_t *font)
 LOGFONTW *
 hb_uniscribe_font_get_logfontw (hb_font_t *font)
 {
-  hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
+  hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
   if (unlikely (!font_data))
     return NULL;
   return &font_data->log_font;
@@ -214,7 +262,7 @@ hb_uniscribe_font_get_logfontw (hb_font_t *font)
 HFONT
 hb_uniscribe_font_get_hfont (hb_font_t *font)
 {
-  hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
+  hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
   if (unlikely (!font_data))
     return 0;
   return font_data->hfont;
@@ -235,11 +283,11 @@ _hb_uniscribe_shape (hb_font_t          *font,
     return false; \
   } HB_STMT_END;
 
-  hb_uniscribe_face_data_t *face_data = _hb_uniscribe_face_get_data (font->face);
+  hb_uniscribe_shaper_face_data_t *face_data = _hb_uniscribe_face_get_data (font->face);
   if (unlikely (!face_data->fh))
     FAIL ("Couldn't get face data");
 
-  hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
+  hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
   if (unlikely (!font_data->hfont))
     FAIL ("Couldn't get font font");