Define get_for_data() factories

This commit is contained in:
Behdad Esfahbod 2008-01-23 02:01:37 -05:00
parent b9d7688fb3
commit 600e5eb80f
3 changed files with 36 additions and 19 deletions

View File

@ -170,6 +170,9 @@ struct CaretValue {
DEFINE_ACCESSOR0( , Type, name, Name)
struct GDEFHeader {
static const hb_tag_t GDEFTag = HB_TAG ('G','D','E','F');
STATIC_DEFINE_GET_FOR_DATA (GDEFHeader);
DEFINE_ACCESSOR (ClassDef, get_glyph_class_def, glyphClassDef);
DEFINE_ACCESSOR (AttachList, get_attach_list, attachList);

View File

@ -49,10 +49,6 @@
DEFINE_LEN(Type, array, num) \
DEFINE_SIZE(Type, array, num)
#define DEFINE_NON_INSTANTIABLE(Type) \
private: inline Type() {} /* cannot be instantiated */ \
public:
/* An array type is one that contains a variable number of objects
* as its last item. An array object is extended with len() and size()
* methods, as well as overloaded [] operator. */
@ -98,6 +94,30 @@
/*
* Class features
*/
/* makes class uninstantiable. should be used for union classes that don't
* contain any complete type */
#define DEFINE_NON_INSTANTIABLE(Type) \
private: inline Type() {} /* cannot be instantiated */ \
public:
/* get_for_data() is a static class method returning a reference to an
* instance of Type located at the input data location. It's just a
* fancy cast! */
#define STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
static inline const Type& get_for_data (const char *data) { \
return *(const Type*)data; \
}
#define STATIC_DEFINE_GET_FOR_DATA(Type) \
STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
STATIC_DEFINE_GET_FOR_DATA0( , Type)
/*
*
* The OpenType Font File
@ -293,15 +313,7 @@ struct OpenTypeFontFile {
static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O');
static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
/* Factory: ::get(font_data)
* This is how you get a handle to one of these
*/
static inline const OpenTypeFontFile& get (const char *font_data) {
return (const OpenTypeFontFile&)*font_data;
}
static inline OpenTypeFontFile& get (char *font_data) {
return (OpenTypeFontFile&)*font_data;
}
STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
/* This is how you get a table */
inline const char* get_table (const OpenTypeTable& table) const {
@ -753,6 +765,10 @@ ASSERT_SIZE (Device, 6);
DEFINE_LIST_ACCESSOR0( , Type, name)
struct GSUBGPOSHeader {
static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B');
static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S');
STATIC_DEFINE_GET_FOR_DATA (GSUBGPOSHeader);
DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */

View File

@ -18,7 +18,7 @@ main (int argc, char **argv)
printf ("Opened font file %s: %d bytes long\n", argv[1], len);
const OpenTypeFontFile &ot = OpenTypeFontFile::get (font_data);
const OpenTypeFontFile &ot = OpenTypeFontFile::get_for_data (font_data);
switch (ot.get_tag()) {
case OpenTypeFontFile::TrueTypeTag:
@ -49,7 +49,7 @@ main (int argc, char **argv)
(const char *)table.get_tag(), table.get_offset(), table.get_length());
if (table.get_tag() == "GSUB" || table.get_tag() == "GPOS") {
const GSUBGPOSHeader &g = (const GSUBGPOSHeader&)*ot[table];
const GSUBGPOSHeader &g = GSUBGPOSHeader::get_for_data (ot[table]);
const ScriptList &scripts = *g.get_script_list();
int num_scripts = scripts.get_len ();
@ -92,15 +92,13 @@ main (int argc, char **argv)
lookup.get_type(), lookup.get_flag());
}
} else if (table.get_tag() == "GDEF") {
const GDEFHeader &gdef = (const GDEFHeader&)*ot[table];
const GDEFHeader &gdef = GDEFHeader::get_for_data (ot[table]);
/*
for (int glyph = 0; glyph < 1000; glyph++)
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));
*/
}
}
}