[glyf] Prefer extended outline table pair

Use GLYF and LOCA when both tables are present, and fall back to the
lowercase pair when either extended table is absent.

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod committed 2026-06-05 12:34:52 +02:00
1 parent c09526c5e6
commit 463616a2c1
3 files changed
+109 -2

No files matched your search

+25 -2
View File
@@ -24,6 +24,7 @@ namespace OT {
* https://docs.microsoft.com/en-us/typography/opentype/spec/glyf
*/
#define HB_OT_TAG_glyf HB_TAG('g','l','y','f')
#define HB_OT_TAG_GLYF HB_TAG('G','L','Y','F')
struct glyf
{
@@ -166,6 +167,7 @@ struct glyf_accelerator_t
{
glyf_accelerator_t (hb_face_t *face)
{
extended = false;
short_offset = false;
num_glyphs = 0;
loca_table = nullptr;
@@ -183,8 +185,26 @@ struct glyf_accelerator_t
return;
short_offset = 0 == head.indexToLocFormat;
loca_table = face->table.loca.get_blob (); // Needs no destruct!
glyf_table = hb_sanitize_context_t ().reference_table<glyf> (face);
#ifndef HB_NO_BEYOND_64K
hb_blob_ptr_t<glyf> GLYF_table = hb_sanitize_context_t ().reference_table<glyf> (face, HB_OT_TAG_GLYF);
hb_blob_ptr_t<loca> LOCA_table = hb_sanitize_context_t ().reference_table<loca> (face, HB_OT_TAG_LOCA);
extended = GLYF_table.get_length () && LOCA_table.get_length ();
if (extended)
{
glyf_table = std::move (GLYF_table);
loca_table = std::move (LOCA_table);
}
else
{
GLYF_table.destroy ();
LOCA_table.destroy ();
}
#endif
if (!extended)
{
glyf_table = hb_sanitize_context_t ().reference_table<glyf> (face);
loca_table = hb_sanitize_context_t ().reference_table<loca> (face);
}
#ifndef HB_NO_VAR
gvar = face->table.gvar;
#endif
@@ -206,9 +226,11 @@ struct glyf_accelerator_t
}
glyf_table.destroy ();
loca_table.destroy ();
}
bool has_data () const { return num_glyphs; }
bool is_extended () const { return extended; }
protected:
template<typename T>
@@ -545,6 +567,7 @@ struct glyf_accelerator_t
#endif
private:
bool extended;
bool short_offset;
unsigned int num_glyphs;
hb_blob_ptr_t<loca> loca_table;
+1
View File
@@ -13,6 +13,7 @@ namespace OT {
* https://docs.microsoft.com/en-us/typography/opentype/spec/loca
*/
#define HB_OT_TAG_loca HB_TAG('l','o','c','a')
#define HB_OT_TAG_LOCA HB_TAG('L','O','C','A')
struct loca
{
+83
View File
@@ -67,6 +67,86 @@ test_maxp_and_loca (void)
#endif
}
#ifndef HB_NO_BEYOND_64K
static hb_face_t *
create_glyf_face (hb_bool_t add_GLYF, hb_bool_t add_LOCA)
{
static const char maxp_data[] =
"\x00\x00\x50\x00" /* version */
"\x00\x01" /* numGlyphs */
;
static const char head_data[54] =
"\x00\x01\x00\x00" /* version */
"\x00\x00\x00\x00" /* fontRevision */
"\x00\x00\x00\x00" /* checkSumAdjustment */
"\x5F\x0F\x3C\xF5" /* magicNumber */
"\x00\x00" /* flags */
"\x03\xE8" /* unitsPerEm */
"\x00\x00\x00\x00\x00\x00\x00\x00" /* created */
"\x00\x00\x00\x00\x00\x00\x00\x00" /* modified */
"\x00\x00\x00\x00\x00\x00\x00\x00" /* bounds */
"\x00\x00" /* macStyle */
"\x00\x00" /* lowestRecPPEM */
"\x00\x00" /* fontDirectionHint */
"\x00\x01" /* indexToLocFormat */
"\x00\x00" /* glyphDataFormat */
;
static const char loca_data[8] =
"\x00\x00\x00\x00"
"\x00\x00\x00\x0A"
;
static const char glyf_data[10] =
"\x00\x01" /* numberOfContours */
"\x00\x01\x00\x02\x00\x04\x00\x06" /* bounds */
;
static const char GLYF_data[10] =
"\x00\x01" /* numberOfContours */
"\x00\x0B\x00\x0C\x00\x18\x00\x1A" /* bounds */
;
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
HB_FACE_ADD_TABLE (face, "head", head_data);
HB_FACE_ADD_TABLE (face, "glyf", glyf_data);
HB_FACE_ADD_TABLE (face, "loca", loca_data);
if (add_GLYF)
HB_FACE_ADD_TABLE (face, "GLYF", GLYF_data);
if (add_LOCA)
HB_FACE_ADD_TABLE (face, "LOCA", loca_data);
return face;
}
static void
test_GLYF_and_LOCA (void)
{
hb_glyph_extents_t extents;
hb_face_t *face;
hb_font_t *font;
face = create_glyf_face (TRUE, TRUE);
g_assert_cmpuint (hb_face_get_glyph_count (face), ==, 1);
font = hb_font_create (face);
hb_face_destroy (face);
g_assert_true (hb_font_get_glyph_extents (font, 0, &extents));
g_assert_cmpint (extents.width, ==, 13);
hb_font_destroy (font);
face = create_glyf_face (TRUE, FALSE);
font = hb_font_create (face);
hb_face_destroy (face);
g_assert_true (hb_font_get_glyph_extents (font, 0, &extents));
g_assert_cmpint (extents.width, ==, 3);
hb_font_destroy (font);
face = create_glyf_face (FALSE, TRUE);
font = hb_font_create (face);
hb_face_destroy (face);
g_assert_true (hb_font_get_glyph_extents (font, 0, &extents));
g_assert_cmpint (extents.width, ==, 3);
hb_font_destroy (font);
}
#endif
int
main (int argc, char **argv)
@@ -74,6 +154,9 @@ main (int argc, char **argv)
hb_test_init (&argc, &argv);
hb_test_add (test_maxp_and_loca);
#ifndef HB_NO_BEYOND_64K
hb_test_add (test_GLYF_and_LOCA);
#endif
return hb_test_run();
}