[base] Support BaseCoord format 4

Add the BASE BaseCoord format 4 dispatch arm. The format mirrors
format 2, but stores the reference glyph as a 24-bit glyph ID for
fonts with an extended glyph repertoire. Share the implementation
through a Types-templated format pair.

The subsetting path remaps the widened reference glyph in the same
way format 2 remaps its 16-bit reference glyph.

Testing: meson test -C build

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod committed 2026-06-05 12:34:51 +02:00
1 parent eb8d87f024
commit e9289735f2
1 file changed
+13 -5
+13 -5
View File
@@ -65,7 +65,8 @@ struct BaseCoordFormat1
DEFINE_SIZE_STATIC (4);
};
struct BaseCoordFormat2
template <typename Types>
struct BaseCoordFormat2_4
{
hb_position_t get_coord (hb_font_t *font, hb_direction_t direction) const
{
@@ -91,13 +92,14 @@ struct BaseCoordFormat2
}
protected:
HBUINT16 format; /* Format identifier--format = 2 */
HBUINT16 format; /* Format identifier--format = 2 or 4 */
FWORD coordinate; /* X or Y value, in design units */
HBGlyphID16 referenceGlyph; /* Glyph ID of control glyph */
typename Types::HBGlyphID
referenceGlyph; /* Glyph ID of control glyph */
HBUINT16 coordPoint; /* Index of contour point on the
* reference glyph */
public:
DEFINE_SIZE_STATIC (8);
DEFINE_SIZE_STATIC (6 + Types::HBGlyphID::static_size);
};
struct BaseCoordFormat3
@@ -175,6 +177,7 @@ struct BaseCoord
case 1: hb_barrier (); return u.format1.get_coord (font, direction);
case 2: hb_barrier (); return u.format2.get_coord (font, direction);
case 3: hb_barrier (); return u.format3.get_coord (font, var_store, direction);
case 4: hb_barrier (); return u.format4.get_coord (font, direction);
default:return 0;
}
}
@@ -196,6 +199,7 @@ struct BaseCoord
case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...));
case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward<Ts> (ds)...));
case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...));
case 4: hb_barrier (); return_trace (c->dispatch (u.format4, std::forward<Ts> (ds)...));
default:return_trace (c->default_return_value ());
}
}
@@ -209,6 +213,7 @@ struct BaseCoord
case 1: hb_barrier (); return_trace (u.format1.sanitize (c));
case 2: hb_barrier (); return_trace (u.format2.sanitize (c));
case 3: hb_barrier (); return_trace (u.format3.sanitize (c));
case 4: hb_barrier (); return_trace (u.format4.sanitize (c));
default:return_trace (false);
}
}
@@ -217,8 +222,11 @@ struct BaseCoord
union {
struct { HBUINT16 v; } format;
BaseCoordFormat1 format1;
BaseCoordFormat2 format2;
BaseCoordFormat2_4<Layout::SmallTypes>
format2;
BaseCoordFormat3 format3;
BaseCoordFormat2_4<Layout::MediumTypes>
format4;
} u;
public:
DEFINE_SIZE_UNION (2, format.v);