mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Improved annotations' display/behavior.
Added an "InteractiveAnnotation" class to homogenize the annotations' structure (highlighting) and user interactions (for now, used for text and link annotations). Text annotations: The appearance (AP) has priority over the icon (Name). The popup extends horizontally (up to a limit) as well as vertically. Reduced the title's font size. The annotation's color (C) is used to color the popup's background. On top of the mouseover show/hide behavior, a click on the icon will lock the annotation open (for mobile purposes). It can be closed with another click on either the icon or the popup. An annotation printing is conditioned by its "print" bit Unsupported annotations are not displayed at all.
This commit is contained in:
parent
3e931048f2
commit
076b3433b4
8 changed files with 305 additions and 131 deletions
|
@ -341,10 +341,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
this.stats.enabled = !!globalScope.PDFJS.enableStats;
|
||||
this.commonObjs = transport.commonObjs;
|
||||
this.objs = new PDFObjects();
|
||||
this.receivingOperatorList = false;
|
||||
this.cleanupAfterRender = false;
|
||||
this.pendingDestroy = false;
|
||||
this.renderTasks = [];
|
||||
this.intentStates = {};
|
||||
}
|
||||
PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
|
||||
/**
|
||||
|
@ -423,12 +422,21 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
// this call to render.
|
||||
this.pendingDestroy = false;
|
||||
|
||||
var renderingIntent = 'intent' in params ?
|
||||
(params.intent == 'print' ? 'print' : 'display') :
|
||||
'display';
|
||||
|
||||
if (!this.intentStates[renderingIntent]) {
|
||||
this.intentStates[renderingIntent] = {};
|
||||
}
|
||||
var intentState = this.intentStates[renderingIntent];
|
||||
|
||||
// If there is no displayReadyPromise yet, then the operatorList was never
|
||||
// requested before. Make the request and create the promise.
|
||||
if (!this.displayReadyPromise) {
|
||||
this.receivingOperatorList = true;
|
||||
this.displayReadyPromise = new LegacyPromise();
|
||||
this.operatorList = {
|
||||
if (!intentState.displayReadyPromise) {
|
||||
intentState.receivingOperatorList = true;
|
||||
intentState.displayReadyPromise = new LegacyPromise();
|
||||
intentState.operatorList = {
|
||||
fnArray: [],
|
||||
argsArray: [],
|
||||
lastChunk: false
|
||||
|
@ -436,18 +444,23 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
|
||||
this.stats.time('Page Request');
|
||||
this.transport.messageHandler.send('RenderPageRequest', {
|
||||
pageIndex: this.pageNumber - 1
|
||||
pageIndex: this.pageNumber - 1,
|
||||
intent: renderingIntent
|
||||
});
|
||||
}
|
||||
|
||||
var internalRenderTask = new InternalRenderTask(complete, params,
|
||||
this.objs, this.commonObjs,
|
||||
this.operatorList, this.pageNumber);
|
||||
this.renderTasks.push(internalRenderTask);
|
||||
intentState.operatorList,
|
||||
this.pageNumber);
|
||||
if (!intentState.renderTasks) {
|
||||
intentState.renderTasks = [];
|
||||
}
|
||||
intentState.renderTasks.push(internalRenderTask);
|
||||
var renderTask = new RenderTask(internalRenderTask);
|
||||
|
||||
var self = this;
|
||||
this.displayReadyPromise.then(
|
||||
intentState.displayReadyPromise.then(
|
||||
function pageDisplayReadyPromise(transparency) {
|
||||
if (self.pendingDestroy) {
|
||||
complete();
|
||||
|
@ -463,9 +476,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
);
|
||||
|
||||
function complete(error) {
|
||||
var i = self.renderTasks.indexOf(internalRenderTask);
|
||||
var i = intentState.renderTasks.indexOf(internalRenderTask);
|
||||
if (i >= 0) {
|
||||
self.renderTasks.splice(i, 1);
|
||||
intentState.renderTasks.splice(i, 1);
|
||||
}
|
||||
|
||||
if (self.cleanupAfterRender) {
|
||||
|
@ -513,14 +526,17 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
*/
|
||||
_tryDestroy: function PDFPageProxy__destroy() {
|
||||
if (!this.pendingDestroy ||
|
||||
this.renderTasks.length !== 0 ||
|
||||
this.receivingOperatorList) {
|
||||
Object.keys(this.intentStates).some(function(intent) {
|
||||
var intentState = this.intentStates[intent];
|
||||
return intentState.renderTasks.length !== 0 ||
|
||||
intentState.receivingOperatorList;
|
||||
}, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete this.operatorList;
|
||||
delete this.displayReadyPromise;
|
||||
delete this.annotationsPromise;
|
||||
Object.keys(this.intentStates).forEach(function(intent) {
|
||||
delete this.intentStates[intent];
|
||||
}, this);
|
||||
this.objs.clear();
|
||||
this.pendingDestroy = false;
|
||||
},
|
||||
|
@ -528,28 +544,33 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
* For internal use only.
|
||||
* @ignore
|
||||
*/
|
||||
_startRenderPage: function PDFPageProxy_startRenderPage(transparency) {
|
||||
this.displayReadyPromise.resolve(transparency);
|
||||
_startRenderPage: function PDFPageProxy_startRenderPage(transparency,
|
||||
intent) {
|
||||
var intentState = this.intentStates[intent];
|
||||
intentState.displayReadyPromise.resolve(transparency);
|
||||
},
|
||||
/**
|
||||
* For internal use only.
|
||||
* @ignore
|
||||
*/
|
||||
_renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk) {
|
||||
_renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
|
||||
intent) {
|
||||
var intentState = this.intentStates[intent];
|
||||
// Add the new chunk to the current operator list.
|
||||
for (var i = 0, ii = operatorListChunk.length; i < ii; i++) {
|
||||
this.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
||||
this.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
|
||||
intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
||||
intentState.operatorList.argsArray.push(
|
||||
operatorListChunk.argsArray[i]);
|
||||
}
|
||||
this.operatorList.lastChunk = operatorListChunk.lastChunk;
|
||||
intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
|
||||
|
||||
// Notify all the rendering tasks there are more operators to be consumed.
|
||||
for (var i = 0; i < this.renderTasks.length; i++) {
|
||||
this.renderTasks[i].operatorListChanged();
|
||||
for (var i = 0; i < intentState.renderTasks.length; i++) {
|
||||
intentState.renderTasks[i].operatorListChanged();
|
||||
}
|
||||
|
||||
if (operatorListChunk.lastChunk) {
|
||||
this.receivingOperatorList = false;
|
||||
intentState.receivingOperatorList = false;
|
||||
this._tryDestroy();
|
||||
}
|
||||
}
|
||||
|
@ -775,13 +796,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
var page = this.pageCache[data.pageIndex];
|
||||
|
||||
page.stats.timeEnd('Page Request');
|
||||
page._startRenderPage(data.transparency);
|
||||
page._startRenderPage(data.transparency, data.intent);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('RenderPageChunk', function transportRender(data) {
|
||||
var page = this.pageCache[data.pageIndex];
|
||||
|
||||
page._renderPageChunk(data.operatorList);
|
||||
page._renderPageChunk(data.operatorList, data.intent);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('commonobj', function transportObj(data) {
|
||||
|
@ -824,8 +845,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
var pageIndex = data[1];
|
||||
var type = data[2];
|
||||
var pageProxy = this.pageCache[pageIndex];
|
||||
if (pageProxy.objs.hasData(id))
|
||||
if (pageProxy.objs.hasData(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'JpegStream':
|
||||
|
@ -861,10 +883,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
this.workerReadyPromise.reject(data);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('PageError', function transportError(data) {
|
||||
messageHandler.on('PageError', function transportError(data, intent) {
|
||||
var page = this.pageCache[data.pageNum - 1];
|
||||
if (page.displayReadyPromise)
|
||||
page.displayReadyPromise.reject(data.error);
|
||||
var intentState = page.intentStates[intent];
|
||||
if (intentState.displayReadyPromise)
|
||||
intentState.displayReadyPromise.reject(data.error);
|
||||
else
|
||||
error(data.error);
|
||||
}, this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue