Merge remote-tracking branch 'upstream/master' into dev

This commit is contained in:
Kalervo Kujala 2012-01-09 20:39:05 +02:00
commit 37d2d82f59
6 changed files with 76 additions and 30 deletions

View File

@ -118,7 +118,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var self = this; var self = this;
var xref = this.xref; var xref = this.xref;
var handler = this.handler; var handler = this.handler;
var uniquePrefix = this.uniquePrefix; var uniquePrefix = this.uniquePrefix || '';
function insertDependency(depList) { function insertDependency(depList) {
fnArray.push('dependency'); fnArray.push('dependency');
@ -211,7 +211,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args = [objId, w, h]; args = [objId, w, h];
var softMask = dict.get('SMask', 'IM') || false; var softMask = dict.get('SMask', 'IM') || false;
if (!softMask && image instanceof JpegStream && image.isNative) { if (!softMask && image instanceof JpegStream &&
image.isNativelySupported(xref, resources)) {
// These JPEGs don't need any more processing so we can just send it. // These JPEGs don't need any more processing so we can just send it.
fn = 'paintJpegXObject'; fn = 'paintJpegXObject';
handler.send('obj', [objId, 'JpegStream', image.getIR()]); handler.send('obj', [objId, 'JpegStream', image.getIR()]);
@ -234,7 +235,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}, handler, xref, resources, image, inline); }, handler, xref, resources, image, inline);
} }
uniquePrefix = uniquePrefix || '';
if (!queue.argsArray) { if (!queue.argsArray) {
queue.argsArray = []; queue.argsArray = [];
} }

View File

@ -9,7 +9,7 @@ var PDFImage = (function PDFImageClosure() {
* when the image data is ready. * when the image data is ready.
*/ */
function handleImageData(handler, xref, res, image, promise) { function handleImageData(handler, xref, res, image, promise) {
if (image instanceof JpegStream && image.isNative) { if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
// For natively supported jpegs send them to the main thread for decoding. // For natively supported jpegs send them to the main thread for decoding.
var dict = image.dict; var dict = image.dict;
var colorSpace = dict.get('ColorSpace', 'CS'); var colorSpace = dict.get('ColorSpace', 'CS');

View File

@ -803,29 +803,16 @@ var JpegStream = (function JpegStreamClosure() {
// need to be removed // need to be removed
this.dict = dict; this.dict = dict;
// Flag indicating wether the image can be natively loaded. this.isAdobeImage = false;
this.isNative = true; this.colorTransform = dict.get('ColorTransform') || -1;
this.colorTransform = -1;
if (isAdobeImage(bytes)) { if (isAdobeImage(bytes)) {
// when bug 674619 land, let's check if browser can do this.isAdobeImage = true;
// normal cmyk and then we won't have to the following bytes = fixAdobeImage(bytes);
var cs = xref.fetchIfRef(dict.get('ColorSpace'));
// DeviceRGB and DeviceGray are the only Adobe images that work natively
if (isName(cs) && (cs.name === 'DeviceRGB' || cs.name === 'DeviceGray')) {
bytes = fixAdobeImage(bytes);
this.src = bytesToString(bytes);
} else {
this.colorTransform = dict.get('ColorTransform');
this.isNative = false;
this.bytes = bytes;
}
} else {
this.src = bytesToString(bytes);
} }
this.bytes = bytes;
DecodeStream.call(this); DecodeStream.call(this);
} }
@ -835,7 +822,8 @@ var JpegStream = (function JpegStreamClosure() {
if (this.bufferLength) if (this.bufferLength)
return; return;
var jpegImage = new JpegImage(); var jpegImage = new JpegImage();
jpegImage.colorTransform = this.colorTransform; if (this.colorTransform != -1)
jpegImage.colorTransform = this.colorTransform;
jpegImage.parse(this.bytes); jpegImage.parse(this.bytes);
var width = jpegImage.width; var width = jpegImage.width;
var height = jpegImage.height; var height = jpegImage.height;
@ -844,11 +832,39 @@ var JpegStream = (function JpegStreamClosure() {
this.bufferLength = data.length; this.bufferLength = data.length;
}; };
JpegStream.prototype.getIR = function jpegStreamGetIR() { JpegStream.prototype.getIR = function jpegStreamGetIR() {
return this.src; return bytesToString(this.bytes);
}; };
JpegStream.prototype.getChar = function jpegStreamGetChar() { JpegStream.prototype.getChar = function jpegStreamGetChar() {
error('internal error: getChar is not valid on JpegStream'); error('internal error: getChar is not valid on JpegStream');
}; };
/**
* Checks if the image can be decoded and displayed by the browser without any
* further processing such as color space conversions.
*/
JpegStream.prototype.isNativelySupported = function isNativelySupported(xref,
res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), 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')
return true;
if (cs.name === 'DeviceCMYK' && !this.isAdobeImage &&
this.colorTransform < 1)
return true;
return false;
};
/**
* Checks if the image can be decoded by the browser.
*/
JpegStream.prototype.isNativelyDecodable = function isNativelyDecodable(xref,
res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
var numComps = cs.numComps;
if (numComps == 1 || numComps == 3)
return true;
return false;
};
return JpegStream; return JpegStream;
})(); })();

View File

@ -0,0 +1 @@
user_pref("browser.shell.checkDefaultBrowser", false);

View File

@ -127,5 +127,23 @@ describe('obj', function() {
expect(ref.gen).toEqual(storedGen); expect(ref.gen).toEqual(storedGen);
}); });
}); });
describe('RefSet', function() {
it('should have a stored value', function() {
var ref = new Ref(4, 2);
var refset = new RefSet();
refset.put(ref);
expect(refset.has(ref)).toBeTruthy();
});
it('should not have an unknown value', function() {
var ref = new Ref(4, 2);
var refset = new RefSet();
expect(refset.has(ref)).toBeFalsy();
refset.put(ref);
var anotherRef = new Ref(2, 4);
expect(refset.has(anotherRef)).toBeFalsy();
});
});
}); });

