Skip to content

Commit d0e9c8c

Browse files
authored
Merge branch 'master' into master
2 parents 85d24b0 + de56b63 commit d0e9c8c

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

src/font.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,15 @@ Font.prototype.updateFeatures = function (options) {
175175
};
176176

177177
/**
178-
* Convert the given text to a list of Glyph objects.
178+
* Convert the given text to a list of Glyph indexes.
179179
* Note that there is no strict one-to-one mapping between characters and
180-
* glyphs, so the list of returned glyphs can be larger or smaller than the
180+
* glyphs, so the list of returned glyph indexes can be larger or smaller than the
181181
* length of the given string.
182182
* @param {string}
183183
* @param {GlyphRenderOptions} [options]
184-
* @return {opentype.Glyph[]}
184+
* @return {number[]}
185185
*/
186-
Font.prototype.stringToGlyphs = function(s, options) {
187-
186+
Font.prototype.stringToGlyphIndexes = function(s, options) {
188187
const bidi = new Bidi();
189188

190189
// Create and register 'glyphIndex' state modifier
@@ -198,7 +197,20 @@ Font.prototype.stringToGlyphs = function(s, options) {
198197

199198
bidi.applyFeatures(this, features);
200199

201-
const indexes = bidi.getTextGlyphs(s);
200+
return bidi.getTextGlyphs(s);
201+
};
202+
203+
/**
204+
* Convert the given text to a list of Glyph objects.
205+
* Note that there is no strict one-to-one mapping between characters and
206+
* glyphs, so the list of returned glyphs can be larger or smaller than the
207+
* length of the given string.
208+
* @param {string}
209+
* @param {GlyphRenderOptions} [options]
210+
* @return {opentype.Glyph[]}
211+
*/
212+
Font.prototype.stringToGlyphs = function(s, options) {
213+
const indexes = this.stringToGlyphIndexes(s, options);
202214

203215
let length = indexes.length;
204216

src/hintingtt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ function ODD(state) {
19501950

19511951
if (exports.DEBUG) console.log(state.step, 'ODD[]', n);
19521952

1953-
stack.push(Math.trunc(n) % 2 ? 1 : 0);
1953+
stack.push(Math.trunc(n) & 1 ? 1 : 0);
19541954
}
19551955

19561956
// EVEN[] EVEN
@@ -1961,7 +1961,7 @@ function EVEN(state) {
19611961

19621962
if (exports.DEBUG) console.log(state.step, 'EVEN[]', n);
19631963

1964-
stack.push(Math.trunc(n) % 2 ? 0 : 1);
1964+
stack.push(Math.trunc(n) & 1 ? 0 : 1);
19651965
}
19661966

19671967
// IF[] IF test

src/tables/cff.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function parseCFFCharstring(font, glyph, code) {
527527

528528
// The number of stem operators on the stack is always even.
529529
// If the value is uneven, that means a width is specified.
530-
hasWidthArg = stack.length % 2 !== 0;
530+
hasWidthArg = (stack.length & 1) !== 0;
531531
if (hasWidthArg && !haveWidth) {
532532
width = stack.shift() + nominalWidthX;
533533
}
@@ -780,7 +780,7 @@ function parseCFFCharstring(font, glyph, code) {
780780
p.curveTo(c1x, c1y, c2x, c2y, x, y);
781781
break;
782782
case 26: // vvcurveto
783-
if (stack.length % 2) {
783+
if (stack.length & 1) {
784784
x += stack.shift();
785785
}
786786

@@ -796,7 +796,7 @@ function parseCFFCharstring(font, glyph, code) {
796796

797797
break;
798798
case 27: // hhcurveto
799-
if (stack.length % 2) {
799+
if (stack.length & 1) {
800800
y += stack.shift();
801801
}
802802

test/font.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('font.js', function() {
1717
fGlyph, iGlyph, ffGlyph, fiGlyph, ffiGlyph
1818
];
1919

20+
glyphs.forEach((glyph, index) => glyph.index = index);
21+
2022
beforeEach(function() {
2123
font = new Font({
2224
familyName: 'MyFont',
@@ -49,6 +51,20 @@ describe('font.js', function() {
4951
});
5052
});
5153

54+
describe('stringToGlyphIndexes', function() {
55+
it('must support standard ligatures', function() {
56+
assert.deepEqual(font.stringToGlyphIndexes('fi'), [fGlyph.index, iGlyph.index]);
57+
font.substitution.add('liga', { sub: [1, 1, 2], by: 5 });
58+
font.substitution.add('liga', { sub: [1, 1], by: 3 });
59+
font.substitution.add('liga', { sub: [1, 2], by: 4 });
60+
assert.deepEqual(font.stringToGlyphIndexes('ff'), [ffGlyph.index]);
61+
assert.deepEqual(font.stringToGlyphIndexes('fi'), [fiGlyph.index]);
62+
assert.deepEqual(font.stringToGlyphIndexes('ffi'), [ffiGlyph.index]);
63+
assert.deepEqual(font.stringToGlyphIndexes('fffiffif'),
64+
[ffGlyph.index, fiGlyph.index, ffiGlyph.index, fGlyph.index]);
65+
});
66+
});
67+
5268
describe('stringToGlyphs', function() {
5369
it('must support standard ligatures', function() {
5470
assert.deepEqual(font.stringToGlyphs('fi'), [fGlyph, iGlyph]);

0 commit comments

Comments
 (0)