[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Oct 25 23:30:34 UTC 2017
src/hb-ot-font.cc | 68 ++++++++++-
src/hb-ot-post-table.hh | 154 ++++++++++++++++++++++++++
test/shaping/tests/fallback-positioning.tests | 2
test/shaping/tests/indic-syllable.tests | 2
test/shaping/tests/use.tests | 2
5 files changed, 222 insertions(+), 6 deletions(-)
New commits:
commit d9e166f74c3ba3128c9ef3ccd8d7799e67f14eab
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Wed Oct 18 20:49:16 2017 +0200
[ot-font] Implement hb_ot_get_glyph_from_name
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 62cef9b5..dff27bf4 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -327,6 +327,15 @@ struct hb_ot_face_post_accelerator_t
return this->post->get_glyph_name (glyph, name, size, this->post_len);
}
+
+ inline bool get_glyph_from_name (const char *name, int len,
+ hb_codepoint_t *glyph) const
+ {
+ if (unlikely (!name) || unlikely(!len))
+ return false;
+
+ return this->post->get_glyph_from_name (name, len, glyph, this->post_len);
+ }
};
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
@@ -578,6 +587,17 @@ hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED,
}
static hb_bool_t
+hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED,
+ void *font_data,
+ const char *name, int len,
+ hb_codepoint_t *glyph,
+ 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_from_name (name, len, glyph);
+}
+
+static hb_bool_t
hb_ot_get_font_h_extents (hb_font_t *font HB_UNUSED,
void *font_data,
hb_font_extents_t *metrics,
@@ -638,7 +658,7 @@ retry:
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);
- //hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr); TODO
+ hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr);
hb_font_funcs_make_immutable (funcs);
diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh
index 3240ec66..c0d25f2b 100644
--- a/src/hb-ot-post-table.hh
+++ b/src/hb-ot-post-table.hh
@@ -173,6 +173,64 @@ struct post
return false;
}
+ inline bool get_glyph_from_name (const char *name, int len,
+ hb_codepoint_t *glyph,
+ unsigned int blob_len) const
+ {
+ if (len < 0)
+ len = strlen (name);
+
+ if (version.to_int () == 0x00010000)
+ {
+ for (int i = 0; i < NUM_FORMAT1_NAMES; i++)
+ {
+ if (strncmp (name, format1_names[i], len) == 0)
+ {
+ *glyph = i;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ if (version.to_int () == 0x00020000)
+ {
+ const postV2Tail &v2 = StructAfter<postV2Tail>(*this);
+ unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs;
+ char* data = (char*) this + offset;
+
+ for (hb_codepoint_t gid = 0; gid < v2.numberOfGlyphs; gid++)
+ {
+ unsigned int index = v2.glyphNameIndex[gid];
+ if (index >= NUM_FORMAT1_NAMES)
+ {
+ for (unsigned int i = 0; data < (char*) this + blob_len; i++)
+ {
+ unsigned int name_length = data[0];
+ unsigned int remaining = (char*) this + blob_len - data - 1;
+ name_length = MIN (name_length, remaining);
+ if (name_length == len && strncmp (name, data + 1, len) == 0)
+ {
+ *glyph = gid;
+ return true;
+ }
+ data += name_length + 1;
+ }
+ return false;
+ }
+ else if (strncmp (name, format1_names[index], len) == 0)
+ {
+ *glyph = gid;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return false;
+ }
+
public:
FixedVersion<>version; /* 0x00010000 for version 1.0
* 0x00020000 for version 2.0
commit 9d4d2fb9af446d5d41058fbb1da8117b3af048d3
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Mon Oct 16 10:05:42 2017 +0200
[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.
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 06d1b806..62cef9b5 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -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);
}
@@ -536,6 +567,17 @@ hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED,
}
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,
hb_font_extents_t *metrics,
@@ -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);
diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh
index 82ab3882..3240ec66 100644
--- a/src/hb-ot-post-table.hh
+++ b/src/hb-ot-post-table.hh
@@ -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
diff --git a/test/shaping/tests/fallback-positioning.tests b/test/shaping/tests/fallback-positioning.tests
index 499db7d8..0529b24b 100644
--- a/test/shaping/tests/fallback-positioning.tests
+++ b/test/shaping/tests/fallback-positioning.tests
@@ -1,2 +1,2 @@
fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ft:U+0078,U+0301,U+0058,U+0301:[x=0+1030|acutecomb=0 at -45,-32+0|X=2+1295|acutecomb=2 at -171,310+0]
-fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ot:U+0078,U+0301,U+0058,U+0301:[gid2=0+1030|gid4=0 at -21,-27+0|gid1=2+1295|gid4=2 at -147,321+0]
+fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ot:U+0078,U+0301,U+0058,U+0301:[x=0+1030|acutecomb=0 at -21,-27+0|X=2+1295|acutecomb=2 at -147,321+0]
diff --git a/test/shaping/tests/indic-syllable.tests b/test/shaping/tests/indic-syllable.tests
index 500fa84b..24118ea5 100644
--- a/test/shaping/tests/indic-syllable.tests
+++ b/test/shaping/tests/indic-syllable.tests
@@ -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 at 75,0+0|eematraguru=0 at -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]
diff --git a/test/shaping/tests/use.tests b/test/shaping/tests/use.tests
index bfce117d..6ffd1264 100644
--- a/test/shaping/tests/use.tests
+++ b/test/shaping/tests/use.tests
@@ -1,4 +1,4 @@
fonts/sha1sum/fbb6c84c9e1fe0c39e152fbe845e51fd81f6748e.ttf::U+1B1B,U+1B44,U+1B13,U+1B3E:[gid3=0+990|gid7=0+2473|gid5=0 at -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]
More information about the HarfBuzz
mailing list