HarfBuzz text shaping engine
http://harfbuzz.github.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1356 lines
37 KiB
1356 lines
37 KiB
16 years ago
|
/*
|
||
|
* Copyright (C) 2007,2008,2009 Red Hat, Inc.
|
||
|
*
|
||
|
* This is part of HarfBuzz, an OpenType Layout engine library.
|
||
|
*
|
||
|
* Permission is hereby granted, without written agreement and without
|
||
|
* license or royalty fees, to use, copy, modify, and distribute this
|
||
|
* software and its documentation for any purpose, provided that the
|
||
|
* above copyright notice and the following two paragraphs appear in
|
||
|
* all copies of this software.
|
||
|
*
|
||
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||
|
* DAMAGE.
|
||
|
*
|
||
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||
|
*
|
||
|
* Red Hat Author(s): Behdad Esfahbod
|
||
|
*/
|
||
|
|
||
16 years ago
|
#ifndef HB_OT_LAYOUT_GPOS_PRIVATE_HH
|
||
|
#define HB_OT_LAYOUT_GPOS_PRIVATE_HH
|
||
16 years ago
|
|
||
16 years ago
|
#include "hb-ot-layout-gsubgpos-private.hh"
|
||
16 years ago
|
|
||
16 years ago
|
#define HB_OT_LAYOUT_GPOS_NO_LAST ((unsigned int) -1)
|
||
16 years ago
|
|
||
|
/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
|
||
|
|
||
|
typedef SHORT Value;
|
||
|
typedef Value ValueRecord[];
|
||
|
|
||
16 years ago
|
struct ValueFormat : USHORT
|
||
|
{
|
||
|
enum
|
||
|
{
|
||
16 years ago
|
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 */
|
||
16 years ago
|
ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */
|
||
16 years ago
|
reserved = 0xF000, /* For future use */
|
||
|
};
|
||
|
|
||
16 years ago
|
inline unsigned int get_len () const
|
||
16 years ago
|
{ return _hb_popcount32 ((unsigned int) *this); }
|
||
16 years ago
|
|
||
16 years ago
|
const void apply_value (hb_ot_layout_context_t *context,
|
||
16 years ago
|
const char *base,
|
||
|
const Value *values,
|
||
16 years ago
|
hb_internal_glyph_position_t *glyph_pos) const
|
||
16 years ago
|
{
|
||
|
unsigned int x_ppem, y_ppem;
|
||
|
hb_16dot16_t x_scale, y_scale;
|
||
|
unsigned int pixel_value;
|
||
|
unsigned int format = *this;
|
||
|
|
||
|
if (!format)
|
||
16 years ago
|
return;
|
||
|
|
||
|
/* All fields are options. Only those available advance the value
|
||
|
* pointer. */
|
||
|
#if 0
|
||
|
struct ValueRecord {
|
||
|
SHORT xPlacement; /* Horizontal adjustment for
|
||
|
* placement--in design units */
|
||
|
SHORT yPlacement; /* Vertical adjustment for
|
||
|
* placement--in design units */
|
||
|
SHORT xAdvance; /* Horizontal adjustment for
|
||
|
* advance--in design units (only used
|
||
|
* for horizontal writing) */
|
||
|
SHORT yAdvance; /* Vertical adjustment for advance--in
|
||
|
* design units (only used for vertical
|
||
|
* writing) */
|
||
|
Offset xPlaDevice; /* Offset to Device table for
|
||
|
* horizontal placement--measured from
|
||
|
* beginning of PosTable (may be NULL) */
|
||
|
Offset yPlaDevice; /* Offset to Device table for vertical
|
||
|
* placement--measured from beginning
|
||
|
* of PosTable (may be NULL) */
|
||
|
Offset xAdvDevice; /* Offset to Device table for
|
||
|
* horizontal advance--measured from
|
||
|
* beginning of PosTable (may be NULL) */
|
||
|
Offset yAdvDevice; /* Offset to Device table for vertical
|
||
|
* advance--measured from beginning of
|
||
|
* PosTable (may be NULL) */
|
||
|
};
|
||
|
#endif
|
||
16 years ago
|
|
||
16 years ago
|
x_scale = context->font->x_scale;
|
||
|
y_scale = context->font->y_scale;
|
||
16 years ago
|
/* design units -> fractional pixel */
|
||
|
if (format & xPlacement)
|
||
16 years ago
|
glyph_pos->x_pos += x_scale * *(SHORT*)values++ / 0x10000;
|
||
16 years ago
|
if (format & yPlacement)
|
||
16 years ago
|
glyph_pos->y_pos += y_scale * *(SHORT*)values++ / 0x10000;
|
||
16 years ago
|
if (format & xAdvance)
|
||
16 years ago
|
glyph_pos->x_advance += x_scale * *(SHORT*)values++ / 0x10000;
|
||
16 years ago
|
if (format & yAdvance)
|
||
16 years ago
|
glyph_pos->y_advance += y_scale * *(SHORT*)values++ / 0x10000;
|
||
16 years ago
|
|
||
16 years ago
|
x_ppem = context->font->x_ppem;
|
||
|
y_ppem = context->font->y_ppem;
|
||
16 years ago
|
/* pixel -> fractional pixel */
|
||
|
if (format & xPlaDevice) {
|
||
|
if (x_ppem)
|
||
16 years ago
|
glyph_pos->x_pos += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6;
|
||
16 years ago
|
else
|
||
|
values++;
|
||
|
}
|
||
|
if (format & yPlaDevice) {
|
||
|
if (y_ppem)
|
||
16 years ago
|
glyph_pos->y_pos += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6;
|
||
16 years ago
|
else
|
||
|
values++;
|
||
|
}
|
||
|
if (format & xAdvDevice) {
|
||
|
if (x_ppem)
|
||
16 years ago
|
glyph_pos->x_advance += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6;
|
||
16 years ago
|
else
|
||
|
values++;
|
||
|
}
|
||
|
if (format & yAdvDevice) {
|
||
|
if (y_ppem)
|
||
16 years ago
|
glyph_pos->y_advance += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6;
|
||
16 years ago
|
else
|
||
|
values++;
|
||
16 years ago
|
}
|
||
|
}
|
||
16 years ago
|
};
|
||
16 years ago
|
ASSERT_SIZE (ValueFormat, 2);
|
||
16 years ago
|
|
||
|
|
||
16 years ago
|
struct AnchorFormat1
|
||
|
{
|
||
16 years ago
|
friend struct Anchor;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id,
|
||
16 years ago
|
hb_position_t *x, hb_position_t *y) const
|
||
|
{
|
||
16 years ago
|
*x = context->font->x_scale * xCoordinate / 0x10000;
|
||
|
*y = context->font->y_scale * yCoordinate / 0x10000;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
|
SHORT xCoordinate; /* Horizontal value--in design units */
|
||
|
SHORT yCoordinate; /* Vertical value--in design units */
|
||
|
};
|
||
|
ASSERT_SIZE (AnchorFormat1, 6);
|
||
|
|
||
16 years ago
|
struct AnchorFormat2
|
||
|
{
|
||
16 years ago
|
friend struct Anchor;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id,
|
||
16 years ago
|
hb_position_t *x, hb_position_t *y) const
|
||
|
{
|
||
16 years ago
|
/* TODO Contour */
|
||
16 years ago
|
*x = context->font->x_scale * xCoordinate / 0x10000;
|
||
|
*y = context->font->y_scale * yCoordinate / 0x10000;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 2 */
|
||
|
SHORT xCoordinate; /* Horizontal value--in design units */
|
||
|
SHORT yCoordinate; /* Vertical value--in design units */
|
||
|
USHORT anchorPoint; /* Index to glyph contour point */
|
||
|
};
|
||
|
ASSERT_SIZE (AnchorFormat2, 8);
|
||
|
|
||
16 years ago
|
struct AnchorFormat3
|
||
|
{
|
||
16 years ago
|
friend struct Anchor;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id,
|
||
16 years ago
|
hb_position_t *x, hb_position_t *y) const
|
||
|
{
|
||
16 years ago
|
*x = context->font->x_scale * xCoordinate / 0x10000;
|
||
|
*y = context->font->y_scale * yCoordinate / 0x10000;
|
||
16 years ago
|
|
||
16 years ago
|
if (context->font->x_ppem)
|
||
|
*x += (this+xDeviceTable).get_delta (context->font->x_ppem) << 6;
|
||
|
if (context->font->y_ppem)
|
||
|
*y += (this+yDeviceTable).get_delta (context->font->y_ppem) << 6;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 3 */
|
||
|
SHORT xCoordinate; /* Horizontal value--in design units */
|
||
|
SHORT yCoordinate; /* Vertical value--in design units */
|
||
|
OffsetTo<Device>
|
||
|
xDeviceTable; /* Offset to Device table for X
|
||
|
* coordinate-- from beginning of
|
||
|
* Anchor table (may be NULL) */
|
||
|
OffsetTo<Device>
|
||
|
yDeviceTable; /* Offset to Device table for Y
|
||
|
* coordinate-- from beginning of
|
||
|
* Anchor table (may be NULL) */
|
||
|
};
|
||
|
ASSERT_SIZE (AnchorFormat3, 10);
|
||
|
|
||
16 years ago
|
struct Anchor
|
||
|
{
|
||
16 years ago
|
inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id,
|
||
16 years ago
|
hb_position_t *x, hb_position_t *y) const
|
||
|
{
|
||
16 years ago
|
*x = *y = 0;
|
||
|
switch (u.format) {
|
||
16 years ago
|
case 1: u.format1->get_anchor (context, glyph_id, x, y); return;
|
||
|
case 2: u.format2->get_anchor (context, glyph_id, x, y); return;
|
||
|
case 3: u.format3->get_anchor (context, glyph_id, x, y); return;
|
||
|
default: return;
|
||
16 years ago
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
AnchorFormat1 format1[];
|
||
|
AnchorFormat2 format2[];
|
||
|
AnchorFormat3 format3[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (Anchor, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct MarkRecord
|
||
|
{
|
||
16 years ago
|
friend struct MarkArray;
|
||
16 years ago
|
|
||
|
private:
|
||
|
USHORT klass; /* Class defined for this mark */
|
||
|
OffsetTo<Anchor>
|
||
|
markAnchor; /* Offset to Anchor table--from
|
||
|
* beginning of MarkArray table */
|
||
|
};
|
||
|
ASSERT_SIZE (MarkRecord, 4);
|
||
|
|
||
16 years ago
|
struct MarkArray
|
||
|
{
|
||
16 years ago
|
inline unsigned int get_class (unsigned int index) const { return markRecord[index].klass; }
|
||
|
inline const Anchor& get_anchor (unsigned int index) const { return this+markRecord[index].markAnchor; }
|
||
16 years ago
|
|
||
|
private:
|
||
|
ArrayOf<MarkRecord>
|
||
|
markRecord; /* Array of MarkRecords--in Coverage order */
|
||
|
};
|
||
|
ASSERT_SIZE (MarkArray, 2);
|
||
|
|
||
|
|
||
|
/* Lookups */
|
||
|
|
||
16 years ago
|
struct SinglePosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct SinglePos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
16 years ago
|
valueFormat.apply_value (context, (const char *) this, values, CURPOSITION ());
|
||
16 years ago
|
|
||
|
buffer->in_pos++;
|
||
16 years ago
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
|
OffsetTo<Coverage>
|
||
|
coverage; /* Offset to Coverage table--from
|
||
|
* beginning of subtable */
|
||
16 years ago
|
ValueFormat valueFormat; /* Defines the types of data in the
|
||
16 years ago
|
* ValueRecord */
|
||
|
ValueRecord values; /* Defines positioning
|
||
|
* value(s)--applied to all glyphs in
|
||
|
* the Coverage table */
|
||
|
};
|
||
|
ASSERT_SIZE (SinglePosFormat1, 6);
|
||
|
|
||
16 years ago
|
struct SinglePosFormat2
|
||
|
{
|
||
16 years ago
|
friend struct SinglePos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
if (HB_LIKELY (index >= valueCount))
|
||
|
return false;
|
||
|
|
||
16 years ago
|
valueFormat.apply_value (context, (const char *) this,
|
||
16 years ago
|
values + index * valueFormat.get_len (),
|
||
|
CURPOSITION ());
|
||
16 years ago
|
|
||
|
buffer->in_pos++;
|
||
16 years ago
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 2 */
|
||
|
OffsetTo<Coverage>
|
||
|
coverage; /* Offset to Coverage table--from
|
||
|
* beginning of subtable */
|
||
16 years ago
|
ValueFormat valueFormat; /* Defines the types of data in the
|
||
16 years ago
|
* ValueRecord */
|
||
|
USHORT valueCount; /* Number of ValueRecords */
|
||
|
ValueRecord values; /* Array of ValueRecords--positioning
|
||
|
* values applied to glyphs */
|
||
|
};
|
||
|
ASSERT_SIZE (SinglePosFormat2, 8);
|
||
|
|
||
16 years ago
|
struct SinglePos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
|
case 2: return u.format2->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
SinglePosFormat1 format1[];
|
||
|
SinglePosFormat2 format2[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (SinglePos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct PairValueRecord
|
||
|
{
|
||
16 years ago
|
friend struct PairPosFormat1;
|
||
16 years ago
|
|
||
|
private:
|
||
|
GlyphID secondGlyph; /* GlyphID of second glyph in the
|
||
|
* pair--first glyph is listed in the
|
||
|
* Coverage table */
|
||
|
ValueRecord values; /* Positioning data for the first glyph
|
||
|
* followed by for second glyph */
|
||
|
};
|
||
|
ASSERT_SIZE (PairValueRecord, 2);
|
||
|
|
||
16 years ago
|
struct PairSet
|
||
|
{
|
||
16 years ago
|
friend struct PairPosFormat1;
|
||
|
|
||
|
private:
|
||
|
USHORT len; /* Number of PairValueRecords */
|
||
|
PairValueRecord
|
||
|
array[]; /* Array of PairValueRecords--ordered
|
||
|
* by GlyphID of the second glyph */
|
||
|
};
|
||
16 years ago
|
ASSERT_SIZE (PairSet, 2);
|
||
|
|
||
16 years ago
|
struct PairPosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct PairPos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
|
unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
|
||
|
if (HB_UNLIKELY (buffer->in_pos + 2 > end))
|
||
|
return false;
|
||
|
|
||
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
unsigned int j = buffer->in_pos + 1;
|
||
16 years ago
|
while (_hb_ot_layout_skip_mark (context->layout, IN_INFO (j), lookup_flag, NULL))
|
||
16 years ago
|
{
|
||
16 years ago
|
if (HB_UNLIKELY (j == end))
|
||
|
return false;
|
||
|
j++;
|
||
|
}
|
||
|
|
||
|
const PairSet &pair_set = this+pairSet[index];
|
||
|
|
||
16 years ago
|
unsigned int len1 = valueFormat1.get_len ();
|
||
|
unsigned int len2 = valueFormat2.get_len ();
|
||
16 years ago
|
unsigned int record_len = 1 + len1 + len2;
|
||
|
|
||
|
unsigned int count = pair_set.len;
|
||
|
const PairValueRecord *record = pair_set.array;
|
||
16 years ago
|
for (unsigned int i = 0; i < count; i++)
|
||
|
{
|
||
|
if (IN_GLYPH (j) == record->secondGlyph)
|
||
|
{
|
||
16 years ago
|
valueFormat1.apply_value (context, (const char *) this, record->values, CURPOSITION ());
|
||
|
valueFormat2.apply_value (context, (const char *) this, record->values + len1, POSITION (j));
|
||
16 years ago
|
if (len2)
|
||
|
j++;
|
||
|
buffer->in_pos = j;
|
||
|
return true;
|
||
|
}
|
||
|
record += record_len;
|
||
|
}
|
||
|
|
||
16 years ago
|
return false;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
|
OffsetTo<Coverage>
|
||
|
coverage; /* Offset to Coverage table--from
|
||
|
* beginning of subtable */
|
||
16 years ago
|
ValueFormat valueFormat1; /* Defines the types of data in
|
||
16 years ago
|
* ValueRecord1--for the first glyph
|
||
|
* in the pair--may be zero (0) */
|
||
16 years ago
|
ValueFormat valueFormat2; /* Defines the types of data in
|
||
16 years ago
|
* ValueRecord2--for the second glyph
|
||
|
* in the pair--may be zero (0) */
|
||
|
OffsetArrayOf<PairSet>
|
||
|
pairSet; /* Array of PairSet tables
|
||
|
* ordered by Coverage Index */
|
||
|
};
|
||
|
ASSERT_SIZE (PairPosFormat1, 10);
|
||
|
|
||
16 years ago
|
struct PairPosFormat2
|
||
|
{
|
||
16 years ago
|
friend struct PairPos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
|
unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
|
||
|
if (HB_UNLIKELY (buffer->in_pos + 2 > end))
|
||
|
return false;
|
||
|
|
||
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
unsigned int j = buffer->in_pos + 1;
|
||
16 years ago
|
while (_hb_ot_layout_skip_mark (context->layout, IN_INFO (j), lookup_flag, NULL))
|
||
16 years ago
|
{
|
||
16 years ago
|
if (HB_UNLIKELY (j == end))
|
||
|
return false;
|
||
|
j++;
|
||
|
}
|
||
|
|
||
|
unsigned int len1 = valueFormat1.get_len ();
|
||
|
unsigned int len2 = valueFormat2.get_len ();
|
||
|
unsigned int record_len = len1 + len2;
|
||
|
|
||
|
unsigned int klass1 = (this+classDef1) (IN_CURGLYPH ());
|
||
|
unsigned int klass2 = (this+classDef2) (IN_GLYPH (j));
|
||
|
if (HB_UNLIKELY (klass1 >= class1Count || klass2 >= class2Count))
|
||
|
return false;
|
||
|
|
||
|
const Value *v = values + record_len * (klass1 * class2Count + klass2);
|
||
16 years ago
|
valueFormat1.apply_value (context, (const char *) this, v, CURPOSITION ());
|
||
|
valueFormat2.apply_value (context, (const char *) this, v + len1, POSITION (j));
|
||
16 years ago
|
|
||
|
if (len2)
|
||
|
j++;
|
||
|
buffer->in_pos = j;
|
||
|
|
||
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
|
||
16 years ago
|
private:
|
||
|
USHORT format; /* Format identifier--format = 2 */
|
||
|
OffsetTo<Coverage>
|
||
|
coverage; /* Offset to Coverage table--from
|
||
|
* beginning of subtable */
|
||
16 years ago
|
ValueFormat valueFormat1; /* ValueRecord definition--for the
|
||
16 years ago
|
* first glyph of the pair--may be zero
|
||
|
* (0) */
|
||
16 years ago
|
ValueFormat valueFormat2; /* ValueRecord definition--for the
|
||
16 years ago
|
* second glyph of the pair--may be
|
||
|
* zero (0) */
|
||
|
OffsetTo<ClassDef>
|
||
|
classDef1; /* Offset to ClassDef table--from
|
||
|
* beginning of PairPos subtable--for
|
||
|
* the first glyph of the pair */
|
||
|
OffsetTo<ClassDef>
|
||
|
classDef2; /* Offset to ClassDef table--from
|
||
|
* beginning of PairPos subtable--for
|
||
|
* the second glyph of the pair */
|
||
|
USHORT class1Count; /* Number of classes in ClassDef1
|
||
|
* table--includes Class0 */
|
||
|
USHORT class2Count; /* Number of classes in ClassDef2
|
||
|
* table--includes Class0 */
|
||
|
ValueRecord values; /* Matrix of value pairs:
|
||
|
* class1-major, class2-minor,
|
||
|
* Each entry has value1 and value2 */
|
||
|
};
|
||
|
ASSERT_SIZE (PairPosFormat2, 16);
|
||
|
|
||
16 years ago
|
struct PairPos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
|
case 2: return u.format2->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
PairPosFormat1 format1[];
|
||
|
PairPosFormat2 format2[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (PairPos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct EntryExitRecord
|
||
|
{
|
||
16 years ago
|
OffsetTo<Anchor>
|
||
|
entryAnchor; /* Offset to EntryAnchor table--from
|
||
|
* beginning of CursivePos
|
||
|
* subtable--may be NULL */
|
||
|
OffsetTo<Anchor>
|
||
|
exitAnchor; /* Offset to ExitAnchor table--from
|
||
|
* beginning of CursivePos
|
||
|
* subtable--may be NULL */
|
||
|
};
|
||
|
ASSERT_SIZE (EntryExitRecord, 4);
|
||
|
|
||
16 years ago
|
struct CursivePosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct CursivePos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
|
/* Now comes the messiest part of the whole OpenType
|
||
|
specification. At first glance, cursive connections seem easy
|
||
|
to understand, but there are pitfalls! The reason is that
|
||
|
the specs don't mention how to compute the advance values
|
||
|
resp. glyph offsets. I was told it would be an omission, to
|
||
|
be fixed in the next OpenType version... Again many thanks to
|
||
|
Andrei Burago <andreib@microsoft.com> for clarifications.
|
||
|
|
||
|
Consider the following example:
|
||
|
|
||
|
| xadv1 |
|
||
|
+---------+
|
||
|
| |
|
||
|
+-----+--+ 1 |
|
||
|
| | .| |
|
||
|
| 0+--+------+
|
||
|
| 2 |
|
||
|
| |
|
||
|
0+--------+
|
||
|
| xadv2 |
|
||
|
|
||
|
glyph1: advance width = 12
|
||
|
anchor point = (3,1)
|
||
|
|
||
|
glyph2: advance width = 11
|
||
|
anchor point = (9,4)
|
||
|
|
||
|
LSB is 1 for both glyphs (so the boxes drawn above are glyph
|
||
|
bboxes). Writing direction is R2L; `0' denotes the glyph's
|
||
|
coordinate origin.
|
||
|
|
||
|
Now the surprising part: The advance width of the *left* glyph
|
||
|
(resp. of the *bottom* glyph) will be modified, no matter
|
||
|
whether the writing direction is L2R or R2L (resp. T2B or
|
||
|
B2T)! This assymetry is caused by the fact that the glyph's
|
||
|
coordinate origin is always the lower left corner for all
|
||
|
writing directions.
|
||
|
|
||
|
Continuing the above example, we can compute the new
|
||
|
(horizontal) advance width of glyph2 as
|
||
|
|
||
|
9 - 3 = 6 ,
|
||
|
|
||
|
and the new vertical offset of glyph2 as
|
||
|
|
||
|
1 - 4 = -3 .
|
||
|
|
||
|
|
||
|
Vertical writing direction is far more complicated:
|
||
|
|
||
|
a) Assuming that we recompute the advance height of the lower glyph:
|
||
|
|
||
|
--
|
||
|
+---------+
|
||
|
-- | |
|
||
|
+-----+--+ 1 | yadv1
|
||
|
| | .| |
|
||
|
yadv2 | 0+--+------+ -- BSB1 --
|
||
|
| 2 | -- -- y_offset
|
||
|
| |
|
||
|
BSB2 -- 0+--------+ --
|
||
|
-- --
|
||
|
|
||
|
glyph1: advance height = 6
|
||
|
anchor point = (3,1)
|
||
|
|
||
|
glyph2: advance height = 7
|
||
|
anchor point = (9,4)
|
||
|
|
||
|
TSB is 1 for both glyphs; writing direction is T2B.
|
||
|
|
||
|
|
||
|
BSB1 = yadv1 - (TSB1 + ymax1)
|
||
|
BSB2 = yadv2 - (TSB2 + ymax2)
|
||
|
y_offset = y2 - y1
|
||
|
|
||
|
vertical advance width of glyph2
|
||
|
= y_offset + BSB2 - BSB1
|
||
|
= (y2 - y1) + (yadv2 - (TSB2 + ymax2)) - (yadv1 - (TSB1 + ymax1))
|
||
|
= y2 - y1 + yadv2 - TSB2 - ymax2 - (yadv1 - TSB1 - ymax1)
|
||
|
= y2 - y1 + yadv2 - TSB2 - ymax2 - yadv1 + TSB1 + ymax1
|
||
|
|
||
|
|
||
|
b) Assuming that we recompute the advance height of the upper glyph:
|
||
|
|
||
|
-- --
|
||
|
+---------+ -- TSB1
|
||
|
-- -- | |
|
||
|
TSB2 -- +-----+--+ 1 | yadv1 ymax1
|
||
|
| | .| |
|
||
|
yadv2 | 0+--+------+ -- --
|
||
|
ymax2 | 2 | -- y_offset
|
||
|
| |
|
||
|
-- 0+--------+ --
|
||
|
--
|
||
|
|
||
|
glyph1: advance height = 6
|
||
|
anchor point = (3,1)
|
||
|
|
||
|
glyph2: advance height = 7
|
||
|
anchor point = (9,4)
|
||
|
|
||
|
TSB is 1 for both glyphs; writing direction is T2B.
|
||
|
|
||
|
y_offset = y2 - y1
|
||
|
|
||
|
vertical advance width of glyph2
|
||
|
= TSB1 + ymax1 + y_offset - (TSB2 + ymax2)
|
||
|
= TSB1 + ymax1 + y2 - y1 - TSB2 - ymax2
|
||
|
|
||
|
|
||
|
Comparing a) with b) shows that b) is easier to compute. I'll wait
|
||
|
for a reply from Andrei to see what should really be implemented...
|
||
|
|
||
|
Since horizontal advance widths or vertical advance heights
|
||
|
can be used alone but not together, no ambiguity occurs. */
|
||
|
|
||
16 years ago
|
struct hb_ot_layout_context_t::info_t::gpos_t *gpi = &context->info.gpos;
|
||
16 years ago
|
hb_codepoint_t last_pos = gpi->last;
|
||
16 years ago
|
gpi->last = HB_OT_LAYOUT_GPOS_NO_LAST;
|
||
16 years ago
|
|
||
|
/* We don't handle mark glyphs here. */
|
||
|
if (property == HB_OT_LAYOUT_GLYPH_CLASS_MARK)
|
||
|
return false;
|
||
|
|
||
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
16 years ago
|
const EntryExitRecord &record = entryExitRecord[index];
|
||
|
|
||
16 years ago
|
if (last_pos == HB_OT_LAYOUT_GPOS_NO_LAST || !record.entryAnchor)
|
||
16 years ago
|
goto end;
|
||
|
|
||
16 years ago
|
hb_position_t entry_x, entry_y;
|
||
16 years ago
|
(this+record.entryAnchor).get_anchor (context, IN_CURGLYPH (), &entry_x, &entry_y);
|
||
16 years ago
|
|
||
16 years ago
|
/* TODO vertical */
|
||
|
|
||
16 years ago
|
if (buffer->direction == HB_DIRECTION_RTL)
|
||
16 years ago
|
{
|
||
|
POSITION (buffer->in_pos)->x_advance = entry_x - gpi->anchor_x;
|
||
|
POSITION (buffer->in_pos)->new_advance = TRUE;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
16 years ago
|
POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x;
|
||
|
POSITION (last_pos)->new_advance = TRUE;
|
||
16 years ago
|
}
|
||
|
|
||
|
if (lookup_flag & LookupFlag::RightToLeft)
|
||
|
{
|
||
16 years ago
|
POSITION (last_pos)->cursive_chain = last_pos - buffer->in_pos;
|
||
|
POSITION (last_pos)->y_pos = entry_y - gpi->anchor_y;
|
||
16 years ago
|
}
|
||
|
else
|
||
|
{
|
||
16 years ago
|
POSITION (buffer->in_pos)->cursive_chain = buffer->in_pos - last_pos;
|
||
16 years ago
|
POSITION (buffer->in_pos)->y_pos = gpi->anchor_y - entry_y;
|
||
|
}
|
||
|
|
||
|
end:
|
||
|
if (record.exitAnchor)
|
||
16 years ago
|
{
|
||
|
gpi->last = buffer->in_pos;
|
||
16 years ago
|
(this+record.exitAnchor).get_anchor (context, IN_CURGLYPH (), &gpi->anchor_x, &gpi->anchor_y);
|
||
16 years ago
|
}
|
||
16 years ago
|
|
||
|
buffer->in_pos++;
|
||
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
|
OffsetTo<Coverage>
|
||
|
coverage; /* Offset to Coverage table--from
|
||
|
* beginning of subtable */
|
||
|
ArrayOf<EntryExitRecord>
|
||
|
entryExitRecord; /* Array of EntryExit records--in
|
||
|
* Coverage Index order */
|
||
|
};
|
||
|
ASSERT_SIZE (CursivePosFormat1, 6);
|
||
|
|
||
16 years ago
|
struct CursivePos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
CursivePosFormat1 format1[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (CursivePos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct BaseArray
|
||
|
{
|
||
16 years ago
|
friend struct MarkBasePosFormat1;
|
||
16 years ago
|
|
||
|
private:
|
||
16 years ago
|
USHORT len; /* Number of rows */
|
||
|
OffsetTo<Anchor>
|
||
|
matrix[]; /* Matrix of offsets to Anchor tables--
|
||
|
* from beginning of BaseArray table--
|
||
|
* base-major--in order of
|
||
|
* BaseCoverage Index--, mark-minor--
|
||
|
* ordered by class--zero-based. */
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (BaseArray, 2);
|
||
|
|
||
16 years ago
|
struct MarkBasePosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct MarkBasePos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (mark_index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
/* now we search backwards for a non-mark glyph */
|
||
|
unsigned int count = buffer->in_pos;
|
||
|
unsigned int i = 1, j = count - 1;
|
||
16 years ago
|
while (_hb_ot_layout_skip_mark (context->layout, IN_INFO (j), LookupFlag::IgnoreMarks, &property))
|
||
16 years ago
|
{
|
||
16 years ago
|
if (HB_UNLIKELY (i == count))
|
||
|
return false;
|
||
16 years ago
|
i++, j--;
|
||
|
}
|
||
16 years ago
|
#if 0
|
||
16 years ago
|
/* The following assertion is too strong. */
|
||
|
if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
|
||
16 years ago
|
return false;
|
||
16 years ago
|
#endif
|
||
16 years ago
|
|
||
|
unsigned int base_index = (this+baseCoverage) (IN_GLYPH (j));
|
||
16 years ago
|
if (base_index == NOT_COVERED)
|
||
16 years ago
|
return false;
|
||
|
|
||
|
const MarkArray& mark_array = this+markArray;
|
||
|
const BaseArray& base_array = this+baseArray;
|
||
|
|
||
|
unsigned int mark_class = mark_array.get_class (mark_index);
|
||
|
const Anchor& mark_anchor = mark_array.get_anchor (mark_index);
|
||
|
|
||
|
if (HB_UNLIKELY (mark_class >= classCount || base_index >= base_array.len))
|
||
|
return false;
|
||
|
|
||
|
hb_position_t mark_x, mark_y, base_x, base_y;
|
||
|
|
||
16 years ago
|
mark_anchor.get_anchor (context, IN_CURGLYPH (), &mark_x, &mark_y);
|
||
16 years ago
|
unsigned int index = base_index * classCount + mark_class;
|
||
16 years ago
|
(&base_array+base_array.matrix[index]).get_anchor (context, IN_GLYPH (j), &base_x, &base_y);
|
||
16 years ago
|
|
||
16 years ago
|
hb_internal_glyph_position_t *o = POSITION (buffer->in_pos);
|
||
16 years ago
|
o->x_pos = base_x - mark_x;
|
||
|
o->y_pos = base_y - mark_y;
|
||
|
o->x_advance = 0;
|
||
|
o->y_advance = 0;
|
||
|
o->back = i;
|
||
|
|
||
|
buffer->in_pos++;
|
||
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
markCoverage; /* Offset to MarkCoverage table--from
|
||
16 years ago
|
* beginning of MarkBasePos subtable */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
baseCoverage; /* Offset to BaseCoverage table--from
|
||
16 years ago
|
* beginning of MarkBasePos subtable */
|
||
|
USHORT classCount; /* Number of classes defined for marks */
|
||
16 years ago
|
OffsetTo<MarkArray>
|
||
|
markArray; /* Offset to MarkArray table--from
|
||
16 years ago
|
* beginning of MarkBasePos subtable */
|
||
16 years ago
|
OffsetTo<BaseArray>
|
||
|
baseArray; /* Offset to BaseArray table--from
|
||
16 years ago
|
* beginning of MarkBasePos subtable */
|
||
|
};
|
||
|
ASSERT_SIZE (MarkBasePosFormat1, 12);
|
||
|
|
||
16 years ago
|
struct MarkBasePos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
MarkBasePosFormat1 format1[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (MarkBasePos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct LigatureAttach
|
||
|
{
|
||
16 years ago
|
friend struct MarkLigPosFormat1;
|
||
16 years ago
|
|
||
|
private:
|
||
16 years ago
|
USHORT len; /* Number of ComponentRecords in this
|
||
|
* ligature, ie. number of rows */
|
||
|
OffsetTo<Anchor>
|
||
|
matrix[]; /* Matrix of offsets to Anchor tables--
|
||
|
* from beginning of LigatureAttach table--
|
||
|
* component-major--in order of
|
||
|
* writing direction--, mark-minor--
|
||
|
* ordered by class--zero-based. */
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (LigatureAttach, 2);
|
||
|
|
||
16 years ago
|
typedef OffsetArrayOf<LigatureAttach> LigatureArray;
|
||
|
/* Array of LigatureAttach
|
||
16 years ago
|
* tables ordered by
|
||
|
* LigatureCoverage Index */
|
||
|
ASSERT_SIZE (LigatureArray, 2);
|
||
|
|
||
16 years ago
|
struct MarkLigPosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct MarkLigPos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (mark_index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
/* now we search backwards for a non-mark glyph */
|
||
|
unsigned int count = buffer->in_pos;
|
||
|
unsigned int i = 1, j = count - 1;
|
||
16 years ago
|
while (_hb_ot_layout_skip_mark (context->layout, IN_INFO (j), LookupFlag::IgnoreMarks, &property))
|
||
16 years ago
|
{
|
||
16 years ago
|
if (HB_UNLIKELY (i == count))
|
||
|
return false;
|
||
16 years ago
|
i++, j--;
|
||
|
}
|
||
|
#if 0
|
||
16 years ago
|
/* The following assertion is too strong. */
|
||
|
if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
|
||
16 years ago
|
return false;
|
||
|
#endif
|
||
|
|
||
|
unsigned int lig_index = (this+ligatureCoverage) (IN_GLYPH (j));
|
||
|
if (lig_index == NOT_COVERED)
|
||
|
return false;
|
||
|
|
||
|
const MarkArray& mark_array = this+markArray;
|
||
|
const LigatureArray& lig_array = this+ligatureArray;
|
||
|
|
||
|
unsigned int mark_class = mark_array.get_class (mark_index);
|
||
|
const Anchor& mark_anchor = mark_array.get_anchor (mark_index);
|
||
|
|
||
|
if (HB_UNLIKELY (mark_class >= classCount || lig_index >= lig_array.len))
|
||
|
return false;
|
||
|
|
||
|
const LigatureAttach& lig_attach = &lig_array+lig_array[lig_index];
|
||
|
count = lig_attach.len;
|
||
|
if (HB_UNLIKELY (!count))
|
||
|
return false;
|
||
|
|
||
|
unsigned int comp_index;
|
||
|
/* We must now check whether the ligature ID of the current mark glyph
|
||
|
* 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 (IN_LIGID (j) == IN_LIGID (buffer->in_pos))
|
||
|
{
|
||
|
comp_index = IN_COMPONENT (buffer->in_pos);
|
||
|
if (comp_index >= count)
|
||
|
comp_index = count - 1;
|
||
|
}
|
||
|
else
|
||
|
comp_index = count - 1;
|
||
|
|
||
|
hb_position_t mark_x, mark_y, lig_x, lig_y;
|
||
|
|
||
16 years ago
|
mark_anchor.get_anchor (context, IN_CURGLYPH (), &mark_x, &mark_y);
|
||
16 years ago
|
unsigned int index = comp_index * classCount + mark_class;
|
||
16 years ago
|
(&lig_attach+lig_attach.matrix[index]).get_anchor (context, IN_GLYPH (j), &lig_x, &lig_y);
|
||
16 years ago
|
|
||
16 years ago
|
hb_internal_glyph_position_t *o = POSITION (buffer->in_pos);
|
||
16 years ago
|
o->x_pos = lig_x - mark_x;
|
||
|
o->y_pos = lig_y - mark_y;
|
||
|
o->x_advance = 0;
|
||
|
o->y_advance = 0;
|
||
|
o->back = i;
|
||
|
|
||
|
buffer->in_pos++;
|
||
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
markCoverage; /* Offset to Mark Coverage table--from
|
||
16 years ago
|
* beginning of MarkLigPos subtable */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
ligatureCoverage; /* Offset to Ligature Coverage
|
||
16 years ago
|
* table--from beginning of MarkLigPos
|
||
|
* subtable */
|
||
|
USHORT classCount; /* Number of defined mark classes */
|
||
16 years ago
|
OffsetTo<MarkArray>
|
||
|
markArray; /* Offset to MarkArray table--from
|
||
16 years ago
|
* beginning of MarkLigPos subtable */
|
||
16 years ago
|
OffsetTo<LigatureArray>
|
||
|
ligatureArray; /* Offset to LigatureArray table--from
|
||
16 years ago
|
* beginning of MarkLigPos subtable */
|
||
|
};
|
||
|
ASSERT_SIZE (MarkLigPosFormat1, 12);
|
||
|
|
||
16 years ago
|
struct MarkLigPos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
MarkLigPosFormat1 format1[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (MarkLigPos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct Mark2Array
|
||
|
{
|
||
16 years ago
|
friend struct MarkMarkPosFormat1;
|
||
16 years ago
|
|
||
|
private:
|
||
16 years ago
|
USHORT len; /* Number of rows */
|
||
|
OffsetTo<Anchor>
|
||
|
matrix[]; /* Matrix of offsets to Anchor tables--
|
||
|
* from beginning of Mark2Array table--
|
||
|
* mark2-major--in order of
|
||
|
* Mark2Coverage Index--, mark1-minor--
|
||
|
* ordered by class--zero-based. */
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (Mark2Array, 2);
|
||
|
|
||
16 years ago
|
struct MarkMarkPosFormat1
|
||
|
{
|
||
16 years ago
|
friend struct MarkMarkPos;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
unsigned int mark1_index = (this+mark1Coverage) (IN_CURGLYPH ());
|
||
|
if (HB_LIKELY (mark1_index == NOT_COVERED))
|
||
|
return false;
|
||
|
|
||
|
/* now we search backwards for a suitable mark glyph until a non-mark glyph */
|
||
|
unsigned int count = buffer->in_pos;
|
||
|
unsigned int i = 1, j = count - 1;
|
||
16 years ago
|
while (_hb_ot_layout_skip_mark (context->layout, IN_INFO (j), lookup_flag, &property))
|
||
16 years ago
|
{
|
||
16 years ago
|
if (HB_UNLIKELY (i == count))
|
||
|
return false;
|
||
16 years ago
|
i++, j--;
|
||
|
}
|
||
16 years ago
|
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. */
|
||
|
if (IN_LIGID (j) != IN_LIGID (buffer->in_pos) ||
|
||
|
IN_COMPONENT (j) != IN_COMPONENT (buffer->in_pos))
|
||
16 years ago
|
return false;
|
||
|
|
||
|
unsigned int mark2_index = (this+mark2Coverage) (IN_GLYPH (j));
|
||
|
if (mark2_index == NOT_COVERED)
|
||
|
return false;
|
||
|
|
||
|
const MarkArray& mark1_array = this+mark1Array;
|
||
|
const Mark2Array& mark2_array = this+mark2Array;
|
||
|
|
||
|
unsigned int mark1_class = mark1_array.get_class (mark1_index);
|
||
|
const Anchor& mark1_anchor = mark1_array.get_anchor (mark1_index);
|
||
|
|
||
|
if (HB_UNLIKELY (mark1_class >= classCount || mark2_index >= mark2_array.len))
|
||
|
return false;
|
||
|
|
||
|
hb_position_t mark1_x, mark1_y, mark2_x, mark2_y;
|
||
|
|
||
16 years ago
|
mark1_anchor.get_anchor (context, IN_CURGLYPH (), &mark1_x, &mark1_y);
|
||
16 years ago
|
unsigned int index = mark2_index * classCount + mark1_class;
|
||
16 years ago
|
(&mark2_array+mark2_array.matrix[index]).get_anchor (context, IN_GLYPH (j), &mark2_x, &mark2_y);
|
||
16 years ago
|
|
||
16 years ago
|
hb_internal_glyph_position_t *o = POSITION (buffer->in_pos);
|
||
16 years ago
|
o->x_pos = mark2_x - mark1_x;
|
||
|
o->y_pos = mark2_y - mark1_y;
|
||
|
o->x_advance = 0;
|
||
|
o->y_advance = 0;
|
||
|
o->back = i;
|
||
|
|
||
|
buffer->in_pos++;
|
||
|
return true;
|
||
16 years ago
|
}
|
||
|
|
||
|
private:
|
||
|
USHORT format; /* Format identifier--format = 1 */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
mark1Coverage; /* Offset to Combining Mark1 Coverage
|
||
16 years ago
|
* table--from beginning of MarkMarkPos
|
||
|
* subtable */
|
||
16 years ago
|
OffsetTo<Coverage>
|
||
|
mark2Coverage; /* Offset to Combining Mark2 Coverage
|
||
16 years ago
|
* table--from beginning of MarkMarkPos
|
||
|
* subtable */
|
||
16 years ago
|
USHORT classCount; /* Number of defined mark classes */
|
||
|
OffsetTo<MarkArray>
|
||
|
mark1Array; /* Offset to Mark1Array table--from
|
||
|
* beginning of MarkMarkPos subtable */
|
||
|
OffsetTo<Mark2Array>
|
||
|
mark2Array; /* Offset to Mark2Array table--from
|
||
|
* beginning of MarkMarkPos subtable */
|
||
16 years ago
|
};
|
||
16 years ago
|
ASSERT_SIZE (MarkMarkPosFormat1, 12);
|
||
16 years ago
|
|
||
16 years ago
|
struct MarkMarkPos
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
|
{
|
||
16 years ago
|
switch (u.format) {
|
||
16 years ago
|
case 1: return u.format1->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
USHORT format; /* Format identifier */
|
||
|
MarkMarkPosFormat1 format1[];
|
||
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (MarkMarkPos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index);
|
||
16 years ago
|
|
||
16 years ago
|
struct ContextPos : Context
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
16 years ago
|
{ return Context::apply (APPLY_ARG, position_lookup); }
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (ContextPos, 2);
|
||
|
|
||
16 years ago
|
struct ChainContextPos : ChainContext
|
||
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const
|
||
16 years ago
|
{ return ChainContext::apply (APPLY_ARG, position_lookup); }
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (ChainContextPos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct ExtensionPos : Extension
|
||
16 years ago
|
{
|
||
16 years ago
|
friend struct PosLookupSubTable;
|
||
|
|
||
|
private:
|
||
16 years ago
|
inline bool apply (APPLY_ARG_DEF) const;
|
||
16 years ago
|
};
|
||
|
ASSERT_SIZE (ExtensionPos, 2);
|
||
|
|
||
|
|
||
16 years ago
|
|
||
16 years ago
|
/*
|
||
|
* PosLookup
|
||
|
*/
|
||
|
|
||
|
|
||
16 years ago
|
struct PosLookupSubTable
|
||
|
{
|
||
16 years ago
|
friend struct PosLookup;
|
||
|
|
||
16 years ago
|
enum {
|
||
|
Single = 1,
|
||
|
Pair = 2,
|
||
|
Cursive = 3,
|
||
|
MarkBase = 4,
|
||
|
MarkLig = 5,
|
||
|
MarkMark = 6,
|
||
|
Context = 7,
|
||
|
ChainContext = 8,
|
||
|
Extension = 9,
|
||
|
};
|
||
|
|
||
16 years ago
|
bool apply (APPLY_ARG_DEF, unsigned int lookup_type) const
|
||
16 years ago
|
{
|
||
16 years ago
|
switch (lookup_type) {
|
||
16 years ago
|
case Single: return u.single->apply (APPLY_ARG);
|
||
|
case Pair: return u.pair->apply (APPLY_ARG);
|
||
|
case Cursive: return u.cursive->apply (APPLY_ARG);
|
||
|
case MarkBase: return u.markBase->apply (APPLY_ARG);
|
||
|
case MarkLig: return u.markLig->apply (APPLY_ARG);
|
||
|
case MarkMark: return u.markMark->apply (APPLY_ARG);
|
||
|
case Context: return u.context->apply (APPLY_ARG);
|
||
|
case ChainContext: return u.chainContext->apply (APPLY_ARG);
|
||
|
case Extension: return u.extension->apply (APPLY_ARG);
|
||
16 years ago
|
default:return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
union {
|
||
16 years ago
|
USHORT format;
|
||
|
SinglePos single[];
|
||
|
PairPos pair[];
|
||
|
CursivePos cursive[];
|
||
|
MarkBasePos markBase[];
|
||
|
MarkLigPos markLig[];
|
||
|
MarkMarkPos markMark[];
|
||
|
ContextPos context[];
|
||
|
ChainContextPos chainContext[];
|
||
|
ExtensionPos extension[];
|
||
16 years ago
|
} u;
|
||
|
};
|
||
|
ASSERT_SIZE (PosLookupSubTable, 2);
|
||
|
|
||
|
|
||
16 years ago
|
struct PosLookup : Lookup
|
||
|
{
|
||
|
inline const PosLookupSubTable& get_subtable (unsigned int i) const
|
||
16 years ago
|
{ return (const PosLookupSubTable&) Lookup::get_subtable (i); }
|
||
16 years ago
|
|
||
|
/* Like get_type(), but looks through extension lookups.
|
||
|
* Never returns Extension */
|
||
16 years ago
|
inline unsigned int get_effective_type (void) const
|
||
|
{
|
||
16 years ago
|
unsigned int type = get_type ();
|
||
|
|
||
16 years ago
|
if (HB_UNLIKELY (type == PosLookupSubTable::Extension))
|
||
16 years ago
|
{
|
||
16 years ago
|
unsigned int count = get_subtable_count ();
|
||
|
type = get_subtable(0).u.extension->get_type ();
|
||
|
/* The spec says all subtables should have the same type.
|
||
|
* This is specially important if one has a reverse type! */
|
||
|
for (unsigned int i = 1; i < count; i++)
|
||
|
if (get_subtable(i).u.extension->get_type () != type)
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
return type;
|
||
|
}
|
||
|
|
||
16 years ago
|
inline bool apply_once (hb_ot_layout_context_t *context,
|
||
16 years ago
|
hb_buffer_t *buffer,
|
||
|
unsigned int context_length,
|
||
|
unsigned int nesting_level_left) const
|
||
16 years ago
|
{
|
||
16 years ago
|
unsigned int lookup_type = get_type ();
|
||
|
unsigned int lookup_flag = get_flag ();
|
||
16 years ago
|
unsigned int property;
|
||
|
|
||
16 years ago
|
if (!_hb_ot_layout_check_glyph_property (context->layout, IN_CURINFO (), lookup_flag, &property))
|
||
16 years ago
|
return false;
|
||
16 years ago
|
|
||
|
for (unsigned int i = 0; i < get_subtable_count (); i++)
|
||
16 years ago
|
if (get_subtable (i).apply (APPLY_ARG, lookup_type))
|
||
16 years ago
|
return true;
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
16 years ago
|
bool apply_string (hb_ot_layout_context_t *context,
|
||
16 years ago
|
hb_buffer_t *buffer,
|
||
16 years ago
|
hb_ot_layout_feature_mask_t mask) const
|
||
|
{
|
||
16 years ago
|
bool ret = false;
|
||
|
|
||
|
if (HB_UNLIKELY (!buffer->in_length))
|
||
|
return false;
|
||
|
|
||
16 years ago
|
context->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST; /* no last valid glyph for cursive pos. */
|
||
16 years ago
|
|
||
16 years ago
|
buffer->in_pos = 0;
|
||
16 years ago
|
while (buffer->in_pos < buffer->in_length)
|
||
|
{
|
||
16 years ago
|
bool done;
|
||
16 years ago
|
if (~IN_PROPERTIES (buffer->in_pos) & mask)
|
||
|
{
|
||
16 years ago
|
done = apply_once (context, buffer, NO_CONTEXT, MAX_NESTING_LEVEL);
|
||
16 years ago
|
ret |= done;
|
||
16 years ago
|
}
|
||
|
else
|
||
|
{
|
||
16 years ago
|
done = false;
|
||
|
/* Contrary to properties defined in GDEF, user-defined properties
|
||
|
will always stop a possible cursive positioning. */
|
||
16 years ago
|
context->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST;
|
||
16 years ago
|
}
|
||
|
|
||
|
if (!done)
|
||
|
buffer->in_pos++;
|
||
16 years ago
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
};
|
||
|
ASSERT_SIZE (PosLookup, 6);
|
||
|
|
||
|
|
||
|
/*
|
||
|
* GPOS
|
||
|
*/
|
||
|
|
||
16 years ago
|
struct GPOS : GSUBGPOS
|
||
|
{
|
||
16 years ago
|
static const hb_tag_t Tag = HB_TAG ('G','P','O','S');
|
||
|
|
||
16 years ago
|
static inline const GPOS& get_for_data (const char *data)
|
||
16 years ago
|
{ return (const GPOS&) GSUBGPOS::get_for_data (data); }
|
||
16 years ago
|
|
||
16 years ago
|
inline const PosLookup& get_lookup (unsigned int i) const
|
||
16 years ago
|
{ return (const PosLookup&) GSUBGPOS::get_lookup (i); }
|
||
16 years ago
|
|
||
16 years ago
|
inline bool position_lookup (hb_ot_layout_context_t *context,
|
||
16 years ago
|
hb_buffer_t *buffer,
|
||
|
unsigned int lookup_index,
|
||
16 years ago
|
hb_ot_layout_feature_mask_t mask) const
|
||
16 years ago
|
{ return get_lookup (lookup_index).apply_string (context, buffer, mask); }
|
||
16 years ago
|
|
||
|
};
|
||
|
ASSERT_SIZE (GPOS, 10);
|
||
|
|
||
|
|
||
|
/* Out-of-class implementation for methods recursing */
|
||
|
|
||
16 years ago
|
inline bool ExtensionPos::apply (APPLY_ARG_DEF) const
|
||
16 years ago
|
{
|
||
16 years ago
|
unsigned int lookup_type = get_type ();
|
||
|
|
||
16 years ago
|
if (HB_UNLIKELY (lookup_type == PosLookupSubTable::Extension))
|
||
16 years ago
|
return false;
|
||
|
|
||
16 years ago
|
return ((PosLookupSubTable&) get_subtable ()).apply (APPLY_ARG, lookup_type);
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index)
|
||
|
{
|
||
16 years ago
|
const GPOS &gpos = *(context->layout->gpos);
|
||
16 years ago
|
const PosLookup &l = gpos.get_lookup (lookup_index);
|
||
|
|
||
|
if (HB_UNLIKELY (nesting_level_left == 0))
|
||
|
return false;
|
||
|
nesting_level_left--;
|
||
|
|
||
|
if (HB_UNLIKELY (context_length < 1))
|
||
|
return false;
|
||
|
|
||
16 years ago
|
return l.apply_once (context, buffer, context_length, nesting_level_left);
|
||
16 years ago
|
}
|
||
|
|
||
|
|
||
16 years ago
|
#endif /* HB_OT_LAYOUT_GPOS_PRIVATE_HH */
|