Mercurial > laserkard
comparison js-lib/buy3.js @ 103:52297178e0eb laserkard
implemented automatic text resize
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 28 Jul 2010 06:36:39 -0400 |
parents | 8ed3394e6b73 |
children | a20199a24415 |
comparison
equal
deleted
inserted
replaced
102:8ed3394e6b73 | 103:52297178e0eb |
---|---|
1 //WHY do I have to write this myself!? | |
2 Object.prototype.keys = function () | |
3 { | |
4 var keys = []; | |
5 for(i in this) if (this.hasOwnProperty(i)) | |
6 { | |
7 keys.push(i); | |
8 } | |
9 return keys; | |
10 } | |
11 | |
12 | |
13 | |
14 | |
1 | 15 |
2 Buy = (function (){ | 16 Buy = (function (){ |
3 | 17 |
4 //Cards drawing functions: | 18 //Cards drawing functions: |
5 | 19 |
8 | 22 |
9 | 23 |
10 | 24 |
11 var draw_card = (function (paper){ | 25 var draw_card = (function (paper){ |
12 | 26 |
13 var helvetica = paper.getFont('HelveticaNeue', 700); | 27 var helvetica = paper.getFont('HelveticaNeue', 700); |
14 var helveticaI = paper.getFont('HelveticaNeue', 800); | 28 var helveticaI = paper.getFont('HelveticaNeue', 800); |
15 var h = paper.height; | 29 var h = paper.height; |
16 var w = paper.width; | 30 var w = paper.width; |
17 | 31 var default_color = "#AAAAAA"; |
18 var standard = (function (text, x, y, pt, font){ | 32 |
19 if (!font) {font = helvetica;} | 33 // var clamp = (function (target args){ |
34 // x = args.x || null; | |
35 // y = args.y || null; | |
36 | |
37 // if (x) { | |
38 // if (target.getBBox().width > display.width * x){ | |
39 // target.scale( | |
40 // } | |
41 // } | |
42 | |
43 // if (y) | |
44 | |
45 // }); | |
46 | |
47 var standard = (function (args){ | |
48 var pt = args.pt || 20; | |
49 var x = args.x || 0; | |
50 var y = args.y || 0; | |
51 var x_max = args.x_max || null; | |
52 var y_max = args.y_max || null; | |
53 var font = args.font || helvetica; | |
54 var text = args.text || ""; | |
20 var scale_x = 0.00030*h*pt/20; | 55 var scale_x = 0.00030*h*pt/20; |
21 var scale_y = 0.00025*w*pt/20; | 56 var scale_y = 0.00025*w*pt/20; |
22 return paper.print(h*x, w*y,text, font).scale( | 57 |
23 scale_x,scale_y,h*x,w*y);}); | 58 |
59 | |
60 target = paper.print(h*x, w*y,text, font).scale( | |
61 scale_x,scale_y,h*x,w*y).attr({"fill": default_color}); | |
62 | |
63 if (x_max){ | |
64 var width = target.getBBox().width; | |
65 var max_width = paper.width*x_max; | |
66 if (width > max_width){ | |
67 var x_mod = max_width/width; | |
68 target.scale(scale_x*x_mod,scale_y,0,0); | |
69 } | |
70 } | |
71 return target; | |
72 }); | |
73 | |
74 | |
75 | |
76 | |
24 | 77 |
25 var bold = { | 78 var bold = { |
26 "name" :(function (text){ | 79 "name" :(function (text){ |
27 return standard(text, 0.2,0.1,20).attr({"fill" : "red"});}), | 80 return standard({x_max : 0.5, "text": text, x: 0.2, y: 0.1, pt: 20});}), |
28 "email" : (function (text){ | 81 "email" : (function (text){ |
29 return standard(text, 0.2,0.4,20,helveticaI).attr( | 82 return standard({"text": text, x: 0.2, y: 0.4,pt: 20,font: helveticaI});})}; |
30 {"fill" : "red"});})}; | 83 |
31 | 84 |
32 | |
33 return { | 85 return { |
34 "bold" : bold | 86 "bold" : bold |
35 }; | 87 }; |
36 | 88 |
37 }); | 89 }); |
132 toggle_on(state_map[order.color]); | 184 toggle_on(state_map[order.color]); |
133 }); | 185 }); |
134 | 186 |
135 var display_init = (function (){ | 187 var display_init = (function (){ |
136 state_map["display"].ref = | 188 state_map["display"].ref = |
137 display.rect(1, 1 , display.width - 1, display.height - 2, 20).attr( | 189 display.rect(1, 1 , display.width - 1, display.height - 2, 15).attr( |
138 state_map["display"].state); | 190 state_map["display"].state); |
139 }); | 191 }); |
140 | 192 |
141 var text_entry_init = (function (){ | 193 var text_entry_init = (function (){ |
142 $('input[type=text][title!=""]').each(function() { | 194 $('input[type=text][title!=""]').each(function() { |
176 | 228 |
177 | 229 |
178 | 230 |
179 | 231 |
180 var init = (function () { | 232 var init = (function () { |
181 display = Raphael("card-display", 340 ,215); | 233 display = Raphael("card-display", 360 ,230); |
182 color = Raphael("color-select", 300, 100); | 234 color = Raphael("color-select", 300, 100); |
183 | 235 |
184 style.bold = Raphael("bold", 170, 107); | 236 style.bold = Raphael("bold", display.width/2, display.height/2); |
185 | 237 |
186 style.classic = Raphael("classic", 170 , 107); | 238 style.classic = Raphael("classic", display.width/2 , display.width/2); |
187 | 239 |
188 helvetica = display.getFont('HelveticaNeue', 700); | 240 helvetica = display.getFont('HelveticaNeue', 700); |
189 helvetica_I = display.getFont('HelveticaNeue', 800); | 241 helvetica_I = display.getFont('HelveticaNeue', 800); |
190 color_select_init(); | 242 color_select_init(); |
191 display_init(); | 243 display_init(); |