| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 | 1×
1×
1×
1×
2×
1×
1×
12×
2×
2×
4×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "./../enum", "./../pdf-color", "./pdf-color-blend"], function (require, exports, enum_1, pdf_color_1, pdf_color_blend_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PdfBlend = (function () {
function PdfBlend(count) {
this.precision = 1000;
}
Object.defineProperty(PdfBlend.prototype, "factors", {
get: function () {
return this.mFactors;
},
set: function (value) {
if ((value == null)) {
throw new Error('ArgumentNullException : Factors');
}
this.mFactors = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfBlend.prototype, "positions", {
get: function () {
return this.mPositions;
},
set: function (value) {
var positionarray = value;
for (var i = 0; i < positionarray.length; i++) {
Iif (((positionarray[i] < 0) || (positionarray[i] > 1))) {
positionarray[i] = 0;
}
}
this.mPositions = positionarray;
this.mPositions = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfBlend.prototype, "count", {
get: function () {
return this.mCount;
},
enumerable: true,
configurable: true
});
PdfBlend.prototype.generateColorBlend = function (colours, colorSpace) {
if ((colours == null)) {
throw new Error('ArgumentNullException : colours');
}
if ((this.positions == null)) {
this.positions = [0];
}
var cBlend = new pdf_color_blend_1.PdfColorBlend(this.count);
var positions = this.positions;
var clrs = null;
if ((positions.length === 1)) {
positions = [3];
positions[0] = 0;
positions[1] = this.positions[0];
positions[2] = 1;
clrs = new Array(3);
clrs[0] = colours[0];
clrs[1] = colours[0];
clrs[2] = colours[1];
}
else {
var c1 = colours[0];
var c2 = colours[1];
clrs = new Array(this.count);
var i = 0;
var count = this.count;
for (i = 0; i < count; ++i) {
clrs[i] = this.interpolate(this.mFactors[i], c1, c2, colorSpace);
}
}
cBlend.positions = positions;
cBlend.colors = clrs;
return cBlend;
};
PdfBlend.prototype.clonePdfBlend = function () {
var blend = this;
if ((this.mFactors != null)) {
blend.factors = (this.mFactors);
}
if ((this.positions != null)) {
blend.positions = (this.positions);
}
return blend;
};
PdfBlend.prototype.gcd = function (u, v) {
if (typeof u === 'number' && typeof v === 'number' && typeof v !== 'undefined') {
if (((u < 0) || (u > 1))) {
throw new Error('ArgumentOutOfRangeException : u');
}
if (((v < 0) || (v > 1))) {
throw new Error('ArgumentOutOfRangeException : v');
}
var iU = (Math.max(1, (u * this.precision)));
var iV = (Math.max(1, (v * this.precision)));
var iResult = this.gcdInt(iU, iV);
var result = ((iResult) / this.precision);
return result;
}
else {
var values = u;
if ((values == null)) {
throw new Error('ArgumentNullException : values');
}
if ((values.length < 1)) {
throw new Error('ArgumentException : Not enough values in the array. - values');
}
var gcd = values[0];
if ((values.length > 1)) {
var count = values.length;
for (var i = 1; i < count; ++i) {
gcd = this.gcd(values[i], gcd);
if ((gcd === (1 / this.precision))) {
break;
}
}
}
return gcd;
}
};
PdfBlend.prototype.gcdInt = function (u, v) {
if ((u <= 0)) {
throw new Error('ArgumentOutOfRangeException' + u + 'The arguments cannot be less or equal to zero.');
}
if ((v <= 0)) {
throw new Error('ArgumentOutOfRangeException' + v + 'The arguments cannot be less or equal to zero.');
}
if (((u === 1) || (v === 1))) {
return 1;
}
var shift = 0;
while (this.isEven(u, v)) {
++shift;
u >>= 1;
v >>= 1;
}
while (((u & 1) <= 0)) {
u >>= 1;
}
do {
while ((v & 1) <= 0) {
v >>= 1;
}
if (u > v) {
var t = v;
v = u;
u = t;
}
v = v - u;
} while (v !== 0);
return (u << shift);
};
PdfBlend.prototype.isEven = function (arg1, arg2) {
if (typeof arg2 === 'number' && typeof arg2 !== 'undefined') {
var result = true;
result = (result && ((arg1 & 1) <= 0));
result = (result && ((arg2 & 1) <= 0));
return result;
}
else {
return ((arg1 & 1) <= 0);
}
};
PdfBlend.prototype.interpolate = function (t, color1, color2, colorSpace) {
if (color1 instanceof pdf_color_1.PdfColor) {
var color = new pdf_color_1.PdfColor();
switch (colorSpace) {
case enum_1.PdfColorSpace.Rgb:
var red = (this.interpolate(t, color1.red, color2.red));
var green = (this.interpolate(t, color1.green, color2.green));
var blue = (this.interpolate(t, color1.blue, color2.blue));
color = new pdf_color_1.PdfColor(red, green, blue);
break;
case enum_1.PdfColorSpace.GrayScale:
var gray = (this.interpolate(t, color1.gray, color2.gray));
color = new pdf_color_1.PdfColor(gray);
break;
case enum_1.PdfColorSpace.Cmyk:
var cyan = (this.interpolate(t, color1.c, color2.c));
var magenta = (this.interpolate(t, color1.m, color2.m));
var yellow = (this.interpolate(t, color1.y, color2.y));
var black = (this.interpolate(t, color1.k, color2.k));
color = new pdf_color_1.PdfColor(cyan, magenta, yellow, black);
break;
}
return color;
}
else {
var t0 = 0;
var t1 = 1;
var result = 0;
if ((t === t0)) {
result = color1;
}
else if ((t === t1)) {
result = color2;
}
else {
result = (color1 + ((t - t0) * ((color2 - color1) / (t1 - t0))));
}
return result;
}
};
return PdfBlend;
}());
exports.PdfBlend = PdfBlend;
});
|