Skip to content

Commit 3cba5a0

Browse files
committed
Normalize CFF CID sub matrices to work on windows.
1 parent 9853079 commit 3cba5a0

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

@@ -6696,6 +6696,33 @@ var CFFCompiler = (function CFFCompilerClosure() {
66966696
var nameIndex = this.compileNameIndex(cff.names);
66976697
output.add(nameIndex);
66986698

6699+
if (cff.isCIDFont) {
6700+
// The spec is unclear on how font matrices should relate to each other
6701+
// when there is one in the main top dict and the sub top dicts.
6702+
// Windows handles this differently than linux and osx so we have to
6703+
// normalize to work on all.
6704+
// Rules based off of some mailing list discussions:
6705+
// - If main font has a matrix and subfont doesn't, use the main matrix.
6706+
// - If no main font matrix and there is a subfont matrix, use the
6707+
// subfont matrix.
6708+
// - If both have matrices, concat together.
6709+
// - If neither have matrices, use default.
6710+
// To make this work on all platforms we move the top matrix into each
6711+
// sub top dict and concat if necessary.
6712+
if (cff.topDict.hasName('FontMatrix')) {
6713+
var base = cff.topDict.getByName('FontMatrix');
6714+
cff.topDict.removeByName('FontMatrix');
6715+
for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
6716+
var subDict = cff.fdArray[i];
6717+
var matrix = base.slice(0);
6718+
if (subDict.hasName('FontMatrix')) {
6719+
matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
6720+
}
6721+
subDict.setByName('FontMatrix', matrix);
6722+
}
6723+
}
6724+
}
6725+
66996726
var compiled = this.compileTopDicts([cff.topDict],
67006727
output.length,
67016728
cff.isCIDFont);

src/util.js

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

226+
// Concatenates two transformation matrices together and returns the result.
227+
Util.transform = function Util_transform(m1, m2) {
228+
return [
229+
m1[0] * m2[0] + m1[2] * m2[1],
230+
m1[1] * m2[0] + m1[3] * m2[1],
231+
m1[0] * m2[2] + m1[2] * m2[3],
232+
m1[1] * m2[2] + m1[3] * m2[3],
233+
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
234+
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
235+
];
236+
};
237+
226238
// For 2d affine transforms
227239
Util.applyTransform = function Util_applyTransform(p, m) {
228240
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
@@ -883,6 +883,13 @@
883883
"lastPage": 4,
884884
"type": "load"
885885
},
886+
{ "id": "issue3061",
887+
"file": "pdfs/issue3061.pdf",
888+
"md5": "696a7cb1b194d095ca3f7861779a606b",
889+
"rounds": 1,
890+
"type": "eq",
891+
"about": "CFF CID font with font matrices in main top dict and sub top dict."
892+
},
886893
{ "id": "issue1878",
887894
"file": "pdfs/issue1878.pdf",
888895
"md5": "b4fb0ce7c19368e7104dce3d0d34bcb3",

0 commit comments

Comments
 (0)