src/hb-ot-name-table.hh | 30 +++++++++--------------------- src/hb-ot-name.cc | 22 ++++++++++++++++++++++ src/hb-ot-name.h | 8 ++++++-- 3 files changed, 37 insertions(+), 23 deletions(-)
New commits: commit f65dba8ef8540016c07bf07a64c0b6b056435f2b Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 15 23:09:28 2018 -0700 [name] Start implementing hb_ot_name_get_utf16() diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 37a2d42f..3d7b7311 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -165,8 +165,9 @@ struct name 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->table = this->blob->as<name> (); + const hb_array_t<NameRecord> &all_names = hb_array_t<NameRecord> (this->table->nameRecordZ.arrayZ, + this->table->count); this->names.init (); @@ -204,6 +205,7 @@ struct name private: hb_blob_t *blob; public: + const name *table; hb_vector_t<hb_ot_name_entry_t> names; }; diff --git a/src/hb-ot-name.cc b/src/hb-ot-name.cc index 85995f8c..b5143d3d 100644 --- a/src/hb-ot-name.cc +++ b/src/hb-ot-name.cc @@ -48,3 +48,25 @@ hb_ot_name_get_names (hb_face_t *face, *entries = name.names.arrayZ(); return name.names.len; } + + +hb_bool_t +hb_ot_name_get_utf16 (hb_face_t *face, + hb_name_id_t name_id, + hb_language_t language, + unsigned int *text_size /* IN/OUT */, + uint16_t *text /* OUT */) +{ + const OT::name_accelerator_t &name = _get_name (face); + unsigned int idx = 0; //XXX + hb_bytes_t bytes = name.table->get_name (idx); + if (*text_size) + { + /* TODO Switch to walking string and validating. */ + memcpy (text, bytes.arrayZ, MIN (*text_size * 2, bytes.len)); + } + /* XXX Null-terminate. */ + *text_size = bytes.len / 2; //TODO + /* TODO Fallback? */ + return true; //XXX +} diff --git a/src/hb-ot-name.h b/src/hb-ot-name.h index ddd2c254..0bf72c6b 100644 --- a/src/hb-ot-name.h +++ b/src/hb-ot-name.h @@ -49,12 +49,14 @@ typedef unsigned int hb_name_id_t; #define HB_NAME_ID_INVALID 0xFFFF +#if 0 HB_EXTERN hb_bool_t -hb_ot_name_get_utf8 (hb_face_t *face, +Xhb_ot_name_get_utf8 (hb_face_t *face, hb_name_id_t name_id, hb_language_t language, unsigned int *text_size /* IN/OUT */, char *text /* OUT */); +#endif HB_EXTERN hb_bool_t hb_ot_name_get_utf16 (hb_face_t *face, @@ -63,12 +65,14 @@ hb_ot_name_get_utf16 (hb_face_t *face, unsigned int *text_size /* IN/OUT */, uint16_t *text /* OUT */); +#if 0 HB_EXTERN hb_bool_t -hb_ot_name_get_utf32 (hb_face_t *face, +Xhb_ot_name_get_utf32 (hb_face_t *face, hb_name_id_t name_id, hb_language_t language, unsigned int *text_size /* IN/OUT */, uint32_t *text /* OUT */); +#endif typedef struct hb_ot_name_entry_t commit 7742644191752b6599837ca2e5009e5d89978747 Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 15 23:00:27 2018 -0700 [name] Implement hb_bytes_t get_name() diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 5625ab2c..37a2d42f 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -131,26 +131,11 @@ struct name { static const hb_tag_t tableTag = HB_OT_TAG_name; - inline unsigned int get_name (unsigned int platform_id, - unsigned int encoding_id, - unsigned int language_id, - unsigned int name_id, - void *buffer, - unsigned int buffer_length) const + inline hb_bytes_t get_name (unsigned int idx) const { - NameRecord key; - key.platformID.set (platform_id); - key.encodingID.set (encoding_id); - key.languageID.set (language_id); - key.nameID.set (name_id); - NameRecord *match = (NameRecord *) bsearch (&key, nameRecordZ.arrayZ, count, sizeof (nameRecordZ[0]), NameRecord::cmp); - - if (!match) - return 0; - - unsigned int length = MIN (buffer_length, (unsigned int) match->length); - memcpy (buffer, (char *) this + stringOffset + match->offset, length); - return length; + const hb_array_t<NameRecord> &all_names = hb_array_t<NameRecord> (nameRecordZ.arrayZ, count); + const NameRecord &record = all_names[idx]; + return hb_bytes_t ((char *) this + stringOffset + record.offset, record.length); } inline unsigned int get_size (void) const @@ -160,6 +145,7 @@ struct name TRACE_SANITIZE (this); char *string_pool = (char *) this + stringOffset; unsigned int _count = count; + /* Move to run-time?! */ for (unsigned int i = 0; i < _count; i++) if (!nameRecordZ[i].sanitize (c, string_pool)) return_trace (false); return_trace (true); _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
