Merge remote-tracking branch 'upstream/master' into var-subset

This commit is contained in:
Ebrahim Byagowi 2019-10-06 09:18:22 +03:30
commit 100dbccaa5
8 changed files with 328 additions and 358 deletions

View File

@ -76,7 +76,6 @@ HB_BASE_sources = \
hb-ot-head-table.hh \
hb-ot-hhea-table.hh \
hb-ot-hmtx-table.hh \
hb-ot-hmtx-table.cc \
hb-ot-kern-table.hh \
hb-ot-layout-base-table.hh \
hb-ot-layout-common.hh \
@ -137,6 +136,7 @@ HB_BASE_sources = \
hb-ot-tag.cc \
hb-ot-var-avar-table.hh \
hb-ot-var-fvar-table.hh \
hb-ot-var-gvar-table.hh \
hb-ot-var-hvar-table.hh \
hb-ot-var-mvar-table.hh \
hb-ot-var-gvar-table.hh \

View File

@ -14,7 +14,6 @@
#include "hb-ot-color.cc"
#include "hb-ot-face.cc"
#include "hb-ot-font.cc"
#include "hb-ot-hmtx-table.cc"
#include "hb-ot-layout.cc"
#include "hb-ot-map.cc"
#include "hb-ot-math.cc"

View File

@ -84,6 +84,7 @@ HB_OT_TABLE (OT, VORG)
#ifndef HB_NO_VAR
HB_OT_TABLE (OT, fvar)
HB_OT_TABLE (OT, avar)
HB_OT_ACCELERATOR (OT, gvar)
HB_OT_TABLE (OT, MVAR)
#endif

View File

@ -316,5 +316,19 @@ hb_ot_font_set_funcs (hb_font_t *font)
nullptr);
}
#ifndef HB_NO_VAR
int
hb_ot_get_side_bearing_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical)
{
return font->face->table.glyf->get_side_bearing_var (glyph, font->coords, font->num_coords, is_vertical);
}
unsigned
hb_ot_get_advance_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical)
{
return font->face->table.glyf->get_advance_var (glyph, font->coords, font->num_coords, is_vertical);
}
#endif
#endif

View File

