提交 650ac00d 编写于 作者: B Behdad Esfahbod

Minor refactoring

上级 f94b0aa6
...@@ -1417,24 +1417,22 @@ struct PosLookup : Lookup ...@@ -1417,24 +1417,22 @@ struct PosLookup : Lookup
return false; return false;
} }
inline bool apply_string (hb_font_t *font, inline bool apply_string (hb_apply_context_t *c) const
hb_buffer_t *buffer,
hb_mask_t mask) const
{ {
bool ret = false; bool ret = false;
if (unlikely (!buffer->len)) if (unlikely (!c->buffer->len))
return false; return false;
hb_apply_context_t c (font, font->face, buffer, mask, *this); c->set_lookup (*this);
buffer->idx = 0; c->buffer->idx = 0;
while (buffer->idx < buffer->len) while (c->buffer->idx < c->buffer->len)
{ {
if ((buffer->info[buffer->idx].mask & mask) && apply_once (&c)) if ((c->buffer->info[c->buffer->idx].mask & c->lookup_mask) && apply_once (c))
ret = true; ret = true;
else else
buffer->idx++; c->buffer->idx++;
} }
return ret; return ret;
...@@ -1461,11 +1459,8 @@ struct GPOS : GSUBGPOS ...@@ -1461,11 +1459,8 @@ struct GPOS : GSUBGPOS
inline const PosLookup& get_lookup (unsigned int i) const inline const PosLookup& get_lookup (unsigned int i) const
{ return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); } { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
inline bool position_lookup (hb_font_t *font, inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_index) const
hb_buffer_t *buffer, { return get_lookup (lookup_index).apply_string (c); }
unsigned int lookup_index,
hb_mask_t mask) const
{ return get_lookup (lookup_index).apply_string (font, buffer, mask); }
static inline void position_start (hb_buffer_t *buffer); static inline void position_start (hb_buffer_t *buffer);
static inline void position_finish (hb_buffer_t *buffer); static inline void position_finish (hb_buffer_t *buffer);
...@@ -1584,7 +1579,9 @@ static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_i ...@@ -1584,7 +1579,9 @@ static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_i
if (unlikely (c->context_length < 1)) if (unlikely (c->context_length < 1))
return false; return false;
hb_apply_context_t new_c (*c, l); hb_apply_context_t new_c (*c);
new_c.nesting_level_left--;
new_c.set_lookup (l);
return l.apply_once (&new_c); return l.apply_once (&new_c);
} }
......
...@@ -1069,46 +1069,44 @@ struct SubstLookup : Lookup ...@@ -1069,46 +1069,44 @@ struct SubstLookup : Lookup
return false; return false;
} }
inline bool apply_string (hb_face_t *face, inline bool apply_string (hb_apply_context_t *c) const
hb_buffer_t *buffer,
hb_mask_t mask) const
{ {
bool ret = false; bool ret = false;
if (unlikely (!buffer->len)) if (unlikely (!c->buffer->len))
return false; return false;
hb_apply_context_t c (NULL, face, buffer, mask, *this); c->set_lookup (*this);
if (likely (!is_reverse ())) if (likely (!is_reverse ()))
{ {
/* in/out forward substitution */ /* in/out forward substitution */
buffer->clear_output (); c->buffer->clear_output ();
buffer->idx = 0; c->buffer->idx = 0;
while (buffer->idx < buffer->len) while (c->buffer->idx < c->buffer->len)
{ {
if ((buffer->info[buffer->idx].mask & mask) && apply_once (&c)) if ((c->buffer->info[c->buffer->idx].mask & c->lookup_mask) && apply_once (c))
ret = true; ret = true;
else else
buffer->next_glyph (); c->buffer->next_glyph ();
} }
if (ret) if (ret)
buffer->swap_buffers (); c->buffer->swap_buffers ();
} }
else else
{ {
/* in-place backward substitution */ /* in-place backward substitution */
buffer->idx = buffer->len - 1; c->buffer->idx = c->buffer->len - 1;
do do
{ {
if ((buffer->info[buffer->idx].mask & mask) && apply_once (&c)) if ((c->buffer->info[c->buffer->idx].mask & c->lookup_mask) && apply_once (c))
ret = true; ret = true;
else else
buffer->idx--; c->buffer->idx--;
} }
while ((int) buffer->idx >= 0); while ((int) c->buffer->idx >= 0);
} }
return ret; return ret;
...@@ -1135,11 +1133,8 @@ struct GSUB : GSUBGPOS ...@@ -1135,11 +1133,8 @@ struct GSUB : GSUBGPOS
inline const SubstLookup& get_lookup (unsigned int i) const inline const SubstLookup& get_lookup (unsigned int i) const
{ return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); } { return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); }
inline bool substitute_lookup (hb_face_t *face, inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index) const
hb_buffer_t *buffer, { return get_lookup (lookup_index).apply_string (c); }
unsigned int lookup_index,
hb_mask_t mask) const
{ return get_lookup (lookup_index).apply_string (face, buffer, mask); }
static inline void substitute_start (hb_buffer_t *buffer); static inline void substitute_start (hb_buffer_t *buffer);
static inline void substitute_finish (hb_buffer_t *buffer); static inline void substitute_finish (hb_buffer_t *buffer);
...@@ -1238,7 +1233,9 @@ static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup ...@@ -1238,7 +1233,9 @@ static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup
if (unlikely (c->context_length < 1)) if (unlikely (c->context_length < 1))
return false; return false;
hb_apply_context_t new_c (*c, l); hb_apply_context_t new_c (*c);
new_c.nesting_level_left--;
new_c.set_lookup (l);
return l.apply_once (&new_c); return l.apply_once (&new_c);
} }
......
...@@ -103,7 +103,6 @@ struct hb_apply_context_t ...@@ -103,7 +103,6 @@ struct hb_apply_context_t
hb_face_t *face_, hb_face_t *face_,
hb_buffer_t *buffer_, hb_buffer_t *buffer_,
hb_mask_t lookup_mask_, hb_mask_t lookup_mask_,
const Lookup &l,
unsigned int context_length_ = NO_CONTEXT, unsigned int context_length_ = NO_CONTEXT,
unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) :
font (font_), face (face_), buffer (buffer_), font (font_), face (face_), buffer (buffer_),
...@@ -111,12 +110,9 @@ struct hb_apply_context_t ...@@ -111,12 +110,9 @@ struct hb_apply_context_t
lookup_mask (lookup_mask_), lookup_mask (lookup_mask_),
context_length (context_length_), context_length (context_length_),
nesting_level_left (nesting_level_left_), nesting_level_left (nesting_level_left_),
lookup_props (l.get_props ()), lookup_props (0), property (0), debug_depth (0) {}
property (0), debug_depth (0) {}
hb_apply_context_t (const hb_apply_context_t &c, const Lookup &l) { void set_lookup (const Lookup &l) {
*this = c;
nesting_level_left--;
lookup_props = l.get_props (); lookup_props = l.get_props ();
} }
......
...@@ -460,7 +460,8 @@ hb_ot_layout_substitute_lookup (hb_face_t *face, ...@@ -460,7 +460,8 @@ hb_ot_layout_substitute_lookup (hb_face_t *face,
unsigned int lookup_index, unsigned int lookup_index,
hb_mask_t mask) hb_mask_t mask)
{ {
return _get_gsub (face).substitute_lookup (face, buffer, lookup_index, mask); hb_apply_context_t c (NULL, face, buffer, mask);
return _get_gsub (face).substitute_lookup (&c, lookup_index);
} }
void void
...@@ -500,7 +501,8 @@ hb_ot_layout_position_lookup (hb_font_t *font, ...@@ -500,7 +501,8 @@ hb_ot_layout_position_lookup (hb_font_t *font,
unsigned int lookup_index, unsigned int lookup_index,
hb_mask_t mask) hb_mask_t mask)
{ {
return _get_gpos (font->face).position_lookup (font, buffer, lookup_index, mask); hb_apply_context_t c (font, font->face, buffer, mask);
return _get_gpos (font->face).position_lookup (&c, lookup_index);
} }
void void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册