Skip to content

Commit

Permalink
[GPOS] Disable split-kerning
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Feb 14, 2024
1 parent d214427 commit 8e195a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 80 deletions.
79 changes: 1 addition & 78 deletions src/ot/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,84 +237,7 @@ impl Apply for PairAdjustment<'_> {
let flags = matrix.value_format_flags();
let len2 = flags.1.len();

// Isolate simple kerning and apply it half to each side.
// Results in better cursor positioning / underline drawing.
if len2 == 0 {
let dir = ctx.buffer.direction;
let mut mask = if dir.is_horizontal() {
ValueFormatFlags::x_advance()
} else {
ValueFormatFlags::y_advance()
};

if dir.is_backward() {
mask |= mask >> 2;
}

mask |= mask << 4;

if (flags.0.bits() & !mask) == 1 {
return bail(ctx, records, len2);
} else {
let mut dummy_pos = GlyphPosition::default();
if records.0.apply_to_pos(ctx, &mut dummy_pos) {
let src = &mut dummy_pos;
let (arr1, arr2) = ctx.buffer.pos.split_at_mut(second_glyph_index);
let dst1 = &mut arr1[first_glyph_index];
let dst2 = &mut arr2[0];

let (
src_advance,
dst1_advance,
dst2_advance,
src_offset,
dst1_offset,
dst2_offset,
) = if dir.is_horizontal() {
(
&mut src.x_advance,
&mut dst1.x_advance,
&mut dst2.x_advance,
&mut src.x_offset,
&mut dst1.x_offset,
&mut dst2.x_offset,
)
} else {
(
&mut src.y_advance,
&mut dst1.y_advance,
&mut dst2.y_advance,
&mut src.y_offset,
&mut dst1.y_offset,
&mut dst2.y_offset,
)
};

let kern = *src_advance;
let kern1 = kern >> 1;
let kern2 = kern - kern1;

if !dir.is_backward() {
*dst1_advance += kern1;
*dst2_advance += kern2;
*dst2_offset += kern2;
} else {
*dst1_advance += kern1;
*dst1_offset += *src_offset - kern2;
*dst2_advance += kern2;
}

let applied_first = kern != 0;
let applied_second = kern != 0;

return success(ctx, applied_first, applied_second, len2);
} else {
return boring(ctx, len2);
}
}
} else {
return bail(ctx, records, len2);
}
return bail(ctx, records, len2);
}
};

Expand Down
15 changes: 15 additions & 0 deletions tests/shaping/aots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,21 @@ fn gpos2_2_004() {
);
}

#[test]
fn gpos2_2_005() {
assert_eq!(
shape(
"tests/fonts/aots/gpos2_2_font5.otf",
"\u{0012}\u{0012}\u{0012}\u{0012}",
"--features=\"test\" --single-par --no-clusters --no-glyph-names --ned",
),
"18@-100,0|\
18@1400,0|\
18@2900,0|\
18@4500,0"
);
}

#[test]
fn gpos3_002() {
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions tests/shaping/in_house.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7481,8 +7481,8 @@ fn positioning_features_001() {
"\u{0041}\u{0056}",
"",
),
"A=0+665|\
V=1@-40,0+635"
"A=0+625|\
V=1+675"
);
}

Expand Down

0 comments on commit 8e195a3

Please sign in to comment.