Skip to content

Commit cebf94e

Browse files
blikblumdevongovett
authored andcommitted
Fix getting the fd index for OTF/CFF CID fonts (#207)
1 parent f2aa3d6 commit cebf94e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/cff/CFFFont.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class CFFFont {
127127

128128
if (gid < ranges[mid].first) {
129129
high = mid - 1;
130-
} else if (mid < high && gid > ranges[mid + 1].first) {
130+
} else if (mid < high && gid >= ranges[mid + 1].first) {
131131
low = mid + 1;
132132
} else {
133133
return ranges[mid].fd;

test/glyphs.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,49 @@ describe('glyphs', function() {
9292
});
9393
});
9494

95+
describe('CFF glyphs (CID font)', function() {
96+
let font = fontkit.openSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf');
97+
98+
it('should get a CFFGlyph', function() {
99+
let glyph = font.getGlyph(27); // :
100+
return assert.equal(glyph.constructor.name, 'CFFGlyph');
101+
});
102+
103+
it('should get a path for the glyph', function() {
104+
let glyph = font.getGlyph(27);
105+
return assert.equal(glyph.path.toSVG(), 'M139 390C175 390 205 419 205 459C205 501 175 530 139 530C103 530 73 501 73 459C73 419 103 390 139 390ZM139 -13C175 -13 205 15 205 56C205 97 175 127 139 127C103 127 73 97 73 56C73 15 103 -13 139 -13Z');
106+
});
107+
108+
it('should get the glyph cbox', function() {
109+
let glyph = font.getGlyph(27);
110+
return assert.deepEqual(glyph.cbox, new BBox(73, -13, 205, 530));
111+
});
112+
113+
it('should get the glyph bbox', function() {
114+
let glyph = font.getGlyph(27);
115+
return assert.deepEqual(glyph.bbox, new BBox(73, -13, 205, 530));
116+
});
117+
118+
it('should get the correct fd index', function() {
119+
let cff = font['CFF '];
120+
// FDSelect ranges
121+
// {first: 0, fd: 5 }
122+
// {first: 1, fd: 15 }
123+
// {first: 17, fd: 17 }
124+
// {first: 27, fd: 15 }
125+
// {first: 102, fd: 3 }
126+
assert.equal(cff.fdForGlyph(0), 5);
127+
assert.equal(cff.fdForGlyph(1), 15);
128+
assert.equal(cff.fdForGlyph(10), 15);
129+
assert.equal(cff.fdForGlyph(16), 15);
130+
assert.equal(cff.fdForGlyph(17), 17);
131+
assert.equal(cff.fdForGlyph(26), 17);
132+
assert.equal(cff.fdForGlyph(27), 15);
133+
assert.equal(cff.fdForGlyph(28), 15);
134+
assert.equal(cff.fdForGlyph(102), 3);
135+
});
136+
});
137+
95138
describe('SBIX glyphs', function() {
96139
let font = fontkit.openSync(__dirname + '/data/ss-emoji/ss-emoji-apple.ttf');
97140

0 commit comments

Comments
 (0)