Merge remote branch 'upstream/master'

This commit is contained in:
Vivien Nicolas 2011-08-30 00:56:20 +02:00
commit b4f3ceef85
8 changed files with 133 additions and 16 deletions

View File

@ -220,7 +220,7 @@ var FontLoader = {
} }
src += ' var fontNames=[' + fontNamesArray + '];\n'; src += ' var fontNames=[' + fontNamesArray + '];\n';
src += ' window.onload = function () {\n'; src += ' window.onload = function () {\n';
src += ' top.postMessage(JSON.stringify(fontNames), "*");\n'; src += ' parent.postMessage(JSON.stringify(fontNames), "*");\n';
src += ' }'; src += ' }';
src += '</script></head><body>'; src += '</script></head><body>';
for (var i = 0; i < names.length; ++i) { for (var i = 0; i < names.length; ++i) {
@ -1868,7 +1868,8 @@ CFF.prototype = {
return null; return null;
}, },
getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs, properties) { getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs,
properties) {
var charstrings = []; var charstrings = [];
var missings = []; var missings = [];

24
pdf.js
View File

@ -4381,7 +4381,7 @@ var PartialEvaluator = (function() {
var descriptor = xref.fetch(fd); var descriptor = xref.fetch(fd);
var fontName = fontDict.get('Name'); var fontName = fontDict.get('Name');
if (!fontName) if (!fontName)
fontName = xref.fetchIfRef(descriptor.get('FontName'));; fontName = xref.fetchIfRef(descriptor.get('FontName'));
assertWellFormed(IsName(fontName), 'invalid font name'); assertWellFormed(IsName(fontName), 'invalid font name');
fontName = fontName.name.replace(/[\+,\-]/g, '_'); fontName = fontName.name.replace(/[\+,\-]/g, '_');
@ -5106,7 +5106,7 @@ var CanvasGraphics = (function() {
var inverseDecode = !!imageObj.decode && imageObj.decode[0] > 0; var inverseDecode = !!imageObj.decode && imageObj.decode[0] > 0;
imageObj.applyStencilMask(pixels, inverseDecode); imageObj.applyStencilMask(pixels, inverseDecode);
} else } else
imageObj.fillRgbaBuffer(pixels); imageObj.fillRgbaBuffer(pixels, imageObj.decode);
tmpCtx.putImageData(imgData, 0, 0); tmpCtx.putImageData(imgData, 0, 0);
ctx.drawImage(tmpCanvas, 0, -h); ctx.drawImage(tmpCanvas, 0, -h);
@ -5901,7 +5901,7 @@ var PDFImage = (function() {
}; };
constructor.prototype = { constructor.prototype = {
getComponents: function getComponents(buffer) { getComponents: function getComponents(buffer, decodeMap) {
var bpc = this.bpc; var bpc = this.bpc;
if (bpc == 8) if (bpc == 8)
return buffer; return buffer;
@ -5915,6 +5915,11 @@ var PDFImage = (function() {
var output = new Uint8Array(length); var output = new Uint8Array(length);
if (bpc == 1) { if (bpc == 1) {
var valueZero = 0, valueOne = 255;
if (decodeMap) {
valueZero = decodeMap[0] ? 255 : 0;
valueOne = decodeMap[1] ? 255 : 0;
}
var rowComps = width * numComps; var rowComps = width * numComps;
var mask = 0; var mask = 0;
var buf = 0; var buf = 0;
@ -5932,13 +5937,11 @@ var PDFImage = (function() {
mask = 128; mask = 128;
} }
var t = buf & mask; output[i] = !(buf & mask) ? valueZero : valueOne;
if (t == 0)
output[i] = 0;
else
output[i] = 255;
} }
} else { } else {
if (decodeMap != null)
TODO('interpolate component values');
var rowComps = width * numComps; var rowComps = width * numComps;
var bits = 0; var bits = 0;
var buf = 0; var buf = 0;
@ -6007,7 +6010,7 @@ var PDFImage = (function() {
} }
} }
}, },
fillRgbaBuffer: function fillRgbaBuffer(buffer) { fillRgbaBuffer: function fillRgbaBuffer(buffer, decodeMap) {
var numComps = this.numComps; var numComps = this.numComps;
var width = this.width; var width = this.width;
var height = this.height; var height = this.height;
@ -6017,7 +6020,8 @@ var PDFImage = (function() {
var rowBytes = (width * numComps * bpc + 7) >> 3; var rowBytes = (width * numComps * bpc + 7) >> 3;
var imgArray = this.image.getBytes(height * rowBytes); var imgArray = this.image.getBytes(height * rowBytes);
var comps = this.colorSpace.getRgbBuffer(this.getComponents(imgArray)); var comps = this.colorSpace.getRgbBuffer(
this.getComponents(imgArray, decodeMap));
var compsPos = 0; var compsPos = 0;
var opacity = this.getOpacity(); var opacity = this.getOpacity();
var opacityPos = 0; var opacityPos = 0;

1
test/pdfs/cable.pdf.link Normal file
View File

@ -0,0 +1 @@
http://www.wrapon.com/docs/PIPEHEATCABLE.PDF

View File

@ -103,18 +103,49 @@ class PDFTestHandler(BaseHTTPRequestHandler):
with open(path, "rb") as f: with open(path, "rb") as f:
self.wfile.write(f.read()) self.wfile.write(f.read())
def sendIndex(self, path, query):
if not path.endswith("/"):
# we need trailing slash
self.send_response(301)
redirectLocation = path + "/"
if query:
redirectLocation += "?" + query
self.send_header("Location", redirectLocation)
self.end_headers()
return
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.end_headers()
if query == "frame":
self.wfile.write("<html><frameset cols=*,200><frame name=pdf>" +
"<frame src='" + path + "'></frameset></html>")
return
location = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path))
self.wfile.write("<html><body><h1>PDFs of " + path + "</h1>\n")
for filename in os.listdir(location):
if filename.lower().endswith('.pdf'):
self.wfile.write("<a href='/web/viewer.html?file=" + path + filename + "' target=pdf>" +
filename + "</a><br>\n")
self.wfile.write("</body></html>")
def do_GET(self): def do_GET(self):
url = urlparse(self.path) url = urlparse(self.path)
# Ignore query string # Ignore query string
path, _ = url.path, url.query path, _ = url.path, url.query
path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path)) path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path))
prefix = os.path.commonprefix(( path, DOC_ROOT )) prefix = os.path.commonprefix(( path, DOC_ROOT ))
_, ext = os.path.splitext(path) _, ext = os.path.splitext(path.lower())
if url.path == "/favicon.ico": if url.path == "/favicon.ico":
self.sendFile(os.path.join(DOC_ROOT, "test", "resources", "favicon.ico"), ext) self.sendFile(os.path.join(DOC_ROOT, "test", "resources", "favicon.ico"), ext)
return return
if os.path.isdir(path):
self.sendIndex(url.path, url.query)
return
if not (prefix == DOC_ROOT if not (prefix == DOC_ROOT
and os.path.isfile(path) and os.path.isfile(path)
and ext in MIMEs): and ext in MIMEs):

View File

@ -97,5 +97,11 @@
"link": true, "link": true,
"rounds": 1, "rounds": 1,
"type": "load" "type": "load"
},
{ "id": "cable",
"file": "pdfs/cable.pdf",
"link": true,
"rounds": 1,
"type": "eq"
} }
] ]

