Commit ad1a4b16 authored by csillag's avatar csillag

Update PDF plugin

... to 18d8f72a (typed-packaging branch),
which brings support for the PDF.js version
shiping with FF35.
parent de6e7f4a
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-95b7a09
** Annotator 1.2.6-dev-18d8f72
** https://github.com/okfn/annotator/
**
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE
**
** Built at: 2014-11-26 22:32:31Z
** Built at: 2014-12-08 17:27:52Z
*/
......@@ -18,44 +18,75 @@
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
var PDFTextMapper, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.PDFTextMapper = (function(_super) {
PDFTextMapper = (function(_super) {
__extends(PDFTextMapper, _super);
PDFTextMapper.isPDFDocument = function() {
return (typeof PDFView !== "undefined" && PDFView !== null) || (typeof PDFViewerApplication !== "undefined" && PDFViewerApplication !== null);
};
PDFTextMapper.applicable = function() {
return typeof PDFView !== "undefined" && PDFView !== null;
return this.isPDFDocument();
};
PDFTextMapper.prototype.requiresSmartStringPadding = true;
PDFTextMapper.prototype.getPageCount = function() {
return PDFView.pages.length;
return this._viewer.pages.length;
};
PDFTextMapper.prototype.getPageIndex = function() {
return PDFView.page - 1;
return this._app.page - 1;
};
PDFTextMapper.prototype.setPageIndex = function(index) {
return PDFView.page = index + 1;
return this._app.page = index + 1;
};
PDFTextMapper.prototype._isPageRendered = function(index) {
var _ref, _ref1;
return (_ref = PDFView.pages[index]) != null ? (_ref1 = _ref.textLayer) != null ? _ref1.renderingDone : void 0 : void 0;
return (_ref = this._viewer.pages[index]) != null ? (_ref1 = _ref.textLayer) != null ? _ref1.renderingDone : void 0 : void 0;
};
PDFTextMapper.prototype.getRootNodeForPage = function(index) {
return PDFView.pages[index].textLayer.textLayerDiv;
return this._viewer.pages[index].textLayer.textLayerDiv;
};
function PDFTextMapper() {
this._finishScan = __bind(this._finishScan, this);
this._parseExtractedText = __bind(this._parseExtractedText, this);
var _ref,
_this = this;
if (typeof PDFViewerApplication !== "undefined" && PDFViewerApplication !== null) {
this._app = PDFViewerApplication;
this._viewer = this._app.pdfViewer;
this._tryExtractPage = function(index) {
return _this._viewer.getPageTextContent(index);
};
} else {
this._app = this._viewer = PDFView;
this._finder = (_ref = this._app.findController) != null ? _ref : PDFFindController;
this._tryExtractPage = function(index) {
return new Promise(function(resolve, reject) {
var tryIt;
tryIt = function() {
var page;
page = _this._finder.pdfPageSource.pages[index];
if ((page != null ? page.pdfPage : void 0) != null) {
return page.getTextContent().then(resolve);
} else {
return setTimeout(tryIt, 100);
}
};
return tryIt();
});
};
}
this.setEvents();
}
......@@ -93,7 +124,7 @@
}
}
});
return $(PDFView.container).on('scroll', function() {
return $(this._viewer.container).on('scroll', function() {
return _this._onScroll();
});
};
......@@ -104,12 +135,11 @@
return text.replace(this._extractionPattern, " ");
};
PDFTextMapper.prototype._waitForInit = function() {
PDFTextMapper.prototype.waitForInit = function() {
var tryIt,
_this = this;
tryIt = function(resolve) {
var _this = this;
if (PDFView.documentFingerprint && PDFView.documentInfo) {
if (_this._app.documentFingerprint && _this._app.documentInfo) {
return resolve();
} else {
return setTimeout((function() {
......@@ -118,7 +148,7 @@
}
};
return new Promise(function(resolve, reject) {
if (typeof PDFView !== "undefined" && PDFView !== null) {
if (PDFTextMapper.applicable()) {
return tryIt(resolve);
} else {
return reject("Not a PDF.js document");
......@@ -130,9 +160,8 @@
var _this = this;
return new Promise(function(resolve, reject) {
_this._pendingScanResolve = resolve;
return _this._waitForInit().then(function() {
return PDFView.getPage(1).then(function() {
console.log("Scanning document for text...");
return _this.waitForInit().then(function() {
return _this._app.pdfDocument.getPage(1).then(function() {
_this.pageInfo = [];
return _this._extractPageText(0);
});
......@@ -141,19 +170,10 @@
};
PDFTextMapper.prototype._extractPageText = function(pageIndex) {
var page, pageSource, _ref,
_this = this;
pageSource = (_ref = PDFFindController.pdfPageSource) != null ? _ref : PDFView.findController.pdfPageSource;
page = pageSource.pages[pageIndex];
if ((page != null ? page.pdfPage : void 0) == null) {
setTimeout((function() {
return _this._extractPageText(pageIndex);
}), 100);
return;
}
return page.getTextContent().then(function(data) {
var content, rawContent, text, textData, _ref1, _ref2;
textData = (_ref1 = (_ref2 = data.bidiTexts) != null ? _ref2 : data.items) != null ? _ref1 : data;
var _this = this;
return this._tryExtractPage(pageIndex).then(function(data) {
var content, rawContent, text, textData, _ref, _ref1;
textData = (_ref = (_ref1 = data.bidiTexts) != null ? _ref1 : data.items) != null ? _ref : data;
rawContent = ((function() {
var _i, _len, _results;
_results = [];
......@@ -168,7 +188,7 @@
index: pageIndex,
content: content
};
if (pageIndex === PDFView.pages.length - 1) {
if (pageIndex === _this.getPageCount() - 1) {
return _this._finishScan();
} else {
return _this._extractPageText(pageIndex + 1);
......@@ -192,9 +212,17 @@
return this.pageInfo[index];
};
PDFTextMapper.prototype.getDocumentFingerprint = function() {
return this._app.documentFingerprint;
};
PDFTextMapper.prototype.getDocumentInfo = function() {
return this.app.documentInfo;
};
return PDFTextMapper;
})(window.PageTextMapperCore);
})(PageTextMapperCore);
Annotator.Plugin.PDF = (function(_super) {
var $;
......@@ -222,7 +250,7 @@
};
PDF.prototype._isPDF = function() {
return window.PDFJS;
return PDFTextMapper.applicable();
};
PDF.prototype._getDocumentURI = function() {
......@@ -239,7 +267,7 @@
PDF.prototype._getFingerPrintURI = function() {
var fingerprint;
fingerprint = PDFView.documentFingerprint;
fingerprint = this.annotator.domMapper.getDocumentFingerprint();
return "urn:x-pdf:" + fingerprint;
};
......@@ -252,7 +280,7 @@
PDF.prototype._getTitle = function() {
var title, _ref1;
title = (_ref1 = PDFView.documentInfo.Title) != null ? _ref1.trim() : void 0;
title = (_ref1 = this.annotator.domMapper.getDocumentInfo().Title) != null ? _ref1.trim() : void 0;
if ((title != null) && title !== "") {
return title;
} else {
......@@ -284,10 +312,8 @@
PDF.prototype.getMetaData = function() {
var _this = this;
return new Promise(function(resolve, reject) {
var init;
init = _this.annotator.domMapper._waitForInit;
if (init != null) {
return init().then(function() {
if (_this.annotator.domMapper.waitForInit != null) {
return _this.annotator.domMapper.waitForInit().then(function() {
return resolve(_this._metadata());
});
} else {
......@@ -312,4 +338,3 @@
})(Annotator.Plugin);
}).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment