Finish and test GDEF

This commit is contained in:
Behdad Esfahbod 2008-01-23 01:38:10 -05:00
parent 303fe62824
commit b9d7688fb3
4 changed files with 77 additions and 32 deletions

View File

@ -3,27 +3,6 @@
#include "harfbuzz-open-private.h" #include "harfbuzz-open-private.h"
struct GDEFHeader {
/* TODO */
private:
Fixed version; /* Version of the GDEF table--initially
* 0x00010000 */
Offset glyphClassDef; /* Offset to class definition table
* for glyph type--from beginning of
* GDEF header (may be NULL) */
Offset attachList; /* Offset to list of glyphs with
* attachment points--from beginning
* of GDEF header (may be NULL) */
Offset ligCaretList; /* Offset to list of positioning points
* for ligature carets--from beginning
* of GDEF header (may be NULL) */
Offset markAttachClassDef; /* Offset to class definition table for
* mark attachment type--from beginning
* of GDEF header (may be NULL) */
};
ASSERT_SIZE (GDEFHeader, 12);
struct GlyphClassDef : ClassDef { struct GlyphClassDef : ClassDef {
static const uint16_t BaseGlyph = 0x0001u; static const uint16_t BaseGlyph = 0x0001u;
static const uint16_t LigatureGlyph = 0x0002u; static const uint16_t LigatureGlyph = 0x0002u;
@ -180,4 +159,55 @@ struct CaretValue {
} u; } u;
}; };
#define DEFINE_ACCESSOR0(const, Type, name, Name) \
inline const Type* name (void) const { \
if (!Name) return NULL; \
return (const Type *)((const char*)this + Name); \
}
#define DEFINE_ACCESSOR(Type, name, Name) \
DEFINE_ACCESSOR0(const, Type, name, Name) \
DEFINE_ACCESSOR0( , Type, name, Name)
struct GDEFHeader {
DEFINE_ACCESSOR (ClassDef, get_glyph_class_def, glyphClassDef);
DEFINE_ACCESSOR (AttachList, get_attach_list, attachList);
DEFINE_ACCESSOR (LigCaretList, get_lig_caret_list, ligCaretList);
DEFINE_ACCESSOR (ClassDef, get_mark_attach_class_def, markAttachClassDef);
/* Returns 0 if not found. */
inline int get_glyph_class (uint16_t glyph_id) const {
const ClassDef *class_def = get_glyph_class_def ();
if (!class_def) return 0;
return class_def->get_class (glyph_id);
}
/* Returns 0 if not found. */
inline int get_mark_attachment_type (uint16_t glyph_id) const {
const ClassDef *class_def = get_mark_attach_class_def ();
if (!class_def) return 0;
return class_def->get_class (glyph_id);
}
/* TODO get_attach and get_lig_caret */
private:
Fixed version; /* Version of the GDEF table--initially
* 0x00010000 */
Offset glyphClassDef; /* Offset to class definition table
* for glyph type--from beginning of
* GDEF header (may be NULL) */
Offset attachList; /* Offset to list of glyphs with
* attachment points--from beginning
* of GDEF header (may be NULL) */
Offset ligCaretList; /* Offset to list of positioning points
* for ligature carets--from beginning
* of GDEF header (may be NULL) */
Offset markAttachClassDef; /* Offset to class definition table for
* mark attachment type--from beginning
* of GDEF header (may be NULL) */
};
ASSERT_SIZE (GDEFHeader, 12);
#endif /* HARFBUZZ_GDEF_PRIVATE_H */ #endif /* HARFBUZZ_GDEF_PRIVATE_H */

View File

