Skip to content

Commit a086c88

Browse files
committed
preserve Arabic medials when line-wrapping
can't believe I never caught this! it's a bit rare since you have to break a word rather than splitting on a space.
1 parent 34bfeab commit a086c88

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/layout-text.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,11 +2015,18 @@ function shapePart(
20152015
face: LoadedFontFace,
20162016
attrs: ShapingAttrs
20172017
) {
2018-
if (face.spaceMayParticipateInShaping(attrs.script)) {
2019-
return shapePartWithoutWordCache(block, offset, length, face.hbfont, attrs);
2020-
} else {
2021-
return shapePartWithWordCache(block, offset, length, face.hbfont, attrs);
2018+
if (!face.spaceMayParticipateInShaping(attrs.script)) {
2019+
const t = block.text;
2020+
const end = offset + length;
2021+
if (
2022+
(offset === 0 || t[offset] === ' ' || t[offset - 1] === ' ') &&
2023+
(end === t.length || t[end] === ' ' || t[end - 1] === ' ')
2024+
) {
2025+
return shapePartWithWordCache(block, offset, length, face.hbfont, attrs);
2026+
}
20222027
}
2028+
2029+
return shapePartWithoutWordCache(block, offset, length, face.hbfont, attrs);
20232030
}
20242031

20252032
export function createIfcShapedItems(

test/text.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,15 +1084,17 @@ describe('Lines', function () {
10841084
expect(inline.lineboxes[1].head.value.offset).to.equal(12);
10851085
});
10861086

1087-
it('adds a soft hyphen to RTL text if one fits after a &shy', function () {
1087+
it('adds a soft hyphen to Arabic and keeps medial form', function () {
10881088
this.reflow(`
10891089
<div id="t" style="direction: rtl; font: 24px Cairo; width: 51px;">
10901090
دامي&shy;دى
10911091
</div>
10921092
`);
10931093
/** @type import('../src/layout-flow.ts').BlockContainerOfInlines */
10941094
const inline = this.get('div');
1095-
expect(inline.lineboxes[0].head.value.glyphs[0 * G_SZ + G_ID]).to.equal(672);
1095+
expect(inline.lineboxes[0].head.value.glyphs[0 * G_SZ + G_ID]).to.equal(672); // hyphen
1096+
expect(inline.lineboxes[0].head.value.glyphs[1 * G_SZ + G_ID]).to.equal(697); // shy
1097+
expect(inline.lineboxes[0].head.value.glyphs[2 * G_SZ + G_ID]).to.equal(441); // yeh, medial
10961098
expect(inline.lineboxes[1].head.value.offset).to.equal(6);
10971099
});
10981100

0 commit comments

Comments
 (0)