Skip to content

Commit aede072

Browse files
authored
Saturate AAT kerning position accumulation (#400)
1 parent b7db0bb commit aede072

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

harfrust/src/hb/aat/layout_kerx_table.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ fn apply_simple_kerning<T: SimpleKerning>(c: &mut AatApplyContext, subtable: &Su
249249
} else {
250250
let kern1 = kern >> 1;
251251
let kern2 = kern - kern1;
252-
pos[i].x_advance += kern1;
253-
pos[j].x_advance += kern2;
254-
pos[j].x_offset += kern2;
252+
pos[i].x_advance = pos[i].x_advance.saturating_add(kern1);
253+
pos[j].x_advance = pos[j].x_advance.saturating_add(kern2);
254+
pos[j].x_offset = pos[j].x_offset.saturating_add(kern2);
255255
}
256256
} else {
257257
if cross_stream {
@@ -260,9 +260,9 @@ fn apply_simple_kerning<T: SimpleKerning>(c: &mut AatApplyContext, subtable: &Su
260260
} else {
261261
let kern1 = kern >> 1;
262262
let kern2 = kern - kern1;
263-
pos[i].y_advance += kern1;
264-
pos[j].y_advance += kern2;
265-
pos[j].y_offset += kern2;
263+
pos[i].y_advance = pos[i].y_advance.saturating_add(kern1);
264+
pos[j].y_advance = pos[j].y_advance.saturating_add(kern2);
265+
pos[j].y_offset = pos[j].y_offset.saturating_add(kern2);
266266
}
267267
}
268268

@@ -573,12 +573,12 @@ impl StateTableDriver<Subtable1<'_>, BigEndian<u16>> for Driver1 {
573573
pos.set_attach_chain(0);
574574
pos.y_offset = 0;
575575
} else if pos.attach_type() != 0 {
576-
pos.y_offset += scaled_v;
576+
pos.y_offset = pos.y_offset.saturating_add(scaled_v);
577577
has_gpos_attachment = true;
578578
}
579579
} else if glyph_mask & c.plan.kern_mask != 0 {
580-
pos.x_advance += scaled_v;
581-
pos.x_offset += scaled_v;
580+
pos.x_advance = pos.x_advance.saturating_add(scaled_v);
581+
pos.x_offset = pos.x_offset.saturating_add(scaled_v);
582582
}
583583
} else {
584584
if has_cross_stream {
@@ -588,13 +588,13 @@ impl StateTableDriver<Subtable1<'_>, BigEndian<u16>> for Driver1 {
588588
pos.set_attach_chain(0);
589589
pos.x_offset = 0;
590590
} else if pos.attach_type() != 0 {
591-
pos.x_offset += scaled_v;
591+
pos.x_offset = pos.x_offset.saturating_add(scaled_v);
592592
has_gpos_attachment = true;
593593
}
594594
} else if glyph_mask & c.plan.kern_mask != 0 {
595595
if pos.y_offset == 0 {
596-
pos.y_advance += scaled_v;
597-
pos.y_offset += scaled_v;
596+
pos.y_advance = pos.y_advance.saturating_add(scaled_v);
597+
pos.y_offset = pos.y_offset.saturating_add(scaled_v);
598598
}
599599
}
600600
}

harfrust/src/hb/kerning.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ fn machine_kern<F>(
172172
} else {
173173
let kern1 = kern >> 1;
174174
let kern2 = kern - kern1;
175-
pos[i].x_advance += kern1;
176-
pos[j].x_advance += kern2;
177-
pos[j].x_offset += kern2;
175+
pos[i].x_advance = pos[i].x_advance.saturating_add(kern1);
176+
pos[j].x_advance = pos[j].x_advance.saturating_add(kern2);
177+
pos[j].x_offset = pos[j].x_offset.saturating_add(kern2);
178178
}
179179
} else {
180180
if cross_stream {
@@ -183,9 +183,9 @@ fn machine_kern<F>(
183183
} else {
184184
let kern1 = kern >> 1;
185185
let kern2 = kern - kern1;
186-
pos[i].y_advance += kern1;
187-
pos[j].y_advance += kern2;
188-
pos[j].y_offset += kern2;
186+
pos[i].y_advance = pos[i].y_advance.saturating_add(kern1);
187+
pos[j].y_advance = pos[j].y_advance.saturating_add(kern2);
188+
pos[j].y_offset = pos[j].y_offset.saturating_add(kern2);
189189
}
190190
}
191191

@@ -488,12 +488,12 @@ fn state_machine_transition(
488488
pos.set_attach_chain(0);
489489
pos.y_offset = 0;
490490
} else if pos.attach_type() != 0 {
491-
pos.y_offset += scaled_v;
491+
pos.y_offset = pos.y_offset.saturating_add(scaled_v);
492492
has_gpos_attachment = true;
493493
}
494494
} else if glyph_mask & kern_mask != 0 {
495-
pos.x_advance += scaled_v;
496-
pos.x_offset += scaled_v;
495+
pos.x_advance = pos.x_advance.saturating_add(scaled_v);
496+
pos.x_offset = pos.x_offset.saturating_add(scaled_v);
497497
}
498498
} else {
499499
if is_cross_stream {
@@ -503,13 +503,13 @@ fn state_machine_transition(
503503
pos.set_attach_chain(0);
504504
pos.x_offset = 0;
505505
} else if pos.attach_type() != 0 {
506-
pos.x_offset += scaled_v;
506+
pos.x_offset = pos.x_offset.saturating_add(scaled_v);
507507
has_gpos_attachment = true;
508508
}
509509
} else if glyph_mask & kern_mask != 0 {
510510
if pos.y_offset == 0 {
511-
pos.y_advance += scaled_v;
512-
pos.y_offset += scaled_v;
511+
pos.y_advance = pos.y_advance.saturating_add(scaled_v);
512+
pos.y_offset = pos.y_offset.saturating_add(scaled_v);
513513
}
514514
}
515515
}

0 commit comments

Comments
 (0)