Formalize buffer var allocations
This commit is contained in:
parent
a9ad3d3460
commit
b65c06025d
|
@ -84,26 +84,10 @@ struct _hb_buffer_t {
|
|||
{ return have_output? out_len : idx; }
|
||||
inline unsigned int next_serial (void) { return serial++; }
|
||||
|
||||
|
||||
HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner);
|
||||
HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner);
|
||||
HB_INTERNAL void deallocate_var_all (void);
|
||||
|
||||
inline void allocate_var_8 (unsigned int var_num, unsigned int i, const char *owner)
|
||||
{ assert (var_num < 2 && i < 4); allocate_var (var_num * 4 + i, 1, owner); }
|
||||
inline void allocate_var_16 (unsigned int var_num, unsigned int i, const char *owner)
|
||||
{ assert (var_num < 2 && i < 2); allocate_var (var_num * 4 + i * 2, 2, owner); }
|
||||
inline void allocate_var_32 (unsigned int var_num, const char *owner)
|
||||
{ assert (var_num < 2); allocate_var (var_num * 4, 4, owner); }
|
||||
|
||||
inline void deallocate_var_8 (unsigned int var_num, unsigned int i, const char *owner)
|
||||
{ assert (var_num < 2 && i < 4); deallocate_var (var_num * 4 + i, 1, owner); }
|
||||
inline void deallocate_var_16 (unsigned int var_num, unsigned int i, const char *owner)
|
||||
{ assert (var_num < 2 && i < 2); deallocate_var (var_num * 4 + i * 2, 2, owner); }
|
||||
inline void deallocate_var_32 (unsigned int var_num, const char *owner)
|
||||
{ assert (var_num < 2); deallocate_var (var_num * 4, 4, owner); }
|
||||
|
||||
|
||||
HB_INTERNAL void add (hb_codepoint_t codepoint,
|
||||
hb_mask_t mask,
|
||||
unsigned int cluster);
|
||||
|
@ -154,6 +138,15 @@ struct _hb_buffer_t {
|
|||
};
|
||||
|
||||
|
||||
#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
|
||||
b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
|
||||
sizeof (b->info[0].var), owner)
|
||||
#define HB_BUFFER_ALLOCATE_VAR(b, var) \
|
||||
HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
|
||||
#define HB_BUFFER_DEALLOCATE_VAR(b, var) \
|
||||
HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
|
||||
|
||||
|
||||
HB_END_DECLS
|
||||
|
||||
#endif /* HB_BUFFER_PRIVATE_HH */
|
||||
|
|
|
@ -398,7 +398,7 @@ dump_var_allocation (const hb_buffer_t *buffer)
|
|||
{
|
||||
char buf[80];
|
||||
for (unsigned int i = 0; i < 8; i++)
|
||||
buf[i] = '0' + buffer->allocated_var_bytes[i];
|
||||
buf[i] = '0' + buffer->allocated_var_bytes[7 - i];
|
||||
buf[8] = '\0';
|
||||
DEBUG_MSG (BUFFER, buffer,
|
||||
"Current var allocation: %s",
|
||||
|
@ -407,7 +407,7 @@ dump_var_allocation (const hb_buffer_t *buffer)
|
|||
|
||||
void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner)
|
||||
{
|
||||
assert (byte_i < 8 && byte_i + count < 8);
|
||||
assert (byte_i < 8 && byte_i + count <= 8);
|
||||
|
||||
if (DEBUG (BUFFER))
|
||||
dump_var_allocation (this);
|
||||
|
@ -424,18 +424,19 @@ void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const c
|
|||
|
||||
void hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner)
|
||||
{
|
||||
if (DEBUG (BUFFER))
|
||||
dump_var_allocation (this);
|
||||
|
||||
DEBUG_MSG (BUFFER, this,
|
||||
"Deallocating var bytes %d..%d for %s",
|
||||
byte_i, byte_i + count - 1, owner);
|
||||
|
||||
assert (byte_i < 8 && byte_i + count < 8);
|
||||
assert (byte_i < 8 && byte_i + count <= 8);
|
||||
for (unsigned int i = byte_i; i < byte_i + count; i++) {
|
||||
assert (allocated_var_bytes[i] && allocated_var_owner[i] == owner);
|
||||
assert (allocated_var_bytes[i]);
|
||||
assert (0 == strcmp (allocated_var_owner[i], owner));
|
||||
allocated_var_bytes[i]--;
|
||||
}
|
||||
|
||||
if (DEBUG (BUFFER))
|
||||
dump_var_allocation (this);
|
||||
}
|
||||
|
||||
void hb_buffer_t::deallocate_var_all (void)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
HB_BEGIN_DECLS
|
||||
|
||||
|
||||
/* buffer var allocations */
|
||||
/* buffer **position** var allocations */
|
||||
#define attach_lookback() var.u16[0] /* number of glyphs to go back to attach this glyph to its base */
|
||||
#define cursive_chain() var.i16[1] /* character to which this connects, may be positive or negative */
|
||||
|
||||
|
@ -1569,6 +1569,10 @@ void
|
|||
GPOS::position_start (hb_buffer_t *buffer)
|
||||
{
|
||||
buffer->clear_positions ();
|
||||
|
||||
unsigned int count = buffer->len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
buffer->pos[i].attach_lookback() = buffer->pos[i].cursive_chain() = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1580,15 +1584,15 @@ GPOS::position_finish (hb_buffer_t *buffer)
|
|||
|
||||
/* Handle cursive connections */
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
{
|
||||
fix_cursive_minor_offset (pos, i, direction);
|
||||
}
|
||||
|
||||
/* Handle attachments */
|
||||
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, props_cache);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -887,8 +887,11 @@ struct GSUB : GSUBGPOS
|
|||
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);
|
||||
|
||||
unsigned int count = buffer->len;
|
||||
/* XXX */
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
buffer->info[i].var1.u32 = buffer->info[i].var2.u32 = 0;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ HB_BEGIN_DECLS
|
|||
|
||||
|
||||
/* buffer var allocations */
|
||||
#define arabic_shaping_action() var2.u32 /* arabic shaping action */
|
||||
#define arabic_shaping_action() complex_var_temporary_u16() /* arabic shaping action */
|
||||
|
||||
|
||||
/*
|
||||
|
@ -195,6 +195,8 @@ _hb_ot_shape_complex_setup_masks_arabic (hb_ot_map_t *map, hb_buffer_t *buffer)
|
|||
unsigned int count = buffer->len;
|
||||
unsigned int prev = 0, state = 0;
|
||||
|
||||
HB_BUFFER_ALLOCATE_VAR (buffer, arabic_shaping_action);
|
||||
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
unsigned int this_type = get_joining_type (buffer->info[i].codepoint, (hb_unicode_general_category_t) buffer->info[i].general_category());
|
||||
|
@ -222,6 +224,8 @@ _hb_ot_shape_complex_setup_masks_arabic (hb_ot_map_t *map, hb_buffer_t *buffer)
|
|||
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
buffer->info[i].mask |= mask_array[buffer->info[i].arabic_shaping_action()];
|
||||
|
||||
HB_BUFFER_DEALLOCATE_VAR (buffer, arabic_shaping_action);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ HB_BEGIN_DECLS
|
|||
|
||||
|
||||
/* buffer var allocations */
|
||||
#define indic_category() var2.u8[0] /* indic_category_t */
|
||||
#define indic_position() var2.u8[1] /* indic_matra_category_t */
|
||||
#define indic_category() complex_var_persistent_u8_0() /* indic_category_t */
|
||||
#define indic_position() complex_var_persistent_u8_1() /* indic_matra_category_t */
|
||||
|
||||
#define INDIC_TABLE_ELEMENT_TYPE uint8_t
|
||||
|
||||
|
|
|
@ -34,10 +34,18 @@
|
|||
HB_BEGIN_DECLS
|
||||
|
||||
|
||||
/* buffer var allocations, used by all shapers */
|
||||
/* buffer var allocations, used during the entire shaping process */
|
||||
#define general_category() var1.u8[0] /* unicode general_category (hb_unicode_general_category_t) */
|
||||
#define combining_class() var1.u8[1] /* unicode combining_class (uint8_t) */
|
||||
|
||||
/* buffer var allocations, used by complex shapers */
|
||||
#define complex_var_persistent_u8_0() var2.u8[0]
|
||||
#define complex_var_persistent_u8_1() var2.u8[1]
|
||||
#define complex_var_persistent_u16() var2.u16[0]
|
||||
#define complex_var_temporary_u8_0() var2.u8[2]
|
||||
#define complex_var_temporary_u8_1() var2.u8[3]
|
||||
#define complex_var_temporary_u16() var2.u16[1]
|
||||
|
||||
|
||||
#define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
|
||||
HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
|
||||
|
|
|
@ -115,7 +115,7 @@ hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
|
|||
hb_mask_t global_mask = c->plan->map.get_global_mask ();
|
||||
c->buffer->reset_masks (global_mask);
|
||||
|
||||
hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer); /* BUFFER: Clobbers var2 */
|
||||
hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer);
|
||||
|
||||
for (unsigned int i = 0; i < c->num_user_features; i++)
|
||||
{
|
||||
|
@ -225,17 +225,21 @@ hb_map_glyphs (hb_font_t *font,
|
|||
static void
|
||||
hb_substitute_default (hb_ot_shape_context_t *c)
|
||||
{
|
||||
hb_ot_layout_substitute_start (c->buffer);
|
||||
|
||||
hb_mirror_chars (c);
|
||||
|
||||
hb_map_glyphs (c->font, c->buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_ot_substitute_complex (hb_ot_shape_context_t *c)
|
||||
{
|
||||
if (!hb_ot_layout_has_substitution (c->face))
|
||||
return;
|
||||
|
||||
if (hb_ot_layout_has_substitution (c->face))
|
||||
c->plan->map.substitute (c->face, c->buffer);
|
||||
|
||||
hb_ot_layout_substitute_finish (c->buffer);
|
||||
|
||||
c->applied_substitute_complex = TRUE;
|
||||
return;
|
||||
}
|
||||
|
@ -271,8 +275,9 @@ static void
|
|||
hb_ot_position_complex (hb_ot_shape_context_t *c)
|
||||
{
|
||||
|
||||
if (!hb_ot_layout_has_positioning (c->face))
|
||||
return;
|
||||
if (hb_ot_layout_has_positioning (c->face))
|
||||
{
|
||||
/* Change glyph origin to what GPOS expects, apply GPOS, change it back. */
|
||||
|
||||
unsigned int count = c->buffer->len;
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
|
@ -290,6 +295,7 @@ hb_ot_position_complex (hb_ot_shape_context_t *c)
|
|||
&c->buffer->pos[i].x_offset,
|
||||
&c->buffer->pos[i].y_offset);
|
||||
}
|
||||
}
|
||||
|
||||
hb_ot_layout_position_finish (c->buffer);
|
||||
|
||||
|
@ -341,10 +347,15 @@ hb_position_complex_fallback_visual (hb_ot_shape_context_t *c)
|
|||
static void
|
||||
hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
||||
{
|
||||
c->buffer->deallocate_var_all ();
|
||||
|
||||
/* Save the original direction, we use it later. */
|
||||
c->target_direction = c->buffer->props.direction;
|
||||
|
||||
_hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class in var1 */
|
||||
HB_BUFFER_ALLOCATE_VAR (c->buffer, general_category);
|
||||
HB_BUFFER_ALLOCATE_VAR (c->buffer, combining_class);
|
||||
|
||||
_hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class */
|
||||
|
||||
hb_form_clusters (c->buffer);
|
||||
|
||||
|
@ -352,12 +363,10 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
|||
|
||||
_hb_ot_shape_normalize (c);
|
||||
|
||||
hb_ot_shape_setup_masks (c); /* BUFFER: Clobbers var2 */
|
||||
hb_ot_shape_setup_masks (c);
|
||||
|
||||
/* SUBSTITUTE */
|
||||
{
|
||||
hb_mirror_chars (c);
|
||||
|
||||
hb_substitute_default (c);
|
||||
|
||||
hb_ot_substitute_complex (c);
|
||||
|
@ -383,6 +392,9 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
|||
hb_position_complex_fallback_visual (c);
|
||||
}
|
||||
|
||||
HB_BUFFER_DEALLOCATE_VAR (c->buffer, combining_class);
|
||||
HB_BUFFER_DEALLOCATE_VAR (c->buffer, general_category);
|
||||
|
||||
c->buffer->props.direction = c->target_direction;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "hb-common.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue