Merge branch 'master' of github.com:mozilla/pdf.js into seac

This commit is contained in:
Brendan Dahl 2012-07-20 15:12:09 -07:00
commit 6ed639e4d8
13 changed files with 189 additions and 42 deletions

View File

@ -132,16 +132,13 @@ ChromeActions.prototype = {
var originalUrl = data.originalUrl;
// The data may not be downloaded so we need just retry getting the pdf with
// the original url.
var blobUrl = data.blobUrl || originalUrl;
var originalUri = NetUtil.newURI(originalUrl);
var blobUri = NetUtil.newURI(blobUrl);
var originalUri = NetUtil.newURI(data.originalUrl);
var blobUri = data.blobUrl ? NetUtil.newURI(data.blobUrl) : originalUri;
var extHelperAppSvc =
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
getService(Ci.nsIExternalHelperAppService);
var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1'].
getService(Ci.nsIWindowWatcher).activeWindow;
var ioService = Services.io;
var channel = ioService.newChannel(originalUrl, null, null);
NetUtil.asyncFetch(blobUri, function(aInputStream, aResult) {
if (!Components.isSuccessCode(aResult)) {

View File

@ -1,3 +1,4 @@
# Chrome notification bar messages and buttons
unsupported_feature=This PDF document might not be displayed correctly.
open_with_different_viewer=Open With Different Viewer
open_with_different_viewer.accessKey=o

View File

@ -87,3 +87,5 @@ loading_error=An error occurred while loading the PDF.
# Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type=[{{type}} Annotation]
request_password=PDF is protected by a password:
printing_not_supported=Warning: Printing is not fully supported by this browser.

View File

@ -1196,20 +1196,20 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Marked content
markPoint: function CanvasGraphics_markPoint(tag) {
TODO('Marked content');
// TODO Marked content.
},
markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
TODO('Marked content');
// TODO Marked content.
},
beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
TODO('Marked content');
// TODO Marked content.
},
beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
tag, properties) {
TODO('Marked content');
// TODO Marked content.
},
endMarkedContent: function CanvasGraphics_endMarkedContent() {
TODO('Marked content');
// TODO Marked content.
},
// Compatibility

View File

@ -399,9 +399,14 @@ var PDFDocument = (function PDFDocumentClosure() {
var length = this.stream.length;
var linearization = false;
if (length) {
linearization = new Linearization(this.stream);
if (linearization.length != length)
linearization = false;
try {
linearization = new Linearization(this.stream);
if (linearization.length != length)
linearization = false;
} catch (err) {
warn('The linearization data is not available ' +
'or unreadable pdf data is found');
}
}
// shadow the prototype getter with a data property
return shadow(this, 'linearization', linearization);

View File

@ -3422,6 +3422,40 @@ var Type1Parser = function type1Parser() {
var kEscapeCommand = 12;
// Breaks up the stack by arguments and also calculates the value.
function breakUpArgs(stack, numArgs) {
var args = [];
var index = stack.length - 1;
for (var i = 0; i < numArgs; i++) {
if (index < 0) {
args.unshift({ arg: [0],
value: 0 });
warn('Malformed charstring stack: not enough values on stack.');
continue;
}
var token = stack[index];
if (token === 'div') {
var a = stack[index - 2];
var b = stack[index - 1];
if (!isInt(a) || !isInt(b)) {
warn('Malformed charsting stack: expected ints on stack for div.');
a = 0;
b = 1;
}
args.unshift({ arg: [a, b, 'div'],
value: a / b });
index -= 3;
} else if (isInt(token)) {
args.unshift({ arg: stack.slice(index, index + 1),
value: token });
index--;
} else {
warn('Malformed charsting stack: found bad token ' + token + '.');
}
}
return args;
}
function decodeCharString(array) {
var charstring = [];
var lsb = 0;
@ -3475,25 +3509,17 @@ var Type1Parser = function type1Parser() {
command = charStringDictionary['12'][escape];
} else {
// TODO Clean this code
if (value == 13) { // hsbw
if (charstring.length == 2) {
lsb = charstring[0];
width = charstring[1];
charstring.splice(0, 1);
} else if (charstring.length == 4 && charstring[3] == 'div') {
lsb = charstring[0];
width = charstring[1] / charstring[2];
charstring.splice(0, 1);
} else if (charstring.length == 4 && charstring[2] == 'div') {
lsb = charstring[0] / charstring[1];
width = charstring[3];
charstring.splice(0, 3);
} else {
error('Unsupported hsbw format: ' + charstring);
}
charstring.push(lsb, 'hmoveto');
var args = breakUpArgs(charstring, 2);
var arg0 = args[0];
var arg1 = args[1];
lsb = arg0.value;
width = arg1.value;
// To convert to type2 we have to move the width value to the first
// part of the charstring and then use hmoveto with lsb.
charstring = arg1.arg;
charstring = charstring.concat(arg0.arg);
charstring.push('hmoveto');
continue;
} else if (value == 10) { // callsubr
if (charstring[charstring.length - 1] < 3) { // subr #0..2

View File

@ -852,7 +852,7 @@ var JpegStream = (function JpegStreamClosure() {
*/
JpegStream.prototype.isNativelySupported =
function JpegStream_isNativelySupported(xref, res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
// when bug 674619 lands, let's check if browser can do
// normal cmyk and then we won't need to decode in JS
if (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB')
@ -867,7 +867,7 @@ var JpegStream = (function JpegStreamClosure() {
*/
JpegStream.prototype.isNativelyDecodable =
function JpegStream_isNativelyDecodable(xref, res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
var numComps = cs.numComps;
if (numComps == 1 || numComps == 3)
return true;

View File

@ -9,13 +9,11 @@ VPATH = @srcdir@
relativesrcdir = browser/extensions/pdfjs/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_TEST_FILES = \
MOCHITEST_BROWSER_FILES = \
browser_pdfjs_main.js \
browser_pdfjs_savedialog.js \
file_pdfjs_test.pdf \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1 @@
http://www.meal-a-day.asia/sites/default/files/Meal-a-Day%20Asia-Pacific%20Biennial%20Report%202012%20v1.01.pdf

View File

@ -604,6 +604,15 @@
"link": true,
"type": "eq"
},
{ "id": "issue1419.pdf",
"file": "pdfs/issue1419.pdf",
"md5": "b5b6c6405d7b48418bccf97277957664",
"rounds": 1,
"link": true,
"pageLimit": 1,
"skipPages": [1],
"type": "eq"
},
{ "id": "issue1317",
"file": "pdfs/issue1317.pdf",
"md5": "6fb46275b30c48c8985617d4f86199e3",

View File

@ -1113,7 +1113,16 @@ canvas {
font-size: 10px;
}
@page {
margin: 0;
}
#printContainer {
display: none;
}
@media print {
/* Rules for browsers that don't support mozPrintCallback. */
#sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer {
display: none;
}
@ -1135,6 +1144,19 @@ canvas {
.page[data-loaded] {
display: block;
}
/* Rules for browsers that support mozPrintCallback */
body[data-mozPrintCallback] #outerContainer {
display: none;
}
body[data-mozPrintCallback] #printContainer {
display: block;
}
#printContainer canvas {
position: relative;
top: 0;
left: 0;
}
}
@media all and (max-width: 950px) {

View File

@ -102,11 +102,9 @@
<span data-l10n-id="open_file_label">Open</span>
</button>
<!--
<button id="print" class="toolbarButton print" title="Print" tabindex="11" data-l10n-id="print" onclick="window.print()">
<span data-l10n-id="print_label">Print</span>
</button>
-->
<button id="download" class="toolbarButton download" title="Download" onclick="PDFView.download();" tabindex="12" data-l10n-id="download">
<span data-l10n-id="download_label">Download</span>
@ -176,5 +174,6 @@
</div> <!-- mainContainer -->
</div> <!-- outerContainer -->
<div id="printContainer"></div>
</body>
</html>

View File

@ -379,6 +379,17 @@ var PDFView = {
return currentPageNumber;
},
get supportsPrinting() {
var canvas = document.createElement('canvas');
var value = 'mozPrintCallback' in canvas;
// shadow
Object.defineProperty(this, 'supportsPrinting', { value: value,
enumerable: true,
configurable: true,
writable: false });
return value;
},
open: function pdfViewOpen(url, scale, password) {
var parameters = {password: password};
if (typeof url === 'string') { // URL
@ -1041,6 +1052,26 @@ var PDFView = {
params[unescape(key)] = unescape(value);
}
return params;
},
beforePrint: function pdfViewSetupBeforePrint() {
if (!this.supportsPrinting) {
var printMessage = mozL10n.get('printing_not_supported', null,
'Warning: Printing is not fully supported by this browser.');
this.error(printMessage);
return;
}
var body = document.querySelector('body');
body.setAttribute('data-mozPrintCallback', true);
for (var i = 0, ii = this.pages.length; i < ii; ++i) {
this.pages[i].beforePrint();
}
},
afterPrint: function pdfViewSetupAfterPrint() {
var div = document.getElementById('printContainer');
while (div.hasChildNodes())
div.removeChild(div.lastChild);
}
};
@ -1360,6 +1391,44 @@ var PageView = function pageView(container, pdfPage, id, scale,
div.setAttribute('data-loaded', true);
};
this.beforePrint = function pageViewBeforePrint() {
var pdfPage = this.pdfPage;
var viewport = pdfPage.getViewport(1);
var canvas = this.canvas = document.createElement('canvas');
canvas.width = viewport.width;
canvas.height = viewport.height;
canvas.style.width = viewport.width + 'pt';
canvas.style.height = viewport.height + 'pt';
var printContainer = document.getElementById('printContainer');
printContainer.appendChild(canvas);
var self = this;
canvas.mozPrintCallback = function(obj) {
var ctx = obj.context;
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
pdfPage.render(renderContext).then(function() {
// Tell the printEngine that rendering this canvas/page has finished.
obj.done();
self.pdfPage.destroy();
}, function(error) {
console.error(error);
// Tell the printEngine that rendering this canvas/page has failed.
// This will make the print proces stop.
if ('abort' in object)
obj.abort();
else
obj.done();
self.pdfPage.destroy();
});
};
};
this.updateStats = function pageViewUpdateStats() {
if (PDFJS.pdfBug && Stats.enabled) {
var stats = this.stats;
@ -1596,6 +1665,9 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
var renderInterval = 0;
var resumeInterval = 500; // in ms
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
// Render the text layer, one div at a time
function renderTextLayer() {
if (textDivs.length === 0) {
@ -1609,9 +1681,12 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
if (textDiv.dataset.textLength > 1) { // avoid div by zero
// Adjust div width to match canvas text
// Due to the .offsetWidth calls, this is slow
// This needs to come after appending to the DOM
var textScale = textDiv.dataset.canvasWidth / textDiv.offsetWidth;
ctx.font = textDiv.style.fontSize + ' sans-serif';
var width = ctx.measureText(textDiv.textContent).width;
var textScale = textDiv.dataset.canvasWidth / width;
CustomStyle.setProp('transform' , textDiv,
'scale(' + textScale + ', 1)');
CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%');
@ -1706,6 +1781,10 @@ window.addEventListener('load', function webViewerLoad(evt) {
document.querySelector('#viewSearch').classList.remove('hidden');
}
if (!PDFView.supportsPrinting) {
document.getElementById('print').classList.add('hidden');
}
// Listen for warnings to trigger the fallback UI. Errors should be caught
// and call PDFView.error() so we don't need to listen for those.
PDFJS.LogManager.addLogger({
@ -1960,3 +2039,11 @@ window.addEventListener('keydown', function keydown(evt) {
evt.preventDefault();
}
});
window.addEventListener('beforeprint', function beforePrint(evt) {
PDFView.beforePrint();
});
window.addEventListener('afterprint', function afterPrint(evt) {
PDFView.afterPrint();
});