Skip to content

Use same obj/font id counter for all partial evaluators on page #3142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

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