[pango/harfbuzz-ng] [GPOS] Start filling apply() functions in



commit 9c25dfbd235bd155ad62f3a8d03e27af9a17b810
Author: Behdad Esfahbod <behdad behdad org>
Date:   Mon May 18 19:47:52 2009 -0400

    [GPOS] Start filling apply() functions in
---
 pango/opentype/harfbuzz-buffer-private.h     |    1 +
 pango/opentype/harfbuzz-buffer.c             |    3 -
 pango/opentype/hb-ot-layout-common-private.h |   35 +++++---
 pango/opentype/hb-ot-layout-gpos-private.h   |  125 +++++++++++++++++++-------
 4 files changed, 115 insertions(+), 49 deletions(-)

diff --git a/pango/opentype/harfbuzz-buffer-private.h b/pango/opentype/harfbuzz-buffer-private.h
index 8dc8447..752149f 100644
--- a/pango/opentype/harfbuzz-buffer-private.h
+++ b/pango/opentype/harfbuzz-buffer-private.h
@@ -79,6 +79,7 @@ _hb_buffer_allocate_ligid( HB_Buffer buffer );
 #define IN_LIGID( pos )        (buffer->in_string[(pos)].ligID)
 #define IN_COMPONENT( pos )    (buffer->in_string[(pos)].component)
 #define POSITION( pos )        (&buffer->positions[(pos)])
+#define CURPOSITION()          (&buffer->positions[buffer->in_pos])
 #define OUT_GLYPH( pos )       (buffer->out_string[(pos)].gindex)
 #define OUT_ITEM( pos )        (&buffer->out_string[(pos)])
 
diff --git a/pango/opentype/harfbuzz-buffer.c b/pango/opentype/harfbuzz-buffer.c
index 02842ea..8e93203 100644
--- a/pango/opentype/harfbuzz-buffer.c
+++ b/pango/opentype/harfbuzz-buffer.c
@@ -354,9 +354,6 @@ HB_INTERNAL HB_Error
 _hb_buffer_replace_glyph( HB_Buffer buffer,
 			  HB_UInt   glyph_index )
 {
-
-  HB_Error error;
-
   if ( !buffer->separate_out )
     {
       buffer->out_string[buffer->out_pos].gindex = glyph_index;
diff --git a/pango/opentype/hb-ot-layout-common-private.h b/pango/opentype/hb-ot-layout-common-private.h
index 50fdc44..a805f48 100644
--- a/pango/opentype/hb-ot-layout-common-private.h
+++ b/pango/opentype/hb-ot-layout-common-private.h
@@ -404,24 +404,31 @@ ASSERT_SIZE (ClassDef, 2);
  */
 
 struct Device {
-  int get_delta (int ppem_size) const {
-    if (ppem_size >= startSize && ppem_size <= endSize &&
-        deltaFormat >= 1 && deltaFormat <= 3) {
-      int s = ppem_size - startSize;
-      int f = deltaFormat;
+  int get_delta (unsigned int ppem_size) const {
 
-      uint16_t byte = deltaValue[s >> (4 - f)];
-      uint16_t bits = byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f));
-      uint16_t mask = 0xFFFF >> (16 - (1 << f));
+    unsigned int f = deltaFormat;
+    if (HB_UNLIKELY (f < 1 || f > 3))
+      return 0;
 
-      int delta = bits & mask;
+    if (ppem_size < startSize || ppem_size > endSize)
+      return 0;
 
-      if (delta >= ((mask + 1) >> 1))
-        delta -= mask + 1;
+    unsigned int s = ppem_size - startSize;
 
-      return delta;
-    }
-    return 0;
+    unsigned int byte = deltaValue[s >> (4 - f)];
+    unsigned int bits = byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f));
+    unsigned int mask = 0xFFFF >> (16 - (1 << f));
+
+    int delta = bits & mask;
+
+    if (delta >= ((mask + 1) >> 1))
+      delta -= mask + 1;
+
+    return delta;
+  }
+
+  inline int operator() (unsigned int ppem_size) const {
+    return get_delta (ppem_size);
   }
 
   private:
