summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2018-10-15 22:22:50 -0700
committerBehdad Esfahbod <behdad@behdad.org>2018-10-15 22:22:50 -0700
commitf0d9c813d37ee16a30750eb8a6516ee258a533cc (patch)
tree2615ea267448c05500b77b644e43299250e40f62
parent298390c02402c29070efbbde673dbe21795b0391 (diff)
[name] Start implementing public API infrastructure
-rw-r--r--src/hb-ot-face.cc1
-rw-r--r--src/hb-ot-face.hh8
-rw-r--r--src/hb-ot-name-table.hh60
-rw-r--r--src/hb-ot-name.h3
4 files changed, 69 insertions, 3 deletions
diff --git a/src/hb-ot-face.cc b/src/hb-ot-face.cc
index 1bc68d36..dd17faf6 100644
--- a/src/hb-ot-face.cc
+++ b/src/hb-ot-face.cc
@@ -30,6 +30,7 @@
#include "hb-ot-glyf-table.hh"
#include "hb-ot-hmtx-table.hh"
#include "hb-ot-kern-table.hh"
+#include "hb-ot-name-table.hh"
#include "hb-ot-post-table.hh"
#include "hb-ot-color-cbdt-table.hh"
#include "hb-ot-layout-gdef-table.hh"
diff --git a/src/hb-ot-face.hh b/src/hb-ot-face.hh
index e3059221..2f0f2e7f 100644
--- a/src/hb-ot-face.hh
+++ b/src/hb-ot-face.hh
@@ -45,6 +45,9 @@
* This is as good as any place. */
#define HB_OT_TABLES \
/* OpenType shaping. */ \
+ HB_OT_ACCELERATOR(OT, GDEF) \
+ HB_OT_ACCELERATOR(OT, GSUB) \
+ HB_OT_ACCELERATOR(OT, GPOS) \
HB_OT_TABLE(OT, JSTF) \
HB_OT_TABLE(OT, BASE) \
/* AAT shaping. */ \
@@ -59,15 +62,14 @@
/* OpenType math. */ \
HB_OT_TABLE(OT, MATH) \
/* OpenType fundamentals. */ \
- HB_OT_ACCELERATOR(OT, GDEF) \
- HB_OT_ACCELERATOR(OT, GSUB) \
- HB_OT_ACCELERATOR(OT, GPOS) \
HB_OT_ACCELERATOR(OT, cmap) \
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) \
+ /* OpenType color fonts. */ \
HB_OT_ACCELERATOR(OT, CBDT) \
/* */
diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh
index bb49c2cb..45726ab5 100644
--- a/src/hb-ot-name-table.hh
+++ b/src/hb-ot-name-table.hh
@@ -58,6 +58,13 @@ struct NameRecord
return 0;
}
+ inline bool supported (void) const
+ {
+ return platformID == 0 ||
+ platformID == 3;
+ /* TODO Add Apple MacRoman (0:1). */
+ }
+
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
{
TRACE_SANITIZE (this);
@@ -75,6 +82,18 @@ struct NameRecord
DEFINE_SIZE_STATIC (12);
};
+static int
+_hb_ot_name_entry_cmp (const void *pa, const void *pb)
+{
+ const hb_ot_name_entry_t *a = (const hb_ot_name_entry_t *) pa;
+ const hb_ot_name_entry_t *b = (const hb_ot_name_entry_t *) pb;
+ if (a->name_id != b->name_id)
+ return a->name_id < b->name_id ? -1 : +1;
+ if (a->index != b->index)
+ return a->index < b->index ? -1 : +1;
+ return 0;
+}
+
struct name
{
static const hb_tag_t tableTag = HB_OT_TAG_name;
@@ -122,6 +141,46 @@ struct name
sanitize_records (c));
}
+ struct accelerator_t
+ {
+ inline void init (hb_face_t *face)
+ {
+ this->blob = hb_sanitize_context_t().reference_table<name> (face);
+ const name *table = this->blob->as<name> ();
+ const hb_array_t<NameRecord> &all_names = hb_array_t<NameRecord> (table->nameRecordZ.arrayZ, table->count);
+
+ this->names.init ();
+
+ for (unsigned int i = 0; i < all_names.len; i++)
+ {
+ if (!all_names[i].supported ()) continue;
+
+ unsigned int name_id = all_names[i].nameID;
+ hb_language_t language = HB_LANGUAGE_INVALID; /* XXX */
+
+ hb_ot_name_entry_t entry = {name_id, i, language};
+
+ this->names.push (entry);
+ }
+
+ this->names.qsort (_hb_ot_name_entry_cmp);
+
+ /* Walk and pick best... */
+ }
+
+ inline void fini (void)
+ {
+ this->names.fini ();
+ hb_blob_destroy (this->blob);
+ }
+
+ private:
+ hb_blob_t *blob;
+ hb_vector_t<hb_ot_name_entry_t> names;
+
+ unsigned int names_count;
+ };
+
/* We only implement format 0 for now. */
HBUINT16 format; /* Format selector (=0/1). */
HBUINT16 count; /* Number of name records. */
@@ -132,6 +191,7 @@ struct name
DEFINE_SIZE_ARRAY (6, nameRecordZ);
};
+struct name_accelerator_t : name::accelerator_t {};
} /* namespace OT */
diff --git a/src/hb-ot-name.h b/src/hb-ot-name.h
index 8e777f18..cdbf91c2 100644
--- a/src/hb-ot-name.h
+++ b/src/hb-ot-name.h
@@ -74,6 +74,9 @@ hb_ot_name_get_utf32 (hb_face_t *face,
typedef struct hb_ot_name_entry_t
{
hb_name_id_t name_id;
+ /*< private >*/
+ unsigned int index;
+ /*< public >*/
hb_language_t language;
} hb_ot_name_entry_t;