Skip to content

Commit

Permalink
Merge pull request #3142 from mduan/issue3133
Browse files Browse the repository at this point in the history
Use same obj/font id counter for all partial evaluators on page
  • Loading branch information
brendandahl committed Apr 23, 2013
2 parents a8b652b + d69f143 commit 75e3ea0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
33 changes: 18 additions & 15 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var Page = (function PageClosure() {
this.pageDict = pageDict;
this.xref = xref;
this.ref = ref;
this.idCounters = {
font: 0,
obj: 0
};
}

Page.prototype = {
Expand Down Expand Up @@ -159,17 +163,19 @@ var Page = (function PageClosure() {
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
[]);
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(
[contentStreamPromise, resourcesPromise]);
dataPromises.then(function(data) {
var contentStream = data[0];
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(
function(opListPromise) {
opListPromise.then(function(data) {
Expand All @@ -181,11 +187,7 @@ var Page = (function PageClosure() {

pdfManager.ensure(this, 'getAnnotationsForDraw', []).then(
function(annotations) {
var annotationEvaluator = new PartialEvaluator(
pdfManager, self.xref, handler, self.pageIndex,
'p' + self.pageIndex + '_annotation');

pdfManager.ensure(annotationEvaluator, 'getAnnotationsOperatorList',
pdfManager.ensure(partialEvaluator, 'getAnnotationsOperatorList',
[annotations]).then(
function(opListPromise) {
opListPromise.then(function(data) {
Expand Down Expand Up @@ -242,12 +244,13 @@ var Page = (function PageClosure() {
dataPromises.then(function(data) {
var contentStream = data[0];
var resources = data[1];
var pe = new PartialEvaluator(
pdfManager,
self.xref, handler, self.pageIndex,
'p' + self.pageIndex + '_');
var partialEvaluator = new PartialEvaluator(
pdfManager, self.xref, handler,
self.pageIndex, 'p' + self.pageIndex + '_',
self.idCounters);

pe.getTextContent(contentStream, resources).then(function(bidiTexts) {
partialEvaluator.getTextContent(
contentStream, resources).then(function(bidiTexts) {
textContentPromise.resolve({
bidiTexts: bidiTexts
});
Expand Down
15 changes: 7 additions & 8 deletions src/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

var PartialEvaluator = (function PartialEvaluatorClosure() {
function PartialEvaluator(pdfManager, xref, handler, pageIndex,
uniquePrefix) {
uniquePrefix, idCounters) {
this.state = new EvalState();
this.stateStack = [];

Expand All @@ -34,8 +34,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
this.handler = handler;
this.pageIndex = pageIndex;
this.uniquePrefix = uniquePrefix;
this.objIdCounter = 0;
this.fontIdCounter = 0;
this.idCounters = idCounters;
}

// Specifies properties for each command
Expand Down Expand Up @@ -277,7 +276,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
var uniquePrefix = this.uniquePrefix || '';
var objId = 'img_' + uniquePrefix + (++this.objIdCounter);
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
dependencies[objId] = true;
retData.args = [objId, w, h];

Expand Down Expand Up @@ -510,11 +509,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {

font = xref.fetchIfRef(font) || fontRes.get(fontName);
if (!isDict(font)) {
++this.fontIdCounter;
++this.idCounters.font;
promise.resolve({
font: {
translated: new ErrorFont('Font ' + fontName + ' is not available'),
loadedName: 'g_font_' + this.uniquePrefix + this.fontIdCounter
loadedName: 'g_font_' + this.uniquePrefix + this.idCounters.obj
},
dependencies: {}
});
Expand All @@ -525,7 +524,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!loadedName) {
// keep track of each font we translated so the caller can
// 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;

var translated;
Expand Down Expand Up @@ -575,7 +574,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
});
}

++this.fontIdCounter;
++this.idCounters.font;
} else {
promise.resolve({
font: font,
Expand Down

0 comments on commit 75e3ea0

Please sign in to comment.