Merge branch 'master' into faxstream
This commit is contained in:
commit
25c27cbda1
@ -26,41 +26,53 @@ var PDFViewer = {
|
|||||||
|
|
||||||
scale: 1.0,
|
scale: 1.0,
|
||||||
|
|
||||||
pageWidth: function() {
|
pageWidth: function(page) {
|
||||||
return 816 * PDFViewer.scale;
|
return page.mediaBox[2] * PDFViewer.scale;
|
||||||
},
|
},
|
||||||
|
|
||||||
pageHeight: function() {
|
pageHeight: function(page) {
|
||||||
return 1056 * PDFViewer.scale;
|
return page.mediaBox[3] * PDFViewer.scale;
|
||||||
},
|
},
|
||||||
|
|
||||||
lastPagesDrawn: [],
|
lastPagesDrawn: [],
|
||||||
|
|
||||||
visiblePages: function() {
|
visiblePages: function() {
|
||||||
var pageHeight = PDFViewer.pageHeight() + 20; // Add 20 for the margins.
|
const pageBottomMargin = 20;
|
||||||
var windowTop = window.pageYOffset;
|
var windowTop = window.pageYOffset;
|
||||||
var windowBottom = window.pageYOffset + window.innerHeight;
|
var windowBottom = window.pageYOffset + window.innerHeight;
|
||||||
var pageStartIndex = Math.floor(windowTop / pageHeight);
|
|
||||||
var pageStopIndex = Math.ceil(windowBottom / pageHeight);
|
var pageHeight, page;
|
||||||
|
var i, n = PDFViewer.numberOfPages, currentHeight = 0;
|
||||||
|
for (i = 1; i <= n; i++) {
|
||||||
|
var page = PDFViewer.pdf.getPage(i);
|
||||||
|
pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin;
|
||||||
|
if (currentHeight + pageHeight > windowTop)
|
||||||
|
break;
|
||||||
|
currentHeight += pageHeight;
|
||||||
|
}
|
||||||
|
|
||||||
var pages = [];
|
var pages = [];
|
||||||
|
for (; i <= n && currentHeight < windowBottom; i++) {
|
||||||
for (var i = pageStartIndex; i <= pageStopIndex; i++) {
|
var page = PDFViewer.pdf.getPage(i);
|
||||||
pages.push(i + 1);
|
pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin;
|
||||||
|
currentHeight += pageHeight;
|
||||||
|
pages.push(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
},
|
},
|
||||||
|
|
||||||
createPage: function(num) {
|
createPage: function(num) {
|
||||||
|
var page = PDFViewer.pdf.getPage(num);
|
||||||
|
|
||||||
var anchor = document.createElement('a');
|
var anchor = document.createElement('a');
|
||||||
anchor.name = '' + num;
|
anchor.name = '' + num;
|
||||||
|
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
div.id = 'pageContainer' + num;
|
div.id = 'pageContainer' + num;
|
||||||
div.className = 'page';
|
div.className = 'page';
|
||||||
div.style.width = PDFViewer.pageWidth() + 'px';
|
div.style.width = PDFViewer.pageWidth(page) + 'px';
|
||||||
div.style.height = PDFViewer.pageHeight() + 'px';
|
div.style.height = PDFViewer.pageHeight(page) + 'px';
|
||||||
|
|
||||||
PDFViewer.element.appendChild(anchor);
|
PDFViewer.element.appendChild(anchor);
|
||||||
PDFViewer.element.appendChild(div);
|
PDFViewer.element.appendChild(div);
|
||||||
@ -91,8 +103,8 @@ var PDFViewer = {
|
|||||||
|
|
||||||
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
||||||
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
||||||
canvas.width = PDFViewer.pageWidth();
|
canvas.width = PDFViewer.pageWidth(page);
|
||||||
canvas.height = PDFViewer.pageHeight();
|
canvas.height = PDFViewer.pageHeight(page);
|
||||||
div.appendChild(canvas);
|
div.appendChild(canvas);
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
72
pdf.js
72
pdf.js
@ -3081,30 +3081,6 @@ var PDFDoc = (function() {
|
|||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ];
|
|
||||||
|
|
||||||
// <canvas> contexts store most of the state we need natively.
|
|
||||||
// However, PDF needs a bit more state, which we store here.
|
|
||||||
var CanvasExtraState = (function() {
|
|
||||||
function constructor() {
|
|
||||||
// Are soft masks and alpha values shapes or opacities?
|
|
||||||
this.alphaIsShape = false;
|
|
||||||
this.fontSize = 0.0;
|
|
||||||
this.textMatrix = IDENTITY_MATRIX;
|
|
||||||
this.leading = 0.0;
|
|
||||||
this.colorSpace = null;
|
|
||||||
// Current point (in user coordinates)
|
|
||||||
this.x = 0.0;
|
|
||||||
this.y = 0.0;
|
|
||||||
// Start of text line (in text coordinates)
|
|
||||||
this.lineX = 0.0;
|
|
||||||
this.lineY = 0.0;
|
|
||||||
}
|
|
||||||
constructor.prototype = {
|
|
||||||
};
|
|
||||||
return constructor;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var Encodings = {
|
var Encodings = {
|
||||||
get ExpertEncoding() {
|
get ExpertEncoding() {
|
||||||
return shadow(this, "ExpertEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
return shadow(this, "ExpertEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||||
@ -3279,6 +3255,34 @@ var Encodings = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ];
|
||||||
|
|
||||||
|
// <canvas> contexts store most of the state we need natively.
|
||||||
|
// However, PDF needs a bit more state, which we store here.
|
||||||
|
var CanvasExtraState = (function() {
|
||||||
|
function constructor() {
|
||||||
|
// Are soft masks and alpha values shapes or opacities?
|
||||||
|
this.alphaIsShape = false;
|
||||||
|
this.fontSize = 0;
|
||||||
|
this.textMatrix = IDENTITY_MATRIX;
|
||||||
|
this.leading = 0;
|
||||||
|
this.colorSpace = null;
|
||||||
|
// Current point (in user coordinates)
|
||||||
|
this.x = 0;
|
||||||
|
this.y = 0;
|
||||||
|
// Start of text line (in text coordinates)
|
||||||
|
this.lineX = 0;
|
||||||
|
this.lineY = 0;
|
||||||
|
// Character and word spacing
|
||||||
|
this.charSpace = 0;
|
||||||
|
this.wordSpace = 0;
|
||||||
|
this.textHScale = 100;
|
||||||
|
}
|
||||||
|
constructor.prototype = {
|
||||||
|
};
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
function ScratchCanvas(width, height) {
|
function ScratchCanvas(width, height) {
|
||||||
var canvas = document.createElement("canvas");
|
var canvas = document.createElement("canvas");
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
@ -3777,13 +3781,13 @@ var CanvasGraphics = (function() {
|
|||||||
endText: function() {
|
endText: function() {
|
||||||
},
|
},
|
||||||
setCharSpacing: function(spacing) {
|
setCharSpacing: function(spacing) {
|
||||||
TODO("character (glyph?) spacing");
|
this.ctx.charSpacing = spacing;
|
||||||
},
|
},
|
||||||
setWordSpacing: function(spacing) {
|
setWordSpacing: function(spacing) {
|
||||||
TODO("word spacing");
|
this.ctx.wordSpacing = spacing;
|
||||||
},
|
},
|
||||||
setHScale: function(scale) {
|
setHScale: function(scale) {
|
||||||
TODO("horizontal text scale");
|
this.ctx.textHScale = (scale % 100) * 0.01;
|
||||||
},
|
},
|
||||||
setLeading: function(leading) {
|
setLeading: function(leading) {
|
||||||
this.current.leading = leading;
|
this.current.leading = leading;
|
||||||
@ -3846,6 +3850,8 @@ var CanvasGraphics = (function() {
|
|||||||
this.moveText(0, this.current.leading);
|
this.moveText(0, this.current.leading);
|
||||||
},
|
},
|
||||||
showText: function(text) {
|
showText: function(text) {
|
||||||
|
// TODO: apply charSpacing, wordSpacing, textHScale
|
||||||
|
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
||||||
this.ctx.scale(1, -1);
|
this.ctx.scale(1, -1);
|
||||||
@ -4008,10 +4014,14 @@ var CanvasGraphics = (function() {
|
|||||||
// we want the canvas to be as large as the step size
|
// we want the canvas to be as large as the step size
|
||||||
var botRight = applyMatrix([x0 + xstep, y0 + ystep], matrix);
|
var botRight = applyMatrix([x0 + xstep, y0 + ystep], matrix);
|
||||||
|
|
||||||
var tmpCanvas = new this.ScratchCanvas(
|
var width = botRight[0] - topLeft[0];
|
||||||
Math.ceil(botRight[0] - topLeft[0]), // width
|
var height = botRight[1] - topLeft[1];
|
||||||
Math.ceil(botRight[1] - topLeft[1]) // height
|
|
||||||
);
|
// TODO: hack to avoid OOM, remove then pattern code is fixed
|
||||||
|
if (Math.abs(width) > 8192 || Math.abs(height) > 8192)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var tmpCanvas = new this.ScratchCanvas(width, height);
|
||||||
|
|
||||||
// set the new canvas element context as the graphics context
|
// set the new canvas element context as the graphics context
|
||||||
var tmpCtx = tmpCanvas.getContext("2d");
|
var tmpCtx = tmpCanvas.getContext("2d");
|
||||||
|
BIN
test/pdfs/sizes.pdf
Normal file
BIN
test/pdfs/sizes.pdf
Normal file
Binary file not shown.
@ -34,3 +34,5 @@ user_pref("dom.w3c_touch_events.enabled", true);
|
|||||||
user_pref("extensions.checkCompatibility", false);
|
user_pref("extensions.checkCompatibility", false);
|
||||||
user_pref("extensions.installDistroAddons", false); // prevent testpilot etc
|
user_pref("extensions.installDistroAddons", false); // prevent testpilot etc
|
||||||
user_pref("browser.safebrowsing.enable", false); // prevent traffic to google servers
|
user_pref("browser.safebrowsing.enable", false); // prevent traffic to google servers
|
||||||
|
user_pref("toolkit.telemetry.prompted", true); // prevent telemetry banner
|
||||||
|
user_pref("toolkit.telemetry.enabled", false);
|
||||||
|
@ -37,6 +37,8 @@ class TestOptions(OptionParser):
|
|||||||
options.manifestFile = DEFAULT_MANIFEST_FILE
|
options.manifestFile = DEFAULT_MANIFEST_FILE
|
||||||
if options.browser and options.browserManifestFile:
|
if options.browser and options.browserManifestFile:
|
||||||
print "Warning: ignoring browser argument since manifest file was also supplied"
|
print "Warning: ignoring browser argument since manifest file was also supplied"
|
||||||
|
if not options.browser and not options.browserManifestFile:
|
||||||
|
self.error("No test browsers found. Use --browserManifest or --browser args.")
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def prompt(question):
|
def prompt(question):
|
||||||
@ -220,8 +222,7 @@ def setUp(options):
|
|||||||
testBrowsers = makeBrowserCommands(options.browserManifestFile)
|
testBrowsers = makeBrowserCommands(options.browserManifestFile)
|
||||||
elif options.browser:
|
elif options.browser:
|
||||||
testBrowsers = [BrowserCommand({"path":options.browser, "name":"firefox"})]
|
testBrowsers = [BrowserCommand({"path":options.browser, "name":"firefox"})]
|
||||||
else:
|
assert len(testBrowsers) > 0
|
||||||
print "No test browsers found. Use --browserManifest or --browser args."
|
|
||||||
|
|
||||||
with open(options.manifestFile) as mf:
|
with open(options.manifestFile) as mf:
|
||||||
manifestList = json.load(mf)
|
manifestList = json.load(mf)
|
||||||
@ -415,6 +416,7 @@ def processResults():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
t1 = time.time()
|
||||||
optionParser = TestOptions()
|
optionParser = TestOptions()
|
||||||
options, args = optionParser.parse_args()
|
options, args = optionParser.parse_args()
|
||||||
options = optionParser.verifyOptions(options)
|
options = optionParser.verifyOptions(options)
|
||||||
@ -434,6 +436,8 @@ def main():
|
|||||||
processResults()
|
processResults()
|
||||||
finally:
|
finally:
|
||||||
teardownBrowsers(browsers)
|
teardownBrowsers(browsers)
|
||||||
|
t2 = time.time()
|
||||||
|
print "Runtime was", int(t2 - t1), "seconds"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -25,5 +25,10 @@
|
|||||||
"link": true,
|
"link": true,
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "load"
|
"type": "load"
|
||||||
|
},
|
||||||
|
{ "id": "sizes",
|
||||||
|
"file": "pdfs/sizes.pdf",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -25,9 +25,6 @@ function load() {
|
|||||||
manifestFile = params.manifestFile;
|
manifestFile = params.manifestFile;
|
||||||
|
|
||||||
canvas = document.createElement("canvas");
|
canvas = document.createElement("canvas");
|
||||||
// 8.5x11in @ 100% ... XXX need something better here
|
|
||||||
canvas.width = 816;
|
|
||||||
canvas.height = 1056;
|
|
||||||
canvas.mozOpaque = true;
|
canvas.mozOpaque = true;
|
||||||
stdout = document.getElementById("stdout");
|
stdout = document.getElementById("stdout");
|
||||||
|
|
||||||
@ -93,7 +90,6 @@ function nextPage() {
|
|||||||
log(" loading page "+ currentTask.pageNum +"... ");
|
log(" loading page "+ currentTask.pageNum +"... ");
|
||||||
|
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
clear(ctx);
|
|
||||||
|
|
||||||
var fonts = [];
|
var fonts = [];
|
||||||
var gfx = null;
|
var gfx = null;
|
||||||
@ -105,6 +101,15 @@ function nextPage() {
|
|||||||
failure = 'compile: '+ e.toString();
|
failure = 'compile: '+ e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// using mediaBox for the canvas size
|
||||||
|
canvas.width = currentPage.mediaBox[2];
|
||||||
|
canvas.height = currentPage.mediaBox[3];
|
||||||
|
clear(ctx);
|
||||||
|
} catch(e) {
|
||||||
|
failure = 'page setup: '+ e.toString();
|
||||||
|
}
|
||||||
|
|
||||||
var fontLoaderTimer = null;
|
var fontLoaderTimer = null;
|
||||||
function checkFontsLoaded() {
|
function checkFontsLoaded() {
|
||||||
try {
|
try {
|
||||||
@ -193,16 +198,22 @@ function sendTaskResult(snapshot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clear(ctx) {
|
function clear(ctx) {
|
||||||
var ctx = canvas.getContext("2d");
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Auto-scroll if the scrollbar is near the bottom, otherwise do nothing. */
|
||||||
|
function checkScrolling() {
|
||||||
|
if ((stdout.scrollHeight - stdout.scrollTop) <= stdout.offsetHeight) {
|
||||||
|
stdout.scrollTop = stdout.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function log(str) {
|
function log(str) {
|
||||||
stdout.innerHTML += str;
|
stdout.innerHTML += str;
|
||||||
window.scrollTo(0, stdout.getBoundingClientRect().bottom);
|
checkScrolling();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -60,6 +60,10 @@ function displayPage(num) {
|
|||||||
|
|
||||||
var page = pdfDocument.getPage(pageNum = num);
|
var page = pdfDocument.getPage(pageNum = num);
|
||||||
|
|
||||||
|
// scale canvas by 2
|
||||||
|
canvas.width = 2 * page.mediaBox[2];
|
||||||
|
canvas.hieght = 2 * page.mediaBox[3];
|
||||||
|
|
||||||
var t1 = Date.now();
|
var t1 = Date.now();
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
Loading…
Reference in New Issue
Block a user