Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mozilla/pdf.js.git into tre…
Browse files Browse the repository at this point in the history
…e-53

Conflicts:
	test/test_manifest.json
  • Loading branch information
notmasteryet committed Jan 5, 2012
2 parents 3533e5a + fbb9acc commit caacd31
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 68 deletions.
56 changes: 10 additions & 46 deletions src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
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.textLayerQueue = [];

if (this.textLayer)
this.textLayer.beginLayout();
},

executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR,
Expand Down Expand Up @@ -322,27 +323,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
endDrawing: function canvasGraphicsEndDrawing() {
this.ctx.restore();

var textLayer = this.textLayer;
if (!textLayer)
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);
if (this.textLayer)
this.textLayer.endLayout();
},

// Graphics state
Expand Down Expand Up @@ -634,24 +616,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
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) {
var ctx = this.ctx;
var current = this.current;
Expand Down Expand Up @@ -751,7 +715,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {

width += charWidth;

text.str += glyph.unicode === ' ' ? ' ' : glyph.unicode;
text.str += glyph.unicode === ' ' ? '\u00A0' : glyph.unicode;
text.length++;
text.canvasWidth += charWidth;
}
Expand All @@ -760,7 +724,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}

if (textSelection)
this.pushTextDivs(text);
this.textLayer.appendText(text, font.loadedName, fontSize);

return text;
},
Expand Down Expand Up @@ -803,7 +767,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (e < 0 && text.geom.spaceWidth > 0) { // avoid div by zero
var numFakeSpaces = Math.round(-e / text.geom.spaceWidth);
if (numFakeSpaces > 0) {
text.str += '&nbsp;';
text.str += '\u00A0';
text.length++;
}
}
Expand All @@ -813,7 +777,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {

if (textSelection) {
if (shownText.str === ' ') {
text.str += '&nbsp;';
text.str += '\u00A0';
} else {
text.str += shownText.str;
}
Expand All @@ -826,7 +790,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}

if (textSelection)
this.pushTextDivs(text);
this.textLayer.appendText(text, font.loadedName, fontSize);
},
nextLineShowText: function canvasGraphicsNextLineShowText(text) {
this.nextLine();
Expand Down
18 changes: 9 additions & 9 deletions src/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,10 +1856,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
// values. The first array element indicates whether a valid code is being
// returned. The second array element is the actual code. The third array
// element indicates whether EOF was reached.
var findTableCode = function ccittFaxStreamFindTableCode(start, end, table,
limit) {
var limitValue = limit || 0;
CCITTFaxStream.prototype.findTableCode =
function ccittFaxStreamFindTableCode(start, end, table, limit) {

var limitValue = limit || 0;
for (var i = start; i <= end; ++i) {
var code = this.lookBits(i);
if (code == EOF)
Expand Down Expand Up @@ -1890,7 +1890,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1];
}
} else {
var result = findTableCode(1, 7, twoDimTable);
var result = this.findTableCode(1, 7, twoDimTable);
if (result[0] && result[2])
return result[1];
}
Expand Down Expand Up @@ -1919,11 +1919,11 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1];
}
} else {
var result = findTableCode(1, 9, whiteTable2);
var result = this.findTableCode(1, 9, whiteTable2);
if (result[0])
return result[1];

result = findTableCode(11, 12, whiteTable1);
result = this.findTableCode(11, 12, whiteTable1);
if (result[0])
return result[1];
}
Expand Down Expand Up @@ -1952,15 +1952,15 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
return p[1];
}
} else {
var result = findTableCode(2, 6, blackTable3);
var result = this.findTableCode(2, 6, blackTable3);
if (result[0])
return result[1];

result = findTableCode(7, 12, blackTable2, 64);
result = this.findTableCode(7, 12, blackTable2, 64);
if (result[0])
return result[1];

result = findTableCode(10, 13, blackTable1);
result = this.findTableCode(10, 13, blackTable1);
if (result[0])
return result[1];
}
Expand Down
11 changes: 8 additions & 3 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ function nextPage(task, loadError) {
canvas.height = pageHeight * pdfToCssUnitsCoef;
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
var textLayer = document.createElement('div');
var textLayerBuilder = {
beginLayout: function nullTextLayerBuilderBeginLayout() {},
endLayout: function nullTextLayerBuilderEndLayout() {},
appendText: function nullTextLayerBuilderAppendText(text, fontName,
fontSize) {}
};

page.startRendering(
ctx,
Expand All @@ -177,7 +182,7 @@ function nextPage(task, loadError) {
failureMessage = 'render : ' + error.message;
snapshotCurrentPage(task, failureMessage);
},
textLayer
textLayerBuilder
);
} catch (e) {
failure = 'page setup : ' + e.toString();
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue1015.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://faculty.washington.edu/fidelr/RayaPubs/TheCaseStudyMethod.pdf
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,12 @@
"rounds": 1,
"link": true,
"type": "load"
},
{ "id": "issue1015",
"file": "pdfs/issue1015.pdf",
"md5": "b61503d1b445742b665212866afb60e2",
"rounds": 1,
"link": true,
"type": "eq"
}
]
2 changes: 1 addition & 1 deletion web/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

