[name] Hook up ltag table
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 24 Oct 2018 06:33:44 +0000 (23:33 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 27 Oct 2018 04:22:26 +0000 (21:22 -0700)
src/hb-aat-layout.cc
src/hb-aat-layout.hh
src/hb-aat-ltag-table.hh
src/hb-ot-face.hh
src/hb-ot-name-table.hh

index 1e1c7b4..ec05393 100644 (file)
@@ -34,7 +34,7 @@
 #include "hb-aat-layout-kerx-table.hh"
 #include "hb-aat-layout-morx-table.hh"
 #include "hb-aat-layout-trak-table.hh"
-#include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise.
+#include "hb-aat-ltag-table.hh"
 
 
 /* Table data courtesy of Apple.  Converted from mnemonics to integers
@@ -181,6 +181,12 @@ _get_trak (hb_face_t *face)
   if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::trak);
   return *(hb_ot_face_data (face)->trak.get ());
 }
+static inline const AAT::ltag&
+_get_ltag (hb_face_t *face)
+{
+  if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::ltag);
+  return *(hb_ot_face_data (face)->ltag.get ());
+}
 
 
 void
@@ -248,3 +254,10 @@ hb_aat_layout_track (hb_ot_shape_plan_t *plan,
   AAT::hb_aat_apply_context_t c (plan, font, buffer);
   trak.apply (&c);
 }
+
+hb_language_t
+_hb_aat_language_get (hb_face_t *face,
+                     unsigned int i)
+{
+  return _get_ltag (face).get_language (i);
+}
index aea5456..8a558e6 100644 (file)
@@ -80,4 +80,9 @@ hb_aat_layout_track (hb_ot_shape_plan_t *plan,
                     hb_font_t *font,
                     hb_buffer_t *buffer);
 
+HB_INTERNAL hb_language_t
+_hb_aat_language_get (hb_face_t *face,
+                     unsigned int i);
+
+
 #endif /* HB_AAT_LAYOUT_HH */
index 08a1b51..8a42b35 100644 (file)
@@ -25,7 +25,7 @@
 #ifndef HB_AAT_LTAG_TABLE_HH
 #define HB_AAT_LTAG_TABLE_HH
 
-#include "hb-aat-layout-common.hh"
+#include "hb-open-type.hh"
 
 /*
  * ltag -- Language Tag
 
 namespace AAT {
 
+using namespace OT;
+
 
 struct FTStringRange
 {
+  friend struct ltag;
+
   inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
   {
     TRACE_SANITIZE (this);
@@ -58,10 +62,19 @@ struct ltag
 {
   static const hb_tag_t tableTag = HB_AAT_TAG_ltag;
 
+  inline hb_language_t get_language (unsigned int i) const
+  {
+    const FTStringRange &range = tagRanges[i];
+    return hb_language_from_string ((const char *) (this+range.tag).arrayZ,
+                                   range.length);
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
-    return_trace (likely (c->check_struct (this) && tagRanges.sanitize (c, this)));
+    return_trace (likely (c->check_struct (this) &&
+                         version >= 1 &&
+                         tagRanges.sanitize (c, this)));
   }
 
   protected:
index c810e9f..4c84f0a 100644 (file)
     HB_OT_ACCELERATOR(OT, hmtx) \
     HB_OT_ACCELERATOR(OT, vmtx) \
     HB_OT_ACCELERATOR(OT, post) \
-    HB_OT_ACCELERATOR(OT, name) \
     HB_OT_ACCELERATOR(OT, kern) \
     HB_OT_ACCELERATOR(OT, glyf) \
     HB_OT_TABLE(OT, VORG) \
+    HB_OT_ACCELERATOR(OT, name) \
+    HB_OT_TABLE(AAT, ltag) \
     /* OpenType color fonts. */ \
     HB_OT_TABLE(OT, COLR) \
     HB_OT_TABLE(OT, CPAL) \
index f42c0db..e580908 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "hb-open-type.hh"
 #include "hb-ot-name-language.hh"
+#include "hb-aat-layout.hh"
 
 
 namespace OT {
@@ -48,7 +49,7 @@ namespace OT {
 
 struct NameRecord
 {
-  inline hb_language_t language (void) const
+  inline hb_language_t language (hb_face_t *face) const
   {
     unsigned int p = platformID;
     unsigned int l = languageID;
@@ -59,8 +60,8 @@ struct NameRecord
     if (p == 1)
       return _hb_ot_name_language_for_mac_code (l);
 
-    //if (p == 0)
-      /* TODO use 'ltag' table? */
+    if (p == 0)
+      return _hb_aat_language_get (face, l);
 
     return HB_LANGUAGE_INVALID;
   }
@@ -194,7 +195,7 @@ struct name
        hb_ot_name_entry_t *entry = this->names.push ();
 
        entry->name_id = all_names[i].nameID;
-       entry->language = all_names[i].language ();
+       entry->language = all_names[i].language (face);
        entry->entry_score =  all_names[i].score ();
        entry->entry_index = i;
       }