Add hb_ot_layout_position_finish()
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 6 Nov 2009 21:47:31 +0000 (16:47 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 6 Nov 2009 21:47:31 +0000 (16:47 -0500)
We expect buffer to be setup with default positions before GPOS.

src/hb-buffer-private.h
src/hb-buffer.h
src/hb-ot-layout-gpos-private.hh
src/hb-ot-layout.cc
src/hb-ot-layout.h

index f98f768..3a74f2e 100644 (file)
@@ -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
index 195ad34..fb87220 100644 (file)
@@ -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;
 
 
index 3159ab1..f8cbe78 100644 (file)
@@ -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)
index d48ef70..45ace5b 100644 (file)
@@ -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 <stdio.h>
+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;
+         }
+      }
+}
index 773828e..40ead82 100644 (file)
@@ -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