Use same obj/font id counter for all partial evaluators on page
This commit is contained in:
parent
8ae5d2745c
commit
d69f14328c
33
src/core.js
33
src/core.js
@ -66,6 +66,10 @@ var Page = (function PageClosure() {
|
|||||||
this.pageDict = pageDict;
|
this.pageDict = pageDict;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
|
this.idCounters = {
|
||||||
|
font: 0,
|
||||||
|
obj: 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Page.prototype = {
|
Page.prototype = {
|
||||||
@ -159,17 +163,19 @@ var Page = (function PageClosure() {
|
|||||||
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
|
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
|
||||||
[]);
|
[]);
|
||||||
var resourcesPromise = pdfManager.ensure(this, 'resources');
|
var resourcesPromise = pdfManager.ensure(this, 'resources');
|
||||||
|
|
||||||
|
var partialEvaluator = new PartialEvaluator(
|
||||||
|
pdfManager, this.xref, handler,
|
||||||
|
this.pageIndex, 'p' + this.pageIndex + '_',
|
||||||
|
this.idCounters);
|
||||||
|
|
||||||
var dataPromises = Promise.all(
|
var dataPromises = Promise.all(
|
||||||
[contentStreamPromise, resourcesPromise]);
|
[contentStreamPromise, resourcesPromise]);
|
||||||
dataPromises.then(function(data) {
|
dataPromises.then(function(data) {
|
||||||
var contentStream = data[0];
|
var contentStream = data[0];
|
||||||
var resources = data[1];
|
var resources = data[1];
|
||||||
var pe = self.pe = new PartialEvaluator(
|
|
||||||
pdfManager,
|
|
||||||
self.xref, handler, self.pageIndex,
|
|
||||||
'p' + self.pageIndex + '_');
|
|
||||||
|
|
||||||
pdfManager.ensure(pe, 'getOperatorList',
|
pdfManager.ensure(partialEvaluator, 'getOperatorList',
|
||||||
[contentStream, resources]).then(
|
[contentStream, resources]).then(
|
||||||
function(opListPromise) {
|
function(opListPromise) {
|
||||||
opListPromise.then(function(data) {
|
opListPromise.then(function(data) {
|
||||||
@ -181,11 +187,7 @@ var Page = (function PageClosure() {
|
|||||||
|
|
||||||
pdfManager.ensure(this, 'getAnnotationsForDraw', []).then(
|
pdfManager.ensure(this, 'getAnnotationsForDraw', []).then(
|
||||||
function(annotations) {
|
function(annotations) {
|
||||||
var annotationEvaluator = new PartialEvaluator(
|
pdfManager.ensure(partialEvaluator, 'getAnnotationsOperatorList',
|
||||||
pdfManager, self.xref, handler, self.pageIndex,
|
|
||||||
'p' + self.pageIndex + '_annotation');
|
|
||||||
|
|
||||||
pdfManager.ensure(annotationEvaluator, 'getAnnotationsOperatorList',
|
|
||||||
[annotations]).then(
|
[annotations]).then(
|
||||||
function(opListPromise) {
|
function(opListPromise) {
|
||||||
opListPromise.then(function(data) {
|
opListPromise.then(function(data) {
|
||||||
@ -242,12 +244,13 @@ var Page = (function PageClosure() {
|
|||||||
dataPromises.then(function(data) {
|
dataPromises.then(function(data) {
|
||||||
var contentStream = data[0];
|
var contentStream = data[0];
|
||||||
var resources = data[1];
|
var resources = data[1];
|
||||||
var pe = new PartialEvaluator(
|
var partialEvaluator = new PartialEvaluator(
|
||||||
pdfManager,
|
pdfManager, self.xref, handler,
|
||||||
self.xref, handler, self.pageIndex,
|
self.pageIndex, 'p' + self.pageIndex + '_',
|
||||||
'p' + self.pageIndex + '_');
|
self.idCounters);
|
||||||
|
|
||||||
pe.getTextContent(contentStream, resources).then(function(bidiTexts) {
|
partialEvaluator.getTextContent(
|
||||||
|
contentStream, resources).then(function(bidiTexts) {
|
||||||
textContentPromise.resolve({
|
textContentPromise.resolve({
|
||||||
bidiTexts: bidiTexts
|
bidiTexts: bidiTexts
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
var PartialEvaluator = (function PartialEvaluatorClosure() {
|
var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||||
function PartialEvaluator(pdfManager, xref, handler, pageIndex,
|
function PartialEvaluator(pdfManager, xref, handler, pageIndex,
|
||||||
uniquePrefix) {
|
uniquePrefix, idCounters) {
|
||||||
this.state = new EvalState();
|
this.state = new EvalState();
|
||||||
this.stateStack = [];
|
this.stateStack = [];
|
||||||
|
|
||||||
@ -34,8 +34,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.pageIndex = pageIndex;
|
this.pageIndex = pageIndex;
|
||||||
this.uniquePrefix = uniquePrefix;
|
this.uniquePrefix = uniquePrefix;
|
||||||
this.objIdCounter = 0;
|
this.idCounters = idCounters;
|
||||||
this.fontIdCounter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specifies properties for each command
|
// Specifies properties for each command
|
||||||
@ -277,7 +276,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.objIdCounter);
|
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
|
||||||
dependencies[objId] = true;
|
dependencies[objId] = true;
|
||||||
retData.args = [objId, w, h];
|
retData.args = [objId, w, h];
|
||||||
|
|
||||||
@ -510,11 +509,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
font = xref.fetchIfRef(font) || fontRes.get(fontName);
|
font = xref.fetchIfRef(font) || fontRes.get(fontName);
|
||||||
if (!isDict(font)) {
|
if (!isDict(font)) {
|
||||||
++this.fontIdCounter;
|
++this.idCounters.font;
|
||||||
promise.resolve({
|
promise.resolve({
|
||||||
font: {
|
font: {
|
||||||
translated: new ErrorFont('Font ' + fontName + ' is not available'),
|
translated: new ErrorFont('Font ' + fontName + ' is not available'),
|
||||||
loadedName: 'g_font_' + this.uniquePrefix + this.fontIdCounter
|
loadedName: 'g_font_' + this.uniquePrefix + this.idCounters.obj
|
||||||
},
|
},
|
||||||
dependencies: {}
|
dependencies: {}
|
||||||
});
|
});
|
||||||
@ -525,7 +524,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (!loadedName) {
|
if (!loadedName) {
|
||||||
// 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
|
||||||
loadedName = 'g_font_' + this.uniquePrefix + (this.fontIdCounter + 1);
|
loadedName = 'g_font_' + this.uniquePrefix + (this.idCounters.font + 1);
|
||||||
font.loadedName = loadedName;
|
font.loadedName = loadedName;
|
||||||
|
|
||||||
var translated;
|
var translated;
|
||||||
@ -575,7 +574,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++this.fontIdCounter;
|
++this.idCounters.font;
|
||||||
} else {
|
} else {
|
||||||
promise.resolve({
|
promise.resolve({
|
||||||
font: font,
|
font: font,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user