Skip to content

Commit

Permalink
Get glyph properties from GDEF instead of unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Oct 11, 2016
1 parent fa13a1c commit b6d4653
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/opentype/GSUBProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default class GSUBProcessor extends OTProcessor {
this.glyphIterator.cur.id = sequence[0];

let features = this.glyphIterator.cur.features;
let replacement = sequence.slice(1).map(gid => new GlyphInfo(gid, undefined, features));
let curGlyph = this.glyphIterator.cur;
let replacement = sequence.slice(1).map((gid, i) => {
let glyph = new GlyphInfo(this.font, gid, undefined, features);
glyph.shaperInfo = curGlyph.shaperInfo;
return glyph;
});

this.glyphs.splice(this.glyphIterator.index + 1, 0, ...replacement);
return true;
Expand Down Expand Up @@ -72,8 +77,8 @@ export default class GSUBProcessor extends OTProcessor {
}

// Create the replacement ligature glyph
let ligatureGlyph = new GlyphInfo(ligature.glyph, characters);
ligatureGlyph.features = curGlyph.features;
let ligatureGlyph = new GlyphInfo(this.font, ligature.glyph, characters, curGlyph.features);
ligatureGlyph.shaperInfo = curGlyph.shaperInfo;

// From Harfbuzz:
// - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
Expand Down
28 changes: 22 additions & 6 deletions src/opentype/GlyphInfo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import unicode from 'unicode-properties';
import OTProcessor from './OTProcessor';

export default class GlyphInfo {
constructor(id, codePoints = [], features = []) {
this.id = id;
constructor(font, id, codePoints = [], features = []) {
this._font = font;
this.codePoints = codePoints;

// TODO: get this info from GDEF if available
this.isMark = this.codePoints.every(unicode.isMark);
this.isLigature = this.codePoints.length > 1;
this.id = id;

this.features = {};
if (Array.isArray(features)) {
Expand All @@ -25,4 +23,22 @@ export default class GlyphInfo {
this.markAttachment = null;
this.shaperInfo = null;
}

get id() {
return this._id;
}

set id(id) {
this._id = id;

if (this._font.GDEF) {
// TODO: clean this up
let classID = OTProcessor.prototype.getClassID(id, this._font.GDEF.glyphClassDef);
this.isMark = classID === 3;
this.isLigature = classID === 2;
} else {
this.isMark = this.codePoints.every(unicode.isMark);
this.isLigature = this.codePoints.length > 1;
}
}
}
2 changes: 1 addition & 1 deletion src/opentype/OTLayoutEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class OTLayoutEngine {
setup(glyphs, features, script, language) {
// Map glyphs to GlyphInfo objects so data can be passed between
// GSUB and GPOS without mutating the real (shared) Glyph objects.
this.glyphInfos = glyphs.map(glyph => new GlyphInfo(glyph.id, [...glyph.codePoints]));
this.glyphInfos = glyphs.map(glyph => new GlyphInfo(this.font, glyph.id, [...glyph.codePoints]));

// Choose a shaper based on the script, and setup a shaping plan.
// This determines which features to apply to which glyphs.
Expand Down
2 changes: 1 addition & 1 deletion src/opentype/shapers/HangulShaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const STATE_TABLE = [
];

function getGlyph(font, code, features) {
return new GlyphInfo(font.glyphForCodePoint(code).id, [code], Object.keys(features));
return new GlyphInfo(font, font.glyphForCodePoint(code).id, [code], features);
}

function decompose(glyphs, i, font) {
Expand Down

0 comments on commit b6d4653

Please sign in to comment.