@ -60,7 +60,8 @@ struct loca
}
protected:
UnsizedArrayOf<HBUINT8> dataZ; /* Location data. */
UnsizedArrayOf<HBUINT8>
dataZ; /* Location data. */
public:
DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always
* check the size externally, allow Null() object of it by
@ -103,6 +104,7 @@ struct glyf
DEBUG_MSG (SUBSET, nullptr, "loca entry_size %d num_offsets %d "
"max_offset %d size %d",
entry_size, num_offsets, max_offset, entry_size * num_offsets);
if (use_short_loca)
_write_loca (padded_offsets, 1, hb_array ((HBUINT16*) loca_prime_data, num_offsets));
else
@ -231,13 +233,11 @@ struct glyf
_zero_instruction_length (hb_bytes_t glyph)
{
const GlyphHeader &glyph_header = *glyph.as<GlyphHeader> ();
int16_t num_contours = (int16_t) glyph_header.numberOfContours;
if (num_contours <= 0) return; // only for simple glyphs
if (!glyph_header.is_simple_glyph ()) return; // only for simple glyphs
unsigned int contours_length = GlyphHeader::static_size + 2 * num_contours;
const HBUINT16 &instruction_length = StructAtOffset<HBUINT16> (&glyph,
contours_length);
(HBUINT16 &) instruction_length = 0;
unsigned int instruction_len_offset = glyph_header.simple_instruction_len_offset ();
const HBUINT16 &instruction_len = StructAtOffset<HBUINT16> (&glyph, instruction_len_offset);
(HBUINT16 &) instruction_len = 0;
}
static bool _remove_composite_instruction_flag (hb_bytes_t glyph)
@ -291,7 +291,8 @@ struct glyf
bool has_data () const { return numberOfContours; }
HBINT16 numberOfContours; /* If the number of contours is
HBINT16 numberOfContours;
/* If the number of contours is
* greater than or equal to zero,
* this is a simple glyph; if negative,
* this is a composite glyph. */
@ -404,25 +405,28 @@ struct glyf
trans.init ((float) tx, (float) ty);
{
const F2DOT14 *points = (const F2DOT14 *) p;
if (flags & WE_HAVE_A_SCALE)
{
matrix[0] = matrix[3] = ((const F2DOT14*)p)->to_float ();
matrix[0] = matrix[3] = points[0].to_float ();
return true;
}
else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
{
matrix[0] = ((const F2DOT14*)p)[0].to_float ();
matrix[3] = ((const F2DOT14*)p)[1].to_float ();
matrix[0] = points[0].to_float ();
matrix[3] = points[1].to_float ();
return true;
}
else if (flags & WE_HAVE_A_TWO_BY_TWO)
{
matrix[0] = ((const F2DOT14*)p)[0].to_float ();
matrix[1] = ((const F2DOT14*)p)[1].to_float ();
matrix[2] = ((const F2DOT14*)p)[2].to_float ();
matrix[3] = ((const F2DOT14*)p)[3].to_float ();
matrix[0] = points[0].to_float ();
matrix[1] = points[1].to_float ();
matrix[2] = points[2].to_float ();
matrix[3] = points[3].to_float ();
return true;
}
}
return tx || ty;
}
@ -483,10 +487,13 @@ struct glyf
struct accelerator_t
{
void init (hb_face_t *face)
void init (hb_face_t *face_)
{
memset (this, 0, sizeof (accelerator_t));
short_offset = false;
num_glyphs = 0;
loca_table = nullptr;
glyf_table = nullptr;
face = face_;
const OT::head &head = *face->table.head;
if (head.indexToLocFormat > 1 || head.glyphDataFormat != 0)
/* Unknown format. Leave num_glyphs=0, that takes care of disabling us. */
@ -497,19 +504,12 @@ struct glyf
glyf_table = hb_sanitize_context_t ().reference_table<glyf> (face);
num_glyphs = hb_max (1u, loca_table.get_length () / (short_offset ? 2 : 4)) - 1;
gvar_accel.init (face);
hmtx_accel.init (face);
vmtx_accel.init (face);
}
void fini ()
{
loca_table.destroy ();
glyf_table.destroy ();
gvar_accel.fini ();
hmtx_accel.fini ();
vmtx_accel.fini ();
}
/*
@ -544,7 +544,8 @@ struct glyf
FLAG_RESERVED2 = 0x80
};
enum phantom_point_index_t {
enum phantom_point_index_t
{
PHANTOM_LEFT = 0,
PHANTOM_RIGHT = 1,
PHANTOM_TOP = 2,
@ -565,15 +566,15 @@ struct glyf
struct x_setter_t
{
void set (contour_point_t &point, float v) const { point.x = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_X_SHORT) != 0; }
bool is_same (uint8_t flag) const { return (flag & FLAG_X_SAME) != 0; }
bool is_short (uint8_t flag) const { return flag & FLAG_X_SHORT; }
bool is_same (uint8_t flag) const { return flag & FLAG_X_SAME; }
};
struct y_setter_t
{
void set (contour_point_t &point, float v) const { point.y = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_Y_SHORT) != 0; }
bool is_same (uint8_t flag) const { return (flag & FLAG_Y_SAME) != 0; }
bool is_short (uint8_t flag) const { return flag & FLAG_Y_SHORT; }
bool is_same (uint8_t flag) const { return flag & FLAG_Y_SAME; }
};
template <typename T>
@ -611,15 +612,15 @@ struct glyf
void init_phantom_points (hb_codepoint_t glyph, hb_array_t<contour_point_t> &phantoms /* IN/OUT */) const
{
const GlyphHeader &header = get_header (glyph);
int h_delta = (int)header.xMin - hmtx_accel.get_side_bearing (glyph);
int v_orig = (int)header.yMax + vmtx_accel.get_side_bearing (glyph);
unsigned int h_adv = hmtx_accel.get_advance (glyph);
unsigned int v_adv = vmtx_accel.get_advance (glyph);
int h_delta = (int) header.xMin - face->table.hmtx->get_side_bearing (glyph);
int v_orig = (int) header.yMax + face->table.vmtx->get_side_bearing (glyph);
unsigned int h_adv = face->table.hmtx->get_advance (glyph);
unsigned int v_adv = face->table.vmtx->get_advance (glyph);
phantoms[PHANTOM_LEFT].x = h_delta;
phantoms[PHANTOM_RIGHT].x = h_adv + h_delta;
phantoms[PHANTOM_TOP].y = v_orig;
phantoms[PHANTOM_BOTTOM].y = -(int)v_adv + v_orig;
phantoms[PHANTOM_BOTTOM].y = v_orig - (int) v_adv;
}
/* for a simple glyph, return contour end points, flags, along with coordinate points
@ -653,17 +654,17 @@ struct glyf
}
const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset);
int16_t num_contours = (int16_t) glyph_header.numberOfContours;
int num_contours = glyph_header.numberOfContours;
const HBUINT16 *end_pts = &StructAfter<HBUINT16, GlyphHeader> (glyph_header);
range_checker_t checker (glyf_table, start_offset, end_offset);
num_points = 0;
if (num_contours > 0)
if (glyph_header.is_simple_glyph ())
{
if (unlikely (!checker.in_range (&end_pts[num_contours + 1]))) return false;
num_points = end_pts[num_contours - 1] + 1;
num_points = end_pts[glyph_header.numberOfContours - 1] + 1;
}
else if (num_contours < 0)
else if (glyph_header.is_composite_glyph ())
{
CompositeGlyphHeader::Iterator composite;
if (unlikely (!get_composite (glyph, &composite))) return false;
@ -675,16 +676,17 @@ struct glyf
points_.resize (num_points + PHANTOM_COUNT);
for (unsigned int i = 0; i < points_.length; i++) points_[i].init ();
if ((num_contours <= 0) || phantom_only) return true;
if (!glyph_header.is_simple_glyph () || phantom_only) return true;
/* Read simple glyph points if !phantom_only */
end_points_.resize (num_contours);
for (int16_t i = 0; i < num_contours; i++)
for (int i = 0; i < num_contours; i++)
end_points_[i] = end_pts[i];
/* Skip instructions */
const HBUINT8 *p = &StructAtOffset<HBUINT8> (&end_pts[num_contours+1], end_pts[num_contours]);
const HBUINT8 *p = &StructAtOffset<HBUINT8> (&end_pts[num_contours+1],
end_pts[num_contours]);
/* Read flags */
for (unsigned int i = 0; i < num_points; i++)
@ -724,6 +726,7 @@ struct glyf
contour_point_t max;
};
#ifndef HB_NO_VAR
/* Note: Recursively calls itself.
* all_points includes phantom points
*/
@ -738,7 +741,7 @@ struct glyf
if (unlikely (!get_contour_points (glyph, points, end_points))) return false;
hb_array_t<contour_point_t> phantoms = points.sub_array (points.length - PHANTOM_COUNT, PHANTOM_COUNT);
init_phantom_points (glyph, phantoms);
if (unlikely (!gvar_accel.apply_deltas_to_points (glyph, coords, coord_count, points.as_array (), end_points.as_array ()))) return false;
if (unlikely (!face->table.gvar->apply_deltas_to_points (glyph, coords, coord_count, points.as_array (), end_points.as_array ()))) return false;
unsigned int comp_index = 0;
CompositeGlyphHeader::Iterator composite;
@ -822,8 +825,8 @@ struct glyf
}
else
{
extents->x_bearing = (int32_t)floorf (bounds.min.x);
extents->width = (int32_t)ceilf (bounds.max.x) - extents->x_bearing;
extents->x_bearing = (int) floor (bounds.min.x);
extents->width = (int) ceil (bounds.max.x) - extents->x_bearing;
}
if (bounds.min.y > bounds.max.y)
{
@ -832,8 +835,8 @@ struct glyf
}
else
{
extents->y_bearing = (int32_t)ceilf (bounds.max.y);
extents->height = (int32_t)floorf (bounds.min.y) - extents->y_bearing;
extents->y_bearing = (int) ceil (bounds.max.y);
extents->height = (int) floor (bounds.min.y) - extents->y_bearing;
}
}
if (phantoms != nullptr)
@ -853,6 +856,7 @@ struct glyf
const int *coords, unsigned int coord_count,
hb_glyph_extents_t *extents) const
{ return get_var_extents_and_phantoms (glyph, coords, coord_count, extents); }
#endif
public:
/* based on FontTools _g_l_y_f.py::trim */
@ -963,11 +967,10 @@ struct glyf
if (!glyph_header.has_data ())
{
*length = 0;
// only 0 byte glyphs are healthy when missing GlyphHeader
/* only 0 byte glyphs are healthy when missing GlyphHeader */
return glyph.length == 0;
}
int16_t num_contours = (int16_t) glyph_header.numberOfContours;
if (num_contours < 0)
if (glyph_header.is_composite_glyph ())
{
unsigned int start = glyph.length;
unsigned int end = glyph.length;
@ -995,14 +998,14 @@ struct glyf
}
else
{
unsigned int instruction_length_offset = GlyphHeader::static_size + 2 * num_contours;
if (unlikely (instruction_length_offset + 2 > glyph.length))
unsigned int instruction_len_offset = glyph_header.simple_instruction_len_offset ();
if (unlikely (instruction_len_offset + 2 > glyph.length))
{
DEBUG_MSG (SUBSET, nullptr, "Glyph size is too short, missing field instructionLength.");
return false;
}
const HBUINT16 &instruction_len = StructAtOffset<HBUINT16> (&glyph, instruction_length_offset);
const HBUINT16 &instruction_len = StructAtOffset<HBUINT16> (&glyph, instruction_len_offset);
/* Out of bounds of the current glyph */
if (unlikely (glyph_header.simple_length (instruction_len) > glyph.length))
{
@ -1014,6 +1017,7 @@ struct glyf
return true;
}
#ifndef HB_NO_VAR
unsigned int get_advance_var (hb_codepoint_t glyph,
const int *coords, unsigned int coord_count,
bool vertical) const
@ -1022,16 +1026,16 @@ struct glyf
contour_point_vector_t phantoms;
phantoms.resize (PHANTOM_COUNT);
if (likely (coord_count == gvar_accel.get_axis_count ()))
if (likely (coord_count == face->table.gvar->get_axis_count ()))
success = get_var_metrics (glyph, coords, coord_count, phantoms);
if (unlikely (!success))
return vertical? vmtx_accel.get_advance (glyph): hmtx_accel.get_advance (glyph);
return vertical ? face->table.vmtx->get_advance (glyph) : face->table.hmtx->get_advance (glyph);
if (vertical)
return (unsigned int)roundf (phantoms[PHANTOM_TOP].y - phantoms[PHANTOM_BOTTOM].y);
return roundf (phantoms[PHANTOM_TOP].y - phantoms[PHANTOM_BOTTOM].y);
else
return (unsigned int)roundf (phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x);
return roundf (phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x);
}
int get_side_bearing_var (hb_codepoint_t glyph, const int *coords, unsigned int coord_count, bool vertical) const
@ -1041,17 +1045,20 @@ struct glyf
phantoms.resize (PHANTOM_COUNT);
if (unlikely (!get_var_extents_and_phantoms (glyph, coords, coord_count, &extents, &phantoms)))
return vertical? vmtx_accel.get_side_bearing (glyph): hmtx_accel.get_side_bearing (glyph);
return vertical ? face->table.vmtx->get_side_bearing (glyph) : face->table.hmtx->get_side_bearing (glyph);
return vertical? (int)ceilf (phantoms[PHANTOM_TOP].y) - extents.y_bearing: (int)floorf (phantoms[PHANTOM_LEFT].x);
return vertical ? ceil (phantoms[PHANTOM_TOP].y) - extents.y_bearing : floor (phantoms[PHANTOM_LEFT].x);
}
#endif
bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
{
#ifndef HB_NO_VAR
unsigned int coord_count;
const int *coords = hb_font_get_var_coords_normalized (font, &coord_count);
if (coords && coord_count > 0 && coord_count == gvar_accel.get_axis_count ())
if (coords && coord_count > 0 && coord_count == face->table.gvar->get_axis_count ())
return get_extents_var (glyph, coords, coord_count, extents);
#endif
unsigned int start_offset, end_offset;
if (!get_offsets (glyph, &start_offset, &end_offset))
@ -1064,7 +1071,7 @@ struct glyf
/* Undocumented rasterizer behavior: shift glyph to the left by (lsb - xMin), i.e., xMin = lsb */
/* extents->x_bearing = hb_min (glyph_header.xMin, glyph_header.xMax); */
extents->x_bearing = hmtx_accel.get_side_bearing (glyph);
extents->x_bearing = face->table.hmtx->get_side_bearing (glyph);
extents->y_bearing = hb_max (glyph_header.yMin, glyph_header.yMax);
extents->width = hb_max (glyph_header.xMin, glyph_header.xMax) - hb_min (glyph_header.xMin, glyph_header.xMax);
extents->height = hb_min (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing;
@ -1095,11 +1102,7 @@ struct glyf
unsigned int num_glyphs;
hb_blob_ptr_t<loca> loca_table;
hb_blob_ptr_t<glyf> glyf_table;
/* variable font support */
gvar::accelerator_t gvar_accel;
hmtx::accelerator_t hmtx_accel;
vmtx::accelerator_t vmtx_accel;
hb_face_t *face;
};
@ -1108,9 +1111,8 @@ struct glyf
hb_codepoint_t new_gid;
hb_codepoint_t old_gid;
hb_bytes_t source_glyph;
hb_bytes_t dest_start; // region of source_glyph to copy first
hb_bytes_t dest_end; // region of source_glyph to copy second
hb_bytes_t dest_start; /* region of source_glyph to copy first */
hb_bytes_t dest_end; /* region of source_glyph to copy second */
bool serialize (hb_serialize_context_t *c,
const hb_subset_plan_t *plan) const

View File

@ -1,54 +0,0 @@
/*
* Copyright © 2019 Adobe 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.
*
* Adobe Author(s): Michiharu Ariza
*/
#include "hb-ot-hmtx-table.hh"
#include "hb-ot-glyf-table.hh"
namespace OT {
int hmtxvmtx_accelerator_base_t::get_side_bearing_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool vertical)
{
glyf::accelerator_t glyf_accel;
glyf_accel.init (font->face);
int side_bearing = glyf_accel.get_side_bearing_var (glyph, font->coords, font->num_coords, vertical);
glyf_accel.fini ();
return side_bearing;
}
unsigned int hmtxvmtx_accelerator_base_t::get_advance_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool vertical)
{
glyf::accelerator_t glyf_accel;
glyf_accel.init (font->face);
unsigned int advance = glyf_accel.get_advance_var (glyph, font->coords, font->num_coords, vertical);
glyf_accel.fini ();
return advance;
}
}

