1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Normalize CFF CID sub matrices to work on windows.

This commit is contained in:
Brendan Dahl 2013-04-15 16:14:07 -07:00
parent 985307907b
commit 3cba5a0c8a
4 changed files with 47 additions and 1 deletions

View file

@ -17,7 +17,7 @@
/* globals assert, bytesToString, CIDToUnicodeMaps, error, ExpertCharset,
ExpertSubsetCharset, FileReaderSync, globalScope, GlyphsUnicode,
info, isArray, isNum, ISOAdobeCharset, isWorker, PDFJS, Stream,
stringToBytes, TextDecoder, TODO, warn, Lexer */
stringToBytes, TextDecoder, TODO, warn, Lexer, Util */
'use strict';
@ -6696,6 +6696,33 @@ var CFFCompiler = (function CFFCompilerClosure() {
var nameIndex = this.compileNameIndex(cff.names);
output.add(nameIndex);
if (cff.isCIDFont) {
// The spec is unclear on how font matrices should relate to each other
// when there is one in the main top dict and the sub top dicts.
// Windows handles this differently than linux and osx so we have to
// normalize to work on all.
// Rules based off of some mailing list discussions:
// - If main font has a matrix and subfont doesn't, use the main matrix.
// - If no main font matrix and there is a subfont matrix, use the
// subfont matrix.
// - If both have matrices, concat together.
// - If neither have matrices, use default.
// To make this work on all platforms we move the top matrix into each
// sub top dict and concat if necessary.
if (cff.topDict.hasName('FontMatrix')) {
var base = cff.topDict.getByName('FontMatrix');
cff.topDict.removeByName('FontMatrix');
for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
var subDict = cff.fdArray[i];
var matrix = base.slice(0);
if (subDict.hasName('FontMatrix')) {
matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
}
subDict.setByName('FontMatrix', matrix);
}
}
}
var compiled = this.compileTopDicts([cff.topDict],
output.length,
cff.isCIDFont);

View file

@ -223,6 +223,18 @@ var Util = PDFJS.Util = (function UtilClosure() {
return Util.makeCssCmyk(cmyk);
};
// Concatenates two transformation matrices together and returns the result.
Util.transform = function Util_transform(m1, m2) {
return [
m1[0] * m2[0] + m1[2] * m2[1],
m1[1] * m2[0] + m1[3] * m2[1],
m1[0] * m2[2] + m1[2] * m2[3],
m1[1] * m2[2] + m1[3] * m2[3],
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
];
};
// For 2d affine transforms
Util.applyTransform = function Util_applyTransform(p, m) {
var xt = p[0] * m[0] + p[1] * m[2] + m[4];