mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
Initial playing around with dependencies
This commit is contained in:
1 parent
8647a429ce
commit
65447f9cbb
20 files changed
+795
No files matched your search
@@ -29,6 +29,13 @@ struct AlternateSet
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{ c->output->add_array (alternates.arrayZ, alternates.len); }
|
||||
|
||||
void depend (hb_depend_context_t *c, hb_codepoint_t source) const
|
||||
{
|
||||
+ hb_iter (alternates)
|
||||
| hb_apply ([&] (const hb_codepoint_t &target) { c->depend_data->add_gsub_lookup (source, c->lookup_index, target); })
|
||||
;
|
||||
}
|
||||
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
{ c->output->add_array (alternates.arrayZ, alternates.len); }
|
||||
|
||||
|
||||
@@ -34,6 +34,18 @@ struct AlternateSubstFormat1_2
|
||||
bool may_have_non_1to1 () const
|
||||
{ return false; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, alternateSet)
|
||||
| hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const typename Types::template OffsetTo<AlternateSet<Types>>&> &_)
|
||||
{
|
||||
const AlternateSet<Types>& as = this+_.second;
|
||||
as.depend (c, _.first);
|
||||
})
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, alternateSet)
|
||||
|
||||
@@ -38,6 +38,19 @@ struct Ligature
|
||||
c->output->add (ligGlyph);
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, hb_codepoint_t first) const
|
||||
{
|
||||
hb_codepoint_t ligset = c->depend_data->new_set(first);
|
||||
c->depend_data->add_gsub_lookup (first, c->lookup_index, ligGlyph, ligset);
|
||||
|
||||
+ hb_iter (component)
|
||||
| hb_apply ([&] (const hb_codepoint_t &source) {
|
||||
c->depend_data->add_to_set (ligset, source);
|
||||
c->depend_data->add_gsub_lookup (source, c->lookup_index, ligGlyph, ligset);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
{
|
||||
c->input->add_array (component.arrayZ, component.get_length ());
|
||||
|
||||
@@ -54,6 +54,14 @@ struct LigatureSet
|
||||
;
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, hb_codepoint_t first) const
|
||||
{
|
||||
+ hb_iter (ligature)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([&] (const Ligature<Types> &_) { _.depend (c, first); })
|
||||
;
|
||||
}
|
||||
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
{
|
||||
+ hb_iter (ligature)
|
||||
|
||||
@@ -43,6 +43,18 @@ struct LigatureSubstFormat1_2
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, ligatureSet)
|
||||
| hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const typename Types::template OffsetTo<LigatureSet<Types>>&> &_)
|
||||
{
|
||||
const LigatureSet<Types>& ls = this+_.second;
|
||||
ls.depend (c, _.first);
|
||||
})
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, ligatureSet)
|
||||
|
||||
@@ -44,6 +44,18 @@ struct MultipleSubstFormat1_2
|
||||
;
|
||||
}
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, sequence)
|
||||
| hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const typename Types::template OffsetTo<Sequence<Types>>&> &_)
|
||||
{
|
||||
const Sequence<Types>& s = this+_.second;
|
||||
s.depend (c, _.first);
|
||||
})
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure_lookups (hb_closure_lookups_context_t *c) const {}
|
||||
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
|
||||
@@ -67,6 +67,8 @@ struct ReverseChainSingleSubstFormat1
|
||||
bool may_have_non_1to1 () const
|
||||
{ return false; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const { return false; }
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
if (!intersects (c->glyphs)) return;
|
||||
|
||||
@@ -28,6 +28,13 @@ struct Sequence
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{ c->output->add_array (substitute.arrayZ, substitute.len); }
|
||||
|
||||
void depend (hb_depend_context_t *c, hb_codepoint_t source) const
|
||||
{
|
||||
+ hb_iter (substitute)
|
||||
| hb_apply ([&] (const hb_codepoint_t &target) { c->depend_data->add_gsub_lookup (source, c->lookup_index, target); })
|
||||
;
|
||||
}
|
||||
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
{ c->output->add_array (substitute.arrayZ, substitute.len); }
|
||||
|
||||
|
||||
@@ -45,6 +45,18 @@ struct SingleSubstFormat1_3
|
||||
bool may_have_non_1to1 () const
|
||||
{ return false; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
hb_codepoint_t d = deltaGlyphID;
|
||||
hb_codepoint_t mask = get_mask ();
|
||||
|
||||
+ hb_iter (this+coverage)
|
||||
| hb_map ([&] (hb_codepoint_t _) { return hb_codepoint_pair_t (_, (_ + d) & mask); })
|
||||
| hb_apply ([&] (const hb_codepoint_pair_t &_) { c->depend_data->add_gsub_lookup(_.first, c->lookup_index, _.second); })
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
hb_codepoint_t d = deltaGlyphID;
|
||||
|
||||
@@ -34,6 +34,16 @@ struct SingleSubstFormat2_4
|
||||
bool may_have_non_1to1 () const
|
||||
{ return false; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
auto &cov = this+coverage;
|
||||
|
||||
+ hb_zip (cov, substitute)
|
||||
| hb_apply ([&] (const hb_codepoint_pair_t &_) { c->depend_data->add_gsub_lookup (_.first, c->lookup_index, _.second); })
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
auto &cov = this+coverage;
|
||||
|
||||
@@ -61,6 +61,11 @@ struct SubstLookup : Lookup
|
||||
return ret;
|
||||
}
|
||||
|
||||
hb_depend_context_t::return_t depend (hb_depend_context_t *c) const
|
||||
{
|
||||
return dispatch (c);
|
||||
}
|
||||
|
||||
hb_closure_lookups_context_t::return_t closure_lookups (hb_closure_lookups_context_t *c, unsigned this_index) const
|
||||
{
|
||||
if (c->is_lookup_visited (this_index))
|
||||
@@ -189,6 +194,7 @@ struct SubstLookup : Lookup
|
||||
|
||||
static inline typename hb_closure_context_t::return_t closure_glyphs_recurse_func (hb_closure_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index);
|
||||
|
||||
|
||||
static inline hb_closure_context_t::return_t dispatch_closure_recurse_func (hb_closure_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index)
|
||||
{
|
||||
if (!c->should_visit_lookup (lookup_index))
|
||||
@@ -204,6 +210,8 @@ struct SubstLookup : Lookup
|
||||
return ret;
|
||||
}
|
||||
|
||||
static typename hb_depend_context_t::return_t depend_recurse_func (hb_depend_context_t *c, unsigned lookup_index);
|
||||
|
||||
template <typename context_t, typename ...Ts>
|
||||
typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
|
||||
{ return Lookup::dispatch<SubTable> (c, std::forward<Ts> (ds)...); }
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "hb-buffer-verify.cc"
|
||||
#include "hb-buffer.cc"
|
||||
#include "hb-common.cc"
|
||||
#include "hb-depend.cc"
|
||||
#include "hb-draw.cc"
|
||||
#include "hb-face-builder.cc"
|
||||
#include "hb-face.cc"
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright © 2024 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): Skef Iterum
|
||||
*/
|
||||
|
||||
#ifndef HB_DEPEND_DATA_HH
|
||||
#define HB_DEPEND_DATA_HH
|
||||
|
||||
|
||||
#include "hb.hh"
|
||||
|
||||
#include "hb-multimap.hh"
|
||||
|
||||
struct hb_depend_data_record_t {
|
||||
hb_depend_data_record_t() = delete;
|
||||
hb_depend_data_record_t(hb_tag_t table_tag,
|
||||
hb_codepoint_t dependent,
|
||||
hb_tag_t layout_tag,
|
||||
hb_codepoint_t ligature_set,
|
||||
hb_codepoint_t context_set // ,
|
||||
// hb_codepoint_t fv_context_set,
|
||||
// bool fv_only
|
||||
) : table_tag(table_tag),
|
||||
dependent(dependent), layout_tag(layout_tag),
|
||||
ligature_set(ligature_set), context_set(context_set) // ,
|
||||
// fv_context_set(fv_context_set), fv_only(fv_only)
|
||||
{}
|
||||
hb_tag_t table_tag;
|
||||
hb_codepoint_t dependent;
|
||||
hb_tag_t layout_tag;
|
||||
hb_codepoint_t ligature_set;
|
||||
hb_codepoint_t context_set;
|
||||
// hb_codepoint_t fv_context_set;
|
||||
// bool fv_only {false};
|
||||
};
|
||||
|
||||
struct hb_glyph_depend_record_t {
|
||||
hb_vector_t<hb_depend_data_record_t> dependencies;
|
||||
};
|
||||
|
||||
struct hb_lookup_feature_record_t {
|
||||
hb_lookup_feature_record_t () = default;
|
||||
explicit hb_lookup_feature_record_t (bool full) : full (full) {}
|
||||
hb_lookup_feature_record_t (const hb_lookup_feature_record_t &o) : full(o.full),
|
||||
fv_indexes(o.fv_indexes) {}
|
||||
hb_lookup_feature_record_t (hb_lookup_feature_record_t &&o) : full(o.full),
|
||||
fv_indexes(std::move(o.fv_indexes)) {}
|
||||
hb_lookup_feature_record_t& operator = (const hb_lookup_feature_record_t &o)
|
||||
{
|
||||
full = o.full;
|
||||
fv_indexes = o.fv_indexes;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool full {true};
|
||||
hb_set_t fv_indexes;
|
||||
};
|
||||
|
||||
struct hb_depend_data_t
|
||||
{
|
||||
hb_depend_data_t () {}
|
||||
|
||||
~hb_depend_data_t () {}
|
||||
|
||||
hb_codepoint_t new_set (hb_codepoint_t cp)
|
||||
{
|
||||
hb_codepoint_t set_index = sets.length;
|
||||
sets.push(std::initializer_list<hb_codepoint_t>({cp}));
|
||||
return set_index;
|
||||
}
|
||||
|
||||
hb_codepoint_t new_set (hb_set_t &set)
|
||||
{
|
||||
hb_codepoint_t set_index = sets.length;
|
||||
sets.push(set);
|
||||
return set_index;
|
||||
}
|
||||
|
||||
hb_codepoint_t add_to_set (hb_codepoint_t set_index, hb_codepoint_t cp) {
|
||||
if (set_index == HB_CODEPOINT_INVALID)
|
||||
set_index = new_set(cp);
|
||||
else if (set_index < sets.length)
|
||||
sets[set_index].add(cp);
|
||||
// else error
|
||||
return set_index;
|
||||
}
|
||||
|
||||
void print()
|
||||
{
|
||||
for (unsigned i = 0; i < glyph_dependencies.length; i++) {
|
||||
auto &gd = glyph_dependencies[i];
|
||||
if (!gd.dependencies.length)
|
||||
continue;
|
||||
printf("GID %u:\n", i);
|
||||
for (auto &d : gd.dependencies) {
|
||||
if (d.table_tag == HB_OT_TAG_GSUB) {
|
||||
printf(" layout %c%c%c%c -> %u", HB_UNTAG(d.layout_tag), d.dependent);
|
||||
if (d.ligature_set != HB_CODEPOINT_INVALID)
|
||||
printf(" (ligature)");
|
||||
printf("\n");
|
||||
} else {
|
||||
printf(" %c%c%c%c -> %u", HB_UNTAG(d.table_tag), d.dependent);
|
||||
if (d.table_tag == HB_TAG('c','m','a','p'))
|
||||
printf(" (UVS is %u)", d.layout_tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void add_depend_layout (hb_codepoint_t target, hb_tag_t table_tag,
|
||||
hb_tag_t layout_tag,
|
||||
hb_codepoint_t dependent,
|
||||
hb_codepoint_t lig_set = HB_CODEPOINT_INVALID,
|
||||
hb_codepoint_t context_set = HB_CODEPOINT_INVALID // ,
|
||||
// hb_codepoint_t fv_context_set = HB_CODEPOINT_INVALID,
|
||||
// bool fv_only = false
|
||||
)
|
||||
{
|
||||
if (target >= glyph_dependencies.length) {
|
||||
DEBUG_MSG (SUBSET, nullptr, "Dependency glyph %u for %c%c%c%c too large",
|
||||
target, HB_UNTAG(table_tag));
|
||||
return;
|
||||
}
|
||||
auto &gdr = glyph_dependencies[target];
|
||||
// XXX Check for dups here
|
||||
gdr.dependencies.push(table_tag, dependent, layout_tag, lig_set,
|
||||
context_set); // , fv_context_set, fv_only);
|
||||
}
|
||||
|
||||
void add_gsub_lookup (hb_codepoint_t target, hb_codepoint_t lookup_index,
|
||||
hb_codepoint_t dependent,
|
||||
hb_codepoint_t lig_set = HB_CODEPOINT_INVALID,
|
||||
hb_codepoint_t context_set = HB_CODEPOINT_INVALID)
|
||||
{
|
||||
for (auto t : lookup_features[lookup_index]) {
|
||||
// hb_codepoint_t fv_context_set {HB_CODEPOINT_INVALID};
|
||||
// if (!e.second.fv_indexes.is_empty ())
|
||||
// fv_context_set = new_set(e.second.fv_indexes);
|
||||
add_depend_layout(target, HB_OT_TAG_GSUB, t, dependent, lig_set,
|
||||
context_set); // , fv_context_set, !e.second.full);
|
||||
}
|
||||
}
|
||||
|
||||
void add_depend (hb_codepoint_t target, hb_tag_t table_tag,
|
||||
hb_codepoint_t dependent,
|
||||
hb_codepoint_t lig_set = HB_CODEPOINT_INVALID,
|
||||
hb_codepoint_t context_set = HB_CODEPOINT_INVALID)
|
||||
{
|
||||
add_depend_layout (target, table_tag, 0, dependent, lig_set,
|
||||
context_set);
|
||||
}
|
||||
|
||||
hb_codepoint_t get_nominal_glyph(hb_codepoint_t cp)
|
||||
{
|
||||
return hb_map_get(&nominal_glyphs, cp);
|
||||
}
|
||||
|
||||
hb_set_t unicodes;
|
||||
hb_map_t nominal_glyphs;
|
||||
|
||||
hb_vector_t<hb_set_t> sets;
|
||||
|
||||
hb_vector_t<hb_glyph_depend_record_t> glyph_dependencies;
|
||||
hb_vector_t<hb_set_t> lookup_features;
|
||||
};
|
||||
|
||||
#endif /* HB_DEPEND_DATA_HH */
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright © 2024 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): Skef Iterum
|
||||
*/
|
||||
|
||||
#include "hb.hh"
|
||||
|
||||
#include "hb-depend.hh"
|
||||
|
||||
#include "hb-face.hh"
|
||||
#include "hb-ot-cmap-table.hh"
|
||||
#include "hb-ot-layout-gsub-table.hh"
|
||||
|
||||
/**
|
||||
* SECTION:hb-depend
|
||||
* @title: hb-depend
|
||||
* @short_description: Represents dependencies between glyphs in an OpenType font
|
||||
* @include: hb-depend.h
|
||||
*
|
||||
* XXX Todo.
|
||||
*/
|
||||
|
||||
hb_depend_t::hb_depend_t (hb_face_t *f)
|
||||
{
|
||||
if (unlikely (f == nullptr)) {
|
||||
successful = false;
|
||||
return;
|
||||
}
|
||||
face = hb_face_reference(f);
|
||||
if (unlikely (!data.glyph_dependencies.resize_exact (face->get_num_glyphs ()))) {
|
||||
successful = false;
|
||||
return;
|
||||
}
|
||||
successful = true;
|
||||
|
||||
get_cmap_dependencies();
|
||||
get_gsub_dependencies();
|
||||
}
|
||||
|
||||
void hb_depend_t::get_cmap_dependencies() {
|
||||
hb_face_collect_nominal_glyph_mapping(face, &data.nominal_glyphs, &data.unicodes);
|
||||
|
||||
OT::cmap_accelerator_t cmap (face);
|
||||
cmap.table->depend(&data);
|
||||
}
|
||||
|
||||
void hb_depend_t::get_gsub_dependencies() {
|
||||
hb_blob_t *gsub_blob = hb_sanitize_context_t ().reference_table<OT::Layout::GSUB> (face);
|
||||
auto table = gsub_blob->as<OT::Layout::GSUB> ();
|
||||
unsigned num_features = table->get_feature_count ();
|
||||
unsigned num_lookups = table->get_lookup_count ();
|
||||
hb_vector_t<hb_tag_t> feature_tags;
|
||||
if (!check_success (feature_tags.resize (num_features)))
|
||||
return;
|
||||
table->get_feature_tags(0, &num_features, feature_tags.arrayZ);
|
||||
if (!check_success (data.lookup_features.resize (num_lookups)))
|
||||
return;
|
||||
|
||||
hb_vector_t<hb_tag_t> feature_query_v;
|
||||
feature_query_v.resize (2);
|
||||
feature_query_v[1] = 0;
|
||||
|
||||
hb_set_t feature_indexes, lookup_indexes;
|
||||
|
||||
for (auto ft : feature_tags) {
|
||||
if (features.has (ft))
|
||||
continue;
|
||||
features.add (ft);
|
||||
feature_query_v[0] = ft;
|
||||
feature_indexes.reset ();
|
||||
hb_ot_layout_collect_features (face, HB_OT_TAG_GSUB, nullptr, nullptr,
|
||||
feature_query_v.arrayZ, &feature_indexes);
|
||||
lookup_indexes.reset ();
|
||||
for (auto feature_index : feature_indexes)
|
||||
table->get_feature (feature_index).add_lookup_indexes_to (&lookup_indexes);
|
||||
|
||||
for (auto lookup_index : lookup_indexes) {
|
||||
data.lookup_features[lookup_index].add (ft);
|
||||
}
|
||||
|
||||
auto &fv = table->get_feature_variations ();
|
||||
auto fi_count = fv.record_count();
|
||||
for (unsigned i = 0; i < fi_count; i++) {
|
||||
lookup_indexes.reset ();
|
||||
for (auto feature_index : feature_indexes) {
|
||||
auto feature_ptr = fv.find_substitute(i, feature_index);
|
||||
if (feature_ptr != nullptr)
|
||||
feature_ptr->add_lookup_indexes_to (&lookup_indexes);
|
||||
}
|
||||
for (auto lookup_index : lookup_indexes) {
|
||||
if (!data.lookup_features[lookup_index].has (ft))
|
||||
data.lookup_features[lookup_index].add (ft);
|
||||
// auto rec = data.lookup_info[lookup_index].get (ft);
|
||||
// rec.fv_indexes.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OT::hb_depend_context_t c (&data, face);
|
||||
int i = -1;
|
||||
for (auto &feature_set : data.lookup_features) {
|
||||
i++;
|
||||
if (feature_set.is_empty ())
|
||||
continue;
|
||||
c.lookup_index = i;
|
||||
c.lookups_seen.clear ();
|
||||
c.set_recurse_func (OT::Layout::GSUB_impl::SubstLookup::dispatch_recurse_func<OT::hb_depend_context_t>);
|
||||
c.recurse(i);
|
||||
}
|
||||
}
|
||||
|
||||
hb_depend_t::~hb_depend_t ()
|
||||
{
|
||||
hb_face_destroy(face);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hb_subset_from_face:
|
||||
* @face: font face to create the plan for.
|
||||
*
|
||||
* Calculates the dependencies between glyphs in the supplied face
|
||||
*
|
||||
* Return value: (transfer full): New depend object. Destroy with
|
||||
* hb_depend_destroy(). If there is a failure creating the depend
|
||||
* object * nullptr will be returned.
|
||||
*
|
||||
* Since: ?.0.0
|
||||
**/
|
||||
hb_depend_t *
|
||||
hb_depend_from_face (hb_face_t *face)
|
||||
{
|
||||
hb_depend_t *depend;
|
||||
if (unlikely (!(depend = hb_object_create<hb_depend_t> (face))))
|
||||
return nullptr;
|
||||
|
||||
if (unlikely (depend->in_error ()))
|
||||
{
|
||||
hb_depend_destroy (depend);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return depend;
|
||||
}
|
||||
|
||||
void
|
||||
hb_depend_print (hb_depend_t *depend)
|
||||
{
|
||||
depend->print();
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_depend_destroy:
|
||||
* @depend: a #hb_depend_t
|
||||
*
|
||||
* Decreases the reference count on @depend, and if it reaches zero, destroys
|
||||
* @depend, freeing all memory.
|
||||
*
|
||||
* Since: ?.0.0
|
||||
**/
|
||||
void
|
||||
hb_depend_destroy (hb_depend_t *depend)
|
||||
{
|
||||
if (!hb_object_destroy (depend)) return;
|
||||
|
||||
hb_free (depend);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright © 2024 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): Skef Iterum
|
||||
*/
|
||||
|
||||
#ifndef HB_DEPEND_H
|
||||
#define HB_DEPEND_H
|
||||
|
||||
#include "hb.h"
|
||||
#include "hb-ot.h"
|
||||
|
||||
HB_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* hb_depend_t:
|
||||
*
|
||||
* Contains information about dependencies between UVS codepoints
|
||||
* and glyphs.
|
||||
*/
|
||||
|
||||
typedef struct hb_depend_t hb_depend_t;
|
||||
|
||||
HB_EXTERN hb_depend_t *
|
||||
hb_depend_from_face (hb_face_t *face);
|
||||
|
||||
HB_EXTERN void
|
||||
hb_depend_print (hb_depend_t *depend);
|
||||
|
||||
HB_EXTERN void
|
||||
hb_depend_destroy(hb_depend_t *depend);
|
||||
|
||||
HB_END_DECLS
|
||||
|
||||
#endif /* HB_DEPEND_H */
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright © 2024 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): Skef Iterum
|
||||
*/
|
||||
|
||||
#ifndef HB_DEPEND_HH
|
||||
#define HB_DEPEND_HH
|
||||
|
||||
#include "hb.hh"
|
||||
|
||||
#include "hb-depend.h"
|
||||
#include "hb-depend-data.hh"
|
||||
|
||||
struct hb_depend_t
|
||||
{
|
||||
HB_INTERNAL hb_depend_t (hb_face_t *face);
|
||||
|
||||
HB_INTERNAL ~hb_depend_t();
|
||||
|
||||
hb_object_header_t header;
|
||||
|
||||
bool successful;
|
||||
|
||||
bool in_error () const { return !successful; }
|
||||
|
||||
bool check_success (bool success)
|
||||
{
|
||||
successful = (successful && success);
|
||||
return successful;
|
||||
}
|
||||
|
||||
void print() { data.print(); }
|
||||
|
||||
void get_cmap_dependencies ();
|
||||
void get_gsub_dependencies ();
|
||||
|
||||
hb_face_t *face;
|
||||
hb_set_t features;
|
||||
hb_depend_data_t data;
|
||||
};
|
||||
|
||||
#endif /* HB_DEPEND_HH */
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "hb-open-type.hh"
|
||||
#include "hb-set.hh"
|
||||
#include "hb-cache.hh"
|
||||
#include "hb-depend-data.hh"
|
||||
|
||||
/*
|
||||
* cmap -- Character to Glyph Index Mapping
|
||||
@@ -1209,6 +1210,18 @@ struct NonDefaultUVS : SortedArray32Of<UVSMapping>
|
||||
;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, hb_codepoint_t sel) const
|
||||
{
|
||||
for (const auto& a : as_array ())
|
||||
{
|
||||
hb_codepoint_t target = depend_data->get_nominal_glyph(a.unicodeValue);
|
||||
if (target == HB_MAP_VALUE_INVALID)
|
||||
continue;
|
||||
depend_data->add_depend_layout(target, HB_OT_TAG_cmap,
|
||||
static_cast<hb_tag_t>(sel), a.glyphID);
|
||||
}
|
||||
}
|
||||
|
||||
NonDefaultUVS* copy (hb_serialize_context_t *c,
|
||||
const hb_set_t *unicodes,
|
||||
const hb_set_t *glyphs_requested,
|
||||
@@ -1275,6 +1288,13 @@ struct VariationSelectorRecord
|
||||
nonDefaultUVS = offset;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, const void *base) const
|
||||
{
|
||||
if (!nonDefaultUVS)
|
||||
return;
|
||||
(base+nonDefaultUVS).depend(depend_data, varSelector);
|
||||
}
|
||||
|
||||
void collect_unicodes (hb_set_t *out, const void *base) const
|
||||
{
|
||||
(base+defaultUVS).collect_unicodes (out);
|
||||
@@ -1461,6 +1481,12 @@ struct CmapSubtableFormat14
|
||||
;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{
|
||||
for (const VariationSelectorRecord& _ : record)
|
||||
_.depend (depend_data, this);
|
||||
}
|
||||
|
||||
void collect_unicodes (hb_set_t *out) const
|
||||
{
|
||||
for (const VariationSelectorRecord& _ : record)
|
||||
@@ -1948,6 +1974,16 @@ struct cmap
|
||||
;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{
|
||||
+ hb_iter (encodingRecord)
|
||||
| hb_map (&EncodingRecord::subtable)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_filter ([&] (const CmapSubtable& _) { return _.u.format == 14; })
|
||||
| hb_apply ([=] (const CmapSubtable& _) { _.u.format14.depend (depend_data); })
|
||||
;
|
||||
}
|
||||
|
||||
bool subset (hb_subset_context_t *c) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
|
||||
@@ -4658,6 +4658,11 @@ struct FeatureVariations
|
||||
{
|
||||
static constexpr unsigned NOT_FOUND_INDEX = 0xFFFFFFFFu;
|
||||
|
||||
unsigned record_count () const
|
||||
{
|
||||
return varRecords.len;
|
||||
}
|
||||
|
||||
bool find_index (const int *coords, unsigned int coord_len,
|
||||
unsigned int *index,
|
||||
ItemVarStoreInstancer *instancer) const
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "hb-ot-map.hh"
|
||||
#include "hb-ot-layout-common.hh"
|
||||
#include "hb-ot-layout-gdef-table.hh"
|
||||
#include "hb-depend-data.hh"
|
||||
|
||||
|
||||
namespace OT {
|
||||
@@ -375,7 +376,34 @@ struct hb_collect_glyphs_context_t :
|
||||
void set_recurse_func (recurse_func_t func) { recurse_func = func; }
|
||||
};
|
||||
|
||||
struct hb_depend_context_t :
|
||||
hb_dispatch_context_t<hb_depend_context_t, bool>
|
||||
{
|
||||
typedef return_t (*recurse_func_t) (hb_depend_context_t *c, unsigned lookup_index);
|
||||
template <typename T>
|
||||
return_t dispatch (const T &obj) { return obj.depend (this); }
|
||||
static return_t default_return_value () { return false; }
|
||||
bool stop_sublookup_iteration (return_t r) const { return r; }
|
||||
|
||||
return_t recurse (unsigned lookup_idx)
|
||||
{
|
||||
if (lookups_seen.has (lookup_idx))
|
||||
return false;
|
||||
lookups_seen.add (lookup_idx);
|
||||
return recurse_func (this, lookup_idx);
|
||||
}
|
||||
|
||||
hb_depend_data_t *depend_data;
|
||||
hb_face_t *face;
|
||||
recurse_func_t recurse_func;
|
||||
hb_codepoint_t lookup_index;
|
||||
hb_set_t lookups_seen;
|
||||
|
||||
hb_depend_context_t (hb_depend_data_t *depend_data_, hb_face_t *face_)
|
||||
: depend_data (depend_data_), face(face_),
|
||||
recurse_func (nullptr) {}
|
||||
void set_recurse_func (recurse_func_t func) { recurse_func = func; }
|
||||
};
|
||||
|
||||
template <typename set_t>
|
||||
struct hb_collect_coverage_context_t :
|
||||
@@ -1812,6 +1840,26 @@ static void context_closure_recurse_lookups (hb_closure_context_t *c,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename HBUINT>
|
||||
static void context_depend_recurse_lookups (hb_depend_context_t *c,
|
||||
unsigned inputCount HB_UNUSED, const HBUINT input[] HB_UNUSED,
|
||||
unsigned lookupCount,
|
||||
const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */,
|
||||
unsigned value HB_UNUSED)
|
||||
{
|
||||
/* XXX What this function should do is recurse through the lookups adding
|
||||
* only those entries of the lookup that are "reachable" given the input.
|
||||
* As it is a lookup reused in multiple contexts will be over-referenced,
|
||||
* leading to inaccurate dependency entries.
|
||||
*
|
||||
* Note that c->lookup_index is not changed. Entries for sub-lookups are
|
||||
* called back with the original index so that they can be entered with
|
||||
* the appropriate layout tags.
|
||||
*/
|
||||
for (unsigned int i = 0; i < lookupCount; i++)
|
||||
c->recurse (lookupRecord[i].lookupListIndex);
|
||||
}
|
||||
|
||||
template <typename context_t>
|
||||
static inline void recurse_lookups (context_t *c,
|
||||
unsigned int lookupCount,
|
||||
@@ -2124,6 +2172,16 @@ struct Rule
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, unsigned value) const
|
||||
{
|
||||
const auto &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>>
|
||||
(inputZ.as_array ((inputCount ? inputCount - 1 : 0)));
|
||||
context_depend_recurse_lookups (c,
|
||||
inputCount, inputZ.arrayZ,
|
||||
lookupCount, lookupRecord.arrayZ,
|
||||
value);
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c, unsigned value, ContextClosureLookupContext &lookup_context) const
|
||||
{
|
||||
if (unlikely (c->lookup_limit_exceeded ())) return;
|
||||
@@ -2257,6 +2315,14 @@ struct RuleSet
|
||||
;
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, unsigned value) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([&] (const Rule &_) { _.depend (c, value); })
|
||||
;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c, unsigned value,
|
||||
ContextClosureLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -2497,6 +2563,15 @@ struct ContextFormat1_4
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, hb_range ((unsigned) ruleSet.len))
|
||||
| hb_map ([&](const hb_pair_t<hb_codepoint_t, unsigned> _) { return hb_pair_t<unsigned, const RuleSet&> (_.first, this+ruleSet[_.second]); })
|
||||
| hb_apply ([&] (const hb_pair_t<unsigned, const RuleSet&>& _) { _.second.depend (c, _.first); })
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs ();
|
||||
@@ -2665,6 +2740,18 @@ struct ContextFormat2_5
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_enumerate (ruleSet)
|
||||
| hb_apply ([&] (const hb_pair_t<unsigned, const typename Types::template OffsetTo<RuleSet>&> _)
|
||||
{
|
||||
const RuleSet& rule_set = this+_.second;
|
||||
rule_set.depend (c, _.first);
|
||||
})
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
if (!(this+coverage).intersects (c->glyphs))
|
||||
@@ -2905,6 +2992,16 @@ struct ContextFormat3
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount));
|
||||
context_depend_recurse_lookups (c,
|
||||
glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1),
|
||||
lookupCount, lookupRecord,
|
||||
0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
if (!(this+coverageZ[0]).intersects (c->glyphs))
|
||||
@@ -3260,6 +3357,18 @@ struct ChainRule
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, unsigned value) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
|
||||
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
|
||||
|
||||
context_depend_recurse_lookups (c,
|
||||
input.lenP1, input.arrayZ,
|
||||
lookup.len, lookup.arrayZ,
|
||||
value);
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c, unsigned value,
|
||||
ChainContextClosureLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -3454,6 +3563,13 @@ struct ChainRuleSet
|
||||
| hb_any
|
||||
;
|
||||
}
|
||||
void depend (hb_depend_context_t *c, unsigned value) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([&] (const ChainRule &_) { _.depend (c, value); })
|
||||
;
|
||||
}
|
||||
void closure (hb_closure_context_t *c, unsigned value, ChainContextClosureLookupContext &lookup_context) const
|
||||
{
|
||||
if (unlikely (c->lookup_limit_exceeded ())) return;
|
||||
@@ -3716,6 +3832,15 @@ struct ChainContextFormat1_4
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_zip (this+coverage, hb_range ((unsigned) ruleSet.len))
|
||||
| hb_map ([&](const hb_pair_t<hb_codepoint_t, unsigned> _) { return hb_pair_t<unsigned, const ChainRuleSet&> (_.first, this+ruleSet[_.second]); })
|
||||
| hb_apply ([&] (const hb_pair_t<unsigned, const ChainRuleSet&>& _) { _.second.depend (c, _.first); })
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs ();
|
||||
@@ -3886,6 +4011,19 @@ struct ChainContextFormat2_5
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
+ hb_enumerate (ruleSet)
|
||||
| hb_apply ([&] (const hb_pair_t<unsigned, const typename Types::template OffsetTo<ChainRuleSet>&> _)
|
||||
{
|
||||
const ChainRuleSet& chainrule_set = this+_.second;
|
||||
chainrule_set.depend (c, _.first);
|
||||
})
|
||||
;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
if (!(this+coverage).intersects (c->glyphs))
|
||||
@@ -4183,6 +4321,20 @@ struct ChainContextFormat3
|
||||
bool may_have_non_1to1 () const
|
||||
{ return true; }
|
||||
|
||||
bool depend (hb_depend_context_t *c) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
|
||||
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
|
||||
|
||||
context_depend_recurse_lookups (c,
|
||||
input.len, (const HBUINT16 *) input.arrayZ + 1,
|
||||
lookup.len, lookup.arrayZ,
|
||||
0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void closure (hb_closure_context_t *c) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
|
||||
@@ -426,11 +426,15 @@ hb_subset_sources = files(
|
||||
'graph/split-helpers.hh',
|
||||
'hb-subset.cc',
|
||||
'hb-subset.hh',
|
||||
'hb-depend.cc',
|
||||
'hb-depend.hh',
|
||||
'hb-depend-data.hh',
|
||||
)
|
||||
|
||||
hb_subset_headers = files(
|
||||
'hb-subset.h',
|
||||
'hb-subset-serialize.h'
|
||||
'hb-depend.h',
|
||||
)
|
||||
|
||||
hb_gobject_sources = files(
|
||||
|
||||
Reference in new issue
Block a user