[ot-face] Unify accelerators and tables

This commit is contained in:
Behdad Esfahbod 2018-08-26 00:21:29 -07:00
parent 7f8b6fe67d
commit e6cb938065
5 changed files with 26 additions and 51 deletions

View File

@ -815,9 +815,9 @@ struct hb_lazy_loader_t : hb_data_wrapper_t<Data, WheresData>
/* Specializations. */
template <unsigned int WheresFace, typename T>
template <typename T, unsigned int WheresFace>
struct hb_face_lazy_loader_t : hb_lazy_loader_t<T,
hb_face_lazy_loader_t<WheresFace, T>,
hb_face_lazy_loader_t<T, WheresFace>,
hb_face_t, WheresFace> {};
template <typename T, unsigned int WheresFace>

View File

@ -843,7 +843,8 @@ struct cmap
{
static const hb_tag_t tableTag = HB_OT_TAG_cmap;
struct subset_plan {
struct subset_plan
{
subset_plan(void)
{
format4_segments.init();

View File

@ -138,13 +138,17 @@ void hb_ot_face_data_t::tables_t::init0 (hb_face_t *face)
{
this->face = face;
#define HB_OT_LAYOUT_TABLE(Namespace, Type) Type.init0 ();
#define HB_OT_LAYOUT_ACCELERATOR(Namespace, Type) HB_OT_LAYOUT_TABLE (Namespace, Type)
HB_OT_LAYOUT_TABLES
#undef HB_OT_LAYOUT_ACCELERATOR
#undef HB_OT_LAYOUT_TABLE
}
void hb_ot_face_data_t::tables_t::fini (void)
{
#define HB_OT_LAYOUT_TABLE(Namespace, Type) Type.fini ();
#define HB_OT_LAYOUT_ACCELERATOR(Namespace, Type) HB_OT_LAYOUT_TABLE (Namespace, Type)
HB_OT_LAYOUT_TABLES
#undef HB_OT_LAYOUT_ACCELERATOR
#undef HB_OT_LAYOUT_TABLE
}
@ -156,7 +160,6 @@ _hb_ot_face_data_create (hb_face_t *face)
return nullptr;
data->table.init0 (face);
data->accel.init0 (face);
const OT::GSUB &gsub = *data->table.GSUB;
const OT::GPOS &gpos = *data->table.GPOS;
@ -200,7 +203,6 @@ _hb_ot_face_data_destroy (hb_ot_face_data_t *data)
free (data->gsub_accels);
free (data->gpos_accels);
data->accel.fini ();
data->table.fini ();
free (data);

View File

@ -85,21 +85,23 @@ struct hb_ot_layout_lookup_accelerator_t
HB_OT_LAYOUT_TABLE(OT, fvar) \
HB_OT_LAYOUT_TABLE(OT, avar) \
HB_OT_LAYOUT_TABLE(OT, MVAR) \
/* OpenType color. */ \
HB_OT_LAYOUT_TABLE(OT, COLR) \
HB_OT_LAYOUT_TABLE(OT, CPAL) \
HB_OT_LAYOUT_TABLE(OT, CBDT) \
HB_OT_LAYOUT_TABLE(OT, CBLC) \
HB_OT_LAYOUT_TABLE(OT, sbix) \
HB_OT_LAYOUT_TABLE(OT, svg) \
/* OpenType math. */ \
HB_OT_LAYOUT_TABLE(OT, MATH) \
/* OpenType fundamentals. */ \
HB_OT_LAYOUT_ACCELERATOR(OT, cmap) \
HB_OT_LAYOUT_ACCELERATOR(OT, hmtx) \
HB_OT_LAYOUT_ACCELERATOR(OT, vmtx) \
HB_OT_LAYOUT_ACCELERATOR(OT, post) \
HB_OT_LAYOUT_ACCELERATOR(OT, kern) \
HB_OT_LAYOUT_ACCELERATOR(OT, glyf) \
HB_OT_LAYOUT_ACCELERATOR(OT, CBDT) \
/* */
/* Declare tables. */
#define HB_OT_LAYOUT_TABLE(Namespace, Type) namespace Namespace { struct Type; }
#define HB_OT_LAYOUT_ACCELERATOR(Namespace, Type) HB_OT_LAYOUT_TABLE (Namespace, Type)
HB_OT_LAYOUT_TABLES
#undef HB_OT_LAYOUT_ACCELERATOR
#undef HB_OT_LAYOUT_TABLE
struct hb_ot_face_data_t
@ -115,53 +117,23 @@ struct hb_ot_face_data_t
enum order_t
{
ORDER_ZERO,
#define HB_OT_LAYOUT_TABLE(Namespace, Type) \
HB_OT_LAYOUT_TABLE_ORDER (Namespace, Type),
#define HB_OT_LAYOUT_TABLE(Namespace, Type) HB_OT_LAYOUT_TABLE_ORDER (Namespace, Type),
#define HB_OT_LAYOUT_ACCELERATOR(Namespace, Type) HB_OT_LAYOUT_TABLE (Namespace, Type)
HB_OT_LAYOUT_TABLES
#undef HB_OT_LAYOUT_ACCELERATOR
#undef HB_OT_LAYOUT_TABLE
};
hb_face_t *face; /* MUST be JUST before the lazy loaders. */
#define HB_OT_LAYOUT_TABLE(Namespace, Type) \
hb_table_lazy_loader_t<struct Namespace::Type, HB_OT_LAYOUT_TABLE_ORDER (Namespace, Type)> Type;
#define HB_OT_LAYOUT_ACCELERATOR(Namespace, Type) \
hb_face_lazy_loader_t<struct Namespace::Type::accelerator_t, HB_OT_LAYOUT_TABLE_ORDER (Namespace, Type)> Type;
HB_OT_LAYOUT_TABLES
#undef HB_OT_LAYOUT_ACCELERATOR
#undef HB_OT_LAYOUT_TABLE
} table;
struct accelerator_t
{
inline void init0 (hb_face_t *face)
{
this->face = face;
cmap.init0 ();
hmtx.init0 ();
vmtx.init0 ();
glyf.init0 ();
cbdt.init0 ();
post.init0 ();
kern.init0 ();
}
inline void fini (void)
{
cmap.fini ();
hmtx.fini ();
vmtx.fini ();
glyf.fini ();
cbdt.fini ();
post.fini ();
kern.fini ();
}
hb_face_t *face; /* MUST be JUST before the lazy loaders. */
hb_face_lazy_loader_t<1, OT::cmap::accelerator_t> cmap;
hb_face_lazy_loader_t<2, OT::hmtx::accelerator_t> hmtx;
hb_face_lazy_loader_t<3, OT::vmtx::accelerator_t> vmtx;
hb_face_lazy_loader_t<4, OT::glyf::accelerator_t> glyf;
hb_face_lazy_loader_t<5, OT::CBDT::accelerator_t> cbdt;
hb_face_lazy_loader_t<6, OT::post::accelerator_t> post;
hb_face_lazy_loader_t<7, OT::kern::accelerator_t> kern;
} accel;
/* More accelerators. Merge into previous. */
unsigned int gsub_lookup_count;
unsigned int gpos_lookup_count;

View File

@ -33,7 +33,7 @@
#include "hb-ot-face.hh"
typedef hb_ot_face_data_t::accelerator_t hb_ot_font_t;
typedef hb_ot_face_data_t::tables_t hb_ot_font_t;
static hb_bool_t
@ -101,7 +101,7 @@ hb_ot_get_glyph_extents (hb_font_t *font,
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
bool ret = ot_font->glyf->get_extents (glyph, extents);
if (!ret)
ret = ot_font->cbdt->get_extents (glyph, extents);
ret = ot_font->CBDT->get_extents (glyph, extents);
// TODO Hook up side-bearings variations.
extents->x_bearing = font->em_scale_x (extents->x_bearing);
extents->y_bearing = font->em_scale_y (extents->y_bearing);
@ -219,7 +219,7 @@ void
hb_ot_font_set_funcs (hb_font_t *font)
{
if (unlikely (!hb_ot_shaper_face_data_ensure (font->face))) return;
hb_ot_font_t *ot_font = &hb_ot_face_data (font->face)->accel;
hb_ot_font_t *ot_font = &hb_ot_face_data (font->face)->table;
/* Load them lazies. We access them with get_relaxed() for performance. */
ot_font->cmap.get ();