Merge branch 'master' of git://github.com/mozilla/pdf.js.git into tree-53

Conflicts:
	test/test_manifest.json
This commit is contained in:
notmasteryet 2012-01-04 19:57:08 -06:00
commit caacd31a2c
9 changed files with 101 additions and 68 deletions

View File

@ -257,8 +257,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
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 // Move the media left-top corner to the (0,0) canvas position
this.ctx.translate(-mediaBox.x, -mediaBox.y); this.ctx.translate(-mediaBox.x, -mediaBox.y);
this.textDivs = [];
this.textLayerQueue = []; if (this.textLayer)
this.textLayer.beginLayout();
}, },
executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR, executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR,
@ -322,27 +323,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
endDrawing: function canvasGraphicsEndDrawing() { endDrawing: function canvasGraphicsEndDrawing() {
this.ctx.restore(); this.ctx.restore();
var textLayer = this.textLayer; if (this.textLayer)
if (!textLayer) this.textLayer.endLayout();
return;
var self = this;
var textDivs = this.textDivs;
this.textLayerTimer = setInterval(function renderTextLayer() {
if (textDivs.length === 0) {
clearInterval(self.textLayerTimer);
return;
}
var textDiv = textDivs.shift();
if (textDiv.dataset.textLength > 1) { // avoid div by zero
textLayer.appendChild(textDiv);
// Adjust div width (via letterSpacing) to match canvas text
// Due to the .offsetWidth calls, this is slow
textDiv.style.letterSpacing =
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) /
(textDiv.dataset.textLength - 1)) + 'px';
}
}, 0);
}, },
// Graphics state // Graphics state
@ -634,24 +616,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return geometry; return geometry;
}, },
pushTextDivs: function canvasGraphicsPushTextDivs(text) {
var div = document.createElement('div');
var fontSize = this.current.fontSize;
// vScale and hScale already contain the scaling to pixel units
// as mozCurrentTransform reflects ctx.scale() changes
// (see beginDrawing())
var fontHeight = fontSize * text.geom.vScale;
div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
div.style.fontSize = fontHeight + 'px';
div.style.fontFamily = this.current.font.loadedName || 'sans-serif';
div.style.left = text.geom.x + 'px';
div.style.top = (text.geom.y - fontHeight) + 'px';
div.innerHTML = text.str;
div.dataset.textLength = text.length;
this.textDivs.push(div);
},
showText: function canvasGraphicsShowText(str, skipTextSelection) { showText: function canvasGraphicsShowText(str, skipTextSelection) {
var ctx = this.ctx; var ctx = this.ctx;
var current = this.current; var current = this.current;
@ -751,7 +715,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
width += charWidth; width += charWidth;
text.str += glyph.unicode === ' ' ? ' ' : glyph.unicode; text.str += glyph.unicode === ' ' ? '\u00A0' : glyph.unicode;
text.length++; text.length++;
text.canvasWidth += charWidth; text.canvasWidth += charWidth;
} }
@ -760,7 +724,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} }
if (textSelection) if (textSelection)
this.pushTextDivs(text); this.textLayer.appendText(text, font.loadedName, fontSize);
return text; return text;
}, },
@ -803,7 +767,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (e < 0 && text.geom.spaceWidth > 0) { // avoid div by zero if (e < 0 && text.geom.spaceWidth > 0) { // avoid div by zero
var numFakeSpaces = Math.round(-e / text.geom.spaceWidth); var numFakeSpaces = Math.round(-e / text.geom.spaceWidth);
if (numFakeSpaces > 0) { if (numFakeSpaces > 0) {
text.str += '&nbsp;'; text.str += '\u00A0';
text.length++; text.length++;
} }
} }
@ -813,7 +777,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (textSelection) { if (textSelection) {
if (shownText.str === ' ') { if (shownText.str === ' ') {
text.str += '&nbsp;'; text.str += '\u00A0';
} else { } else {
text.str += shownText.str; text.str += shownText.str;
} }
@ -826,7 +790,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} }
if (textSelection) if (textSelection)
this.pushTextDivs(text); this.textLayer.appendText(text, font.loadedName, fontSize);
}, },
nextLineShowText: function canvasGraphicsNextLineShowText(text) { nextLineShowText: function canvasGraphicsNextLineShowText(text) {
this.nextLine(); this.nextLine();

View File

@ -1856,10 +1856,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
// values. The first array element indicates whether a valid code is being // values. The first array element indicates whether a valid code is being
// returned. The second array element is the actual code. The third array // returned. The second array element is the actual code. The third array
// element indicates whether EOF was reached. // element indicates whether EOF was reached.
var findTableCode = function ccittFaxStreamFindTableCode(start, end, table, CCITTFaxStream.prototype.findTableCode =
limit) { function ccittFaxStreamFindTableCode(start, end, table, limit) {
var limitValue = limit || 0;
var limitValue = limit || 0;
for (var i = start; i <= end; ++i) { for (var i = start; i <= end; ++i) {
var code = this.lookBits(i); var code = this.lookBits(i);
if (code == EOF) if (code == EOF)
@ -1890,7 +1890,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1]; return p[1];
} }
} else { } else {
var result = findTableCode(1, 7, twoDimTable); var result = this.findTableCode(1, 7, twoDimTable);
if (result[0] && result[2]) if (result[0] && result[2])
return result[1]; return result[1];
} }
@ -1919,11 +1919,11 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1]; return p[1];
} }
} else { } else {
var result = findTableCode(1, 9, whiteTable2); var result = this.findTableCode(1, 9, whiteTable2);
if (result[0]) if (result[0])
return result[1]; return result[1];
result = findTableCode(11, 12, whiteTable1); result = this.findTableCode(11, 12, whiteTable1);
if (result[0]) if (result[0])
return result[1]; return result[1];
} }
@ -1952,15 +1952,15 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1]; return p[1];
} }
} else { } else {
var result = findTableCode(2, 6, blackTable3); var result = this.findTableCode(2, 6, blackTable3);
if (result[0]) if (result[0])
return result[1]; return result[1];
result = findTableCode(7, 12, blackTable2, 64); result = this.findTableCode(7, 12, blackTable2, 64);
if (result[0]) if (result[0])
return result[1]; return result[1];
result = findTableCode(10, 13, blackTable1); result = this.findTableCode(10, 13, blackTable1);
if (result[0]) if (result[0])
return result[1]; return result[1];
} }

