whitespace fixes and move inheriting of dict props into the page since it only happens there

This commit is contained in:
Andreas Gal 2011-06-21 15:05:33 -04:00
parent bad69c984c
commit 5a96404705

56
pdf.js
View File

@ -784,16 +784,6 @@ var Dict = (function() {
get2: function(key1, key2) { get2: function(key1, key2) {
return this.get(key1) || this.get(key2); return this.get(key1) || this.get(key2);
}, },
getOrInherit: function(key, xref) {
var obj = this.map[key];
var dict = this;
while (!obj && dict) {
dict = xref.fetchIfRef(dict.get("Parent"));
if (dict)
obj = dict.get(key);
}
return obj;
},
has: function(key) { has: function(key) {
return key in this.map; return key in this.map;
}, },
@ -1707,15 +1697,28 @@ var Page = (function() {
} }
constructor.prototype = { constructor.prototype = {
getPageProp: function(key) {
return this.pageDict.get(key);
},
inheritPageProp: function(key) {
var dict = this.pageDict;
var obj = dict.get(key);
while (!obj) {
dict = this.xref.fetchIfRef(dict.get("Parent"));
if (!dict)
break;
obj = dict.get(key);
}
return obj;
},
get content() { get content() {
return shadow(this, "content", this.pageDict.get("Contents")); return shadow(this, "content", this.getPageProp("Contents"));
}, },
get resources() { get resources() {
return shadow(this, "resources", return shadow(this, "resources", this.inheritPageProp("Resources"));
this.pageDict.getOrInherit("Resources", this.xref));
}, },
get mediaBox() { get mediaBox() {
var obj = this.pageDict.getOrInherit("MediaBox", this.xref); var obj = this.inheritPageProp("MediaBox");
return shadow(this, "mediaBox", ((IsArray(obj) && obj.length == 4) return shadow(this, "mediaBox", ((IsArray(obj) && obj.length == 4)
? obj ? obj
: null)); : null));
@ -2890,7 +2893,6 @@ var CanvasGraphics = (function() {
shadingFill: function(entryRef) { shadingFill: function(entryRef) {
var xref = this.xref; var xref = this.xref;
var res = this.res; var res = this.res;
var shadingRes = xref.fetchIfRef(res.get("Shading")); var shadingRes = xref.fetchIfRef(res.get("Shading"));
if (!shadingRes) if (!shadingRes)
error("No shading resource found"); error("No shading resource found");
@ -2915,8 +2917,10 @@ var CanvasGraphics = (function() {
if (background) if (background)
TODO("handle background colors"); TODO("handle background colors");
const types = [null, this.fillFunctionShading, const types = [null,
this.fillAxialShading, this.fillRadialShading]; this.fillFunctionShading,
this.fillAxialShading,
this.fillRadialShading];
var typeNum = shading.get("ShadingType"); var typeNum = shading.get("ShadingType");
var fillFn = types[typeNum]; var fillFn = types[typeNum];
@ -3101,7 +3105,6 @@ var CanvasGraphics = (function() {
csStream = colorSpaces.get(csStream); csStream = colorSpaces.get(csStream);
var colorSpace = new ColorSpace(xref, csStream); var colorSpace = new ColorSpace(xref, csStream);
var decode = dict.get2("Decode", "D"); var decode = dict.get2("Decode", "D");
TODO("create color map"); TODO("create color map");
@ -3313,7 +3316,6 @@ var ColorSpace = (function() {
break; break;
case "ICCBased": case "ICCBased":
var dict = stream.dict; var dict = stream.dict;
this.stream = stream; this.stream = stream;
this.dict = dict; this.dict = dict;
this.numComps = dict.get("N"); this.numComps = dict.get("N");
@ -3338,9 +3340,11 @@ var PDFFunction = (function() {
if (!dict) if (!dict)
dict = fn; dict = fn;
const types = [this.constructSampled, null, const types = [this.constructSampled,
this.constructInterpolated, this.constructStiched, null,
this.constructPostScript]; this.constructInterpolated,
this.constructStiched,
this.constructPostScript];
var typeNum = dict.get("FunctionType"); var typeNum = dict.get("FunctionType");
var typeFn = types[typeNum]; var typeFn = types[typeNum];
@ -3406,9 +3410,8 @@ var PDFFunction = (function() {
// encode // encode
v = encode[i2] + ((v - domain[i2]) * v = encode[i2] + ((v - domain[i2]) *
(encode[i2 + 1] - encode[i2]) / (encode[i2 + 1] - encode[i2]) /
(domain[i2 + 1] - domain[i2])); (domain[i2 + 1] - domain[i2]));
// clip to the size // clip to the size
args[i] = clip(v, 0, size[i] - 1); args[i] = clip(v, 0, size[i] - 1);
} }
@ -3435,8 +3438,7 @@ var PDFFunction = (function() {
var i2 = i * 2; var i2 = i * 2;
// decode // decode
v = decode[i2] + (v * (decode[i2 + 1] - decode[i2]) / v = decode[i2] + (v * (decode[i2 + 1] - decode[i2]) /
((1 << bps) - 1)); ((1 << bps) - 1));
// clip to the domain // clip to the domain
output.push(clip(v, range[i2], range[i2 + 1])); output.push(clip(v, range[i2], range[i2 + 1]));
} }