[ot] Add MAXP table support

Templatize the existing maxp implementation over the OpenType size
family and add MAXP as the 24-bit numGlyphs variant. Prefer MAXP when
loading the face glyph count, expose it through the face table list, and
keep MAXP as MAXP during subsetting.

The earlier order-sensitive failure reproduced only with libharfbuzz and
libharfbuzz-subset built against different lazy-loader table orders.
After rebuilding both libraries with MAXP next to maxp, the reproducer
and full suite pass.

Tested with: meson test -C build --suite subset
Tested with: meson test -C build

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod committed 2026-06-05 12:34:52 +02:00
1 parent 1f3ab6b96f
commit a45917c004
4 files changed
+30 -7

No files matched your search

+3
View File
@@ -53,6 +53,9 @@
/* OpenType fundamentals. */
HB_OT_CORE_TABLE (OT, head)
HB_OT_CORE_TABLE (OT, maxp)
#ifndef HB_NO_BEYOND_64K
HB_OT_CORE_TABLE (OT, MAXP)
#endif
#if !defined(HB_NO_FACE_COLLECT_UNICODES) || !defined(HB_NO_OT_FONT)
HB_OT_ACCELERATOR (OT, cmap)
#endif
+20 -7
View File
@@ -28,6 +28,7 @@
#define HB_OT_MAXP_TABLE_HH
#include "hb-open-type.hh"
#include "OT/Layout/types.hh"
namespace OT {
@@ -38,6 +39,7 @@ namespace OT {
*/
#define HB_OT_TAG_maxp HB_TAG('m','a','x','p')
#define HB_OT_TAG_MAXP HB_TAG('M','A','X','P')
struct maxpV1Tail
{
@@ -69,10 +71,9 @@ struct maxpV1Tail
};
struct maxp
template <typename Types>
struct maxpMAXP
{
static constexpr hb_tag_t tableTag = HB_OT_TAG_maxp;
unsigned int get_num_glyphs () const { return numGlyphs; }
void set_num_glyphs (unsigned int count)
@@ -97,10 +98,11 @@ struct maxp
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
maxp *maxp_prime = c->serializer->embed (this);
maxpMAXP *maxp_prime = c->serializer->embed (this);
if (unlikely (!maxp_prime)) return_trace (false);
maxp_prime->numGlyphs = hb_min (c->plan->num_output_glyphs (), 0xFFFFu);
maxp_prime->numGlyphs = hb_min (c->plan->num_output_glyphs (),
(1u << (8 * Types::size)) - 1);
if (maxp_prime->version.major == 1)
{
hb_barrier ();
@@ -142,11 +144,22 @@ struct maxp
protected:
FixedVersion<>version;/* Version of the maxp table (0.5 or 1.0),
* 0x00005000u or 0x00010000u. */
HBUINT16 numGlyphs;
typename Types::HBUINT
numGlyphs;
/* The number of glyphs in the font. */
/*maxpV1Tail v1Tail[HB_VAR_ARRAY]; */
public:
DEFINE_SIZE_STATIC (6);
DEFINE_SIZE_STATIC (4 + Types::HBUINT::static_size);
};
struct maxp : maxpMAXP<Layout::SmallTypes>
{
static constexpr hb_tag_t tableTag = HB_OT_TAG_maxp;
};
struct MAXP : maxpMAXP<Layout::MediumTypes>
{
static constexpr hb_tag_t tableTag = HB_OT_TAG_MAXP;
};
+4
View File
@@ -72,6 +72,10 @@ const unsigned char *endchar_str = static_endchar_str;
static inline unsigned
load_num_glyphs_from_maxp (const hb_face_t *face)
{
#ifndef HB_NO_BEYOND_64K
if (face->table.MAXP)
return face->table.MAXP->get_num_glyphs ();
#endif
return face->table.maxp->get_num_glyphs ();
}
+3
View File
@@ -22,6 +22,9 @@ bool _hb_subset_table_other (hb_subset_plan_t *plan, hb_vector_t<char> &buf, hb
case HB_TAG('v','h','e','a'): *success = true; return true; /* skip vhea, handled by vmtx */
case HB_TAG('v','m','t','x'): *success = _hb_subset_table<const OT::vmtx> (plan, buf); return true;
case HB_TAG('m','a','x','p'): *success = _hb_subset_table<const OT::maxp> (plan, buf); return true;
#ifndef HB_NO_BEYOND_64K
case HB_TAG('M','A','X','P'): *success = _hb_subset_table<const OT::MAXP> (plan, buf); return true;
#endif
case HB_TAG('l','o','c','a'): *success = true; return true; /* skip loca, handled by glyf */
case HB_TAG('c','m','a','p'): *success = _hb_subset_table<const OT::cmap> (plan, buf); return true;
case HB_TAG('O','S','/','2'): *success = _hb_subset_table<const OT::OS2 > (plan, buf); return true;