View File

@ -781,9 +781,13 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
div.appendChild(canvas); div.appendChild(canvas);
this.canvas = canvas; this.canvas = canvas;
var textLayer = document.createElement('div'); var textLayerDiv = null;
textLayer.className = 'textLayer'; if (!PDFJS.disableTextLayer) {
div.appendChild(textLayer); textLayerDiv = document.createElement('div');
textLayerDiv.className = 'textLayer';
div.appendChild(textLayerDiv);
}
var textLayer = textLayerDiv ? new TextLayerBuilder(textLayerDiv) : null;
var scale = this.scale; var scale = this.scale;
canvas.width = pageWidth * scale; canvas.width = pageWidth * scale;
@ -807,7 +811,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
cache.push(this); cache.push(this);
callback(); callback();
}).bind(this), new TextLayerBuilder(textLayer) }).bind(this), textLayer
); );
setupAnnotations(this.content, this.scale); setupAnnotations(this.content, this.scale);
@ -878,6 +882,10 @@ var ThumbnailView = function thumbnailView(container, page, id, pageRatio) {
return ctx; return ctx;
} }
this.drawingRequired = function thumbnailViewDrawingRequired() {
return !this.hasImage;
};
this.draw = function thumbnailViewDraw(callback) { this.draw = function thumbnailViewDraw(callback) {
if (this.hasImage) { if (this.hasImage) {
callback(); callback();
@ -1003,7 +1011,10 @@ window.addEventListener('load', function webViewerLoad(evt) {
document.getElementById('fileInput').value = null; document.getElementById('fileInput').value = null;
if ('disableWorker' in params) if ('disableWorker' in params)
PDFJS.disableWorker = params['disableWorker'] === 'true' ? true : false; PDFJS.disableWorker = (params['disableWorker'] === 'true');
if ('disableTextLayer' in params)
PDFJS.disableTextLayer = (params['disableTextLayer'] === 'true');
var sidebarScrollView = document.getElementById('sidebarScrollView'); var sidebarScrollView = document.getElementById('sidebarScrollView');
sidebarScrollView.addEventListener('scroll', updateThumbViewArea, true); sidebarScrollView.addEventListener('scroll', updateThumbViewArea, true);