[name] Hook things up
Accept Mac Latin name entries as ASCII as well.
This commit is contained in:
parent
69f5da0629
commit
4668a05006
|
@ -84,7 +84,8 @@ struct NameRecord
|
||||||
/* Symbol. */
|
/* Symbol. */
|
||||||
if (p == 3 && e == 0) return 8;
|
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;
|
return UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
@ -198,11 +199,15 @@ struct name
|
||||||
}
|
}
|
||||||
|
|
||||||
this->names.qsort (_hb_ot_name_entry_cmp);
|
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;
|
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)
|
this->names[i - 1].language == this->names[i].language)
|
||||||
continue;
|
continue;
|
||||||
this->names[j++] = this->names[i];
|
this->names[j++] = this->names[i];
|
||||||
|
@ -217,7 +222,8 @@ struct name
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_index (hb_name_id_t name_id,
|
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 key = {name_id, {0}, language};
|
||||||
const hb_ot_name_entry_t *entry = (const hb_ot_name_entry_t *)
|
const hb_ot_name_entry_t *entry = (const hb_ot_name_entry_t *)
|
||||||
|
@ -226,7 +232,13 @@ struct name
|
||||||
this->names.len,
|
this->names.len,
|
||||||
sizeof (key),
|
sizeof (key),
|
||||||
_hb_ot_name_entry_cmp_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:
|
private:
|
||||||
|
|
|
@ -106,13 +106,17 @@ hb_ot_name_get_utf (hb_face_t *face,
|
||||||
{
|
{
|
||||||
const OT::name_accelerator_t &name = _get_name (face);
|
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)
|
if (idx != -1)
|
||||||
{
|
{
|
||||||
hb_bytes_t bytes = name.table->get_name (idx);
|
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);
|
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)
|
if (text_size)
|
||||||
|
|
|
@ -398,4 +398,59 @@ struct hb_latin1_t
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
#endif /* HB_UTF_HH */
|
||||||
|
|
Loading…
Reference in New Issue