From 056c7ec1aea1eca60a3b20b583b8a8072be9d758 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 18 May 2009 19:47:52 -0400 Subject: [PATCH] [GPOS] Start filling apply() functions in --- src/harfbuzz-buffer-private.h | 1 + src/harfbuzz-buffer.c | 3 - src/hb-ot-layout-common-private.h | 35 ++++++----- src/hb-ot-layout-gpos-private.h | 127 ++++++++++++++++++++++++++++---------- 4 files changed, 116 insertions(+), 50 deletions(-) diff --git a/src/harfbuzz-buffer-private.h b/src/harfbuzz-buffer-private.h index 8dc8447..752149f 100644 --- a/src/harfbuzz-buffer-private.h +++ b/src/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/src/harfbuzz-buffer.c b/src/harfbuzz-buffer.c index 02842ea..8e93203 100644 --- a/src/harfbuzz-buffer.c +++ b/src/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/src/hb-ot-layout-common-private.h b/src/hb-ot-layout-common-private.h index fa22c08..64d61a2 100644 --- a/src/hb-ot-layout-common-private.h +++ b/src/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/src/hb-ot-layout-gpos-private.h b/src/hb-ot-layout-gpos-private.h index bdf6ff4..8775b78 100644 --- a/src/hb-ot-layout-gpos-private.h +++ b/src/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*)values++).get_delta (x_ppem) << 6; + if (format & yPlaDevice) + glyph_pos->y_pos += (base+*(OffsetTo*)values++).get_delta (y_ppem) << 6; + if (format & xAdvDevice) + glyph_pos->x_advance += (base+*(OffsetTo*)values++).get_delta (x_ppem) << 6; + if (format & yAdvDevice) + glyph_pos->y_advance += (base+*(OffsetTo*)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; /* 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; /* 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; /* 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 @@ -334,10 +395,10 @@ struct PairPosFormat2 { OffsetTo 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 -- 2.7.4