Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into cid0
Conflicts: pdf.js
This commit is contained in:
commit
078433fecd
4
Makefile
4
Makefile
@ -166,9 +166,9 @@ PDF_WEB_FILES = \
|
|||||||
extension:
|
extension:
|
||||||
# Copy a standalone version of pdf.js inside the content directory
|
# Copy a standalone version of pdf.js inside the content directory
|
||||||
@rm -Rf $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
@rm -Rf $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
||||||
@mkdir $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
@mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/web
|
||||||
@cp $(PDF_JS_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
@cp $(PDF_JS_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
||||||
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/
|
||||||
|
|
||||||
# Create the xpi
|
# Create the xpi
|
||||||
@cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
|
@cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
|
||||||
|
@ -493,16 +493,16 @@ var CipherTransformFactory = (function cipherTransformFactory() {
|
|||||||
|
|
||||||
function constructor(dict, fileId, password) {
|
function constructor(dict, fileId, password) {
|
||||||
var filter = dict.get('Filter');
|
var filter = dict.get('Filter');
|
||||||
if (!IsName(filter) || filter.name != 'Standard')
|
if (!isName(filter) || filter.name != 'Standard')
|
||||||
error('unknown encryption method');
|
error('unknown encryption method');
|
||||||
this.dict = dict;
|
this.dict = dict;
|
||||||
var algorithm = dict.get('V');
|
var algorithm = dict.get('V');
|
||||||
if (!IsInt(algorithm) ||
|
if (!isInt(algorithm) ||
|
||||||
(algorithm != 1 && algorithm != 2 && algorithm != 4))
|
(algorithm != 1 && algorithm != 2 && algorithm != 4))
|
||||||
error('unsupported encryption algorithm');
|
error('unsupported encryption algorithm');
|
||||||
this.algorithm = algorithm;
|
this.algorithm = algorithm;
|
||||||
var keyLength = dict.get('Length') || 40;
|
var keyLength = dict.get('Length') || 40;
|
||||||
if (!IsInt(keyLength) ||
|
if (!isInt(keyLength) ||
|
||||||
keyLength < 40 || (keyLength % 8) != 0)
|
keyLength < 40 || (keyLength % 8) != 0)
|
||||||
error('invalid key length');
|
error('invalid key length');
|
||||||
// prepare keys
|
// prepare keys
|
||||||
|
@ -13,9 +13,6 @@ const PDF_CONTENT_TYPE = 'application/pdf';
|
|||||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||||
Cu.import('resource://gre/modules/Services.jsm');
|
Cu.import('resource://gre/modules/Services.jsm');
|
||||||
|
|
||||||
// TODO
|
|
||||||
// Add some download progress event
|
|
||||||
|
|
||||||
function log(aMsg) {
|
function log(aMsg) {
|
||||||
let msg = 'pdfContentHandler.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
let msg = 'pdfContentHandler.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
||||||
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
|
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
|
||||||
@ -23,33 +20,44 @@ function log(aMsg) {
|
|||||||
dump(msg + '\n');
|
dump(msg + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fireEventTo(aName, aData, aWindow) {
|
||||||
|
let window = aWindow.wrappedJSObject;
|
||||||
|
let evt = window.document.createEvent('CustomEvent');
|
||||||
|
evt.initCustomEvent('pdf' + aName, false, false, aData);
|
||||||
|
window.document.dispatchEvent(evt);
|
||||||
|
}
|
||||||
|
|
||||||
function loadDocument(aWindow, aDocumentUrl) {
|
function loadDocument(aWindow, aDocumentUrl) {
|
||||||
let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
|
let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
|
||||||
.createInstance(Ci.nsIXMLHttpRequest);
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
xhr.open('GET', aDocumentUrl);
|
xhr.onprogress = function updateProgress(evt) {
|
||||||
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
|
if (evt.lengthComputable)
|
||||||
xhr.onreadystatechange = function() {
|
fireEventTo(evt.type, evt.loaded / evt.total, aWindow);
|
||||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
};
|
||||||
let data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
|
|
||||||
xhr.responseArrayBuffer || xhr.response);
|
|
||||||
try {
|
|
||||||
var view = new Uint8Array(data);
|
|
||||||
|
|
||||||
// I think accessing aWindow.wrappedJSObject returns a
|
xhr.onerror = function error(evt) {
|
||||||
// XPCSafeJSObjectWrapper and so it is safe but mrbkap can confirm that
|
fireEventTo(evt.type, false, aWindow);
|
||||||
let window = aWindow.wrappedJSObject;
|
};
|
||||||
var arrayBuffer = new window.ArrayBuffer(data.byteLength);
|
|
||||||
var view2 = new window.Uint8Array(arrayBuffer);
|
|
||||||
view2.set(view);
|
|
||||||
|
|
||||||
let evt = window.document.createEvent('CustomEvent');
|
xhr.onload = function load(evt) {
|
||||||
evt.initCustomEvent('pdfloaded', false, false, arrayBuffer);
|
let data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
|
||||||
window.document.dispatchEvent(evt);
|
xhr.responseArrayBuffer || xhr.response);
|
||||||
} catch (e) {
|
try {
|
||||||
log('Error - ' + e);
|
let view = new Uint8Array(data);
|
||||||
}
|
|
||||||
|
let window = aWindow.wrappedJSObject;
|
||||||
|
let arrayBuffer = new window.ArrayBuffer(data.byteLength);
|
||||||
|
let view2 = new window.Uint8Array(arrayBuffer);
|
||||||
|
view2.set(view);
|
||||||
|
|
||||||
|
fireEventTo(evt.type, arrayBuffer, aWindow);
|
||||||
|
} catch (e) {
|
||||||
|
log('Error - ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
xhr.open('GET', aDocumentUrl);
|
||||||
|
xhr.responseType = 'arraybuffer';
|
||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +148,7 @@ pdfContentHandler.prototype = {
|
|||||||
url = url.replace('%s', uri.spec);
|
url = url.replace('%s', uri.spec);
|
||||||
window.location = url;
|
window.location = url;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Error - ' + e);
|
log('Error retrieving the pdf.js base url - ' + e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
8
fonts.js
8
fonts.js
@ -1218,7 +1218,7 @@ var Font = (function Font() {
|
|||||||
encoding[i] = {
|
encoding[i] = {
|
||||||
unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
|
unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
|
||||||
i + kCmapGlyphOffset : i,
|
i + kCmapGlyphOffset : i,
|
||||||
width: IsNum(width) ? width : properties.defaultWidth
|
width: isNum(width) ? width : properties.defaultWidth
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2208,7 +2208,7 @@ CFF.prototype = {
|
|||||||
var cmd = map[command];
|
var cmd = map[command];
|
||||||
assert(cmd, 'Unknow command: ' + command);
|
assert(cmd, 'Unknow command: ' + command);
|
||||||
|
|
||||||
if (IsArray(cmd))
|
if (isArray(cmd))
|
||||||
charstring.splice(i++, 1, cmd[0], cmd[1]);
|
charstring.splice(i++, 1, cmd[0], cmd[1]);
|
||||||
else
|
else
|
||||||
charstring[i] = cmd;
|
charstring[i] = cmd;
|
||||||
@ -2334,7 +2334,7 @@ CFF.prototype = {
|
|||||||
continue;
|
continue;
|
||||||
var value = properties.private[field];
|
var value = properties.private[field];
|
||||||
|
|
||||||
if (IsArray(value)) {
|
if (isArray(value)) {
|
||||||
data += self.encodeNumber(value[0]);
|
data += self.encodeNumber(value[0]);
|
||||||
for (var i = 1; i < value.length; i++)
|
for (var i = 1; i < value.length; i++)
|
||||||
data += self.encodeNumber(value[i] - value[i - 1]);
|
data += self.encodeNumber(value[i] - value[i - 1]);
|
||||||
@ -2493,7 +2493,7 @@ var Type2CFF = (function type2CFF() {
|
|||||||
var width = mapping.width;
|
var width = mapping.width;
|
||||||
properties.glyphs[glyph] = properties.encoding[index] = {
|
properties.glyphs[glyph] = properties.encoding[index] = {
|
||||||
unicode: code,
|
unicode: code,
|
||||||
width: IsNum(width) ? width : defaultWidth
|
width: isNum(width) ? width : defaultWidth
|
||||||
};
|
};
|
||||||
|
|
||||||
charstrings.push({
|
charstrings.push({
|
||||||
|
@ -258,7 +258,7 @@ var Type2Parser = function(aFilePath) {
|
|||||||
var count = decoded.length;
|
var count = decoded.length;
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var token = decoded[i];
|
var token = decoded[i];
|
||||||
if (IsNum(token)) {
|
if (isNum(token)) {
|
||||||
stack.push(token);
|
stack.push(token);
|
||||||
} else {
|
} else {
|
||||||
switch (token.operand) {
|
switch (token.operand) {
|
||||||
|
@ -107,15 +107,18 @@ var PDFView = {
|
|||||||
|
|
||||||
document.title = url;
|
document.title = url;
|
||||||
|
|
||||||
getPdf({url: url, progress: PDFView.progressLevel}, function(data) {
|
getPdf(
|
||||||
document.getElementById('loading').style.display = 'none';
|
{
|
||||||
PDFView.load(data, scale);
|
url: url,
|
||||||
});
|
progress: function getPdfProgress(evt) {
|
||||||
},
|
if (evt.lengthComputable)
|
||||||
|
PDFView.progress(evt.loaded / evt.total);
|
||||||
progressLevel: function(evt) {
|
},
|
||||||
var p = Math.round((evt.loaded / evt.total) * 100);
|
error: PDFView.error
|
||||||
document.getElementById('loading').innerHTML = 'Loading... ' + p + '%';
|
},
|
||||||
|
function getPdfLoad(data) {
|
||||||
|
PDFView.load(data, scale);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
navigateTo: function(dest) {
|
navigateTo: function(dest) {
|
||||||
@ -134,7 +137,21 @@ var PDFView = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
error: function() {
|
||||||
|
var loadingIndicator = document.getElementById('loading');
|
||||||
|
loadingIndicator.innerHTML = 'Error';
|
||||||
|
},
|
||||||
|
|
||||||
|
progress: function(level) {
|
||||||
|
var percent = Math.round(level * 100);
|
||||||
|
var loadingIndicator = document.getElementById('loading');
|
||||||
|
loadingIndicator.innerHTML = 'Loading... ' + percent + '%';
|
||||||
|
},
|
||||||
|
|
||||||
load: function(data, scale) {
|
load: function(data, scale) {
|
||||||
|
var loadingIndicator = document.getElementById('loading');
|
||||||
|
loadingIndicator.style.display = 'none';
|
||||||
|
|
||||||
var sidebar = document.getElementById('sidebarView');
|
var sidebar = document.getElementById('sidebarView');
|
||||||
sidebar.parentNode.scrollTop = 0;
|
sidebar.parentNode.scrollTop = 0;
|
||||||
|
|
||||||
@ -482,10 +499,18 @@ window.addEventListener('load', function(evt) {
|
|||||||
document.getElementById('fileInput').value = null;
|
document.getElementById('fileInput').value = null;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
window.addEventListener('pdfloaded', function(evt) {
|
window.addEventListener('pdfload', function(evt) {
|
||||||
PDFView.load(evt.detail);
|
PDFView.load(evt.detail);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
window.addEventListener('pdfprogress', function(evt) {
|
||||||
|
PDFView.progress(evt.detail);
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
window.addEventListener('pdferror', function(evt) {
|
||||||
|
PDFView.error();
|
||||||
|
}, true);
|
||||||
|
|
||||||
function updateViewarea() {
|
function updateViewarea() {
|
||||||
var visiblePages = PDFView.getVisiblePages();
|
var visiblePages = PDFView.getVisiblePages();
|
||||||
for (var i = 0; i < visiblePages.length; i++) {
|
for (var i = 0; i < visiblePages.length; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user