added stiched functions
This commit is contained in:
parent
ac1000cc86
commit
a48a74862a
57
pdf.js
57
pdf.js
@ -5727,7 +5727,7 @@ var PDFFunction = (function() {
|
|||||||
if (!typeFn)
|
if (!typeFn)
|
||||||
error('Unknown type of function');
|
error('Unknown type of function');
|
||||||
|
|
||||||
typeFn.call(this, fn, dict);
|
typeFn.call(this, fn, dict, xref);
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
@ -5872,9 +5872,58 @@ var PDFFunction = (function() {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
constructStiched: function() {
|
constructStiched: function(fn, dict, xref) {
|
||||||
TODO('unhandled type of function');
|
var domain = dict.get('Domain');
|
||||||
this.func = function() { return [255, 105, 180]; }
|
var range = dict.get('Range');
|
||||||
|
|
||||||
|
if (!domain)
|
||||||
|
error('No domain');
|
||||||
|
|
||||||
|
var inputSize = domain.length / 2;
|
||||||
|
if (inputSize != 1)
|
||||||
|
error('Bad domain for stiched function');
|
||||||
|
|
||||||
|
var fnRefs = dict.get('Functions');
|
||||||
|
var fns = [];
|
||||||
|
for (var i = 0, ii = fnRefs.length; i < ii; ++i)
|
||||||
|
fns.push(new PDFFunction(xref, xref.fetchIfRef(fnRefs[i])));
|
||||||
|
|
||||||
|
var bounds = dict.get('Bounds');
|
||||||
|
var encode = dict.get('Encode');
|
||||||
|
|
||||||
|
this.func = function(args) {
|
||||||
|
var clip = function(v, min, max) {
|
||||||
|
if (v > max)
|
||||||
|
v = max;
|
||||||
|
else if (v < min)
|
||||||
|
v = min;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clip to domain
|
||||||
|
var v = clip(args[0], domain[0], domain[1]);
|
||||||
|
// calulate which bound the value is in
|
||||||
|
for (var i = 0, ii = bounds.length; i < ii; ++i) {
|
||||||
|
if (v < bounds[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode value into domain of function
|
||||||
|
var dmin = domain[0];
|
||||||
|
if (i > 0)
|
||||||
|
dmin = bounds[i - 1];
|
||||||
|
var dmax = domain[1];
|
||||||
|
if (i < bounds.length)
|
||||||
|
dmax = bounds[i];
|
||||||
|
|
||||||
|
var rmin = encode[2 * i];
|
||||||
|
var rmax = encode[2 * i + 1];
|
||||||
|
|
||||||
|
var v2 = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
|
||||||
|
|
||||||
|
// call the appropropriate function
|
||||||
|
return fns[i].func([v2]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
constructPostScript: function() {
|
constructPostScript: function() {
|
||||||
TODO('unhandled type of function');
|
TODO('unhandled type of function');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user