diff --git a/pango/opentype/hb-ot-layout-gpos-private.h b/pango/opentype/hb-ot-layout-gpos-private.h
index bdf6ff4..8775b78 100644
--- a/pango/opentype/hb-ot-layout-gpos-private.h
+++ b/pango/opentype/hb-ot-layout-gpos-private.h
@@ -67,31 +67,77 @@ struct ValueRecord {
 					 * PosTable (may be NULL) */
 };
 ASSERT_SIZE (ValueRecord, 16);
+#endif
 
-struct ValueFormat {
-  /* TODO */
+struct ValueFormat : USHORT {
+
+  enum {
+    xPlacement	= 0x0001,	/* Includes horizontal adjustment for placement */
+    yPlacement	= 0x0002,	/* Includes vertical adjustment for placement */
+    xAdvance	= 0x0004,	/* Includes horizontal adjustment for advance */
+    yAdvance	= 0x0008,	/* Includes vertical adjustment for advance */
+    xPlaDevice	= 0x0010,	/* Includes horizontal Device table for placement */
+    yPlaDevice	= 0x0020,	/* Includes vertical Device table for placement */
+    xAdvDevice	= 0x0040,	/* Includes horizontal Device table for advance */
+    yAdvDevice	= 0x0080,	/* Includes vertical Device table for advance */
+    reserved	= 0xF000,	/* For future use */
+  };
+
+  inline unsigned int get_len () const {
+    return _hb_popcount32 ((unsigned int) *this);
+  }
 
-  private:
-  0x0001	xPlacement;		/* Includes horizontal adjustment
-					 * for placement */
-  0x0002	yPlacement;		/* Includes vertical adjustment for
-					 * placement */
-  0x0004	xAdvance;		/* Includes horizontal adjustment
-					 * for advance */
-  0x0008	yAdvance;		/* Includes vertical adjustment for
-					 * advance */
-  0x0010	xPlaDevice;		/* Includes horizontal Device table
-					 * for placement */
-  0x0020	yPlaDevice;		/* Includes vertical Device table
-					 * for placement */
-  0x0040	xAdvDevice;		/* Includes horizontal Device table
-					 * for advance */
-  0x0080	yAdvDevice;		/* Includes vertical Device table
-					 * for advance */
-  0xF000	reserved;		/* For future use */
-};
-ASSERT_SIZE (ValueFormat, 18);
-#endif
+  const Value* apply_value (hb_ot_layout_t *layout,
+			    const char     *base,
+			    const Value    *values,
+			    HB_Position     glyph_pos) const
+  {
+    unsigned int x_ppem, y_ppem;
+    hb_16dot16_t x_scale, y_scale;
+    unsigned int pixel_value;
+    unsigned int format = *this;
+
+    if (!format)
+      return values;
+
+    x_scale = layout->gpos_info.x_scale;
+    y_scale = layout->gpos_info.y_scale;
+    /* design units -> fractional pixel */
+    if (format & xPlacement)
+      glyph_pos->x_pos += x_scale * *(USHORT*)values++ / 0x10000;
+    if (format & yPlacement)
+      glyph_pos->y_pos += y_scale * *(USHORT*)values++ / 0x10000;
+    if (format & xAdvance)
+      glyph_pos->x_advance += x_scale * *(USHORT*)values++ / 0x10000;
+    if (format & yAdvance)
+      glyph_pos->y_advance += y_scale * *(USHORT*)values++ / 0x10000;
+
+    if (HB_LIKELY (!layout->gpos_info.dvi))
+    {
+      x_ppem = layout->gpos_info.x_ppem;
+      y_ppem = layout->gpos_info.y_ppem;
+      /* pixel -> fractional pixel */
+      if (format & xPlaDevice)
+	glyph_pos->x_pos += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6;
+      if (format & yPlaDevice)
+	glyph_pos->y_pos += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6;
+      if (format & xAdvDevice)
+	glyph_pos->x_advance += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6;
+      if (format & yAdvDevice)
+	glyph_pos->y_advance += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6;
+    }
+    else
+    {
+      if (format & xPlaDevice) values++;
+      if (format & yPlaDevice) values++;
+      if (format & xAdvDevice) values++;
+      if (format & yAdvDevice) values++;
+    }
+
+    return values;
+  }
+};
+ASSERT_SIZE (ValueFormat, 2);
 
 
 struct AnchorFormat1 {
@@ -212,8 +258,13 @@ struct SinglePosFormat1 {
 
   private:
   inline bool apply (APPLY_ARG_DEF) const {
-    /* TODO */
-    return false;
+
+    unsigned int index = (this+coverage) (IN_CURGLYPH ());
+    if (HB_LIKELY (index == NOT_COVERED))
+      return false;
+
+    valueFormat.apply_value (layout, (const char *) this, values, CURPOSITION ());
+    return true;
   }
 
   private:
@@ -221,7 +272,7 @@ struct SinglePosFormat1 {
   OffsetTo<Coverage>
 		coverage;		/* Offset to Coverage table--from
 					 * beginning of subtable */
-  USHORT	valueFormat;		/* Defines the types of data in the
+  ValueFormat	valueFormat;		/* Defines the types of data in the
 					 * ValueRecord */
   ValueRecord	values;			/* Defines positioning
 					 * value(s)--applied to all glyphs in
@@ -235,8 +286,18 @@ struct SinglePosFormat2 {
 
   private:
   inline bool apply (APPLY_ARG_DEF) const {
-    /* TODO */
-    return false;
+
+    unsigned int index = (this+coverage) (IN_CURGLYPH ());
+    if (HB_LIKELY (index == NOT_COVERED))
+      return false;
+
+    if (HB_LIKELY (index >= valueCount))
+      return false;
+
+    valueFormat.apply_value (layout, (const char *) this,
+			     values + index * valueFormat.get_len (),
+			     CURPOSITION ());
+    return true;
   }
 
   private:
@@ -244,7 +305,7 @@ struct SinglePosFormat2 {
   OffsetTo<Coverage>
 		coverage;		/* Offset to Coverage table--from
 					 * beginning of subtable */
-  USHORT	valueFormat;		/* Defines the types of data in the
+  ValueFormat	valueFormat;		/* Defines the types of data in the
 					 * ValueRecord */
   USHORT	valueCount;		/* Number of ValueRecords */
   ValueRecord	values;			/* Array of ValueRecords--positioning
@@ -307,10 +368,10 @@ struct PairPosFormat1 {
   OffsetTo<Coverage>
 		coverage;		/* Offset to Coverage table--from
 					 * beginning of subtable */
-  USHORT	valueFormat1;		/* Defines the types of data in
+  ValueFormat	valueFormat1;		/* Defines the types of data in
 					 * ValueRecord1--for the first glyph
 					 * in the pair--may be zero (0) */
-  USHORT	valueFormat2;		/* Defines the types of data in
+  ValueFormat	valueFormat2;		/* Defines the types of data in
 					 * ValueRecord2--for the second glyph
 					 * in the pair--may be zero (0) */
   OffsetArrayOf<PairSet>
@@ -334,10 +395,10 @@ struct PairPosFormat2 {
   OffsetTo<Coverage>
 		coverage;		/* Offset to Coverage table--from
 					 * beginning of subtable */
-  USHORT	valueFormat1;		/* ValueRecord definition--for the
+  ValueFormat	valueFormat1;		/* ValueRecord definition--for the
 					 * first glyph of the pair--may be zero
 					 * (0) */
-  USHORT	valueFormat2;		/* ValueRecord definition--for the
+  ValueFormat	valueFormat2;		/* ValueRecord definition--for the
 					 * second glyph of the pair--may be
 					 * zero (0) */
   OffsetTo<ClassDef>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]