@ -175,6 +175,7 @@ struct Tag {
inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; } inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; }
inline bool operator== (Tag o) const { return v[0]==o.v[0]&&v[1]==o.v[1]&&v[2]==o.v[2]&&v[3]==o.v[3]; } inline bool operator== (Tag o) const { return v[0]==o.v[0]&&v[1]==o.v[1]&&v[2]==o.v[2]&&v[3]==o.v[3]; }
inline bool operator== (const char *c) const { return v[0]==c[0]&&v[1]==c[1]&&v[2]==c[2]&&v[3]==c[3]; } inline bool operator== (const char *c) const { return v[0]==c[0]&&v[1]==c[1]&&v[2]==c[2]&&v[3]==c[3]; }
inline bool operator== (uint32_t i) const { return i == (uint32_t) *this; }
inline operator uint32_t(void) const { return (v[0]<<24)+(v[1]<<16) +(v[2]<<8)+v[3]; } inline operator uint32_t(void) const { return (v[0]<<24)+(v[1]<<16) +(v[2]<<8)+v[3]; }
/* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */
inline operator const char* (void) const { return (const char *)this; } inline operator const char* (void) const { return (const char *)this; }
@ -399,6 +400,8 @@ struct Script {
return (LangSys *)((char*)this + defaultLangSys); return (LangSys *)((char*)this + defaultLangSys);
} }
/* TODO implement find_language_system based on find_tag */
private: private:
Offset defaultLangSys; /* Offset to DefaultLangSys table--from Offset defaultLangSys; /* Offset to DefaultLangSys table--from
* beginning of Script table--may be NULL */ * beginning of Script table--may be NULL */
@ -420,6 +423,8 @@ struct LangSys {
return reqFeatureIndex;; return reqFeatureIndex;;
} }
/* TODO implement find_feature */
private: private:
Offset lookupOrder; /* = NULL (reserved for an offset to a Offset lookupOrder; /* = NULL (reserved for an offset to a
* reordering table) */ * reordering table) */
@ -674,8 +679,8 @@ struct ClassDef {
/* Returns 0 if not found. */ /* Returns 0 if not found. */
inline int get_class (uint16_t glyph_id) const { inline int get_class (uint16_t glyph_id) const {
switch (u.classFormat) { switch (u.classFormat) {
case 1: u.format1.get_class(glyph_id); case 1: return u.format1.get_class(glyph_id);
case 2: u.format2.get_class(glyph_id); case 2: return u.format2.get_class(glyph_id);
default:return 0; default:return 0;
} }
} }
@ -740,7 +745,7 @@ ASSERT_SIZE (Device, 6);
assert (name##List); \ assert (name##List); \
return (const Type##List *)((const char*)this + name##List); \ return (const Type##List *)((const char*)this + name##List); \
} \ } \
inline const Type& name (unsigned int i) const { \ inline const Type& get_##name (unsigned int i) const { \
return (*get_##name##_list())[i]; \ return (*get_##name##_list())[i]; \
} }
#define DEFINE_LIST_ACCESSOR(Type, name) \ #define DEFINE_LIST_ACCESSOR(Type, name) \
@ -749,15 +754,11 @@ ASSERT_SIZE (Device, 6);
struct GSUBGPOSHeader { struct GSUBGPOSHeader {
/* DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
inline unsigned int get_size (void) const { DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */
return offsetof (GSUBGPOSHeader, padding); DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list, get_lookup(i) */
}
*/
DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list and script(i) */ /* TODO implement find_script */
DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list and feature(i) */
DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list and lookup(i) */
private: private:
Fixed_Version version; /* Version of the GSUB/GPOS table--initially set Fixed_Version version; /* Version of the GSUB/GPOS table--initially set

View File

@ -7,6 +7,10 @@ HARFBUZZ_BEGIN_DECLS();
typedef uint32_t hb_tag_t; typedef uint32_t hb_tag_t;
#define HB_TAG(a,b,c,d) ((hb_tag_t)(((uint8_t)a<<24)|((uint8_t)b<<16)|((uint8_t)c<<8)|(uint8_t)d)) #define HB_TAG(a,b,c,d) ((hb_tag_t)(((uint8_t)a<<24)|((uint8_t)b<<16)|((uint8_t)c<<8)|(uint8_t)d))
#define HB_TAG_STR(s) (HB_TAG(((const char *) s)[0], \
((const char *) s)[1], \
((const char *) s)[2], \
((const char *) s)[3]))
HARFBUZZ_END_DECLS(); HARFBUZZ_END_DECLS();

View File

@ -91,6 +91,16 @@ main (int argc, char **argv)
printf (" Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups, printf (" Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups,
lookup.get_type(), lookup.get_flag()); lookup.get_type(), lookup.get_flag());
} }
} else if (table.get_tag() == "GDEF") {
const GDEFHeader &gdef = (const GDEFHeader&)*ot[table];
/*
for (int glyph = 0; glyph < 1000; 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));
*/
} }
} }
} }