Skip to content

Commit 33f7e86

Browse files
committed
Merge pull request mozilla#2047 from yurydelendik/font-linux
Fixes fonts on linux
2 parents cfca36c + e32ecc4 commit 33f7e86

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/fonts.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,7 @@ var Font = (function FontClosure() {
29382938
}
29392939
this.toFontChar = toFontChar;
29402940
}
2941+
var unitsPerEm = properties.unitsPerEm || 1000; // defaulting to 1000
29412942

29422943
var fields = {
29432944
// PostScript Font Program
@@ -2958,7 +2959,7 @@ var Font = (function FontClosure() {
29582959
'\x00\x00\x00\x00' + // checksumAdjustement
29592960
'\x5F\x0F\x3C\xF5' + // magicNumber
29602961
'\x00\x00' + // Flags
2961-
'\x03\xE8' + // unitsPerEM (defaulting to 1000)
2962+
safeString16(unitsPerEm) + // unitsPerEM
29622963
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
29632964
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
29642965
'\x00\x00' + // xMin
@@ -4413,6 +4414,19 @@ var CFFParser = (function CFFParserClosure() {
44134414
var charStringOffset = topDict.getByName('CharStrings');
44144415
cff.charStrings = this.parseCharStrings(charStringOffset);
44154416

4417+
var fontMatrix = topDict.getByName('FontMatrix');
4418+
if (fontMatrix) {
4419+
// estimating unitsPerEM for the font
4420+
properties.unitsPerEm = 1 / fontMatrix[0];
4421+
}
4422+
4423+
var fontBBox = topDict.getByName('FontBBox');
4424+
if (fontBBox) {
4425+
// adjusting ascent/descent
4426+
properties.ascent = fontBBox[3];
4427+
properties.descent = fontBBox[1];
4428+
}
4429+
44164430
var charset, encoding;
44174431
if (cff.isCIDFont) {
44184432
var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
@@ -4486,7 +4500,7 @@ var CFFParser = (function CFFParserClosure() {
44864500
return parseFloatOperand(pos);
44874501
} else if (value === 28) {
44884502
value = dict[pos++];
4489-
value = (value << 8) | dict[pos++];
4503+
value = ((value << 24) | (dict[pos++] << 16)) >> 16;
44904504
return value;
44914505
} else if (value === 29) {
44924506
value = dict[pos++];

test/unit/font_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('font', function() {
4242
}
4343

4444
describe('CFFParser', function() {
45-
var parser = new CFFParser(fontData);
45+
var parser = new CFFParser(fontData, {});
4646
var cff = parser.parse();
4747

4848
it('parses header', function() {

0 commit comments

Comments
 (0)