Skip to content

Commit b52274d

Browse files
committed
Merge pull request mozilla#3102 from brendandahl/sub-matrix
Normalize CFF CID sub matrices to work on windows.
2 parents 2a320f8 + 3cba5a0 commit b52274d

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/fonts.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* globals assert, bytesToString, CIDToUnicodeMaps, error, ExpertCharset,
1818
ExpertSubsetCharset, FileReaderSync, globalScope, GlyphsUnicode,
1919
info, isArray, isNum, ISOAdobeCharset, isWorker, PDFJS, Stream,
20-
stringToBytes, TextDecoder, TODO, warn, Lexer */
20+
stringToBytes, TextDecoder, TODO, warn, Lexer, Util */
2121

2222
'use strict';
2323

@@ -6791,6 +6791,33 @@ var CFFCompiler = (function CFFCompilerClosure() {
67916791
var nameIndex = this.compileNameIndex(cff.names);
67926792
output.add(nameIndex);
67936793

6794+
if (cff.isCIDFont) {
6795+
// The spec is unclear on how font matrices should relate to each other
6796+
// when there is one in the main top dict and the sub top dicts.
6797+
// Windows handles this differently than linux and osx so we have to
6798+
// normalize to work on all.
6799+
// Rules based off of some mailing list discussions:
6800+
// - If main font has a matrix and subfont doesn't, use the main matrix.
6801+
// - If no main font matrix and there is a subfont matrix, use the
6802+
// subfont matrix.
6803+
// - If both have matrices, concat together.
6804+
// - If neither have matrices, use default.
6805+
// To make this work on all platforms we move the top matrix into each
6806+
// sub top dict and concat if necessary.
6807+
if (cff.topDict.hasName('FontMatrix')) {
6808+
var base = cff.topDict.getByName('FontMatrix');
6809+
cff.topDict.removeByName('FontMatrix');
6810+
for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
6811+
var subDict = cff.fdArray[i];
6812+
var matrix = base.slice(0);
6813+
if (subDict.hasName('FontMatrix')) {
6814+
matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
6815+
}
6816+
subDict.setByName('FontMatrix', matrix);
6817+
}
6818+
}
6819+
}
6820+
67946821
var compiled = this.compileTopDicts([cff.topDict],
67956822
output.length,
67966823
cff.isCIDFont);

src/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ var Util = PDFJS.Util = (function UtilClosure() {
262262
return Util.makeCssCmyk(cmyk);
263263
};
264264

265+
// Concatenates two transformation matrices together and returns the result.
266+
Util.transform = function Util_transform(m1, m2) {
267+
return [
268+
m1[0] * m2[0] + m1[2] * m2[1],
269+
m1[1] * m2[0] + m1[3] * m2[1],
270+
m1[0] * m2[2] + m1[2] * m2[3],
271+
m1[1] * m2[2] + m1[3] * m2[3],
272+
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
273+
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
274+
];
275+
};
276+
265277
// For 2d affine transforms
266278
Util.applyTransform = function Util_applyTransform(p, m) {
267279
var xt = p[0] * m[0] + p[1] * m[2] + m[4];

test/pdfs/issue3061.pdf

16.6 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,13 @@
906906
"lastPage": 4,
907907
"type": "load"
908908
},
909+
{ "id": "issue3061",
910+
"file": "pdfs/issue3061.pdf",
911+
"md5": "696a7cb1b194d095ca3f7861779a606b",
912+
"rounds": 1,
913+
"type": "eq",
914+
"about": "CFF CID font with font matrices in main top dict and sub top dict."
915+
},
909916
{ "id": "issue1878",
910917
"file": "pdfs/issue1878.pdf",
911918
"md5": "b4fb0ce7c19368e7104dce3d0d34bcb3",

0 commit comments

Comments
 (0)