mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 22:41:10 +01:00
[instancer] support full instancing for avar2 (#5676)
This commit is contained in:
1 parent
db63939aaa
commit
cf31e7ac4e
10 files changed
+147
-37
No files matched your search
@@ -411,6 +411,54 @@ struct avar
|
||||
#endif
|
||||
}
|
||||
|
||||
bool has_v2_data () const { return version.major > 1; }
|
||||
|
||||
// axis normalization is done in 2.14 here
|
||||
// TODO: deprecate this API once fonttools is updated to use 16.16 normalization
|
||||
bool map_coords_2_14 (float *coords, unsigned int coords_length) const
|
||||
{
|
||||
hb_vector_t<int> coords_2_14;
|
||||
if (!coords_2_14.resize (coords_length)) return false;
|
||||
unsigned int count = hb_min (coords_length, axisCount);
|
||||
|
||||
const SegmentMaps *map = &firstAxisSegmentMaps;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
int v = roundf (map->map_float (coords[i]) * 16384.f);
|
||||
coords_2_14[i] = v;
|
||||
coords[i] = v / 16384.f;
|
||||
map = &StructAfter<SegmentMaps> (*map);
|
||||
}
|
||||
|
||||
#ifndef HB_NO_AVAR2
|
||||
if (version.major < 2)
|
||||
return true;
|
||||
hb_barrier ();
|
||||
|
||||
for (; count < axisCount; count++)
|
||||
map = &StructAfter<SegmentMaps> (*map);
|
||||
|
||||
const auto &v2 = * (const avarV2Tail *) map;
|
||||
|
||||
const auto &varidx_map = this+v2.varIdxMap;
|
||||
const auto &var_store = this+v2.varStore;
|
||||
auto *var_store_cache = var_store.create_cache ();
|
||||
|
||||
for (unsigned i = 0; i < coords_length; i++)
|
||||
{
|
||||
int v = coords_2_14[i];
|
||||
uint32_t varidx = varidx_map.map (i);
|
||||
float delta = var_store.get_delta (varidx, coords_2_14.arrayZ, coords_2_14.length, var_store_cache);
|
||||
v += roundf (delta);
|
||||
v = hb_clamp (v, -(1<<16), +(1<<16));
|
||||
coords[i] = v / 16384.f;
|
||||
}
|
||||
|
||||
OT::ItemVariationStore::destroy_cache (var_store_cache);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool subset (hb_subset_context_t *c) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
|
||||
+72
-34
@@ -160,36 +160,43 @@
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
bool
|
||||
normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
|
||||
{
|
||||
if (plan->user_axes_location.is_empty ())
|
||||
return;
|
||||
return true;
|
||||
|
||||
hb_array_t<const OT::AxisRecord> axes = face->table.fvar->get_axes ();
|
||||
plan->normalized_coords.resize (axes.length);
|
||||
if (!plan->check_success (plan->normalized_coords.resize (axes.length)))
|
||||
return false;
|
||||
|
||||
bool has_avar = face->table.avar->has_data ();
|
||||
const OT::SegmentMaps *seg_maps = nullptr;
|
||||
unsigned avar_axis_count = 0;
|
||||
hb_vector_t<float> normalized_mins;
|
||||
hb_vector_t<float> normalized_defaults;
|
||||
hb_vector_t<float> normalized_maxs;
|
||||
if (has_avar)
|
||||
{
|
||||
seg_maps = face->table.avar->get_segment_maps ();
|
||||
avar_axis_count = face->table.avar->get_axis_count();
|
||||
if (!plan->check_success (normalized_mins.resize (axes.length)) ||
|
||||
!plan->check_success (normalized_defaults.resize (axes.length)) ||
|
||||
!plan->check_success (normalized_maxs.resize (axes.length)))
|
||||
return false;
|
||||
}
|
||||
|
||||
bool axis_not_pinned = false;
|
||||
unsigned old_axis_idx = 0, new_axis_idx = 0;
|
||||
for (const auto& axis : axes)
|
||||
unsigned new_axis_idx = 0;
|
||||
unsigned last_idx = 0;
|
||||
for (const auto& _ : + hb_enumerate (axes))
|
||||
{
|
||||
unsigned i = _.first;
|
||||
const OT::AxisRecord &axis = _.second;
|
||||
hb_tag_t axis_tag = axis.get_axis_tag ();
|
||||
plan->axes_old_index_tag_map.set (old_axis_idx, axis_tag);
|
||||
plan->axes_old_index_tag_map.set (i, axis_tag);
|
||||
|
||||
if (!plan->user_axes_location.has (axis_tag) ||
|
||||
!plan->user_axes_location.get (axis_tag).is_point ())
|
||||
{
|
||||
axis_not_pinned = true;
|
||||
plan->axes_index_map.set (old_axis_idx, new_axis_idx);
|
||||
plan->axes_index_map.set (i, new_axis_idx);
|
||||
plan->axis_tags.push (axis_tag);
|
||||
new_axis_idx++;
|
||||
}
|
||||
@@ -216,35 +223,66 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
|
||||
normalized_default = roundf (normalized_default * 16384.f) / 16384.f;
|
||||
normalized_max = roundf (normalized_max * 16384.f) / 16384.f;
|
||||
|
||||
if (has_avar && old_axis_idx < avar_axis_count)
|
||||
if (has_avar)
|
||||
{
|
||||
normalized_min = seg_maps->map_float (normalized_min);
|
||||
normalized_default = seg_maps->map_float (normalized_default);
|
||||
normalized_max = seg_maps->map_float (normalized_max);
|
||||
|
||||
// Round to 2.14
|
||||
normalized_min = roundf (normalized_min * 16384.f) / 16384.f;
|
||||
normalized_default = roundf (normalized_default * 16384.f) / 16384.f;
|
||||
normalized_max = roundf (normalized_max * 16384.f) / 16384.f;
|
||||
normalized_mins[i] = normalized_min;
|
||||
normalized_defaults[i] = normalized_default;
|
||||
normalized_maxs[i] = normalized_max;
|
||||
last_idx = i;
|
||||
}
|
||||
plan->axes_location.set (axis_tag, Triple ((double) normalized_min,
|
||||
(double) normalized_default,
|
||||
(double) normalized_max));
|
||||
else
|
||||
{
|
||||
plan->axes_location.set (axis_tag, Triple ((double) normalized_min,
|
||||
(double) normalized_default,
|
||||
(double) normalized_max));
|
||||
if (normalized_default == -0.f)
|
||||
normalized_default = 0.f; // Normalize -0 to 0
|
||||
if (normalized_default != 0.f)
|
||||
plan->pinned_at_default = false;
|
||||
|
||||
if (normalized_default == -0.f)
|
||||
normalized_default = 0.f; // Normalize -0 to 0
|
||||
if (normalized_default != 0.f)
|
||||
plan->pinned_at_default = false;
|
||||
|
||||
plan->normalized_coords[old_axis_idx] = roundf (normalized_default * 16384.f);
|
||||
plan->normalized_coords[i] = roundf (normalized_default * 16384.f);
|
||||
}
|
||||
}
|
||||
|
||||
old_axis_idx++;
|
||||
|
||||
if (has_avar && old_axis_idx < avar_axis_count)
|
||||
seg_maps = &StructAfter<OT::SegmentMaps> (*seg_maps);
|
||||
}
|
||||
plan->all_axes_pinned = !axis_not_pinned;
|
||||
|
||||
// TODO: use avar map_coords_16_16() when normalization is changed to 16.16
|
||||
// in fonttools
|
||||
if (has_avar)
|
||||
{
|
||||
const OT::avar* avar_table = face->table.avar;
|
||||
if (avar_table->has_v2_data () && !plan->all_axes_pinned)
|
||||
{
|
||||
DEBUG_MSG (SUBSET, nullptr, "Partial-instancing avar2 table is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned coords_len = last_idx + 1;
|
||||
if (!plan->check_success (avar_table->map_coords_2_14 (normalized_mins.arrayZ, coords_len)) ||
|
||||
!plan->check_success (avar_table->map_coords_2_14 (normalized_defaults.arrayZ, coords_len)) ||
|
||||
!plan->check_success (avar_table->map_coords_2_14 (normalized_maxs.arrayZ, coords_len)))
|
||||
return false;
|
||||
|
||||
for (const auto& _ : + hb_enumerate (axes))
|
||||
{
|
||||
unsigned i = _.first;
|
||||
hb_tag_t axis_tag = _.second.get_axis_tag ();
|
||||
if (plan->user_axes_location.has (axis_tag))
|
||||
{
|
||||
plan->axes_location.set (axis_tag, Triple ((double) normalized_mins[i],
|
||||
(double) normalized_defaults[i],
|
||||
(double) normalized_maxs[i]));
|
||||
float normalized_default = normalized_defaults[i];
|
||||
if (normalized_default == -0.f)
|
||||
normalized_default = 0.f; // Normalize -0 to 0
|
||||
if (normalized_default != 0.f)
|
||||
plan->pinned_at_default = false;
|
||||
|
||||
plan->normalized_coords[i] = roundf (normalized_default * 16384.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -677,7 +677,8 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face,
|
||||
return;
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
normalize_axes_location (face, this);
|
||||
if (!check_success (normalize_axes_location (face, this)))
|
||||
return;
|
||||
#endif
|
||||
|
||||
_populate_unicodes_to_retain (input->sets.unicodes, input->sets.glyphs, this);
|
||||
|
||||
@@ -333,7 +333,7 @@ generate_varstore_inner_maps (const hb_set_t& varidx_set,
|
||||
unsigned subtable_count,
|
||||
hb_vector_t<hb_inc_bimap_t> &inner_maps /* OUT */);
|
||||
|
||||
HB_INTERNAL void
|
||||
HB_INTERNAL bool
|
||||
normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan);
|
||||
|
||||
HB_INTERNAL void
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
FONTS:
|
||||
RobotoDelta-Roman-VF-subset.ttf
|
||||
|
||||
PROFILES:
|
||||
default.txt
|
||||
|
||||
SUBSETS:
|
||||
*
|
||||
|
||||
INSTANCES:
|
||||
opsz=70,wght=600,wdth=120,slnt=-6,GRAD=-150,XTSP=50,XOPQ=200,YOPQ=50,XTRA=300,BDSZ=-0.5,WDSP=500,XOUC=50,YOUC=100,XTUC=600,XTUD=700,XTUR=500,YOPE=140,YTUC=600,STUI=200,STUO=60,XOLC=80,YOLC=60,XTLC=300,YTAS=700,YTDE=-300,YTLC=500,STLI=200,STLO=400,YOLB=200,XOFI=100,YOFI=200,XTFI=600,YTFI=500,BARS=800,VANG=-2,VROT=4,YTTL=40,XTTW=20,YTOS=15
|
||||
|
||||
IUP_OPTIONS:
|
||||
Yes
|
||||
No
|
||||
|
||||
# ignore diffs in PariPos table:
|
||||
# fonttools does extension demotion while harfbuzz doesn't
|
||||
OPTIONS:
|
||||
no_fonttools
|
||||
@@ -84,6 +84,7 @@ tests = [
|
||||
'empty_region_vardata',
|
||||
'colrv1_partial_instance',
|
||||
'instantiate_gvar_padding',
|
||||
'avar2_full_instance',
|
||||
]
|
||||
|
||||
if get_option('experimental_api')
|
||||
|
||||
@@ -43,7 +43,9 @@ class Test:
|
||||
if not self.instance:
|
||||
return self.instance
|
||||
else:
|
||||
s = "." + self.instance.replace(":", "-")
|
||||
# include the first 6 axes to avoid file name too long error
|
||||
axes = self.instance.replace(":", "-").split(",")
|
||||
s = "." + ",".join(axes[:6])
|
||||
if self.iup_optimize:
|
||||
s += ".iup_optimize"
|
||||
return s
|
||||
|
||||
Reference in new issue
Block a user