From 2157e56b34e7b932dd144ee3563f5bd682bbed30 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 15 Oct 2018 22:22:50 -0700 Subject: [PATCH] [name] Start implementing public API infrastructure --- src/hb-ot-face.cc | 1 + src/hb-ot-face.hh | 7 +++--- src/hb-ot-name-table.hh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ src/hb-ot-name.h | 3 +++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-face.cc b/src/hb-ot-face.cc index 1bc68d3..dd17faf 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 a45a493..c810e9f 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,13 +62,11 @@ /* 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) \ HB_OT_TABLE(OT, VORG) \ diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index bb49c2c..45726ab 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 (face); + const name *table = this->blob->as (); + const hb_array_t &all_names = hb_array_t (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 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 1f643d5..8b2c02b 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; -- 2.7.4