Accept Mac Latin name entries as ASCII as well.
/* Symbol. */
if (p == 3 && e == 0) return 8;
- /* TODO Apple MacRoman (0:1). */
+ /* We treat all Mac Latin names as ASCII only. */
+ if (p == 1 && e == 0) return 10; /* 10 is magic number :| */
return UNSUPPORTED;
}
}
this->names.qsort (_hb_ot_name_entry_cmp);
- /* Walk and pick best only for each name_id,language pair... */
+ /* Walk and pick best only for each name_id,language pair,
+ * while dropping unsupported encodings. */
unsigned int j = 0;
- for (unsigned int i = 1; i < this->names.len; i++)
+ for (unsigned int i = 0; i < this->names.len; i++)
{
- if (this->names[i - 1].name_id == this->names[i].name_id &&
+ if (this->names[i].entry_score == UNSUPPORTED)
+ continue;
+ if (i &&
+ this->names[i - 1].name_id == this->names[i].name_id &&
this->names[i - 1].language == this->names[i].language)
continue;
this->names[j++] = this->names[i];
}
inline int get_index (hb_name_id_t name_id,
- hb_language_t language) const
+ hb_language_t language,
+ unsigned int *width=nullptr) const
{
const hb_ot_name_entry_t key = {name_id, {0}, language};
const hb_ot_name_entry_t *entry = (const hb_ot_name_entry_t *)
this->names.len,
sizeof (key),
_hb_ot_name_entry_cmp_key);
- return entry ? entry->entry_index : -1;
+ if (!entry)
+ return -1;
+
+ if (width)
+ *width = entry->entry_score < 10 ? 2 : 1;
+
+ return entry->entry_index;
}
private:
{
const OT::name_accelerator_t &name = _get_name (face);
- int idx = name.get_index (name_id, language);
+ unsigned int width;
+ int idx = name.get_index (name_id, language, &width);
if (idx != -1)
{
hb_bytes_t bytes = name.table->get_name (idx);
- if (true /*UTF16-BE*/)
+ if (width == 2) /* UTF16-BE */
return hb_ot_name_convert_utf<hb_utf16_be_t, utf_t> (&bytes, text_size, text);
+
+ if (width == 1) /* ASCII */
+ return hb_ot_name_convert_utf<hb_ascii_t, utf_t> (&bytes, text_size, text);
}
if (text_size)
}
};
+
+struct hb_ascii_t
+{
+ typedef uint8_t codepoint_t;
+
+ static inline const codepoint_t *
+ next (const codepoint_t *text,
+ const codepoint_t *end HB_UNUSED,
+ hb_codepoint_t *unicode,
+ hb_codepoint_t replacement HB_UNUSED)
+ {
+ *unicode = *text++;
+ if (*unicode >= 0x100)
+ *unicode = replacement;
+ return text;
+ }
+
+ static inline const codepoint_t *
+ prev (const codepoint_t *text,
+ const codepoint_t *start HB_UNUSED,
+ hb_codepoint_t *unicode,
+ hb_codepoint_t replacement)
+ {
+ *unicode = *--text;
+ if (*unicode >= 0x0080)
+ *unicode = replacement;
+ return text;
+ }
+
+ static inline unsigned int
+ strlen (const codepoint_t *text)
+ {
+ unsigned int l = 0;
+ while (*text++) l++;
+ return l;
+ }
+
+ static inline unsigned int
+ encode_len (hb_codepoint_t unicode HB_UNUSED)
+ {
+ return 1;
+ }
+
+ static inline codepoint_t *
+ encode (codepoint_t *text,
+ const codepoint_t *end HB_UNUSED,
+ hb_codepoint_t unicode)
+ {
+ if (unlikely (unicode >= 0x0080u))
+ unicode = '?';
+ *text++ = unicode;
+ return text;
+ }
+};
+
#endif /* HB_UTF_HH */