function subarray(start, end) {
return this.slice(start, end);
return new TypedArray(this.slice(start, end));
}

function setArrayOffset(array, offset) {
Expand Down
5 changes: 4 additions & 1 deletion web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ body {
/* === Toolbar === */
#controls {
background-color: #eee;
background: -o-linear-gradient(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));
border-bottom: 1px solid #666;
Expand Down Expand Up @@ -82,6 +83,7 @@ span#info {
bottom: 18px;
left: -290px;
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;
-webkit-transition: left 0.25s ease-in-out 1s;
z-index: 1;
Expand All @@ -90,6 +92,7 @@ span#info {
#sidebar:hover {
left: 0px;
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;
-webkit-transition: left 0.25s ease-in-out 0s;
}
Expand Down Expand Up @@ -327,7 +330,7 @@ canvas {
color: black;
padding: 3px;
margin: 3px;
white-space: pre;
width: 98%;
}

.clearBoth {
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</button>
</div>
<div class="clearBoth"></div>
<div id="errorMoreInfo" hidden='true'></div>
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
</div>

<div id="sidebar">
Expand Down
67 changes: 60 additions & 7 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,14 @@ var PDFView = {
};
moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true');
errorMoreInfo.innerHTML = 'PDF.JS Build: ' + PDFJS.build + '\n';
errorMoreInfo.value = 'PDF.JS Build: ' + PDFJS.build + '\n';

if (moreInfo) {
errorMoreInfo.innerHTML += 'Message: ' + moreInfo.message;
errorMoreInfo.value += 'Message: ' + moreInfo.message;
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) {
Expand Down Expand Up @@ -437,14 +438,18 @@ var PDFView = {
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) {
this.setHash(this.initialBookmark);
this.initialBookmark = null;
}
else if (storedHash)
this.setHash(storedHash);
else {
this.setScale(scale || kDefaultScale, true);
this.parseScale(scale || kDefaultScale, true);
this.page = 1;
}
},
Expand Down Expand Up @@ -794,7 +799,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,

cache.push(this);
callback();
}).bind(this), textLayer
}).bind(this), new TextLayerBuilder(textLayer)
);

setupAnnotations(this.content, this.scale);
Expand Down Expand Up @@ -927,14 +932,61 @@ 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) {
var params = document.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var param = params[i].split('=');
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));

if (!window.File || !window.FileReader || !window.FileList || !window.Blob)
Expand Down Expand Up @@ -1081,7 +1133,8 @@ window.addEventListener('scalechange', function scalechange(evt) {

if (!evt.resetAutoSettings &&
(document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected)) {
document.getElementById('pageFitOption').selected ||
document.getElementById('pageAutoOption').selected)) {
updateViewarea();
return;
}
Expand Down

0 comments on commit caacd31

Please sign in to comment.