diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 155a4b5d3..9834acefc 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -93,15 +93,15 @@ struct Glyph float topSideY = all_points[len - 2].y; float bottomSideY = all_points[len - 1].y; - unsigned hori_aw = roundf (rightSideX - leftSideX); + signed hori_aw = roundf (rightSideX - leftSideX); if (hori_aw < 0) hori_aw = 0; int lsb = roundf (xMin - leftSideX); - plan->hmtx_map.set (new_gid, hb_pair (hori_aw, lsb)); + plan->hmtx_map.set (new_gid, hb_pair ((unsigned) hori_aw, lsb)); - unsigned vert_aw = roundf (topSideY - bottomSideY); + signed vert_aw = roundf (topSideY - bottomSideY); if (vert_aw < 0) vert_aw = 0; int tsb = roundf (topSideY - yMax); - plan->vmtx_map.set (new_gid, hb_pair (vert_aw, tsb)); + plan->vmtx_map.set (new_gid, hb_pair ((unsigned) vert_aw, tsb)); } bool compile_header_bytes (const hb_subset_plan_t *plan, diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index a0ba7b57b..d35c60126 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -31,6 +31,7 @@ #include "hb-ot-maxp-table.hh" #include "hb-ot-hhea-table.hh" #include "hb-ot-var-hvar-table.hh" +#include "hb-ot-var-mvar-table.hh" #include "hb-ot-metrics.hh" /* @@ -76,10 +77,10 @@ struct hmtxvmtx const hb_hashmap_t>* get_mtx_map (const hb_subset_plan_t *plan) const { return T::is_horizontal ? &plan->hmtx_map : &plan->vmtx_map; } - bool subset_update_header (hb_subset_plan_t *plan, + bool subset_update_header (hb_subset_context_t *c, unsigned int num_hmetrics) const { - hb_blob_t *src_blob = hb_sanitize_context_t ().reference_table (plan->source, H::tableTag); + hb_blob_t *src_blob = hb_sanitize_context_t ().reference_table (c->plan->source, H::tableTag); hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail (src_blob); hb_blob_destroy (src_blob); @@ -91,7 +92,26 @@ struct hmtxvmtx H *table = (H *) hb_blob_get_data (dest_blob, &length); table->numberOfLongMetrics = num_hmetrics; - bool result = plan->add_table (H::tableTag, dest_blob); +#ifndef HB_NO_VAR + if (c->plan->normalized_coords) + { + auto &MVAR = *c->plan->source->table.MVAR; + if (T::is_horizontal) + { + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE, caretSlopeRise); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN, caretSlopeRun); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET, caretOffset); + } + else + { + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_RISE, caretSlopeRise); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_RUN, caretSlopeRun); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET, caretOffset); + } + } +#endif + + bool result = c->plan->add_table (H::tableTag, dest_blob); hb_blob_destroy (dest_blob); return result; @@ -169,7 +189,7 @@ struct hmtxvmtx return_trace (false); // Amend header num hmetrics - if (unlikely (!subset_update_header (c->plan, num_long_metrics))) + if (unlikely (!subset_update_header (c, num_long_metrics))) return_trace (false); return_trace (true); diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 3de2fec7a..7b3fdee28 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -30,6 +30,7 @@ #include "hb-open-type.hh" #include "hb-ot-os2-unicode-ranges.hh" +#include "hb-ot-var-mvar-table.hh" #include "hb-set.hh" @@ -62,6 +63,7 @@ struct OS2V2Tail bool has_data () const { return sxHeight || sCapHeight; } const OS2V2Tail * operator -> () const { return this; } + OS2V2Tail * operator -> () { return this; } bool sanitize (hb_sanitize_context_t *c) const { @@ -213,6 +215,37 @@ struct OS2 OS2 *os2_prime = c->serializer->embed (this); if (unlikely (!os2_prime)) return_trace (false); +#ifndef HB_NO_VAR + if (c->plan->normalized_coords) + { + auto &MVAR = *c->plan->source->table.MVAR; + auto *table = os2_prime; + + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, sTypoAscender); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER, sTypoDescender); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP, sTypoLineGap); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_ASCENT, usWinAscent); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_DESCENT, usWinDescent); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_SIZE, ySubscriptXSize); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_SIZE, ySubscriptYSize); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_OFFSET, ySubscriptXOffset); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_OFFSET, ySubscriptYOffset); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_SIZE, ySuperscriptXSize); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_SIZE, ySuperscriptYSize); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET, ySuperscriptXOffset); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_OFFSET, ySuperscriptYOffset); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_STRIKEOUT_SIZE, yStrikeoutSize); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_STRIKEOUT_OFFSET, yStrikeoutPosition); + + if (os2_prime->version >= 2) + { + auto *table = & const_cast (os2_prime->v2 ()); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_X_HEIGHT, sxHeight); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_CAP_HEIGHT, sCapHeight); + } + } +#endif + if (c->plan->user_axes_location.has (HB_TAG ('w','g','h','t')) && !c->plan->pinned_at_default) { diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index a1ee14587..e0eb77094 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -28,6 +28,7 @@ #define HB_OT_POST_TABLE_HH #include "hb-open-type.hh" +#include "hb-ot-var-mvar-table.hh" #define HB_STRING_ARRAY_NAME format1_names #define HB_STRING_ARRAY_LIST "hb-ot-post-macroman.hh" @@ -98,6 +99,17 @@ struct post post *post_prime = c->serializer->start_embed (); if (unlikely (!post_prime)) return_trace (false); +#ifndef HB_NO_VAR + if (c->plan->normalized_coords) + { + auto &MVAR = *c->plan->source->table.MVAR; + auto *table = post_prime; + + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_UNDERLINE_SIZE, underlineThickness); + HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_UNDERLINE_OFFSET, underlinePosition); + } +#endif + bool glyph_names = c->plan->flags & HB_SUBSET_FLAGS_GLYPH_NAMES; if (!serialize (c->serializer, glyph_names)) return_trace (false); diff --git a/src/hb-ot-var-mvar-table.hh b/src/hb-ot-var-mvar-table.hh index 420366fbb..d27ebb39c 100644 --- a/src/hb-ot-var-mvar-table.hh +++ b/src/hb-ot-var-mvar-table.hh @@ -116,4 +116,13 @@ protected: } /* namespace OT */ +#define HB_ADD_MVAR_VAR(tag, field) \ + c->serializer->check_assign (table->field, \ + roundf (table->field + \ + MVAR.get_var (tag, \ + c->plan->normalized_coords.arrayZ, \ + c->plan->normalized_coords.length)), \ + HB_SERIALIZE_ERROR_INT_OVERFLOW) + + #endif /* HB_OT_VAR_MVAR_TABLE_HH */ diff --git a/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=150,wdth=80,CTGR=0.ttf b/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=150,wdth=80,CTGR=0.ttf new file mode 100644 index 000000000..7b086cbe8 Binary files /dev/null and b/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=150,wdth=80,CTGR=0.ttf differ diff --git a/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=300,wdth=90,CTGR=0.ttf b/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=300,wdth=90,CTGR=0.ttf new file mode 100644 index 000000000..0f8151196 Binary files /dev/null and b/test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=300,wdth=90,CTGR=0.ttf differ diff --git a/test/subset/data/fonts/NotoSans-VF.abc.ttf b/test/subset/data/fonts/NotoSans-VF.abc.ttf new file mode 100644 index 000000000..8a5de1ff3 Binary files /dev/null and b/test/subset/data/fonts/NotoSans-VF.abc.ttf differ diff --git a/test/subset/data/profiles/no-layout.txt b/test/subset/data/profiles/no-layout.txt new file mode 100644 index 000000000..d03b77a5f --- /dev/null +++ b/test/subset/data/profiles/no-layout.txt @@ -0,0 +1 @@ +--drop-tables+=GSUB,GPOS,GDEF diff --git a/test/subset/data/tests/mvar_full_instance.tests b/test/subset/data/tests/mvar_full_instance.tests new file mode 100644 index 000000000..6cdd562a7 --- /dev/null +++ b/test/subset/data/tests/mvar_full_instance.tests @@ -0,0 +1,12 @@ +FONTS: +NotoSans-VF.abc.ttf + +PROFILES: +no-layout.txt + +SUBSETS: +* + +INSTANCES: +wght=150,wdth=80,CTGR=0 +wght=300,wdth=90,CTGR=0