View File

@ -165,9 +165,14 @@ function nextPage(task, loadError) {
canvas.height = pageHeight * pdfToCssUnitsCoef; canvas.height = pageHeight * pdfToCssUnitsCoef;
clear(ctx); clear(ctx);
// using non-attached to the document div to test // using the text layer builder that does nothing to test
// text layer creation operations // text layer creation operations
var textLayer = document.createElement('div'); var textLayerBuilder = {
beginLayout: function nullTextLayerBuilderBeginLayout() {},
endLayout: function nullTextLayerBuilderEndLayout() {},
appendText: function nullTextLayerBuilderAppendText(text, fontName,
fontSize) {}
};
page.startRendering( page.startRendering(
ctx, ctx,
@ -177,7 +182,7 @@ function nextPage(task, loadError) {
failureMessage = 'render : ' + error.message; failureMessage = 'render : ' + error.message;
snapshotCurrentPage(task, failureMessage); snapshotCurrentPage(task, failureMessage);
}, },
textLayer textLayerBuilder
); );
} catch (e) { } catch (e) {
failure = 'page setup : ' + e.toString(); failure = 'page setup : ' + e.toString();

View File

@ -0,0 +1 @@
http://faculty.washington.edu/fidelr/RayaPubs/TheCaseStudyMethod.pdf

View File

@ -388,5 +388,12 @@
"rounds": 1, "rounds": 1,
"link": true, "link": true,
"type": "load" "type": "load"
},
{ "id": "issue1015",
"file": "pdfs/issue1015.pdf",
"md5": "b61503d1b445742b665212866afb60e2",
"rounds": 1,
"link": true,
"type": "eq"
} }
] ]

View File