View File

@ -42,6 +42,13 @@
#define HB_OT_TAG_vmtx HB_TAG('v','m','t','x')
HB_INTERNAL int
hb_ot_get_side_bearing_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical);
HB_INTERNAL unsigned
hb_ot_get_advance_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical);
namespace OT {
@ -53,11 +60,6 @@ struct LongMetric
DEFINE_SIZE_STATIC (4);
};
struct hmtxvmtx_accelerator_base_t
{
HB_INTERNAL static int get_side_bearing_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool vertical);
HB_INTERNAL static unsigned int get_advance_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool vertical);
};
template <typename T, typename H>
struct hmtxvmtx
@ -136,10 +138,9 @@ struct hmtxvmtx
| hb_map ([c, &_mtx] (unsigned _)
{
hb_codepoint_t old_gid;
if (c->plan->old_gid_for_new_gid (_, &old_gid))
return hb_pair (_mtx.get_advance (old_gid), _mtx.get_side_bearing (old_gid));
else
if (!c->plan->old_gid_for_new_gid (_, &old_gid))
return hb_pair (0u, 0);
return hb_pair (_mtx.get_advance (old_gid), _mtx.get_side_bearing (old_gid));
})
;
@ -152,14 +153,12 @@ struct hmtxvmtx
// Amend header num hmetrics
if (unlikely (!subset_update_header (c->plan, num_advances)))
{
return_trace (false);
}
return_trace (true);
}
struct accelerator_t : hmtxvmtx_accelerator_base_t
struct accelerator_t
{
friend struct hmtxvmtx;
@ -213,13 +212,17 @@ struct hmtxvmtx
{
int side_bearing = get_side_bearing (glyph);
#ifndef HB_NO_VAR
if (unlikely (glyph >= num_metrics) || !font->num_coords)
return side_bearing;
if (var_table.get_blob () == &Null (hb_blob_t))
return get_side_bearing_var_tt (font, glyph, T::tableTag == HB_OT_TAG_vmtx);
return hb_ot_get_side_bearing_var_tt (font, glyph, T::tableTag == HB_OT_TAG_vmtx);
return side_bearing + var_table->get_side_bearing_var (glyph, font->coords, font->num_coords); // TODO Optimize?!
#else
return side_bearing;
#endif
}
unsigned int get_advance (hb_codepoint_t glyph) const
@ -243,13 +246,17 @@ struct hmtxvmtx
{
unsigned int advance = get_advance (glyph);
#ifndef HB_NO_VAR
if (unlikely (glyph >= num_metrics) || !font->num_coords)
return advance;
if (var_table.get_blob () == &Null (hb_blob_t))
return get_advance_var_tt (font, glyph, T::tableTag == HB_OT_TAG_vmtx);
return hb_ot_get_advance_var_tt (font, glyph, T::tableTag == HB_OT_TAG_vmtx);
return advance + roundf (var_table->get_advance_var (glyph, font->coords, font->num_coords)); // TODO Optimize?!
#else
return advance;
#endif
}
unsigned int num_advances_for_subset (const hb_subset_plan_t *plan) const

View File

@ -1,5 +1,6 @@
/*
* Copyright © 2019 Adobe Inc.
* Copyright © 2019 Ebrahim Byagowi
*
* This is part of HarfBuzz, a text shaping library.
*
@ -202,7 +203,8 @@ struct TupleVarCount : HBUINT16
unsigned int get_count () const { return (*this) & CountMask; }
protected:
enum Flags {
enum Flags
{
SharedPointNumbers = 0x8000u,
CountMask = 0x0FFFu
};
@ -299,11 +301,12 @@ struct GlyphVarData
POINT_RUN_COUNT_MASK = 0x7F
};
if (!check.in_range (p)) return false;
if (unlikely (!check.in_range (p))) return false;
uint16_t count = *p++;
if (count & POINTS_ARE_WORDS)
{
if (!check.in_range (p)) return false;
if (unlikely (!check.in_range (p))) return false;
count = ((count & POINT_RUN_COUNT_MASK) << 8) | *p++;
}
points.resize (count);
@ -312,7 +315,7 @@ struct GlyphVarData
uint16_t i = 0;
while (i < count)
{
if (!check.in_range (p)) return false;
if (unlikely (!check.in_range (p))) return false;
uint16_t j;
uint8_t control = *p++;
uint16_t run_count = (control & POINT_RUN_COUNT_MASK) + 1;
@ -320,7 +323,8 @@ struct GlyphVarData
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range ((const HBUINT16 *)p)) return false;
if (unlikely (!check.in_range ((const HBUINT16 *) p)))
return false;
n += *(const HBUINT16 *)p;
points[i] = n;
p += HBUINT16::static_size;
@ -330,7 +334,7 @@ struct GlyphVarData
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range (p)) return false;
if (unlikely (!check.in_range (p))) return false;
n += *p++;
points[i] = n;
}
@ -355,34 +359,28 @@ struct GlyphVarData
unsigned int count = deltas.length;
while (i < count)
{
if (!check.in_range (p)) return false;
uint16_t j;
if (unlikely (!check.in_range (p))) return false;
uint8_t control = *p++;
uint16_t run_count = (control & DELTA_RUN_COUNT_MASK) + 1;
unsigned int run_count = (control & DELTA_RUN_COUNT_MASK) + 1;
unsigned int j;
if (control & DELTAS_ARE_ZERO)
{
for (j = 0; j < run_count && i < count; j++, i++)
deltas[i] = 0;
}
else if (control & DELTAS_ARE_WORDS)
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range ((const HBUINT16 *)p))
if (unlikely (!check.in_range ((const HBUINT16 *) p)))
return false;
deltas[i] = *(const HBINT16 *) p;
p += HBUINT16::static_size;
}
}
else
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range (p))
if (unlikely (!check.in_range (p)))
return false;
deltas[i] = *(const HBINT8 *) p++;
}
}
if (j < run_count)
return false;
}
@ -393,7 +391,6 @@ struct GlyphVarData
TupleVarCount tupleVarCount;
OffsetTo<HBUINT8> data;
/* TupleVarHeader tupleVarHeaders[] */
public:
DEFINE_SIZE_MIN (4);
};
@ -527,8 +524,6 @@ struct gvar
{
void init (hb_face_t *face)
{
memset (this, 0, sizeof (accelerator_t));
gvar_table = hb_sanitize_context_t ().reference_table<gvar> (face);
hb_blob_ptr_t<fvar> fvar_table = hb_sanitize_context_t ().reference_table<fvar> (face);
unsigned int axis_count = fvar_table->get_axis_count ();
@ -608,7 +603,8 @@ struct gvar
contour_point_vector_t deltas; /* flag is used to indicate referenced point */
deltas.resize (points.length);
do {
do
{
float scalar = iterator.current_tuple->calculate_scalar (coords, coord_count, shared_tuples.as_array ());
if (scalar == 0.f) continue;
const HBUINT8 *p = iterator.get_serialized_data ();
@ -665,13 +661,15 @@ struct gvar
* Note that a gap may wrap around at left (start_point) and/or at right (end_point).
*/
unsigned int prev, next;
for (;;) {
for (;;)
{
i = j;
j = next_index (i, start_point, end_point);
if (deltas[i].flag && !deltas[j].flag) break;
}
prev = j = i;
for (;;) {
for (;;)
{
i = j;
j = next_index (i, start_point, end_point);
if (!deltas[i].flag && deltas[j].flag) break;
@ -679,7 +677,8 @@ struct gvar
next = j;
/* Infer deltas for all unref points in the gap between prev and next */
i = prev;
for (;;) {
for (;;)
{
i = next_index (i, start_point, end_point);
if (i == next) break;
deltas[i].x = infer_delta<x_getter> (orig_points.as_array (), deltas.as_array (), i, prev, next);
@ -694,8 +693,8 @@ no_more_gaps:
/* apply specified / inferred deltas to points */
for (unsigned int i = 0; i < points.length; i++)
{
points[i].x += roundf (deltas[i].x);
points[i].y += roundf (deltas[i].y);
points[i].x += (float) roundf (deltas[i].x);
points[i].y += (float) roundf (deltas[i].y);
}
} while (iterator.move_to_next ());
@ -717,12 +716,14 @@ no_more_gaps:
FixedVersion<>version; /* Version of gvar table. Set to 0x00010000u. */
HBUINT16 axisCount;
HBUINT16 sharedTupleCount;
LOffsetTo<F2DOT14> sharedTuples; /* LOffsetTo<UnsizedArrayOf<Tupple>> */
LOffsetTo<F2DOT14>
sharedTuples; /* LOffsetTo<UnsizedArrayOf<Tupple>> */
HBUINT16 glyphCount;
HBUINT16 flags;
LOffsetTo<GlyphVarData> dataZ; /* Array of GlyphVarData */
UnsizedArrayOf<HBUINT8> offsetZ; /* Array of 16-bit or 32-bit (glyphCount+1) offsets */
LOffsetTo<GlyphVarData>
dataZ; /* Array of GlyphVarData */
UnsizedArrayOf<HBUINT8>
offsetZ; /* Array of 16-bit or 32-bit (glyphCount+1) offsets */
public:
DEFINE_SIZE_MIN (20);
};