адаптация s13bby/osc под vst и gui. (вайбкод)
вайбкод потому что мне в моменте стало понятно. что проще было сразу писать на фреймворке JUCE, чем адаптировать консольное приложение на MiniAudio. обновляться данный репозиторий не будет. СmakeLists адаптирован онли под linux.
This commit is contained in:
@@ -0,0 +1,426 @@
|
||||
#ifndef OT_VAR_VARC_VARC_SUBSET_HH
|
||||
#define OT_VAR_VARC_VARC_SUBSET_HH
|
||||
|
||||
#include "VARC.hh"
|
||||
|
||||
namespace OT {
|
||||
|
||||
struct varc_subset_plan_t
|
||||
{
|
||||
varc_subset_plan_t (const VARC &source_,
|
||||
hb_subset_context_t *subset_context_,
|
||||
const Coverage &source_coverage_,
|
||||
const CFF2Index &source_records_,
|
||||
const ConditionList &source_conditions_,
|
||||
const CFF2Index &source_axis_indices_,
|
||||
const MultiItemVariationStore &source_var_store_) :
|
||||
source (source_),
|
||||
subset_context (subset_context_),
|
||||
source_coverage (source_coverage_),
|
||||
source_records (source_records_),
|
||||
source_conditions (source_conditions_),
|
||||
source_axis_indices (source_axis_indices_),
|
||||
source_var_store (source_var_store_)
|
||||
{}
|
||||
|
||||
bool collect_glyphs ()
|
||||
{
|
||||
const hb_set_t &glyphset = subset_context->plan->_glyphset_varced;
|
||||
for (auto _ : + hb_zip (source_coverage,
|
||||
hb_range ((unsigned) source_records.count)))
|
||||
{
|
||||
hb_codepoint_t old_gid = _.first;
|
||||
unsigned index = _.second;
|
||||
if (glyphset.has (old_gid))
|
||||
{
|
||||
hb_codepoint_t new_gid;
|
||||
if (unlikely (!subset_context->plan->new_gid_for_old_gid (old_gid,
|
||||
&new_gid)))
|
||||
return false;
|
||||
old_indices.push (index);
|
||||
new_gids.push (new_gid);
|
||||
data_size = hb_unsigned_add_saturate (data_size,
|
||||
source_records[index].length);
|
||||
}
|
||||
}
|
||||
|
||||
return !old_indices.in_error () && !new_gids.in_error () &&
|
||||
data_size != UINT_MAX;
|
||||
}
|
||||
|
||||
bool collect_indices ()
|
||||
{
|
||||
for (unsigned old_index : old_indices)
|
||||
{
|
||||
hb_ubytes_t remaining = source_records[old_index];
|
||||
while (remaining)
|
||||
{
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (source, remaining,
|
||||
nullptr, nullptr,
|
||||
&component)))
|
||||
return false;
|
||||
|
||||
if (component.flags & (unsigned) VarComponent::flags_t::HAVE_CONDITION)
|
||||
{
|
||||
if (unlikely (component.condition_index >= source_conditions.get_count ()))
|
||||
return false;
|
||||
condition_indices.add (component.condition_index);
|
||||
}
|
||||
if (component.flags & (unsigned) VarComponent::flags_t::HAVE_AXES)
|
||||
{
|
||||
if (unlikely (component.axis_indices_index >= source_axis_indices.count))
|
||||
return false;
|
||||
axis_indices.add (component.axis_indices_index);
|
||||
}
|
||||
if ((component.flags & (unsigned) VarComponent::flags_t::AXIS_VALUES_HAVE_VARIATION) &&
|
||||
component.axis_values_var_idx != VarIdx::NO_VARIATION)
|
||||
var_indices.add (component.axis_values_var_idx);
|
||||
if ((component.flags & (unsigned) VarComponent::flags_t::TRANSFORM_HAS_VARIATION) &&
|
||||
component.transform_var_idx != VarIdx::NO_VARIATION)
|
||||
var_indices.add (component.transform_var_idx);
|
||||
|
||||
remaining = remaining.sub_array (component.size);
|
||||
}
|
||||
}
|
||||
|
||||
if (unlikely (condition_indices.in_error () || axis_indices.in_error () ||
|
||||
var_indices.in_error ()))
|
||||
return false;
|
||||
|
||||
for (hb_codepoint_t condition_index : condition_indices)
|
||||
if (unlikely (!source_conditions[condition_index].collect_var_indices (&var_indices)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool create_maps ()
|
||||
{
|
||||
const auto *plan = subset_context->plan;
|
||||
if (!plan->user_axes_location.is_empty ())
|
||||
{
|
||||
/* Instancing axes referenced by VARC is not supported. Keep this
|
||||
* restriction for avar2 as well; component coordinate overrides
|
||||
* and their variation data need special handling. */
|
||||
axis_map = &axes_index_map;
|
||||
for (auto _ : plan->axes_index_map)
|
||||
if (!plan->user_axes_location.has (plan->axes_old_index_tag_map.get (_.first)))
|
||||
axes_index_map.set (_.first, _.second);
|
||||
if (unlikely (axes_index_map.in_error ())) return false;
|
||||
}
|
||||
condition_map.add_set (&condition_indices);
|
||||
axis_indices_map.add_set (&axis_indices);
|
||||
return !condition_map.in_error () && !axis_indices_map.in_error () &&
|
||||
source_var_store.create_subset_plan (var_indices,
|
||||
&var_inner_maps,
|
||||
&varidx_map);
|
||||
}
|
||||
|
||||
bool compile_records ()
|
||||
{
|
||||
if (unlikely (!records.alloc_exact (old_indices.length)))
|
||||
return false;
|
||||
|
||||
bool retain_gids = subset_context->plan->flags & HB_SUBSET_FLAGS_RETAIN_GIDS;
|
||||
if (retain_gids && auxiliary_indices_unchanged ())
|
||||
{
|
||||
/* The records reference the same indices, so retain them byte-for-byte. */
|
||||
for (unsigned old_index : old_indices)
|
||||
records.push (source_records[old_index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_vector_t<unsigned> record_offsets;
|
||||
record_data.alloc (data_size);
|
||||
if (unlikely (!record_offsets.alloc_exact (old_indices.length + 1)))
|
||||
return false;
|
||||
|
||||
for (unsigned old_index : old_indices)
|
||||
{
|
||||
record_offsets.push (record_data.length);
|
||||
if (unlikely (!compile_record (source_records[old_index], retain_gids)))
|
||||
return false;
|
||||
}
|
||||
record_offsets.push (record_data.length);
|
||||
|
||||
if (unlikely (record_data.in_error () || record_offsets.in_error ()))
|
||||
return false;
|
||||
for (unsigned i = 0; i < old_indices.length; i++)
|
||||
records.push (hb_ubytes_t (record_data.arrayZ + record_offsets[i],
|
||||
record_offsets[i + 1] - record_offsets[i]));
|
||||
data_size = record_data.length;
|
||||
}
|
||||
|
||||
return !records.in_error ();
|
||||
}
|
||||
|
||||
bool select_axis_indices ()
|
||||
{
|
||||
if (unlikely (!selected_axis_indices.alloc_exact (
|
||||
axis_indices_map.get_population ()) ||
|
||||
(axis_map && !axis_indices_data.resize (
|
||||
axis_indices_map.get_population ()))))
|
||||
return false;
|
||||
for (unsigned i = 0; i < axis_indices_map.get_population (); i++)
|
||||
{
|
||||
hb_ubytes_t bytes = source_axis_indices[axis_indices_map.backward (i)];
|
||||
if (axis_map)
|
||||
{
|
||||
hb_vector_t<int> indices;
|
||||
const HBUINT8 *p = (const HBUINT8 *) bytes.arrayZ;
|
||||
if (unlikely (!TupleValues::decompile (p, indices, p + bytes.length, true)))
|
||||
return false;
|
||||
for (int &index : indices)
|
||||
{
|
||||
if (unlikely (!axis_map->has (index))) return false;
|
||||
index = axis_map->get (index);
|
||||
}
|
||||
auto &data = axis_indices_data[i];
|
||||
/* One control byte and at most four data bytes per value. */
|
||||
unsigned size = hb_unsigned_mul_saturate (indices.length, 5u);
|
||||
if (unlikely (size == UINT_MAX || !data.resize_dirty (size))) return false;
|
||||
data.shrink (TupleValues::compile_unsafe (indices.as_array (), data.arrayZ));
|
||||
bytes = data.as_array ();
|
||||
}
|
||||
axis_indices_data_size = hb_unsigned_add_saturate (axis_indices_data_size,
|
||||
bytes.length);
|
||||
selected_axis_indices.push (bytes);
|
||||
}
|
||||
|
||||
return axis_indices_data_size != UINT_MAX &&
|
||||
!selected_axis_indices.in_error ();
|
||||
}
|
||||
|
||||
const VARC &source;
|
||||
hb_subset_context_t *subset_context;
|
||||
const Coverage &source_coverage;
|
||||
const CFF2Index &source_records;
|
||||
const ConditionList &source_conditions;
|
||||
const CFF2Index &source_axis_indices;
|
||||
const MultiItemVariationStore &source_var_store;
|
||||
|
||||
hb_vector_t<unsigned> old_indices;
|
||||
hb_sorted_vector_t<hb_codepoint_t> new_gids;
|
||||
unsigned data_size = 0;
|
||||
|
||||
hb_set_t condition_indices;
|
||||
hb_set_t axis_indices;
|
||||
hb_set_t var_indices;
|
||||
hb_inc_bimap_t condition_map;
|
||||
hb_inc_bimap_t axis_indices_map;
|
||||
hb_vector_t<hb_inc_bimap_t> var_inner_maps;
|
||||
hb_map_t varidx_map;
|
||||
|
||||
hb_vector_t<unsigned char> record_data;
|
||||
hb_vector_t<hb_ubytes_t> records;
|
||||
|
||||
hb_vector_t<hb_ubytes_t> selected_axis_indices;
|
||||
hb_vector_t<hb_vector_t<unsigned char>> axis_indices_data;
|
||||
unsigned axis_indices_data_size = 0;
|
||||
hb_map_t axes_index_map;
|
||||
const hb_map_t *axis_map = nullptr;
|
||||
|
||||
private:
|
||||
bool auxiliary_indices_unchanged () const
|
||||
{
|
||||
for (hb_codepoint_t old_index : condition_indices)
|
||||
if (condition_map.get (old_index) != old_index)
|
||||
return false;
|
||||
for (hb_codepoint_t old_index : axis_indices)
|
||||
if (axis_indices_map.get (old_index) != old_index)
|
||||
return false;
|
||||
for (hb_codepoint_t old_index : var_indices)
|
||||
if (varidx_map.get (old_index) != old_index)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool append_varint (uint32_t value)
|
||||
{
|
||||
unsigned size = HBUINT32VAR::get_size (value);
|
||||
unsigned offset = record_data.length;
|
||||
unsigned new_length = hb_unsigned_add_saturate (offset, size);
|
||||
if (unlikely (new_length == UINT_MAX ||
|
||||
!record_data.resize_dirty (new_length)))
|
||||
return false;
|
||||
HBUINT32VAR::serialize_unsafe (record_data.arrayZ + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool append_bytes (hb_ubytes_t record,
|
||||
unsigned component_size,
|
||||
unsigned start,
|
||||
unsigned end)
|
||||
{
|
||||
if (unlikely (start > end || end > component_size)) return false;
|
||||
unsigned offset = record_data.length;
|
||||
unsigned size = end - start;
|
||||
unsigned new_length = hb_unsigned_add_saturate (offset, size);
|
||||
if (unlikely (new_length == UINT_MAX ||
|
||||
!record_data.resize_dirty (new_length)))
|
||||
return false;
|
||||
hb_memcpy (record_data.arrayZ + offset, record.arrayZ + start, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool compile_record (hb_ubytes_t record, bool retain_gids)
|
||||
{
|
||||
hb_ubytes_t remaining = record;
|
||||
while (remaining)
|
||||
{
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (source, remaining,
|
||||
nullptr, nullptr,
|
||||
&component) ||
|
||||
!compile_component (remaining, component, retain_gids)))
|
||||
return false;
|
||||
remaining = remaining.sub_array (component.size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool compile_component (hb_ubytes_t record,
|
||||
const VarComponent::record_t &component,
|
||||
bool retain_gids)
|
||||
{
|
||||
hb_codepoint_t new_gid = component.gid;
|
||||
if (unlikely ((!retain_gids &&
|
||||
!subset_context->plan->new_gid_for_old_gid (component.gid,
|
||||
&new_gid)) ||
|
||||
new_gid > 0xFFFFFFu))
|
||||
return false;
|
||||
|
||||
uint32_t flags = component.flags;
|
||||
unsigned gid_size = component.gid_size;
|
||||
if (new_gid > 0xFFFFu)
|
||||
{
|
||||
flags |= (unsigned) VarComponent::flags_t::GID_IS_24BIT;
|
||||
gid_size = HBGlyphID24::static_size;
|
||||
}
|
||||
|
||||
if (unlikely (!append_varint (flags))) return false;
|
||||
unsigned gid_offset = record_data.length;
|
||||
unsigned gid_end = hb_unsigned_add_saturate (gid_offset, gid_size);
|
||||
if (unlikely (gid_end == UINT_MAX ||
|
||||
!record_data.resize_dirty (gid_end)))
|
||||
return false;
|
||||
unsigned char *out = record_data.arrayZ + gid_offset;
|
||||
if (gid_size == HBGlyphID16::static_size)
|
||||
* (HBGlyphID16 *) out = new_gid;
|
||||
else
|
||||
* (HBGlyphID24 *) out = new_gid;
|
||||
|
||||
unsigned cursor = component.gid_offset + component.gid_size;
|
||||
if (flags & (unsigned) VarComponent::flags_t::HAVE_CONDITION)
|
||||
{
|
||||
if (unlikely (!condition_map.has (component.condition_index) ||
|
||||
!append_bytes (record, component.size,
|
||||
cursor, component.condition_offset) ||
|
||||
!append_varint (condition_map.get (component.condition_index))))
|
||||
return false;
|
||||
cursor = component.condition_offset + component.condition_size;
|
||||
}
|
||||
if (flags & (unsigned) VarComponent::flags_t::HAVE_AXES)
|
||||
{
|
||||
if (unlikely (!axis_indices_map.has (component.axis_indices_index) ||
|
||||
!append_bytes (record, component.size,
|
||||
cursor, component.axis_indices_offset) ||
|
||||
!append_varint (axis_indices_map.get (component.axis_indices_index))))
|
||||
return false;
|
||||
cursor = component.axis_indices_offset + component.axis_indices_size;
|
||||
}
|
||||
if (flags & (unsigned) VarComponent::flags_t::AXIS_VALUES_HAVE_VARIATION)
|
||||
{
|
||||
uint32_t var_idx = component.axis_values_var_idx;
|
||||
if (unlikely ((var_idx != VarIdx::NO_VARIATION && !varidx_map.has (var_idx)) ||
|
||||
!append_bytes (record, component.size,
|
||||
cursor, component.axis_values_var_offset) ||
|
||||
!append_varint (var_idx == VarIdx::NO_VARIATION ?
|
||||
var_idx : varidx_map.get (var_idx))))
|
||||
return false;
|
||||
cursor = component.axis_values_var_offset + component.axis_values_var_size;
|
||||
}
|
||||
if (flags & (unsigned) VarComponent::flags_t::TRANSFORM_HAS_VARIATION)
|
||||
{
|
||||
uint32_t var_idx = component.transform_var_idx;
|
||||
if (unlikely ((var_idx != VarIdx::NO_VARIATION && !varidx_map.has (var_idx)) ||
|
||||
!append_bytes (record, component.size,
|
||||
cursor, component.transform_var_offset) ||
|
||||
!append_varint (var_idx == VarIdx::NO_VARIATION ?
|
||||
var_idx : varidx_map.get (var_idx))))
|
||||
return false;
|
||||
cursor = component.transform_var_offset + component.transform_var_size;
|
||||
}
|
||||
|
||||
return append_bytes (record, component.size, cursor, component.size);
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
VARC::subset (hb_subset_context_t *c) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
auto fail = [&] ()
|
||||
{
|
||||
c->serializer->err (HB_SERIALIZE_ERROR_OTHER);
|
||||
return false;
|
||||
};
|
||||
|
||||
const Coverage &source_coverage = this+coverage;
|
||||
const CFF2Index &source_records = this+glyphRecords;
|
||||
const ConditionList &source_conditions = this+conditionList;
|
||||
const TupleList &source_axis_indices = this+axisIndicesList;
|
||||
const CFF2Index &source_axis_indices_index = source_axis_indices;
|
||||
const MultiItemVariationStore &source_var_store = this+varStore;
|
||||
varc_subset_plan_t subset_plan (*this, c,
|
||||
source_coverage,
|
||||
source_records,
|
||||
source_conditions,
|
||||
source_axis_indices_index,
|
||||
source_var_store);
|
||||
if (unlikely (!subset_plan.collect_glyphs ()))
|
||||
return_trace (fail ());
|
||||
if (!subset_plan.old_indices)
|
||||
return_trace (false);
|
||||
if (unlikely (!subset_plan.collect_indices () ||
|
||||
!subset_plan.create_maps () ||
|
||||
!subset_plan.compile_records ()))
|
||||
return_trace (fail ());
|
||||
|
||||
VARC *out = c->serializer->start_embed<VARC> ();
|
||||
if (unlikely (!out || !c->serializer->extend_min (out)))
|
||||
return_trace (false);
|
||||
out->version = version;
|
||||
|
||||
if (unlikely (!subset_plan.select_axis_indices ()))
|
||||
return_trace (fail ());
|
||||
|
||||
if (unlikely (!out->coverage.serialize_serialize (c->serializer,
|
||||
subset_plan.new_gids.iter ()) ||
|
||||
(subset_plan.condition_map.get_population () &&
|
||||
!out->conditionList.serialize_serialize (c->serializer,
|
||||
&source_conditions,
|
||||
subset_plan.condition_map,
|
||||
subset_plan.varidx_map,
|
||||
subset_plan.axis_map)) ||
|
||||
(subset_plan.axis_indices_map.get_population () &&
|
||||
!out->axisIndicesList.serialize_serialize (c->serializer,
|
||||
subset_plan.selected_axis_indices.iter (),
|
||||
&subset_plan.axis_indices_data_size)) ||
|
||||
(subset_plan.var_indices.get_population () &&
|
||||
!out->varStore.serialize_serialize (c->serializer,
|
||||
&source_var_store,
|
||||
subset_plan.var_inner_maps.as_array (),
|
||||
subset_plan.axis_map)) ||
|
||||
!out->glyphRecords.serialize_serialize (c->serializer,
|
||||
subset_plan.records.iter (),
|
||||
&subset_plan.data_size)))
|
||||
return_trace (false);
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
} /* namespace OT */
|
||||
|
||||
#endif /* OT_VAR_VARC_VARC_SUBSET_HH */
|
||||
@@ -0,0 +1,565 @@
|
||||
#ifndef HB_OT_VAR_VARC_CC
|
||||
#define HB_OT_VAR_VARC_CC
|
||||
#ifdef HB_OT_VAR_VARC_CC /* Pacify -Wunused-macros. */
|
||||
|
||||
#include "VARC.hh"
|
||||
|
||||
#ifndef HB_NO_VAR_COMPOSITES
|
||||
|
||||
#include "../../../hb-draw.hh"
|
||||
#include "../../../hb-depend-data.hh"
|
||||
#include "../../../hb-ot-layout-common.hh"
|
||||
#include "../../../hb-ot-layout-gdef-table.hh"
|
||||
|
||||
namespace OT {
|
||||
|
||||
//namespace Var {
|
||||
|
||||
#define VARC_PROCESS_TRANSFORM_COMPONENTS \
|
||||
HB_STMT_START { \
|
||||
PROCESS_TRANSFORM_COMPONENT ( 0, FWORD, HAVE_TRANSLATE_X, translateX); \
|
||||
PROCESS_TRANSFORM_COMPONENT ( 0, FWORD, HAVE_TRANSLATE_Y, translateY); \
|
||||
PROCESS_TRANSFORM_COMPONENT (12, F4DOT12, HAVE_ROTATION, rotation); \
|
||||
PROCESS_TRANSFORM_COMPONENT (10, F6DOT10, HAVE_SCALE_X, scaleX); \
|
||||
PROCESS_TRANSFORM_COMPONENT (10, F6DOT10, HAVE_SCALE_Y, scaleY); \
|
||||
PROCESS_TRANSFORM_COMPONENT (12, F4DOT12, HAVE_SKEW_X, skewX); \
|
||||
PROCESS_TRANSFORM_COMPONENT (12, F4DOT12, HAVE_SKEW_Y, skewY); \
|
||||
PROCESS_TRANSFORM_COMPONENT ( 0, FWORD, HAVE_TCENTER_X, tCenterX); \
|
||||
PROCESS_TRANSFORM_COMPONENT ( 0, FWORD, HAVE_TCENTER_Y, tCenterY); \
|
||||
} HB_STMT_END
|
||||
|
||||
bool
|
||||
VarComponent::decompile_record (const VARC &varc,
|
||||
hb_ubytes_t total_record,
|
||||
hb_vector_t<unsigned> *axis_indices,
|
||||
hb_vector_t<double> *axis_values,
|
||||
record_t *decoded,
|
||||
int64_t *budget)
|
||||
{
|
||||
const unsigned char *start = total_record.arrayZ;
|
||||
const unsigned char *record = start;
|
||||
const unsigned char *end = start + total_record.length;
|
||||
|
||||
if (axis_indices) axis_indices->clear ();
|
||||
if (axis_values) axis_values->clear ();
|
||||
|
||||
#define READ_UINT32VAR(name) \
|
||||
HB_STMT_START { \
|
||||
if (unlikely (unsigned (end - record) < HBUINT32VAR::min_size)) return false; \
|
||||
hb_barrier (); \
|
||||
auto &varint = * (const HBUINT32VAR *) record; \
|
||||
unsigned size = varint.get_size (); \
|
||||
if (unlikely (unsigned (end - record) < size)) return false; \
|
||||
name = (uint32_t) varint; \
|
||||
record += size; \
|
||||
} HB_STMT_END
|
||||
#define READ_UINT32VAR_FIELD(name, field) \
|
||||
HB_STMT_START { \
|
||||
decoded->field##_offset = record - start; \
|
||||
READ_UINT32VAR (name); \
|
||||
decoded->field##_size = record - start - decoded->field##_offset; \
|
||||
} HB_STMT_END
|
||||
|
||||
READ_UINT32VAR (decoded->flags);
|
||||
|
||||
decoded->gid_offset = record - start;
|
||||
if (decoded->flags & (unsigned) flags_t::GID_IS_24BIT)
|
||||
{
|
||||
decoded->gid_size = HBGlyphID24::static_size;
|
||||
if (unlikely (unsigned (end - record) < HBGlyphID24::static_size)) return false;
|
||||
hb_barrier ();
|
||||
decoded->gid = * (const HBGlyphID24 *) record;
|
||||
record += HBGlyphID24::static_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
decoded->gid_size = HBGlyphID16::static_size;
|
||||
if (unlikely (unsigned (end - record) < HBGlyphID16::static_size)) return false;
|
||||
hb_barrier ();
|
||||
decoded->gid = * (const HBGlyphID16 *) record;
|
||||
record += HBGlyphID16::static_size;
|
||||
}
|
||||
|
||||
if (decoded->flags & (unsigned) flags_t::HAVE_CONDITION)
|
||||
READ_UINT32VAR_FIELD (decoded->condition_index, condition);
|
||||
|
||||
if (decoded->flags & (unsigned) flags_t::HAVE_AXES)
|
||||
{
|
||||
READ_UINT32VAR_FIELD (decoded->axis_indices_index, axis_indices);
|
||||
unsigned axis_count;
|
||||
if (axis_indices)
|
||||
{
|
||||
axis_indices->extend ((&varc+varc.axisIndicesList)[decoded->axis_indices_index]);
|
||||
if (unlikely (axis_indices->in_error ())) return false;
|
||||
axis_count = axis_indices->length;
|
||||
}
|
||||
else
|
||||
axis_count = hb_len ((&varc+varc.axisIndicesList)[decoded->axis_indices_index]);
|
||||
if (unlikely (budget && axis_count &&
|
||||
!hb_budget_spend (*budget, HB_BUDGET_1, axis_count)))
|
||||
return false;
|
||||
if (axis_values)
|
||||
{
|
||||
if (unlikely (!axis_values->resize (axis_count))) return false;
|
||||
const HBUINT8 *p = (const HBUINT8 *) record;
|
||||
if (unlikely (!TupleValues::decompile (p, *axis_values,
|
||||
(const HBUINT8 *) end)))
|
||||
return false;
|
||||
record = (const unsigned char *) p;
|
||||
}
|
||||
else if (unlikely (!TupleValues::skip (record, end, axis_count)))
|
||||
return false;
|
||||
}
|
||||
|
||||
decoded->axis_values_var_idx = VarIdx::NO_VARIATION;
|
||||
if (decoded->flags & (unsigned) flags_t::AXIS_VALUES_HAVE_VARIATION)
|
||||
READ_UINT32VAR_FIELD (decoded->axis_values_var_idx, axis_values_var);
|
||||
|
||||
decoded->transform_var_idx = VarIdx::NO_VARIATION;
|
||||
if (decoded->flags & (unsigned) flags_t::TRANSFORM_HAS_VARIATION)
|
||||
READ_UINT32VAR_FIELD (decoded->transform_var_idx, transform_var);
|
||||
|
||||
#define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \
|
||||
if (decoded->flags & (unsigned) flags_t::flag) \
|
||||
{ \
|
||||
static_assert (type::static_size == HBINT16::static_size, ""); \
|
||||
if (unlikely (unsigned (end - record) < HBINT16::static_size)) return false; \
|
||||
hb_barrier (); \
|
||||
decoded->transform.name = * (const HBINT16 *) record; \
|
||||
record += HBINT16::static_size; \
|
||||
}
|
||||
VARC_PROCESS_TRANSFORM_COMPONENTS;
|
||||
#undef PROCESS_TRANSFORM_COMPONENT
|
||||
|
||||
unsigned reserved = decoded->flags & (unsigned) flags_t::RESERVED_MASK;
|
||||
while (reserved)
|
||||
{
|
||||
uint32_t discard HB_UNUSED;
|
||||
READ_UINT32VAR (discard);
|
||||
reserved &= reserved - 1;
|
||||
}
|
||||
|
||||
decoded->size = record - start;
|
||||
#undef READ_UINT32VAR_FIELD
|
||||
#undef READ_UINT32VAR
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VARC::closure_glyphs (hb_set_t *glyphset) const
|
||||
{
|
||||
if (unlikely (glyphset->in_error ()))
|
||||
return false;
|
||||
|
||||
hb_set_t pending = *glyphset;
|
||||
if (unlikely (pending.in_error ()))
|
||||
return false;
|
||||
|
||||
while (pending)
|
||||
{
|
||||
hb_codepoint_t gid = pending.get_min ();
|
||||
pending.del (gid);
|
||||
|
||||
unsigned index = (this+coverage).get_coverage (gid);
|
||||
if (index == NOT_COVERED) continue;
|
||||
|
||||
hb_ubytes_t record = (this+glyphRecords)[index];
|
||||
while (record)
|
||||
{
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (*this, record,
|
||||
nullptr, nullptr, &component)))
|
||||
return false;
|
||||
if (!glyphset->has (component.gid))
|
||||
{
|
||||
glyphset->add (component.gid);
|
||||
if (unlikely (glyphset->in_error ()))
|
||||
return false;
|
||||
pending.add (component.gid);
|
||||
if (unlikely (pending.in_error ()))
|
||||
return false;
|
||||
}
|
||||
record = record.sub_array (component.size);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VARC::depend (hb_depend_data_builder_t *depend_data) const
|
||||
{
|
||||
const CFF2Index &records = this+glyphRecords;
|
||||
for (auto _ : + hb_zip (this+coverage,
|
||||
hb_range ((unsigned) records.count)))
|
||||
{
|
||||
hb_codepoint_t gid = _.first;
|
||||
hb_ubytes_t record = records[_.second];
|
||||
while (record)
|
||||
{
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (*this, record,
|
||||
nullptr, nullptr, &component)))
|
||||
{
|
||||
depend_data->fail ();
|
||||
return;
|
||||
}
|
||||
depend_data->add_depend (gid, tableTag, component.gid);
|
||||
record = record.sub_array (component.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef HB_NO_DRAW
|
||||
|
||||
struct hb_transforming_pen_context_t
|
||||
{
|
||||
hb_transform_t<> transform;
|
||||
hb_draw_funcs_t *dfuncs;
|
||||
void *data;
|
||||
hb_draw_state_t *st;
|
||||
int64_t *budget_remaining;
|
||||
};
|
||||
|
||||
static void
|
||||
hb_transforming_pen_move_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
hb_draw_state_t *st,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_transforming_pen_context_t *c = (hb_transforming_pen_context_t *) data;
|
||||
|
||||
c->transform.transform_point (to_x, to_y);
|
||||
|
||||
c->dfuncs->move_to (c->data, *c->st, to_x, to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_transforming_pen_line_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
hb_draw_state_t *st,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_transforming_pen_context_t *c = (hb_transforming_pen_context_t *) data;
|
||||
|
||||
c->transform.transform_point (to_x, to_y);
|
||||
|
||||
c->dfuncs->line_to (c->data, *c->st, to_x, to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_transforming_pen_quadratic_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
hb_draw_state_t *st,
|
||||
float control_x, float control_y,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_transforming_pen_context_t *c = (hb_transforming_pen_context_t *) data;
|
||||
|
||||
c->transform.transform_point (control_x, control_y);
|
||||
c->transform.transform_point (to_x, to_y);
|
||||
|
||||
c->dfuncs->quadratic_to (c->data, *c->st, control_x, control_y, to_x, to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_transforming_pen_cubic_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
hb_draw_state_t *st,
|
||||
float control1_x, float control1_y,
|
||||
float control2_x, float control2_y,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_transforming_pen_context_t *c = (hb_transforming_pen_context_t *) data;
|
||||
|
||||
c->transform.transform_point (control1_x, control1_y);
|
||||
c->transform.transform_point (control2_x, control2_y);
|
||||
c->transform.transform_point (to_x, to_y);
|
||||
|
||||
c->dfuncs->cubic_to (c->data, *c->st, control1_x, control1_y, control2_x, control2_y, to_x, to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_transforming_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
hb_draw_state_t *st,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_transforming_pen_context_t *c = (hb_transforming_pen_context_t *) data;
|
||||
|
||||
c->dfuncs->close_path (c->data, *c->st);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_transforming_pen_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_transforming_pen_context_t *) draw_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_transforming_pen_funcs ();
|
||||
|
||||
static struct hb_transforming_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_transforming_pen_funcs_lazy_loader_t>
|
||||
{
|
||||
static hb_draw_funcs_t *create ()
|
||||
{
|
||||
hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
|
||||
|
||||
hb_draw_funcs_set_move_to_func (funcs, hb_transforming_pen_move_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_line_to_func (funcs, hb_transforming_pen_line_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_transforming_pen_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_transforming_pen_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_transforming_pen_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_transforming_pen_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
hb_atexit (free_static_transforming_pen_funcs);
|
||||
|
||||
return funcs;
|
||||
}
|
||||
} static_transforming_pen_funcs;
|
||||
|
||||
static inline
|
||||
void free_static_transforming_pen_funcs ()
|
||||
{
|
||||
static_transforming_pen_funcs.free_instance ();
|
||||
}
|
||||
|
||||
static hb_draw_funcs_t *
|
||||
hb_transforming_pen_get_funcs ()
|
||||
{
|
||||
return static_transforming_pen_funcs.get_unconst ();
|
||||
}
|
||||
|
||||
hb_ubytes_t
|
||||
VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
hb_codepoint_t parent_gid,
|
||||
hb_array_t<const int> coords,
|
||||
hb_transform_t<> total_transform,
|
||||
hb_ubytes_t total_record,
|
||||
hb_scalar_cache_t *cache) const
|
||||
{
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_4)))
|
||||
return hb_ubytes_t ();
|
||||
|
||||
const unsigned char *end = total_record.arrayZ + total_record.length;
|
||||
auto &VARC = *c.font->face->table.VARC->table;
|
||||
auto &varStore = &VARC+VARC.varStore;
|
||||
|
||||
auto &axisIndices = c.scratch.axisIndices;
|
||||
auto &axisValues = c.scratch.axisValues;
|
||||
record_t component;
|
||||
if (unlikely (!decompile_record (VARC, total_record,
|
||||
&axisIndices, &axisValues, &component,
|
||||
&c.budget)))
|
||||
return hb_ubytes_t ();
|
||||
|
||||
uint32_t flags = component.flags;
|
||||
hb_codepoint_t gid = component.gid;
|
||||
const unsigned char *record = total_record.arrayZ + component.size;
|
||||
|
||||
// Condition
|
||||
bool show = true;
|
||||
if (flags & (unsigned) flags_t::HAVE_CONDITION)
|
||||
{
|
||||
const auto &condition = (&VARC+VARC.conditionList)[component.condition_index];
|
||||
auto instancer = MultiItemVarStoreInstancer(&varStore, nullptr, coords, cache);
|
||||
show = condition.evaluate (coords.arrayZ, coords.length, &instancer);
|
||||
}
|
||||
|
||||
// Axis values
|
||||
|
||||
// Apply variations if any
|
||||
if ((flags & (unsigned) flags_t::AXIS_VALUES_HAVE_VARIATION) &&
|
||||
show && !axisValues.in_error ())
|
||||
{
|
||||
if (unlikely (!hb_budget_spend (c.budget, axisValues.length,
|
||||
coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
varStore.get_delta (component.axis_values_var_idx, coords,
|
||||
axisValues.as_array (), cache);
|
||||
}
|
||||
|
||||
auto component_coords = coords;
|
||||
/* Copying coords is expensive; so we have put an arbitrary
|
||||
* limit on the max number of coords for now. */
|
||||
if ((flags & (unsigned) flags_t::RESET_UNSPECIFIED_AXES) ||
|
||||
coords.length > HB_VAR_COMPOSITE_MAX_AXES)
|
||||
component_coords = hb_array (c.font->coords, c.font->num_coords);
|
||||
|
||||
uint32_t transformVarIdx = component.transform_var_idx;
|
||||
hb_transform_decomposed_t<> transform = component.transform;
|
||||
|
||||
if (show)
|
||||
{
|
||||
// Only use coord_setter if there's actually any axis overrides.
|
||||
if (unlikely (axisIndices &&
|
||||
!hb_budget_spend (c.budget, HB_BUDGET_1,
|
||||
component_coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
coord_setter_t coord_setter (axisIndices ? component_coords : hb_array<int> ());
|
||||
for (unsigned i = 0; i < axisIndices.length; i++)
|
||||
coord_setter[axisIndices[i]] = hb_clamp_to<int> (round (axisValues[i]));
|
||||
if (axisIndices)
|
||||
component_coords = coord_setter.get_coords ();
|
||||
|
||||
// Apply transform variations if any
|
||||
if (transformVarIdx != VarIdx::NO_VARIATION)
|
||||
{
|
||||
double transformValues[9];
|
||||
unsigned numTransformValues = 0;
|
||||
#define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \
|
||||
if (flags & (unsigned) flags_t::flag) \
|
||||
transformValues[numTransformValues++] = (double) transform.name;
|
||||
VARC_PROCESS_TRANSFORM_COMPONENTS;
|
||||
#undef PROCESS_TRANSFORM_COMPONENT
|
||||
if (unlikely (!hb_budget_spend (c.budget, numTransformValues,
|
||||
coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
varStore.get_delta (transformVarIdx, coords, hb_array (transformValues, numTransformValues), cache);
|
||||
numTransformValues = 0;
|
||||
#define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \
|
||||
if (flags & (unsigned) flags_t::flag) \
|
||||
transform.name = (float) transformValues[numTransformValues++];
|
||||
VARC_PROCESS_TRANSFORM_COMPONENTS;
|
||||
#undef PROCESS_TRANSFORM_COMPONENT
|
||||
}
|
||||
|
||||
// Divide them by their divisors
|
||||
#define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \
|
||||
if (shift && (flags & (unsigned) flags_t::flag)) \
|
||||
transform.name *= 1.f / (1 << shift);
|
||||
VARC_PROCESS_TRANSFORM_COMPONENTS;
|
||||
#undef PROCESS_TRANSFORM_COMPONENT
|
||||
|
||||
if (!(flags & (unsigned) flags_t::HAVE_SCALE_Y))
|
||||
transform.scaleY = transform.scaleX;
|
||||
|
||||
transform.rotation *= HB_PI;
|
||||
transform.skewX *= HB_PI;
|
||||
transform.skewY *= HB_PI;
|
||||
|
||||
total_transform.transform (transform.to_transform ());
|
||||
|
||||
bool same_coords = component_coords.length == coords.length &&
|
||||
component_coords.arrayZ == coords.arrayZ;
|
||||
|
||||
c.depth_left--;
|
||||
VARC.get_path_at (c, gid,
|
||||
component_coords, total_transform,
|
||||
parent_gid,
|
||||
same_coords ? cache : nullptr);
|
||||
c.depth_left++;
|
||||
}
|
||||
|
||||
return hb_ubytes_t (record, end - record);
|
||||
}
|
||||
|
||||
bool
|
||||
VARC::get_path_at (const hb_varc_context_t &c,
|
||||
hb_codepoint_t glyph,
|
||||
hb_array_t<const int> coords,
|
||||
hb_transform_t<> transform,
|
||||
hb_codepoint_t parent_glyph,
|
||||
hb_scalar_cache_t *parent_cache) const
|
||||
{
|
||||
// Don't recurse on the same glyph.
|
||||
unsigned idx = glyph == parent_glyph ?
|
||||
NOT_COVERED :
|
||||
(this+coverage).get_coverage (glyph);
|
||||
if (idx == NOT_COVERED)
|
||||
{
|
||||
if (c.draw_session)
|
||||
{
|
||||
/* Out of budget: draw nothing, but signal success so remaining
|
||||
* leaves are skipped instead of falling back per-glyph. */
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true;
|
||||
|
||||
hb_transform_t<> leaf_transform = transform;
|
||||
leaf_transform.x0 *= c.font->x_multf;
|
||||
leaf_transform.y0 *= c.font->y_multf;
|
||||
|
||||
// Build a transforming pen to apply the transform.
|
||||
hb_draw_funcs_t *transformer_funcs = hb_transforming_pen_get_funcs ();
|
||||
hb_transforming_pen_context_t context {leaf_transform,
|
||||
c.draw_session->funcs,
|
||||
c.draw_session->draw_data,
|
||||
&c.draw_session->st,
|
||||
&c.budget};
|
||||
hb_draw_session_t transformer_session {transformer_funcs, &context};
|
||||
hb_draw_session_t &shape_draw_session = leaf_transform.is_identity () ? *c.draw_session : transformer_session;
|
||||
|
||||
if (c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch.glyf_scratch, nullptr, &shape_draw_session.get_budget ())) return true;
|
||||
#ifndef HB_NO_CFF
|
||||
if (c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords, &shape_draw_session.get_budget ())) return true;
|
||||
if (c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session, &shape_draw_session.get_budget ())) return true; // Doesn't have variations
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
else if (c.extents)
|
||||
{
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true;
|
||||
|
||||
hb_glyph_extents_t glyph_extents;
|
||||
if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget))
|
||||
#ifndef HB_NO_CFF
|
||||
if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget))
|
||||
if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents, &c.budget)) // Doesn't have variations
|
||||
#endif
|
||||
return false;
|
||||
|
||||
hb_extents_t<> comp_extents (glyph_extents);
|
||||
hb_transform_t<> leaf_transform = transform;
|
||||
leaf_transform.x0 *= c.font->x_multf;
|
||||
leaf_transform.y0 *= c.font->y_multf;
|
||||
leaf_transform.transform_extents (comp_extents);
|
||||
c.extents->union_ (comp_extents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (c.depth_left <= 0)
|
||||
return true;
|
||||
|
||||
if (c.edges_left <= 0)
|
||||
return true;
|
||||
(c.edges_left)--;
|
||||
|
||||
hb_decycler_node_t node (c.decycler);
|
||||
if (unlikely (!node.visit (glyph)))
|
||||
return true;
|
||||
|
||||
hb_ubytes_t record = (this+glyphRecords)[idx];
|
||||
|
||||
hb_scalar_cache_t static_cache;
|
||||
hb_scalar_cache_t *cache = parent_cache ?
|
||||
parent_cache :
|
||||
(this+varStore).create_cache (&static_cache);
|
||||
|
||||
VarCompositeGlyph::get_path_at (c,
|
||||
glyph,
|
||||
coords, transform,
|
||||
record,
|
||||
cache);
|
||||
|
||||
if (cache != parent_cache)
|
||||
(this+varStore).destroy_cache (cache, &static_cache);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#undef VARC_PROCESS_TRANSFORM_COMPONENTS
|
||||
|
||||
//} // namespace Var
|
||||
} // namespace OT
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* HB_OT_VAR_VARC_CC (pacify clang) */
|
||||
#endif /* HB_OT_VAR_VARC_CC */
|
||||
@@ -0,0 +1,327 @@
|
||||
#ifndef OT_VAR_VARC_VARC_HH
|
||||
#define OT_VAR_VARC_VARC_HH
|
||||
|
||||
#include "../../../hb-decycler.hh"
|
||||
#include "../../../hb-geometry.hh"
|
||||
#include "../../../hb-ot-layout-common.hh"
|
||||
#include "../../../hb-ot-glyf-table.hh"
|
||||
#include "../../../hb-ot-cff2-table.hh"
|
||||
#include "../../../hb-ot-cff1-table.hh"
|
||||
|
||||
#include "coord-setter.hh"
|
||||
|
||||
struct hb_depend_data_builder_t;
|
||||
|
||||
namespace OT {
|
||||
|
||||
//namespace Var {
|
||||
|
||||
/*
|
||||
* VARC -- Variable Composites
|
||||
* https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md
|
||||
*/
|
||||
|
||||
#ifndef HB_NO_VAR_COMPOSITES
|
||||
|
||||
struct hb_varc_scratch_t
|
||||
{
|
||||
hb_vector_t<unsigned> axisIndices;
|
||||
hb_vector_t<double> axisValues;
|
||||
hb_glyf_scratch_t glyf_scratch;
|
||||
};
|
||||
|
||||
struct hb_varc_context_t
|
||||
{
|
||||
hb_font_t *font;
|
||||
hb_draw_session_t *draw_session;
|
||||
hb_extents_t<> *extents;
|
||||
mutable hb_decycler_t decycler;
|
||||
mutable signed edges_left;
|
||||
mutable signed depth_left;
|
||||
/* Renderer-owned live budget, shared by VARC record processing and
|
||||
* every leaf loaded from glyf/CFF/CFF2. */
|
||||
int64_t &budget;
|
||||
hb_varc_scratch_t &scratch;
|
||||
};
|
||||
|
||||
struct VARC;
|
||||
|
||||
struct VarComponent
|
||||
{
|
||||
enum class flags_t : uint32_t
|
||||
{
|
||||
RESET_UNSPECIFIED_AXES = 1u << 0,
|
||||
HAVE_AXES = 1u << 1,
|
||||
AXIS_VALUES_HAVE_VARIATION = 1u << 2,
|
||||
TRANSFORM_HAS_VARIATION = 1u << 3,
|
||||
HAVE_TRANSLATE_X = 1u << 4,
|
||||
HAVE_TRANSLATE_Y = 1u << 5,
|
||||
HAVE_ROTATION = 1u << 6,
|
||||
HAVE_CONDITION = 1u << 7,
|
||||
HAVE_SCALE_X = 1u << 8,
|
||||
HAVE_SCALE_Y = 1u << 9,
|
||||
HAVE_TCENTER_X = 1u << 10,
|
||||
HAVE_TCENTER_Y = 1u << 11,
|
||||
GID_IS_24BIT = 1u << 12,
|
||||
HAVE_SKEW_X = 1u << 13,
|
||||
HAVE_SKEW_Y = 1u << 14,
|
||||
RESERVED_MASK = ~((1u << 15) - 1),
|
||||
};
|
||||
|
||||
struct record_t
|
||||
{
|
||||
uint32_t flags;
|
||||
hb_codepoint_t gid;
|
||||
unsigned gid_offset;
|
||||
unsigned gid_size;
|
||||
unsigned condition_index;
|
||||
unsigned condition_offset;
|
||||
unsigned condition_size;
|
||||
unsigned axis_indices_index;
|
||||
unsigned axis_indices_offset;
|
||||
unsigned axis_indices_size;
|
||||
uint32_t axis_values_var_idx;
|
||||
unsigned axis_values_var_offset;
|
||||
unsigned axis_values_var_size;
|
||||
uint32_t transform_var_idx;
|
||||
unsigned transform_var_offset;
|
||||
unsigned transform_var_size;
|
||||
hb_transform_decomposed_t<> transform;
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
HB_INTERNAL hb_ubytes_t
|
||||
get_path_at (const hb_varc_context_t &c,
|
||||
hb_codepoint_t parent_gid,
|
||||
hb_array_t<const int> coords,
|
||||
hb_transform_t<> transform,
|
||||
hb_ubytes_t record,
|
||||
hb_scalar_cache_t *cache = nullptr) const;
|
||||
|
||||
HB_INTERNAL static bool decompile_record (const VARC &varc,
|
||||
hb_ubytes_t record,
|
||||
hb_vector_t<unsigned> *axis_indices,
|
||||
hb_vector_t<double> *axis_values,
|
||||
record_t *decoded /* OUT */,
|
||||
int64_t *budget = nullptr);
|
||||
};
|
||||
|
||||
struct VarCompositeGlyph
|
||||
{
|
||||
static void
|
||||
get_path_at (const hb_varc_context_t &c,
|
||||
hb_codepoint_t gid,
|
||||
hb_array_t<const int> coords,
|
||||
hb_transform_t<> transform,
|
||||
hb_ubytes_t record,
|
||||
hb_scalar_cache_t *cache)
|
||||
{
|
||||
while (record)
|
||||
{
|
||||
const VarComponent &comp = * (const VarComponent *) (record.arrayZ);
|
||||
record = comp.get_path_at (c,
|
||||
gid,
|
||||
coords, transform,
|
||||
record,
|
||||
cache);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
HB_MARK_AS_FLAG_T (VarComponent::flags_t);
|
||||
|
||||
struct VARC
|
||||
{
|
||||
friend struct VarComponent;
|
||||
|
||||
static constexpr hb_tag_t tableTag = HB_TAG ('V', 'A', 'R', 'C');
|
||||
|
||||
HB_INTERNAL bool
|
||||
get_path_at (const hb_varc_context_t &c,
|
||||
hb_codepoint_t gid,
|
||||
hb_array_t<const int> coords,
|
||||
hb_transform_t<> transform = HB_TRANSFORM_IDENTITY,
|
||||
hb_codepoint_t parent_gid = HB_CODEPOINT_INVALID,
|
||||
hb_scalar_cache_t *parent_cache = nullptr) const;
|
||||
|
||||
HB_INTERNAL bool closure_glyphs (hb_set_t *glyphset) const;
|
||||
HB_INTERNAL void depend (hb_depend_data_builder_t *depend_data) const;
|
||||
HB_INTERNAL bool subset (hb_subset_context_t *c) const;
|
||||
|
||||
bool
|
||||
get_path (hb_font_t *font,
|
||||
hb_codepoint_t gid,
|
||||
hb_draw_session_t &draw_session,
|
||||
hb_varc_scratch_t &scratch) const
|
||||
{
|
||||
int64_t &budget = draw_session.get_budget ();
|
||||
hb_varc_context_t c {font,
|
||||
&draw_session,
|
||||
nullptr,
|
||||
hb_decycler_t {},
|
||||
HB_MAX_GRAPH_EDGE_COUNT,
|
||||
HB_MAX_NESTING_LEVEL,
|
||||
budget,
|
||||
scratch};
|
||||
|
||||
return get_path_at (c, gid,
|
||||
hb_array (font->coords, font->num_coords));
|
||||
}
|
||||
|
||||
bool
|
||||
get_extents (hb_font_t *font,
|
||||
hb_codepoint_t gid,
|
||||
hb_extents_t<> *extents,
|
||||
hb_varc_scratch_t &scratch) const
|
||||
{
|
||||
int64_t budget = HB_BUDGET_GLYPH;
|
||||
hb_varc_context_t c {font,
|
||||
nullptr,
|
||||
extents,
|
||||
hb_decycler_t {},
|
||||
HB_MAX_GRAPH_EDGE_COUNT,
|
||||
HB_MAX_NESTING_LEVEL,
|
||||
budget,
|
||||
scratch};
|
||||
|
||||
return get_path_at (c, gid,
|
||||
hb_array (font->coords, font->num_coords));
|
||||
}
|
||||
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (version.sanitize (c) &&
|
||||
hb_barrier () &&
|
||||
version.major == 1 &&
|
||||
coverage.sanitize (c, this) &&
|
||||
varStore.sanitize (c, this) &&
|
||||
conditionList.sanitize (c, this) &&
|
||||
axisIndicesList.sanitize (c, this) &&
|
||||
glyphRecords.sanitize (c, this));
|
||||
}
|
||||
|
||||
struct accelerator_t
|
||||
{
|
||||
friend struct VarComponent;
|
||||
|
||||
accelerator_t (hb_face_t *face)
|
||||
{
|
||||
table = hb_sanitize_context_t ().reference_table<VARC> (face);
|
||||
}
|
||||
~accelerator_t ()
|
||||
{
|
||||
auto *scratch = cached_scratch.get_relaxed ();
|
||||
if (scratch)
|
||||
{
|
||||
scratch->~hb_varc_scratch_t ();
|
||||
hb_free (scratch);
|
||||
}
|
||||
|
||||
table.destroy ();
|
||||
}
|
||||
|
||||
bool has_data () const { return table->has_data (); }
|
||||
|
||||
bool
|
||||
get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session) const
|
||||
{
|
||||
if (!table->has_data ()) return false;
|
||||
|
||||
auto *scratch = acquire_scratch ();
|
||||
if (unlikely (!scratch)) return true;
|
||||
bool ret = table->get_path (font, gid, draw_session, *scratch);
|
||||
release_scratch (scratch);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool closure_glyphs (hb_set_t *glyphset) const
|
||||
{
|
||||
if (table->has_data ())
|
||||
return table->closure_glyphs (glyphset);
|
||||
return true;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_builder_t *depend_data) const
|
||||
{
|
||||
if (table->has_data ())
|
||||
table->depend (depend_data);
|
||||
}
|
||||
|
||||
bool
|
||||
get_extents (hb_font_t *font,
|
||||
hb_codepoint_t gid,
|
||||
hb_glyph_extents_t *extents) const
|
||||
{
|
||||
#ifndef HB_NO_DRAW
|
||||
if (!table->has_data ()) return false;
|
||||
|
||||
hb_extents_t<> f_extents;
|
||||
|
||||
auto *scratch = acquire_scratch ();
|
||||
if (unlikely (!scratch)) return true;
|
||||
bool ret = table->get_extents (font, gid, &f_extents, *scratch);
|
||||
release_scratch (scratch);
|
||||
|
||||
if (ret)
|
||||
*extents = f_extents.to_glyph_extents (font->x_scale < 0, font->y_scale < 0);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
hb_varc_scratch_t *acquire_scratch () const
|
||||
{
|
||||
hb_varc_scratch_t *scratch = cached_scratch.get_acquire ();
|
||||
|
||||
if (!scratch || unlikely (!cached_scratch.cmpexch (scratch, nullptr)))
|
||||
{
|
||||
scratch = (hb_varc_scratch_t *) hb_calloc (1, sizeof (hb_varc_scratch_t));
|
||||
if (unlikely (!scratch))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return scratch;
|
||||
}
|
||||
void release_scratch (hb_varc_scratch_t *scratch) const
|
||||
{
|
||||
if (!cached_scratch.cmpexch (nullptr, scratch))
|
||||
{
|
||||
scratch->~hb_varc_scratch_t ();
|
||||
hb_free (scratch);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
hb_blob_ptr_t<VARC> table;
|
||||
mutable hb_atomic_t<hb_varc_scratch_t *> cached_scratch;
|
||||
};
|
||||
|
||||
bool has_data () const { return version.major != 0; }
|
||||
|
||||
protected:
|
||||
FixedVersion<> version; /* Version identifier */
|
||||
Offset32To<Coverage> coverage;
|
||||
Offset32To<MultiItemVariationStore> varStore;
|
||||
Offset32To<ConditionList> conditionList;
|
||||
Offset32To<TupleList> axisIndicesList;
|
||||
Offset32To<CFF2Index/*Of<VarCompositeGlyph>*/> glyphRecords;
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (24);
|
||||
};
|
||||
|
||||
struct VARC_accelerator_t : VARC::accelerator_t {
|
||||
VARC_accelerator_t (hb_face_t *face) : VARC::accelerator_t (face) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
#endif /* OT_VAR_VARC_VARC_HH */
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef OT_VAR_VARC_COORD_SETTER_HH
|
||||
#define OT_VAR_VARC_COORD_SETTER_HH
|
||||
|
||||
|
||||
#include "../../../hb.hh"
|
||||
|
||||
|
||||
namespace OT {
|
||||
//namespace Var {
|
||||
|
||||
|
||||
struct coord_setter_t
|
||||
{
|
||||
coord_setter_t (hb_array_t<const int> coords_)
|
||||
{
|
||||
length = coords_.length;
|
||||
if (length <= ARRAY_LENGTH (static_coords))
|
||||
hb_memcpy (static_coords, coords_.arrayZ, length * sizeof (int));
|
||||
else
|
||||
dynamic_coords.extend (coords_);
|
||||
}
|
||||
|
||||
int& operator [] (unsigned idx)
|
||||
{
|
||||
if (unlikely (idx >= HB_VAR_COMPOSITE_MAX_AXES))
|
||||
return Crap(int);
|
||||
|
||||
if (length <= ARRAY_LENGTH (static_coords))
|
||||
{
|
||||
if (idx < ARRAY_LENGTH (static_coords))
|
||||
{
|
||||
while (length <= idx)
|
||||
static_coords[length++] = 0;
|
||||
return static_coords[idx];
|
||||
}
|
||||
else
|
||||
dynamic_coords.extend (hb_array (static_coords, length));
|
||||
}
|
||||
|
||||
if (dynamic_coords.length <= idx)
|
||||
{
|
||||
if (unlikely (!dynamic_coords.resize (idx + 1)))
|
||||
return Crap(int);
|
||||
length = idx + 1;
|
||||
}
|
||||
return dynamic_coords.arrayZ[idx];
|
||||
}
|
||||
|
||||
hb_array_t<int> get_coords ()
|
||||
{ return length <= ARRAY_LENGTH (static_coords) ? hb_array (static_coords, length) : dynamic_coords.as_array (); }
|
||||
|
||||
private:
|
||||
hb_vector_t<int> dynamic_coords;
|
||||
unsigned length;
|
||||
int static_coords[sizeof (void *) * 8];
|
||||
};
|
||||
|
||||
|
||||
//} // namespace Var
|
||||
|
||||
} // namespace OT
|
||||
|
||||
#endif /* OT_VAR_VARC_COORD_SETTER_HH */
|
||||
Reference in New Issue
Block a user