@ -14,7 +14,7 @@
} }
function subarray(start, end) { function subarray(start, end) {
return this.slice(start, end); return new TypedArray(this.slice(start, end));
} }
function setArrayOffset(array, offset) { function setArrayOffset(array, offset) {

View File

@ -15,6 +15,7 @@ body {
/* === Toolbar === */ /* === Toolbar === */
#controls { #controls {
background-color: #eee; background-color: #eee;
background: -o-linear-gradient(bottom,#eee 0%,#fff 100%);
background: -moz-linear-gradient(center bottom, #eee 0%, #fff 100%); background: -moz-linear-gradient(center bottom, #eee 0%, #fff 100%);
background: -webkit-gradient(linear, left bottom, left top, color-stop(0.0, #ddd), color-stop(1.0, #fff)); background: -webkit-gradient(linear, left bottom, left top, color-stop(0.0, #ddd), color-stop(1.0, #fff));
border-bottom: 1px solid #666; border-bottom: 1px solid #666;
@ -82,6 +83,7 @@ span#info {
bottom: 18px; bottom: 18px;
left: -290px; left: -290px;
transition: left 0.25s ease-in-out 1s; transition: left 0.25s ease-in-out 1s;
-o-transition: left 0.25s ease-in-out 1s;
-moz-transition: left 0.25s ease-in-out 1s; -moz-transition: left 0.25s ease-in-out 1s;
-webkit-transition: left 0.25s ease-in-out 1s; -webkit-transition: left 0.25s ease-in-out 1s;
z-index: 1; z-index: 1;
@ -90,6 +92,7 @@ span#info {
#sidebar:hover { #sidebar:hover {
left: 0px; left: 0px;
transition: left 0.25s ease-in-out 0s; transition: left 0.25s ease-in-out 0s;
-o-transition: left 0.25s ease-in-out 0s;
-moz-transition: left 0.25s ease-in-out 0s; -moz-transition: left 0.25s ease-in-out 0s;
-webkit-transition: left 0.25s ease-in-out 0s; -webkit-transition: left 0.25s ease-in-out 0s;
} }
@ -327,7 +330,7 @@ canvas {
color: black; color: black;
padding: 3px; padding: 3px;
margin: 3px; margin: 3px;
white-space: pre; width: 98%;
} }
.clearBoth { .clearBoth {

View File

@ -114,7 +114,7 @@
</button> </button>
</div> </div>
<div class="clearBoth"></div> <div class="clearBoth"></div>
<div id="errorMoreInfo" hidden='true'></div> <textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
</div> </div>
<div id="sidebar"> <div id="sidebar">

View File

@ -346,13 +346,14 @@ var PDFView = {
}; };
moreInfoButton.removeAttribute('hidden'); moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true'); lessInfoButton.setAttribute('hidden', 'true');
errorMoreInfo.innerHTML = 'PDF.JS Build: ' + PDFJS.build + '\n'; errorMoreInfo.value = 'PDF.JS Build: ' + PDFJS.build + '\n';
if (moreInfo) { if (moreInfo) {
errorMoreInfo.innerHTML += 'Message: ' + moreInfo.message; errorMoreInfo.value += 'Message: ' + moreInfo.message;
if (moreInfo.stack) if (moreInfo.stack)
errorMoreInfo.innerHTML += '\n' + 'Stack: ' + moreInfo.stack; errorMoreInfo.value += '\n' + 'Stack: ' + moreInfo.stack;
} }
errorMoreInfo.rows = errorMoreInfo.value.split('\n').length - 1;
}, },
progress: function pdfViewProgress(level) { progress: function pdfViewProgress(level) {
@ -437,6 +438,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;
@ -444,7 +449,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;
} }
}, },
@ -794,7 +799,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
cache.push(this); cache.push(this);
callback(); callback();
}).bind(this), textLayer }).bind(this), new TextLayerBuilder(textLayer)
); );
setupAnnotations(this.content, this.scale); setupAnnotations(this.content, this.scale);
@ -927,6 +932,53 @@ var DocumentOutlineView = function documentOutlineView(outline) {
} }
}; };
var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
this.textLayerDiv = textLayerDiv;
this.beginLayout = function textLayerBuilderBeginLayout() {
this.textDivs = [];
this.textLayerQueue = [];
};
this.endLayout = function textLayerBuilderEndLayout() {
var self = this;
var textDivs = this.textDivs;
var textLayerDiv = this.textLayerDiv;
this.textLayerTimer = setInterval(function renderTextLayer() {
if (textDivs.length === 0) {
clearInterval(self.textLayerTimer);
return;
}
var textDiv = textDivs.shift();
if (textDiv.dataset.textLength >= 1) { // avoid div by zero
textLayerDiv.appendChild(textDiv);
// Adjust div width (via letterSpacing) to match canvas text
// Due to the .offsetWidth calls, this is slow
textDiv.style.letterSpacing =
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) /
(textDiv.dataset.textLength - 1)) + 'px';
}
}, 0);
};
this.appendText = function textLayerBuilderAppendText(text,
fontName, fontSize) {
var textDiv = document.createElement('div');
// vScale and hScale already contain the scaling to pixel units
var fontHeight = fontSize * text.geom.vScale;
textDiv.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
textDiv.style.fontSize = fontHeight + 'px';
textDiv.style.fontFamily = fontName || 'sans-serif';
textDiv.style.left = text.geom.x + 'px';
textDiv.style.top = (text.geom.y - fontHeight) + 'px';
textDiv.textContent = text.str;
textDiv.dataset.textLength = text.length;
this.textDivs.push(textDiv);
};
};
window.addEventListener('load', function webViewerLoad(evt) { window.addEventListener('load', function webViewerLoad(evt) {
var params = document.location.search.substring(1).split('&'); var params = document.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) { for (var i = 0; i < params.length; i++) {
@ -934,7 +986,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)
@ -1081,7 +1133,8 @@ window.addEventListener('scalechange', function scalechange(evt) {
if (!evt.resetAutoSettings && if (!evt.resetAutoSettings &&
(document.getElementById('pageWidthOption').selected || (document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected)) { document.getElementById('pageFitOption').selected ||
document.getElementById('pageAutoOption').selected)) {
updateViewarea(); updateViewarea();
return; return;
} }