Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Unreleased

- Rearrange glyphs in AAT morx tables only when the marked range holds every glyph the verb moves, like CoreText and HarfBuzz (#142, #143)
- Fix AAT glyph insertion: insert the marked glyph count, set the mark after inserting, skip the inserted glyphs, and limit how many glyphs a font can insert, like HarfBuzz (#171, #172, #173, #174)
- Stop AAT morx state machines that never advance after a bounded number of steps, like HarfBuzz (#175)
- Shape Tai Tham sakot followed by a consonant after vowel signs like HarfBuzz, instead of inserting a dotted circle
Expand Down
21 changes: 14 additions & 7 deletions src/aat/AATMorxProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const MARK_FIRST = 0x8000;
const MARK_LAST = 0x2000;
const VERB = 0x000f;

// number of glyphs each rearrangement verb moves, e.g. 3 for AxCD => CDxA
const VERB_LENGTH = [0, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4];

// contextual substitution and glyph insertion flag
const SET_MARK = 0x8000;

Expand Down Expand Up @@ -148,15 +151,19 @@ export default class AATMorxProcessor {
}

if (entry.flags & MARK_LAST) {
this.lastGlyph = index;
this.lastGlyph = Math.min(index, this.glyphs.length - 1);
}

reorderGlyphs(
this.glyphs,
entry.flags & VERB,
this.firstGlyph,
this.lastGlyph,
);
// Like CoreText and HarfBuzz, leave the glyphs alone unless the marked
// range holds every glyph the verb moves (#142, #143).
let verb = entry.flags & VERB;
let firstGlyph = this.firstGlyph === null ? 0 : this.firstGlyph;
if (
this.lastGlyph !== null &&
this.lastGlyph - firstGlyph + 1 >= VERB_LENGTH[verb]
) {
reorderGlyphs(this.glyphs, verb, firstGlyph, this.lastGlyph);
}
}

processContextualSubstitution(glyph, entry, index) {
Expand Down
Binary file added test/data/fonttest/TestMORXFour.ttf
Binary file not shown.
Binary file added test/data/fonttest/TestMORXThree.ttf
Binary file not shown.
40 changes: 40 additions & 0 deletions test/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,44 @@ describe('issues', function () {
assert(glyphs.length <= 65536);
});
});

describe('#142 - morx rearrangement without a marked range', function () {
it('should leave the glyphs unchanged', function () {
// MORX-3 from Unicode text-rendering-tests runs every rearrangement
// verb before any glyph has been marked.
let font = fontkit.openSync(
new URL('data/fonttest/TestMORXThree.ttf', import.meta.url),
);

for (let digit of ['3', '4', '8', '⓯']) {
assert.deepEqual(
font
.layout(`ABXCD${digit}`)
.glyphs.slice(0, 5)
.map((glyph) => glyph.name),
['A', 'B', 'X', 'C', 'D'],
);
}
});
});

describe('#143 - morx rearrangement underflow', function () {
it('should not move glyphs outside the marked range', function () {
// MORX-5 from Unicode text-rendering-tests marks a range shorter than
// the glyphs each rearrangement verb moves.
let font = fontkit.openSync(
new URL('data/fonttest/TestMORXFour.ttf', import.meta.url),
);

for (let text of ['PQRAXYZ3', 'PQRAXYZ⓬', 'PQRABXYZ⓬', 'PQRABCXYZ⓯']) {
assert.deepEqual(
font
.layout(text)
.glyphs.slice(0, -1)
.map((glyph) => glyph.name),
[...text.slice(0, -1)],
);
}
});
});
});
Loading