diff --git a/src/hb-buffer-private.h b/src/hb-buffer-private.h index f98f76850..3a74f2e5b 100644 --- a/src/hb-buffer-private.h +++ b/src/hb-buffer-private.h @@ -51,11 +51,7 @@ typedef struct _hb_internal_glyph_position_t { hb_position_t y_advance; hb_position_t x_offset; hb_position_t y_offset; - uint32_t new_advance :1; /* if set, the advance width values are - absolute, i.e., they won't be - added to the original glyph's value - but rather replace them */ - uint32_t back : 15; /* number of glyphs to go back + uint32_t back : 16; /* number of glyphs to go back for drawing current glyph */ int32_t cursive_chain : 16; /* character to which this connects, may be positive or negative; used diff --git a/src/hb-buffer.h b/src/hb-buffer.h index 195ad3414..fb872207c 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -56,16 +56,7 @@ typedef struct _hb_glyph_position_t { hb_position_t y_advance; hb_position_t x_offset; hb_position_t y_offset; - /* XXX these should all be replaced by "uint32_t internal" */ - uint32_t new_advance :1; /* if set, the advance width values are - absolute, i.e., they won't be - added to the original glyph's value - but rather replace them */ - uint32_t back : 15; /* number of glyphs to go back - for drawing current glyph */ - int32_t cursive_chain : 16; /* character to which this connects, - may be positive or negative; used - only internally */ + uint32_t internal; } hb_glyph_position_t; diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 3159ab160..f8cbe7810 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -840,13 +840,13 @@ struct CursivePosFormat1 if (buffer->direction == HB_DIRECTION_RTL) { - POSITION (buffer->in_pos)->x_advance = entry_x - gpi->anchor_x; - POSITION (buffer->in_pos)->new_advance = true; + /* advance is absolute, not relative */ + POSITION (buffer->in_pos)->x_advance = entry_x - gpi->anchor_x; } else { - POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x; - POSITION (last_pos)->new_advance = true; + /* advance is absolute, not relative */ + POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x; } if (lookup_flag & LookupFlag::RightToLeft) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index d48ef70b6..45ace5b40 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -564,3 +564,55 @@ hb_ot_layout_position_lookup (hb_face_t *face, context.face = face; return _get_gpos (face).position_lookup (&context, buffer, lookup_index, mask); } + +#include +void +hb_ot_layout_position_finish (hb_face_t *face, + hb_font_t *font, + hb_buffer_t *buffer) +{ + unsigned int i, j; + unsigned int len = hb_buffer_get_length (buffer); + hb_internal_glyph_position_t *positions = (hb_internal_glyph_position_t *) hb_buffer_get_glyph_positions (buffer); + + /* TODO: Vertical */ + + /* Handle cursive connections */ + /* First handle all left-to-right connections */ + for (j = 0; j < len; j++) { + if (positions[j].cursive_chain > 0) { + printf ("0000000000000\n"); + positions[j].y_offset += positions[j - positions[j].cursive_chain].y_offset; + positions[j].cursive_chain = 0; + } + } + /* Then handle all right-to-left connections */ + for (i = len; i > 0; i--) { + j = i - 1; + if (positions[j].cursive_chain < 0) { + positions[j].y_offset += positions[j - positions[j].cursive_chain].y_offset; + positions[j].cursive_chain = 0; + } + } + + /* Handle attachments */ + for (i = 0; i < len; i++) + if (positions[i].back) + { + unsigned int back = i - positions[i].back; + positions[i].back = 0; + positions[i].x_offset += positions[back].x_offset; + positions[i].y_offset += positions[back].y_offset; + + if (buffer->direction == HB_DIRECTION_RTL) + for (j = back + 1; j < i + 1; j++) { + positions[i].x_offset += positions[j].x_advance; + positions[i].y_offset += positions[j].y_advance; + } + else + for (j = back; j < i; j++) { + positions[i].x_offset -= positions[j].x_advance; + positions[i].y_offset -= positions[j].y_advance; + } + } +} diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 773828e8f..40ead8290 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -198,11 +198,17 @@ hb_bool_t hb_ot_layout_has_positioning (hb_face_t *face); hb_bool_t -hb_ot_layout_position_lookup (hb_face_t *face, - hb_font_t *font, - hb_buffer_t *buffer, - unsigned int lookup_index, - hb_mask_t mask); +hb_ot_layout_position_lookup (hb_face_t *face, + hb_font_t *font, + hb_buffer_t *buffer, + unsigned int lookup_index, + hb_mask_t mask); + +/* Should be called after all the position_lookup's are done */ +void +hb_ot_layout_position_finish (hb_face_t *face, + hb_font_t *font, + hb_buffer_t *buffer); HB_END_DECLS