[api-minor] Change the pageIndex, on PDFPageProxy instances, to a private property

This property has never been documented and/or *intentionally* exposed through the API, instead the `PDFPageProxy.pageNumber` property is the documented/intended API to use here.
Hence pageIndex is changed to a "private" property on `PDFPageProxy` instances, and internal API functionality is also updated to *consistently* use `this._pageIndex` rather than a mix of formats.
This commit is contained in:
Jonas Jenwald 2020-03-19 15:36:09 +01:00
parent c3f4690bde
commit ae2900e510
3 changed files with 18 additions and 16 deletions

View File

@ -608,8 +608,8 @@ class PDFDocumentProxy {
/** /**
* @param {{num: number, gen: number}} ref - The page reference. Must have * @param {{num: number, gen: number}} ref - The page reference. Must have
* the `num` and `gen` properties. * the `num` and `gen` properties.
* @returns {Promise} A promise that is resolved with the page index that is * @returns {Promise} A promise that is resolved with the page index (starting
* associated with the reference. * from zero) that is associated with the reference.
*/ */
getPageIndex(ref) { getPageIndex(ref) {
return this._transport.getPageIndex(ref); return this._transport.getPageIndex(ref);
@ -909,7 +909,7 @@ class PDFDocumentProxy {
*/ */
class PDFPageProxy { class PDFPageProxy {
constructor(pageIndex, pageInfo, transport, pdfBug = false) { constructor(pageIndex, pageInfo, transport, pdfBug = false) {
this.pageIndex = pageIndex; this._pageIndex = pageIndex;
this._pageInfo = pageInfo; this._pageInfo = pageInfo;
this._transport = transport; this._transport = transport;
this._stats = pdfBug ? new StatTimer() : null; this._stats = pdfBug ? new StatTimer() : null;
@ -927,7 +927,7 @@ class PDFPageProxy {
* @type {number} Page number of the page. First page is 1. * @type {number} Page number of the page. First page is 1.
*/ */
get pageNumber() { get pageNumber() {
return this.pageIndex + 1; return this._pageIndex + 1;
} }
/** /**
@ -999,7 +999,7 @@ class PDFPageProxy {
getAnnotations({ intent = null } = {}) { getAnnotations({ intent = null } = {}) {
if (!this.annotationsPromise || this.annotationsIntent !== intent) { if (!this.annotationsPromise || this.annotationsIntent !== intent) {
this.annotationsPromise = this._transport.getAnnotations( this.annotationsPromise = this._transport.getAnnotations(
this.pageIndex, this._pageIndex,
intent intent
); );
this.annotationsIntent = intent; this.annotationsIntent = intent;
@ -1063,7 +1063,7 @@ class PDFPageProxy {
this._stats.time("Page Request"); this._stats.time("Page Request");
} }
this._pumpOperatorList({ this._pumpOperatorList({
pageIndex: this.pageNumber - 1, pageIndex: this._pageIndex,
intent: renderingIntent, intent: renderingIntent,
renderInteractiveForms: renderInteractiveForms === true, renderInteractiveForms: renderInteractiveForms === true,
}); });
@ -1111,7 +1111,7 @@ class PDFPageProxy {
objs: this.objs, objs: this.objs,
commonObjs: this.commonObjs, commonObjs: this.commonObjs,
operatorList: intentState.operatorList, operatorList: intentState.operatorList,
pageNumber: this.pageNumber, pageIndex: this._pageIndex,
canvasFactory: canvasFactoryInstance, canvasFactory: canvasFactoryInstance,
webGLContext, webGLContext,
useRequestAnimationFrame: renderingIntent !== "print", useRequestAnimationFrame: renderingIntent !== "print",
@ -1180,7 +1180,7 @@ class PDFPageProxy {
this._stats.time("Page Request"); this._stats.time("Page Request");
} }
this._pumpOperatorList({ this._pumpOperatorList({
pageIndex: this.pageIndex, pageIndex: this._pageIndex,
intent: renderingIntent, intent: renderingIntent,
}); });
} }
@ -1200,7 +1200,7 @@ class PDFPageProxy {
return this._transport.messageHandler.sendWithStream( return this._transport.messageHandler.sendWithStream(
"GetTextContent", "GetTextContent",
{ {
pageIndex: this.pageNumber - 1, pageIndex: this._pageIndex,
normalizeWhitespace: normalizeWhitespace === true, normalizeWhitespace: normalizeWhitespace === true,
combineTextItems: disableCombineTextItems !== true, combineTextItems: disableCombineTextItems !== true,
}, },
@ -1249,7 +1249,7 @@ class PDFPageProxy {
*/ */
_destroy() { _destroy() {
this.destroyed = true; this.destroyed = true;
this._transport.pageCache[this.pageIndex] = null; this._transport.pageCache[this._pageIndex] = null;
const waitOn = []; const waitOn = [];
Object.keys(this.intentStates).forEach(intent => { Object.keys(this.intentStates).forEach(intent => {
@ -2734,7 +2734,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
objs, objs,
commonObjs, commonObjs,
operatorList, operatorList,
pageNumber, pageIndex,
canvasFactory, canvasFactory,
webGLContext, webGLContext,
useRequestAnimationFrame = false, useRequestAnimationFrame = false,
@ -2746,7 +2746,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this.commonObjs = commonObjs; this.commonObjs = commonObjs;
this.operatorListIdx = null; this.operatorListIdx = null;
this.operatorList = operatorList; this.operatorList = operatorList;
this.pageNumber = pageNumber; this._pageIndex = pageIndex;
this.canvasFactory = canvasFactory; this.canvasFactory = canvasFactory;
this.webGLContext = webGLContext; this.webGLContext = webGLContext;
this._pdfBug = pdfBug; this._pdfBug = pdfBug;
@ -2786,7 +2786,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
globalThis.StepperManager && globalThis.StepperManager &&
globalThis.StepperManager.enabled globalThis.StepperManager.enabled
) { ) {
this.stepper = globalThis.StepperManager.create(this.pageNumber - 1); this.stepper = globalThis.StepperManager.create(this._pageIndex);
this.stepper.init(this.operatorList); this.stepper.init(this.operatorList);
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint(); this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
} }
@ -2831,7 +2831,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this.callback( this.callback(
error || error ||
new RenderingCancelledException( new RenderingCancelledException(
`Rendering cancelled, page ${this.pageNumber}`, `Rendering cancelled, page ${this._pageIndex + 1}`,
"canvas" "canvas"
) )
); );

View File

@ -505,7 +505,7 @@ describe("api", function() {
promise promise
.then(function(data) { .then(function(data) {
expect(data instanceof PDFPageProxy).toEqual(true); expect(data instanceof PDFPageProxy).toEqual(true);
expect(data.pageIndex).toEqual(0); expect(data.pageNumber).toEqual(1);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);
@ -1769,7 +1769,9 @@ describe("api", function() {
}) })
.catch(function(error) { .catch(function(error) {
expect(error instanceof RenderingCancelledException).toEqual(true); expect(error instanceof RenderingCancelledException).toEqual(true);
expect(error.message).toEqual("Rendering cancelled, page 1");
expect(error.type).toEqual("canvas"); expect(error.type).toEqual("canvas");
CanvasFactory.destroy(canvasAndCtx); CanvasFactory.destroy(canvasAndCtx);
done(); done();
}); });

View File

@ -678,7 +678,7 @@ class PDFPageView {
const ensureNotCancelled = () => { const ensureNotCancelled = () => {
if (cancelled) { if (cancelled) {
throw new RenderingCancelledException( throw new RenderingCancelledException(
"Rendering cancelled, page " + this.id, `Rendering cancelled, page ${this.id}`,
"svg" "svg"
); );
} }