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

This commit is contained in:
Brendan Dahl 2012-01-04 11:25:46 -08:00
commit 702af87731
10 changed files with 103 additions and 45 deletions

View File

@ -255,6 +255,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} }
// Scale so that canvas units are the same as PDF user space units // Scale so that canvas units are the same as PDF user space units
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height);
// Move the media left-top corner to the (0,0) canvas position
this.ctx.translate(-mediaBox.x, -mediaBox.y);
this.textDivs = []; this.textDivs = [];
this.textLayerQueue = []; this.textLayerQueue = [];
}, },
@ -359,6 +361,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
setDash: function canvasGraphicsSetDash(dashArray, dashPhase) { setDash: function canvasGraphicsSetDash(dashArray, dashPhase) {
this.ctx.mozDash = dashArray; this.ctx.mozDash = dashArray;
this.ctx.mozDashOffset = dashPhase; this.ctx.mozDashOffset = dashPhase;
this.ctx.webkitLineDash = dashArray;
this.ctx.webkitLineDashOffset = dashPhase;
}, },
setRenderingIntent: function canvasGraphicsSetRenderingIntent(intent) { setRenderingIntent: function canvasGraphicsSetRenderingIntent(intent) {
TODO('set rendering intent: ' + intent); TODO('set rendering intent: ' + intent);

View File

@ -70,8 +70,7 @@ var Page = (function PageClosure() {
this.xref = xref; this.xref = xref;
this.ref = ref; this.ref = ref;
this.ctx = null; this.displayReadyPromise = null;
this.callback = null;
} }
Page.prototype = { Page.prototype = {
@ -110,9 +109,11 @@ var Page = (function PageClosure() {
width: this.width, width: this.width,
height: this.height height: this.height
}; };
var mediaBox = this.mediaBox;
var offsetX = mediaBox[0], offsetY = mediaBox[1];
if (isArray(obj) && obj.length == 4) { if (isArray(obj) && obj.length == 4) {
var tl = this.rotatePoint(obj[0], obj[1]); var tl = this.rotatePoint(obj[0] - offsetX, obj[1] - offsetY);
var br = this.rotatePoint(obj[2], obj[3]); var br = this.rotatePoint(obj[2] - offsetX, obj[3] - offsetY);
view.x = Math.min(tl.x, br.x); view.x = Math.min(tl.x, br.x);
view.y = Math.min(tl.y, br.y); view.y = Math.min(tl.y, br.y);
view.width = Math.abs(tl.x - br.x); view.width = Math.abs(tl.x - br.x);
@ -165,20 +166,12 @@ var Page = (function PageClosure() {
IRQueue, fonts) { IRQueue, fonts) {
var self = this; var self = this;
this.IRQueue = IRQueue; this.IRQueue = IRQueue;
var gfx = new CanvasGraphics(this.ctx, this.objs, this.textLayer);
var displayContinuation = function pageDisplayContinuation() { var displayContinuation = function pageDisplayContinuation() {
// Always defer call to display() to work around bug in // Always defer call to display() to work around bug in
// Firefox error reporting from XHR callbacks. // Firefox error reporting from XHR callbacks.
setTimeout(function pageSetTimeout() { setTimeout(function pageSetTimeout() {
try { self.displayReadyPromise.resolve();
self.display(gfx, self.callback);
} catch (e) {
if (self.callback)
self.callback(e);
else
throw e;
}
}); });
}; };
@ -395,12 +388,27 @@ var Page = (function PageClosure() {
return items; return items;
}, },
startRendering: function pageStartRendering(ctx, callback, textLayer) { startRendering: function pageStartRendering(ctx, callback, textLayer) {
this.ctx = ctx;
this.callback = callback;
this.textLayer = textLayer;
this.startRenderingTime = Date.now(); this.startRenderingTime = Date.now();
this.pdf.startRendering(this);
// If there is no displayReadyPromise yet, then the IRQueue was never
// requested before. Make the request and create the promise.
if (!this.displayReadyPromise) {
this.pdf.startRendering(this);
this.displayReadyPromise = new Promise();
}
// Once the IRQueue and fonts are loaded, perform the actual rendering.
this.displayReadyPromise.then(function pageDisplayReadyPromise() {
var gfx = new CanvasGraphics(ctx, this.objs, textLayer);
try {
this.display(gfx, callback);
} catch (e) {
if (self.callback)
self.callback(e);
else
throw e;
}
}.bind(this));
} }
}; };

View File

@ -2092,7 +2092,7 @@ var Font = (function FontClosure() {
window.btoa(data) + ');'); window.btoa(data) + ');');
var rule = "@font-face { font-family:'" + fontName + "';src:" + url + '}'; var rule = "@font-face { font-family:'" + fontName + "';src:" + url + '}';
document.documentElement.firstChild.appendChild( document.documentElement.getElementsByTagName('head')[0].appendChild(
document.createElement('style')); document.createElement('style'));
var styleSheet = document.styleSheets[document.styleSheets.length - 1]; var styleSheet = document.styleSheets[document.styleSheets.length - 1];

View File

@ -270,7 +270,6 @@ var PDFFunction = (function PDFFunctionClosure() {
constructStiched: function pdfFunctionConstructStiched(fn, dict, xref) { constructStiched: function pdfFunctionConstructStiched(fn, dict, xref) {
var domain = dict.get('Domain'); var domain = dict.get('Domain');
var range = dict.get('Range');
if (!domain) if (!domain)
error('No domain'); error('No domain');
@ -279,13 +278,13 @@ var PDFFunction = (function PDFFunctionClosure() {
if (inputSize != 1) if (inputSize != 1)
error('Bad domain for stiched function'); error('Bad domain for stiched function');
var fnRefs = dict.get('Functions'); var fnRefs = xref.fetchIfRef(dict.get('Functions'));
var fns = []; var fns = [];
for (var i = 0, ii = fnRefs.length; i < ii; ++i) for (var i = 0, ii = fnRefs.length; i < ii; ++i)
fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i]))); fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
var bounds = dict.get('Bounds'); var bounds = xref.fetchIfRef(dict.get('Bounds'));
var encode = dict.get('Encode'); var encode = xref.fetchIfRef(dict.get('Encode'));
return [CONSTRUCT_STICHED, domain, bounds, encode, fns]; return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
}, },

View File

@ -284,7 +284,7 @@ var Promise = (function PromiseClosure() {
} }
this.isResolved = true; this.isResolved = true;
this.data = data; this.data = data || null;
var callbacks = this.callbacks; var callbacks = this.callbacks;
for (var i = 0, ii = callbacks.length; i < ii; i++) { for (var i = 0, ii = callbacks.length; i < ii; i++) {

View File

@ -0,0 +1 @@
http://www.myhillsapartment.com/island_club/floorplans/images/links/Island_IC_brochure.pdf

View File

@ -356,6 +356,13 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue1001",
"file": "pdfs/issue1001.pdf",
"md5": "0f1496e80a82a923e91d9e74c55ad94e",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "aboutstacks", { "id": "aboutstacks",
"file": "pdfs/aboutstacks.pdf", "file": "pdfs/aboutstacks.pdf",
"md5": "6e7c8416a293ba2d83bc8dd20c6ccf51", "md5": "6e7c8416a293ba2d83bc8dd20c6ccf51",

View File

@ -5,8 +5,13 @@
// Checking if the typed arrays are supported // Checking if the typed arrays are supported
(function checkTypedArrayCompatibility() { (function checkTypedArrayCompatibility() {
if (typeof Uint8Array !== 'undefined') if (typeof Uint8Array !== 'undefined') {
// some mobile version might not support Float64Array
if (typeof Float64Array === 'undefined')
window.Float64Array = Float32Array;
return; return;
}
function subarray(start, end) { function subarray(start, end) {
return this.slice(start, end); return this.slice(start, end);
@ -46,6 +51,8 @@
window.Uint32Array = TypedArray; window.Uint32Array = TypedArray;
window.Int32Array = TypedArray; window.Int32Array = TypedArray;
window.Uint16Array = TypedArray; window.Uint16Array = TypedArray;
window.Float32Array = TypedArray;
window.Float64Array = TypedArray;
})(); })();
// Object.create() ? // Object.create() ?

View File

@ -67,10 +67,11 @@
<option value="0.75">75%</option> <option value="0.75">75%</option>
<option value="1">100%</option> <option value="1">100%</option>
<option value="1.25">125%</option> <option value="1.25">125%</option>
<option value="1.5" selected="selected">150%</option> <option value="1.5">150%</option>
<option value="2">200%</option> <option value="2">200%</option>
<option id="pageWidthOption" value="page-width">Page Width</option> <option id="pageWidthOption" value="page-width">Page Width</option>
<option id="pageFitOption" value="page-fit">Page Fit</option> <option id="pageFitOption" value="page-fit">Page Fit</option>
<option id="pageAutoOption" value="auto" selected="selected">Auto</option>
</select> </select>
<div class="separator"></div> <div class="separator"></div>

View File

@ -4,7 +4,7 @@
'use strict'; 'use strict';
var kDefaultURL = 'compressed.tracemonkey-pldi-09.pdf'; var kDefaultURL = 'compressed.tracemonkey-pldi-09.pdf';
var kDefaultScale = 1.5; var kDefaultScale = 'auto';
var kDefaultScaleDelta = 1.1; var kDefaultScaleDelta = 1.1;
var kCacheSize = 20; var kCacheSize = 20;
var kCssUnits = 96.0 / 72.0; var kCssUnits = 96.0 / 72.0;
@ -146,9 +146,13 @@ var PDFView = {
pages: [], pages: [],
thumbnails: [], thumbnails: [],
currentScale: 0, currentScale: 0,
currentScaleValue: null,
initialBookmark: document.location.hash.substring(1), initialBookmark: document.location.hash.substring(1),
setScale: function pdfViewSetScale(val, resetAutoSettings) { setScale: function pdfViewSetScale(val, resetAutoSettings) {
if (val == this.currentScale)
return;
var pages = this.pages; var pages = this.pages;
for (var i = 0; i < pages.length; i++) for (var i = 0; i < pages.length; i++)
pages[i].update(val * kCssUnits); pages[i].update(val * kCssUnits);
@ -169,6 +173,7 @@ var PDFView = {
return; return;
var scale = parseFloat(value); var scale = parseFloat(value);
this.currentScaleValue = value;
if (scale) { if (scale) {
this.setScale(scale, true); this.setScale(scale, true);
return; return;
@ -187,6 +192,10 @@ var PDFView = {
this.setScale( this.setScale(
Math.min(pageWidthScale, pageHeightScale), resetAutoSettings); Math.min(pageWidthScale, pageHeightScale), resetAutoSettings);
} }
if ('auto' == value)
this.setScale(Math.min(1.0, pageWidthScale), resetAutoSettings);
selectScaleOption(value);
}, },
zoomIn: function pdfViewZoomIn() { zoomIn: function pdfViewZoomIn() {
@ -428,6 +437,10 @@ var PDFView = {
this.switchSidebarView('outline'); this.switchSidebarView('outline');
} }
// Reset the current scale, as otherwise the page's scale might not get
// updated if the zoom level stayed the same.
this.currentScale = 0;
this.currentScaleValue = null;
if (this.initialBookmark) { if (this.initialBookmark) {
this.setHash(this.initialBookmark); this.setHash(this.initialBookmark);
this.initialBookmark = null; this.initialBookmark = null;
@ -435,7 +448,7 @@ var PDFView = {
else if (storedHash) else if (storedHash)
this.setHash(storedHash); this.setHash(storedHash);
else { else {
this.setScale(scale || kDefaultScale, true); this.parseScale(scale || kDefaultScale, true);
this.page = 1; this.page = 1;
} }
}, },
@ -463,8 +476,16 @@ var PDFView = {
if ('zoom' in params) { if ('zoom' in params) {
var zoomArgs = params.zoom.split(','); // scale,left,top var zoomArgs = params.zoom.split(','); // scale,left,top
// building destination array // building destination array
// If the zoom value, it has to get divided by 100. If it is a string,
// it should stay as it is.
var zoomArg = zoomArgs[0];
var zoomArgNumber = parseFloat(zoomArg);
if (zoomArgNumber)
zoomArg = zoomArgNumber / 100;
var dest = [null, {name: 'XYZ'}, (zoomArgs[1] | 0), var dest = [null, {name: 'XYZ'}, (zoomArgs[1] | 0),
(zoomArgs[2] | 0), (zoomArgs[0] | 0) / 100]; (zoomArgs[2] | 0), zoomArg];
var currentPage = this.pages[pageNumber - 1]; var currentPage = this.pages[pageNumber - 1];
currentPage.scrollIntoView(dest); currentPage.scrollIntoView(dest);
} else } else
@ -917,7 +938,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
params[unescape(param[0])] = unescape(param[1]); params[unescape(param[0])] = unescape(param[1]);
} }
var scale = ('scale' in params) ? params.scale : kDefaultScale; var scale = ('scale' in params) ? params.scale : 0;
PDFView.open(params.file || kDefaultURL, parseFloat(scale)); PDFView.open(params.file || kDefaultURL, parseFloat(scale));
if (!window.File || !window.FileReader || !window.FileList || !window.Blob) if (!window.File || !window.FileReader || !window.FileList || !window.Blob)
@ -952,10 +973,15 @@ function updateViewarea() {
PDFView.page = firstPage.id; PDFView.page = firstPage.id;
updateViewarea.inProgress = false; updateViewarea.inProgress = false;
var currentScale = PDFView.currentScale;
var currentScaleValue = PDFView.currentScaleValue;
var normalizedScaleValue = currentScaleValue == currentScale ?
currentScale * 100 : currentScaleValue;
var kViewerTopMargin = 52; var kViewerTopMargin = 52;
var pageNumber = firstPage.id; var pageNumber = firstPage.id;
var pdfOpenParams = '#page=' + pageNumber; var pdfOpenParams = '#page=' + pageNumber;
pdfOpenParams += '&zoom=' + Math.round(PDFView.currentScale * 100); pdfOpenParams += '&zoom=' + normalizedScaleValue;
var currentPage = PDFView.pages[pageNumber - 1]; var currentPage = PDFView.pages[pageNumber - 1];
var topLeft = currentPage.getPagePoint(window.pageXOffset, var topLeft = currentPage.getPagePoint(window.pageXOffset,
window.pageYOffset - firstPage.y - kViewerTopMargin); window.pageYOffset - firstPage.y - kViewerTopMargin);
@ -964,7 +990,7 @@ function updateViewarea() {
var store = PDFView.store; var store = PDFView.store;
store.set('exists', true); store.set('exists', true);
store.set('page', pageNumber); store.set('page', pageNumber);
store.set('zoom', Math.round(PDFView.currentScale * 100)); store.set('zoom', normalizedScaleValue);
store.set('scrollLeft', Math.round(topLeft.x)); store.set('scrollLeft', Math.round(topLeft.x));
store.set('scrollTop', Math.round(topLeft.y)); store.set('scrollTop', Math.round(topLeft.y));
@ -1000,7 +1026,8 @@ window.addEventListener('webkitTransitionEnd', updateThumbViewArea, true);
window.addEventListener('resize', function webViewerResize(evt) { window.addEventListener('resize', function webViewerResize(evt) {
if (document.getElementById('pageWidthOption').selected || if (document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected) document.getElementById('pageFitOption').selected ||
document.getElementById('pageAutoOption').selected)
PDFView.parseScale(document.getElementById('scaleSelect').value); PDFView.parseScale(document.getElementById('scaleSelect').value);
updateViewarea(); updateViewarea();
}); });
@ -1037,20 +1064,9 @@ window.addEventListener('change', function webViewerChange(evt) {
document.getElementById('download').setAttribute('hidden', 'true'); document.getElementById('download').setAttribute('hidden', 'true');
}, true); }, true);
window.addEventListener('scalechange', function scalechange(evt) { function selectScaleOption(value) {
var customScaleOption = document.getElementById('customScaleOption');
customScaleOption.selected = false;
if (!evt.resetAutoSettings &&
(document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected)) {
updateViewarea();
return;
}
var options = document.getElementById('scaleSelect').options; var options = document.getElementById('scaleSelect').options;
var predefinedValueFound = false; var predefinedValueFound = false;
var value = '' + evt.scale;
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
var option = options[i]; var option = options[i];
if (option.value != value) { if (option.value != value) {
@ -1060,7 +1076,22 @@ window.addEventListener('scalechange', function scalechange(evt) {
option.selected = true; option.selected = true;
predefinedValueFound = true; predefinedValueFound = true;
} }
return predefinedValueFound;
}
window.addEventListener('scalechange', function scalechange(evt) {
var customScaleOption = document.getElementById('customScaleOption');
customScaleOption.selected = false;
if (!evt.resetAutoSettings &&
(document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected ||
document.getElementById('pageAutoOption').selected)) {
updateViewarea();
return;
}
var predefinedValueFound = selectScaleOption('' + evt.scale);
if (!predefinedValueFound) { if (!predefinedValueFound) {
customScaleOption.textContent = Math.round(evt.scale * 10000) / 100 + '%'; customScaleOption.textContent = Math.round(evt.scale * 10000) / 100 + '%';
customScaleOption.selected = true; customScaleOption.selected = true;