35
web/compatibility.js Normal file → Executable file
View File

@ -148,10 +148,39 @@
Function.prototype.bind = function(obj) { Function.prototype.bind = function(obj) {
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1); var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
var binded = function(tailArgs) { var bound = function() {
var args = headArgs.concat(tailArgs); var args = Array.prototype.concat.apply(headArgs, arguments);
return fn.apply(obj, args); return fn.apply(obj, args);
}; };
return binded; return bound;
}; };
})(); })();
// IE9 text/html data URI
(function() {
if (document.documentMode !== 9)
return;
// overriding the src property
var originalSrcDescriptor = Object.getOwnPropertyDescriptor(
HTMLIFrameElement.prototype, 'src');
Object.defineProperty(HTMLIFrameElement.prototype, 'src', {
get: function() { return this.$src; },
set: function(src) {
this.$src = src;
if (src.substr(0, 14) != 'data:text/html') {
originalSrcDescriptor.set.call(this, src);
return;
}
// for text/html, using blank document and then
// document's open, write, and close operations
originalSrcDescriptor.set.call(this, 'about:blank');
setTimeout((function() {
var doc = this.contentDocument;
doc.open('text/html');
doc.write(src.substr(src.indexOf(',') + 1));
doc.close();
}).bind(this), 0);
},
enumerable: true
});
})();

41
web/viewer.css Normal file → Executable file
View File

@ -36,6 +36,11 @@ body {
line-height: 32px; line-height: 32px;
} }
#controls > button > img {
width: 32px;
height: 32px;
}
#controls > button[disabled] > img { #controls > button[disabled] > img {
opacity: 0.5; opacity: 0.5;
} }
@ -159,6 +164,11 @@ span#info {
-webkit-box-shadow: 0px 4px 10px #000; -webkit-box-shadow: 0px 4px 10px #000;
} }
#sidebarControls > button > img {
width: 32px;
height: 32px;
}
#sidebarControls > button[disabled] > img { #sidebarControls > button[disabled] > img {
opacity: 0.5; opacity: 0.5;
} }
@ -210,3 +220,34 @@ canvas {
-webkit-box-shadow: 0px 2px 10px #ff0; -webkit-box-shadow: 0px 2px 10px #ff0;
} }
/* === Printed media overrides === */
@media print {
#sidebar {
display: none;
}
#controls {
display: none;
}
#viewer {
margin: 0;
padding: 0;
}
.page {
display: none;
margin: 0;
}
.page canvas {
box-shadow: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
}
.page[data-loaded] {
display: block;
page-break-after: always;
}
}

View File

@ -87,6 +87,8 @@ var PDFView = {
navigateTo: function(dest) { navigateTo: function(dest) {
if (typeof dest === 'string') if (typeof dest === 'string')
dest = this.destinations[dest]; dest = this.destinations[dest];
if (!(dest instanceof Array))
return; // invalid destination
// dest array looks like that: <page-ref> </XYZ|FitXXX> <args..> // dest array looks like that: <page-ref> </XYZ|FitXXX> <args..>
var destRef = dest[0]; var destRef = dest[0];
var pageNumber = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R']; var pageNumber = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'];
@ -209,6 +211,7 @@ var PageView = function(container, content, id, width, height,
while (div.hasChildNodes()) while (div.hasChildNodes())
div.removeChild(div.lastChild); div.removeChild(div.lastChild);
div.removeAttribute('data-loaded');
}; };
function setupLinks(canvas, content, scale) { function setupLinks(canvas, content, scale) {
@ -257,6 +260,7 @@ var PageView = function(container, content, id, width, height,
this.content.startRendering(ctx, this.updateStats); this.content.startRendering(ctx, this.updateStats);
setupLinks(canvas, this.content, this.scale); setupLinks(canvas, this.content, this.scale);
div.setAttribute('data-loaded', true);
return true; return true;
}; };