Merge remote branch 'upstream/master'
This commit is contained in:
commit
fdf4db3365
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
BIN
images/source/FileButton.psd.zip
Normal file
BIN
images/source/FileButton.psd.zip
Normal file
Binary file not shown.
@ -27,7 +27,30 @@ span {
|
||||
|
||||
.control > input {
|
||||
float: left;
|
||||
border: 1px solid #4d4d4d;
|
||||
height: 20px;
|
||||
padding: 0px;
|
||||
margin: 0px 2px 0px 0px;
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.control > select {
|
||||
float: left;
|
||||
border: 1px solid #4d4d4d;
|
||||
height: 22px;
|
||||
padding: 2px 0px 0px;
|
||||
margin: 0px 0px 1px;
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.control > span {
|
||||
@ -61,7 +84,7 @@ span {
|
||||
background-color: #eee;
|
||||
border-bottom: 1px solid #666;
|
||||
padding: 4px 0px 0px 8px;
|
||||
position:fixed;
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
height: 40px;
|
||||
@ -79,7 +102,7 @@ span {
|
||||
|
||||
#previousPageButton {
|
||||
background: url('images/buttons.png') no-repeat 0px -23px;
|
||||
cursor: pointer;
|
||||
cursor: default;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin: 0px;
|
||||
@ -97,7 +120,7 @@ span {
|
||||
|
||||
#nextPageButton {
|
||||
background: url('images/buttons.png') no-repeat -28px -23px;
|
||||
cursor: pointer;
|
||||
cursor: default;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin: 0px;
|
||||
@ -113,71 +136,61 @@ span {
|
||||
background: url('images/buttons.png') no-repeat -28px 0px;
|
||||
}
|
||||
|
||||
#scaleComboBoxInput {
|
||||
background: url('images/combobox.png') no-repeat 0px -23px;
|
||||
#openFileButton {
|
||||
background: url('images/buttons.png') no-repeat -56px -23px;
|
||||
cursor: default;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin: 0px;
|
||||
width: 35px;
|
||||
margin: 0px 0px 0px 3px;
|
||||
width: 29px;
|
||||
height: 23px;
|
||||
}
|
||||
|
||||
#scaleComboBoxInput input {
|
||||
background: none;
|
||||
border: 0px;
|
||||
margin: 3px 2px 0px;
|
||||
width: 31px;
|
||||
#openFileButton.down {
|
||||
background: url('images/buttons.png') no-repeat -56px -46px;
|
||||
}
|
||||
|
||||
#scaleComboBoxButton {
|
||||
background: url('images/combobox.png') no-repeat -41px -23px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin: 0px;
|
||||
width: 21px;
|
||||
height: 23px;
|
||||
#openFileButton.disabled {
|
||||
background: url('images/buttons.png') no-repeat -56px 0px;
|
||||
}
|
||||
|
||||
#scaleComboBoxButton.down {
|
||||
background: url('images/combobox.png') no-repeat -41px -46px;
|
||||
}
|
||||
|
||||
#scaleComboBoxButton.disabled {
|
||||
background: url('images/combobox.png') no-repeat -41px 0px;
|
||||
}
|
||||
|
||||
#scaleComboBoxList {
|
||||
background-color: #fff;
|
||||
border: 1px solid #666;
|
||||
clear: both;
|
||||
position: relative;
|
||||
#fileInput {
|
||||
display: none;
|
||||
top: -20px;
|
||||
width: 48px;
|
||||
}
|
||||
|
||||
#scaleComboBoxList > ul {
|
||||
list-style: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
#scaleComboBoxList > ul > li {
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#scaleComboBoxList > ul > li:hover {
|
||||
background-color: #09f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#pageNumber, #scale {
|
||||
#pageNumber {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
position: fixed;
|
||||
width: 150px;
|
||||
top: 62px;
|
||||
bottom: 18px;
|
||||
border-top-right-radius: 8px;
|
||||
border-bottom-right-radius: 8px;
|
||||
-moz-border-radius-topright: 8px;
|
||||
-moz-border-radius-bottomright: 8px;
|
||||
-webkit-border-top-right-radius: 8px;
|
||||
-webkit-border-bottom-right-radius: 8px;
|
||||
}
|
||||
|
||||
#sidebarScrollView {
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
overflow-y: auto;
|
||||
top: 40px;
|
||||
right: 10px;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
#sidebarContentView {
|
||||
height: auto;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#viewer {
|
||||
margin: 44px 0px 0px;
|
||||
padding: 8px 0px;
|
||||
|
@ -2,7 +2,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>pdf.js Multi-Page Viewer</title>
|
||||
<link rel="stylesheet" href="multi-page-viewer.css" type="text/css" media="screen" charset="utf-8"/>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
|
||||
<link rel="stylesheet" href="multi-page-viewer.css" type="text/css" media="screen"/>
|
||||
<script type="text/javascript" src="pdf.js"></script>
|
||||
<script type="text/javascript" src="fonts.js"></script>
|
||||
<script type="text/javascript" src="glyphlist.js"></script>
|
||||
@ -11,7 +12,8 @@
|
||||
<body>
|
||||
<div id="controls">
|
||||
<span class="control">
|
||||
<span id="previousPageButton"></span><span id="nextPageButton"></span>
|
||||
<span id="previousPageButton" class="disabled"></span>
|
||||
<span id="nextPageButton" class="disabled"></span>
|
||||
<span class="label">Previous/Next</span>
|
||||
</span>
|
||||
<span class="control">
|
||||
@ -21,20 +23,29 @@
|
||||
<span class="label">Page Number</span>
|
||||
</span>
|
||||
<span class="control">
|
||||
<span id="scaleComboBoxInput"><input type="text" id="scale" value="100%" size="2"/></span><span id="scaleComboBoxButton"></span>
|
||||
<select id="scaleSelect">
|
||||
<option value="50">50%</option>
|
||||
<option value="75">75%</option>
|
||||
<option value="100" selected="selected">100%</option>
|
||||
<option value="125">125%</option>
|
||||
<option value="150">150%</option>
|
||||
<option value="200">200%</option>
|
||||
</select>
|
||||
<span class="label">Zoom</span>
|
||||
<div id="scaleComboBoxList">
|
||||
<ul>
|
||||
<li>50%</li>
|
||||
<li>75%</li>
|
||||
<li>100%</li>
|
||||
<li>125%</li>
|
||||
<li>150%</li>
|
||||
<li>200%</li>
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
<span class="control">
|
||||
<span id="openFileButton"></span>
|
||||
<input type="file" id="fileInput"/>
|
||||
<span class="label">Open File</span>
|
||||
</span>
|
||||
</div>
|
||||
<!--<div id="sidebar">
|
||||
<div id="sidebarScrollView">
|
||||
<div id="sidebarContentView">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
<div id="viewer"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -11,7 +11,8 @@ var PDFViewer = {
|
||||
previousPageButton: null,
|
||||
nextPageButton: null,
|
||||
pageNumberInput: null,
|
||||
scaleInput: null,
|
||||
scaleSelect: null,
|
||||
fileInput: null,
|
||||
|
||||
willJumpToPage: false,
|
||||
|
||||
@ -66,92 +67,103 @@ var PDFViewer = {
|
||||
removePage: function(num) {
|
||||
var div = document.getElementById('pageContainer' + num);
|
||||
|
||||
if (div && div.hasChildNodes()) {
|
||||
while (div.childNodes.length > 0) {
|
||||
if (div) {
|
||||
while (div.hasChildNodes()) {
|
||||
div.removeChild(div.firstChild);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
drawPage: function(num) {
|
||||
if (PDFViewer.pdf) {
|
||||
var page = PDFViewer.pdf.getPage(num);
|
||||
var div = document.getElementById('pageContainer' + num);
|
||||
|
||||
if (div && !div.hasChildNodes()) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.id = 'page' + num;
|
||||
canvas.mozOpaque = true;
|
||||
|
||||
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
||||
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
||||
canvas.width = PDFViewer.pageWidth();
|
||||
canvas.height = PDFViewer.pageHeight();
|
||||
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
|
||||
var gfx = new CanvasGraphics(ctx);
|
||||
var fonts = [];
|
||||
if (!PDFViewer.pdf) {
|
||||
return;
|
||||
}
|
||||
|
||||
// page.compile will collect all fonts for us, once we have loaded them
|
||||
// we can trigger the actual page rendering with page.display
|
||||
page.compile(gfx, fonts);
|
||||
|
||||
var fontsReady = true;
|
||||
|
||||
// Inspect fonts and translate the missing one
|
||||
var fontCount = fonts.length;
|
||||
|
||||
for (var i = 0; i < fontCount; i++) {
|
||||
var font = fonts[i];
|
||||
|
||||
if (Fonts[font.name]) {
|
||||
fontsReady = fontsReady && !Fonts[font.name].loading;
|
||||
continue;
|
||||
}
|
||||
var div = document.getElementById('pageContainer' + num);
|
||||
var canvas = document.createElement('canvas');
|
||||
|
||||
if (div && !div.hasChildNodes()) {
|
||||
div.appendChild(canvas);
|
||||
|
||||
var page = PDFViewer.pdf.getPage(num);
|
||||
|
||||
new Font(font.name, font.file, font.properties);
|
||||
|
||||
fontsReady = false;
|
||||
canvas.id = 'page' + num;
|
||||
canvas.mozOpaque = true;
|
||||
|
||||
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
||||
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
||||
canvas.width = PDFViewer.pageWidth();
|
||||
canvas.height = PDFViewer.pageHeight();
|
||||
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
|
||||
var gfx = new CanvasGraphics(ctx);
|
||||
var fonts = [];
|
||||
|
||||
// page.compile will collect all fonts for us, once we have loaded them
|
||||
// we can trigger the actual page rendering with page.display
|
||||
page.compile(gfx, fonts);
|
||||
|
||||
var areFontsReady = true;
|
||||
|
||||
// Inspect fonts and translate the missing one
|
||||
var fontCount = fonts.length;
|
||||
|
||||
for (var i = 0; i < fontCount; i++) {
|
||||
var font = fonts[i];
|
||||
|
||||
if (Fonts[font.name]) {
|
||||
areFontsReady = areFontsReady && !Fonts[font.name].loading;
|
||||
continue;
|
||||
}
|
||||
|
||||
var pageInterval;
|
||||
var delayLoadFont = function() {
|
||||
for (var i = 0; i < fontCount; i++) {
|
||||
if (Fonts[font.name].loading) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
clearInterval(pageInterval);
|
||||
|
||||
PDFViewer.drawPage(num);
|
||||
}
|
||||
|
||||
if (!fontsReady) {
|
||||
pageInterval = setInterval(delayLoadFont, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
page.display(gfx);
|
||||
div.appendChild(canvas);
|
||||
new Font(font.name, font.file, font.properties);
|
||||
|
||||
areFontsReady = false;
|
||||
}
|
||||
|
||||
var pageInterval;
|
||||
|
||||
var delayLoadFont = function() {
|
||||
for (var i = 0; i < fontCount; i++) {
|
||||
if (Fonts[font.name].loading) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
clearInterval(pageInterval);
|
||||
|
||||
while (div.hasChildNodes()) {
|
||||
div.removeChild(div.firstChild);
|
||||
}
|
||||
|
||||
PDFViewer.drawPage(num);
|
||||
}
|
||||
|
||||
if (!areFontsReady) {
|
||||
pageInterval = setInterval(delayLoadFont, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
page.display(gfx);
|
||||
}
|
||||
},
|
||||
|
||||
changeScale: function(num) {
|
||||
while (PDFViewer.element.childNodes.length > 0) {
|
||||
while (PDFViewer.element.hasChildNodes()) {
|
||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
|
||||
}
|
||||
|
||||
PDFViewer.scale = num / 100;
|
||||
|
||||
var i;
|
||||
|
||||
if (PDFViewer.pdf) {
|
||||
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
for (i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
PDFViewer.createPage(i);
|
||||
}
|
||||
|
||||
@ -160,7 +172,21 @@ var PDFViewer = {
|
||||
}
|
||||
}
|
||||
|
||||
PDFViewer.scaleInput.value = Math.floor(PDFViewer.scale * 100) + '%';
|
||||
for (i = 0; i < PDFViewer.scaleSelect.childNodes; i++) {
|
||||
var option = PDFViewer.scaleSelect.childNodes[i];
|
||||
|
||||
if (option.value == num) {
|
||||
if (!option.selected) {
|
||||
option.selected = 'selected';
|
||||
}
|
||||
} else {
|
||||
if (option.selected) {
|
||||
option.removeAttribute('selected');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PDFViewer.scaleSelect.value = Math.floor(PDFViewer.scale * 100) + '%';
|
||||
},
|
||||
|
||||
goToPage: function(num) {
|
||||
@ -190,7 +216,7 @@ var PDFViewer = {
|
||||
}
|
||||
},
|
||||
|
||||
open: function(url) {
|
||||
openURL: function(url) {
|
||||
PDFViewer.url = url;
|
||||
document.title = url;
|
||||
|
||||
@ -206,21 +232,35 @@ var PDFViewer = {
|
||||
req.responseArrayBuffer ||
|
||||
req.response;
|
||||
|
||||
PDFViewer.pdf = new PDFDoc(new Stream(data));
|
||||
PDFViewer.numberOfPages = PDFViewer.pdf.numPages;
|
||||
document.getElementById('numPages').innerHTML = PDFViewer.numberOfPages.toString();
|
||||
|
||||
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
PDFViewer.createPage(i);
|
||||
}
|
||||
|
||||
if (PDFViewer.numberOfPages > 0) {
|
||||
PDFViewer.drawPage(1);
|
||||
}
|
||||
PDFViewer.readPDF(data);
|
||||
}
|
||||
};
|
||||
|
||||
req.send(null);
|
||||
},
|
||||
|
||||
readPDF: function(data) {
|
||||
while (PDFViewer.element.hasChildNodes()) {
|
||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
|
||||
}
|
||||
|
||||
PDFViewer.pdf = new PDFDoc(new Stream(data));
|
||||
PDFViewer.numberOfPages = PDFViewer.pdf.numPages;
|
||||
document.getElementById('numPages').innerHTML = PDFViewer.numberOfPages.toString();
|
||||
|
||||
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
PDFViewer.createPage(i);
|
||||
}
|
||||
|
||||
if (PDFViewer.numberOfPages > 0) {
|
||||
PDFViewer.drawPage(1);
|
||||
document.location.hash = 1;
|
||||
}
|
||||
|
||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ?
|
||||
'disabled' : '';
|
||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ?
|
||||
'disabled' : '';
|
||||
}
|
||||
};
|
||||
|
||||
@ -320,41 +360,67 @@ window.onload = function() {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
PDFViewer.scaleInput = document.getElementById('scale');
|
||||
PDFViewer.scaleInput.buttonElement = document.getElementById('scaleComboBoxButton');
|
||||
PDFViewer.scaleInput.buttonElement.listElement = document.getElementById('scaleComboBoxList');
|
||||
PDFViewer.scaleInput.onchange = function(evt) {
|
||||
PDFViewer.scaleSelect = document.getElementById('scaleSelect');
|
||||
PDFViewer.scaleSelect.onchange = function(evt) {
|
||||
PDFViewer.changeScale(parseInt(this.value));
|
||||
};
|
||||
|
||||
PDFViewer.scaleInput.buttonElement.onclick = function(evt) {
|
||||
this.listElement.style.display = (this.listElement.style.display === 'block') ? 'none' : 'block';
|
||||
};
|
||||
PDFViewer.scaleInput.buttonElement.onmousedown = function(evt) {
|
||||
if (this.className.indexOf('disabled') === -1) {
|
||||
this.className = 'down';
|
||||
}
|
||||
};
|
||||
PDFViewer.scaleInput.buttonElement.onmouseup = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
PDFViewer.scaleInput.buttonElement.onmouseout = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
var listItems = PDFViewer.scaleInput.buttonElement.listElement.getElementsByTagName('LI');
|
||||
|
||||
for (var i = 0; i < listItems.length; i++) {
|
||||
var listItem = listItems[i];
|
||||
listItem.onclick = function(evt) {
|
||||
PDFViewer.changeScale(parseInt(this.innerHTML));
|
||||
PDFViewer.scaleInput.buttonElement.listElement.style.display = 'none';
|
||||
if (window.File && window.FileReader && window.FileList && window.Blob) {
|
||||
var openFileButton = document.getElementById('openFileButton');
|
||||
openFileButton.onclick = function(evt) {
|
||||
if (this.className.indexOf('disabled') === -1) {
|
||||
PDFViewer.fileInput.click();
|
||||
}
|
||||
};
|
||||
openFileButton.onmousedown = function(evt) {
|
||||
if (this.className.indexOf('disabled') === -1) {
|
||||
this.className = 'down';
|
||||
}
|
||||
};
|
||||
openFileButton.onmouseup = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
openFileButton.onmouseout = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
PDFViewer.fileInput = document.getElementById('fileInput');
|
||||
PDFViewer.fileInput.onchange = function(evt) {
|
||||
var files = evt.target.files;
|
||||
|
||||
if (files.length > 0) {
|
||||
var file = files[0];
|
||||
var fileReader = new FileReader();
|
||||
|
||||
document.title = file.name;
|
||||
|
||||
// Read the local file into a Uint8Array.
|
||||
fileReader.onload = function(evt) {
|
||||
var data = evt.target.result;
|
||||
var buffer = new ArrayBuffer(data.length);
|
||||
var uint8Array = new Uint8Array(buffer);
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
uint8Array[i] = data.charCodeAt(i);
|
||||
}
|
||||
|
||||
PDFViewer.readPDF(uint8Array);
|
||||
};
|
||||
|
||||
// Read as a binary string since "readAsArrayBuffer" is not yet
|
||||
// implemented in Firefox.
|
||||
fileReader.readAsBinaryString(file);
|
||||
}
|
||||
};
|
||||
PDFViewer.fileInput.value = null;
|
||||
} else {
|
||||
document.getElementById('fileWrapper').style.display = 'none';
|
||||
}
|
||||
|
||||
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber;
|
||||
PDFViewer.scale = parseInt(PDFViewer.scaleInput.value) / 100 || 1.0;
|
||||
PDFViewer.open(PDFViewer.queryParams.file || PDFViewer.url);
|
||||
PDFViewer.scale = parseInt(PDFViewer.scaleSelect.value) / 100 || 1.0;
|
||||
|
||||
PDFViewer.openURL(PDFViewer.queryParams.file || PDFViewer.url);
|
||||
|
||||
window.onscroll = function(evt) {
|
||||
var lastPagesDrawn = PDFViewer.lastPagesDrawn;
|
||||
|
169
test.py
169
test.py
@ -1,7 +1,16 @@
|
||||
import json, os, sys, subprocess
|
||||
import json, os, sys, subprocess, urllib2
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||
from urlparse import urlparse
|
||||
|
||||
def prompt(question):
|
||||
'''Return True iff the user answered "yes" to |question|.'''
|
||||
inp = raw_input(question +' [yes/no] > ')
|
||||
return inp == 'yes'
|
||||
|
||||
ANAL = True
|
||||
DEFAULT_MANIFEST_FILE = 'test_manifest.json'
|
||||
REFDIR = 'ref'
|
||||
TMPDIR = 'tmp'
|
||||
VERBOSE = False
|
||||
|
||||
MIMEs = {
|
||||
@ -20,6 +29,12 @@ class State:
|
||||
remaining = 0
|
||||
results = { }
|
||||
done = False
|
||||
masterMode = False
|
||||
numErrors = 0
|
||||
numEqFailures = 0
|
||||
numEqNoSnapshot = 0
|
||||
numFBFFailures = 0
|
||||
numLoadFailures = 0
|
||||
|
||||
class Result:
|
||||
def __init__(self, snapshot, failure):
|
||||
@ -34,8 +49,11 @@ class PDFTestHandler(BaseHTTPRequestHandler):
|
||||
BaseHTTPRequestHandler.log_request(code, size)
|
||||
|
||||
def do_GET(self):
|
||||
url = urlparse(self.path)
|
||||
# Ignore query string
|
||||
path, _ = url.path, url.query
|
||||
cwd = os.getcwd()
|
||||
path = os.path.abspath(os.path.realpath(cwd + os.sep + self.path))
|
||||
path = os.path.abspath(os.path.realpath(cwd + os.sep + path))
|
||||
cwd = os.path.abspath(cwd)
|
||||
prefix = os.path.commonprefix(( path, cwd ))
|
||||
_, ext = os.path.splitext(path)
|
||||
@ -69,31 +87,59 @@ class PDFTestHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
|
||||
result = json.loads(self.rfile.read(numBytes))
|
||||
browser = 'firefox4'
|
||||
id, failure, round, page, snapshot = result['id'], result['failure'], result['round'], result['page'], result['snapshot']
|
||||
browser, id, failure, round, page, snapshot = result['browser'], result['id'], result['failure'], result['round'], result['page'], result['snapshot']
|
||||
taskResults = State.taskResults[browser][id]
|
||||
taskResults[round][page - 1] = Result(snapshot, failure)
|
||||
taskResults[round].append(Result(snapshot, failure))
|
||||
assert len(taskResults[round]) == page
|
||||
|
||||
if result['taskDone']:
|
||||
check(State.manifest[id], taskResults, browser)
|
||||
# Please oh please GC this ...
|
||||
del State.taskResults[browser][id]
|
||||
State.remaining -= 1
|
||||
|
||||
State.done = (0 == State.remaining)
|
||||
|
||||
|
||||
def set_up():
|
||||
|
||||
def setUp(manifestFile, masterMode):
|
||||
# Only serve files from a pdf.js clone
|
||||
assert not ANAL or os.path.isfile('pdf.js') and os.path.isdir('.git')
|
||||
|
||||
State.masterMode = masterMode
|
||||
if masterMode and os.path.isdir(TMPDIR):
|
||||
print 'Temporary snapshot dir tmp/ is still around.'
|
||||
print 'tmp/ can be removed if it has nothing you need.'
|
||||
if prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'):
|
||||
subprocess.call(( 'rm', '-rf', 'tmp' ))
|
||||
|
||||
assert not os.path.isdir(TMPDIR)
|
||||
|
||||
testBrowsers = [ b for b in
|
||||
( 'firefox4', )
|
||||
#'chrome12', 'chrome13', 'firefox5', 'firefox6','opera11' ):
|
||||
( 'firefox5', )
|
||||
#'chrome12', 'chrome13', 'firefox4', 'firefox6','opera11' ):
|
||||
if os.access(b, os.R_OK | os.X_OK) ]
|
||||
|
||||
mf = open('test_manifest.json')
|
||||
mf = open(manifestFile)
|
||||
manifestList = json.load(mf)
|
||||
mf.close()
|
||||
|
||||
for item in manifestList:
|
||||
f, isLink = item['file'], item.get('link', False)
|
||||
if isLink and not os.access(f, os.R_OK):
|
||||
linkFile = open(f +'.link')
|
||||
link = linkFile.read()
|
||||
linkFile.close()
|
||||
|
||||
sys.stdout.write('Downloading '+ link +' to '+ f +' ...')
|
||||
sys.stdout.flush()
|
||||
response = urllib2.urlopen(link)
|
||||
|
||||
out = open(f, 'w')
|
||||
out.write(response.read())
|
||||
out.close()
|
||||
|
||||
print 'done'
|
||||
|
||||
for b in testBrowsers:
|
||||
State.taskResults[b] = { }
|
||||
for item in manifestList:
|
||||
@ -101,15 +147,16 @@ def set_up():
|
||||
State.manifest[id] = item
|
||||
taskResults = [ ]
|
||||
for r in xrange(rounds):
|
||||
taskResults.append([ None ] * 100)
|
||||
taskResults.append([ ])
|
||||
State.taskResults[b][id] = taskResults
|
||||
|
||||
State.remaining = len(manifestList)
|
||||
|
||||
for b in testBrowsers:
|
||||
print 'Launching', b
|
||||
qs = 'browser='+ b +'&manifestFile='+ manifestFile
|
||||
subprocess.Popen(( os.path.abspath(os.path.realpath(b)),
|
||||
'http://localhost:8080/test_slave.html' ))
|
||||
'http://localhost:8080/test_slave.html?'+ qs))
|
||||
|
||||
|
||||
def check(task, results, browser):
|
||||
@ -123,13 +170,14 @@ def check(task, results, browser):
|
||||
failure = pageResult.failure
|
||||
if failure:
|
||||
failed = True
|
||||
State.numErrors += 1
|
||||
print 'TEST-UNEXPECTED-FAIL | test failed', task['id'], '| in', browser, '| page', p + 1, 'round', r, '|', failure
|
||||
|
||||
if failed:
|
||||
return
|
||||
|
||||
kind = task['type']
|
||||
if '==' == kind:
|
||||
if 'eq' == kind:
|
||||
checkEq(task, results, browser)
|
||||
elif 'fbf' == kind:
|
||||
checkFBF(task, results, browser)
|
||||
@ -140,23 +188,60 @@ def check(task, results, browser):
|
||||
|
||||
|
||||
def checkEq(task, results, browser):
|
||||
print ' !!! [TODO: == tests] !!!'
|
||||
print 'TEST-PASS | == test', task['id'], '| in', browser
|
||||
pfx = os.path.join(REFDIR, sys.platform, browser, task['id'])
|
||||
results = results[0]
|
||||
|
||||
passed = True
|
||||
for page in xrange(len(results)):
|
||||
snapshot = results[page].snapshot
|
||||
ref = None
|
||||
eq = True
|
||||
|
||||
path = os.path.join(pfx, str(page + 1))
|
||||
if not os.access(path, os.R_OK):
|
||||
print 'WARNING: no reference snapshot', path
|
||||
State.numEqNoSnapshot += 1
|
||||
else:
|
||||
f = open(path)
|
||||
ref = f.read()
|
||||
f.close()
|
||||
|
||||
eq = (ref == snapshot)
|
||||
if not eq:
|
||||
print 'TEST-UNEXPECTED-FAIL | eq', task['id'], '| in', browser, '| rendering of page', page + 1, '!= reference rendering'
|
||||
passed = False
|
||||
State.numEqFailures += 1
|
||||
|
||||
if State.masterMode and (ref is None or not eq):
|
||||
tmpTaskDir = os.path.join(TMPDIR, sys.platform, browser, task['id'])
|
||||
try:
|
||||
os.makedirs(tmpTaskDir)
|
||||
except OSError, e:
|
||||
pass
|
||||
|
||||
of = open(os.path.join(tmpTaskDir, str(page + 1)), 'w')
|
||||
of.write(snapshot)
|
||||
of.close()
|
||||
|
||||
if passed:
|
||||
print 'TEST-PASS | eq test', task['id'], '| in', browser
|
||||
|
||||
printed = [False]
|
||||
|
||||
def checkFBF(task, results, browser):
|
||||
round0, round1 = results[0], results[1]
|
||||
assert len(round0) == len(round1)
|
||||
|
||||
passed = True
|
||||
for page in xrange(len(round1)):
|
||||
r0Page, r1Page = round0[page], round1[page]
|
||||
if r0Page is None:
|
||||
break
|
||||
if r0Page.snapshot != r1Page.snapshot:
|
||||
print 'TEST-UNEXPECTED-FAIL | forward-back-forward test', task['id'], '| in', browser, '| first rendering of page', page + 1, '!= second'
|
||||
print 'TEST-PASS | forward-back-forward test', task['id'], '| in', browser
|
||||
passed = False
|
||||
State.numFBFFailures += 1
|
||||
if passed:
|
||||
print 'TEST-PASS | forward-back-forward test', task['id'], '| in', browser
|
||||
|
||||
|
||||
def checkLoad(task, results, browser):
|
||||
@ -165,11 +250,55 @@ def checkLoad(task, results, browser):
|
||||
print 'TEST-PASS | load test', task['id'], '| in', browser
|
||||
|
||||
|
||||
def main():
|
||||
set_up()
|
||||
def processResults():
|
||||
print ''
|
||||
numErrors, numEqFailures, numEqNoSnapshot, numFBFFailures = State.numErrors, State.numEqFailures, State.numEqNoSnapshot, State.numFBFFailures
|
||||
numFatalFailures = (numErrors + numFBFFailures)
|
||||
if 0 == numEqFailures and 0 == numFatalFailures:
|
||||
print 'All tests passed.'
|
||||
else:
|
||||
print 'OHNOES! Some tests failed!'
|
||||
if 0 < numErrors:
|
||||
print ' errors:', numErrors
|
||||
if 0 < numEqFailures:
|
||||
print ' different ref/snapshot:', numEqFailures
|
||||
if 0 < numFBFFailures:
|
||||
print ' different first/second rendering:', numFBFFailures
|
||||
|
||||
if State.masterMode and (0 < numEqFailures or 0 < numEqNoSnapshot):
|
||||
print "Some eq tests failed or didn't have snapshots."
|
||||
print 'Checking to see if master references can be updated...'
|
||||
if 0 < numFatalFailures:
|
||||
print ' No. Some non-eq tests failed.'
|
||||
else:
|
||||
' Yes! The references in tmp/ can be synced with ref/.'
|
||||
if not prompt('Would you like to update the master copy in ref/?'):
|
||||
print ' OK, not updating.'
|
||||
else:
|
||||
sys.stdout.write(' Updating ... ')
|
||||
|
||||
# XXX unclear what to do on errors here ...
|
||||
# NB: do *NOT* pass --delete to rsync. That breaks this
|
||||
# entire scheme.
|
||||
subprocess.check_call(( 'rsync', '-arv', 'tmp/', 'ref/' ))
|
||||
|
||||
print 'done'
|
||||
|
||||
|
||||
def main(args):
|
||||
masterMode = False
|
||||
manifestFile = DEFAULT_MANIFEST_FILE
|
||||
if len(args) == 1:
|
||||
masterMode = (args[0] == '-m')
|
||||
manifestFile = args[0] if not masterMode else manifestFile
|
||||
|
||||
setUp(manifestFile, masterMode)
|
||||
|
||||
server = HTTPServer(('127.0.0.1', 8080), PDFTestHandler)
|
||||
while not State.done:
|
||||
server.handle_request()
|
||||
|
||||
processResults()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main(sys.argv[1:])
|
||||
|
@ -1,8 +1,8 @@
|
||||
[
|
||||
{ "id": "tracemonkey-==",
|
||||
{ "id": "tracemonkey-eq",
|
||||
"file": "tests/tracemonkey.pdf",
|
||||
"rounds": 1,
|
||||
"type": "=="
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "tracemonkey-fbf",
|
||||
"file": "tests/tracemonkey.pdf",
|
||||
@ -13,5 +13,11 @@
|
||||
"file": "tests/canvas.pdf",
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "pdfspec-load",
|
||||
"file": "tests/pdf.pdf",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
}
|
||||
]
|
||||
|
@ -5,9 +5,24 @@
|
||||
<script type="text/javascript" src="fonts.js"></script>
|
||||
<script type="text/javascript" src="glyphlist.js"></script>
|
||||
<script type="application/javascript">
|
||||
var canvas, currentTask, currentTaskIdx, failure, manifest, pdfDoc, stdout;
|
||||
var browser, canvas, currentTask, currentTaskIdx, failure, manifest, pdfDoc, stdout;
|
||||
|
||||
function queryParams() {
|
||||
var qs = window.location.search.substring(1);
|
||||
var kvs = qs.split("&");
|
||||
var params = { };
|
||||
for (var i = 0; i < kvs.length; ++i) {
|
||||
var kv = kvs[i].split("=");
|
||||
params[unescape(kv[0])] = unescape(kv[1]);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
function load() {
|
||||
var params = queryParams();
|
||||
browser = params.browser;
|
||||
manifestFile = params.manifestFile;
|
||||
|
||||
canvas = document.createElement("canvas");
|
||||
// 8.5x11in @ 100% ... XXX need something better here
|
||||
canvas.width = 816;
|
||||
@ -15,10 +30,11 @@ function load() {
|
||||
canvas.mozOpaque = true;
|
||||
stdout = document.getElementById("stdout");
|
||||
|
||||
log("Harness thinks this browser is '"+ browser +"'\n");
|
||||
log("Fetching manifest ...");
|
||||
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("GET", "test_manifest.json", false);
|
||||
r.open("GET", manifestFile, false);
|
||||
r.onreadystatechange = function(e) {
|
||||
if (r.readyState == 4) {
|
||||
log("done\n");
|
||||
@ -67,14 +83,13 @@ function nextPage() {
|
||||
failure = '';
|
||||
log(" drawing page "+ currentTask.pageNum +"...");
|
||||
|
||||
currentPage = pdfDoc.getPage(currentTask.pageNum);
|
||||
|
||||
var ctx = canvas.getContext("2d");
|
||||
clear(ctx);
|
||||
|
||||
var fonts = [];
|
||||
var gfx = new CanvasGraphics(ctx);
|
||||
try {
|
||||
currentPage = pdfDoc.getPage(currentTask.pageNum);
|
||||
currentPage.compile(gfx, fonts);
|
||||
} catch(e) {
|
||||
failure = 'compile: '+ e.toString();
|
||||
@ -111,7 +126,8 @@ function done() {
|
||||
}
|
||||
|
||||
function sendTaskResult(snapshot) {
|
||||
var result = { id: currentTask.id,
|
||||
var result = { browser: browser,
|
||||
id: currentTask.id,
|
||||
taskDone: currentTask.taskDone,
|
||||
failure: failure,
|
||||
file: currentTask.file,
|
||||
|
1
tests/pdf.pdf.link
Normal file
1
tests/pdf.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_1-7.pdf
|
Loading…
Reference in New Issue
Block a user