2017-08-18 01:55:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2017 Google, Inc.
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#ifndef HB_AAT_LAYOUT_COMMON_HH
|
|
|
|
#define HB_AAT_LAYOUT_COMMON_HH
|
2017-08-18 01:55:54 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-aat-layout.hh"
|
2023-01-10 05:32:15 +01:00
|
|
|
#include "hb-aat-map.hh"
|
2018-12-08 07:50:25 +01:00
|
|
|
#include "hb-open-type.hh"
|
2017-08-18 01:55:54 +02:00
|
|
|
|
2021-05-05 12:11:43 +02:00
|
|
|
namespace OT {
|
|
|
|
struct GDEF;
|
|
|
|
};
|
2017-08-18 01:55:54 +02:00
|
|
|
|
|
|
|
namespace AAT {
|
|
|
|
|
|
|
|
using namespace OT;
|
|
|
|
|
|
|
|
|
2023-01-10 05:32:15 +01:00
|
|
|
struct ankr;
|
|
|
|
|
|
|
|
struct hb_aat_apply_context_t :
|
|
|
|
hb_dispatch_context_t<hb_aat_apply_context_t, bool, HB_DEBUG_APPLY>
|
|
|
|
{
|
|
|
|
const char *get_name () { return "APPLY"; }
|
|
|
|
template <typename T>
|
|
|
|
return_t dispatch (const T &obj) { return obj.apply (this); }
|
|
|
|
static return_t default_return_value () { return false; }
|
|
|
|
bool stop_sublookup_iteration (return_t r) const { return r; }
|
|
|
|
|
|
|
|
const hb_ot_shape_plan_t *plan;
|
|
|
|
hb_font_t *font;
|
|
|
|
hb_face_t *face;
|
|
|
|
hb_buffer_t *buffer;
|
|
|
|
hb_sanitize_context_t sanitizer;
|
|
|
|
const ankr *ankr_table;
|
|
|
|
const OT::GDEF *gdef_table;
|
|
|
|
const hb_sorted_vector_t<hb_aat_map_t::range_flags_t> *range_flags = nullptr;
|
|
|
|
hb_mask_t subtable_flags = 0;
|
|
|
|
|
|
|
|
/* Unused. For debug tracing only. */
|
|
|
|
unsigned int lookup_index;
|
|
|
|
|
|
|
|
HB_INTERNAL hb_aat_apply_context_t (const hb_ot_shape_plan_t *plan_,
|
|
|
|
hb_font_t *font_,
|
|
|
|
hb_buffer_t *buffer_,
|
|
|
|
hb_blob_t *blob = const_cast<hb_blob_t *> (&Null (hb_blob_t)));
|
|
|
|
|
|
|
|
HB_INTERNAL ~hb_aat_apply_context_t ();
|
|
|
|
|
|
|
|
HB_INTERNAL void set_ankr_table (const AAT::ankr *ankr_table_);
|
|
|
|
|
|
|
|
void set_lookup_index (unsigned int i) { lookup_index = i; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-09 15:48:51 +01:00
|
|
|
/*
|
|
|
|
* Lookup Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T> struct Lookup;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat0
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
if (unlikely (glyph_id >= num_glyphs)) return nullptr;
|
|
|
|
return &arrayZ[glyph_id];
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-07-17 18:45:25 +02:00
|
|
|
return_trace (arrayZ.sanitize (c, c->get_num_glyphs ()));
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (arrayZ.sanitize (c, c->get_num_glyphs (), base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 0 */
|
2018-01-09 15:48:51 +01:00
|
|
|
UnsizedArrayOf<T>
|
|
|
|
arrayZ; /* Array of lookup values, indexed by glyph index. */
|
|
|
|
public:
|
2018-11-22 07:18:55 +01:00
|
|
|
DEFINE_SIZE_UNBOUNDED (2);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSegmentSingle
|
|
|
|
{
|
2019-01-22 12:11:24 +01:00
|
|
|
static constexpr unsigned TerminationWordCount = 2u;
|
2018-11-25 05:12:28 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (hb_codepoint_t g) const
|
|
|
|
{ return g < first ? -1 : g <= last ? 0 : +1 ; }
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 last; /* Last GlyphID in this segment */
|
|
|
|
HBGlyphID16 first; /* First GlyphID in this segment */
|
2018-01-09 15:48:51 +01:00
|
|
|
T value; /* The lookup value (only one) */
|
|
|
|
public:
|
2018-01-11 09:15:34 +01:00
|
|
|
DEFINE_SIZE_STATIC (4 + T::static_size);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat2
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSegmentSingle<T> *v = segments.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? &v->value : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 2 */
|
2019-04-30 22:05:10 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSegmentSingle<T>>
|
2018-01-09 15:48:51 +01:00
|
|
|
segments; /* The actual segments. These must already be sorted,
|
|
|
|
* according to the first word in each one (the last
|
|
|
|
* glyph in each segment). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, segments);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSegmentArray
|
|
|
|
{
|
2019-01-22 12:11:24 +01:00
|
|
|
static constexpr unsigned TerminationWordCount = 2u;
|
2018-11-25 05:12:28 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id, const void *base) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (hb_codepoint_t g) const
|
|
|
|
{ return g < first ? -1 : g <= last ? 0 : +1; }
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
first <= last &&
|
|
|
|
valuesZ.sanitize (c, base, last - first + 1));
|
|
|
|
}
|
2019-04-24 05:57:11 +02:00
|
|
|
template <typename ...Ts>
|
2019-05-08 05:58:43 +02:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base, Ts&&... ds) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
first <= last &&
|
2021-11-02 07:18:22 +01:00
|
|
|
valuesZ.sanitize (c, base, last - first + 1, std::forward<Ts> (ds)...));
|
2018-11-08 16:23:14 +01:00
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 last; /* Last GlyphID in this segment */
|
|
|
|
HBGlyphID16 first; /* First GlyphID in this segment */
|
2021-03-31 20:49:14 +02:00
|
|
|
NNOffset16To<UnsizedArrayOf<T>>
|
2018-01-09 15:48:51 +01:00
|
|
|
valuesZ; /* A 16-bit offset from the start of
|
|
|
|
* the table to the data. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat4
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSegmentArray<T> *v = segments.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? v->get_value (glyph_id, this) : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c, this));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c, this, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-11 22:41:01 +02:00
|
|
|
HBUINT16 format; /* Format identifier--format = 4 */
|
2019-04-30 22:05:10 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSegmentArray<T>>
|
2018-01-09 15:48:51 +01:00
|
|
|
segments; /* The actual segments. These must already be sorted,
|
|
|
|
* according to the first word in each one (the last
|
|
|
|
* glyph in each segment). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, segments);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSingle
|
|
|
|
{
|
2019-01-22 12:11:24 +01:00
|
|
|
static constexpr unsigned TerminationWordCount = 1u;
|
2018-11-25 05:12:28 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 glyph; /* Last GlyphID */
|
2018-01-09 15:48:51 +01:00
|
|
|
T value; /* The lookup value (only one) */
|
|
|
|
public:
|
2018-10-11 22:41:01 +02:00
|
|
|
DEFINE_SIZE_STATIC (2 + T::static_size);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat6
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSingle<T> *v = entries.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? &v->value : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (entries.sanitize (c));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (entries.sanitize (c, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 6 */
|
2019-04-30 22:05:10 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSingle<T>>
|
2018-01-09 15:48:51 +01:00
|
|
|
entries; /* The actual entries, sorted by glyph index. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, entries);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat8
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-10-14 23:52:17 +02:00
|
|
|
return firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount ?
|
|
|
|
&valueArrayZ[glyph_id - firstGlyph] : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && valueArrayZ.sanitize (c, glyphCount));
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && valueArrayZ.sanitize (c, glyphCount, base));
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-14 23:52:17 +02:00
|
|
|
HBUINT16 format; /* Format identifier--format = 8 */
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 firstGlyph; /* First glyph index included in the trimmed array. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last
|
2018-01-09 15:48:51 +01:00
|
|
|
* glyph minus the value of firstGlyph plus 1). */
|
|
|
|
UnsizedArrayOf<T>
|
|
|
|
valueArrayZ; /* The lookup values (indexed by the glyph index
|
|
|
|
* minus the value of firstGlyph). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (6, valueArrayZ);
|
|
|
|
};
|
|
|
|
|
2018-10-20 00:23:49 +02:00
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat10
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-12-16 20:08:10 +01:00
|
|
|
const typename T::type get_value_or_null (hb_codepoint_t glyph_id) const
|
2018-10-20 00:23:49 +02:00
|
|
|
{
|
|
|
|
if (!(firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount))
|
2020-04-20 11:42:45 +02:00
|
|
|
return Null (T);
|
2018-10-20 00:23:49 +02:00
|
|
|
|
|
|
|
const HBUINT8 *p = &valueArrayZ[(glyph_id - firstGlyph) * valueSize];
|
|
|
|
|
|
|
|
unsigned int v = 0;
|
|
|
|
unsigned int count = valueSize;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
v = (v << 8) | *p++;
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-20 00:23:49 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
valueSize <= 4 &&
|
|
|
|
valueArrayZ.sanitize (c, glyphCount * valueSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
HBUINT16 format; /* Format identifier--format = 8 */
|
|
|
|
HBUINT16 valueSize; /* Byte size of each value. */
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 firstGlyph; /* First glyph index included in the trimmed array. */
|
2018-10-20 00:23:49 +02:00
|
|
|
HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last
|
|
|
|
* glyph minus the value of firstGlyph plus 1). */
|
|
|
|
UnsizedArrayOf<HBUINT8>
|
|
|
|
valueArrayZ; /* The lookup values (indexed by the glyph index
|
|
|
|
* minus the value of firstGlyph). */
|
|
|
|
public:
|
2018-10-20 21:04:51 +02:00
|
|
|
DEFINE_SIZE_ARRAY (8, valueArrayZ);
|
2018-10-20 00:23:49 +02:00
|
|
|
};
|
|
|
|
|
2018-01-09 15:48:51 +01:00
|
|
|
template <typename T>
|
|
|
|
struct Lookup
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return u.format0.get_value (glyph_id, num_glyphs);
|
|
|
|
case 2: return u.format2.get_value (glyph_id);
|
|
|
|
case 4: return u.format4.get_value (glyph_id);
|
|
|
|
case 6: return u.format6.get_value (glyph_id);
|
|
|
|
case 8: return u.format8.get_value (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
default:return nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const typename T::type get_value_or_null (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-10-10 19:24:51 +02:00
|
|
|
{
|
2018-10-20 00:23:49 +02:00
|
|
|
switch (u.format) {
|
|
|
|
/* Format 10 cannot return a pointer. */
|
|
|
|
case 10: return u.format10.get_value_or_null (glyph_id);
|
|
|
|
default:
|
|
|
|
const T *v = get_value (glyph_id, num_glyphs);
|
2020-04-20 11:42:45 +02:00
|
|
|
return v ? *v : Null (T);
|
2018-10-20 00:23:49 +02:00
|
|
|
}
|
2018-10-10 19:24:51 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
typename T::type get_class (hb_codepoint_t glyph_id,
|
|
|
|
unsigned int num_glyphs,
|
|
|
|
unsigned int outOfRange) const
|
2018-11-28 20:46:26 +01:00
|
|
|
{
|
|
|
|
const T *v = get_value (glyph_id, num_glyphs);
|
|
|
|
return v ? *v : outOfRange;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (!u.format.sanitize (c)) return_trace (false);
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return_trace (u.format0.sanitize (c));
|
|
|
|
case 2: return_trace (u.format2.sanitize (c));
|
|
|
|
case 4: return_trace (u.format4.sanitize (c));
|
|
|
|
case 6: return_trace (u.format6.sanitize (c));
|
|
|
|
case 8: return_trace (u.format8.sanitize (c));
|
2018-10-20 00:23:49 +02:00
|
|
|
case 10: return_trace (u.format10.sanitize (c));
|
2018-01-09 15:48:51 +01:00
|
|
|
default:return_trace (true);
|
|
|
|
}
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2018-11-08 16:23:14 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (!u.format.sanitize (c)) return_trace (false);
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return_trace (u.format0.sanitize (c, base));
|
|
|
|
case 2: return_trace (u.format2.sanitize (c, base));
|
|
|
|
case 4: return_trace (u.format4.sanitize (c, base));
|
|
|
|
case 6: return_trace (u.format6.sanitize (c, base));
|
|
|
|
case 8: return_trace (u.format8.sanitize (c, base));
|
2019-01-17 23:56:27 +01:00
|
|
|
case 10: return_trace (false); /* We don't support format10 here currently. */
|
2018-11-08 16:23:14 +01:00
|
|
|
default:return_trace (true);
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
union {
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier */
|
2018-01-09 15:48:51 +01:00
|
|
|
LookupFormat0<T> format0;
|
|
|
|
LookupFormat2<T> format2;
|
|
|
|
LookupFormat4<T> format4;
|
|
|
|
LookupFormat6<T> format6;
|
|
|
|
LookupFormat8<T> format8;
|
2018-10-20 00:23:49 +02:00
|
|
|
LookupFormat10<T> format10;
|
2018-01-09 15:48:51 +01:00
|
|
|
} u;
|
|
|
|
public:
|
2018-10-18 06:41:25 +02:00
|
|
|
DEFINE_SIZE_UNION (2, format);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
2022-07-05 23:44:58 +02:00
|
|
|
DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (AAT, Lookup, 2);
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-10-26 02:29:32 +02:00
|
|
|
enum { DELETED_GLYPH = 0xFFFF };
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-01-11 09:15:34 +01:00
|
|
|
/*
|
2018-11-06 21:07:19 +01:00
|
|
|
* (Extended) State Table
|
2018-01-11 09:15:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Entry
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-11 18:54:49 +01:00
|
|
|
/* Note, we don't recurse-sanitize data because we don't access it.
|
|
|
|
* That said, in our DEFINE_SIZE_STATIC we access T::static_size,
|
|
|
|
* which ensures that data has a simple sanitize(). To be determined
|
2018-10-27 06:01:11 +02:00
|
|
|
* if I need to remove that as well.
|
|
|
|
*
|
2018-11-24 06:27:57 +01:00
|
|
|
* HOWEVER! Because we are a template, our DEFINE_SIZE_STATIC
|
|
|
|
* assertion wouldn't be checked, hence the line below. */
|
|
|
|
static_assert (T::static_size, "");
|
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
return_trace (c->check_struct (this));
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-01-11 18:54:49 +01:00
|
|
|
HBUINT16 newState; /* Byte offset from beginning of state table
|
|
|
|
* to the new state. Really?!?! Or just state
|
|
|
|
* number? The latter in morx for sure. */
|
2018-01-11 09:15:34 +01:00
|
|
|
HBUINT16 flags; /* Table specific. */
|
|
|
|
T data; /* Optional offsets to per-glyph tables. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4 + T::static_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Entry<void>
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int count /*XXX Unused?*/) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
HBUINT16 newState; /* Byte offset from beginning of state table to the new state. */
|
|
|
|
HBUINT16 flags; /* Table specific. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types, typename Extra>
|
2018-01-11 09:15:34 +01:00
|
|
|
struct StateTable
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
typedef typename Types::HBUSHORT HBUSHORT;
|
2018-11-28 20:51:56 +01:00
|
|
|
typedef typename Types::ClassTypeNarrow ClassType;
|
2018-10-30 16:11:34 +01:00
|
|
|
|
2018-09-14 11:31:33 +02:00
|
|
|
enum State
|
|
|
|
{
|
|
|
|
STATE_START_OF_TEXT = 0,
|
|
|
|
STATE_START_OF_LINE = 1,
|
|
|
|
};
|
|
|
|
enum Class
|
|
|
|
{
|
|
|
|
CLASS_END_OF_TEXT = 0,
|
|
|
|
CLASS_OUT_OF_BOUNDS = 1,
|
|
|
|
CLASS_DELETED_GLYPH = 2,
|
|
|
|
CLASS_END_OF_LINE = 3,
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int new_state (unsigned int newState) const
|
2018-12-02 18:38:53 +01:00
|
|
|
{ return Types::extended ? newState : ((int) newState - (int) stateArrayTable) / (int) nClasses; }
|
2018-10-31 04:51:44 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_class (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-11 22:43:57 +01:00
|
|
|
{
|
2018-10-26 02:29:32 +02:00
|
|
|
if (unlikely (glyph_id == DELETED_GLYPH)) return CLASS_DELETED_GLYPH;
|
2018-11-07 18:08:44 +01:00
|
|
|
return (this+classTable).get_class (glyph_id, num_glyphs, 1);
|
2018-01-11 22:43:57 +01:00
|
|
|
}
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
const Entry<Extra> *get_entries () const
|
2018-12-12 12:44:37 +01:00
|
|
|
{ return (this+entryTable).arrayZ; }
|
2018-01-11 18:54:49 +01:00
|
|
|
|
2019-01-24 17:17:00 +01:00
|
|
|
const Entry<Extra> &get_entry (int state, unsigned int klass) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
2019-01-24 17:17:00 +01:00
|
|
|
if (unlikely (klass >= nClasses))
|
2021-02-18 19:16:37 +01:00
|
|
|
klass = StateTable::CLASS_OUT_OF_BOUNDS;
|
2018-01-11 18:15:53 +01:00
|
|
|
|
2018-10-31 03:26:16 +01:00
|
|
|
const HBUSHORT *states = (this+stateArrayTable).arrayZ;
|
2018-01-11 09:15:34 +01:00
|
|
|
const Entry<Extra> *entries = (this+entryTable).arrayZ;
|
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
unsigned int entry = states[state * nClasses + klass];
|
2018-11-08 00:04:53 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "e%u", entry);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2019-01-24 17:17:00 +01:00
|
|
|
return entries[entry];
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c,
|
|
|
|
unsigned int *num_entries_out = nullptr) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-15 21:41:51 +01:00
|
|
|
if (unlikely (!(c->check_struct (this) &&
|
2019-01-24 17:06:16 +01:00
|
|
|
nClasses >= 4 /* Ensure pre-defined classes fit. */ &&
|
2018-01-15 21:41:51 +01:00
|
|
|
classTable.sanitize (c, this)))) return_trace (false);
|
2018-01-11 18:15:53 +01:00
|
|
|
|
2018-10-31 03:26:16 +01:00
|
|
|
const HBUSHORT *states = (this+stateArrayTable).arrayZ;
|
2018-01-11 18:15:53 +01:00
|
|
|
const Entry<Extra> *entries = (this+entryTable).arrayZ;
|
|
|
|
|
2018-10-11 21:56:17 +02:00
|
|
|
unsigned int num_classes = nClasses;
|
2018-11-08 00:04:53 +01:00
|
|
|
if (unlikely (hb_unsigned_mul_overflows (num_classes, states[0].static_size)))
|
|
|
|
return_trace (false);
|
|
|
|
unsigned int row_stride = num_classes * states[0].static_size;
|
2018-10-11 21:56:17 +02:00
|
|
|
|
2018-11-08 00:04:53 +01:00
|
|
|
/* Apple 'kern' table has this peculiarity:
|
|
|
|
*
|
|
|
|
* "Because the stateTableOffset in the state table header is (strictly
|
|
|
|
* speaking) redundant, some 'kern' tables use it to record an initial
|
|
|
|
* state where that should not be StartOfText. To determine if this is
|
|
|
|
* done, calculate what the stateTableOffset should be. If it's different
|
|
|
|
* from the actual stateTableOffset, use it as the initial state."
|
|
|
|
*
|
|
|
|
* We implement this by calling the initial state zero, but allow *negative*
|
|
|
|
* states if the start state indeed was not the first state. Since the code
|
|
|
|
* is shared, this will also apply to 'mort' table. The 'kerx' / 'morx'
|
|
|
|
* tables are not affected since those address states by index, not offset.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int min_state = 0;
|
|
|
|
int max_state = 0;
|
2018-01-11 18:15:53 +01:00
|
|
|
unsigned int num_entries = 0;
|
|
|
|
|
2018-11-08 00:04:53 +01:00
|
|
|
int state_pos = 0;
|
|
|
|
int state_neg = 0;
|
2018-01-11 18:15:53 +01:00
|
|
|
unsigned int entry = 0;
|
2018-11-08 00:04:53 +01:00
|
|
|
while (min_state < state_neg || state_pos <= max_state)
|
2018-01-11 18:15:53 +01:00
|
|
|
{
|
2018-11-08 00:04:53 +01:00
|
|
|
if (min_state < state_neg)
|
|
|
|
{
|
|
|
|
/* Negative states. */
|
|
|
|
if (unlikely (hb_unsigned_mul_overflows (min_state, num_classes)))
|
|
|
|
return_trace (false);
|
2018-11-12 20:23:31 +01:00
|
|
|
if (unlikely (!c->check_range (&states[min_state * num_classes],
|
|
|
|
-min_state,
|
|
|
|
row_stride)))
|
2018-11-08 00:04:53 +01:00
|
|
|
return_trace (false);
|
2019-01-24 17:10:12 +01:00
|
|
|
if ((c->max_ops -= state_neg - min_state) <= 0)
|
2018-11-08 00:04:53 +01:00
|
|
|
return_trace (false);
|
|
|
|
{ /* Sweep new states. */
|
|
|
|
const HBUSHORT *stop = &states[min_state * num_classes];
|
|
|
|
if (unlikely (stop > states))
|
|
|
|
return_trace (false);
|
|
|
|
for (const HBUSHORT *p = states; stop < p; p--)
|
Narrow down cast operators on IntType
Say for USHORT, we were implementing casts from and to unsigned.
With this change, we cast from and to uint16_t only. This allows
compiler more opportunities to catch possible narrowing issues in
the code.
It needed a couple of fixes in the codebase though, because
previously, if a USHORT was participating in arithmetic with signed
numbers, eg. "u + 1", the result would have been unsigned. With
this change, it would be signed. The correct fix is to update the
code to read "u + 1u".
That said, I think about conditionally adding back the cast
out to signed/unsigned, to facilitate better type deduction.
But I couldn't think of a real situation where that would help
with anything. So I didn't add. Here's what it was:
template <typename Type2 = hb_conditional<hb_is_signed (Type), signed, unsigned>,
hb_enable_if (sizeof (Type) < sizeof (Type2))>
operator hb_type_identity_t<Type2> () const { return v; }
https://github.com/harfbuzz/harfbuzz/pull/2875
2021-02-23 06:09:15 +01:00
|
|
|
num_entries = hb_max (num_entries, *(p - 1) + 1u);
|
2018-11-08 00:04:53 +01:00
|
|
|
state_neg = min_state;
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 21:56:17 +02:00
|
|
|
|
2018-11-08 00:04:53 +01:00
|
|
|
if (state_pos <= max_state)
|
|
|
|
{
|
|
|
|
/* Positive states. */
|
2018-11-12 20:23:31 +01:00
|
|
|
if (unlikely (!c->check_range (states,
|
|
|
|
max_state + 1,
|
|
|
|
row_stride)))
|
2018-11-08 00:04:53 +01:00
|
|
|
return_trace (false);
|
2019-01-24 17:10:12 +01:00
|
|
|
if ((c->max_ops -= max_state - state_pos + 1) <= 0)
|
2018-11-08 00:04:53 +01:00
|
|
|
return_trace (false);
|
|
|
|
{ /* Sweep new states. */
|
|
|
|
if (unlikely (hb_unsigned_mul_overflows ((max_state + 1), num_classes)))
|
|
|
|
return_trace (false);
|
|
|
|
const HBUSHORT *stop = &states[(max_state + 1) * num_classes];
|
|
|
|
if (unlikely (stop < states))
|
|
|
|
return_trace (false);
|
|
|
|
for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++)
|
Narrow down cast operators on IntType
Say for USHORT, we were implementing casts from and to unsigned.
With this change, we cast from and to uint16_t only. This allows
compiler more opportunities to catch possible narrowing issues in
the code.
It needed a couple of fixes in the codebase though, because
previously, if a USHORT was participating in arithmetic with signed
numbers, eg. "u + 1", the result would have been unsigned. With
this change, it would be signed. The correct fix is to update the
code to read "u + 1u".
That said, I think about conditionally adding back the cast
out to signed/unsigned, to facilitate better type deduction.
But I couldn't think of a real situation where that would help
with anything. So I didn't add. Here's what it was:
template <typename Type2 = hb_conditional<hb_is_signed (Type), signed, unsigned>,
hb_enable_if (sizeof (Type) < sizeof (Type2))>
operator hb_type_identity_t<Type2> () const { return v; }
https://github.com/harfbuzz/harfbuzz/pull/2875
2021-02-23 06:09:15 +01:00
|
|
|
num_entries = hb_max (num_entries, *p + 1u);
|
2018-11-08 00:04:53 +01:00
|
|
|
state_pos = max_state + 1;
|
|
|
|
}
|
2018-01-11 18:15:53 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:18:07 +02:00
|
|
|
if (unlikely (!c->check_array (entries, num_entries)))
|
2018-01-11 18:15:53 +01:00
|
|
|
return_trace (false);
|
2019-01-24 17:10:12 +01:00
|
|
|
if ((c->max_ops -= num_entries - entry) <= 0)
|
2018-10-18 07:34:16 +02:00
|
|
|
return_trace (false);
|
2018-01-11 18:15:53 +01:00
|
|
|
{ /* Sweep new entries. */
|
|
|
|
const Entry<Extra> *stop = &entries[num_entries];
|
|
|
|
for (const Entry<Extra> *p = &entries[entry]; p < stop; p++)
|
2018-10-31 04:51:44 +01:00
|
|
|
{
|
2018-11-08 00:04:53 +01:00
|
|
|
int newState = new_state (p->newState);
|
2019-05-08 05:54:31 +02:00
|
|
|
min_state = hb_min (min_state, newState);
|
|
|
|
max_state = hb_max (max_state, newState);
|
2018-10-31 04:51:44 +01:00
|
|
|
}
|
2018-01-11 18:15:53 +01:00
|
|
|
entry = num_entries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
if (num_entries_out)
|
|
|
|
*num_entries_out = num_entries;
|
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
return_trace (true);
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
HBUINT nClasses; /* Number of classes, which is the number of indices
|
2018-01-11 09:15:34 +01:00
|
|
|
* in a single line in the state array. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<ClassType, HBUINT>
|
2018-01-11 09:15:34 +01:00
|
|
|
classTable; /* Offset to the class table. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<HBUSHORT>, HBUINT>
|
2018-01-11 09:15:34 +01:00
|
|
|
stateArrayTable;/* Offset to the state array. */
|
2019-04-30 22:05:10 +02:00
|
|
|
NNOffsetTo<UnsizedArrayOf<Entry<Extra>>, HBUINT>
|
2018-01-11 09:15:34 +01:00
|
|
|
entryTable; /* Offset to the entry array. */
|
|
|
|
|
|
|
|
public:
|
2018-10-31 05:49:59 +01:00
|
|
|
DEFINE_SIZE_STATIC (4 * sizeof (HBUINT));
|
2018-01-11 09:15:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-28 20:46:26 +01:00
|
|
|
template <typename HBUCHAR>
|
2018-10-30 16:11:34 +01:00
|
|
|
struct ClassTable
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_class (hb_codepoint_t glyph_id, unsigned int outOfRange) const
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
2018-11-06 21:23:18 +01:00
|
|
|
unsigned int i = glyph_id - firstGlyph;
|
|
|
|
return i >= classArray.len ? outOfRange : classArray.arrayZ[i];
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_class (hb_codepoint_t glyph_id,
|
|
|
|
unsigned int num_glyphs HB_UNUSED,
|
|
|
|
unsigned int outOfRange) const
|
2018-11-28 20:46:26 +01:00
|
|
|
{
|
|
|
|
return get_class (glyph_id, outOfRange);
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-11-06 21:23:18 +01:00
|
|
|
return_trace (c->check_struct (this) && classArray.sanitize (c));
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
|
|
|
protected:
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 firstGlyph; /* First glyph index included in the trimmed array. */
|
2021-04-01 00:04:43 +02:00
|
|
|
Array16Of<HBUCHAR> classArray; /* The class codes (indexed by glyph index minus
|
2018-11-06 21:23:18 +01:00
|
|
|
* firstGlyph). */
|
2018-10-30 16:11:34 +01:00
|
|
|
public:
|
2018-11-06 21:23:18 +01:00
|
|
|
DEFINE_SIZE_ARRAY (4, classArray);
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 17:51:40 +01:00
|
|
|
struct ObsoleteTypes
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool extended = false;
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef HBUINT16 HBUINT;
|
|
|
|
typedef HBUINT8 HBUSHORT;
|
2018-11-28 20:51:56 +01:00
|
|
|
typedef ClassTable<HBUINT8> ClassTypeNarrow;
|
|
|
|
typedef ClassTable<HBUINT16> ClassTypeWide;
|
2018-11-28 20:46:26 +01:00
|
|
|
|
2018-10-31 23:09:09 +01:00
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int offsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
2018-10-31 23:09:09 +01:00
|
|
|
{
|
2022-06-30 00:32:30 +02:00
|
|
|
/* https://github.com/harfbuzz/harfbuzz/issues/3483 */
|
|
|
|
/* If offset is less than base, return an offset that would
|
|
|
|
* result in an address half a 32bit address-space away,
|
|
|
|
* to make sure sanitize fails even on 32bit builds. */
|
2022-07-02 00:20:31 +02:00
|
|
|
if (unlikely (offset < unsigned ((const char *) array - (const char *) base)))
|
2022-06-30 00:32:30 +02:00
|
|
|
return INT_MAX / T::static_size;
|
|
|
|
|
2021-03-22 23:22:15 +01:00
|
|
|
/* https://github.com/harfbuzz/harfbuzz/issues/2816 */
|
|
|
|
return (offset - unsigned ((const char *) array - (const char *) base)) / T::static_size;
|
2018-10-31 23:09:09 +01:00
|
|
|
}
|
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int byteOffsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
2018-11-28 21:24:30 +01:00
|
|
|
{
|
|
|
|
return offsetToIndex (offset, base, array);
|
|
|
|
}
|
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int wordOffsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
2018-10-31 23:09:09 +01:00
|
|
|
{
|
|
|
|
return offsetToIndex (2 * offset, base, array);
|
|
|
|
}
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
2018-11-07 17:51:40 +01:00
|
|
|
struct ExtendedTypes
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool extended = true;
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef HBUINT32 HBUINT;
|
|
|
|
typedef HBUINT16 HBUSHORT;
|
2018-11-28 20:51:56 +01:00
|
|
|
typedef Lookup<HBUINT16> ClassTypeNarrow;
|
|
|
|
typedef Lookup<HBUINT16> ClassTypeWide;
|
2018-11-28 20:46:26 +01:00
|
|
|
|
2018-10-31 23:09:09 +01:00
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int offsetToIndex (unsigned int offset,
|
2018-12-24 02:19:52 +01:00
|
|
|
const void *base HB_UNUSED,
|
|
|
|
const T *array HB_UNUSED)
|
2018-10-31 23:09:09 +01:00
|
|
|
{
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int byteOffsetToIndex (unsigned int offset,
|
2018-12-24 02:19:52 +01:00
|
|
|
const void *base HB_UNUSED,
|
|
|
|
const T *array HB_UNUSED)
|
2018-11-28 21:24:30 +01:00
|
|
|
{
|
|
|
|
return offset / 2;
|
|
|
|
}
|
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int wordOffsetToIndex (unsigned int offset,
|
2018-12-24 02:19:52 +01:00
|
|
|
const void *base HB_UNUSED,
|
|
|
|
const T *array HB_UNUSED)
|
2018-10-31 23:09:09 +01:00
|
|
|
{
|
|
|
|
return offset;
|
|
|
|
}
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Types, typename EntryData>
|
2018-01-12 00:01:36 +01:00
|
|
|
struct StateTableDriver
|
|
|
|
{
|
2021-02-18 20:03:26 +01:00
|
|
|
using StateTableT = StateTable<Types, EntryData>;
|
2021-02-18 20:07:46 +01:00
|
|
|
using EntryT = Entry<EntryData>;
|
2021-02-18 19:15:25 +01:00
|
|
|
|
2021-02-18 20:03:26 +01:00
|
|
|
StateTableDriver (const StateTableT &machine_,
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_buffer_t *buffer_,
|
|
|
|
hb_face_t *face_) :
|
2018-01-12 00:01:36 +01:00
|
|
|
machine (machine_),
|
|
|
|
buffer (buffer_),
|
2018-02-04 20:58:02 +01:00
|
|
|
num_glyphs (face_->get_num_glyphs ()) {}
|
2018-01-12 00:01:36 +01:00
|
|
|
|
|
|
|
template <typename context_t>
|
2023-01-10 05:32:15 +01:00
|
|
|
void drive (context_t *c, hb_aat_apply_context_t *ac)
|
2018-01-12 00:01:36 +01:00
|
|
|
{
|
2018-01-20 03:08:56 +01:00
|
|
|
if (!c->in_place)
|
|
|
|
buffer->clear_output ();
|
|
|
|
|
2021-02-18 20:03:26 +01:00
|
|
|
int state = StateTableT::STATE_START_OF_TEXT;
|
2023-01-10 20:16:04 +01:00
|
|
|
// If there's only one range, we already checked the flag.
|
|
|
|
auto *last_range = ac->range_flags && (ac->range_flags->length > 1) ? &(*ac->range_flags)[0] : nullptr;
|
2018-10-26 02:33:48 +02:00
|
|
|
for (buffer->idx = 0; buffer->successful;)
|
2018-01-12 00:01:36 +01:00
|
|
|
{
|
2023-01-10 20:17:38 +01:00
|
|
|
/* This block is copied in NoncontextualSubtable::apply. Keep in sync. */
|
2023-01-10 05:32:15 +01:00
|
|
|
if (last_range)
|
|
|
|
{
|
|
|
|
auto *range = last_range;
|
|
|
|
if (buffer->idx < buffer->len)
|
|
|
|
{
|
|
|
|
unsigned cluster = buffer->cur().cluster;
|
|
|
|
while (cluster < range->cluster_first)
|
|
|
|
range--;
|
|
|
|
while (cluster > range->cluster_last)
|
|
|
|
range++;
|
|
|
|
|
|
|
|
|
|
|
|
last_range = range;
|
|
|
|
}
|
|
|
|
if (!(range->flags & ac->subtable_flags))
|
|
|
|
{
|
|
|
|
if (buffer->idx == buffer->len || unlikely (!buffer->successful))
|
|
|
|
break;
|
|
|
|
|
2023-01-10 19:03:38 +01:00
|
|
|
state = StateTableT::STATE_START_OF_TEXT;
|
2023-01-10 05:32:15 +01:00
|
|
|
(void) buffer->next_glyph ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-20 03:08:56 +01:00
|
|
|
unsigned int klass = buffer->idx < buffer->len ?
|
2023-01-10 05:32:15 +01:00
|
|
|
machine.get_class (buffer->cur().codepoint, num_glyphs) :
|
2021-02-18 20:03:26 +01:00
|
|
|
(unsigned) StateTableT::CLASS_END_OF_TEXT;
|
2018-11-08 00:04:53 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx);
|
2021-02-18 20:07:46 +01:00
|
|
|
const EntryT &entry = machine.get_entry (state, klass);
|
2023-01-10 02:14:40 +01:00
|
|
|
const int next_state = machine.new_state (entry.newState);
|
2018-01-12 00:01:36 +01:00
|
|
|
|
2021-02-18 20:07:46 +01:00
|
|
|
/* Conditions under which it's guaranteed safe-to-break before current glyph:
|
2018-10-06 21:31:44 +02:00
|
|
|
*
|
2021-02-18 20:07:46 +01:00
|
|
|
* 1. There was no action in this transition; and
|
|
|
|
*
|
|
|
|
* 2. If we break before current glyph, the results will be the same. That
|
|
|
|
* is guaranteed if:
|
|
|
|
*
|
|
|
|
* 2a. We were already in start-of-text state; or
|
|
|
|
*
|
|
|
|
* 2b. We are epsilon-transitioning to start-of-text state; or
|
|
|
|
*
|
|
|
|
* 2c. Starting from start-of-text state seeing current glyph:
|
|
|
|
*
|
|
|
|
* 2c'. There won't be any actions; and
|
|
|
|
*
|
|
|
|
* 2c". We would end up in the same state that we were going to end up
|
|
|
|
* in now, including whether epsilon-transitioning.
|
|
|
|
*
|
|
|
|
* and
|
|
|
|
*
|
|
|
|
* 3. If we break before current glyph, there won't be any end-of-text action
|
|
|
|
* after previous glyph.
|
|
|
|
*
|
|
|
|
* This triples the transitions we need to look up, but is worth returning
|
|
|
|
* granular unsafe-to-break results. See eg.:
|
|
|
|
*
|
|
|
|
* https://github.com/harfbuzz/harfbuzz/issues/2860
|
|
|
|
*/
|
|
|
|
const EntryT *wouldbe_entry;
|
|
|
|
bool safe_to_break =
|
|
|
|
/* 1. */
|
|
|
|
!c->is_actionable (this, entry)
|
|
|
|
&&
|
|
|
|
/* 2. */
|
|
|
|
(
|
|
|
|
/* 2a. */
|
|
|
|
state == StateTableT::STATE_START_OF_TEXT
|
|
|
|
||
|
|
|
|
/* 2b. */
|
|
|
|
(
|
|
|
|
(entry.flags & context_t::DontAdvance) &&
|
|
|
|
next_state == StateTableT::STATE_START_OF_TEXT
|
|
|
|
)
|
|
|
|
||
|
|
|
|
/* 2c. */
|
|
|
|
(
|
|
|
|
wouldbe_entry = &machine.get_entry (StateTableT::STATE_START_OF_TEXT, klass)
|
|
|
|
,
|
|
|
|
/* 2c'. */
|
|
|
|
!c->is_actionable (this, *wouldbe_entry)
|
|
|
|
&&
|
|
|
|
/* 2c". */
|
|
|
|
(
|
|
|
|
next_state == machine.new_state (wouldbe_entry->newState)
|
|
|
|
&&
|
|
|
|
(entry.flags & context_t::DontAdvance) == (wouldbe_entry->flags & context_t::DontAdvance)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
&&
|
|
|
|
/* 3. */
|
|
|
|
!c->is_actionable (this, machine.get_entry (state, StateTableT::CLASS_END_OF_TEXT))
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!safe_to_break && buffer->backtrack_len () && buffer->idx < buffer->len)
|
|
|
|
buffer->unsafe_to_break_from_outbuffer (buffer->backtrack_len () - 1, buffer->idx + 1);
|
2018-02-04 20:58:02 +01:00
|
|
|
|
2023-01-10 02:14:40 +01:00
|
|
|
c->transition (this, entry);
|
2018-01-12 11:09:21 +01:00
|
|
|
|
2021-02-18 20:07:46 +01:00
|
|
|
state = next_state;
|
2018-11-07 22:42:16 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "s%d", state);
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2021-02-18 17:31:46 +01:00
|
|
|
if (buffer->idx == buffer->len || unlikely (!buffer->successful))
|
2018-10-31 04:51:44 +01:00
|
|
|
break;
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0)
|
2021-03-15 22:18:06 +01:00
|
|
|
(void) buffer->next_glyph ();
|
2018-01-12 00:01:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 11:42:25 +01:00
|
|
|
if (!c->in_place)
|
2022-01-04 18:52:05 +01:00
|
|
|
buffer->sync ();
|
2018-01-12 00:01:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-02-18 20:03:26 +01:00
|
|
|
const StateTableT &machine;
|
2018-01-12 00:01:36 +01:00
|
|
|
hb_buffer_t *buffer;
|
|
|
|
unsigned int num_glyphs;
|
|
|
|
};
|
|
|
|
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2017-08-18 01:55:54 +02:00
|
|
|
} /* namespace AAT */
|
|
|
|
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#endif /* HB_AAT_LAYOUT_COMMON_HH */
|