diff --git a/src/Makefile.sources b/src/Makefile.sources index 07bbd0652..22980c93f 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -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 \ diff --git a/src/harfbuzz.cc b/src/harfbuzz.cc index 2aa5a7942..fe1c36023 100644 --- a/src/harfbuzz.cc +++ b/src/harfbuzz.cc @@ -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" diff --git a/src/hb-ot-face-table-list.hh b/src/hb-ot-face-table-list.hh index 30bab5cb5..6fa9baf13 100644 --- a/src/hb-ot-face-table-list.hh +++ b/src/hb-ot-face-table-list.hh @@ -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 diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 5b6fe27c9..d2bea8a01 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -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 diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 5ee3c270a..a7b934da2 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -23,7 +23,7 @@ * 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, Garret Rieger, Roderick Sheeter + * Google Author(s): Behdad Esfahbod, Garret Rieger, Roderick Sheeter * Adobe Author(s): Michiharu Ariza */ @@ -60,11 +60,12 @@ struct loca } protected: - UnsizedArrayOf dataZ; /* Location data. */ + UnsizedArrayOf + 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 - * defining it _MIN instead. */ + DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always + * check the size externally, allow Null() object of it by + * defining it _MIN instead. */ }; @@ -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 @@ -115,7 +117,7 @@ struct glyf free); bool result = plan->add_table (HB_OT_TAG_loca, loca_blob) - && _add_head_and_set_loca_version( plan, use_short_loca); + && _add_head_and_set_loca_version (plan, use_short_loca); hb_blob_destroy (loca_blob); return result; @@ -231,13 +233,11 @@ struct glyf _zero_instruction_length (hb_bytes_t glyph) { const GlyphHeader &glyph_header = *glyph.as (); - 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 (&glyph, - contours_length); - (HBUINT16 &) instruction_length = 0; + unsigned int instruction_len_offset = glyph_header.simple_instruction_len_offset (); + const HBUINT16 &instruction_len = StructAtOffset (&glyph, instruction_len_offset); + (HBUINT16 &) instruction_len = 0; } static bool _remove_composite_instruction_flag (hb_bytes_t glyph) @@ -291,14 +291,15 @@ struct glyf bool has_data () const { return numberOfContours; } - 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. */ - FWORD xMin; /* Minimum x for coordinate data. */ - FWORD yMin; /* Minimum y for coordinate data. */ - FWORD xMax; /* Maximum x for coordinate data. */ - FWORD yMax; /* Maximum y for coordinate data. */ + 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. */ + FWORD xMin; /* Minimum x for coordinate data. */ + FWORD yMin; /* Minimum y for coordinate data. */ + FWORD xMax; /* Maximum x for coordinate data. */ + FWORD yMax; /* Maximum y for coordinate data. */ DEFINE_SIZE_STATIC (10); }; @@ -321,8 +322,8 @@ struct glyf UNSCALED_COMPONENT_OFFSET = 0x1000 }; - HBUINT16 flags; - HBGlyphID glyphIndex; + HBUINT16 flags; + HBGlyphID glyphIndex; unsigned int get_size () const { @@ -348,8 +349,8 @@ struct glyf const HBUINT8 *p = &StructAfter (glyphIndex); if (flags & ARG_1_AND_2_ARE_WORDS) { - point1 = ((const HBUINT16 *)p)[0]; - point2 = ((const HBUINT16 *)p)[1]; + point1 = ((const HBUINT16 *) p)[0]; + point2 = ((const HBUINT16 *) p)[1]; } else { @@ -379,7 +380,7 @@ struct glyf protected: bool scaled_offsets () const - { return (flags & (SCALED_COMPONENT_OFFSET|UNSCALED_COMPONENT_OFFSET)) == SCALED_COMPONENT_OFFSET; } + { return (flags & (SCALED_COMPONENT_OFFSET | UNSCALED_COMPONENT_OFFSET)) == SCALED_COMPONENT_OFFSET; } bool get_transformation (float (&matrix)[4], contour_point_t &trans) const { @@ -390,9 +391,9 @@ struct glyf const HBINT8 *p = &StructAfter (glyphIndex); if (flags & ARG_1_AND_2_ARE_WORDS) { - tx = *(const HBINT16 *)p; + tx = *(const HBINT16 *) p; p += HBINT16::static_size; - ty = *(const HBINT16 *)p; + ty = *(const HBINT16 *) p; p += HBINT16::static_size; } else @@ -402,26 +403,29 @@ struct glyf } if (is_anchored ()) tx = ty = 0; - trans.init ((float)tx, (float)ty); + trans.init ((float) tx, (float) ty); - if (flags & WE_HAVE_A_SCALE) { - matrix[0] = matrix[3] = ((const F2DOT14*)p)->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 (); - 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 (); - return true; + const F2DOT14 *points = (const F2DOT14 *) p; + if (flags & WE_HAVE_A_SCALE) + { + matrix[0] = matrix[3] = points[0].to_float (); + return true; + } + else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) + { + 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] = 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; } @@ -450,8 +454,8 @@ struct glyf bool in_range (const CompositeGlyphHeader *composite) const { return (const char *) composite >= glyph_start - && ((const char *) composite + CompositeGlyphHeader::min_size) <= glyph_end - && ((const char *) composite + composite->get_size ()) <= glyph_end; + && ((const char *) composite + CompositeGlyphHeader::min_size) <= glyph_end + && ((const char *) composite + composite->get_size ()) <= glyph_end; } }; @@ -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 (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, @@ -557,7 +558,7 @@ struct glyf { unsigned int start_offset, end_offset; if (!get_offsets (glyph, &start_offset, &end_offset) || end_offset - start_offset < GlyphHeader::static_size) - return Null(GlyphHeader); + return Null (GlyphHeader); return StructAtOffset (glyf_table, start_offset); } @@ -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 @@ -585,9 +586,9 @@ struct glyf float v = 0; for (unsigned int i = 0; i < points_.length - PHANTOM_COUNT; i++) { - uint8_t flag = points_[i].flag; - if (coord_setter.is_short (flag)) - { + uint8_t flag = points_[i].flag; + if (coord_setter.is_short (flag)) + { if (unlikely (!checker.in_range (p))) return false; if (coord_setter.is_same (flag)) v += *p++; @@ -599,7 +600,7 @@ struct glyf if (!coord_setter.is_same (flag)) { if (unlikely (!checker.in_range ((const HBUINT16 *)p))) return false; - v += *(const HBINT16 *)p; + v += *(const HBINT16 *) p; p += HBINT16::static_size; } } @@ -611,15 +612,15 @@ struct glyf void init_phantom_points (hb_codepoint_t glyph, hb_array_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 @@ -636,16 +637,16 @@ struct glyf if (unlikely (!get_offsets (glyph, &start_offset, &end_offset))) return false; if (unlikely (end_offset - start_offset < GlyphHeader::static_size)) { - /* empty glyph */ + /* empty glyph */ points_.resize (PHANTOM_COUNT); for (unsigned int i = 0; i < points_.length; i++) points_[i].init (); - return true; + return true; } CompositeGlyphHeader::Iterator composite; if (get_composite (glyph, &composite)) { - /* For a composite glyph, add one pseudo point for each component */ + /* For a composite glyph, add one pseudo point for each component */ do { num_points++; } while (composite.move_to_next()); points_.resize (num_points + PHANTOM_COUNT); for (unsigned int i = 0; i < points_.length; i++) points_[i].init (); @@ -653,17 +654,17 @@ struct glyf } const GlyphHeader &glyph_header = StructAtOffset (glyf_table, start_offset); - int16_t num_contours = (int16_t) glyph_header.numberOfContours; + int num_contours = glyph_header.numberOfContours; const HBUINT16 *end_pts = &StructAfter (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,22 +676,23 @@ 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++) - end_points_[i] = end_pts[i]; + for (int i = 0; i < num_contours; i++) + end_points_[i] = end_pts[i]; /* Skip instructions */ - const HBUINT8 *p = &StructAtOffset (&end_pts[num_contours+1], end_pts[num_contours]); + const HBUINT8 *p = &StructAtOffset (&end_pts[num_contours+1], + end_pts[num_contours]); /* Read flags */ for (unsigned int i = 0; i < num_points; i++) { - if (unlikely (!checker.in_range (p))) return false; - uint8_t flag = *p++; + if (unlikely (!checker.in_range (p))) return false; + uint8_t flag = *p++; points_[i].flag = flag; if ((flag & FLAG_REPEAT) != 0) { @@ -712,10 +714,10 @@ struct glyf void add (const contour_point_t &p) { - min.x = hb_min (min.x, p.x); - min.y = hb_min (min.y, p.y); - max.x = hb_max (max.x, p.x); - max.y = hb_max (max.y, p.y); + min.x = hb_min (min.x, p.x); + min.y = hb_min (min.y, p.y); + max.x = hb_max (max.x, p.x); + max.y = hb_max (max.y, p.y); } bool empty () const { return (min.x >= max.x) || (min.y >= max.y); } @@ -724,6 +726,7 @@ struct glyf contour_point_t max; }; +#ifndef HB_NO_VAR /* Note: Recursively calls itself. * all_points includes phantom points */ @@ -733,18 +736,18 @@ struct glyf unsigned int depth=0) const { if (unlikely (depth++ > HB_MAX_NESTING_LEVEL)) return false; - contour_point_vector_t points; - hb_vector_t end_points; + contour_point_vector_t points; + hb_vector_t end_points; if (unlikely (!get_contour_points (glyph, points, end_points))) return false; - hb_array_t phantoms = points.sub_array (points.length-PHANTOM_COUNT, PHANTOM_COUNT); + hb_array_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; if (!get_composite (glyph, &composite)) { - /* simple glyph */ + /* simple glyph */ all_points.extend (points.as_array ()); } else @@ -754,8 +757,8 @@ struct glyf { contour_point_vector_t comp_points; if (unlikely (!get_points_var (composite.current->glyphIndex, coords, coord_count, - comp_points, depth)) - || comp_points.length < PHANTOM_COUNT) return false; + comp_points, depth)) + || comp_points.length < PHANTOM_COUNT) return false; /* Copy phantom points from component if USE_MY_METRICS flag set */ if (composite.current->flags & CompositeGlyphHeader::USE_MY_METRICS) @@ -776,7 +779,7 @@ struct glyf { contour_point_t delta; delta.init (all_points[p1].x - comp_points[p2].x, - all_points[p1].y - comp_points[p2].y); + all_points[p1].y - comp_points[p2].y); comp_points.translate (delta); } @@ -800,7 +803,7 @@ struct glyf { contour_point_vector_t all_points; if (unlikely (!get_points_var (glyph, coords, coord_count, all_points) || - all_points.length < PHANTOM_COUNT)) return false; + all_points.length < PHANTOM_COUNT)) return false; /* Undocumented rasterizer behavior: * Shift points horizontally by the updated left side bearing @@ -811,7 +814,7 @@ struct glyf if (extents != nullptr) { - contour_bounds_t bounds; + contour_bounds_t bounds; for (unsigned int i = 0; i + PHANTOM_COUNT < all_points.length; i++) bounds.add (all_points[i]); @@ -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,13 +835,13 @@ 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) { - for (unsigned int i = 0; i < PHANTOM_COUNT; i++) + for (unsigned int i = 0; i < PHANTOM_COUNT; i++) (*phantoms)[i] = all_points[all_points.length - PHANTOM_COUNT + i]; } return true; @@ -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,18 +998,18 @@ 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."); + DEBUG_MSG (SUBSET, nullptr, "Glyph size is too short, missing field instructionLength."); return false; } - const HBUINT16 &instruction_len = StructAtOffset (&glyph, instruction_length_offset); + const HBUINT16 &instruction_len = StructAtOffset (&glyph, instruction_len_offset); /* Out of bounds of the current glyph */ if (unlikely (glyph_header.simple_length (instruction_len) > glyph.length)) { - DEBUG_MSG(SUBSET, nullptr, "The instructions array overruns the glyph's boundaries."); + DEBUG_MSG (SUBSET, nullptr, "The instructions array overruns the glyph's boundaries."); return false; } *length = (uint16_t) instruction_len; @@ -1014,24 +1017,25 @@ 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 { bool success = false; - contour_point_vector_t phantoms; + 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 ()) - return get_extents_var (glyph, coords, coord_count, extents); + 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; @@ -1072,34 +1079,30 @@ struct glyf return true; } - hb_bytes_t bytes_for_glyph (const char * glyf, hb_codepoint_t gid) - { - unsigned int start_offset, end_offset; - if (unlikely (!(get_offsets (gid, &start_offset, &end_offset) && - remove_padding (start_offset, &end_offset)))) + hb_bytes_t bytes_for_glyph (const char *glyf, hb_codepoint_t gid) { - DEBUG_MSG(SUBSET, nullptr, "Unable to get offset or remove padding for %d", gid); - return hb_bytes_t (); + unsigned int start_offset, end_offset; + if (unlikely (!(get_offsets (gid, &start_offset, &end_offset) && + remove_padding (start_offset, &end_offset)))) + { + DEBUG_MSG (SUBSET, nullptr, "Unable to get offset or remove padding for %d", gid); + return hb_bytes_t (); + } + hb_bytes_t glyph_bytes = hb_bytes_t (glyf + start_offset, end_offset - start_offset); + if (!glyph_bytes.as ()->has_data ()) + { + DEBUG_MSG (SUBSET, nullptr, "Glyph size smaller than minimum header %d", gid); + return hb_bytes_t (); + } + return glyph_bytes; } - hb_bytes_t glyph_bytes = hb_bytes_t (glyf + start_offset, end_offset - start_offset); - if (!glyph_bytes.as ()->has_data ()) - { - DEBUG_MSG(SUBSET, nullptr, "Glyph size smaller than minimum header %d", gid); - return hb_bytes_t (); - } - return glyph_bytes; - } private: bool short_offset; unsigned int num_glyphs; hb_blob_ptr_t loca_table; hb_blob_ptr_t 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,40 +1111,39 @@ 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 - { - TRACE_SERIALIZE (this); - - hb_bytes_t dest_glyph = dest_start.copy(c); - dest_glyph = hb_bytes_t (&dest_glyph, dest_glyph.length + dest_end.copy(c).length); - unsigned int pad_length = padding (); - DEBUG_MSG(SUBSET, nullptr, "serialize %d byte glyph, width %d pad %d", dest_glyph.length, dest_glyph.length + pad_length, pad_length); - - HBUINT8 pad; - pad = 0; - while (pad_length > 0) + bool serialize (hb_serialize_context_t *c, + const hb_subset_plan_t *plan) const { - c->embed(pad); - pad_length--; - } + TRACE_SERIALIZE (this); - if (dest_glyph.length) - { - _fix_component_gids (plan, dest_glyph); - if (plan->drop_hints) + hb_bytes_t dest_glyph = dest_start.copy (c); + dest_glyph = hb_bytes_t (&dest_glyph, dest_glyph.length + dest_end.copy (c).length); + unsigned int pad_length = padding (); + DEBUG_MSG (SUBSET, nullptr, "serialize %d byte glyph, width %d pad %d", dest_glyph.length, dest_glyph.length + pad_length, pad_length); + + HBUINT8 pad; + pad = 0; + while (pad_length > 0) { - _zero_instruction_length (dest_glyph); - c->check_success (_remove_composite_instruction_flag (dest_glyph)); + c->embed (pad); + pad_length--; } - } - return_trace (true); - } + if (dest_glyph.length) + { + _fix_component_gids (plan, dest_glyph); + if (plan->drop_hints) + { + _zero_instruction_length (dest_glyph); + c->check_success (_remove_composite_instruction_flag (dest_glyph)); + } + } + + return_trace (true); + } void drop_hints (const OT::glyf::accelerator_t& glyf) { @@ -1176,9 +1178,9 @@ struct glyf } } - unsigned int length () const { return dest_start.length + dest_end.length; } + unsigned int length () const { return dest_start.length + dest_end.length; } /* pad to 2 to ensure 2-byte loca will be ok */ - unsigned int padding () const { return length () % 2; } + unsigned int padding () const { return length () % 2; } unsigned int padded_size () const { return length () + padding (); } }; diff --git a/src/hb-ot-hmtx-table.cc b/src/hb-ot-hmtx-table.cc deleted file mode 100644 index 012a9f2d9..000000000 --- a/src/hb-ot-hmtx-table.cc +++ /dev/null @@ -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; -} - -} diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 700381abe..8e3368d00 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -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 struct hmtxvmtx @@ -134,13 +136,12 @@ struct hmtxvmtx auto it = + hb_range (c->plan->num_output_glyphs ()) | 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 - return hb_pair (0u, 0); - }) + { + hb_codepoint_t old_gid; + 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)); + }) ; table_prime->serialize (c->serializer, it, num_advances); @@ -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 diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index a48fd0107..510174c35 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -1,5 +1,6 @@ /* - * Copyright © 2019 Adobe Inc. + * Copyright © 2019 Adobe Inc. + * Copyright © 2019 Ebrahim Byagowi * * This is part of HarfBuzz, a text shaping library. * @@ -44,9 +45,9 @@ struct contour_point_t void init (float x_=0.f, float y_=0.f) { flag = 0; x = x_; y = y_; } void translate (const contour_point_t &p) { x += p.x; y += p.y; } - - uint8_t flag; - float x, y; + + uint8_t flag; + float x, y; }; struct contour_point_vector_t : hb_vector_t @@ -80,7 +81,7 @@ struct contour_point_vector_t : hb_vector_t struct range_checker_t { range_checker_t (const void *table_, unsigned int start_offset_, unsigned int end_offset_) - : table ((const char*)table_), start_offset (start_offset_), end_offset (end_offset_) {} + : table ((const char*) table_), start_offset (start_offset_), end_offset (end_offset_) {} template bool in_range (const T *p) const @@ -100,10 +101,10 @@ struct Tuple : UnsizedArrayOf {}; struct TuppleIndex : HBUINT16 { enum Flags { - EmbeddedPeakTuple = 0x8000u, - IntermediateRegion = 0x4000u, - PrivatePointNumbers = 0x2000u, - TupleIndexMask = 0x0FFFu + EmbeddedPeakTuple = 0x8000u, + IntermediateRegion = 0x4000u, + PrivatePointNumbers = 0x2000u, + TupleIndexMask = 0x0FFFu }; DEFINE_SIZE_STATIC (2); @@ -114,9 +115,9 @@ struct TupleVarHeader unsigned int get_size (unsigned int axis_count) const { return min_size + - (has_peak ()? get_peak_tuple ().get_size (axis_count): 0) + - (has_intermediate ()? (get_start_tuple (axis_count).get_size (axis_count) + - get_end_tuple (axis_count).get_size (axis_count)): 0); + (has_peak () ? get_peak_tuple ().get_size (axis_count) : 0) + + (has_intermediate () ? (get_start_tuple (axis_count).get_size (axis_count) + + get_end_tuple (axis_count).get_size (axis_count)) : 0); } const TupleVarHeader &get_next (unsigned int axis_count) const @@ -133,7 +134,7 @@ struct TupleVarHeader { unsigned int index = get_index (); if (unlikely (index * coord_count >= shared_tuples.length)) - return 0.f; + return 0.f; peak_tuple = &shared_tuples[coord_count * index]; } @@ -154,37 +155,37 @@ struct TupleVarHeader if (has_intermediate ()) { - int start = start_tuple[i]; - int end = end_tuple[i]; + int start = start_tuple[i]; + int end = end_tuple[i]; if (unlikely (start > peak || peak > end || (start < 0 && end > 0 && peak))) continue; if (v < start || v > end) return 0.f; if (v < peak) - { if (peak != start) scalar *= (float)(v - start) / (peak - start); } + { if (peak != start) scalar *= (float) (v - start) / (peak - start); } else - { if (peak != end) scalar *= (float)(end - v) / (end - peak); } + { if (peak != end) scalar *= (float) (end - v) / (end - peak); } } else if (!v || v < hb_min (0, peak) || v > hb_max (0, peak)) return 0.f; else - scalar *= (float)v / peak; + scalar *= (float) v / peak; } return scalar; } unsigned int get_data_size () const { return varDataSize; } - bool has_peak () const { return (tupleIndex & TuppleIndex::EmbeddedPeakTuple); } - bool has_intermediate () const { return (tupleIndex & TuppleIndex::IntermediateRegion); } + bool has_peak () const { return (tupleIndex & TuppleIndex::EmbeddedPeakTuple); } + bool has_intermediate () const { return (tupleIndex & TuppleIndex::IntermediateRegion); } bool has_private_points () const { return (tupleIndex & TuppleIndex::PrivatePointNumbers); } - unsigned int get_index () const { return (tupleIndex & TuppleIndex::TupleIndexMask); } + unsigned int get_index () const { return (tupleIndex & TuppleIndex::TupleIndexMask); } protected: const Tuple &get_peak_tuple () const { return StructAfter (tupleIndex); } const Tuple &get_start_tuple (unsigned int axis_count) const - { return *(const Tuple *)&get_peak_tuple ()[has_peak ()? axis_count: 0]; } + { return *(const Tuple *) &get_peak_tuple ()[has_peak () ? axis_count : 0]; } const Tuple &get_end_tuple (unsigned int axis_count) const - { return *(const Tuple *)&get_peak_tuple ()[has_peak ()? (axis_count * 2): axis_count]; } + { return *(const Tuple *) &get_peak_tuple ()[has_peak () ? (axis_count * 2) : axis_count]; } HBUINT16 varDataSize; TuppleIndex tupleIndex; @@ -202,7 +203,8 @@ struct TupleVarCount : HBUINT16 unsigned int get_count () const { return (*this) & CountMask; } protected: - enum Flags { + enum Flags + { SharedPointNumbers = 0x8000u, CountMask = 0x0FFFu }; @@ -214,7 +216,7 @@ struct TupleVarCount : HBUINT16 struct GlyphVarData { const TupleVarHeader &get_tuple_var_header (void) const - { return StructAfter(data); } + { return StructAfter (data); } struct tuple_iterator_t { @@ -227,7 +229,7 @@ struct GlyphVarData current_tuple = &var_data->get_tuple_var_header (); data_offset = 0; } - + bool get_shared_indices (hb_vector_t &shared_indices /* OUT */) { if (var_data->has_shared_point_numbers ()) @@ -257,7 +259,7 @@ struct GlyphVarData } bool in_range (const void *p, unsigned int l) const - { return (const char*)p >= (const char*)var_data && (const char*)p+l <= (const char*)var_data + length; } + { return (const char*) p >= (const char*) var_data && (const char*) p+l <= (const char*) var_data + length; } template bool in_range (const T *p) const { return in_range (p, sizeof (*p)); } @@ -265,14 +267,14 @@ struct GlyphVarData { return &(var_data+var_data->data) + data_offset; } private: - const GlyphVarData *var_data; - unsigned int length; - unsigned int index; - unsigned int axis_count; - unsigned int data_offset; + const GlyphVarData *var_data; + unsigned int length; + unsigned int index; + unsigned int axis_count; + unsigned int data_offset; public: - const TupleVarHeader *current_tuple; + const TupleVarHeader *current_tuple; }; static bool get_tuple_iterator (const GlyphVarData *var_data, @@ -295,15 +297,16 @@ struct GlyphVarData { enum packed_point_flag_t { - POINTS_ARE_WORDS = 0x80, + POINTS_ARE_WORDS = 0x80, 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; } @@ -346,8 +350,8 @@ struct GlyphVarData { enum packed_delta_flag_t { - DELTAS_ARE_ZERO = 0x80, - DELTAS_ARE_WORDS = 0x40, + DELTAS_ARE_ZERO = 0x80, + DELTAS_ARE_WORDS = 0x40, DELTA_RUN_COUNT_MASK = 0x3F }; @@ -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; + 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++; + deltas[i] = *(const HBINT8 *) p++; } - } if (j < run_count) return false; } @@ -393,7 +391,6 @@ struct GlyphVarData TupleVarCount tupleVarCount; OffsetTo data; /* TupleVarHeader tupleVarHeaders[] */ - public: DEFINE_SIZE_MIN (4); }; @@ -406,13 +403,13 @@ struct gvar { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && (version.major == 1) && - (glyphCount == c->get_num_glyphs ()) && - c->check_array (&(this+sharedTuples), axisCount * sharedTupleCount) && - (is_long_offset ()? - c->check_array (get_long_offset_array (), glyphCount+1): - c->check_array (get_short_offset_array (), glyphCount+1)) && - c->check_array (((const HBUINT8*)&(this+dataZ)) + get_offset (0), - get_offset (glyphCount) - get_offset (0))); + (glyphCount == c->get_num_glyphs ()) && + c->check_array (&(this+sharedTuples), axisCount * sharedTupleCount) && + (is_long_offset () ? + c->check_array (get_long_offset_array (), glyphCount+1) : + c->check_array (get_short_offset_array (), glyphCount+1)) && + c->check_array (((const HBUINT8*)&(this+dataZ)) + get_offset (0), + get_offset (glyphCount) - get_offset (0))); } /* GlyphVarData not sanitized here; must be checked while accessing each glyph varation data */ @@ -443,9 +440,9 @@ struct gvar } bool long_offset = subset_data_size & ~0xFFFFu; - out->flags = long_offset? 1: 0; + out->flags = long_offset ? 1 : 0; - HBUINT8 *subset_offsets = c->serializer->allocate_size ((long_offset? 4: 2) * (num_glyphs+1)); + HBUINT8 *subset_offsets = c->serializer->allocate_size ((long_offset ? 4 : 2) * (num_glyphs + 1)); if (!subset_offsets) return_trace (false); /* shared tuples */ @@ -456,11 +453,11 @@ struct gvar unsigned int shared_tuple_size = F2DOT14::static_size * axisCount * sharedTupleCount; F2DOT14 *tuples = c->serializer->allocate_size (shared_tuple_size); if (!tuples) return_trace (false); - out->sharedTuples = (char *)tuples - (char *)out; + out->sharedTuples = (char *) tuples - (char *) out; memcpy (tuples, &(this+sharedTuples), shared_tuple_size); } - char *subset_data = c->serializer->allocate_size(subset_data_size); + char *subset_data = c->serializer->allocate_size (subset_data_size); if (!subset_data) return_trace (false); out->dataZ = subset_data - (char *)out; @@ -468,21 +465,21 @@ struct gvar for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++) { hb_codepoint_t old_gid; - unsigned int length = c->plan->old_gid_for_new_gid (gid, &old_gid)? get_glyph_var_data_length (old_gid): 0; + unsigned int length = c->plan->old_gid_for_new_gid (gid, &old_gid) ? get_glyph_var_data_length (old_gid) : 0; if (long_offset) - ((HBUINT32 *)subset_offsets)[gid] = glyph_offset; + ((HBUINT32 *) subset_offsets)[gid] = glyph_offset; else - ((HBUINT16 *)subset_offsets)[gid] = glyph_offset / 2; - + ((HBUINT16 *) subset_offsets)[gid] = glyph_offset / 2; + if (length > 0) memcpy (subset_data, get_glyph_var_data (old_gid), length); subset_data += length; glyph_offset += length; } if (long_offset) - ((HBUINT32 *)subset_offsets)[num_glyphs] = glyph_offset; + ((HBUINT32 *) subset_offsets)[num_glyphs] = glyph_offset; else - ((HBUINT16 *)subset_offsets)[num_glyphs] = glyph_offset / 2; + ((HBUINT16 *) subset_offsets)[num_glyphs] = glyph_offset / 2; return_trace (true); } @@ -496,11 +493,11 @@ struct gvar if ((start_offset == end_offset) || unlikely ((start_offset > get_offset (glyphCount)) || (start_offset + GlyphVarData::min_size > end_offset))) - return &Null(GlyphVarData); - return &(((unsigned char *)this+start_offset)+dataZ); + return &Null (GlyphVarData); + return &(((unsigned char *) this + start_offset) + dataZ); } - bool is_long_offset () const { return (flags & 1)!=0; } + bool is_long_offset () const { return (flags & 1) != 0; } unsigned int get_offset (unsigned int i) const { @@ -512,23 +509,21 @@ struct gvar unsigned int get_glyph_var_data_length (unsigned int glyph) const { - unsigned int end_offset = get_offset (glyph+1); + unsigned int end_offset = get_offset (glyph + 1); unsigned int start_offset = get_offset (glyph); - if (unlikely (start_offset > end_offset || end_offset > get_offset(glyphCount))) + if (unlikely (start_offset > end_offset || end_offset > get_offset (glyphCount))) return 0; return end_offset - start_offset; } - const HBUINT32 *get_long_offset_array () const { return (const HBUINT32 *)&offsetZ; } - const HBUINT16 *get_short_offset_array () const { return (const HBUINT16 *)&offsetZ; } + const HBUINT32 * get_long_offset_array () const { return (const HBUINT32 *) &offsetZ; } + const HBUINT16 *get_short_offset_array () const { return (const HBUINT16 *) &offsetZ; } public: struct accelerator_t { void init (hb_face_t *face) { - memset (this, 0, sizeof (accelerator_t)); - gvar_table = hb_sanitize_context_t ().reference_table (face); hb_blob_ptr_t fvar_table = hb_sanitize_context_t ().reference_table (face); unsigned int axis_count = fvar_table->get_axis_count (); @@ -541,7 +536,7 @@ struct gvar unsigned int num_shared_coord = gvar_table->sharedTupleCount * gvar_table->axisCount; shared_tuples.resize (num_shared_coord); for (unsigned int i = 0; i < num_shared_coord; i++) - shared_tuples[i] = (&(gvar_table+gvar_table->sharedTuples))[i]; + shared_tuples[i] = (&(gvar_table + gvar_table->sharedTuples))[i]; } void fini () @@ -566,11 +561,11 @@ struct gvar float next_delta = T::get (deltas[next]); if (prev_val == next_val) - return (prev_delta == next_delta)? prev_delta: 0.f; + return (prev_delta == next_delta) ? prev_delta : 0.f; else if (target_val <= hb_min (prev_val, next_val)) - return (prev_val < next_val) ? prev_delta: next_delta; + return (prev_val < next_val) ? prev_delta : next_delta; else if (target_val >= hb_max (prev_val, next_val)) - return (prev_val > next_val)? prev_delta: next_delta; + return (prev_val > next_val) ? prev_delta : next_delta; /* linear interpolation */ float r = (target_val - prev_val) / (next_val - prev_val); @@ -578,7 +573,7 @@ struct gvar } static unsigned int next_index (unsigned int i, unsigned int start, unsigned int end) - { return (i >= end)? start: (i + 1); } + { return (i >= end) ? start : (i + 1); } public: bool apply_deltas_to_points (hb_codepoint_t glyph, @@ -589,8 +584,8 @@ struct gvar if (unlikely (coord_count != gvar_table->axisCount)) return false; const GlyphVarData *var_data = gvar_table->get_glyph_var_data (glyph); - if (var_data == &Null(GlyphVarData)) return true; - hb_vector_t shared_indices; + if (var_data == &Null (GlyphVarData)) return true; + hb_vector_t shared_indices; GlyphVarData::tuple_iterator_t iterator; if (!GlyphVarData::get_tuple_iterator (var_data, gvar_table->get_glyph_var_data_length (glyph), @@ -605,10 +600,11 @@ struct gvar for (unsigned int i = 0; i < orig_points.length; i++) orig_points[i] = points[i]; - contour_point_vector_t deltas; /* flag is used to indicate referenced point */ + 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 (); @@ -617,19 +613,19 @@ struct gvar return false; range_checker_t checker (p, 0, length); - hb_vector_t private_indices; + hb_vector_t private_indices; if (iterator.current_tuple->has_private_points () && !GlyphVarData::unpack_points (p, private_indices, checker)) return false; - const hb_array_t &indices = private_indices.length? private_indices: shared_indices; + const hb_array_t &indices = private_indices.length ? private_indices : shared_indices; - bool apply_to_all = (indices.length == 0); - unsigned int num_deltas = apply_to_all? points.length: indices.length; - hb_vector_t x_deltas; + bool apply_to_all = (indices.length == 0); + unsigned int num_deltas = apply_to_all ? points.length : indices.length; + hb_vector_t x_deltas; x_deltas.resize (num_deltas); if (!GlyphVarData::unpack_deltas (p, x_deltas, checker)) return false; - hb_vector_t y_deltas; + hb_vector_t y_deltas; y_deltas.resize (num_deltas); if (!GlyphVarData::unpack_deltas (p, y_deltas, checker)) return false; @@ -638,7 +634,7 @@ struct gvar deltas[i].init (); for (unsigned int i = 0; i < num_deltas; i++) { - unsigned int pt_index = apply_to_all? i: indices[i]; + unsigned int pt_index = apply_to_all ? i : indices[i]; deltas[pt_index].flag = 1; /* this point is referenced, i.e., explicit deltas specified */ deltas[pt_index].x += x_deltas[i] * scalar; deltas[pt_index].y += y_deltas[i] * scalar; @@ -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 (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 ()); @@ -709,20 +708,22 @@ no_more_gaps: { return gvar_table->get_glyph_var_data (glyph); } private: - hb_blob_ptr_t gvar_table; - hb_vector_t shared_tuples; + hb_blob_ptr_t gvar_table; + hb_vector_t shared_tuples; }; protected: - FixedVersion<> version; /* Version of gvar table. Set to 0x00010000u. */ - HBUINT16 axisCount; - HBUINT16 sharedTupleCount; - LOffsetTo sharedTuples; /* LOffsetTo> */ - HBUINT16 glyphCount; - HBUINT16 flags; - LOffsetTo dataZ; /* Array of GlyphVarData */ - UnsizedArrayOf offsetZ; /* Array of 16-bit or 32-bit (glyphCount+1) offsets */ - + FixedVersion<>version; /* Version of gvar table. Set to 0x00010000u. */ + HBUINT16 axisCount; + HBUINT16 sharedTupleCount; + LOffsetTo + sharedTuples; /* LOffsetTo> */ + HBUINT16 glyphCount; + HBUINT16 flags; + LOffsetTo + dataZ; /* Array of GlyphVarData */ + UnsizedArrayOf + offsetZ; /* Array of 16-bit or 32-bit (glyphCount+1) offsets */ public: DEFINE_SIZE_MIN (20); };