提交 d468f9af 编写于 作者: B Behdad Esfahbod

[HB] Share Extension lookup code between GSUB and GPOS

上级 498f1909
...@@ -318,7 +318,6 @@ struct SinglePos ...@@ -318,7 +318,6 @@ struct SinglePos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -507,7 +506,6 @@ struct PairPos ...@@ -507,7 +506,6 @@ struct PairPos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -734,7 +732,6 @@ struct CursivePos ...@@ -734,7 +732,6 @@ struct CursivePos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -853,7 +850,6 @@ struct MarkBasePos ...@@ -853,7 +850,6 @@ struct MarkBasePos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -943,7 +939,6 @@ struct MarkLigPos ...@@ -943,7 +939,6 @@ struct MarkLigPos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -1061,7 +1056,6 @@ struct MarkMarkPos ...@@ -1061,7 +1056,6 @@ struct MarkMarkPos
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -1083,6 +1077,9 @@ static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index); ...@@ -1083,6 +1077,9 @@ static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index);
struct ContextPos : Context struct ContextPos : Context
{ {
friend struct PosLookupSubTable;
private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
return Context::apply (APPLY_ARG, position_lookup); return Context::apply (APPLY_ARG, position_lookup);
...@@ -1092,6 +1089,9 @@ ASSERT_SIZE (ContextPos, 2); ...@@ -1092,6 +1089,9 @@ ASSERT_SIZE (ContextPos, 2);
struct ChainContextPos : ChainContext struct ChainContextPos : ChainContext
{ {
friend struct PosLookupSubTable;
private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
return ChainContext::apply (APPLY_ARG, position_lookup); return ChainContext::apply (APPLY_ARG, position_lookup);
...@@ -1100,59 +1100,17 @@ struct ChainContextPos : ChainContext ...@@ -1100,59 +1100,17 @@ struct ChainContextPos : ChainContext
ASSERT_SIZE (ChainContextPos, 2); ASSERT_SIZE (ChainContextPos, 2);
struct ExtensionPosFormat1 struct ExtensionPos : Extension
{
friend struct ExtensionPos;
private:
inline unsigned int get_type (void) const { return extensionLookupType; }
inline unsigned int get_offset (void) const { return (extensionOffset[0] << 16) + extensionOffset[1]; }
inline bool apply (APPLY_ARG_DEF) const;
private:
USHORT format; /* Format identifier. Set to 1. */
USHORT extensionLookupType; /* Lookup type of subtable referenced
* by ExtensionOffset (i.e. the
* extension subtable). */
USHORT extensionOffset[2]; /* Offset to the extension subtable,
* of lookup type subtable.
* Defined as two shorts to avoid
* alignment requirements. */
};
ASSERT_SIZE (ExtensionPosFormat1, 8);
struct ExtensionPos
{ {
friend struct PosLookup;
friend struct PosLookupSubTable; friend struct PosLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const;
inline unsigned int get_type (void) const
{
switch (u.format) {
case 1: return u.format1->get_type ();
default:return 0;
}
}
inline bool apply (APPLY_ARG_DEF) const
{
switch (u.format) {
case 1: return u.format1->apply (APPLY_ARG);
default:return false;
}
}
private:
union {
USHORT format; /* Format identifier */
ExtensionPosFormat1 format1[];
} u;
}; };
ASSERT_SIZE (ExtensionPos, 2); ASSERT_SIZE (ExtensionPos, 2);
/* /*
* PosLookup * PosLookup
*/ */
...@@ -1329,14 +1287,14 @@ ASSERT_SIZE (GPOS, 10); ...@@ -1329,14 +1287,14 @@ ASSERT_SIZE (GPOS, 10);
/* Out-of-class implementation for methods recursing */ /* Out-of-class implementation for methods recursing */
inline bool ExtensionPosFormat1::apply (APPLY_ARG_DEF) const inline bool ExtensionPos::apply (APPLY_ARG_DEF) const
{ {
unsigned int lookup_type = get_type (); unsigned int lookup_type = get_type ();
if (HB_UNLIKELY (lookup_type == PosLookupSubTable::Extension)) if (HB_UNLIKELY (lookup_type == PosLookupSubTable::Extension))
return false; return false;
return ((PosLookupSubTable&)*(((char *) this) + get_offset ())).apply (APPLY_ARG, lookup_type); return ((PosLookupSubTable&) get_subtable ()).apply (APPLY_ARG, lookup_type);
} }
static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index) static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index)
......
...@@ -45,7 +45,6 @@ struct SingleSubstFormat1 ...@@ -45,7 +45,6 @@ struct SingleSubstFormat1
friend struct SingleSubst; friend struct SingleSubst;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
hb_codepoint_t glyph_id = IN_CURGLYPH (); hb_codepoint_t glyph_id = IN_CURGLYPH ();
...@@ -80,7 +79,6 @@ struct SingleSubstFormat2 ...@@ -80,7 +79,6 @@ struct SingleSubstFormat2
friend struct SingleSubst; friend struct SingleSubst;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
hb_codepoint_t glyph_id = IN_CURGLYPH (); hb_codepoint_t glyph_id = IN_CURGLYPH ();
...@@ -119,7 +117,6 @@ struct SingleSubst ...@@ -119,7 +117,6 @@ struct SingleSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -144,14 +141,6 @@ struct Sequence ...@@ -144,14 +141,6 @@ struct Sequence
friend struct MultipleSubstFormat1; friend struct MultipleSubstFormat1;
private: private:
inline void set_glyph_class (hb_ot_layout_t *layout, unsigned int property) const
{
unsigned int count = substitute.len;
for (unsigned int n = 0; n < count; n++)
_hb_ot_layout_set_glyph_property (layout, substitute[n], property);
}
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
if (HB_UNLIKELY (!substitute.len)) if (HB_UNLIKELY (!substitute.len))
...@@ -164,11 +153,12 @@ struct Sequence ...@@ -164,11 +153,12 @@ struct Sequence
if ( _hb_ot_layout_has_new_glyph_classes (layout) ) if ( _hb_ot_layout_has_new_glyph_classes (layout) )
{ {
/* this is a guess only ... */ /* this is a guess only ... */
if ( property == HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE ) if ( property == HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE )
property = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH; property = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
set_glyph_class (layout, property); unsigned int count = substitute.len;
for (unsigned int n = 0; n < count; n++)
_hb_ot_layout_set_glyph_property (layout, substitute[n], property);
} }
return true; return true;
...@@ -185,7 +175,6 @@ struct MultipleSubstFormat1 ...@@ -185,7 +175,6 @@ struct MultipleSubstFormat1
friend struct MultipleSubst; friend struct MultipleSubst;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
...@@ -212,7 +201,6 @@ struct MultipleSubst ...@@ -212,7 +201,6 @@ struct MultipleSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -239,7 +227,6 @@ struct AlternateSubstFormat1 ...@@ -239,7 +227,6 @@ struct AlternateSubstFormat1
friend struct AlternateSubst; friend struct AlternateSubst;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
hb_codepoint_t glyph_id = IN_CURGLYPH (); hb_codepoint_t glyph_id = IN_CURGLYPH ();
...@@ -294,7 +281,6 @@ struct AlternateSubst ...@@ -294,7 +281,6 @@ struct AlternateSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -397,7 +383,6 @@ struct LigatureSet ...@@ -397,7 +383,6 @@ struct LigatureSet
friend struct LigatureSubstFormat1; friend struct LigatureSubstFormat1;
private: private:
inline bool apply (APPLY_ARG_DEF, bool is_mark) const inline bool apply (APPLY_ARG_DEF, bool is_mark) const
{ {
unsigned int num_ligs = ligature.len; unsigned int num_ligs = ligature.len;
...@@ -423,7 +408,6 @@ struct LigatureSubstFormat1 ...@@ -423,7 +408,6 @@ struct LigatureSubstFormat1
friend struct LigatureSubst; friend struct LigatureSubst;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
hb_codepoint_t glyph_id = IN_CURGLYPH (); hb_codepoint_t glyph_id = IN_CURGLYPH ();
...@@ -455,7 +439,6 @@ struct LigatureSubst ...@@ -455,7 +439,6 @@ struct LigatureSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -478,6 +461,9 @@ static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index); ...@@ -478,6 +461,9 @@ static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index);
struct ContextSubst : Context struct ContextSubst : Context
{ {
friend struct SubstLookupSubTable;
private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
return Context::apply (APPLY_ARG, substitute_lookup); return Context::apply (APPLY_ARG, substitute_lookup);
...@@ -487,6 +473,9 @@ ASSERT_SIZE (ContextSubst, 2); ...@@ -487,6 +473,9 @@ ASSERT_SIZE (ContextSubst, 2);
struct ChainContextSubst : ChainContext struct ChainContextSubst : ChainContext
{ {
friend struct SubstLookupSubTable;
private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
return ChainContext::apply (APPLY_ARG, substitute_lookup); return ChainContext::apply (APPLY_ARG, substitute_lookup);
...@@ -495,55 +484,12 @@ struct ChainContextSubst : ChainContext ...@@ -495,55 +484,12 @@ struct ChainContextSubst : ChainContext
ASSERT_SIZE (ChainContextSubst, 2); ASSERT_SIZE (ChainContextSubst, 2);
struct ExtensionSubstFormat1 struct ExtensionSubst : Extension
{
friend struct ExtensionSubst;
private:
inline unsigned int get_type (void) const { return extensionLookupType; }
inline unsigned int get_offset (void) const { return (extensionOffset[0] << 16) + extensionOffset[1]; }
inline bool apply (APPLY_ARG_DEF) const;
private:
USHORT format; /* Format identifier. Set to 1. */
USHORT extensionLookupType; /* Lookup type of subtable referenced
* by ExtensionOffset (i.e. the
* extension subtable). */
USHORT extensionOffset[2]; /* Offset to the extension subtable,
* of lookup type subtable.
* Defined as two shorts to avoid
* alignment requirements. */
};
ASSERT_SIZE (ExtensionSubstFormat1, 8);
struct ExtensionSubst
{ {
friend struct SubstLookup;
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const;
inline unsigned int get_type (void) const
{
switch (u.format) {
case 1: return u.format1->get_type ();
default:return 0;
}
}
inline bool apply (APPLY_ARG_DEF) const
{
switch (u.format) {
case 1: return u.format1->apply (APPLY_ARG);
default:return false;
}
}
private:
union {
USHORT format; /* Format identifier */
ExtensionSubstFormat1 format1[];
} u;
}; };
ASSERT_SIZE (ExtensionSubst, 2); ASSERT_SIZE (ExtensionSubst, 2);
...@@ -607,7 +553,6 @@ struct ReverseChainSingleSubst ...@@ -607,7 +553,6 @@ struct ReverseChainSingleSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
switch (u.format) { switch (u.format) {
...@@ -815,14 +760,14 @@ ASSERT_SIZE (GSUB, 10); ...@@ -815,14 +760,14 @@ ASSERT_SIZE (GSUB, 10);
/* Out-of-class implementation for methods recursing */ /* Out-of-class implementation for methods recursing */
inline bool ExtensionSubstFormat1::apply (APPLY_ARG_DEF) const inline bool ExtensionSubst::apply (APPLY_ARG_DEF) const
{ {
unsigned int lookup_type = get_type (); unsigned int lookup_type = get_type ();
if (HB_UNLIKELY (lookup_type == SubstLookupSubTable::Extension)) if (HB_UNLIKELY (lookup_type == SubstLookupSubTable::Extension))
return false; return false;
return ((SubstLookupSubTable&)*(((char *) this) + get_offset ())).apply (APPLY_ARG, lookup_type); return ((SubstLookupSubTable&) get_subtable ()).apply (APPLY_ARG, lookup_type);
} }
static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index) static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index)
......
...@@ -686,6 +686,58 @@ struct ChainContext ...@@ -686,6 +686,58 @@ struct ChainContext
ASSERT_SIZE (ChainContext, 2); ASSERT_SIZE (ChainContext, 2);
struct ExtensionFormat1
{
friend struct Extension;
private:
inline unsigned int get_type (void) const { return extensionLookupType; }
inline unsigned int get_offset (void) const { return (extensionOffset[0] << 16) + extensionOffset[1]; }
inline const LookupSubTable& get_subtable (void) const
{
unsigned int offset = get_offset ();
if (HB_UNLIKELY (!offset)) return Null(LookupSubTable);
return (LookupSubTable&) *(((char *) this) + offset);
}
private:
USHORT format; /* Format identifier. Set to 1. */
USHORT extensionLookupType; /* Lookup type of subtable referenced
* by ExtensionOffset (i.e. the
* extension subtable). */
USHORT extensionOffset[2]; /* Offset to the extension subtable,
* of lookup type subtable.
* Defined as two shorts to avoid
* alignment requirements. */
};
ASSERT_SIZE (ExtensionFormat1, 8);
struct Extension
{
inline unsigned int get_type (void) const
{
switch (u.format) {
case 1: return u.format1->get_type ();
default:return 0;
}
}
inline const LookupSubTable& get_subtable (void) const
{
switch (u.format) {
case 1: return u.format1->get_subtable ();
default:return Null(LookupSubTable);
}
}
private:
union {
USHORT format; /* Format identifier */
ExtensionFormat1 format1[];
} u;
};
ASSERT_SIZE (Extension, 2);
/* /*
* GSUB/GPOS Common * GSUB/GPOS Common
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册