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: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ Fontkit includes several methods for accessing glyph metrics and performing layo

Returns the advance width (described above) for a single glyph id.

#### `font.layout(string, features = [])`
#### `font.layout(string, features = [] | {})`

This method returns a `GlyphRun` object, which includes an array of `Glyph`s and `GlyphPosition`s for the given string.
`Glyph` objects are described below. `GlyphPosition` objects include 4 properties: `xAdvance`, `yAdvance`, `xOffset`,
and `yOffset`.

The `features` parameter is an array of [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) to be applied
in addition to the default set. If this is an AAT font, the OpenType feature tags are mapped to AAT features.
The `features` parameter is either an array of [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) to be applied
in addition to the default set, or an object mapping OpenType features to a boolean enabling or disabling each. If this is an AAT font, the OpenType feature tags are mapped to AAT features.

### Variation fonts

Expand Down
13 changes: 9 additions & 4 deletions src/aat/AATMorxProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ export default class AATMorxProcessor {
}

// Processes an array of glyphs and applies the specified features
// Features should be in the form of {featureType:{featureSetting:true}}
// Features should be in the form of {featureType:{featureSetting:boolean}}
process(glyphs, features = {}) {
for (let chain of this.morx.chains) {
let flags = chain.defaultFlags;

// enable/disable the requested features
for (let feature of chain.features) {
let f;
if ((f = features[feature.featureType]) && f[feature.featureSetting]) {
flags &= feature.disableFlags;
flags |= feature.enableFlags;
if (f = features[feature.featureType]) {
if (f[feature.featureSetting]) {
flags &= feature.disableFlags;
flags |= feature.enableFlags;
} else if (f[feature.featureSetting] === false) {
flags |= ~feature.disableFlags;
flags &= ~feature.enableFlags;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/glyph_mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ describe('character to glyph mapping', function() {
return assert.deepEqual(glyphs.map(g => g.codePoints), [[102, 102, 105], [32], [49], [8260], [50]]);
});

it('should allow for disabling of default AAT morx features', function() {
let {glyphs} = font.layout('ffi 1⁄2', { 'liga': false });
assert.equal(glyphs.length, 7);
assert.deepEqual(glyphs.map(g => g.id), [73, 73, 76, 3, 20, 645, 21]);
return assert.deepEqual(glyphs.map(g => g.codePoints), [[102], [102], [105], [32], [49], [8260], [50]]);
});

it('should apply user specified features', function() {
let {glyphs} = font.layout('ffi 1⁄2', [ 'numr' ]);
assert.equal(glyphs.length, 3);
Expand Down