Removes PDFPageSource
This commit is contained in:
parent
7663942ee5
commit
fe4ac86781
@ -28,7 +28,6 @@
|
|||||||
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
||||||
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
||||||
* @property {Cache} cache - The page cache.
|
* @property {Cache} cache - The page cache.
|
||||||
* @property {PDFPageSource} pageSource
|
|
||||||
* @property {IPDFTextLayerFactory} textLayerFactory
|
* @property {IPDFTextLayerFactory} textLayerFactory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -49,7 +48,6 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
var linkService = options.linkService;
|
var linkService = options.linkService;
|
||||||
var renderingQueue = options.renderingQueue;
|
var renderingQueue = options.renderingQueue;
|
||||||
var cache = options.cache;
|
var cache = options.cache;
|
||||||
var pageSource = options.pageSource;
|
|
||||||
var textLayerFactory = options.textLayerFactory;
|
var textLayerFactory = options.textLayerFactory;
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -64,7 +62,6 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
this.renderingQueue = renderingQueue;
|
this.renderingQueue = renderingQueue;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
this.pageSource = pageSource;
|
|
||||||
this.textLayerFactory = textLayerFactory;
|
this.textLayerFactory = textLayerFactory;
|
||||||
|
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
@ -378,28 +375,13 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
draw: function PDFPageView_draw(callback) {
|
draw: function PDFPageView_draw(callback) {
|
||||||
var pdfPage = this.pdfPage;
|
|
||||||
|
|
||||||
if (this.pagePdfPromise) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!pdfPage) {
|
|
||||||
var promise = this.pageSource.getPage();
|
|
||||||
promise.then(function(pdfPage) {
|
|
||||||
delete this.pagePdfPromise;
|
|
||||||
this.setPdfPage(pdfPage);
|
|
||||||
this.draw(callback);
|
|
||||||
}.bind(this));
|
|
||||||
this.pagePdfPromise = promise;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||||
console.error('Must be in new state before drawing');
|
console.error('Must be in new state before drawing');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderingState = RenderingStates.RUNNING;
|
this.renderingState = RenderingStates.RUNNING;
|
||||||
|
|
||||||
|
var pdfPage = this.pdfPage;
|
||||||
var viewport = this.viewport;
|
var viewport = this.viewport;
|
||||||
var div = this.div;
|
var div = this.div;
|
||||||
// Wrap the canvas so if it has a css transform for highdpi the overflow
|
// Wrap the canvas so if it has a css transform for highdpi the overflow
|
||||||
|
@ -235,7 +235,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
var scale = this._currentScale || 1.0;
|
var scale = this._currentScale || 1.0;
|
||||||
var viewport = pdfPage.getViewport(scale * CSS_UNITS);
|
var viewport = pdfPage.getViewport(scale * CSS_UNITS);
|
||||||
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||||
var pageSource = new PDFPageSource(pdfDocument, pageNum);
|
|
||||||
var textLayerFactory = null;
|
var textLayerFactory = null;
|
||||||
if (!PDFJS.disableTextLayer) {
|
if (!PDFJS.disableTextLayer) {
|
||||||
textLayerFactory = this;
|
textLayerFactory = this;
|
||||||
@ -248,7 +247,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
linkService: this.linkService,
|
linkService: this.linkService,
|
||||||
renderingQueue: this.renderingQueue,
|
renderingQueue: this.renderingQueue,
|
||||||
cache: this.cache,
|
cache: this.cache,
|
||||||
pageSource: pageSource,
|
|
||||||
textLayerFactory: textLayerFactory
|
textLayerFactory: textLayerFactory
|
||||||
});
|
});
|
||||||
bindOnAfterDraw(pageView);
|
bindOnAfterDraw(pageView);
|
||||||
@ -299,6 +297,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
this._currentScaleValue = null;
|
this._currentScaleValue = null;
|
||||||
this.location = null;
|
this.location = null;
|
||||||
this._pagesRotation = 0;
|
this._pagesRotation = 0;
|
||||||
|
this._pagesRequests = [];
|
||||||
|
|
||||||
var container = this.viewer;
|
var container = this.viewer;
|
||||||
while (container.hasChildNodes()) {
|
while (container.hasChildNodes()) {
|
||||||
@ -614,13 +613,38 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {PDFPageView} pageView
|
||||||
|
* @returns {PDFPage}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_ensurePdfPageLoaded: function (pageView) {
|
||||||
|
if (pageView.pdfPage) {
|
||||||
|
return Promise.resolve(pageView.pdfPage);
|
||||||
|
}
|
||||||
|
var pageNumber = pageView.id;
|
||||||
|
if (this._pagesRequests[pageNumber]) {
|
||||||
|
return this._pagesRequests[pageNumber];
|
||||||
|
}
|
||||||
|
var promise = this.pdfDocument.getPage(pageNumber).then(
|
||||||
|
function (pdfPage) {
|
||||||
|
pageView.setPdfPage(pdfPage);
|
||||||
|
this._pagesRequests[pageNumber] = null;
|
||||||
|
return pdfPage;
|
||||||
|
}.bind(this));
|
||||||
|
this._pagesRequests[pageNumber] = promise;
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
|
||||||
forceRendering: function (currentlyVisiblePages) {
|
forceRendering: function (currentlyVisiblePages) {
|
||||||
var visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
var visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
||||||
var pageView = this.renderingQueue.getHighestPriority(visiblePages,
|
var pageView = this.renderingQueue.getHighestPriority(visiblePages,
|
||||||
this.pages,
|
this.pages,
|
||||||
this.scroll.down);
|
this.scroll.down);
|
||||||
if (pageView) {
|
if (pageView) {
|
||||||
|
this._ensurePdfPageLoaded(pageView).then(function () {
|
||||||
this.renderingQueue.renderView(pageView);
|
this.renderingQueue.renderView(pageView);
|
||||||
|
}.bind(this));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -705,31 +729,3 @@ var SimpleLinkService = (function SimpleLinkServiceClosure() {
|
|||||||
};
|
};
|
||||||
return SimpleLinkService;
|
return SimpleLinkService;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/**
|
|
||||||
* PDFPage object source.
|
|
||||||
* @class
|
|
||||||
*/
|
|
||||||
var PDFPageSource = (function PDFPageSourceClosure() {
|
|
||||||
/**
|
|
||||||
* @constructs
|
|
||||||
* @param {PDFDocument} pdfDocument
|
|
||||||
* @param {number} pageNumber
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function PDFPageSource(pdfDocument, pageNumber) {
|
|
||||||
this.pdfDocument = pdfDocument;
|
|
||||||
this.pageNumber = pageNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
PDFPageSource.prototype = /** @lends PDFPageSource.prototype */ {
|
|
||||||
/**
|
|
||||||
* @returns {Promise<PDFPage>}
|
|
||||||
*/
|
|
||||||
getPage: function () {
|
|
||||||
return this.pdfDocument.getPage(this.pageNumber);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return PDFPageSource;
|
|
||||||
})();
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals mozL10n, RenderingStates, Promise, scrollIntoView, PDFPageSource,
|
/* globals mozL10n, RenderingStates, Promise, scrollIntoView,
|
||||||
watchScroll, getVisibleElements */
|
watchScroll, getVisibleElements */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -28,13 +28,11 @@ var THUMBNAIL_SCROLL_MARGIN = -19;
|
|||||||
* @param defaultViewport
|
* @param defaultViewport
|
||||||
* @param linkService
|
* @param linkService
|
||||||
* @param renderingQueue
|
* @param renderingQueue
|
||||||
* @param pageSource
|
|
||||||
*
|
*
|
||||||
* @implements {IRenderableView}
|
* @implements {IRenderableView}
|
||||||
*/
|
*/
|
||||||
var ThumbnailView = function thumbnailView(container, id, defaultViewport,
|
var ThumbnailView = function thumbnailView(container, id, defaultViewport,
|
||||||
linkService, renderingQueue,
|
linkService, renderingQueue) {
|
||||||
pageSource) {
|
|
||||||
var anchor = document.createElement('a');
|
var anchor = document.createElement('a');
|
||||||
anchor.href = linkService.getAnchorUrl('#page=' + id);
|
anchor.href = linkService.getAnchorUrl('#page=' + id);
|
||||||
anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}');
|
anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}');
|
||||||
@ -80,7 +78,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
|
|||||||
this.hasImage = false;
|
this.hasImage = false;
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
this.renderingQueue = renderingQueue;
|
this.renderingQueue = renderingQueue;
|
||||||
this.pageSource = pageSource;
|
|
||||||
|
|
||||||
this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) {
|
this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) {
|
||||||
this.pdfPage = pdfPage;
|
this.pdfPage = pdfPage;
|
||||||
@ -143,15 +140,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.draw = function thumbnailViewDraw(callback) {
|
this.draw = function thumbnailViewDraw(callback) {
|
||||||
if (!this.pdfPage) {
|
|
||||||
var promise = this.pageSource.getPage(this.id);
|
|
||||||
promise.then(function(pdfPage) {
|
|
||||||
this.setPdfPage(pdfPage);
|
|
||||||
this.draw(callback);
|
|
||||||
}.bind(this));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||||
console.error('Must be in new state before drawing');
|
console.error('Must be in new state before drawing');
|
||||||
}
|
}
|
||||||
@ -204,18 +192,14 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
|
|||||||
return tempCanvas;
|
return tempCanvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setImage = function thumbnailViewSetImage(img) {
|
this.setImage = function thumbnailViewSetImage(pageView) {
|
||||||
if (!this.pdfPage) {
|
var img = pageView.canvas;
|
||||||
var promise = this.pageSource.getPage();
|
|
||||||
promise.then(function(pdfPage) {
|
|
||||||
this.setPdfPage(pdfPage);
|
|
||||||
this.setImage(img);
|
|
||||||
}.bind(this));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.hasImage || !img) {
|
if (this.hasImage || !img) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.pdfPage) {
|
||||||
|
this.setPdfPage(pageView.pdfPage);
|
||||||
|
}
|
||||||
this.renderingState = RenderingStates.FINISHED;
|
this.renderingState = RenderingStates.FINISHED;
|
||||||
var ctx = this.getPageDrawContext();
|
var ctx = this.getPageDrawContext();
|
||||||
|
|
||||||
@ -330,6 +314,7 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
|
|||||||
_resetView: function () {
|
_resetView: function () {
|
||||||
this.thumbnails = [];
|
this.thumbnails = [];
|
||||||
this._pagesRotation = 0;
|
this._pagesRotation = 0;
|
||||||
|
this._pagesRequests = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
setDocument: function (pdfDocument) {
|
setDocument: function (pdfDocument) {
|
||||||
@ -351,15 +336,37 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
|
|||||||
var pagesCount = pdfDocument.numPages;
|
var pagesCount = pdfDocument.numPages;
|
||||||
var viewport = firstPage.getViewport(1.0);
|
var viewport = firstPage.getViewport(1.0);
|
||||||
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||||
var pageSource = new PDFPageSource(pdfDocument, pageNum);
|
|
||||||
var thumbnail = new ThumbnailView(this.container, pageNum,
|
var thumbnail = new ThumbnailView(this.container, pageNum,
|
||||||
viewport.clone(), this.linkService,
|
viewport.clone(), this.linkService,
|
||||||
this.renderingQueue, pageSource);
|
this.renderingQueue);
|
||||||
this.thumbnails.push(thumbnail);
|
this.thumbnails.push(thumbnail);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {PDFPageView} pageView
|
||||||
|
* @returns {PDFPage}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_ensurePdfPageLoaded: function (thumbView) {
|
||||||
|
if (thumbView.pdfPage) {
|
||||||
|
return Promise.resolve(thumbView.pdfPage);
|
||||||
|
}
|
||||||
|
var pageNumber = thumbView.id;
|
||||||
|
if (this._pagesRequests[pageNumber]) {
|
||||||
|
return this._pagesRequests[pageNumber];
|
||||||
|
}
|
||||||
|
var promise = this.pdfDocument.getPage(pageNumber).then(
|
||||||
|
function (pdfPage) {
|
||||||
|
thumbView.setPdfPage(pdfPage);
|
||||||
|
this._pagesRequests[pageNumber] = null;
|
||||||
|
return pdfPage;
|
||||||
|
}.bind(this));
|
||||||
|
this._pagesRequests[pageNumber] = promise;
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
|
||||||
ensureThumbnailVisible:
|
ensureThumbnailVisible:
|
||||||
function PDFThumbnailViewer_ensureThumbnailVisible(page) {
|
function PDFThumbnailViewer_ensureThumbnailVisible(page) {
|
||||||
// Ensure that the thumbnail of the current page is visible
|
// Ensure that the thumbnail of the current page is visible
|
||||||
@ -373,7 +380,9 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
|
|||||||
this.thumbnails,
|
this.thumbnails,
|
||||||
this.scroll.down);
|
this.scroll.down);
|
||||||
if (thumbView) {
|
if (thumbView) {
|
||||||
|
this._ensurePdfPageLoaded(thumbView).then(function () {
|
||||||
this.renderingQueue.renderView(thumbView);
|
this.renderingQueue.renderView(thumbView);
|
||||||
|
}.bind(this));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1734,7 +1734,7 @@ document.addEventListener('pagerendered', function (e) {
|
|||||||
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||||
var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
|
var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
|
||||||
getThumbnail(pageIndex);
|
getThumbnail(pageIndex);
|
||||||
thumbnailView.setImage(pageView.canvas);
|
thumbnailView.setImage(pageView);
|
||||||
|
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
//if (pageView.textLayer && pageView.textLayer.textDivs &&
|
//if (pageView.textLayer && pageView.textLayer.textDivs &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user