Merge upstream.
This commit is contained in:
commit
ebeff10a9a
22
pdf.js
22
pdf.js
@ -3764,7 +3764,7 @@ var CanvasGraphics = (function() {
|
||||
transform: function(a, b, c, d, e, f) {
|
||||
this.ctx.transform(a, b, c, d, e, f);
|
||||
},
|
||||
|
||||
|
||||
// Path
|
||||
moveTo: function(x, y) {
|
||||
this.ctx.moveTo(x, y);
|
||||
@ -3825,7 +3825,7 @@ var CanvasGraphics = (function() {
|
||||
endPath: function() {
|
||||
this.consumePath();
|
||||
},
|
||||
|
||||
|
||||
// Clipping
|
||||
clip: function() {
|
||||
this.pendingClip = NORMAL_CLIP;
|
||||
@ -3833,7 +3833,7 @@ var CanvasGraphics = (function() {
|
||||
eoClip: function() {
|
||||
this.pendingClip = EO_CLIP;
|
||||
},
|
||||
|
||||
|
||||
// Text
|
||||
beginText: function() {
|
||||
this.current.textMatrix = IDENTITY_MATRIX;
|
||||
@ -3858,27 +3858,27 @@ var CanvasGraphics = (function() {
|
||||
this.current.leading = leading;
|
||||
},
|
||||
setFont: function(fontRef, size) {
|
||||
var font = this.res.get('Font');
|
||||
var font = this.xref.fetchIfRef(this.res.get("Font"));
|
||||
if (!IsDict(font))
|
||||
return;
|
||||
|
||||
|
||||
font = font.get(fontRef.name);
|
||||
font = this.xref.fetchIfRef(font);
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
var fontName = '';
|
||||
var fontDescriptor = font.get('FontDescriptor');
|
||||
|
||||
var fontName = "";
|
||||
var fontDescriptor = font.get("FontDescriptor");
|
||||
if (fontDescriptor && fontDescriptor.num) {
|
||||
var fontDescriptor = this.xref.fetchIfRef(fontDescriptor);
|
||||
fontName = fontDescriptor.get('FontName').name.replace('+', '_');
|
||||
fontName = fontDescriptor.get("FontName").name.replace("+", "_");
|
||||
}
|
||||
|
||||
|
||||
if (!fontName) {
|
||||
// TODO: fontDescriptor is not available, fallback to default font
|
||||
fontName = 'sans-serif';
|
||||
}
|
||||
|
||||
|
||||
this.current.fontName = fontName;
|
||||
this.current.fontSize = size;
|
||||
|
||||
|
1
test/pdfs/DiwanProfile.pdf.link
Normal file
1
test/pdfs/DiwanProfile.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://oannis.com/DiwanProfile.pdf
|
@ -42,5 +42,11 @@
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "openoffice-pdf",
|
||||
"file": "pdfs/DiwanProfile.pdf",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
}
|
||||
]
|
||||
|
153
web/compatibility.js
Normal file
153
web/compatibility.js
Normal file
@ -0,0 +1,153 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
// Checking if the typed arrays are supported
|
||||
(function() {
|
||||
if (typeof Uint8Array !== "undefined")
|
||||
return;
|
||||
|
||||
function subarray(start, end) {
|
||||
return this.slice(start, end);
|
||||
}
|
||||
|
||||
function set_(array, offset) {
|
||||
if (arguments.length < 2) offset = 0;
|
||||
for (var i = 0, n = array.length; i < n; ++i, ++offset)
|
||||
this[offset] = array[i] & 0xFF;
|
||||
}
|
||||
|
||||
function TypedArray(arg1) {
|
||||
var result;
|
||||
if (typeof arg1 === "number") {
|
||||
result = new Array(arg1);
|
||||
for (var i = 0; i < arg1; ++i)
|
||||
result[i] = 0;
|
||||
} else
|
||||
result = arg1.slice(0);
|
||||
result.subarray = subarray;
|
||||
result.buffer = result;
|
||||
result.byteLength = result.length;
|
||||
result.set = set_;
|
||||
if (typeof arg1 === "object" && arg1.buffer)
|
||||
result.buffer = arg1.buffer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
window.Uint8Array = TypedArray;
|
||||
|
||||
// we don't need support for set, byteLength for 32-bit array
|
||||
// so we can use the TypedArray as well
|
||||
window.Uint32Array = TypedArray;
|
||||
window.Int32Array = TypedArray;
|
||||
})();
|
||||
|
||||
// Object.create() ?
|
||||
(function() {
|
||||
if (typeof Object.create !== "undefined")
|
||||
return;
|
||||
|
||||
Object.create = function(proto) {
|
||||
var constructor = function() {};
|
||||
constructor.prototype = proto;
|
||||
return new constructor();
|
||||
};
|
||||
})();
|
||||
|
||||
// Object.defineProperty() ?
|
||||
(function() {
|
||||
if (typeof Object.defineProperty !== "undefined")
|
||||
return;
|
||||
|
||||
Object.defineProperty = function(obj, name, def) {
|
||||
delete obj[name];
|
||||
if ("get" in def)
|
||||
obj.__defineGetter__(name, def["get"]);
|
||||
if ("set" in def)
|
||||
obj.__defineSetter__(name, def["set"]);
|
||||
if ("value" in def) {
|
||||
obj.__defineSetter__(name, function(value) {
|
||||
this.__defineGetter__(name, function() {
|
||||
return value;
|
||||
});
|
||||
return value;
|
||||
});
|
||||
obj[name] = def.value;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
// No XMLHttpRequest.response ?
|
||||
(function() {
|
||||
var xhrPrototype = XMLHttpRequest.prototype;
|
||||
if ("response" in xhrPrototype ||
|
||||
"mozResponseArrayBuffer" in xhrPrototype ||
|
||||
"mozResponse" in xhrPrototype ||
|
||||
"responseArrayBuffer" in xhrPrototype)
|
||||
return;
|
||||
// IE ?
|
||||
if (typeof VBArray !== "undefined") {
|
||||
Object.defineProperty(xhrPrototype, "response", {
|
||||
get: function() {
|
||||
return new Uint8Array( new VBArray(this.responseBody).toArray() );
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// other browsers
|
||||
function responseTypeSetter() {
|
||||
// will be only called to set "arraybuffer"
|
||||
this.overrideMimeType("text/plain; charset=x-user-defined");
|
||||
}
|
||||
if (typeof xhrPrototype.overrideMimeType === "function") {
|
||||
Object.defineProperty(xhrPrototype, "responseType", { set: responseTypeSetter });
|
||||
}
|
||||
function responseGetter() {
|
||||
var text = this.responseText;
|
||||
var i, n = text.length;
|
||||
var result = new Uint8Array(n);
|
||||
for (i = 0; i < n; ++i)
|
||||
result[i] = text.charCodeAt(i) & 0xFF;
|
||||
return result;
|
||||
}
|
||||
Object.defineProperty(xhrPrototype, "response", { get: responseGetter });
|
||||
})();
|
||||
|
||||
// window.btoa (base64 encode function) ?
|
||||
(function() {
|
||||
if ("btoa" in window)
|
||||
return;
|
||||
|
||||
var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
window.btoa = function(chars) {
|
||||
var buffer = "";
|
||||
var i, n;
|
||||
for (i = 0, n = chars.length; i < n; i += 3) {
|
||||
var b1 = chars.charCodeAt(i) & 0xFF;
|
||||
var b2 = chars.charCodeAt(i + 1) & 0xFF;
|
||||
var b3 = chars.charCodeAt(i + 2) & 0xFF;
|
||||
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
||||
var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
|
||||
buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
})();
|
||||
|
||||
// Function.prototype.bind ?
|
||||
(function() {
|
||||
if (typeof Function.prototype.bind !== "undefined")
|
||||
return;
|
||||
|
||||
Function.prototype.bind = function(obj) {
|
||||
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
|
||||
var binded = function(tailArgs) {
|
||||
var args = headArgs.concat(tailArgs);
|
||||
return fn.apply(obj, args);
|
||||
};
|
||||
return binded;
|
||||
};
|
||||
})();
|
@ -4,6 +4,7 @@
|
||||
<title>pdf.js Multi-Page Viewer</title>
|
||||
<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="compatibility.js"></script>
|
||||
<script type="text/javascript" src="../pdf.js"></script>
|
||||
<script type="text/javascript" src="../fonts.js"></script>
|
||||
<script type="text/javascript" src="../crypto.js"></script>
|
||||
@ -34,7 +35,7 @@
|
||||
</select>
|
||||
<span class="label">Zoom</span>
|
||||
</span>
|
||||
<span class="control">
|
||||
<span class="control" id="fileWrapper">
|
||||
<span id="openFileButton"></span>
|
||||
<input type="file" id="fileInput"/>
|
||||
<span class="label">Open File</span>
|
||||
|
@ -1,8 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple pdf.js page viewer</title>
|
||||
<link rel="stylesheet" href="viewer.css"></link>
|
||||
|
||||
<script type="text/javascript" src="compatibility.js"></script>
|
||||
<script type="text/javascript" src="viewer.js"></script>
|
||||
<script type="text/javascript" src="../pdf.js"></script>
|
||||
<script type="text/javascript" src="../fonts.js"></script>
|
||||
|
@ -287,7 +287,7 @@ function WorkerPDFDoc(canvas) {
|
||||
var rule = ("@font-face { font-family:'" + data.fontName +
|
||||
"';src:" + url + '}');
|
||||
var styleSheet = document.styleSheets[0];
|
||||
styleSheet.insertRule(rule, styleSheet.length);
|
||||
styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
||||
|
||||
// Just adding the font-face to the DOM doesn't make it load. It
|
||||
// seems it's loaded once Gecko notices it's used. Therefore,
|
||||
|
Loading…
x
Reference in New Issue
Block a user