From 0bc2d83b7f4f6fb6d9f214c930b9de65cc143012 Mon Sep 17 00:00:00 2001
From: Konstantin Ritt <ritt.ks@gmail.com>
Date: Thu, 23 Jan 2014 21:52:56 +0200
Subject: Introduce AAT shaper

...that only picks up fonts that have a "Mort" or "Morx" table.
---
 src/hb-coretext.cc    | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/hb-coretext.h     |   4 ++
 src/hb-shaper-list.hh |   5 +++
 3 files changed, 111 insertions(+)

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 7d78a78..09bc1da 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -807,3 +807,105 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
 
   return true;
 }
+
+
+/*
+ * AAT shaper
+ */
+
+HB_SHAPER_DATA_ENSURE_DECLARE(aat, face)
+HB_SHAPER_DATA_ENSURE_DECLARE(aat, font)
+
+
+/*
+ * shaper face data
+ */
+
+struct hb_aat_shaper_face_data_t {
+  CGFontRef cg_font;
+};
+
+hb_aat_shaper_face_data_t *
+_hb_aat_shaper_face_data_create (hb_face_t *face)
+{
+  hb_blob_t *mort_blob = face->reference_table (HB_AAT_TAG_MORT);
+  /* Umm, we just reference the table to check whether it exists.
+   * Maybe add better API for this? */
+  if (!hb_blob_get_length (mort_blob))
+  {
+    hb_blob_destroy (mort_blob);
+    mort_blob = face->reference_table (HB_AAT_TAG_MORX);
+    if (!hb_blob_get_length (mort_blob))
+    {
+      hb_blob_destroy (mort_blob);
+      return NULL;
+    }
+  }
+  hb_blob_destroy (mort_blob);
+
+  return (hb_aat_shaper_face_data_t *) _hb_coretext_shaper_face_data_create (face);
+}
+
+void
+_hb_aat_shaper_face_data_destroy (hb_aat_shaper_face_data_t *data)
+{
+  CFRelease (data->cg_font);
+  free (data);
+}
+
+
+/*
+ * shaper font data
+ */
+
+struct hb_aat_shaper_font_data_t {
+  CTFontRef ct_font;
+};
+
+hb_aat_shaper_font_data_t *
+_hb_aat_shaper_font_data_create (hb_font_t *font)
+{
+  return (hb_aat_shaper_font_data_t *) _hb_coretext_shaper_font_data_create (font);
+}
+
+void
+_hb_aat_shaper_font_data_destroy (hb_aat_shaper_font_data_t *data)
+{
+  CFRelease (data->ct_font);
+  free (data);
+}
+
+
+/*
+ * shaper shape_plan data
+ */
+
+struct hb_aat_shaper_shape_plan_data_t {};
+
+hb_aat_shaper_shape_plan_data_t *
+_hb_aat_shaper_shape_plan_data_create (hb_shape_plan_t    *shape_plan HB_UNUSED,
+					     const hb_feature_t *user_features HB_UNUSED,
+					     unsigned int        num_user_features HB_UNUSED)
+{
+  return (hb_aat_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+}
+
+void
+_hb_aat_shaper_shape_plan_data_destroy (hb_aat_shaper_shape_plan_data_t *data HB_UNUSED)
+{
+}
+
+
+/*
+ * shaper
+ */
+
+hb_bool_t
+_hb_aat_shape (hb_shape_plan_t    *shape_plan,
+               hb_font_t          *font,
+               hb_buffer_t        *buffer,
+               const hb_feature_t *features,
+               unsigned int        num_features)
+{
+  return _hb_coretext_shape (shape_plan, font, buffer, features, num_features);
+}
diff --git a/src/hb-coretext.h b/src/hb-coretext.h
index c4954fa..7f4053b 100644
--- a/src/hb-coretext.h
+++ b/src/hb-coretext.h
@@ -34,6 +34,10 @@
 HB_BEGIN_DECLS
 
 
+#define HB_AAT_TAG_MORT HB_TAG('M','o','r','t')
+#define HB_AAT_TAG_MORX HB_TAG('M','o','r','x')
+
+
 CGFontRef
 hb_coretext_face_get_cg_font (hb_face_t *face);
 
diff --git a/src/hb-shaper-list.hh b/src/hb-shaper-list.hh
index da6d8e0..a13ec4f 100644
--- a/src/hb-shaper-list.hh
+++ b/src/hb-shaper-list.hh
@@ -35,6 +35,11 @@
 HB_SHAPER_IMPLEMENT (graphite2)
 #endif
 
+#ifdef HAVE_CORETEXT
+/* Only picks up fonts that have a "Mort" or "Morx" table. */
+HB_SHAPER_IMPLEMENT (aat)
+#endif
+
 #ifdef HAVE_OT
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 #endif
-- 
1.8.3.msysgit.0

