/*
- * Copyright (C) 2007,2008,2009,2010 Red Hat, Inc.
- * Copyright (C) 2010 Google, Inc.
+ * Copyright © 2007,2008,2009,2010 Red Hat, Inc.
+ * Copyright © 2010 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
HB_BEGIN_DECLS
+/* buffer 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 */
+
+
/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
typedef USHORT Value;
inline unsigned int get_size (void) const
{ return get_len () * Value::static_size; }
- void apply_value (hb_ot_layout_context_t *layout,
- const void *base,
- const Value *values,
- hb_glyph_position_t &glyph_pos) const
+ void apply_value (hb_font_t *font,
+ const void *base,
+ const Value *values,
+ hb_glyph_position_t &glyph_pos) const
{
unsigned int x_ppem, y_ppem;
unsigned int format = *this;
if (!format) return;
/* design units -> fractional pixel */
- if (format & xPlacement) glyph_pos.x_offset += layout->scale_x (get_short (values++));
- if (format & yPlacement) glyph_pos.y_offset += layout->scale_y (get_short (values++));
- if (format & xAdvance) glyph_pos.x_advance += layout->scale_x (get_short (values++));
- if (format & yAdvance) glyph_pos.y_advance += layout->scale_y (get_short (values++));
+ if (format & xPlacement) glyph_pos.x_offset += font->em_scale_x (get_short (values++));
+ if (format & yPlacement) glyph_pos.y_offset += font->em_scale_y (get_short (values++));
+ if (format & xAdvance) glyph_pos.x_advance += font->em_scale_x (get_short (values++));
+ if (format & yAdvance) glyph_pos.y_advance += font->em_scale_y (get_short (values++));
if (!has_device ()) return;
- x_ppem = layout->font->x_ppem;
- y_ppem = layout->font->y_ppem;
+ x_ppem = font->x_ppem;
+ y_ppem = font->y_ppem;
if (!x_ppem && !y_ppem) return;
/* pixel -> fractional pixel */
if (format & xPlaDevice) {
- if (x_ppem) glyph_pos.x_offset += (base + get_device (values++)).get_x_delta (layout); else values++;
+ if (x_ppem) glyph_pos.x_offset += (base + get_device (values++)).get_x_delta (font); else values++;
}
if (format & yPlaDevice) {
- if (y_ppem) glyph_pos.y_offset += (base + get_device (values++)).get_y_delta (layout); else values++;
+ if (y_ppem) glyph_pos.y_offset += (base + get_device (values++)).get_y_delta (font); else values++;
}
if (format & xAdvDevice) {
- if (x_ppem) glyph_pos.x_advance += (base + get_device (values++)).get_x_delta (layout); else values++;
+ if (x_ppem) glyph_pos.x_advance += (base + get_device (values++)).get_x_delta (font); else values++;
}
if (format & yAdvDevice) {
- if (y_ppem) glyph_pos.y_advance += (base + get_device (values++)).get_y_delta (layout); else values++;
+ if (y_ppem) glyph_pos.y_advance += (base + get_device (values++)).get_y_delta (font); else values++;
}
}
friend struct Anchor;
private:
- inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id HB_UNUSED,
+ inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED,
hb_position_t *x, hb_position_t *y) const
{
- *x = layout->scale_x (xCoordinate);
- *y = layout->scale_y (yCoordinate);
+ *x = font->em_scale_x (xCoordinate);
+ *y = font->em_scale_y (yCoordinate);
}
inline bool sanitize (hb_sanitize_context_t *c) {
friend struct Anchor;
private:
- inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id,
+ inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id,
hb_position_t *x, hb_position_t *y) const
{
- unsigned int x_ppem = layout->font->x_ppem;
- unsigned int y_ppem = layout->font->y_ppem;
+ unsigned int x_ppem = font->x_ppem;
+ unsigned int y_ppem = font->y_ppem;
hb_position_t cx, cy;
- hb_bool_t ret;
+ hb_bool_t ret = false;
if (x_ppem || y_ppem)
- ret = hb_font_get_contour_point (layout->font, layout->face, anchorPoint, glyph_id, &cx, &cy);
- *x = x_ppem && ret ? cx : layout->scale_x (xCoordinate);
- *y = y_ppem && ret ? cy : layout->scale_y (yCoordinate);
+ ret = hb_font_get_contour_point (font, glyph_id, anchorPoint, &cx, &cy);
+ *x = x_ppem && ret ? cx : font->em_scale_x (xCoordinate);
+ *y = y_ppem && ret ? cy : font->em_scale_y (yCoordinate);
}
inline bool sanitize (hb_sanitize_context_t *c) {
friend struct Anchor;
private:
- inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id HB_UNUSED,
+ inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED,
hb_position_t *x, hb_position_t *y) const
{
- *x = layout->scale_x (xCoordinate);
- *y = layout->scale_y (yCoordinate);
+ *x = font->em_scale_x (xCoordinate);
+ *y = font->em_scale_y (yCoordinate);
/* pixel -> fractional pixel */
- if (layout->font->x_ppem)
- *x += (this+xDeviceTable).get_x_delta (layout);
- if (layout->font->y_ppem)
- *y += (this+yDeviceTable).get_x_delta (layout);
+ if (font->x_ppem)
+ *x += (this+xDeviceTable).get_x_delta (font);
+ if (font->y_ppem)
+ *y += (this+yDeviceTable).get_x_delta (font);
}
inline bool sanitize (hb_sanitize_context_t *c) {
struct Anchor
{
- inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id,
+ inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id,
hb_position_t *x, hb_position_t *y) const
{
*x = *y = 0;
switch (u.format) {
- case 1: u.format1.get_anchor (layout, glyph_id, x, y); return;
- case 2: u.format2.get_anchor (layout, glyph_id, x, y); return;
- case 3: u.format3.get_anchor (layout, glyph_id, x, y); return;
- default: return;
+ case 1: u.format1.get_anchor (font, glyph_id, x, y); return;
+ case 2: u.format2.get_anchor (font, glyph_id, x, y); return;
+ case 3: u.format3.get_anchor (font, glyph_id, x, y); return;
+ default: return;
}
}
hb_position_t mark_x, mark_y, base_x, base_y;
- mark_anchor.get_anchor (c->layout, c->buffer->info[c->buffer->i].codepoint, &mark_x, &mark_y);
- glyph_anchor.get_anchor (c->layout, c->buffer->info[glyph_pos].codepoint, &base_x, &base_y);
+ mark_anchor.get_anchor (c->font, c->buffer->info[c->buffer->i].codepoint, &mark_x, &mark_y);
+ glyph_anchor.get_anchor (c->font, c->buffer->info[glyph_pos].codepoint, &base_x, &base_y);
hb_glyph_position_t &o = c->buffer->pos[c->buffer->i];
- o.x_offset = base_x - mark_x;
- o.y_offset = base_y - mark_y;
- o.back() = c->buffer->i - glyph_pos;
+ o.x_offset = base_x - mark_x;
+ o.y_offset = base_y - mark_y;
+ o.attach_lookback() = c->buffer->i - glyph_pos;
c->buffer->i++;
return true;
if (likely (index == NOT_COVERED))
return false;
- valueFormat.apply_value (c->layout, this, values, c->buffer->pos[c->buffer->i]);
+ valueFormat.apply_value (c->font, this, values, c->buffer->pos[c->buffer->i]);
c->buffer->i++;
return true;
if (likely (index >= valueCount))
return false;
- valueFormat.apply_value (c->layout, this,
+ valueFormat.apply_value (c->font, this,
&values[index * valueFormat.get_len ()],
c->buffer->pos[c->buffer->i]);
{
if (c->buffer->info[pos].codepoint == record->secondGlyph)
{
- valueFormats[0].apply_value (c->layout, this, &record->values[0], c->buffer->pos[c->buffer->i]);
- valueFormats[1].apply_value (c->layout, this, &record->values[len1], c->buffer->pos[pos]);
+ valueFormats[0].apply_value (c->font, this, &record->values[0], c->buffer->pos[c->buffer->i]);
+ valueFormats[1].apply_value (c->font, this, &record->values[len1], c->buffer->pos[pos]);
if (len2)
pos++;
c->buffer->i = pos;
return false;
unsigned int j = c->buffer->i + 1;
- while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], c->lookup_flag, NULL))
+ while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL))
{
if (unlikely (j == end))
return false;
return false;
unsigned int j = c->buffer->i + 1;
- while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], c->lookup_flag, NULL))
+ while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL))
{
if (unlikely (j == end))
return false;
return false;
const Value *v = &values[record_len * (klass1 * class2Count + klass2)];
- valueFormat1.apply_value (c->layout, this, v, c->buffer->pos[c->buffer->i]);
- valueFormat2.apply_value (c->layout, this, v + len1, c->buffer->pos[j]);
+ valueFormat1.apply_value (c->font, this, v, c->buffer->pos[c->buffer->i]);
+ valueFormat2.apply_value (c->font, this, v + len1, c->buffer->pos[j]);
if (len2)
j++;
return false;
unsigned int j = c->buffer->i + 1;
- while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], c->lookup_flag, NULL))
+ while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL))
{
if (unlikely (j == end))
return false;
unsigned int i = c->buffer->i;
hb_position_t entry_x, entry_y, exit_x, exit_y;
- (this+this_record.exitAnchor).get_anchor (c->layout, c->buffer->info[i].codepoint, &exit_x, &exit_y);
- (this+next_record.entryAnchor).get_anchor (c->layout, c->buffer->info[j].codepoint, &entry_x, &entry_y);
+ (this+this_record.exitAnchor).get_anchor (c->font, c->buffer->info[i].codepoint, &exit_x, &exit_y);
+ (this+next_record.entryAnchor).get_anchor (c->font, c->buffer->info[j].codepoint, &entry_x, &entry_y);
hb_direction_t direction = c->buffer->props.direction;
c->buffer->pos[i].y_advance = c->buffer->pos[i].y_offset + exit_y - entry_y;
}
- if (c->lookup_flag & LookupFlag::RightToLeft)
+ if (c->lookup_props & LookupFlag::RightToLeft)
{
c->buffer->pos[i].cursive_chain() = j - i;
if (likely (HB_DIRECTION_IS_HORIZONTAL (direction)))
if (unlikely (!j))
return false;
j--;
- } while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], LookupFlag::IgnoreMarks, &property));
+ } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], LookupFlag::IgnoreMarks, &property));
/* The following assertion is too strong, so we've disabled it. */
- if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
- return false;
+ if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
+ {/*return false;*/}
unsigned int base_index = (this+baseCoverage) (c->buffer->info[j].codepoint);
if (base_index == NOT_COVERED)
if (unlikely (!j))
return false;
j--;
- } while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], LookupFlag::IgnoreMarks, &property));
+ } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], LookupFlag::IgnoreMarks, &property));
/* The following assertion is too strong, so we've disabled it. */
- if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
- return false;
+ if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
+ {/*return false;*/}
unsigned int lig_index = (this+ligatureCoverage) (c->buffer->info[j].codepoint);
if (lig_index == NOT_COVERED)
* 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->i].lig_id() && c->buffer->info[c->buffer->i].component())
+ if (c->buffer->info[j].lig_id() && c->buffer->info[j].lig_id() == c->buffer->info[c->buffer->i].lig_id() && c->buffer->info[c->buffer->i].lig_comp())
{
- comp_index = c->buffer->info[c->buffer->i].component() - 1;
+ comp_index = c->buffer->info[c->buffer->i].lig_comp() - 1;
if (comp_index >= comp_count)
comp_index = comp_count - 1;
}
if (unlikely (!j))
return false;
j--;
- } while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->info[j], c->lookup_flag, &property));
+ } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, &property));
if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK))
return false;
/* 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].component() != c->buffer->info[c->buffer->i].component()) ||
- (c->buffer->info[j].component() && c->buffer->info[j].lig_id() != c->buffer->info[c->buffer->i].lig_id()))
+ if ((c->buffer->info[j].lig_comp() != c->buffer->info[c->buffer->i].lig_comp()) ||
+ (c->buffer->info[j].lig_comp() && c->buffer->info[j].lig_id() != c->buffer->info[c->buffer->i].lig_id()))
return false;
unsigned int mark2_index = (this+mark2Coverage) (c->buffer->info[j].codepoint);
inline const PosLookupSubTable& get_subtable (unsigned int i) const
{ return this+CastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; }
- inline bool apply_once (hb_ot_layout_context_t *layout,
+ inline bool apply_once (hb_font_t *font,
hb_buffer_t *buffer,
hb_mask_t lookup_mask,
unsigned int context_length,
unsigned int lookup_type = get_type ();
hb_apply_context_t c[1] = {{0}};
- c->layout = layout;
+ c->font = font;
+ c->face = font->face;
c->buffer = buffer;
c->lookup_mask = lookup_mask;
c->context_length = context_length;
c->nesting_level_left = nesting_level_left;
- c->lookup_flag = get_flag ();
+ c->lookup_props = get_props ();
- if (!_hb_ot_layout_check_glyph_property (c->layout->face, &c->buffer->info[c->buffer->i], c->lookup_flag, &c->property))
+ if (!_hb_ot_layout_check_glyph_property (c->face, &c->buffer->info[c->buffer->i], c->lookup_props, &c->property))
return false;
for (unsigned int i = 0; i < get_subtable_count (); i++)
return false;
}
- inline bool apply_string (hb_ot_layout_context_t *layout,
+ inline bool apply_string (hb_font_t *font,
hb_buffer_t *buffer,
hb_mask_t mask) const
{
while (buffer->i < buffer->len)
{
if ((buffer->info[buffer->i].mask & mask) &&
- apply_once (layout, buffer, mask, NO_CONTEXT, MAX_NESTING_LEVEL))
+ apply_once (font, buffer, mask, NO_CONTEXT, MAX_NESTING_LEVEL))
ret = true;
else
buffer->i++;
inline const PosLookup& get_lookup (unsigned int i) const
{ return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
- inline bool position_lookup (hb_ot_layout_context_t *layout,
+ inline bool position_lookup (hb_font_t *font,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask) const
- { return get_lookup (lookup_index).apply_string (layout, buffer, mask); }
+ { return get_lookup (lookup_index).apply_string (font, buffer, mask); }
+
+ static inline void position_finish (hb_buffer_t *buffer);
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
DEFINE_SIZE_STATIC (10);
};
+void
+GPOS::position_finish (hb_buffer_t *buffer)
+{
+ unsigned int i, j;
+ unsigned int len;
+ hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len);
+ hb_direction_t direction = buffer->props.direction;
+
+ /* Handle cursive connections:
+ * First handle all chain-back connections, then handle all chain-forward connections. */
+ if (likely (HB_DIRECTION_IS_HORIZONTAL (direction)))
+ {
+ for (j = 0; j < len; j++) {
+ if (pos[j].cursive_chain() < 0)
+ pos[j].y_offset += pos[j + pos[j].cursive_chain()].y_offset;
+ }
+ for (i = len; i > 0; i--) {
+ j = i - 1;
+ if (pos[j].cursive_chain() > 0)
+ pos[j].y_offset += pos[j + pos[j].cursive_chain()].y_offset;
+ }
+ }
+ else
+ {
+ for (j = 0; j < len; j++) {
+ if (pos[j].cursive_chain() < 0)
+ pos[j].x_offset += pos[j + pos[j].cursive_chain()].x_offset;
+ }
+ for (i = len; i > 0; i--) {
+ j = i - 1;
+ if (pos[j].cursive_chain() > 0)
+ pos[j].x_offset += pos[j + pos[j].cursive_chain()].x_offset;
+ }
+ }
+
+
+ /* Handle attachments */
+ for (i = 0; i < len; i++)
+ if (pos[i].attach_lookback())
+ {
+ unsigned int back = i - pos[i].attach_lookback();
+ pos[i].x_offset += pos[back].x_offset;
+ pos[i].y_offset += pos[back].y_offset;
+
+ if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
+ for (j = back + 1; j < i + 1; j++) {
+ pos[i].x_offset += pos[j].x_advance;
+ pos[i].y_offset += pos[j].y_advance;
+ }
+ else
+ for (j = back; j < i; j++) {
+ pos[i].x_offset -= pos[j].x_advance;
+ pos[i].y_offset -= pos[j].y_advance;
+ }
+ }
+}
+
/* Out-of-class implementation for methods recursing */
static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_index)
{
- const GPOS &gpos = *(c->layout->face->ot_layout->gpos);
+ const GPOS &gpos = *(c->face->ot_layout->gpos);
const PosLookup &l = gpos.get_lookup (lookup_index);
if (unlikely (c->nesting_level_left == 0))
if (unlikely (c->context_length < 1))
return false;
- return l.apply_once (c->layout, c->buffer, c->lookup_mask, c->context_length, c->nesting_level_left - 1);
+ return l.apply_once (c->font, c->buffer, c->lookup_mask, c->context_length, c->nesting_level_left - 1);
}
+#undef attach_lookback
+#undef cursive_chain
+
+
HB_END_DECLS
#endif /* HB_OT_LAYOUT_GPOS_PRIVATE_HH */