amcharts.rb 3.1.1.3 → 3.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,230 @@
1
+ /** @preserve
2
+ jsPDF addImage plugin (JPEG only at this time)
3
+ Copyright (c) 2012 https://github.com/siefkenj/
4
+ */
5
+
6
+ /**
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ * ====================================================================
26
+ */
27
+
28
+ ;(function(jsPDFAPI) {
29
+ 'use strict'
30
+
31
+ var namespace = 'addImage_'
32
+
33
+ // takes a string imgData containing the raw bytes of
34
+ // a jpeg image and returns [width, height]
35
+ // Algorithm from: http://www.64lines.com/jpeg-width-height
36
+ var getJpegSize = function(imgData) {
37
+ 'use strict'
38
+ var width, height;
39
+ // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
40
+ if (!imgData.charCodeAt(0) === 0xff ||
41
+ !imgData.charCodeAt(1) === 0xd8 ||
42
+ !imgData.charCodeAt(2) === 0xff ||
43
+ !imgData.charCodeAt(3) === 0xe0 ||
44
+ !imgData.charCodeAt(6) === 'J'.charCodeAt(0) ||
45
+ !imgData.charCodeAt(7) === 'F'.charCodeAt(0) ||
46
+ !imgData.charCodeAt(8) === 'I'.charCodeAt(0) ||
47
+ !imgData.charCodeAt(9) === 'F'.charCodeAt(0) ||
48
+ !imgData.charCodeAt(10) === 0x00) {
49
+ throw new Error('getJpegSize requires a binary jpeg file')
50
+ }
51
+ var blockLength = imgData.charCodeAt(4)*256 + imgData.charCodeAt(5);
52
+ var i = 4, len = imgData.length;
53
+ while ( i < len ) {
54
+ i += blockLength;
55
+ if (imgData.charCodeAt(i) !== 0xff) {
56
+ throw new Error('getJpegSize could not find the size of the image');
57
+ }
58
+ if (imgData.charCodeAt(i+1) === 0xc0 || //(SOF) Huffman - Baseline DCT
59
+ imgData.charCodeAt(i+1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
60
+ imgData.charCodeAt(i+1) === 0xc2 || // Progressive DCT (SOF2)
61
+ imgData.charCodeAt(i+1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
62
+ imgData.charCodeAt(i+1) === 0xc4 || // Differential sequential DCT (SOF5)
63
+ imgData.charCodeAt(i+1) === 0xc5 || // Differential progressive DCT (SOF6)
64
+ imgData.charCodeAt(i+1) === 0xc6 || // Differential spatial (SOF7)
65
+ imgData.charCodeAt(i+1) === 0xc7) {
66
+ height = imgData.charCodeAt(i+5)*256 + imgData.charCodeAt(i+6);
67
+ width = imgData.charCodeAt(i+7)*256 + imgData.charCodeAt(i+8);
68
+ return [width, height];
69
+ } else {
70
+ i += 2;
71
+ blockLength = imgData.charCodeAt(i)*256 + imgData.charCodeAt(i+1)
72
+ }
73
+ }
74
+ }
75
+ // Image functionality ported from pdf.js
76
+ , putImage = function(img) {
77
+ var objectNumber = this.internal.newObject()
78
+ , out = this.internal.write
79
+ , putStream = this.internal.putStream
80
+
81
+ img['n'] = objectNumber
82
+
83
+ out('<</Type /XObject')
84
+ out('/Subtype /Image')
85
+ out('/Width ' + img['w'])
86
+ out('/Height ' + img['h'])
87
+ if (img['cs'] === 'Indexed') {
88
+ out('/ColorSpace [/Indexed /DeviceRGB '
89
+ + (img['pal'].length / 3 - 1) + ' ' + (objectNumber + 1)
90
+ + ' 0 R]');
91
+ } else {
92
+ out('/ColorSpace /' + img['cs']);
93
+ if (img['cs'] === 'DeviceCMYK') {
94
+ out('/Decode [1 0 1 0 1 0 1 0]');
95
+ }
96
+ }
97
+ out('/BitsPerComponent ' + img['bpc']);
98
+ if ('f' in img) {
99
+ out('/Filter /' + img['f']);
100
+ }
101
+ if ('dp' in img) {
102
+ out('/DecodeParms <<' + img['dp'] + '>>');
103
+ }
104
+ if ('trns' in img && img['trns'].constructor == Array) {
105
+ var trns = '';
106
+ for ( var i = 0; i < img['trns'].length; i++) {
107
+ trns += (img[trns][i] + ' ' + img['trns'][i] + ' ');
108
+ out('/Mask [' + trns + ']');
109
+ }
110
+ }
111
+ if ('smask' in img) {
112
+ out('/SMask ' + (objectNumber + 1) + ' 0 R');
113
+ }
114
+ out('/Length ' + img['data'].length + '>>');
115
+
116
+ putStream(img['data']);
117
+
118
+ out('endobj');
119
+ }
120
+ , putResourcesCallback = function() {
121
+ var images = this.internal.collections[namespace + 'images']
122
+ for ( var i in images ) {
123
+ putImage.call(this, images[i])
124
+ }
125
+ }
126
+ , putXObjectsDictCallback = function(){
127
+ var images = this.internal.collections[namespace + 'images']
128
+ , out = this.internal.write
129
+ , image
130
+ for (var i in images) {
131
+ image = images[i]
132
+ out(
133
+ '/I' + image['i']
134
+ , image['n']
135
+ , '0'
136
+ , 'R'
137
+ )
138
+ }
139
+ }
140
+
141
+ jsPDFAPI.addImage = function(imageData, format, x, y, w, h) {
142
+ 'use strict'
143
+ if (typeof imageData === 'object' && imageData.nodeType === 1) {
144
+ var canvas = document.createElement('canvas');
145
+ canvas.width = imageData.clientWidth;
146
+ canvas.height = imageData.clientHeight;
147
+
148
+ var ctx = canvas.getContext('2d');
149
+ if (!ctx) {
150
+ throw ('addImage requires canvas to be supported by browser.');
151
+ }
152
+ ctx.drawImage(imageData, 0, 0, canvas.width, canvas.height);
153
+ imageData = canvas.toDataURL('image/jpeg');
154
+ format = "JPEG";
155
+ }
156
+ if (format.toUpperCase() !== 'JPEG') {
157
+ throw new Error('addImage currently only supports format \'JPEG\', not \''+format+'\'');
158
+ }
159
+
160
+ var imageIndex
161
+ , images = this.internal.collections[namespace + 'images']
162
+ , coord = this.internal.getCoordinateString
163
+ , vcoord = this.internal.getVerticalCoordinateString;
164
+
165
+ // Detect if the imageData is raw binary or Data URL
166
+ if (imageData.substring(0, 23) === 'data:image/jpeg;base64,') {
167
+ imageData = atob(imageData.replace('data:image/jpeg;base64,', ''));
168
+ }
169
+
170
+ if (images){
171
+ // this is NOT the first time this method is ran on this instance of jsPDF object.
172
+ imageIndex = Object.keys ?
173
+ Object.keys(images).length :
174
+ (function(o){
175
+ var i = 0
176
+ for (var e in o){if(o.hasOwnProperty(e)){ i++ }}
177
+ return i
178
+ })(images)
179
+ } else {
180
+ // this is the first time this method is ran on this instance of jsPDF object.
181
+ imageIndex = 0
182
+ this.internal.collections[namespace + 'images'] = images = {}
183
+ this.internal.events.subscribe('putResources', putResourcesCallback)
184
+ this.internal.events.subscribe('putXobjectDict', putXObjectsDictCallback)
185
+ }
186
+
187
+ var dims = getJpegSize(imageData);
188
+ var info = {
189
+ w : dims[0],
190
+ h : dims[1],
191
+ cs : 'DeviceRGB',
192
+ bpc : 8,
193
+ f : 'DCTDecode',
194
+ i : imageIndex,
195
+ data : imageData
196
+ // n: objectNumber will be added by putImage code
197
+
198
+ };
199
+ images[imageIndex] = info
200
+ if (!w && !h) {
201
+ w = -96;
202
+ h = -96;
203
+ }
204
+ if (w < 0) {
205
+ w = (-1) * info['w'] * 72 / w / this.internal.scaleFactor;
206
+ }
207
+ if (h < 0) {
208
+ h = (-1) * info['h'] * 72 / h / this.internal.scaleFactor;
209
+ }
210
+ if (w === 0) {
211
+ w = h * info['w'] / info['h'];
212
+ }
213
+ if (h === 0) {
214
+ h = w * info['h'] / info['w'];
215
+ }
216
+
217
+ this.internal.write(
218
+ 'q'
219
+ , coord(w)
220
+ , '0 0'
221
+ , coord(h) // TODO: check if this should be shifted by vcoord
222
+ , coord(x)
223
+ , vcoord(y + h)
224
+ , 'cm /I'+info['i']
225
+ , 'Do Q'
226
+ )
227
+
228
+ return this
229
+ }
230
+ })(jsPDF.API)
@@ -0,0 +1,288 @@
1
+ /**
2
+ * A class to parse color values
3
+ * @author Stoyan Stefanov <sstoo@gmail.com>
4
+ * @link http://www.phpied.com/rgb-color-parser-in-javascript/
5
+ * @license Use it if you like it
6
+ */
7
+ function RGBColor(color_string)
8
+ {
9
+ this.ok = false;
10
+
11
+ // strip any leading #
12
+ if (color_string.charAt(0) == '#') { // remove # if any
13
+ color_string = color_string.substr(1,6);
14
+ }
15
+
16
+ color_string = color_string.replace(/ /g,'');
17
+ color_string = color_string.toLowerCase();
18
+
19
+ // before getting into regexps, try simple matches
20
+ // and overwrite the input
21
+ var simple_colors = {
22
+ aliceblue: 'f0f8ff',
23
+ antiquewhite: 'faebd7',
24
+ aqua: '00ffff',
25
+ aquamarine: '7fffd4',
26
+ azure: 'f0ffff',
27
+ beige: 'f5f5dc',
28
+ bisque: 'ffe4c4',
29
+ black: '000000',
30
+ blanchedalmond: 'ffebcd',
31
+ blue: '0000ff',
32
+ blueviolet: '8a2be2',
33
+ brown: 'a52a2a',
34
+ burlywood: 'deb887',
35
+ cadetblue: '5f9ea0',
36
+ chartreuse: '7fff00',
37
+ chocolate: 'd2691e',
38
+ coral: 'ff7f50',
39
+ cornflowerblue: '6495ed',
40
+ cornsilk: 'fff8dc',
41
+ crimson: 'dc143c',
42
+ cyan: '00ffff',
43
+ darkblue: '00008b',
44
+ darkcyan: '008b8b',
45
+ darkgoldenrod: 'b8860b',
46
+ darkgray: 'a9a9a9',
47
+ darkgreen: '006400',
48
+ darkkhaki: 'bdb76b',
49
+ darkmagenta: '8b008b',
50
+ darkolivegreen: '556b2f',
51
+ darkorange: 'ff8c00',
52
+ darkorchid: '9932cc',
53
+ darkred: '8b0000',
54
+ darksalmon: 'e9967a',
55
+ darkseagreen: '8fbc8f',
56
+ darkslateblue: '483d8b',
57
+ darkslategray: '2f4f4f',
58
+ darkturquoise: '00ced1',
59
+ darkviolet: '9400d3',
60
+ deeppink: 'ff1493',
61
+ deepskyblue: '00bfff',
62
+ dimgray: '696969',
63
+ dodgerblue: '1e90ff',
64
+ feldspar: 'd19275',
65
+ firebrick: 'b22222',
66
+ floralwhite: 'fffaf0',
67
+ forestgreen: '228b22',
68
+ fuchsia: 'ff00ff',
69
+ gainsboro: 'dcdcdc',
70
+ ghostwhite: 'f8f8ff',
71
+ gold: 'ffd700',
72
+ goldenrod: 'daa520',
73
+ gray: '808080',
74
+ green: '008000',
75
+ greenyellow: 'adff2f',
76
+ honeydew: 'f0fff0',
77
+ hotpink: 'ff69b4',
78
+ indianred : 'cd5c5c',
79
+ indigo : '4b0082',
80
+ ivory: 'fffff0',
81
+ khaki: 'f0e68c',
82
+ lavender: 'e6e6fa',
83
+ lavenderblush: 'fff0f5',
84
+ lawngreen: '7cfc00',
85
+ lemonchiffon: 'fffacd',
86
+ lightblue: 'add8e6',
87
+ lightcoral: 'f08080',
88
+ lightcyan: 'e0ffff',
89
+ lightgoldenrodyellow: 'fafad2',
90
+ lightgrey: 'd3d3d3',
91
+ lightgreen: '90ee90',
92
+ lightpink: 'ffb6c1',
93
+ lightsalmon: 'ffa07a',
94
+ lightseagreen: '20b2aa',
95
+ lightskyblue: '87cefa',
96
+ lightslateblue: '8470ff',
97
+ lightslategray: '778899',
98
+ lightsteelblue: 'b0c4de',
99
+ lightyellow: 'ffffe0',
100
+ lime: '00ff00',
101
+ limegreen: '32cd32',
102
+ linen: 'faf0e6',
103
+ magenta: 'ff00ff',
104
+ maroon: '800000',
105
+ mediumaquamarine: '66cdaa',
106
+ mediumblue: '0000cd',
107
+ mediumorchid: 'ba55d3',
108
+ mediumpurple: '9370d8',
109
+ mediumseagreen: '3cb371',
110
+ mediumslateblue: '7b68ee',
111
+ mediumspringgreen: '00fa9a',
112
+ mediumturquoise: '48d1cc',
113
+ mediumvioletred: 'c71585',
114
+ midnightblue: '191970',
115
+ mintcream: 'f5fffa',
116
+ mistyrose: 'ffe4e1',
117
+ moccasin: 'ffe4b5',
118
+ navajowhite: 'ffdead',
119
+ navy: '000080',
120
+ oldlace: 'fdf5e6',
121
+ olive: '808000',
122
+ olivedrab: '6b8e23',
123
+ orange: 'ffa500',
124
+ orangered: 'ff4500',
125
+ orchid: 'da70d6',
126
+ palegoldenrod: 'eee8aa',
127
+ palegreen: '98fb98',
128
+ paleturquoise: 'afeeee',
129
+ palevioletred: 'd87093',
130
+ papayawhip: 'ffefd5',
131
+ peachpuff: 'ffdab9',
132
+ peru: 'cd853f',
133
+ pink: 'ffc0cb',
134
+ plum: 'dda0dd',
135
+ powderblue: 'b0e0e6',
136
+ purple: '800080',
137
+ red: 'ff0000',
138
+ rosybrown: 'bc8f8f',
139
+ royalblue: '4169e1',
140
+ saddlebrown: '8b4513',
141
+ salmon: 'fa8072',
142
+ sandybrown: 'f4a460',
143
+ seagreen: '2e8b57',
144
+ seashell: 'fff5ee',
145
+ sienna: 'a0522d',
146
+ silver: 'c0c0c0',
147
+ skyblue: '87ceeb',
148
+ slateblue: '6a5acd',
149
+ slategray: '708090',
150
+ snow: 'fffafa',
151
+ springgreen: '00ff7f',
152
+ steelblue: '4682b4',
153
+ tan: 'd2b48c',
154
+ teal: '008080',
155
+ thistle: 'd8bfd8',
156
+ tomato: 'ff6347',
157
+ turquoise: '40e0d0',
158
+ violet: 'ee82ee',
159
+ violetred: 'd02090',
160
+ wheat: 'f5deb3',
161
+ white: 'ffffff',
162
+ whitesmoke: 'f5f5f5',
163
+ yellow: 'ffff00',
164
+ yellowgreen: '9acd32'
165
+ };
166
+ for (var key in simple_colors) {
167
+ if (color_string == key) {
168
+ color_string = simple_colors[key];
169
+ }
170
+ }
171
+ // emd of simple type-in colors
172
+
173
+ // array of color definition objects
174
+ var color_defs = [
175
+ {
176
+ re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
177
+ example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
178
+ process: function (bits){
179
+ return [
180
+ parseInt(bits[1]),
181
+ parseInt(bits[2]),
182
+ parseInt(bits[3])
183
+ ];
184
+ }
185
+ },
186
+ {
187
+ re: /^(\w{2})(\w{2})(\w{2})$/,
188
+ example: ['#00ff00', '336699'],
189
+ process: function (bits){
190
+ return [
191
+ parseInt(bits[1], 16),
192
+ parseInt(bits[2], 16),
193
+ parseInt(bits[3], 16)
194
+ ];
195
+ }
196
+ },
197
+ {
198
+ re: /^(\w{1})(\w{1})(\w{1})$/,
199
+ example: ['#fb0', 'f0f'],
200
+ process: function (bits){
201
+ return [
202
+ parseInt(bits[1] + bits[1], 16),
203
+ parseInt(bits[2] + bits[2], 16),
204
+ parseInt(bits[3] + bits[3], 16)
205
+ ];
206
+ }
207
+ }
208
+ ];
209
+
210
+ // search through the definitions to find a match
211
+ for (var i = 0; i < color_defs.length; i++) {
212
+ var re = color_defs[i].re;
213
+ var processor = color_defs[i].process;
214
+ var bits = re.exec(color_string);
215
+ if (bits) {
216
+ channels = processor(bits);
217
+ this.r = channels[0];
218
+ this.g = channels[1];
219
+ this.b = channels[2];
220
+ this.ok = true;
221
+ }
222
+
223
+ }
224
+
225
+ // validate/cleanup values
226
+ this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
227
+ this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
228
+ this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);
229
+
230
+ // some getters
231
+ this.toRGB = function () {
232
+ return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
233
+ }
234
+ this.toHex = function () {
235
+ var r = this.r.toString(16);
236
+ var g = this.g.toString(16);
237
+ var b = this.b.toString(16);
238
+ if (r.length == 1) r = '0' + r;
239
+ if (g.length == 1) g = '0' + g;
240
+ if (b.length == 1) b = '0' + b;
241
+ return '#' + r + g + b;
242
+ }
243
+
244
+ // help
245
+ this.getHelpXML = function () {
246
+
247
+ var examples = new Array();
248
+ // add regexps
249
+ for (var i = 0; i < color_defs.length; i++) {
250
+ var example = color_defs[i].example;
251
+ for (var j = 0; j < example.length; j++) {
252
+ examples[examples.length] = example[j];
253
+ }
254
+ }
255
+ // add type-in colors
256
+ for (var sc in simple_colors) {
257
+ examples[examples.length] = sc;
258
+ }
259
+
260
+ var xml = document.createElement('ul');
261
+ xml.setAttribute('id', 'rgbcolor-examples');
262
+ for (var i = 0; i < examples.length; i++) {
263
+ try {
264
+ var list_item = document.createElement('li');
265
+ var list_color = new RGBColor(examples[i]);
266
+ var example_div = document.createElement('div');
267
+ example_div.style.cssText =
268
+ 'margin: 3px; '
269
+ + 'border: 1px solid black; '
270
+ + 'background:' + list_color.toHex() + '; '
271
+ + 'color:' + list_color.toHex()
272
+ ;
273
+ example_div.appendChild(document.createTextNode('test'));
274
+ var list_item_value = document.createTextNode(
275
+ ' ' + examples[i] + ' -> ' + list_color.toRGB() + ' -> ' + list_color.toHex()
276
+ );
277
+ list_item.appendChild(example_div);
278
+ list_item.appendChild(list_item_value);
279
+ xml.appendChild(list_item);
280
+
281
+ } catch(e){}
282
+ }
283
+ return xml;
284
+
285
+ }
286
+
287
+ }
288
+