@@ -202,11 +202,11 @@ StatusOr<std::optional<GlyphSet>> TryMergingABaseSegment(
202202
203203StatusOr<std::optional<GlyphSet>> MergeSegmentWithHeuristic (
204204 SegmentationContext& context, uint32_t base_segment_index) {
205- auto base_segment_glyphs = context. glyph_groupings . AndGlyphGroups (). find (
206- SegmentSet{ base_segment_index} );
207- if (base_segment_glyphs == context. glyph_groupings . AndGlyphGroups (). end () ||
205+ auto base_segment_glyphs =
206+ context. glyph_groupings . ExclusiveGlyphs ( base_segment_index);
207+ if (base_segment_glyphs. empty () ||
208208 !TRY (CandidateMerge::IsPatchTooSmall (context, base_segment_index,
209- base_segment_glyphs-> second ))) {
209+ base_segment_glyphs))) {
210210 // Patch is big enough, no merge is needed.
211211 return std::nullopt ;
212212 }
@@ -293,16 +293,15 @@ Status CollectExclusiveCandidateMerges(
293293 return absl::OkStatus ();
294294 }
295295
296- SegmentSet triggering_segments{segment_index};
297296 auto segment_glyphs =
298- context.glyph_groupings .AndGlyphGroups ().find (triggering_segments);
299- if (segment_glyphs == context.glyph_groupings .AndGlyphGroups ().end () ||
300- segment_glyphs->second .empty ()) {
297+ context.glyph_groupings .ExclusiveGlyphs (segment_index);
298+ if (segment_glyphs.empty ()) {
301299 // This segment has no exclusive glyphs, so no need to consider it for a
302300 // merge.
303301 continue ;
304302 }
305303
304+ SegmentSet triggering_segments{segment_index};
306305 auto candidate_merge = TRY (CandidateMerge::AssessMerge (
307306 context, base_segment_index, triggering_segments,
308307 smallest_candidate_merge));
@@ -361,10 +360,9 @@ StatusOr<std::optional<GlyphSet>> MergeSegmentWithCosts(
361360 // would be to gather some frequency data, test this approach as is, and then
362361 // refine it potentially using some of the proposals noted above.
363362
364- auto base_segment_glyphs = context.glyph_groupings .AndGlyphGroups ().find (
365- SegmentSet{base_segment_index});
366- if (base_segment_glyphs == context.glyph_groupings .AndGlyphGroups ().end () ||
367- base_segment_glyphs->second .empty ()) {
363+ auto base_segment_glyphs =
364+ context.glyph_groupings .ExclusiveGlyphs (base_segment_index);
365+ if (base_segment_glyphs.empty ()) {
368366 // This base segment has no exclusive glyphs, there's no need to to compute
369367 // merges.
370368 return std::nullopt ;
@@ -379,8 +377,8 @@ StatusOr<std::optional<GlyphSet>> MergeSegmentWithCosts(
379377 // If min group size is met, then we will no longer consider merge's that
380378 // have a positive cost delta so start with an existing smallest candidate
381379 // set to cost delta 0 which will filter out positive cost delta candidates.
382- unsigned base_size = TRY (
383- context.patch_size_cache ->GetPatchSize (base_segment_glyphs-> second ));
380+ unsigned base_size =
381+ TRY ( context.patch_size_cache ->GetPatchSize (base_segment_glyphs));
384382 smallest_candidate_merge = CandidateMerge::BaselineCandidate (
385383 base_segment_index, 0.0 , base_size, base_segment.Probability (),
386384 context.GetMergeStrategy ().NetworkOverheadCost ());
@@ -572,14 +570,8 @@ Status ValidateIncrementalGroupings(hb_face_t* face,
572570 return absl::FailedPreconditionError (" glyph_condition_set isn't correct." );
573571 }
574572
575- if (non_incremental_context.glyph_groupings .AndGlyphGroups () !=
576- context.glyph_groupings .AndGlyphGroups ()) {
577- return absl::FailedPreconditionError (" and_glyph groups aren't correct." );
578- }
579-
580- if (non_incremental_context.glyph_groupings .OrGlyphGroups () !=
581- context.glyph_groupings .OrGlyphGroups ()) {
582- return absl::FailedPreconditionError (" or_glyph groups aren't correct." );
573+ if (non_incremental_context.glyph_groupings != context.glyph_groupings ) {
574+ return absl::FailedPreconditionError (" glyph groups aren't correct." );
583575 }
584576
585577 return absl::OkStatus ();
@@ -694,18 +686,18 @@ Status ClosureGlyphSegmenter::MoveSegmentsToInitFont(
694686 continue ;
695687 }
696688
697- for (const auto & [candidate_segments , _] :
698- context.glyph_groupings .AndGlyphGroups ()) {
699- if (candidate_segments .size () <= 1 ||
700- candidate_segments .intersects (excluded)) {
701- // All size 1 segments handled in the previous loop.
702- // Since this is conjunction, having an excluded segment in it's
689+ for (const auto & [condition , _] :
690+ context.glyph_groupings .ConditionsAndGlyphs ()) {
691+ if (condition. conditions () .size () <= 1 ||
692+ condition. TriggeringSegments () .intersects (excluded)) {
693+ // All size 1 conditions are disjunctive and handled in the previous
694+ // loop. Since this is conjunction, having an excluded segment in it's
703695 // condition makes the probability near 0.
704696 continue ;
705697 }
706698
707- change_made = TRY (CheckAndApplyInitFontMove (candidate_segments, context,
708- initial_segment));
699+ change_made = TRY (CheckAndApplyInitFontMove (
700+ condition. TriggeringSegments (), context, initial_segment));
709701 if (change_made) {
710702 break ;
711703 }
0 commit comments