2009-05-18 21:09:33 +00:00
|
|
|
/*
|
2010-05-06 16:55:14 +00:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Red Hat, Inc.
|
2009-05-18 21:09:33 +00:00
|
|
|
*
|
2010-04-22 04:11:43 +00:00
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
2009-05-18 21:09:33 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-08-03 00:03:12 +00:00
|
|
|
#ifndef HB_OT_LAYOUT_GPOS_PRIVATE_HH
|
|
|
|
#define HB_OT_LAYOUT_GPOS_PRIVATE_HH
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-08-03 00:03:12 +00:00
|
|
|
#include "hb-ot-layout-gsubgpos-private.hh"
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
|
|
|
|
#undef BUFFER
|
|
|
|
#define BUFFER context->buffer
|
|
|
|
|
|
|
|
|
2009-05-25 08:04:24 +00:00
|
|
|
#define HB_OT_LAYOUT_GPOS_NO_LAST ((unsigned int) -1)
|
2009-05-18 21:09:33 +00:00
|
|
|
|
|
|
|
/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
|
|
|
|
|
2010-05-06 17:06:15 +00:00
|
|
|
typedef USHORT Value;
|
2009-08-26 22:53:43 +00:00
|
|
|
|
2010-05-10 23:01:17 +00:00
|
|
|
typedef Value ValueRecord[VAR];
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct ValueFormat : USHORT
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
2009-05-18 23:47:52 +00:00
|
|
|
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 */
|
2009-05-26 19:38:53 +00:00
|
|
|
ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */
|
2010-03-29 04:04:12 +00:00
|
|
|
reserved = 0xF000, /* For future use */
|
2009-05-18 23:47:52 +00:00
|
|
|
|
2010-03-29 04:04:12 +00:00
|
|
|
devices = 0x00F0 /* Mask for having any Device table */
|
2010-04-21 06:02:57 +00:00
|
|
|
};
|
2009-05-21 08:49:04 +00:00
|
|
|
|
2010-04-21 06:02:57 +00:00
|
|
|
/* All fields are options. Only those available advance the value pointer. */
|
2009-05-21 08:49:04 +00:00
|
|
|
#if 0
|
|
|
|
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
|
2009-05-18 23:47:52 +00:00
|
|
|
|
2010-04-21 06:02:57 +00:00
|
|
|
inline unsigned int get_len () const
|
|
|
|
{ return _hb_popcount32 ((unsigned int) *this); }
|
|
|
|
inline unsigned int get_size () const
|
2010-05-06 23:33:31 +00:00
|
|
|
{ return get_len () * Value::static_size; }
|
2010-04-21 06:02:57 +00:00
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
void apply_value (hb_ot_layout_context_t *layout,
|
2010-05-10 21:47:22 +00:00
|
|
|
const void *base,
|
2010-04-21 06:02:57 +00:00
|
|
|
const Value *values,
|
|
|
|
hb_internal_glyph_position_t *glyph_pos) const
|
|
|
|
{
|
|
|
|
unsigned int x_ppem, y_ppem;
|
|
|
|
hb_16dot16_t x_scale, y_scale;
|
|
|
|
unsigned int format = *this;
|
|
|
|
|
|
|
|
if (!format) return;
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
x_scale = layout->font->x_scale;
|
|
|
|
y_scale = layout->font->y_scale;
|
2009-05-18 23:47:52 +00:00
|
|
|
/* design units -> fractional pixel */
|
2010-05-06 17:06:15 +00:00
|
|
|
if (format & xPlacement) glyph_pos->x_offset += _hb_16dot16_mul_round (x_scale, get_short (values++));
|
|
|
|
if (format & yPlacement) glyph_pos->y_offset += _hb_16dot16_mul_round (y_scale, get_short (values++));
|
|
|
|
if (format & xAdvance) glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, get_short (values++));
|
|
|
|
if (format & yAdvance) glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, get_short (values++));
|
2009-05-18 23:47:52 +00:00
|
|
|
|
2010-04-29 18:31:56 +00:00
|
|
|
if (!has_device ()) return;
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
x_ppem = layout->font->x_ppem;
|
|
|
|
y_ppem = layout->font->y_ppem;
|
2010-04-29 18:31:56 +00:00
|
|
|
|
|
|
|
if (!x_ppem && !y_ppem) return;
|
|
|
|
|
2009-07-30 20:28:45 +00:00
|
|
|
/* pixel -> fractional pixel */
|
|
|
|
if (format & xPlaDevice) {
|
2010-05-06 17:06:15 +00:00
|
|
|
if (x_ppem) glyph_pos->x_offset += (base + get_device (values++)).get_delta (x_ppem) << 16; else values++;
|
2009-07-30 20:28:45 +00:00
|
|
|
}
|
|
|
|
if (format & yPlaDevice) {
|
2010-05-06 17:06:15 +00:00
|
|
|
if (y_ppem) glyph_pos->y_offset += (base + get_device (values++)).get_delta (y_ppem) << 16; else values++;
|
2009-07-30 20:28:45 +00:00
|
|
|
}
|
|
|
|
if (format & xAdvDevice) {
|
2010-05-06 17:06:15 +00:00
|
|
|
if (x_ppem) glyph_pos->x_advance += (base + get_device (values++)).get_delta (x_ppem) << 16; else values++;
|
2009-07-30 20:28:45 +00:00
|
|
|
}
|
|
|
|
if (format & yAdvDevice) {
|
2010-05-06 17:06:15 +00:00
|
|
|
if (y_ppem) glyph_pos->y_advance += (base + get_device (values++)).get_delta (y_ppem) << 16; else values++;
|
2009-05-18 23:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-21 06:02:57 +00:00
|
|
|
|
|
|
|
private:
|
2010-05-06 16:55:14 +00:00
|
|
|
inline bool sanitize_value_devices (hb_sanitize_context_t *context, void *base, Value *values) {
|
2010-04-21 06:02:57 +00:00
|
|
|
unsigned int format = *this;
|
|
|
|
|
|
|
|
if (format & xPlacement) values++;
|
|
|
|
if (format & yPlacement) values++;
|
|
|
|
if (format & xAdvance) values++;
|
|
|
|
if (format & yAdvance) values++;
|
|
|
|
|
2010-05-06 17:06:15 +00:00
|
|
|
if ((format & xPlaDevice) && !get_device (values++).sanitize (context, base)) return false;
|
|
|
|
if ((format & yPlaDevice) && !get_device (values++).sanitize (context, base)) return false;
|
|
|
|
if ((format & xAdvDevice) && !get_device (values++).sanitize (context, base)) return false;
|
|
|
|
if ((format & yAdvDevice) && !get_device (values++).sanitize (context, base)) return false;
|
2010-04-21 06:02:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-06 17:06:15 +00:00
|
|
|
static inline OffsetTo<Device>& get_device (Value* value)
|
|
|
|
{ return *CastP<OffsetTo<Device> > (value); }
|
|
|
|
static inline const OffsetTo<Device>& get_device (const Value* value)
|
|
|
|
{ return *CastP<OffsetTo<Device> > (value); }
|
|
|
|
|
|
|
|
static inline const SHORT& get_short (const Value* value)
|
|
|
|
{ return *CastP<SHORT> (value); }
|
|
|
|
|
2010-04-21 06:02:57 +00:00
|
|
|
public:
|
|
|
|
|
2010-04-29 18:31:56 +00:00
|
|
|
inline bool has_device () const {
|
2010-04-21 06:02:57 +00:00
|
|
|
unsigned int format = *this;
|
|
|
|
return (format & devices) != 0;
|
|
|
|
}
|
|
|
|
|
2010-05-06 16:55:14 +00:00
|
|
|
inline bool sanitize_value (hb_sanitize_context_t *context, void *base, Value *values) {
|
2010-04-21 06:02:57 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 14:26:52 +00:00
|
|
|
return context->check_range (values, get_size ())
|
2010-05-05 05:49:22 +00:00
|
|
|
&& (!has_device () || sanitize_value_devices (context, base, values));
|
2010-04-21 06:02:57 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 16:55:14 +00:00
|
|
|
inline bool sanitize_values (hb_sanitize_context_t *context, void *base, Value *values, unsigned int count) {
|
2010-04-21 06:02:57 +00:00
|
|
|
TRACE_SANITIZE ();
|
|
|
|
unsigned int len = get_len ();
|
|
|
|
|
2010-05-06 00:15:14 +00:00
|
|
|
if (!context->check_array (values, get_size (), count)) return false;
|
2010-04-21 06:02:57 +00:00
|
|
|
|
|
|
|
if (!has_device ()) return true;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < count; i++) {
|
2010-05-05 04:23:19 +00:00
|
|
|
if (!sanitize_value_devices (context, base, values))
|
2010-04-21 06:02:57 +00:00
|
|
|
return false;
|
|
|
|
values += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-22 17:59:39 +00:00
|
|
|
/* Just sanitize referenced Device tables. Doesn't check the values themselves. */
|
2010-05-06 16:55:14 +00:00
|
|
|
inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *context, void *base, Value *values, unsigned int count, unsigned int stride) {
|
2010-04-21 06:02:57 +00:00
|
|
|
TRACE_SANITIZE ();
|
|
|
|
|
|
|
|
if (!has_device ()) return true;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < count; i++) {
|
2010-05-05 04:23:19 +00:00
|
|
|
if (!sanitize_value_devices (context, base, values))
|
2010-04-21 06:02:57 +00:00
|
|
|
return false;
|
|
|
|
values += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct AnchorFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct Anchor;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:01:05 +00:00
|
|
|
inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id HB_UNUSED,
|
2009-05-20 02:16:04 +00:00
|
|
|
hb_position_t *x, hb_position_t *y) const
|
|
|
|
{
|
2010-05-05 05:01:05 +00:00
|
|
|
*x = _hb_16dot16_mul_round (layout->font->x_scale, xCoordinate);
|
|
|
|
*y = _hb_16dot16_mul_round (layout->font->y_scale, yCoordinate);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
|
|
|
SHORT xCoordinate; /* Horizontal value--in design units */
|
|
|
|
SHORT yCoordinate; /* Vertical value--in design units */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct AnchorFormat2
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct Anchor;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:01:05 +00:00
|
|
|
inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id,
|
2009-05-20 02:16:04 +00:00
|
|
|
hb_position_t *x, hb_position_t *y) const
|
|
|
|
{
|
2010-05-05 05:01:05 +00:00
|
|
|
unsigned int x_ppem = layout->font->x_ppem;
|
|
|
|
unsigned int y_ppem = layout->font->y_ppem;
|
2010-04-29 07:59:06 +00:00
|
|
|
hb_position_t cx, cy;
|
|
|
|
hb_bool_t ret;
|
|
|
|
|
|
|
|
if (x_ppem || y_ppem)
|
2010-05-05 05:01:05 +00:00
|
|
|
ret = hb_font_get_contour_point (layout->font, layout->face, anchorPoint, glyph_id, &cx, &cy);
|
|
|
|
*x = x_ppem && ret ? cx : _hb_16dot16_mul_round (layout->font->x_scale, xCoordinate);
|
|
|
|
*y = y_ppem && ret ? cy : _hb_16dot16_mul_round (layout->font->y_scale, yCoordinate);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
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 */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (8);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct AnchorFormat3
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct Anchor;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:01:05 +00:00
|
|
|
inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id HB_UNUSED,
|
2009-05-20 02:16:04 +00:00
|
|
|
hb_position_t *x, hb_position_t *y) const
|
|
|
|
{
|
2010-05-05 05:01:05 +00:00
|
|
|
*x = _hb_16dot16_mul_round (layout->font->x_scale, xCoordinate);
|
|
|
|
*y = _hb_16dot16_mul_round (layout->font->y_scale, yCoordinate);
|
2009-05-21 08:54:01 +00:00
|
|
|
|
2010-03-16 07:46:17 +00:00
|
|
|
/* pixel -> fractional pixel */
|
2010-05-05 05:01:05 +00:00
|
|
|
if (layout->font->x_ppem)
|
|
|
|
*x += (this+xDeviceTable).get_delta (layout->font->x_ppem) << 16;
|
|
|
|
if (layout->font->y_ppem)
|
|
|
|
*y += (this+yDeviceTable).get_delta (layout->font->y_ppem) << 16;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& xDeviceTable.sanitize (context, this)
|
|
|
|
&& yDeviceTable.sanitize (context, this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
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) */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (10);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct Anchor
|
|
|
|
{
|
2010-05-05 05:01:05 +00:00
|
|
|
inline void get_anchor (hb_ot_layout_context_t *layout, hb_codepoint_t glyph_id,
|
2009-05-20 02:16:04 +00:00
|
|
|
hb_position_t *x, hb_position_t *y) const
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
*x = *y = 0;
|
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: u.format1.get_anchor (layout, glyph_id, x, y); return;
|
|
|
|
case 2: u.format2.get_anchor (layout, glyph_id, x, y); return;
|
|
|
|
case 3: u.format3.get_anchor (layout, glyph_id, x, y); return;
|
2010-05-05 05:01:05 +00:00
|
|
|
default: return;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
|
|
|
case 2: return u.format2.sanitize (context);
|
|
|
|
case 3: return u.format3.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
AnchorFormat1 format1;
|
|
|
|
AnchorFormat2 format2;
|
|
|
|
AnchorFormat3 format3;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
2010-05-10 22:08:46 +00:00
|
|
|
public:
|
2010-05-10 22:47:48 +00:00
|
|
|
DEFINE_SIZE_UNION (2, format);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-14 22:14:03 +00:00
|
|
|
struct AnchorMatrix
|
|
|
|
{
|
|
|
|
inline const Anchor& get_anchor (unsigned int row, unsigned int col, unsigned int cols) const {
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (row >= rows || col >= cols)) return Null(Anchor);
|
2009-08-14 22:14:03 +00:00
|
|
|
return this+matrix[row * cols + col];
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context, unsigned int cols) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
if (!context->check_struct (this)) return false;
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (cols >= ((unsigned int) -1) / rows)) return false;
|
2009-08-14 22:14:03 +00:00
|
|
|
unsigned int count = rows * cols;
|
2010-05-06 23:33:31 +00:00
|
|
|
if (!context->check_array (matrix, matrix[0].static_size, count)) return false;
|
2009-08-14 22:14:03 +00:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2010-05-06 16:55:14 +00:00
|
|
|
if (!matrix[i].sanitize (context, this)) return false;
|
2009-08-14 22:14:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
USHORT rows; /* Number of rows */
|
|
|
|
private:
|
|
|
|
OffsetTo<Anchor>
|
2009-11-03 15:47:29 +00:00
|
|
|
matrix[VAR]; /* Matrix of offsets to Anchor tables--
|
2009-08-14 22:14:03 +00:00
|
|
|
* from beginning of AnchorMatrix table */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (2, matrix);
|
2009-08-14 22:14:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkRecord
|
|
|
|
{
|
2009-05-21 08:58:24 +00:00
|
|
|
friend struct MarkArray;
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& markAnchor.sanitize (context, base);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT klass; /* Class defined for this mark */
|
|
|
|
OffsetTo<Anchor>
|
|
|
|
markAnchor; /* Offset to Anchor table--from
|
|
|
|
* beginning of MarkArray table */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2010-05-10 21:28:16 +00:00
|
|
|
struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context,
|
2009-08-14 23:33:24 +00:00
|
|
|
unsigned int mark_index, unsigned int glyph_index,
|
|
|
|
const AnchorMatrix &anchors, unsigned int class_count,
|
|
|
|
unsigned int glyph_pos) const
|
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-10 21:28:16 +00:00
|
|
|
const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index);
|
2009-08-14 23:33:24 +00:00
|
|
|
unsigned int mark_class = record.klass;
|
|
|
|
|
|
|
|
const Anchor& mark_anchor = this + record.markAnchor;
|
|
|
|
const Anchor& glyph_anchor = anchors.get_anchor (glyph_index, mark_class, class_count);
|
|
|
|
|
|
|
|
hb_position_t mark_x, mark_y, base_x, base_y;
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
mark_anchor.get_anchor (context->layout, IN_CURGLYPH (), &mark_x, &mark_y);
|
|
|
|
glyph_anchor.get_anchor (context->layout, IN_GLYPH (glyph_pos), &base_x, &base_y);
|
2009-08-14 23:33:24 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
hb_internal_glyph_position_t *o = POSITION (context->buffer->in_pos);
|
2009-08-14 23:33:24 +00:00
|
|
|
o->x_advance = 0;
|
|
|
|
o->y_advance = 0;
|
2009-11-05 17:20:11 +00:00
|
|
|
o->x_offset = base_x - mark_x;
|
|
|
|
o->y_offset = base_y - mark_y;
|
2010-05-05 05:13:09 +00:00
|
|
|
o->back = context->buffer->in_pos - glyph_pos;
|
2009-08-14 23:33:24 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos++;
|
2009-08-14 23:33:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-10 21:28:16 +00:00
|
|
|
return ArrayOf<MarkRecord>::sanitize (context, this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Lookups */
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct SinglePosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct SinglePos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 02:16:04 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 23:47:52 +00:00
|
|
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index == NOT_COVERED))
|
2009-05-18 23:47:52 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-10 21:47:22 +00:00
|
|
|
valueFormat.apply_value (context->layout, this, values, CURPOSITION ());
|
2009-05-31 02:17:32 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos++;
|
2009-05-18 23:47:52 +00:00
|
|
|
return true;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& coverage.sanitize (context, this)
|
2010-05-10 21:47:22 +00:00
|
|
|
&& valueFormat.sanitize_value (context, this, values);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
|
|
|
OffsetTo<Coverage>
|
|
|
|
coverage; /* Offset to Coverage table--from
|
|
|
|
* beginning of subtable */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat; /* Defines the types of data in the
|
2009-05-18 21:09:33 +00:00
|
|
|
* ValueRecord */
|
|
|
|
ValueRecord values; /* Defines positioning
|
|
|
|
* value(s)--applied to all glyphs in
|
|
|
|
* the Coverage table */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (6, values);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct SinglePosFormat2
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct SinglePos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 02:16:04 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 23:47:52 +00:00
|
|
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index == NOT_COVERED))
|
2009-05-18 23:47:52 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index >= valueCount))
|
2009-05-18 23:47:52 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-10 21:47:22 +00:00
|
|
|
valueFormat.apply_value (context->layout, this,
|
2010-03-16 07:46:17 +00:00
|
|
|
&values[index * valueFormat.get_len ()],
|
2009-05-18 23:47:52 +00:00
|
|
|
CURPOSITION ());
|
2009-05-31 02:17:32 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos++;
|
2009-05-18 23:47:52 +00:00
|
|
|
return true;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& coverage.sanitize (context, this)
|
2010-05-10 21:47:22 +00:00
|
|
|
&& valueFormat.sanitize_values (context, this, values, valueCount);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 2 */
|
|
|
|
OffsetTo<Coverage>
|
|
|
|
coverage; /* Offset to Coverage table--from
|
|
|
|
* beginning of subtable */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat; /* Defines the types of data in the
|
2009-05-18 21:09:33 +00:00
|
|
|
* ValueRecord */
|
|
|
|
USHORT valueCount; /* Number of ValueRecords */
|
|
|
|
ValueRecord values; /* Array of ValueRecords--positioning
|
|
|
|
* values applied to glyphs */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (8, values);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct SinglePos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 02:16:04 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
|
|
|
case 2: return u.format2.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
|
|
|
case 2: return u.format2.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
SinglePosFormat1 format1;
|
|
|
|
SinglePosFormat2 format2;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PairValueRecord
|
|
|
|
{
|
2009-05-20 02:16:04 +00:00
|
|
|
friend struct PairPosFormat1;
|
2009-05-18 21:09:33 +00:00
|
|
|
|
|
|
|
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 */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (2, values);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PairSet
|
|
|
|
{
|
2009-05-20 02:16:04 +00:00
|
|
|
friend struct PairPosFormat1;
|
|
|
|
|
2010-03-29 04:04:12 +00:00
|
|
|
/* Note: Doesn't sanitize the Device entries in the ValueRecord */
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context, unsigned int format_len) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
if (!context->check_struct (this)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
unsigned int count = (1 + format_len) * len;
|
2010-05-06 23:33:31 +00:00
|
|
|
return context->check_array (array, USHORT::static_size, count);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 02:16:04 +00:00
|
|
|
private:
|
|
|
|
USHORT len; /* Number of PairValueRecords */
|
2010-05-10 23:01:17 +00:00
|
|
|
USHORT array[VAR]; /* Array of PairValueRecords--ordered
|
2009-05-20 02:16:04 +00:00
|
|
|
* by GlyphID of the second glyph */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (2, array);
|
2009-05-20 02:16:04 +00:00
|
|
|
};
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PairPosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PairPos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 02:16:04 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-05 05:23:44 +00:00
|
|
|
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
|
2010-05-05 05:13:09 +00:00
|
|
|
if (unlikely (context->buffer->in_pos + 2 > end))
|
2009-05-20 02:16:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index == NOT_COVERED))
|
2009-05-20 02:16:04 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
unsigned int j = context->buffer->in_pos + 1;
|
2010-05-05 05:01:05 +00:00
|
|
|
while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), context->lookup_flag, NULL))
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (j == end))
|
2009-05-20 02:16:04 +00:00
|
|
|
return false;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
2009-05-20 02:30:09 +00:00
|
|
|
unsigned int len1 = valueFormat1.get_len ();
|
|
|
|
unsigned int len2 = valueFormat2.get_len ();
|
2010-05-06 23:33:31 +00:00
|
|
|
unsigned int record_size = USHORT::static_size * (1 + len1 + len2);
|
2009-05-20 02:16:04 +00:00
|
|
|
|
2010-03-29 04:04:12 +00:00
|
|
|
const PairSet &pair_set = this+pairSet[index];
|
2009-05-20 02:16:04 +00:00
|
|
|
unsigned int count = pair_set.len;
|
2010-05-10 23:01:17 +00:00
|
|
|
const PairValueRecord *record = CastP<PairValueRecord> (pair_set.array);
|
2009-05-20 03:42:30 +00:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (IN_GLYPH (j) == record->secondGlyph)
|
|
|
|
{
|
2010-05-10 21:47:22 +00:00
|
|
|
valueFormat1.apply_value (context->layout, this, &record->values[0], CURPOSITION ());
|
|
|
|
valueFormat2.apply_value (context->layout, this, &record->values[len1], POSITION (j));
|
2009-05-20 02:16:04 +00:00
|
|
|
if (len2)
|
|
|
|
j++;
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos = j;
|
2009-05-20 02:16:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-05-10 21:36:03 +00:00
|
|
|
record = &StructAtOffset<PairValueRecord> (record, record_size);
|
2009-05-20 02:16:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-03-29 04:04:12 +00:00
|
|
|
|
|
|
|
unsigned int len1 = valueFormat1.get_len ();
|
|
|
|
unsigned int len2 = valueFormat2.get_len ();
|
|
|
|
|
2010-05-06 18:48:27 +00:00
|
|
|
if (!(context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& coverage.sanitize (context, this)
|
2010-05-11 03:13:08 +00:00
|
|
|
&& pairSet.sanitize (context, this, len1 + len2))) return false;
|
2010-03-29 04:04:12 +00:00
|
|
|
|
|
|
|
if (!(valueFormat1.has_device () || valueFormat2.has_device ())) return true;
|
|
|
|
|
|
|
|
unsigned int stride = 1 + len1 + len2;
|
|
|
|
unsigned int count1 = pairSet.len;
|
|
|
|
for (unsigned int i = 0; i < count1; i++)
|
|
|
|
{
|
2010-05-06 16:55:14 +00:00
|
|
|
PairSet &pair_set = const_cast<PairSet &> (this+pairSet[i]); /* XXX clean this up */
|
2010-03-29 04:04:12 +00:00
|
|
|
|
|
|
|
unsigned int count2 = pair_set.len;
|
2010-05-10 23:01:17 +00:00
|
|
|
PairValueRecord *record = CastP<PairValueRecord> (pair_set.array);
|
2010-05-10 21:47:22 +00:00
|
|
|
if (!(valueFormat1.sanitize_values_stride_unsafe (context, this, &record->values[0], count2, stride) &&
|
|
|
|
valueFormat2.sanitize_values_stride_unsafe (context, this, &record->values[len1], count2, stride)))
|
2010-03-29 04:04:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
|
|
|
OffsetTo<Coverage>
|
|
|
|
coverage; /* Offset to Coverage table--from
|
|
|
|
* beginning of subtable */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat1; /* Defines the types of data in
|
2009-05-18 21:09:33 +00:00
|
|
|
* ValueRecord1--for the first glyph
|
|
|
|
* in the pair--may be zero (0) */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat2; /* Defines the types of data in
|
2009-05-18 21:09:33 +00:00
|
|
|
* ValueRecord2--for the second glyph
|
|
|
|
* in the pair--may be zero (0) */
|
|
|
|
OffsetArrayOf<PairSet>
|
|
|
|
pairSet; /* Array of PairSet tables
|
|
|
|
* ordered by Coverage Index */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (10, pairSet);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PairPosFormat2
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PairPos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 02:30:09 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-05 05:23:44 +00:00
|
|
|
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
|
2010-05-05 05:13:09 +00:00
|
|
|
if (unlikely (context->buffer->in_pos + 2 > end))
|
2009-05-20 02:30:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index == NOT_COVERED))
|
2009-05-20 02:30:09 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
unsigned int j = context->buffer->in_pos + 1;
|
2010-05-05 05:01:05 +00:00
|
|
|
while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), context->lookup_flag, NULL))
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (j == end))
|
2009-05-20 02:30:09 +00:00
|
|
|
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));
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (klass1 >= class1Count || klass2 >= class2Count))
|
2009-05-20 02:30:09 +00:00
|
|
|
return false;
|
|
|
|
|
2010-03-16 07:46:17 +00:00
|
|
|
const Value *v = &values[record_len * (klass1 * class2Count + klass2)];
|
2010-05-10 21:47:22 +00:00
|
|
|
valueFormat1.apply_value (context->layout, this, v, CURPOSITION ());
|
|
|
|
valueFormat2.apply_value (context->layout, this, v + len1, POSITION (j));
|
2009-05-20 02:30:09 +00:00
|
|
|
|
|
|
|
if (len2)
|
|
|
|
j++;
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos = j;
|
2009-05-20 02:30:09 +00:00
|
|
|
|
|
|
|
return true;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
if (!(context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& coverage.sanitize (context, this)
|
|
|
|
&& classDef1.sanitize (context, this)
|
|
|
|
&& classDef2.sanitize (context, this))) return false;
|
2009-08-14 21:31:16 +00:00
|
|
|
|
2010-03-29 04:04:12 +00:00
|
|
|
unsigned int len1 = valueFormat1.get_len ();
|
|
|
|
unsigned int len2 = valueFormat2.get_len ();
|
|
|
|
unsigned int stride = len1 + len2;
|
2010-03-16 07:46:17 +00:00
|
|
|
unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
|
2010-03-29 04:04:12 +00:00
|
|
|
unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
|
2010-05-06 00:15:14 +00:00
|
|
|
return context->check_array (values, record_size, count) &&
|
2010-05-10 21:47:22 +00:00
|
|
|
valueFormat1.sanitize_values_stride_unsafe (context, this, &values[0], count, stride) &&
|
|
|
|
valueFormat2.sanitize_values_stride_unsafe (context, this, &values[len1], count, stride);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
2009-05-20 02:30:09 +00:00
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 2 */
|
|
|
|
OffsetTo<Coverage>
|
|
|
|
coverage; /* Offset to Coverage table--from
|
|
|
|
* beginning of subtable */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat1; /* ValueRecord definition--for the
|
2009-05-18 21:09:33 +00:00
|
|
|
* first glyph of the pair--may be zero
|
|
|
|
* (0) */
|
2009-05-18 23:47:52 +00:00
|
|
|
ValueFormat valueFormat2; /* ValueRecord definition--for the
|
2009-05-18 21:09:33 +00:00
|
|
|
* 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 */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (16, values);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PairPos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
|
|
|
case 2: return u.format2.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
|
|
|
case 2: return u.format2.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
PairPosFormat1 format1;
|
|
|
|
PairPosFormat2 format2;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct EntryExitRecord
|
|
|
|
{
|
2010-05-10 20:38:32 +00:00
|
|
|
friend struct CursivePosFormat1;
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 16:55:14 +00:00
|
|
|
return entryAnchor.sanitize (context, base)
|
|
|
|
&& exitAnchor.sanitize (context, base);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-10 20:38:32 +00:00
|
|
|
private:
|
2009-05-18 21:09:33 +00:00
|
|
|
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 */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct CursivePosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct CursivePos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:25:41 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-20 03:25:41 +00:00
|
|
|
/* 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. */
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
struct hb_ot_layout_context_t::info_t::gpos_t *gpi = &context->layout->info.gpos;
|
2009-05-20 08:16:35 +00:00
|
|
|
hb_codepoint_t last_pos = gpi->last;
|
2009-05-25 08:04:24 +00:00
|
|
|
gpi->last = HB_OT_LAYOUT_GPOS_NO_LAST;
|
2009-05-20 08:16:35 +00:00
|
|
|
|
|
|
|
/* We don't handle mark glyphs here. */
|
2010-04-29 06:25:30 +00:00
|
|
|
if (context->property == HB_OT_LAYOUT_GLYPH_CLASS_MARK)
|
2009-05-20 08:16:35 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (index == NOT_COVERED))
|
2009-05-20 08:16:35 +00:00
|
|
|
return false;
|
|
|
|
|
2009-05-20 03:25:41 +00:00
|
|
|
const EntryExitRecord &record = entryExitRecord[index];
|
|
|
|
|
2009-05-25 08:04:24 +00:00
|
|
|
if (last_pos == HB_OT_LAYOUT_GPOS_NO_LAST || !record.entryAnchor)
|
2009-05-20 03:25:41 +00:00
|
|
|
goto end;
|
|
|
|
|
2009-05-27 02:26:08 +00:00
|
|
|
hb_position_t entry_x, entry_y;
|
2010-05-05 05:01:05 +00:00
|
|
|
(this+record.entryAnchor).get_anchor (context->layout, IN_CURGLYPH (), &entry_x, &entry_y);
|
2009-05-20 03:25:41 +00:00
|
|
|
|
2009-05-27 04:17:37 +00:00
|
|
|
/* TODO vertical */
|
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
if (context->buffer->direction == HB_DIRECTION_RTL)
|
2009-05-20 03:25:41 +00:00
|
|
|
{
|
2009-11-06 21:47:31 +00:00
|
|
|
/* advance is absolute, not relative */
|
2010-05-05 05:13:09 +00:00
|
|
|
POSITION (context->buffer->in_pos)->x_advance = entry_x - gpi->anchor_x;
|
2009-05-20 03:25:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-06 21:47:31 +00:00
|
|
|
/* advance is absolute, not relative */
|
|
|
|
POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x;
|
2009-05-20 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
2010-04-29 06:25:30 +00:00
|
|
|
if (context->lookup_flag & LookupFlag::RightToLeft)
|
2009-05-20 03:25:41 +00:00
|
|
|
{
|
2010-05-05 05:13:09 +00:00
|
|
|
POSITION (last_pos)->cursive_chain = last_pos - context->buffer->in_pos;
|
2009-11-05 17:20:11 +00:00
|
|
|
POSITION (last_pos)->y_offset = entry_y - gpi->anchor_y;
|
2009-05-20 03:25:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-05 05:13:09 +00:00
|
|
|
POSITION (context->buffer->in_pos)->cursive_chain = context->buffer->in_pos - last_pos;
|
|
|
|
POSITION (context->buffer->in_pos)->y_offset = gpi->anchor_y - entry_y;
|
2009-05-20 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (record.exitAnchor)
|
2009-05-20 08:16:35 +00:00
|
|
|
{
|
2010-05-05 05:13:09 +00:00
|
|
|
gpi->last = context->buffer->in_pos;
|
2010-05-05 05:01:05 +00:00
|
|
|
(this+record.exitAnchor).get_anchor (context->layout, IN_CURGLYPH (), &gpi->anchor_x, &gpi->anchor_y);
|
2009-05-20 08:16:35 +00:00
|
|
|
}
|
2009-05-20 03:25:41 +00:00
|
|
|
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer->in_pos++;
|
2009-05-20 03:25:41 +00:00
|
|
|
return true;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 16:55:14 +00:00
|
|
|
return coverage.sanitize (context, this)
|
|
|
|
&& entryExitRecord.sanitize (context, this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
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 */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (6, entryExitRecord);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct CursivePos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
CursivePosFormat1 format1;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-14 22:14:03 +00:00
|
|
|
typedef AnchorMatrix BaseArray; /* base-major--
|
|
|
|
* in order of BaseCoverage Index--,
|
|
|
|
* mark-minor--
|
2009-05-21 08:47:05 +00:00
|
|
|
* ordered by class--zero-based. */
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkBasePosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct MarkBasePos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-21 10:32:01 +00:00
|
|
|
unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (mark_index == NOT_COVERED))
|
2009-05-21 10:32:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* now we search backwards for a non-mark glyph */
|
2010-04-29 06:19:21 +00:00
|
|
|
unsigned int property;
|
2010-05-05 05:13:09 +00:00
|
|
|
unsigned int j = context->buffer->in_pos;
|
2009-08-12 19:40:04 +00:00
|
|
|
do
|
2009-05-21 10:32:01 +00:00
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!j))
|
2009-05-26 21:58:37 +00:00
|
|
|
return false;
|
2009-08-14 23:37:18 +00:00
|
|
|
j--;
|
2010-05-05 05:01:05 +00:00
|
|
|
} while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property));
|
2009-08-12 19:40:04 +00:00
|
|
|
|
2010-05-10 20:57:29 +00:00
|
|
|
/* The following assertion is too strong, so we've disabled it. */
|
|
|
|
if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
|
2009-05-21 10:32:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int base_index = (this+baseCoverage) (IN_GLYPH (j));
|
2009-05-21 12:27:07 +00:00
|
|
|
if (base_index == NOT_COVERED)
|
2009-05-21 10:32:01 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
return (this+markArray).apply (context, mark_index, base_index, this+baseArray, classCount, j);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& markCoverage.sanitize (context, this)
|
|
|
|
&& baseCoverage.sanitize (context, this)
|
|
|
|
&& markArray.sanitize (context, this)
|
2010-05-11 03:13:08 +00:00
|
|
|
&& baseArray.sanitize (context, this, (unsigned int) classCount);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
2009-05-21 08:47:05 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
markCoverage; /* Offset to MarkCoverage table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkBasePos subtable */
|
2009-05-21 08:47:05 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
baseCoverage; /* Offset to BaseCoverage table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkBasePos subtable */
|
|
|
|
USHORT classCount; /* Number of classes defined for marks */
|
2009-05-21 08:47:05 +00:00
|
|
|
OffsetTo<MarkArray>
|
|
|
|
markArray; /* Offset to MarkArray table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkBasePos subtable */
|
2009-05-21 08:47:05 +00:00
|
|
|
OffsetTo<BaseArray>
|
|
|
|
baseArray; /* Offset to BaseArray table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkBasePos subtable */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkBasePos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
MarkBasePosFormat1 format1;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-14 22:14:03 +00:00
|
|
|
typedef AnchorMatrix LigatureAttach; /* component-major--
|
|
|
|
* in order of writing direction--,
|
|
|
|
* mark-minor--
|
2009-05-22 22:29:45 +00:00
|
|
|
* ordered by class--zero-based. */
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-08-14 22:32:56 +00:00
|
|
|
typedef OffsetListOf<LigatureAttach> LigatureArray;
|
2009-05-22 22:29:45 +00:00
|
|
|
/* Array of LigatureAttach
|
2009-05-18 21:09:33 +00:00
|
|
|
* tables ordered by
|
|
|
|
* LigatureCoverage Index */
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkLigPosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct MarkLigPos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-22 22:29:45 +00:00
|
|
|
unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (mark_index == NOT_COVERED))
|
2009-05-22 22:29:45 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* now we search backwards for a non-mark glyph */
|
2010-04-29 06:19:21 +00:00
|
|
|
unsigned int property;
|
2010-05-05 05:13:09 +00:00
|
|
|
unsigned int j = context->buffer->in_pos;
|
2009-08-12 19:40:04 +00:00
|
|
|
do
|
2009-05-22 22:29:45 +00:00
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!j))
|
2009-05-26 21:58:37 +00:00
|
|
|
return false;
|
2009-08-14 23:37:18 +00:00
|
|
|
j--;
|
2010-05-05 05:01:05 +00:00
|
|
|
} while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property));
|
2009-08-12 19:40:04 +00:00
|
|
|
|
2010-05-10 20:57:29 +00:00
|
|
|
/* The following assertion is too strong, so we've disabled it. */
|
|
|
|
if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
|
2009-05-22 22:29:45 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int lig_index = (this+ligatureCoverage) (IN_GLYPH (j));
|
|
|
|
if (lig_index == NOT_COVERED)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const LigatureArray& lig_array = this+ligatureArray;
|
2009-08-14 22:32:56 +00:00
|
|
|
const LigatureAttach& lig_attach = lig_array[lig_index];
|
2009-08-14 22:14:03 +00:00
|
|
|
|
|
|
|
/* Find component to attach to */
|
2009-08-14 23:37:18 +00:00
|
|
|
unsigned int comp_count = lig_attach.rows;
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!comp_count))
|
2009-05-22 22:29:45 +00:00
|
|
|
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. */
|
2010-05-05 05:13:09 +00:00
|
|
|
if (IN_LIGID (j) && IN_LIGID (j) == IN_LIGID (context->buffer->in_pos) && IN_COMPONENT (context->buffer->in_pos))
|
2009-05-22 22:29:45 +00:00
|
|
|
{
|
2010-05-05 05:13:09 +00:00
|
|
|
comp_index = IN_COMPONENT (context->buffer->in_pos) - 1;
|
2009-08-14 23:37:18 +00:00
|
|
|
if (comp_index >= comp_count)
|
|
|
|
comp_index = comp_count - 1;
|
2009-05-22 22:29:45 +00:00
|
|
|
}
|
|
|
|
else
|
2009-08-14 23:37:18 +00:00
|
|
|
comp_index = comp_count - 1;
|
2009-05-22 22:29:45 +00:00
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
return (this+markArray).apply (context, mark_index, comp_index, lig_attach, classCount, j);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& markCoverage.sanitize (context, this)
|
|
|
|
&& ligatureCoverage.sanitize (context, this)
|
|
|
|
&& markArray.sanitize (context, this)
|
2010-05-11 03:13:08 +00:00
|
|
|
&& ligatureArray.sanitize (context, this, (unsigned int) classCount);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
2009-05-22 22:29:45 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
markCoverage; /* Offset to Mark Coverage table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkLigPos subtable */
|
2009-05-22 22:29:45 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
ligatureCoverage; /* Offset to Ligature Coverage
|
2009-05-18 21:09:33 +00:00
|
|
|
* table--from beginning of MarkLigPos
|
|
|
|
* subtable */
|
|
|
|
USHORT classCount; /* Number of defined mark classes */
|
2009-05-22 22:29:45 +00:00
|
|
|
OffsetTo<MarkArray>
|
|
|
|
markArray; /* Offset to MarkArray table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkLigPos subtable */
|
2009-05-22 22:29:45 +00:00
|
|
|
OffsetTo<LigatureArray>
|
|
|
|
ligatureArray; /* Offset to LigatureArray table--from
|
2009-05-18 21:09:33 +00:00
|
|
|
* beginning of MarkLigPos subtable */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkLigPos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
MarkLigPosFormat1 format1;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-14 22:14:03 +00:00
|
|
|
typedef AnchorMatrix Mark2Array; /* mark2-major--
|
|
|
|
* in order of Mark2Coverage Index--,
|
|
|
|
* mark1-minor--
|
|
|
|
* ordered by class--zero-based. */
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkMarkPosFormat1
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct MarkMarkPos;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-21 12:27:07 +00:00
|
|
|
unsigned int mark1_index = (this+mark1Coverage) (IN_CURGLYPH ());
|
2010-05-04 02:51:19 +00:00
|
|
|
if (likely (mark1_index == NOT_COVERED))
|
2009-05-21 12:27:07 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* now we search backwards for a suitable mark glyph until a non-mark glyph */
|
2010-04-29 06:19:21 +00:00
|
|
|
unsigned int property;
|
2010-05-05 05:13:09 +00:00
|
|
|
unsigned int j = context->buffer->in_pos;
|
2009-08-12 19:40:04 +00:00
|
|
|
do
|
2009-05-21 12:27:07 +00:00
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!j))
|
2009-05-26 21:58:37 +00:00
|
|
|
return false;
|
2009-08-14 23:37:18 +00:00
|
|
|
j--;
|
2010-05-05 05:01:05 +00:00
|
|
|
} while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), context->lookup_flag, &property));
|
2009-08-12 19:40:04 +00:00
|
|
|
|
2009-05-26 21:58:37 +00:00
|
|
|
if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Two marks match only if they belong to the same base, or same component
|
2009-11-05 21:16:14 +00:00
|
|
|
* of the same ligature. That is, the component numbers must match, and
|
|
|
|
* if those are non-zero, the ligid number should also match. */
|
2010-05-05 05:13:09 +00:00
|
|
|
if ((IN_COMPONENT (j) != IN_COMPONENT (context->buffer->in_pos)) ||
|
|
|
|
(IN_COMPONENT (j) && IN_LIGID (j) != IN_LIGID (context->buffer->in_pos)))
|
2009-05-21 12:27:07 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int mark2_index = (this+mark2Coverage) (IN_GLYPH (j));
|
|
|
|
if (mark2_index == NOT_COVERED)
|
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
return (this+mark1Array).apply (context, mark1_index, mark2_index, this+mark2Array, classCount, j);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 16:55:14 +00:00
|
|
|
&& mark1Coverage.sanitize (context, this)
|
|
|
|
&& mark2Coverage.sanitize (context, this)
|
|
|
|
&& mark1Array.sanitize (context, this)
|
2010-05-11 03:13:08 +00:00
|
|
|
&& mark2Array.sanitize (context, this, (unsigned int) classCount);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
USHORT format; /* Format identifier--format = 1 */
|
2009-05-21 12:27:07 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
mark1Coverage; /* Offset to Combining Mark1 Coverage
|
2009-05-18 21:09:33 +00:00
|
|
|
* table--from beginning of MarkMarkPos
|
|
|
|
* subtable */
|
2009-05-21 12:27:07 +00:00
|
|
|
OffsetTo<Coverage>
|
|
|
|
mark2Coverage; /* Offset to Combining Mark2 Coverage
|
2009-05-18 21:09:33 +00:00
|
|
|
* table--from beginning of MarkMarkPos
|
|
|
|
* subtable */
|
2009-05-21 12:27:07 +00:00
|
|
|
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 */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct MarkMarkPos
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 17:30:23 +00:00
|
|
|
if (!u.format.sanitize (context)) return false;
|
2009-08-04 17:30:49 +00:00
|
|
|
switch (u.format) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.format1.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2010-05-10 23:45:41 +00:00
|
|
|
MarkMarkPosFormat1 format1;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
static inline bool position_lookup (hb_apply_context_t *context, unsigned int lookup_index);
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct ContextPos : Context
|
|
|
|
{
|
2009-05-22 02:31:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-08-28 21:14:33 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-05 05:32:04 +00:00
|
|
|
return Context::apply (context, position_lookup);
|
2009-08-28 21:14:33 +00:00
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct ChainContextPos : ChainContext
|
|
|
|
{
|
2009-05-22 02:31:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const
|
2009-08-28 21:14:33 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-05 05:32:04 +00:00
|
|
|
return ChainContext::apply (context, position_lookup);
|
2009-08-28 21:14:33 +00:00
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-22 02:31:33 +00:00
|
|
|
struct ExtensionPos : Extension
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookupSubTable;
|
|
|
|
|
|
|
|
private:
|
2009-08-04 17:30:49 +00:00
|
|
|
inline const struct PosLookupSubTable& get_subtable (void) const
|
2010-04-22 20:51:42 +00:00
|
|
|
{
|
|
|
|
unsigned int offset = get_offset ();
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!offset)) return Null(PosLookupSubTable);
|
2010-05-10 21:36:03 +00:00
|
|
|
return StructAtOffset<PosLookupSubTable> (this, offset);
|
2010-04-22 20:51:42 +00:00
|
|
|
}
|
2009-08-04 17:30:49 +00:00
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context) const;
|
2009-08-04 17:30:49 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-22 02:31:33 +00:00
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
/*
|
|
|
|
* PosLookup
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PosLookupSubTable
|
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
friend struct PosLookup;
|
|
|
|
|
2009-05-20 07:53:00 +00:00
|
|
|
enum {
|
|
|
|
Single = 1,
|
|
|
|
Pair = 2,
|
|
|
|
Cursive = 3,
|
|
|
|
MarkBase = 4,
|
|
|
|
MarkLig = 5,
|
|
|
|
MarkMark = 6,
|
|
|
|
Context = 7,
|
|
|
|
ChainContext = 8,
|
2009-08-18 20:41:59 +00:00
|
|
|
Extension = 9
|
2009-05-20 07:53:00 +00:00
|
|
|
};
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool apply (hb_apply_context_t *context, unsigned int lookup_type) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2009-05-18 21:09:33 +00:00
|
|
|
switch (lookup_type) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case Single: return u.single.apply (context);
|
|
|
|
case Pair: return u.pair.apply (context);
|
|
|
|
case Cursive: return u.cursive.apply (context);
|
|
|
|
case MarkBase: return u.markBase.apply (context);
|
|
|
|
case MarkLig: return u.markLig.apply (context);
|
|
|
|
case MarkMark: return u.markMark.apply (context);
|
|
|
|
case Context: return u.context.apply (context);
|
|
|
|
case ChainContext: return u.chainContext.apply (context);
|
|
|
|
case Extension: return u.extension.apply (context);
|
2009-05-18 21:09:33 +00:00
|
|
|
default:return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-11 01:39:24 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context, unsigned int lookup_type) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-11 01:39:24 +00:00
|
|
|
switch (lookup_type) {
|
2010-05-10 23:45:41 +00:00
|
|
|
case Single: return u.single.sanitize (context);
|
|
|
|
case Pair: return u.pair.sanitize (context);
|
|
|
|
case Cursive: return u.cursive.sanitize (context);
|
|
|
|
case MarkBase: return u.markBase.sanitize (context);
|
|
|
|
case MarkLig: return u.markLig.sanitize (context);
|
|
|
|
case MarkMark: return u.markMark.sanitize (context);
|
|
|
|
case Context: return u.context.sanitize (context);
|
|
|
|
case ChainContext: return u.chainContext.sanitize (context);
|
|
|
|
case Extension: return u.extension.sanitize (context);
|
2009-08-04 17:30:49 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
private:
|
|
|
|
union {
|
2010-05-11 01:39:24 +00:00
|
|
|
USHORT sub_format;
|
2010-05-10 23:45:41 +00:00
|
|
|
SinglePos single;
|
|
|
|
PairPos pair;
|
|
|
|
CursivePos cursive;
|
|
|
|
MarkBasePos markBase;
|
|
|
|
MarkLigPos markLig;
|
|
|
|
MarkMarkPos markMark;
|
|
|
|
ContextPos context;
|
|
|
|
ChainContextPos chainContext;
|
|
|
|
ExtensionPos extension;
|
2009-05-18 21:09:33 +00:00
|
|
|
} u;
|
2010-05-10 22:08:46 +00:00
|
|
|
public:
|
2010-05-11 01:39:24 +00:00
|
|
|
DEFINE_SIZE_UNION (2, sub_format);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct PosLookup : Lookup
|
|
|
|
{
|
|
|
|
inline const PosLookupSubTable& get_subtable (unsigned int i) const
|
2010-04-23 20:35:01 +00:00
|
|
|
{ return this+CastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; }
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
inline bool apply_once (hb_ot_layout_context_t *layout,
|
2009-05-22 21:58:09 +00:00
|
|
|
hb_buffer_t *buffer,
|
|
|
|
unsigned int context_length,
|
2010-05-05 05:30:48 +00:00
|
|
|
unsigned int nesting_level_left) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-05-18 21:09:33 +00:00
|
|
|
unsigned int lookup_type = get_type ();
|
2010-05-05 05:40:25 +00:00
|
|
|
hb_apply_context_t context[1] = {{0}};
|
2010-04-29 06:19:21 +00:00
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
context->layout = layout;
|
2010-05-05 05:13:09 +00:00
|
|
|
context->buffer = buffer;
|
2010-05-05 05:23:44 +00:00
|
|
|
context->context_length = context_length;
|
2010-04-29 06:25:30 +00:00
|
|
|
context->nesting_level_left = nesting_level_left;
|
|
|
|
context->lookup_flag = get_flag ();
|
2009-05-22 21:58:09 +00:00
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
if (!_hb_ot_layout_check_glyph_property (context->layout->face, IN_CURINFO (), context->lookup_flag, &context->property))
|
2009-05-22 21:58:09 +00:00
|
|
|
return false;
|
2009-05-18 21:09:33 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < get_subtable_count (); i++)
|
2010-05-05 05:32:04 +00:00
|
|
|
if (get_subtable (i).apply (context, lookup_type))
|
2009-05-18 21:09:33 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
inline bool apply_string (hb_ot_layout_context_t *layout,
|
2009-08-10 23:00:36 +00:00
|
|
|
hb_buffer_t *buffer,
|
|
|
|
hb_mask_t mask) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-05 05:13:09 +00:00
|
|
|
#undef BUFFER
|
|
|
|
#define BUFFER buffer
|
2009-05-18 21:09:33 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!buffer->in_length))
|
2009-05-18 21:09:33 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
layout->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST; /* no last valid glyph for cursive pos. */
|
2009-05-18 21:43:49 +00:00
|
|
|
|
2009-05-18 21:09:33 +00:00
|
|
|
buffer->in_pos = 0;
|
2009-05-20 03:42:30 +00:00
|
|
|
while (buffer->in_pos < buffer->in_length)
|
|
|
|
{
|
2009-05-18 21:43:49 +00:00
|
|
|
bool done;
|
2009-08-08 20:53:23 +00:00
|
|
|
if (~IN_MASK (buffer->in_pos) & mask)
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-05 05:30:48 +00:00
|
|
|
done = apply_once (layout, buffer, NO_CONTEXT, MAX_NESTING_LEVEL);
|
2009-05-18 21:43:49 +00:00
|
|
|
ret |= done;
|
2009-05-20 03:42:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-18 21:43:49 +00:00
|
|
|
done = false;
|
|
|
|
/* Contrary to properties defined in GDEF, user-defined properties
|
|
|
|
will always stop a possible cursive positioning. */
|
2010-05-05 05:01:05 +00:00
|
|
|
layout->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST;
|
2009-05-18 21:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!done)
|
|
|
|
buffer->in_pos++;
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-08-04 17:30:49 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-05 04:23:19 +00:00
|
|
|
if (unlikely (!Lookup::sanitize (context))) return false;
|
2010-04-23 20:35:01 +00:00
|
|
|
OffsetArrayOf<PosLookupSubTable> &list = CastR<OffsetArrayOf<PosLookupSubTable> > (subTable);
|
2010-05-11 01:39:24 +00:00
|
|
|
return list.sanitize (context, this, get_type ());
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
2009-08-04 17:30:49 +00:00
|
|
|
typedef OffsetListOf<PosLookup> PosLookupList;
|
2009-05-18 21:09:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GPOS
|
|
|
|
*/
|
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
struct GPOS : GSUBGPOS
|
|
|
|
{
|
2009-08-05 00:27:05 +00:00
|
|
|
static const hb_tag_t Tag = HB_OT_TAG_GPOS;
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2009-05-20 03:42:30 +00:00
|
|
|
inline const PosLookup& get_lookup (unsigned int i) const
|
2010-04-23 20:35:01 +00:00
|
|
|
{ return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 05:01:05 +00:00
|
|
|
inline bool position_lookup (hb_ot_layout_context_t *layout,
|
2009-08-08 20:53:23 +00:00
|
|
|
hb_buffer_t *buffer,
|
|
|
|
unsigned int lookup_index,
|
|
|
|
hb_mask_t mask) const
|
2010-05-05 05:01:05 +00:00
|
|
|
{ return get_lookup (lookup_index).apply_string (layout, buffer, mask); }
|
2009-05-18 21:09:33 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-05 04:23:19 +00:00
|
|
|
if (unlikely (!GSUBGPOS::sanitize (context))) return false;
|
2010-04-23 20:35:01 +00:00
|
|
|
OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList);
|
2010-05-06 16:55:14 +00:00
|
|
|
return list.sanitize (context, this);
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (10);
|
2009-05-18 21:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Out-of-class implementation for methods recursing */
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
inline bool ExtensionPos::apply (hb_apply_context_t *context) const
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_APPLY ();
|
2010-05-05 05:32:04 +00:00
|
|
|
return get_subtable ().apply (context, get_type ());
|
2009-08-04 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool ExtensionPos::sanitize (hb_sanitize_context_t *context)
|
2009-08-04 17:30:49 +00:00
|
|
|
{
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-05 04:23:19 +00:00
|
|
|
if (unlikely (!Extension::sanitize (context))) return false;
|
2010-04-22 20:51:42 +00:00
|
|
|
unsigned int offset = get_offset ();
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (!offset)) return true;
|
2010-05-11 01:39:24 +00:00
|
|
|
return StructAtOffset<PosLookupSubTable> (this, offset).sanitize (context, get_type ());
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 05:32:04 +00:00
|
|
|
static inline bool position_lookup (hb_apply_context_t *context, unsigned int lookup_index)
|
2009-05-20 03:42:30 +00:00
|
|
|
{
|
2010-05-05 05:01:05 +00:00
|
|
|
const GPOS &gpos = *(context->layout->face->ot_layout.gpos);
|
2009-05-18 21:09:33 +00:00
|
|
|
const PosLookup &l = gpos.get_lookup (lookup_index);
|
|
|
|
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (context->nesting_level_left == 0))
|
2009-05-18 21:09:33 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:23:44 +00:00
|
|
|
if (unlikely (context->context_length < 1))
|
2009-05-18 21:09:33 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-05 05:30:48 +00:00
|
|
|
return l.apply_once (context->layout, context->buffer, context->context_length, context->nesting_level_left - 1);
|
2009-05-18 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 00:03:12 +00:00
|
|
|
#endif /* HB_OT_LAYOUT_GPOS_PRIVATE_HH */
|