Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"useTabs": false,
"tabWidth": 2,
"semi": true,
"trailingComma": "es5"
}
31 changes: 31 additions & 0 deletions src/opentype/tables/advanced/lookups/gsub/lookup-type-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SubstLookupRecord,
} from "./gsub-lookup.js";
import { CoverageTable } from "../../shared/coverage.js";
import { ClassDefinition } from "../../shared/class.js";

class LookupType6 extends LookupType {
type = 6;
Expand Down Expand Up @@ -82,6 +83,36 @@ class LookupType6 extends LookupType {
return new CoverageTable(p);
}

getBacktrackClassDef() {
if (this.format !== 2)
throw new Error(
`lookup type 6.${this.format} does not use class definitions.`
);
let p = this.parser;
p.currentPosition = this.start + this.backtrackClassDefOffset;
return new ClassDefinition(p);
}

getInputClassDef() {
if (this.format !== 2)
throw new Error(
`lookup type 6.${this.format} does not use class definitions.`
);
let p = this.parser;
p.currentPosition = this.start + this.inputClassDefOffset;
return new ClassDefinition(p);
}

getLookaheadClassDef() {
if (this.format !== 2)
throw new Error(
`lookup type 6.${this.format} does not use class definitions.`
);
let p = this.parser;
p.currentPosition = this.start + this.lookaheadClassDefOffset;
return new ClassDefinition(p);
}

getSubstLookupRecord(index) {
return this.substLookupRecords?.[index];
}
Expand Down
55 changes: 55 additions & 0 deletions testing/node/gsub/issue-153/gsub.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,59 @@ describe("GSUB 6.2 checks", () => {
substitutionCount: 1,
});
});

test("getInputClassDef returns class definitions for i and j", () => {
const { GSUB } = font.opentype.tables;
const lookup = GSUB.getLookup(3);
const subtable = lookup.getSubTable(0);

const inputClassDef = subtable.getInputClassDef();

expect(inputClassDef.classFormat).toBe(2);

expect(inputClassDef.classRangeRecords).toEqual([
{ startGlyphID: 272, endGlyphID: 272, class: 2 }, // i
{ startGlyphID: 288, endGlyphID: 288, class: 1 }, // j
]);
});

test("getBacktrackClassDef returns no class definitions", () => {
const { GSUB } = font.opentype.tables;
const lookup = GSUB.getLookup(3);
const subtable = lookup.getSubTable(0);

const backtrackClassDef = subtable.getBacktrackClassDef();

// Bangers has no backtrack chars for this lookup
expect(backtrackClassDef.classRangeRecords).toEqual([]);
});

test("getLookaheadClassDef returns multiple definitions", () => {
const { GSUB } = font.opentype.tables;
const lookup = GSUB.getLookup(3);
const subtable = lookup.getSubTable(0);

const lookaheadClassDef = subtable.getLookaheadClassDef();

// Bangers lookahead:
// uni0308
// uni0307
// gravecomb
// acutecomb
// uni030B
// uni0302
// uni030C
// uni0306
// uni030A
// tildecomb
// uni0304
// hookabovecomb
// uni030F
// uni0312
expect(lookaheadClassDef.classRangeRecords).toEqual([
{ startGlyphID: 525, endGlyphID: 529, class: 1 },
{ startGlyphID: 531, endGlyphID: 538, class: 1 },
{ startGlyphID: 540, endGlyphID: 540, class: 1 },
]);
});
});