[name] Start implementing public API infrastructure

pull/1319/head
Behdad Esfahbod 6 years ago
parent 0bf93ec0fb
commit 2157e56b34
  1. 1
      src/hb-ot-face.cc
  2. 7
      src/hb-ot-face.hh
  3. 60
      src/hb-ot-name-table.hh
  4. 3
      src/hb-ot-name.h

@ -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"

@ -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) \

@ -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 */

@ -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;

Loading…
Cancel
Save