Make main.cc compile again, which means finished getter API
This commit is contained in:
parent
e50c3978d3
commit
40a81314fa
|
@ -106,7 +106,11 @@
|
|||
if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
|
||||
return *(const Type *)((const char*)this + array[i].offset); \
|
||||
} \
|
||||
/* TODO: implement find_tag() and get_tag() publicly */
|
||||
inline const Tag& get_tag (unsigned int i) const { \
|
||||
if (HB_UNLIKELY (i >= num)) return NullTag; \
|
||||
return array[i].tag; \
|
||||
}
|
||||
/* TODO: implement bsearch find_tag() and use it */
|
||||
|
||||
|
||||
#define DEFINE_ARRAY_INTERFACE(Type, name) \
|
||||
|
@ -124,32 +128,53 @@
|
|||
return this->get_len (); \
|
||||
}
|
||||
|
||||
#define DEFINE_FIND_TAG_INTERFACE(Type, name) \
|
||||
inline const Type* find_##name (hb_tag_t tag) const { \
|
||||
for (unsigned int i = 0; i < this->get_len (); i++) \
|
||||
if (tag == (*this)[i].tag) \
|
||||
return &(*this)[i]; \
|
||||
return NULL; \
|
||||
} \
|
||||
inline const Type& get_##name##_by_tag (hb_tag_t tag) const { \
|
||||
for (unsigned int i = 0; i < this->get_len (); i++) \
|
||||
if (tag == (*this)[i].tag) \
|
||||
return (*this)[i]; \
|
||||
return Null##Type; \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* List types
|
||||
*/
|
||||
|
||||
#define DEFINE_LIST_ACCESSOR(Type, name) \
|
||||
#define DEFINE_LIST_ARRAY(Type, name) \
|
||||
inline const Type##List& get_##name##_list (void) const { \
|
||||
if (HB_UNLIKELY (!name##List)) return Null##Type##List; \
|
||||
return *(const Type##List *)((const char*)this + name##List); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFINE_LIST_INTERFACE(Type, name) \
|
||||
inline const Type& get_##name (unsigned int i) const { \
|
||||
return get_##name##_list ()[i]; \
|
||||
} \
|
||||
inline unsigned int get_##name##_count (void) const { \
|
||||
return get_##name##_list ().get_len (); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Tag types
|
||||
*/
|
||||
|
||||
#define DEFINE_TAG_ARRAY_INTERFACE(Type, name) \
|
||||
DEFINE_ARRAY_INTERFACE (Type, name); \
|
||||
inline hb_tag_t get_##name##_tag (unsigned int i) const { \
|
||||
return (*this)[i].tag; \
|
||||
}
|
||||
#define DEFINE_TAG_LIST_INTERFACE(Type, name) \
|
||||
DEFINE_LIST_INTERFACE (Type, name); \
|
||||
inline const Tag& get_##name##_tag (unsigned int i) const { \
|
||||
return get_##name##_list ().get_tag (i); \
|
||||
}
|
||||
|
||||
#define DEFINE_TAG_FIND_INTERFACE(Type, name) \
|
||||
inline const Type* find_##name (hb_tag_t tag) const { \
|
||||
for (unsigned int i = 0; i < get_##name##_count (); i++) \
|
||||
if (tag == get_##name##_tag (i)) \
|
||||
return &get_##name (i); \
|
||||
return NULL; \
|
||||
} \
|
||||
inline const Type& get_##name##_by_tag (hb_tag_t tag) const { \
|
||||
const Type* res = find_##name (tag); \
|
||||
if (res) \
|
||||
return *res; \
|
||||
else \
|
||||
return Null##Type; \
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -344,7 +369,7 @@ typedef struct TableDirectory {
|
|||
friend struct OffsetTable;
|
||||
|
||||
inline bool is_null (void) const { return length == 0; }
|
||||
inline hb_tag_t get_tag (void) const { return tag; }
|
||||
inline const Tag& get_tag (void) const { return tag; }
|
||||
inline unsigned long get_checksum (void) const { return checkSum; }
|
||||
inline unsigned long get_offset (void) const { return offset; }
|
||||
inline unsigned long get_length (void) const { return length; }
|
||||
|
@ -364,8 +389,8 @@ typedef struct OffsetTable {
|
|||
friend struct OpenTypeFontFile;
|
||||
friend struct TTCHeader;
|
||||
|
||||
DEFINE_ARRAY_INTERFACE (OpenTypeTable, table);
|
||||
DEFINE_FIND_TAG_INTERFACE (OpenTypeTable, table);
|
||||
DEFINE_TAG_ARRAY_INTERFACE (OpenTypeTable, table); /* get_table_count(), get_table(i), get_table_tag(i) */
|
||||
DEFINE_TAG_FIND_INTERFACE (OpenTypeTable, table); /* find_table(tag), get_table_by_tag(tag) */
|
||||
|
||||
private:
|
||||
/* OpenTypeTables, in no particular order */
|
||||
|
@ -418,9 +443,9 @@ struct OpenTypeFontFile {
|
|||
|
||||
STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
|
||||
|
||||
DEFINE_ARRAY_INTERFACE (OpenTypeFontFace, face);
|
||||
DEFINE_ARRAY_INTERFACE (OpenTypeFontFace, face); /* get_face_count(), get_face(i) */
|
||||
|
||||
inline hb_tag_t get_tag (void) const { return tag; }
|
||||
inline const Tag& get_tag (void) const { return tag; }
|
||||
|
||||
/* This is how you get a table */
|
||||
inline const char* get_table_data (const OpenTypeTable& table) const {
|
||||
|
@ -510,19 +535,28 @@ struct LangSys {
|
|||
DEFINE_NULL_ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
|
||||
|
||||
struct Script {
|
||||
/* LangSys', in sorted alphabetical tag order */
|
||||
DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
|
||||
|
||||
inline const bool has_default_language_system (void) const {
|
||||
DEFINE_ARRAY_INTERFACE (LangSys, lang_sys); /* get_lang_sys_count(), get_lang_sys(i) */
|
||||
|
||||
inline const Tag& get_lang_sys_tag (unsigned int i) const {
|
||||
return get_tag (i);
|
||||
}
|
||||
|
||||
/* TODO bsearch */
|
||||
DEFINE_TAG_FIND_INTERFACE (LangSys, lang_sys); /* find_lang_sys (), get_lang_sys_by_tag (tag) */
|
||||
|
||||
inline const bool has_default_lang_sys (void) const {
|
||||
return defaultLangSys != 0;
|
||||
}
|
||||
inline const LangSys& get_default_language_system (void) const {
|
||||
inline const LangSys& get_default_lang_sys (void) const {
|
||||
if (HB_UNLIKELY (!defaultLangSys))
|
||||
return NullLangSys;
|
||||
return *(LangSys*)((const char*)this + defaultLangSys);
|
||||
}
|
||||
|
||||
/* TODO implement find_language_system based on find_tag */
|
||||
private:
|
||||
/* LangSys', in sorted alphabetical tag order */
|
||||
DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
|
||||
|
||||
private:
|
||||
Offset defaultLangSys; /* Offset to DefaultLangSys table--from
|
||||
|
@ -535,6 +569,10 @@ struct Script {
|
|||
DEFINE_NULL_ASSERT_SIZE (Script, 4);
|
||||
|
||||
struct ScriptList {
|
||||
|
||||
friend struct GSUBGPOS;
|
||||
|
||||
private:
|
||||
/* Scripts, in sorted alphabetical tag order */
|
||||
DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount);
|
||||
|
||||
|
@ -567,6 +605,10 @@ struct Feature {
|
|||
DEFINE_NULL_ASSERT_SIZE (Feature, 4);
|
||||
|
||||
struct FeatureList {
|
||||
|
||||
friend struct GSUBGPOS;
|
||||
|
||||
private:
|
||||
/* Feature indices, in sorted alphabetical tag order */
|
||||
DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount);
|
||||
|
||||
|
@ -620,6 +662,10 @@ struct Lookup {
|
|||
DEFINE_NULL_ASSERT_SIZE (Lookup, 6);
|
||||
|
||||
struct LookupList {
|
||||
|
||||
friend struct GSUBGPOS;
|
||||
|
||||
private:
|
||||
/* Lookup indices, in sorted alphabetical tag order */
|
||||
DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount);
|
||||
|
||||
|
@ -889,9 +935,18 @@ typedef struct GSUBGPOS {
|
|||
STATIC_DEFINE_GET_FOR_DATA (GSUBGPOS);
|
||||
/* XXX check version here? */
|
||||
|
||||
DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
|
||||
DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */
|
||||
DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list, get_lookup(i) */
|
||||
DEFINE_TAG_LIST_INTERFACE (Script, script ); /* get_script_count (), get_script (i), get_script_tag (i) */
|
||||
DEFINE_TAG_LIST_INTERFACE (Feature, feature); /* get_feature_count(), get_feature(i), get_feature_tag(i) */
|
||||
DEFINE_LIST_INTERFACE (Lookup, lookup ); /* get_lookup_count (), get_lookup (i) */
|
||||
|
||||
/* TODO bsearch */
|
||||
DEFINE_TAG_FIND_INTERFACE (Script, script ); /* find_script (), get_script_by_tag (tag) */
|
||||
DEFINE_TAG_FIND_INTERFACE (Feature, feature); /* find_feature(), get_feature_by_tag(tag) */
|
||||
|
||||
private:
|
||||
DEFINE_LIST_ARRAY(Script, script);
|
||||
DEFINE_LIST_ARRAY(Feature, feature);
|
||||
DEFINE_LIST_ARRAY(Lookup, lookup);
|
||||
|
||||
private:
|
||||
Fixed_Version version; /* Version of the GSUB/GPOS table--initially set
|
||||
|
|
93
src/main.cc
93
src/main.cc
|
@ -67,66 +67,105 @@ main (int argc, char **argv)
|
|||
printf ("%d font(s) found in file\n", num_fonts);
|
||||
for (int n_font = 0; n_font < num_fonts; n_font++) {
|
||||
const OpenTypeFontFace &font = ot.get_face (n_font);
|
||||
printf ("Font %d of %d:\n", n_font+1, num_fonts);
|
||||
printf ("Font %d of %d:\n", n_font, num_fonts);
|
||||
|
||||
int num_tables = font.get_table_count ();
|
||||
printf (" %d table(s) found in font\n", num_tables);
|
||||
for (int n_table = 0; n_table < num_tables; n_table++) {
|
||||
const OpenTypeTable &table = font.get_table (n_table);
|
||||
printf (" Table %2d of %2d: %.4s (0x%08lx+0x%08lx)\n", n_table+1, num_tables,
|
||||
printf (" Table %2d of %2d: %.4s (0x%08lx+0x%08lx)\n", n_table, num_tables,
|
||||
(const char *)table.get_tag(), table.get_offset(), table.get_length());
|
||||
|
||||
if (table.get_tag() == GSUBGPOS::GSUBTag || table.get_tag() == GSUBGPOS::GPOSTag) {
|
||||
switch (table.get_tag ()) {
|
||||
|
||||
case GSUBGPOS::GSUBTag:
|
||||
case GSUBGPOS::GPOSTag:
|
||||
{
|
||||
|
||||
const GSUBGPOS &g = GSUBGPOS::get_for_data (ot.get_table_data (table));
|
||||
|
||||
const ScriptList &scripts = g.get_script_list();
|
||||
int num_scripts = scripts.get_len ();
|
||||
int num_scripts = g.get_script_count ();
|
||||
printf (" %d script(s) found in table\n", num_scripts);
|
||||
for (int n_script = 0; n_script < num_scripts; n_script++) {
|
||||
const Script &script = scripts[n_script];
|
||||
printf (" Script %2d of %2d: %.4s\n", n_script+1, num_scripts,
|
||||
(const char *)scripts.get_tag(n_script));
|
||||
const Script &script = g.get_script (n_script);
|
||||
printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts,
|
||||
(const char *)g.get_script_tag(n_script));
|
||||
|
||||
if (!script.has_default_language_system())
|
||||
if (!script.has_default_lang_sys())
|
||||
printf (" No default language system\n");
|
||||
int num_langsys = script.get_len ();
|
||||
int num_langsys = script.get_lang_sys_count ();
|
||||
printf (" %d language system(s) found in script\n", num_langsys);
|
||||
for (int n_langsys = 0; n_langsys < num_langsys; n_langsys++) {
|
||||
const LangSys &langsys = script[n_langsys];
|
||||
printf (" Language System %2d of %2d: %.4s; %d features\n", n_langsys+1, num_langsys,
|
||||
(const char *)script.get_tag(n_langsys),
|
||||
langsys.get_len ());
|
||||
for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) {
|
||||
const LangSys &langsys = n_langsys == -1
|
||||
? script.get_default_lang_sys ()
|
||||
: script.get_lang_sys (n_langsys);
|
||||
printf (n_langsys == -1
|
||||
? " Default Language System\n"
|
||||
: " Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
|
||||
(const char *)script.get_lang_sys_tag (n_langsys));
|
||||
if (!langsys.get_required_feature_index ())
|
||||
printf (" No required feature\n");
|
||||
|
||||
int num_features = langsys.get_feature_count ();
|
||||
printf (" %d feature(s) found in language system\n", num_features);
|
||||
for (int n_feature = 0; n_feature < num_features; n_feature++) {
|
||||
unsigned int feature_index = langsys.get_feature_index (n_feature);
|
||||
printf (" Feature index %2d of %2d: %d\n", n_feature, num_features,
|
||||
langsys.get_feature_index (n_feature));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const FeatureList &features = g.get_feature_list();
|
||||
int num_features = features.get_len ();
|
||||
int num_features = g.get_feature_count ();
|
||||
printf (" %d feature(s) found in table\n", num_features);
|
||||
for (int n_feature = 0; n_feature < num_features; n_feature++) {
|
||||
const Feature &feature = features[n_feature];
|
||||
printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature+1, num_features,
|
||||
(const char *)features.get_tag(n_feature),
|
||||
feature.get_len());
|
||||
const Feature &feature = g.get_feature (n_feature);
|
||||
printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature, num_features,
|
||||
(const char *)g.get_feature_tag(n_feature),
|
||||
feature.get_lookup_count());
|
||||
|
||||
int num_lookups = feature.get_lookup_count ();
|
||||
printf (" %d lookup(s) found in language system\n", num_lookups);
|
||||
for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
|
||||
unsigned int lookup_index = feature.get_lookup_index (n_lookup);
|
||||
printf (" Feature index %2d of %2d: %d\n", n_lookup, num_lookups,
|
||||
feature.get_lookup_index (n_lookup));
|
||||
}
|
||||
}
|
||||
|
||||
const LookupList &lookups = g.get_lookup_list();
|
||||
int num_lookups = lookups.get_len ();
|
||||
int num_lookups = g.get_lookup_count ();
|
||||
printf (" %d lookup(s) found in table\n", num_lookups);
|
||||
for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
|
||||
const Lookup &lookup = lookups[n_lookup];
|
||||
printf (" Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups,
|
||||
const Lookup &lookup = g.get_lookup (n_lookup);
|
||||
printf (" Lookup %2d of %2d: type %d, flags 0x%04X\n", n_lookup, num_lookups,
|
||||
lookup.get_type(), lookup.get_flag());
|
||||
}
|
||||
} else if (table.get_tag() == "GDEF") {
|
||||
const GDEF &gdef = GDEF::get_for_data (ot[table]);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case GDEF::Tag:
|
||||
{
|
||||
|
||||
const GDEF &gdef = GDEF::get_for_data (ot.get_table_data (table));
|
||||
|
||||
printf (" Has %sglyph classes\n",
|
||||
gdef.has_glyph_classes () ? "" : "no ");
|
||||
printf (" Has %smark attachment types\n",
|
||||
gdef.has_mark_attachment_types () ? "" : "no ");
|
||||
printf (" Has %sattach list\n",
|
||||
gdef.has_attach_list () ? "" : "no ");
|
||||
printf (" Has %slig caret list\n",
|
||||
gdef.has_lig_caret_list () ? "" : "no ");
|
||||
|
||||
for (int glyph = 0; glyph < 1; glyph++)
|
||||
printf (" glyph %d has class %d and mark attachment type %d\n",
|
||||
glyph,
|
||||
gdef.get_glyph_class (glyph),
|
||||
gdef.get_mark_attachment_type (glyph));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue