Minor
diff --git a/src/Makefile.am b/src/Makefile.am
index 847c9e7..9b583fd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,7 @@
hb-shaper-list.hh \
hb-shaper-impl-private.hh \
hb-shaper-private.hh \
+ hb-shaper.cc \
hb-tt-font.cc \
hb-unicode-private.hh \
hb-unicode.cc \
diff --git a/src/hb-fallback-shape.cc b/src/hb-fallback-shape.cc
index 4c9a3b3..48aba73 100644
--- a/src/hb-fallback-shape.cc
+++ b/src/hb-fallback-shape.cc
@@ -87,7 +87,8 @@
*/
hb_bool_t
-_hb_fallback_shape (hb_font_t *font,
+_hb_fallback_shape (hb_shape_plan_t *shape_plan,
+ hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features HB_UNUSED,
unsigned int num_features HB_UNUSED)
diff --git a/src/hb-old.cc b/src/hb-old.cc
index b898b3f..879ee70 100644
--- a/src/hb-old.cc
+++ b/src/hb-old.cc
@@ -302,7 +302,8 @@
}
hb_bool_t
-_hb_old_shape (hb_font_t *font,
+_hb_old_shape (hb_shape_plan_t *shape_plan,
+ hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 512ffa5..a3c4153 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -541,7 +541,8 @@
}
hb_bool_t
-_hb_ot_shape (hb_font_t *font,
+_hb_ot_shape (hb_shape_plan_t *shape_plan,
+ hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
diff --git a/src/hb-shape-plan-private.hh b/src/hb-shape-plan-private.hh
index 1f54608..68246f4 100644
--- a/src/hb-shape-plan-private.hh
+++ b/src/hb-shape-plan-private.hh
@@ -39,7 +39,7 @@
hb_object_header_t header;
ASSERT_POD ();
- hb_shape_func_t *shapers[HB_NUM_SHAPERS];
+ hb_shape_func_t *shapers[HB_SHAPERS_COUNT];
struct hb_shaper_data_t shaper_data;
};
diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc
index b96d5f2..e76847d 100644
--- a/src/hb-shape-plan.cc
+++ b/src/hb-shape-plan.cc
@@ -53,6 +53,8 @@
hb_face_make_immutable (face);
+ /* Plan! */
+
return shape_plan;
}
diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index a1f3402..3915de7 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -30,85 +30,6 @@
#include "hb-buffer-private.hh"
-static const struct hb_shaper_pair_t {
- char name[16];
- hb_shape_func_t *func;
-} all_shapers[] = {
-#define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape},
-#include "hb-shaper-list.hh"
-#undef HB_SHAPER_IMPLEMENT
-};
-
-
-/* Thread-safe, lock-free, shapers */
-
-static const hb_shaper_pair_t *static_shapers;
-
-static
-void free_static_shapers (void)
-{
- if (unlikely (static_shapers != all_shapers))
- free ((void *) static_shapers);
-}
-
-static const hb_shaper_pair_t *
-get_shapers (void)
-{
-retry:
- hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers);
-
- if (unlikely (!shapers))
- {
- char *env = getenv ("HB_SHAPER_LIST");
- if (!env || !*env) {
- (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]);
- return (const hb_shaper_pair_t *) all_shapers;
- }
-
- /* Not found; allocate one. */
- shapers = (hb_shaper_pair_t *) malloc (sizeof (all_shapers));
- if (unlikely (!shapers))
- return (const hb_shaper_pair_t *) all_shapers;
- memcpy (shapers, all_shapers, sizeof (all_shapers));
-
- /* Reorder shaper list to prefer requested shapers. */
- unsigned int i = 0;
- char *end, *p = env;
- for (;;) {
- end = strchr (p, ',');
- if (!end)
- end = p + strlen (p);
-
- for (unsigned int j = i; j < ARRAY_LENGTH (all_shapers); j++)
- if (end - p == (int) strlen (shapers[j].name) &&
- 0 == strncmp (shapers[j].name, p, end - p))
- {
- /* Reorder this shaper to position i */
- struct hb_shaper_pair_t t = shapers[j];
- memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i));
- shapers[i] = t;
- i++;
- }
-
- if (!*end)
- break;
- else
- p = end + 1;
- }
-
- if (!hb_atomic_ptr_cmpexch (&static_shapers, NULL, shapers)) {
- free (shapers);
- goto retry;
- }
-
-#ifdef HAVE_ATEXIT
- atexit (free_static_shapers); /* First person registers atexit() callback. */
-#endif
- }
-
- return shapers;
-}
-
static const char **static_shaper_list;
@@ -127,15 +48,15 @@
if (unlikely (!shaper_list))
{
/* Not found; allocate one. */
- shaper_list = (const char **) calloc (1 + ARRAY_LENGTH (all_shapers), sizeof (const char *));
+ shaper_list = (const char **) calloc (1 + HB_SHAPERS_COUNT, sizeof (const char *));
if (unlikely (!shaper_list)) {
static const char *nil_shaper_list[] = {NULL};
return nil_shaper_list;
}
- const hb_shaper_pair_t *shapers = get_shapers ();
+ const hb_shaper_pair_t *shapers = _hb_shapers_get ();
unsigned int i;
- for (i = 0; i < ARRAY_LENGTH (all_shapers); i++)
+ for (i = 0; i < HB_SHAPERS_COUNT; i++)
shaper_list[i] = shapers[i].name;
shaper_list[i] = NULL;
@@ -160,18 +81,19 @@
unsigned int num_features,
const char * const *shaper_list)
{
+ const hb_shaper_pair_t *shapers = _hb_shapers_get ();
+
hb_font_make_immutable (font); /* So we can safely cache stuff on it */
if (likely (!shaper_list)) {
- const hb_shaper_pair_t *shapers = get_shapers ();
- for (unsigned int i = 0; i < ARRAY_LENGTH (all_shapers); i++)
- if (likely (shapers[i].func (font, buffer, features, num_features)))
+ for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
+ if (likely (shapers[i].func (NULL, font, buffer, features, num_features)))
return true;
} else {
while (*shaper_list) {
- for (unsigned int i = 0; i < ARRAY_LENGTH (all_shapers); i++)
- if (0 == strcmp (*shaper_list, all_shapers[i].name)) {
- if (likely (all_shapers[i].func (font, buffer, features, num_features)))
+ for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
+ if (0 == strcmp (*shaper_list, shapers[i].name)) {
+ if (likely (shapers[i].func (NULL, font, buffer, features, num_features)))
return true;
break;
}
diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh
index 88be96c..fa279bc 100644
--- a/src/hb-shaper-private.hh
+++ b/src/hb-shaper-private.hh
@@ -29,7 +29,10 @@
#include "hb-private.hh"
-typedef hb_bool_t hb_shape_func_t (hb_font_t *font,
+#include "hb-shape-plan.h" /* TODO remove */
+
+typedef hb_bool_t hb_shape_func_t (hb_shape_plan_t *shape_plan,
+ hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features);
@@ -39,6 +42,15 @@
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
+struct hb_shaper_pair_t {
+ char name[16];
+ hb_shape_func_t *func;
+};
+
+HB_INTERNAL const hb_shaper_pair_t *
+_hb_shapers_get (void);
+
+
/* For embedding in face / font / ... */
struct hb_shaper_data_t {
#define HB_SHAPER_IMPLEMENT(shaper) void *shaper;
@@ -46,7 +58,7 @@
#undef HB_SHAPER_IMPLEMENT
};
-#define HB_NUM_SHAPERS (sizeof (hb_shaper_data_t) / sizeof (void *))
+#define HB_SHAPERS_COUNT (sizeof (hb_shaper_data_t) / sizeof (void *))
/* Means: succeeded, but don't need to keep any data. */
#define HB_SHAPER_DATA_SUCCEEDED ((void *) +1)
diff --git a/src/hb-shaper.cc b/src/hb-shaper.cc
new file mode 100644
index 0000000..a16ffc8
--- /dev/null
+++ b/src/hb-shaper.cc
@@ -0,0 +1,109 @@
+/*
+ * 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-shaper-private.hh"
+
+
+static const hb_shaper_pair_t all_shapers[] = {
+#define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape},
+#include "hb-shaper-list.hh"
+#undef HB_SHAPER_IMPLEMENT
+};
+
+
+/* Thread-safe, lock-free, shapers */
+
+static const hb_shaper_pair_t *static_shapers;
+
+static
+void free_static_shapers (void)
+{
+ if (unlikely (static_shapers != all_shapers))
+ free ((void *) static_shapers);
+}
+
+const hb_shaper_pair_t *
+_hb_shapers_get (void)
+{
+retry:
+ hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers);
+
+ if (unlikely (!shapers))
+ {
+ char *env = getenv ("HB_SHAPER_LIST");
+ if (!env || !*env) {
+ (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]);
+ return (const hb_shaper_pair_t *) all_shapers;
+ }
+
+ /* Not found; allocate one. */
+ shapers = (hb_shaper_pair_t *) malloc (sizeof (all_shapers));
+ if (unlikely (!shapers)) {
+ (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]);
+ return (const hb_shaper_pair_t *) all_shapers;
+ }
+
+ memcpy (shapers, all_shapers, sizeof (all_shapers));
+
+ /* Reorder shaper list to prefer requested shapers. */
+ unsigned int i = 0;
+ char *end, *p = env;
+ for (;;) {
+ end = strchr (p, ',');
+ if (!end)
+ end = p + strlen (p);
+
+ for (unsigned int j = i; j < ARRAY_LENGTH (all_shapers); j++)
+ if (end - p == (int) strlen (shapers[j].name) &&
+ 0 == strncmp (shapers[j].name, p, end - p))
+ {
+ /* Reorder this shaper to position i */
+ struct hb_shaper_pair_t t = shapers[j];
+ memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i));
+ shapers[i] = t;
+ i++;
+ }
+
+ if (!*end)
+ break;
+ else
+ p = end + 1;
+ }
+
+ if (!hb_atomic_ptr_cmpexch (&static_shapers, NULL, shapers)) {
+ free (shapers);
+ goto retry;
+ }
+
+#ifdef HAVE_ATEXIT
+ atexit (free_static_shapers); /* First person registers atexit() callback. */
+#endif
+ }
+
+ return shapers;
+}
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index fe7be70..faba587 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -270,7 +270,8 @@
hb_bool_t
-_hb_uniscribe_shape (hb_font_t *font,
+_hb_uniscribe_shape (hb_shape_plan_t *shape_plan,
+ hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)