Browse Source

Fix up late patches to pdf.js and web/compatibility.js.

Rob Sayre 14 years ago
parent
commit
699c91b0aa
  1. 22
      pdf.js
  2. 61
      web/compatibility.js

22
pdf.js

@ -3764,7 +3764,7 @@ var CanvasGraphics = (function() {
transform: function(a, b, c, d, e, f) { transform: function(a, b, c, d, e, f) {
this.ctx.transform(a, b, c, d, e, f); this.ctx.transform(a, b, c, d, e, f);
}, },
// Path // Path
moveTo: function(x, y) { moveTo: function(x, y) {
this.ctx.moveTo(x, y); this.ctx.moveTo(x, y);
@ -3825,7 +3825,7 @@ var CanvasGraphics = (function() {
endPath: function() { endPath: function() {
this.consumePath(); this.consumePath();
}, },
// Clipping // Clipping
clip: function() { clip: function() {
this.pendingClip = NORMAL_CLIP; this.pendingClip = NORMAL_CLIP;
@ -3833,7 +3833,7 @@ var CanvasGraphics = (function() {
eoClip: function() { eoClip: function() {
this.pendingClip = EO_CLIP; this.pendingClip = EO_CLIP;
}, },
// Text // Text
beginText: function() { beginText: function() {
this.current.textMatrix = IDENTITY_MATRIX; this.current.textMatrix = IDENTITY_MATRIX;
@ -3858,27 +3858,27 @@ var CanvasGraphics = (function() {
this.current.leading = leading; this.current.leading = leading;
}, },
setFont: function(fontRef, size) { setFont: function(fontRef, size) {
var font = this.xref.fetchIfRef(this.res.get("Font")); var font = this.xref.fetchIfRef(this.res.get('Font'));
if (!IsDict(font)) if (!IsDict(font))
return; return;
font = font.get(fontRef.name); font = font.get(fontRef.name);
font = this.xref.fetchIfRef(font); font = this.xref.fetchIfRef(font);
if (!font) if (!font)
return; return;
var fontName = ""; var fontName = '';
var fontDescriptor = font.get("FontDescriptor"); var fontDescriptor = font.get('FontDescriptor');
if (fontDescriptor && fontDescriptor.num) { if (fontDescriptor && fontDescriptor.num) {
var fontDescriptor = this.xref.fetchIfRef(fontDescriptor); var fontDescriptor = this.xref.fetchIfRef(fontDescriptor);
fontName = fontDescriptor.get("FontName").name.replace("+", "_"); fontName = fontDescriptor.get('FontName').name.replace('+', '_');
} }
if (!fontName) { if (!fontName) {
// TODO: fontDescriptor is not available, fallback to default font // TODO: fontDescriptor is not available, fallback to default font
fontName = 'sans-serif'; fontName = 'sans-serif';
} }
this.current.fontName = fontName; this.current.fontName = fontName;
this.current.fontSize = size; this.current.fontSize = size;

61
web/compatibility.js

@ -3,7 +3,7 @@
// Checking if the typed arrays are supported // Checking if the typed arrays are supported
(function() { (function() {
if (typeof Uint8Array !== "undefined") if (typeof Uint8Array !== 'undefined')
return; return;
function subarray(start, end) { function subarray(start, end) {
@ -18,7 +18,7 @@
function TypedArray(arg1) { function TypedArray(arg1) {
var result; var result;
if (typeof arg1 === "number") { if (typeof arg1 === 'number') {
result = new Array(arg1); result = new Array(arg1);
for (var i = 0; i < arg1; ++i) for (var i = 0; i < arg1; ++i)
result[i] = 0; result[i] = 0;
@ -28,23 +28,23 @@
result.buffer = result; result.buffer = result;
result.byteLength = result.length; result.byteLength = result.length;
result.set = set_; result.set = set_;
if (typeof arg1 === "object" && arg1.buffer) if (typeof arg1 === 'object' && arg1.buffer)
result.buffer = arg1.buffer; result.buffer = arg1.buffer;
return result; return result;
} }
window.Uint8Array = TypedArray; window.Uint8Array = TypedArray;
// we don't need support for set, byteLength for 32-bit array // we don't need support for set, byteLength for 32-bit array
// so we can use the TypedArray as well // so we can use the TypedArray as well
window.Uint32Array = TypedArray; window.Uint32Array = TypedArray;
window.Int32Array = TypedArray; window.Int32Array = TypedArray;
})(); })();
// Object.create() ? // Object.create() ?
(function() { (function() {
if (typeof Object.create !== "undefined") if (typeof Object.create !== 'undefined')
return; return;
Object.create = function(proto) { Object.create = function(proto) {
@ -56,16 +56,16 @@
// Object.defineProperty() ? // Object.defineProperty() ?
(function() { (function() {
if (typeof Object.defineProperty !== "undefined") if (typeof Object.defineProperty !== 'undefined')
return; return;
Object.defineProperty = function(obj, name, def) { Object.defineProperty = function(obj, name, def) {
delete obj[name]; delete obj[name];
if ("get" in def) if ('get' in def)
obj.__defineGetter__(name, def["get"]); obj.__defineGetter__(name, def['get']);
if ("set" in def) if ('set' in def)
obj.__defineSetter__(name, def["set"]); obj.__defineSetter__(name, def['set']);
if ("value" in def) { if ('value' in def) {
obj.__defineSetter__(name, function(value) { obj.__defineSetter__(name, function(value) {
this.__defineGetter__(name, function() { this.__defineGetter__(name, function() {
return value; return value;
@ -80,16 +80,16 @@
// No XMLHttpRequest.response ? // No XMLHttpRequest.response ?
(function() { (function() {
var xhrPrototype = XMLHttpRequest.prototype; var xhrPrototype = XMLHttpRequest.prototype;
if ("response" in xhrPrototype || if ('response' in xhrPrototype ||
"mozResponseArrayBuffer" in xhrPrototype || 'mozResponseArrayBuffer' in xhrPrototype ||
"mozResponse" in xhrPrototype || 'mozResponse' in xhrPrototype ||
"responseArrayBuffer" in xhrPrototype) 'responseArrayBuffer' in xhrPrototype)
return; return;
// IE ? // IE ?
if (typeof VBArray !== "undefined") { if (typeof VBArray !== 'undefined') {
Object.defineProperty(xhrPrototype, "response", { Object.defineProperty(xhrPrototype, 'response', {
get: function() { get: function() {
return new Uint8Array( new VBArray(this.responseBody).toArray() ); return new Uint8Array(new VBArray(this.responseBody).toArray());
} }
}); });
return; return;
@ -98,10 +98,11 @@
// other browsers // other browsers
function responseTypeSetter() { function responseTypeSetter() {
// will be only called to set "arraybuffer" // will be only called to set "arraybuffer"
this.overrideMimeType("text/plain; charset=x-user-defined"); this.overrideMimeType('text/plain; charset=x-user-defined');
} }
if (typeof xhrPrototype.overrideMimeType === "function") { if (typeof xhrPrototype.overrideMimeType === 'function') {
Object.defineProperty(xhrPrototype, "responseType", { set: responseTypeSetter }); Object.defineProperty(xhrPrototype, 'responseType',
{ set: responseTypeSetter });
} }
function responseGetter() { function responseGetter() {
var text = this.responseText; var text = this.responseText;
@ -111,18 +112,19 @@
result[i] = text.charCodeAt(i) & 0xFF; result[i] = text.charCodeAt(i) & 0xFF;
return result; return result;
} }
Object.defineProperty(xhrPrototype, "response", { get: responseGetter }); Object.defineProperty(xhrPrototype, 'response', { get: responseGetter });
})(); })();
// window.btoa (base64 encode function) ? // window.btoa (base64 encode function) ?
(function() { (function() {
if ("btoa" in window) if ('btoa' in window)
return; return;
var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
window.btoa = function(chars) { window.btoa = function(chars) {
var buffer = ""; var buffer = '';
var i, n; var i, n;
for (i = 0, n = chars.length; i < n; i += 3) { for (i = 0, n = chars.length; i < n; i += 3) {
var b1 = chars.charCodeAt(i) & 0xFF; var b1 = chars.charCodeAt(i) & 0xFF;
@ -131,15 +133,16 @@
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4); var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64; var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
var d4 = i + 2 < n ? (b3 & 0x3F) : 64; var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4); buffer += (digits.charAt(d1) + digits.charAt(d2) +
digits.charAt(d3) + digits.charAt(d4));
} }
return buffer; return buffer;
}; };
})(); })();
// Function.prototype.bind ? // Function.prototype.bind ?
(function() { (function() {
if (typeof Function.prototype.bind !== "undefined") if (typeof Function.prototype.bind !== 'undefined')
return; return;
Function.prototype.bind = function(obj) { Function.prototype.bind = function(obj) {

Loading…
Cancel
Save