Making src/core/evaluator.js adhere to the style guide
This commit is contained in:
parent
026d58e9a4
commit
c6a06c0f16
@ -103,18 +103,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
var groupSubtype = group.get('S');
|
var groupSubtype = group.get('S');
|
||||||
if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
|
if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
|
||||||
groupOptions.isolated = group.get('I') || false;
|
groupOptions.isolated = (group.get('I') || false);
|
||||||
groupOptions.knockout = group.get('K') || false;
|
groupOptions.knockout = (group.get('K') || false);
|
||||||
var colorSpace = group.get('CS');
|
var colorSpace = group.get('CS');
|
||||||
groupOptions.colorSpace = colorSpace ?
|
groupOptions.colorSpace = (colorSpace ?
|
||||||
ColorSpace.parseToIR(colorSpace, this.xref, resources) : null;
|
ColorSpace.parseToIR(colorSpace, this.xref, resources) : null);
|
||||||
}
|
}
|
||||||
operatorList.addOp(OPS.beginGroup, [groupOptions]);
|
operatorList.addOp(OPS.beginGroup, [groupOptions]);
|
||||||
}
|
}
|
||||||
|
|
||||||
operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
|
operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
|
||||||
|
|
||||||
this.getOperatorList(xobj, xobj.dict.get('Resources') || resources,
|
this.getOperatorList(xobj, (xobj.dict.get('Resources') || resources),
|
||||||
operatorList, state);
|
operatorList, state);
|
||||||
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
||||||
|
|
||||||
@ -123,8 +123,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(
|
buildPaintImageXObject:
|
||||||
resources, image, inline, operatorList,
|
function PartialEvaluator_buildPaintImageXObject(resources, image,
|
||||||
|
inline, operatorList,
|
||||||
cacheKey, cache) {
|
cacheKey, cache) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var dict = image.dict;
|
var dict = image.dict;
|
||||||
@ -136,9 +137,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageMask = dict.get('ImageMask', 'IM') || false;
|
var imageMask = (dict.get('ImageMask', 'IM') || false);
|
||||||
if (imageMask) {
|
if (imageMask) {
|
||||||
// This depends on a tmpCanvas beeing filled with the
|
// This depends on a tmpCanvas being filled with the
|
||||||
// current fillStyle, such that processing the pixel
|
// current fillStyle, such that processing the pixel
|
||||||
// data can't be done here. Instead of creating a
|
// data can't be done here. Instead of creating a
|
||||||
// complete PDFImage, only read the information needed
|
// complete PDFImage, only read the information needed
|
||||||
@ -150,7 +151,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var imgArray = image.getBytes(bitStrideLength * height);
|
var imgArray = image.getBytes(bitStrideLength * height);
|
||||||
var decode = dict.get('Decode', 'D');
|
var decode = dict.get('Decode', 'D');
|
||||||
var canTransfer = image instanceof DecodeStream;
|
var canTransfer = image instanceof DecodeStream;
|
||||||
var inverseDecode = !!decode && decode[0] > 0;
|
var inverseDecode = (!!decode && decode[0] > 0);
|
||||||
|
|
||||||
var imgData = PDFImage.createMask(imgArray, width, height,
|
var imgData = PDFImage.createMask(imgArray, width, height,
|
||||||
canTransfer, inverseDecode);
|
canTransfer, inverseDecode);
|
||||||
@ -165,13 +166,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var softMask = dict.get('SMask', 'SM') || false;
|
var softMask = (dict.get('SMask', 'SM') || false);
|
||||||
var mask = dict.get('Mask') || false;
|
var mask = (dict.get('Mask') || false);
|
||||||
|
|
||||||
var SMALL_IMAGE_DIMENSIONS = 200;
|
var SMALL_IMAGE_DIMENSIONS = 200;
|
||||||
// Inlining small images into the queue as RGB data
|
// Inlining small images into the queue as RGB data
|
||||||
if (inline && !softMask && !mask &&
|
if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
|
||||||
!(image instanceof JpegStream) &&
|
|
||||||
(w + h) < SMALL_IMAGE_DIMENSIONS) {
|
(w + h) < SMALL_IMAGE_DIMENSIONS) {
|
||||||
var imageObj = new PDFImage(this.xref, resources, image,
|
var imageObj = new PDFImage(this.xref, resources, image,
|
||||||
inline, null, null);
|
inline, null, null);
|
||||||
@ -184,7 +184,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
// If there is no imageMask, create the PDFImage and a lot
|
// If there is no imageMask, create the PDFImage and a lot
|
||||||
// of image processing can be done here.
|
// of image processing can be done here.
|
||||||
var uniquePrefix = this.uniquePrefix || '';
|
var uniquePrefix = (this.uniquePrefix || '');
|
||||||
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
|
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
|
||||||
operatorList.addDependency(objId);
|
operatorList.addDependency(objId);
|
||||||
var args = [objId, w, h];
|
var args = [objId, w, h];
|
||||||
@ -193,17 +193,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
image.isNativelySupported(this.xref, resources)) {
|
image.isNativelySupported(this.xref, resources)) {
|
||||||
// These JPEGs don't need any more processing so we can just send it.
|
// These JPEGs don't need any more processing so we can just send it.
|
||||||
operatorList.addOp(OPS.paintJpegXObject, args);
|
operatorList.addOp(OPS.paintJpegXObject, args);
|
||||||
this.handler.send(
|
this.handler.send('obj',
|
||||||
'obj', [objId, this.pageIndex, 'JpegStream', image.getIR()]);
|
[objId, this.pageIndex, 'JpegStream', image.getIR()]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PDFImage.buildImage(function(imageObj) {
|
PDFImage.buildImage(function(imageObj) {
|
||||||
var imgData = imageObj.createImageData(/* forceRGBA = */ false);
|
var imgData = imageObj.createImageData(/* forceRGBA = */ false);
|
||||||
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
|
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
|
||||||
null, [imgData.data.buffer]);
|
null, [imgData.data.buffer]);
|
||||||
}, self.handler, self.xref, resources, image, inline);
|
}, self.handler, self.xref, resources, image, inline);
|
||||||
|
|
||||||
operatorList.addOp(OPS.paintImageXObject, args);
|
operatorList.addOp(OPS.paintImageXObject, args);
|
||||||
if (cacheKey) {
|
if (cacheKey) {
|
||||||
cache.key = cacheKey;
|
cache.key = cacheKey;
|
||||||
@ -224,12 +224,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
operatorList);
|
operatorList);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleTilingType: function PartialEvaluator_handleTilingType(
|
handleTilingType:
|
||||||
fn, args, resources, pattern, patternDict,
|
function PartialEvaluator_handleTilingType(fn, args, resources,
|
||||||
|
pattern, patternDict,
|
||||||
operatorList) {
|
operatorList) {
|
||||||
// Create an IR of the pattern code.
|
// Create an IR of the pattern code.
|
||||||
var tilingOpList = this.getOperatorList(pattern,
|
var tilingOpList = this.getOperatorList(pattern,
|
||||||
patternDict.get('Resources') || resources);
|
(patternDict.get('Resources') || resources));
|
||||||
// Add the dependencies to the parent operator list so they are resolved
|
// Add the dependencies to the parent operator list so they are resolved
|
||||||
// before sub operator list is executed synchronously.
|
// before sub operator list is executed synchronously.
|
||||||
operatorList.addDependencies(tilingOpList.dependencies);
|
operatorList.addDependencies(tilingOpList.dependencies);
|
||||||
@ -239,9 +240,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}, patternDict, args));
|
}, patternDict, args));
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSetFont: function PartialEvaluator_handleSetFont(
|
handleSetFont:
|
||||||
resources, fontArgs, fontRef, operatorList) {
|
function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
|
||||||
|
operatorList) {
|
||||||
// TODO(mack): Not needed?
|
// TODO(mack): Not needed?
|
||||||
var fontName;
|
var fontName;
|
||||||
if (fontArgs) {
|
if (fontArgs) {
|
||||||
@ -404,7 +405,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (!isDict(font)) {
|
if (!isDict(font)) {
|
||||||
return errorFont();
|
return errorFont();
|
||||||
}
|
}
|
||||||
// Workaround for bad PDF generators that doesn't reference fonts
|
// Workaround for bad PDF generators that don't reference fonts
|
||||||
// properly, i.e. by not using an object identifier.
|
// properly, i.e. by not using an object identifier.
|
||||||
// Check if the fontRef is a Dict (as opposed to a standard object),
|
// Check if the fontRef is a Dict (as opposed to a standard object),
|
||||||
// in which case we don't cache the font and instead reference it by
|
// in which case we don't cache the font and instead reference it by
|
||||||
@ -414,8 +415,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.fontCache.put(fontRef, font);
|
this.fontCache.put(fontRef, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep track of each font we translated so the caller can
|
// Keep track of each font we translated so the caller can
|
||||||
// load them asynchronously before calling display on a page
|
// load them asynchronously before calling display on a page.
|
||||||
font.loadedName = 'g_font_' + (fontRefIsDict ?
|
font.loadedName = 'g_font_' + (fontRefIsDict ?
|
||||||
fontName.replace(/\W/g, '') : (fontRef.num + '_' + fontRef.gen));
|
fontName.replace(/\W/g, '') : (fontRef.num + '_' + fontRef.gen));
|
||||||
|
|
||||||
@ -432,7 +433,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
if (font.translated.loadCharProcs) {
|
if (font.translated.loadCharProcs) {
|
||||||
var charProcs = font.get('CharProcs').getAll();
|
var charProcs = font.get('CharProcs').getAll();
|
||||||
var fontResources = font.get('Resources') || resources;
|
var fontResources = (font.get('Resources') || resources);
|
||||||
var charProcKeys = Object.keys(charProcs);
|
var charProcKeys = Object.keys(charProcs);
|
||||||
var charProcOperatorList = {};
|
var charProcOperatorList = {};
|
||||||
for (var i = 0, n = charProcKeys.length; i < n; ++i) {
|
for (var i = 0, n = charProcKeys.length; i < n; ++i) {
|
||||||
@ -448,10 +449,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
parentOperatorList.addDependencies(charProcOperatorList.dependencies);
|
parentOperatorList.addDependencies(charProcOperatorList.dependencies);
|
||||||
}
|
}
|
||||||
font.translated.charProcOperatorList = charProcOperatorList;
|
font.translated.charProcOperatorList = charProcOperatorList;
|
||||||
font.loaded = true;
|
|
||||||
} else {
|
|
||||||
font.loaded = true;
|
|
||||||
}
|
}
|
||||||
|
font.loaded = true;
|
||||||
return font;
|
return font;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -465,11 +464,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var handler = this.handler;
|
var handler = this.handler;
|
||||||
var imageCache = {};
|
var imageCache = {};
|
||||||
|
|
||||||
operatorList = operatorList || new OperatorList();
|
operatorList = (operatorList || new OperatorList());
|
||||||
|
|
||||||
resources = resources || new Dict();
|
resources = (resources || new Dict());
|
||||||
var xobjs = resources.get('XObject') || new Dict();
|
var xobjs = (resources.get('XObject') || new Dict());
|
||||||
var patterns = resources.get('Pattern') || new Dict();
|
var patterns = (resources.get('Pattern') || new Dict());
|
||||||
var preprocessor = new EvaluatorPreprocessor(stream, xref);
|
var preprocessor = new EvaluatorPreprocessor(stream, xref);
|
||||||
if (evaluatorState) {
|
if (evaluatorState) {
|
||||||
preprocessor.setState(evaluatorState);
|
preprocessor.setState(evaluatorState);
|
||||||
@ -493,8 +492,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var pattern;
|
var pattern;
|
||||||
if (isName(patternName) &&
|
if (isName(patternName) &&
|
||||||
(pattern = patterns.get(patternName.name))) {
|
(pattern = patterns.get(patternName.name))) {
|
||||||
|
var dict = (isStream(pattern) ? pattern.dict : pattern);
|
||||||
var dict = isStream(pattern) ? pattern.dict : pattern;
|
|
||||||
var typeNum = dict.get('PatternType');
|
var typeNum = dict.get('PatternType');
|
||||||
|
|
||||||
if (typeNum == TILING_PATTERN) {
|
if (typeNum == TILING_PATTERN) {
|
||||||
@ -527,14 +525,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
var xobj = xobjs.get(name);
|
var xobj = xobjs.get(name);
|
||||||
if (xobj) {
|
if (xobj) {
|
||||||
assertWellFormed(
|
assertWellFormed(isStream(xobj), 'XObject should be a stream');
|
||||||
isStream(xobj), 'XObject should be a stream');
|
|
||||||
|
|
||||||
var type = xobj.dict.get('Subtype');
|
var type = xobj.dict.get('Subtype');
|
||||||
assertWellFormed(
|
assertWellFormed(isName(type),
|
||||||
isName(type),
|
'XObject should have a Name subtype');
|
||||||
'XObject should have a Name subtype'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ('Form' == type.name) {
|
if ('Form' == type.name) {
|
||||||
self.buildFormXObject(resources, xobj, null, operatorList,
|
self.buildFormXObject(resources, xobj, null, operatorList,
|
||||||
@ -608,15 +603,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
break;
|
break;
|
||||||
case OPS.shadingFill:
|
case OPS.shadingFill:
|
||||||
var shadingRes = resources.get('Shading');
|
var shadingRes = resources.get('Shading');
|
||||||
if (!shadingRes)
|
if (!shadingRes) {
|
||||||
error('No shading resource found');
|
error('No shading resource found');
|
||||||
|
}
|
||||||
|
|
||||||
var shading = shadingRes.get(args[0].name);
|
var shading = shadingRes.get(args[0].name);
|
||||||
if (!shading)
|
if (!shading) {
|
||||||
error('No shading object found');
|
error('No shading object found');
|
||||||
|
}
|
||||||
|
|
||||||
var shadingFill = Pattern.parseShading(
|
var shadingFill = Pattern.parseShading(shading, null, xref,
|
||||||
shading, null, xref, resources);
|
resources);
|
||||||
var patternIR = shadingFill.getIR();
|
var patternIR = shadingFill.getIR();
|
||||||
args = [patternIR];
|
args = [patternIR];
|
||||||
fn = OPS.shadingFill;
|
fn = OPS.shadingFill;
|
||||||
@ -625,20 +622,20 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var dictName = args[0];
|
var dictName = args[0];
|
||||||
var extGState = resources.get('ExtGState');
|
var extGState = resources.get('ExtGState');
|
||||||
|
|
||||||
if (!isDict(extGState) || !extGState.has(dictName.name))
|
if (!isDict(extGState) || !extGState.has(dictName.name)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
var gState = extGState.get(dictName.name);
|
var gState = extGState.get(dictName.name);
|
||||||
self.setGState(resources, gState, operatorList, xref);
|
self.setGState(resources, gState, operatorList, xref);
|
||||||
args = [];
|
args = [];
|
||||||
continue;
|
continue;
|
||||||
} // switch
|
}
|
||||||
|
|
||||||
operatorList.addOp(fn, args);
|
operatorList.addOp(fn, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// some pdf don't close all restores inside object/form
|
// Some PDFs don't close all restores inside object/form.
|
||||||
// closing those for them
|
// Closing those for them.
|
||||||
for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
|
for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
|
||||||
operatorList.addOp(OPS.restore, []);
|
operatorList.addOp(OPS.restore, []);
|
||||||
}
|
}
|
||||||
@ -646,10 +643,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return operatorList;
|
return operatorList;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextContent: function PartialEvaluator_getTextContent(
|
getTextContent: function PartialEvaluator_getTextContent(stream, resources,
|
||||||
stream, resources, textState) {
|
textState) {
|
||||||
|
|
||||||
textState = textState || new TextState();
|
textState = (textState || new TextState());
|
||||||
|
|
||||||
var bidiTexts = [];
|
var bidiTexts = [];
|
||||||
var SPACE_FACTOR = 0.35;
|
var SPACE_FACTOR = 0.35;
|
||||||
@ -662,7 +659,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return self.loadFont(fontName, fontRef, xref, resources, null);
|
return self.loadFont(fontName, fontRef, xref, resources, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
resources = xref.fetchIfRef(resources) || new Dict();
|
resources = (xref.fetchIfRef(resources) || new Dict());
|
||||||
// The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
|
// The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
|
||||||
var xobjs = null;
|
var xobjs = null;
|
||||||
var xobjsCache = {};
|
var xobjsCache = {};
|
||||||
@ -756,7 +753,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!xobjs) {
|
if (!xobjs) {
|
||||||
xobjs = resources.get('XObject') || new Dict();
|
xobjs = (resources.get('XObject') || new Dict());
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = args[0].name;
|
var name = args[0].name;
|
||||||
@ -768,15 +765,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var xobj = xobjs.get(name);
|
var xobj = xobjs.get(name);
|
||||||
if (!xobj)
|
if (!xobj) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
assertWellFormed(isStream(xobj), 'XObject should be a stream');
|
assertWellFormed(isStream(xobj), 'XObject should be a stream');
|
||||||
|
|
||||||
var type = xobj.dict.get('Subtype');
|
var type = xobj.dict.get('Subtype');
|
||||||
assertWellFormed(
|
assertWellFormed(isName(type),
|
||||||
isName(type),
|
'XObject should have a Name subtype');
|
||||||
'XObject should have a Name subtype'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ('Form' !== type.name) {
|
if ('Form' !== type.name) {
|
||||||
xobjsCache.key = name;
|
xobjsCache.key = name;
|
||||||
@ -784,11 +780,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var formTexts = this.getTextContent(
|
var formTexts = this.getTextContent(xobj,
|
||||||
xobj,
|
(xobj.dict.get('Resources') || resources), textState);
|
||||||
xobj.dict.get('Resources') || resources,
|
|
||||||
textState
|
|
||||||
);
|
|
||||||
xobjsCache.key = name;
|
xobjsCache.key = name;
|
||||||
xobjsCache.texts = formTexts;
|
xobjsCache.texts = formTexts;
|
||||||
Util.concatenateToArray(bidiTexts, formTexts);
|
Util.concatenateToArray(bidiTexts, formTexts);
|
||||||
@ -797,8 +790,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var dictName = args[0];
|
var dictName = args[0];
|
||||||
var extGState = resources.get('ExtGState');
|
var extGState = resources.get('ExtGState');
|
||||||
|
|
||||||
if (!isDict(extGState) || !extGState.has(dictName.name))
|
if (!isDict(extGState) || !extGState.has(dictName.name)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
var gsState = extGState.get(dictName.name);
|
var gsState = extGState.get(dictName.name);
|
||||||
|
|
||||||
@ -808,15 +802,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} // switch
|
}
|
||||||
|
|
||||||
if (chunkBuf.length > 0) {
|
if (chunkBuf.length > 0) {
|
||||||
var chunk = chunkBuf.join('');
|
var chunk = chunkBuf.join('');
|
||||||
var bidiText = PDFJS.bidi(chunk, -1, font.vertical);
|
var bidiText = PDFJS.bidi(chunk, -1, font.vertical);
|
||||||
var renderParams = textState.calcRenderParams(preprocessor.ctm);
|
var renderParams = textState.calcRenderParams(preprocessor.ctm);
|
||||||
var fontHeight = textState.fontSize * renderParams.vScale;
|
var fontHeight = textState.fontSize * renderParams.vScale;
|
||||||
var fontAscent = font.ascent ? font.ascent * fontHeight :
|
var fontAscent = (font.ascent ? (font.ascent * fontHeight) :
|
||||||
font.descent ? (1 + font.descent) * fontHeight : fontHeight;
|
(font.descent ? ((1 + font.descent) * fontHeight) : fontHeight));
|
||||||
bidiText.x = renderParams.renderMatrix[4] - (fontAscent *
|
bidiText.x = renderParams.renderMatrix[4] - (fontAscent *
|
||||||
Math.sin(renderParams.angle));
|
Math.sin(renderParams.angle));
|
||||||
bidiText.y = renderParams.renderMatrix[5] + (fontAscent *
|
bidiText.y = renderParams.renderMatrix[5] + (fontAscent *
|
||||||
@ -831,7 +825,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
chunkBuf.length = 0;
|
chunkBuf.length = 0;
|
||||||
}
|
}
|
||||||
} // while
|
}
|
||||||
|
|
||||||
return bidiTexts;
|
return bidiTexts;
|
||||||
},
|
},
|
||||||
@ -840,11 +834,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
partialEvaluatorExtractDataStructures(dict, baseDict,
|
partialEvaluatorExtractDataStructures(dict, baseDict,
|
||||||
xref, properties) {
|
xref, properties) {
|
||||||
// 9.10.2
|
// 9.10.2
|
||||||
var toUnicode = dict.get('ToUnicode') ||
|
var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
|
||||||
baseDict.get('ToUnicode');
|
if (toUnicode) {
|
||||||
if (toUnicode)
|
|
||||||
properties.toUnicode = this.readToUnicode(toUnicode, xref, properties);
|
properties.toUnicode = this.readToUnicode(toUnicode, xref, properties);
|
||||||
|
}
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
// CIDSystemInfo helps to match CID to glyphs
|
// CIDSystemInfo helps to match CID to glyphs
|
||||||
var cidSystemInfo = dict.get('CIDSystemInfo');
|
var cidSystemInfo = dict.get('CIDSystemInfo');
|
||||||
@ -857,9 +850,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cidToGidMap = dict.get('CIDToGIDMap');
|
var cidToGidMap = dict.get('CIDToGIDMap');
|
||||||
if (isStream(cidToGidMap))
|
if (isStream(cidToGidMap)) {
|
||||||
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
|
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Based on 9.6.6 of the spec the encoding can come from multiple places
|
// Based on 9.6.6 of the spec the encoding can come from multiple places
|
||||||
// and depends on the font type. The base encoding and differences are
|
// and depends on the font type. The base encoding and differences are
|
||||||
@ -873,20 +867,21 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var encoding = dict.get('Encoding');
|
var encoding = dict.get('Encoding');
|
||||||
if (isDict(encoding)) {
|
if (isDict(encoding)) {
|
||||||
baseEncodingName = encoding.get('BaseEncoding');
|
baseEncodingName = encoding.get('BaseEncoding');
|
||||||
baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name :
|
baseEncodingName = (isName(baseEncodingName) ?
|
||||||
null;
|
baseEncodingName.name : null);
|
||||||
// Load the differences between the base and original
|
// Load the differences between the base and original
|
||||||
if (encoding.has('Differences')) {
|
if (encoding.has('Differences')) {
|
||||||
var diffEncoding = encoding.get('Differences');
|
var diffEncoding = encoding.get('Differences');
|
||||||
var index = 0;
|
var index = 0;
|
||||||
for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
|
for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
|
||||||
var data = diffEncoding[j];
|
var data = diffEncoding[j];
|
||||||
if (isNum(data))
|
if (isNum(data)) {
|
||||||
index = data;
|
index = data;
|
||||||
else
|
} else {
|
||||||
differences[index++] = data.name;
|
differences[index++] = data.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (isName(encoding)) {
|
} else if (isName(encoding)) {
|
||||||
baseEncodingName = encoding.name;
|
baseEncodingName = encoding.name;
|
||||||
} else {
|
} else {
|
||||||
@ -904,14 +899,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (baseEncodingName) {
|
if (baseEncodingName) {
|
||||||
properties.defaultEncoding = Encodings[baseEncodingName].slice();
|
properties.defaultEncoding = Encodings[baseEncodingName].slice();
|
||||||
} else {
|
} else {
|
||||||
var encoding = properties.type === 'TrueType' ?
|
var encoding = (properties.type === 'TrueType' ?
|
||||||
Encodings.WinAnsiEncoding :
|
Encodings.WinAnsiEncoding :
|
||||||
Encodings.StandardEncoding;
|
Encodings.StandardEncoding);
|
||||||
// The Symbolic attribute can be misused for regular fonts
|
// The Symbolic attribute can be misused for regular fonts
|
||||||
// Heuristic: we have to check if the font is a standard one also
|
// Heuristic: we have to check if the font is a standard one also
|
||||||
if (!!(properties.flags & FontFlags.Symbolic)) {
|
if (!!(properties.flags & FontFlags.Symbolic)) {
|
||||||
encoding = !properties.file && /Symbol/i.test(properties.name) ?
|
encoding = (!properties.file && /Symbol/i.test(properties.name) ?
|
||||||
Encodings.SymbolSetEncoding : Encodings.MacRomanEncoding;
|
Encodings.SymbolSetEncoding :
|
||||||
|
Encodings.MacRomanEncoding);
|
||||||
}
|
}
|
||||||
properties.defaultEncoding = encoding;
|
properties.defaultEncoding = encoding;
|
||||||
}
|
}
|
||||||
@ -949,6 +945,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
|
readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
|
||||||
// Extract the encoding from the CIDToGIDMap
|
// Extract the encoding from the CIDToGIDMap
|
||||||
var glyphsData = cidToGidStream.getBytes();
|
var glyphsData = cidToGidStream.getBytes();
|
||||||
@ -957,17 +954,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var result = [];
|
var result = [];
|
||||||
for (var j = 0, jj = glyphsData.length; j < jj; j++) {
|
for (var j = 0, jj = glyphsData.length; j < jj; j++) {
|
||||||
var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
|
var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
|
||||||
if (glyphID === 0)
|
if (glyphID === 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
var code = j >> 1;
|
var code = j >> 1;
|
||||||
result[code] = glyphID;
|
result[code] = glyphID;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
extractWidths: function PartialEvaluator_extractWidths(dict,
|
extractWidths: function PartialEvaluator_extractWidths(dict, xref,
|
||||||
xref,
|
|
||||||
descriptor,
|
descriptor,
|
||||||
properties) {
|
properties) {
|
||||||
var glyphsWidths = [];
|
var glyphsWidths = [];
|
||||||
@ -983,18 +979,20 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var start = widths[i++];
|
var start = widths[i++];
|
||||||
var code = xref.fetchIfRef(widths[i]);
|
var code = xref.fetchIfRef(widths[i]);
|
||||||
if (isArray(code)) {
|
if (isArray(code)) {
|
||||||
for (var j = 0, jj = code.length; j < jj; j++)
|
for (var j = 0, jj = code.length; j < jj; j++) {
|
||||||
glyphsWidths[start++] = code[j];
|
glyphsWidths[start++] = code[j];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var width = widths[++i];
|
var width = widths[++i];
|
||||||
for (var j = start; j <= code; j++)
|
for (var j = start; j <= code; j++) {
|
||||||
glyphsWidths[j] = width;
|
glyphsWidths[j] = width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.vertical) {
|
if (properties.vertical) {
|
||||||
var vmetrics = dict.get('DW2') || [880, -1000];
|
var vmetrics = (dict.get('DW2') || [880, -1000]);
|
||||||
defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
|
defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
|
||||||
vmetrics = dict.get('W2');
|
vmetrics = dict.get('W2');
|
||||||
if (vmetrics) {
|
if (vmetrics) {
|
||||||
@ -1002,24 +1000,27 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var start = vmetrics[i++];
|
var start = vmetrics[i++];
|
||||||
var code = xref.fetchIfRef(vmetrics[i]);
|
var code = xref.fetchIfRef(vmetrics[i]);
|
||||||
if (isArray(code)) {
|
if (isArray(code)) {
|
||||||
for (var j = 0, jj = code.length; j < jj; j++)
|
for (var j = 0, jj = code.length; j < jj; j++) {
|
||||||
glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
|
glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
|
var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
|
||||||
for (var j = start; j <= code; j++)
|
for (var j = start; j <= code; j++) {
|
||||||
glyphsVMetrics[j] = vmetric;
|
glyphsVMetrics[j] = vmetric;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var firstChar = properties.firstChar;
|
var firstChar = properties.firstChar;
|
||||||
var widths = dict.get('Widths');
|
var widths = dict.get('Widths');
|
||||||
if (widths) {
|
if (widths) {
|
||||||
var j = firstChar;
|
var j = firstChar;
|
||||||
for (var i = 0, ii = widths.length; i < ii; i++)
|
for (var i = 0, ii = widths.length; i < ii; i++) {
|
||||||
glyphsWidths[j++] = widths[i];
|
glyphsWidths[j++] = widths[i];
|
||||||
defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
|
}
|
||||||
|
defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
|
||||||
} else {
|
} else {
|
||||||
// Trying get the BaseFont metrics (see comment above).
|
// Trying get the BaseFont metrics (see comment above).
|
||||||
var baseFontName = dict.get('BaseFont');
|
var baseFontName = dict.get('BaseFont');
|
||||||
@ -1034,11 +1035,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Heuristic: detection of monospace font by checking all non-zero widths
|
// Heuristic: detection of monospace font by checking all non-zero widths
|
||||||
var isMonospace = true, firstWidth = defaultWidth;
|
var isMonospace = true;
|
||||||
|
var firstWidth = defaultWidth;
|
||||||
for (var glyph in glyphsWidths) {
|
for (var glyph in glyphsWidths) {
|
||||||
var glyphWidth = glyphsWidths[glyph];
|
var glyphWidth = glyphsWidths[glyph];
|
||||||
if (!glyphWidth)
|
if (!glyphWidth) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (!firstWidth) {
|
if (!firstWidth) {
|
||||||
firstWidth = glyphWidth;
|
firstWidth = glyphWidth;
|
||||||
continue;
|
continue;
|
||||||
@ -1048,8 +1051,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isMonospace)
|
if (isMonospace) {
|
||||||
properties.flags |= FontFlags.FixedPitch;
|
properties.flags |= FontFlags.FixedPitch;
|
||||||
|
}
|
||||||
|
|
||||||
properties.defaultWidth = defaultWidth;
|
properties.defaultWidth = defaultWidth;
|
||||||
properties.widths = glyphsWidths;
|
properties.widths = glyphsWidths;
|
||||||
@ -1058,7 +1062,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
|
isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
|
||||||
|
|
||||||
// Simulating descriptor flags attribute
|
// Simulating descriptor flags attribute
|
||||||
var fontNameWoStyle = baseFontName.split('-')[0];
|
var fontNameWoStyle = baseFontName.split('-')[0];
|
||||||
return (fontNameWoStyle in serifFonts) ||
|
return (fontNameWoStyle in serifFonts) ||
|
||||||
@ -1066,9 +1069,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
||||||
var defaultWidth = 0, widths = [], monospace = false;
|
var defaultWidth = 0;
|
||||||
|
var widths = [];
|
||||||
var lookupName = stdFontMap[name] || name;
|
var monospace = false;
|
||||||
|
var lookupName = (stdFontMap[name] || name);
|
||||||
|
|
||||||
if (!(lookupName in Metrics)) {
|
if (!(lookupName in Metrics)) {
|
||||||
// Use default fonts for looking up font metrics if the passed
|
// Use default fonts for looking up font metrics if the passed
|
||||||
@ -1095,8 +1099,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(
|
buildCharCodeToWidth:
|
||||||
widthsByGlyphName, properties) {
|
function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
|
||||||
|
properties) {
|
||||||
var widths = Object.create(null);
|
var widths = Object.create(null);
|
||||||
var differences = properties.differences;
|
var differences = properties.differences;
|
||||||
var encoding = properties.defaultEncoding;
|
var encoding = properties.defaultEncoding;
|
||||||
@ -1114,8 +1119,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return widths;
|
return widths;
|
||||||
},
|
},
|
||||||
|
|
||||||
translateFont: function PartialEvaluator_translateFont(dict,
|
translateFont: function PartialEvaluator_translateFont(dict, xref) {
|
||||||
xref) {
|
|
||||||
var baseDict = dict;
|
var baseDict = dict;
|
||||||
var type = dict.get('Subtype');
|
var type = dict.get('Subtype');
|
||||||
assertWellFormed(isName(type), 'invalid font Subtype');
|
assertWellFormed(isName(type), 'invalid font Subtype');
|
||||||
@ -1127,16 +1131,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
// - set the type according to the descendant font
|
// - set the type according to the descendant font
|
||||||
// - get the FontDescriptor from the descendant font
|
// - get the FontDescriptor from the descendant font
|
||||||
var df = dict.get('DescendantFonts');
|
var df = dict.get('DescendantFonts');
|
||||||
if (!df)
|
if (!df) {
|
||||||
error('Descendant fonts are not specified');
|
error('Descendant fonts are not specified');
|
||||||
|
}
|
||||||
dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
|
dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
|
||||||
|
|
||||||
type = dict.get('Subtype');
|
type = dict.get('Subtype');
|
||||||
assertWellFormed(isName(type), 'invalid font Subtype');
|
assertWellFormed(isName(type), 'invalid font Subtype');
|
||||||
composite = true;
|
composite = true;
|
||||||
}
|
}
|
||||||
var maxCharIndex = composite ? 0xFFFF : 0xFF;
|
var maxCharIndex = (composite ? 0xFFFF : 0xFF);
|
||||||
|
|
||||||
var descriptor = dict.get('FontDescriptor');
|
var descriptor = dict.get('FontDescriptor');
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
@ -1150,8 +1154,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
// FontDescriptor was not required.
|
// FontDescriptor was not required.
|
||||||
// This case is here for compatibility.
|
// This case is here for compatibility.
|
||||||
var baseFontName = dict.get('BaseFont');
|
var baseFontName = dict.get('BaseFont');
|
||||||
if (!isName(baseFontName))
|
if (!isName(baseFontName)) {
|
||||||
error('Base font is not specified');
|
error('Base font is not specified');
|
||||||
|
}
|
||||||
|
|
||||||
// Using base font name as a font name.
|
// Using base font name as a font name.
|
||||||
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
||||||
@ -1159,8 +1164,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
// Simulating descriptor flags attribute
|
// Simulating descriptor flags attribute
|
||||||
var fontNameWoStyle = baseFontName.split('-')[0];
|
var fontNameWoStyle = baseFontName.split('-')[0];
|
||||||
var flags = (
|
var flags =
|
||||||
this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
|
(this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
|
||||||
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
||||||
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
|
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
|
||||||
FontFlags.Nonsymbolic);
|
FontFlags.Nonsymbolic);
|
||||||
@ -1177,7 +1182,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.extractDataStructures(dict, dict, xref, properties);
|
this.extractDataStructures(dict, dict, xref, properties);
|
||||||
properties.widths = this.buildCharCodeToWidth(metrics.widths,
|
properties.widths = this.buildCharCodeToWidth(metrics.widths,
|
||||||
properties);
|
properties);
|
||||||
|
|
||||||
return new Font(baseFontName, null, properties);
|
return new Font(baseFontName, null, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1187,12 +1191,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
// to ignore this rule when a variant of a standart font is used.
|
// to ignore this rule when a variant of a standart font is used.
|
||||||
// TODO Fill the width array depending on which of the base font this is
|
// TODO Fill the width array depending on which of the base font this is
|
||||||
// a variant.
|
// a variant.
|
||||||
var firstChar = dict.get('FirstChar') || 0;
|
var firstChar = (dict.get('FirstChar') || 0);
|
||||||
var lastChar = dict.get('LastChar') || maxCharIndex;
|
var lastChar = (dict.get('LastChar') || maxCharIndex);
|
||||||
|
|
||||||
var fontName = descriptor.get('FontName');
|
var fontName = descriptor.get('FontName');
|
||||||
var baseFont = dict.get('BaseFont');
|
var baseFont = dict.get('BaseFont');
|
||||||
// Some bad pdf's have a string as the font name.
|
// Some bad PDFs have a string as the font name.
|
||||||
if (isString(fontName)) {
|
if (isString(fontName)) {
|
||||||
fontName = Name.get(fontName);
|
fontName = Name.get(fontName);
|
||||||
}
|
}
|
||||||
@ -1209,7 +1213,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
baseFontStr + '"');
|
baseFontStr + '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fontName = fontName || baseFont;
|
fontName = (fontName || baseFont);
|
||||||
|
|
||||||
assertWellFormed(isName(fontName), 'invalid font name');
|
assertWellFormed(isName(fontName), 'invalid font name');
|
||||||
|
|
||||||
@ -1217,11 +1221,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (fontFile) {
|
if (fontFile) {
|
||||||
if (fontFile.dict) {
|
if (fontFile.dict) {
|
||||||
var subtype = fontFile.dict.get('Subtype');
|
var subtype = fontFile.dict.get('Subtype');
|
||||||
if (subtype)
|
if (subtype) {
|
||||||
subtype = subtype.name;
|
subtype = subtype.name;
|
||||||
|
}
|
||||||
var length1 = fontFile.dict.get('Length1');
|
var length1 = fontFile.dict.get('Length1');
|
||||||
|
|
||||||
var length2 = fontFile.dict.get('Length2');
|
var length2 = fontFile.dict.get('Length2');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1237,9 +1240,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
composite: composite,
|
composite: composite,
|
||||||
wideChars: composite,
|
wideChars: composite,
|
||||||
fixedPitch: false,
|
fixedPitch: false,
|
||||||
fontMatrix: dict.get('FontMatrix') || FONT_IDENTITY_MATRIX,
|
fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
|
||||||
firstChar: firstChar || 0,
|
firstChar: firstChar || 0,
|
||||||
lastChar: lastChar || maxCharIndex,
|
lastChar: (lastChar || maxCharIndex),
|
||||||
bbox: descriptor.get('FontBBox'),
|
bbox: descriptor.get('FontBBox'),
|
||||||
ascent: descriptor.get('Ascent'),
|
ascent: descriptor.get('Ascent'),
|
||||||
descent: descriptor.get('Descent'),
|
descent: descriptor.get('Descent'),
|
||||||
@ -1305,7 +1308,6 @@ var OperatorList = (function OperatorListClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OperatorList.prototype = {
|
OperatorList.prototype = {
|
||||||
|
|
||||||
get length() {
|
get length() {
|
||||||
return this.argsArray.length;
|
return this.argsArray.length;
|
||||||
},
|
},
|
||||||
@ -1385,6 +1387,7 @@ var TextState = (function TextStateClosure() {
|
|||||||
this.textHScale = 1;
|
this.textHScale = 1;
|
||||||
this.textRise = 0;
|
this.textRise = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextState.prototype = {
|
TextState.prototype = {
|
||||||
initialiseTextObj: function TextState_initialiseTextObj() {
|
initialiseTextObj: function TextState_initialiseTextObj() {
|
||||||
var m = this.textMatrix;
|
var m = this.textMatrix;
|
||||||
@ -1564,10 +1567,12 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessor() {
|
|||||||
this.ctm = new Float32Array([1, 0, 0, 1, 0, 0]);
|
this.ctm = new Float32Array([1, 0, 0, 1, 0, 0]);
|
||||||
this.savedStates = [];
|
this.savedStates = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
EvaluatorPreprocessor.prototype = {
|
EvaluatorPreprocessor.prototype = {
|
||||||
get savedStatesDepth() {
|
get savedStatesDepth() {
|
||||||
return this.savedStates.length;
|
return this.savedStates.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
read: function EvaluatorPreprocessor_read() {
|
read: function EvaluatorPreprocessor_read() {
|
||||||
var args = [];
|
var args = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -1578,7 +1583,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessor() {
|
|||||||
if (!isCmd(obj)) {
|
if (!isCmd(obj)) {
|
||||||
// argument
|
// argument
|
||||||
if (obj !== null && obj !== undefined) {
|
if (obj !== null && obj !== undefined) {
|
||||||
args.push(obj instanceof Dict ? obj.getAll() : obj);
|
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
||||||
assertWellFormed(args.length <= 33, 'Too many arguments');
|
assertWellFormed(args.length <= 33, 'Too many arguments');
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -1616,22 +1621,24 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to type-check vararg functions
|
// TODO figure out how to type-check vararg functions
|
||||||
|
|
||||||
this.preprocessCommand(fn, args);
|
this.preprocessCommand(fn, args);
|
||||||
|
|
||||||
return { fn: fn, args: args };
|
return { fn: fn, args: args };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getState: function EvaluatorPreprocessor_getState() {
|
getState: function EvaluatorPreprocessor_getState() {
|
||||||
return {
|
return {
|
||||||
ctm: this.ctm
|
ctm: this.ctm
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
setState: function EvaluatorPreprocessor_setState(state) {
|
setState: function EvaluatorPreprocessor_setState(state) {
|
||||||
this.ctm = state.ctm;
|
this.ctm = state.ctm;
|
||||||
},
|
},
|
||||||
preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn,
|
|
||||||
args) {
|
preprocessCommand:
|
||||||
|
function EvaluatorPreprocessor_preprocessCommand(fn, args) {
|
||||||
switch (fn | 0) {
|
switch (fn | 0) {
|
||||||
case OPS.save:
|
case OPS.save:
|
||||||
this.savedStates.push(this.getState());
|
this.savedStates.push(this.getState());
|
||||||
@ -1664,13 +1671,13 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
var state = parentState;
|
var state = parentState;
|
||||||
for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
|
for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
|
||||||
var item = pattern[i];
|
var item = pattern[i];
|
||||||
state = state[item] || (state[item] = []);
|
state = (state[item] || (state[item] = []));
|
||||||
}
|
}
|
||||||
state[pattern[pattern.length - 1]] = fn;
|
state[pattern[pattern.length - 1]] = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePaintSolidColorImageMask(index, count, fnArray, argsArray) {
|
function handlePaintSolidColorImageMask(index, count, fnArray, argsArray) {
|
||||||
// Handles special case of mainly latex documents which
|
// Handles special case of mainly LaTeX documents which
|
||||||
// use image masks to draw lines with the current fill style.
|
// use image masks to draw lines with the current fill style.
|
||||||
// 'count' groups of (save, transform, paintImageMaskXObject, restore)+
|
// 'count' groups of (save, transform, paintImageMaskXObject, restore)+
|
||||||
// have been found at index.
|
// have been found at index.
|
||||||
@ -1704,8 +1711,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
var j = context.currentOperation - 3, i = j + 4;
|
var j = context.currentOperation - 3, i = j + 4;
|
||||||
var ii = fnArray.length;
|
var ii = fnArray.length;
|
||||||
|
|
||||||
for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {
|
for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
|
||||||
}
|
|
||||||
var count = Math.min((i - j) >> 2, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
|
var count = Math.min((i - j) >> 2, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
|
||||||
if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
|
if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
|
||||||
context.currentOperation = i - 1;
|
context.currentOperation = i - 1;
|
||||||
@ -1744,16 +1750,13 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
var rowSize = map[q].w << 2;
|
var rowSize = map[q].w << 2;
|
||||||
var dataOffset = 0;
|
var dataOffset = 0;
|
||||||
var offset = (map[q].x + map[q].y * imgWidth) << 2;
|
var offset = (map[q].x + map[q].y * imgWidth) << 2;
|
||||||
imgData.set(
|
imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
|
||||||
data.subarray(0, rowSize), offset - imgRowSize);
|
|
||||||
for (var k = 0, kk = map[q].h; k < kk; k++) {
|
for (var k = 0, kk = map[q].h; k < kk; k++) {
|
||||||
imgData.set(
|
imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
|
||||||
data.subarray(dataOffset, dataOffset + rowSize), offset);
|
|
||||||
dataOffset += rowSize;
|
dataOffset += rowSize;
|
||||||
offset += imgRowSize;
|
offset += imgRowSize;
|
||||||
}
|
}
|
||||||
imgData.set(
|
imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
|
||||||
data.subarray(dataOffset - rowSize, dataOffset), offset);
|
|
||||||
while (offset >= 0) {
|
while (offset >= 0) {
|
||||||
data[offset - 4] = data[offset];
|
data[offset - 4] = data[offset];
|
||||||
data[offset - 3] = data[offset + 1];
|
data[offset - 3] = data[offset + 1];
|
||||||
@ -1787,8 +1790,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
var j = context.currentOperation - 3, i = j + 4;
|
var j = context.currentOperation - 3, i = j + 4;
|
||||||
var ii = fnArray.length;
|
var ii = fnArray.length;
|
||||||
|
|
||||||
for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {
|
for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
|
||||||
}
|
|
||||||
var count = (i - j) >> 2;
|
var count = (i - j) >> 2;
|
||||||
count = handlePaintSolidColorImageMask(j, count, fnArray, argsArray);
|
count = handlePaintSolidColorImageMask(j, count, fnArray, argsArray);
|
||||||
if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
|
if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
|
||||||
@ -1842,7 +1844,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
var transformArgs = argsArray[j + (q << 2) + 1];
|
var transformArgs = argsArray[j + (q << 2) + 1];
|
||||||
var maskParams = argsArray[j + (q << 2) + 2][0];
|
var maskParams = argsArray[j + (q << 2) + 2][0];
|
||||||
images.push({ data: maskParams.data, width: maskParams.width,
|
images.push({ data: maskParams.data, width: maskParams.width,
|
||||||
height: maskParams.height, transform: transformArgs});
|
height: maskParams.height,
|
||||||
|
transform: transformArgs });
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacing queue items
|
// replacing queue items
|
||||||
@ -1958,8 +1961,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||||||
context.currentOperation = i;
|
context.currentOperation = i;
|
||||||
});
|
});
|
||||||
|
|
||||||
function QueueOptimizer() {
|
function QueueOptimizer() {}
|
||||||
}
|
|
||||||
QueueOptimizer.prototype = {
|
QueueOptimizer.prototype = {
|
||||||
optimize: function QueueOptimizer_optimize(queue) {
|
optimize: function QueueOptimizer_optimize(queue) {
|
||||||
var fnArray = queue.fnArray, argsArray = queue.argsArray;
|
var fnArray = queue.fnArray, argsArray = queue.argsArray;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user