Combine lig_id and lig_comp into one byte, to free up one for Indic

This commit is contained in:
Behdad Esfahbod 2012-05-09 17:53:13 +02:00
parent 92332e5116
commit a9844d41c6
3 changed files with 34 additions and 17 deletions

View File

@ -1105,9 +1105,11 @@ struct MarkLigPosFormat1
* is identical to the ligature ID of the found ligature. If yes, we
* can directly use the component index. If not, we attach the mark
* glyph to the last component of the ligature. */
if (c->buffer->info[j].lig_id() && c->buffer->info[j].lig_id() == c->buffer->info[c->buffer->idx].lig_id() && c->buffer->info[c->buffer->idx].lig_comp())
if (get_lig_id (c->buffer->info[j]) &&
get_lig_id (c->buffer->info[j]) == get_lig_id (c->buffer->info[c->buffer->idx]) &&
get_lig_comp (c->buffer->info[c->buffer->idx]) > 0)
{
comp_index = c->buffer->info[c->buffer->idx].lig_comp() - 1;
comp_index = get_lig_comp (c->buffer->info[c->buffer->idx]) - 1;
if (comp_index >= comp_count)
comp_index = comp_count - 1;
}
@ -1208,8 +1210,9 @@ struct MarkMarkPosFormat1
/* Two marks match only if they belong to the same base, or same component
* of the same ligature. That is, the component numbers must match, and
* if those are non-zero, the ligid number should also match. */
if ((c->buffer->info[j].lig_comp() != c->buffer->info[c->buffer->idx].lig_comp()) ||
(c->buffer->info[j].lig_comp() && c->buffer->info[j].lig_id() != c->buffer->info[c->buffer->idx].lig_id()))
if ((get_lig_comp (c->buffer->info[j]) != get_lig_comp (c->buffer->info[c->buffer->idx])) ||
(get_lig_comp (c->buffer->info[j]) > 0 &&
get_lig_id (c->buffer->info[j]) != get_lig_id (c->buffer->info[c->buffer->idx])))
return false;
unsigned int mark2_index = (this+mark2Coverage) (c->buffer->info[j].codepoint);
@ -1545,8 +1548,7 @@ GPOS::position_finish (hb_buffer_t *buffer)
for (unsigned int i = 0; i < len; i++)
fix_mark_attachment (pos, i, direction);
HB_BUFFER_DEALLOCATE_VAR (buffer, lig_comp);
HB_BUFFER_DEALLOCATE_VAR (buffer, lig_id);
HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props);
HB_BUFFER_DEALLOCATE_VAR (buffer, props_cache);
}

View File

@ -516,8 +516,7 @@ struct Ligature
/* Allocate new ligature id */
unsigned int lig_id = allocate_lig_id (c->buffer);
c->buffer->info[c->buffer->idx].lig_comp() = 0;
c->buffer->info[c->buffer->idx].lig_id() = lig_id;
set_lig_props (c->buffer->info[c->buffer->idx], lig_id, 0);
if (skippy_iter.idx < c->buffer->idx + count) /* No input glyphs skipped */
{
@ -538,8 +537,7 @@ struct Ligature
{
while (c->should_mark_skip_current_glyph ())
{
c->buffer->info[c->buffer->idx].lig_comp() = i;
c->buffer->info[c->buffer->idx].lig_id() = lig_id;
set_lig_props (c->buffer->info[c->buffer->idx], lig_id, i);
c->replace_glyph (c->buffer->info[c->buffer->idx].codepoint);
}
@ -1193,12 +1191,11 @@ void
GSUB::substitute_start (hb_buffer_t *buffer)
{
HB_BUFFER_ALLOCATE_VAR (buffer, props_cache);
HB_BUFFER_ALLOCATE_VAR (buffer, lig_id);
HB_BUFFER_ALLOCATE_VAR (buffer, lig_comp);
HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
unsigned int count = buffer->len;
for (unsigned int i = 0; i < count; i++)
buffer->info[i].props_cache() = buffer->info[i].lig_id() = buffer->info[i].lig_comp() = 0;
buffer->info[i].props_cache() = buffer->info[i].lig_props() = 0;
}
void

View File

@ -35,12 +35,30 @@
/* buffer var allocations */
#define lig_id() var2.u8[2] /* unique ligature id */
#define lig_comp() var2.u8[3] /* component number in the ligature (0 = base) */
#define lig_props() var2.u8[3]
/* unique ligature id */
/* component number in the ligature (0 = base) */
static inline void
set_lig_props (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_comp)
{
info.lig_props() = (lig_id << 4) | (lig_comp & 0x0F);
}
static inline unsigned int
get_lig_id (hb_glyph_info_t &info)
{
return info.lig_props() >> 4;
}
static inline unsigned int
get_lig_comp (hb_glyph_info_t &info)
{
return info.lig_props() & 0x0F;
}
static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
uint8_t lig_id = buffer->next_serial ();
if (unlikely (!lig_id)) lig_id = buffer->next_serial (); /* in case of overflow */
uint8_t lig_id = buffer->next_serial () & 0x0F;
if (unlikely (!lig_id))
lig_id = allocate_lig_id (buffer); /* in case of overflow */
return lig_id;
}