Skip to content

Commit c23e836

Browse files
committed
Dependency graph: recompute store incoming edge counts when segment definitions change.
1 parent e8da23c commit c23e836

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

ift/encoder/dependency_closure.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ DependencyClosure::ComputeIncomingEdgeCount() const {
213213

214214
btree_set<Node> nodes;
215215
for (segment_index_t s = 0; s < segmentation_info_->Segments().size(); s++) {
216+
if (segmentation_info_->Segments().at(s).Definition().Empty()) {
217+
continue;
218+
}
216219
nodes.insert(Node::Segment(s));
217220
}
218221

@@ -292,6 +295,11 @@ StatusOr<DependencyClosure::AnalysisAccuracy> DependencyClosure::AnalyzeSegment(
292295
}
293296

294297
const Segment& segment = segmentation_info_->Segments().at(segment_id);
298+
if (segment.Definition().Empty()) {
299+
// Empty segments are ignored.
300+
continue;
301+
}
302+
295303
if (!segment.Definition().feature_tags.empty()) {
296304
// Feature based segments not yet handled.
297305
inaccurate_results_++;

ift/encoder/dependency_closure.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class DependencyClosure {
6767
common::GlyphSet& or_gids,
6868
common::GlyphSet& exclusive_gids);
6969

70+
// This structure caches information derived from the segmentation info segments.
71+
// This function signals that segmentation info segments have changed and recomputes
72+
// the internal cached information.
73+
void SegmentsChanged() {
74+
incoming_edge_count_ = ComputeIncomingEdgeCount();
75+
}
76+
7077
uint64_t AccurateResults() const { return accurate_results_; }
7178
uint64_t InaccurateResults() const { return inaccurate_results_; }
7279

@@ -198,7 +205,6 @@ class DependencyClosure {
198205

199206
absl::flat_hash_map<hb_codepoint_t, glyph_id_t> unicode_to_gid_;
200207
std::unique_ptr<hb_depend_t, decltype(&hb_depend_destroy)> dependency_graph_;
201-
// TODO XXXXX this needs to be rebuilt whenever segments in seg info are modified.
202208
absl::flat_hash_map<Node, unsigned> incoming_edge_count_;
203209

204210
// These glyphs may participate in complex substitutions and as a result we can't

ift/encoder/dependency_closure_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,28 @@ TEST_F(DependencyClosureTest, BidiMirroring) {
312312
ASSERT_TRUE(s.ok()) << s;
313313
}
314314

315+
TEST_F(DependencyClosureTest, SegmentsChanged) {
316+
// Test that the dep graph analysis accounts for bidi mirroring in the
317+
// harfbuzz closure
318+
Reconfigure({}, {
319+
{{'a'}, ProbabilityBound::Zero()},
320+
{{'b'}, ProbabilityBound::Zero()},
321+
});
322+
323+
Status s = CompareAnalysis({0});
324+
ASSERT_TRUE(s.ok()) << s;
325+
s = CompareAnalysis({1});
326+
ASSERT_TRUE(s.ok()) << s;
327+
328+
segmentation_info.ReassignInitSubset(closure_cache, {'a'});
329+
dependency_closure->SegmentsChanged();
330+
331+
s = CompareAnalysis({0});
332+
ASSERT_TRUE(s.ok()) << s;
333+
s = CompareAnalysis({1});
334+
ASSERT_TRUE(s.ok()) << s;
335+
}
336+
315337
} // namespace ift::encoder
316338

317339
// TODO(garretrieger) more tests (once functionality is available):

ift/encoder/segmentation_context.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Status SegmentationContext::ReassignInitSubset(SubsetDefinition new_def) {
103103
GlyphSet changed_gids = SegmentationInfo().NonInitFontGlyphs();
104104
SegmentSet changed_segments = segmentation_info_->ReassignInitSubset(
105105
glyph_closure_cache, std::move(new_def));
106+
depedency_closure_->SegmentsChanged();
106107

107108
// Consider all glyphs moved to the init font as changed.
108109
changed_gids.subtract(SegmentationInfo().NonInitFontGlyphs());

0 commit comments

Comments
 (0)