[ot-font] Implement hb_ot_get_glyph_name
Turns out we already have support for “post” table, it just needed to be activated and put in use.
This commit is contained in:
parent
bf133497e5
commit
9d4d2fb9af
|
@ -38,7 +38,7 @@
|
|||
#include "hb-ot-hmtx-table.hh"
|
||||
#include "hb-ot-os2-table.hh"
|
||||
#include "hb-ot-var-hvar-table.hh"
|
||||
//#include "hb-ot-post-table.hh"
|
||||
#include "hb-ot-post-table.hh"
|
||||
|
||||
|
||||
struct hb_ot_face_metrics_accelerator_t
|
||||
|
@ -301,6 +301,34 @@ struct hb_ot_face_cbdt_accelerator_t
|
|||
}
|
||||
};
|
||||
|
||||
struct hb_ot_face_post_accelerator_t
|
||||
{
|
||||
hb_blob_t *post_blob;
|
||||
unsigned int post_len;
|
||||
const OT::post *post;
|
||||
|
||||
inline void init (hb_face_t *face)
|
||||
{
|
||||
this->post_blob = OT::Sanitizer<OT::post>::sanitize (face->reference_table (HB_OT_TAG_post));
|
||||
this->post = OT::Sanitizer<OT::post>::lock_instance (this->post_blob);
|
||||
this->post_len = hb_blob_get_length (this->post_blob);
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
hb_blob_destroy (this->post_blob);
|
||||
}
|
||||
|
||||
inline bool get_glyph_name (hb_codepoint_t glyph,
|
||||
char *name, unsigned int size) const
|
||||
{
|
||||
if (unlikely (!name) || unlikely(!size))
|
||||
return false;
|
||||
|
||||
return this->post->get_glyph_name (glyph, name, size, this->post_len);
|
||||
}
|
||||
};
|
||||
|
||||
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
|
||||
hb_codepoint_t codepoint,
|
||||
hb_codepoint_t *glyph);
|
||||
|
@ -436,6 +464,7 @@ struct hb_ot_font_t
|
|||
hb_ot_face_metrics_accelerator_t v_metrics;
|
||||
OT::hb_lazy_loader_t<hb_ot_face_glyf_accelerator_t> glyf;
|
||||
OT::hb_lazy_loader_t<hb_ot_face_cbdt_accelerator_t> cbdt;
|
||||
OT::hb_lazy_loader_t<hb_ot_face_post_accelerator_t> post;
|
||||
};
|
||||
|
||||
|
||||
|
@ -453,6 +482,7 @@ _hb_ot_font_create (hb_face_t *face)
|
|||
ot_font->h_metrics.ascender - ot_font->h_metrics.descender); /* TODO Can we do this lazily? */
|
||||
ot_font->glyf.init (face);
|
||||
ot_font->cbdt.init (face);
|
||||
ot_font->post.init (face);
|
||||
|
||||
return ot_font;
|
||||
}
|
||||
|
@ -467,6 +497,7 @@ _hb_ot_font_destroy (void *data)
|
|||
ot_font->v_metrics.fini ();
|
||||
ot_font->glyf.fini ();
|
||||
ot_font->cbdt.fini ();
|
||||
ot_font->post.fini ();
|
||||
|
||||
free (ot_font);
|
||||
}
|
||||
|
@ -535,6 +566,17 @@ hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED,
|
||||
void *font_data,
|
||||
hb_codepoint_t glyph,
|
||||
char *name, unsigned int size,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
||||
return ot_font->post->get_glyph_name (glyph, name, size);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_ot_get_font_h_extents (hb_font_t *font HB_UNUSED,
|
||||
void *font_data,
|
||||
|
@ -595,7 +637,7 @@ retry:
|
|||
//hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, nullptr, nullptr); TODO
|
||||
//hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr); TODO
|
||||
hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr); TODO
|
||||
|
||||
hb_font_funcs_make_immutable (funcs);
|
||||
|
|
|
@ -29,6 +29,48 @@
|
|||
|
||||
#include "hb-open-type-private.hh"
|
||||
|
||||
#define NUM_FORMAT1_NAMES 258
|
||||
|
||||
static const char* const format1_names[NUM_FORMAT1_NAMES] =
|
||||
{
|
||||
".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl",
|
||||
"numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft",
|
||||
"parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
|
||||
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
|
||||
"nine", "colon", "semicolon", "less", "equal", "greater", "question", "at",
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
|
||||
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft",
|
||||
"backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b",
|
||||
"c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
|
||||
"r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar",
|
||||
"braceright", "asciitilde", "Adieresis", "Aring", "Ccedilla", "Eacute",
|
||||
"Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex",
|
||||
"adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave",
|
||||
"ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis",
|
||||
"ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute",
|
||||
"ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling",
|
||||
"section", "bullet", "paragraph", "germandbls", "registered", "copyright",
|
||||
"trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity",
|
||||
"plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff",
|
||||
"summation", "product", "pi", "integral", "ordfeminine", "ordmasculine",
|
||||
"Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot",
|
||||
"radical", "florin", "approxequal", "Delta", "guillemotleft",
|
||||
"guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde",
|
||||
"Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright",
|
||||
"quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis",
|
||||
"fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl",
|
||||
"daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase",
|
||||
"perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave",
|
||||
"Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
|
||||
"apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi",
|
||||
"circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla",
|
||||
"hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron",
|
||||
"Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn",
|
||||
"thorn", "minus", "multiply", "onesuperior", "twosuperior", "threesuperior",
|
||||
"onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve",
|
||||
"Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron",
|
||||
"dcroat",
|
||||
};
|
||||
|
||||
namespace OT {
|
||||
|
||||
|
@ -77,6 +119,60 @@ struct post
|
|||
return_trace (true);
|
||||
}
|
||||
|
||||
inline bool get_glyph_name (hb_codepoint_t glyph,
|
||||
char *buffer, unsigned int buffer_length,
|
||||
unsigned int blob_len) const
|
||||
{
|
||||
if (version.to_int () == 0x00010000)
|
||||
{
|
||||
if (glyph >= NUM_FORMAT1_NAMES)
|
||||
return false;
|
||||
|
||||
strncpy(buffer, format1_names[glyph], buffer_length);
|
||||
buffer[buffer_length] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
if (version.to_int () == 0x00020000)
|
||||
{
|
||||
const postV2Tail &v2 = StructAfter<postV2Tail>(*this);
|
||||
|
||||
if (glyph >= v2.numberOfGlyphs)
|
||||
return false;
|
||||
|
||||
unsigned int index = v2.glyphNameIndex[glyph];
|
||||
if (index >= NUM_FORMAT1_NAMES)
|
||||
{
|
||||
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs;
|
||||
char* data = (char*) this + offset;
|
||||
for (unsigned int i = 0; data < (char*) this + blob_len; i++)
|
||||
{
|
||||
unsigned int name_length = data[0];
|
||||
data++;
|
||||
if (i == index - NUM_FORMAT1_NAMES)
|
||||
{
|
||||
unsigned int remaining = (char*) this + blob_len - data;
|
||||
name_length = MIN (name_length, buffer_length);
|
||||
name_length = MIN (name_length, remaining);
|
||||
memcpy (buffer, data, name_length);
|
||||
buffer[name_length] = '\0';
|
||||
return true;
|
||||
}
|
||||
data += name_length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(buffer, format1_names[index], buffer_length);
|
||||
buffer[buffer_length] = '\0';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
FixedVersion<>version; /* 0x00010000 for version 1.0
|
||||
* 0x00020000 for version 2.0
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ft:U+0078,U+0301,U+0058,U+0301:[x=0+1030|acutecomb=0@-45,-32+0|X=2+1295|acutecomb=2@-171,310+0]
|
||||
fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ot:U+0078,U+0301,U+0058,U+0301:[gid2=0+1030|gid4=0@-21,-27+0|gid1=2+1295|gid4=2@-147,321+0]
|
||||
fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ot:U+0078,U+0301,U+0058,U+0301:[x=0+1030|acutecomb=0@-21,-27+0|X=2+1295|acutecomb=2@-147,321+0]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fonts/sha1sum/54674a3111d209fb6be0ed31745314b7a8d2c244.ttf::U+0BA4,U+0BCD,U+00B3:[taprehalftamil=0+1509|uni00B3=2+674]
|
||||
fonts/sha1sum/3d0b77a2360aa6faa1385aaa510509ab70dfbeff.ttf::U+0CF1:[gid1=0+1129]
|
||||
fonts/sha1sum/3d0b77a2360aa6faa1385aaa510509ab70dfbeff.ttf::U+0CF2:[gid2=0+1539]
|
||||
fonts/sha1sum/87f85d17d26f1fe9ad28d7365101958edaefb967.ttf:--font-funcs=ot:U+0980,U+0981:[gid1=0+520|gid2=0+0]
|
||||
fonts/sha1sum/87f85d17d26f1fe9ad28d7365101958edaefb967.ttf:--font-funcs=ot:U+0980,U+0981:[anjibeng=0+520|candrabindubeng=0+0]
|
||||
fonts/sha1sum/85fe0be440c64ac77699e21c2f1bd933a919167e.ttf::U+0A15,U+0A51,U+0A47:[kaguru=0+1273|udaatguru=0@75,0+0|eematraguru=0@-40,0+0]
|
||||
fonts/sha1sum/1735326da89f0818cd8c51a0600e9789812c0f94.ttf::U+0A51:[uni25CC=0+1044|udaatguru=0+0]
|
||||
fonts/sha1sum/1735326da89f0818cd8c51a0600e9789812c0f94.ttf::U+25CC,U+0A51:[uni25CC=0+1044|udaatguru=0+0]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fonts/sha1sum/fbb6c84c9e1fe0c39e152fbe845e51fd81f6748e.ttf::U+1B1B,U+1B44,U+1B13,U+1B3E:[gid3=0+990|gid7=0+2473|gid5=0@-293,-400+0]
|
||||
fonts/sha1sum/4cce528e99f600ed9c25a2b69e32eb94a03b4ae8.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+0|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212]
|
||||
fonts/sha1sum/f518eb6f6b5eec2946c9fbbbde44e45d46f5e2ac.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+1211|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212]
|
||||
fonts/sha1sum/6ff0fbead4462d9f229167b4e6839eceb8465058.ttf:--font-funcs=ot:U+11103,U+11128:[gid1=0+837|gid2=0+0]
|
||||
fonts/sha1sum/6ff0fbead4462d9f229167b4e6839eceb8465058.ttf:--font-funcs=ot:U+11103,U+11128:[u11103=0+837|u11128=0+0]
|
||||
|
|
Loading…
Reference in New Issue