Mercurial > laserkard
diff 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 |
line wrap: on
line diff
1.1 --- a/js-lib/buy3.js Tue Jul 27 22:23:13 2010 -0400 1.2 +++ b/js-lib/buy3.js Wed Jul 28 06:36:39 2010 -0400 1.3 @@ -1,3 +1,17 @@ 1.4 +//WHY do I have to write this myself!? 1.5 +Object.prototype.keys = function () 1.6 +{ 1.7 + var keys = []; 1.8 + for(i in this) if (this.hasOwnProperty(i)) 1.9 + { 1.10 + keys.push(i); 1.11 + } 1.12 + return keys; 1.13 +} 1.14 + 1.15 + 1.16 + 1.17 + 1.18 1.19 Buy = (function (){ 1.20 1.21 @@ -10,26 +24,64 @@ 1.22 1.23 var draw_card = (function (paper){ 1.24 1.25 - var helvetica = paper.getFont('HelveticaNeue', 700); 1.26 - var helveticaI = paper.getFont('HelveticaNeue', 800); 1.27 - var h = paper.height; 1.28 - var w = paper.width; 1.29 + var helvetica = paper.getFont('HelveticaNeue', 700); 1.30 + var helveticaI = paper.getFont('HelveticaNeue', 800); 1.31 + var h = paper.height; 1.32 + var w = paper.width; 1.33 + var default_color = "#AAAAAA"; 1.34 1.35 - var standard = (function (text, x, y, pt, font){ 1.36 - if (!font) {font = helvetica;} 1.37 + // var clamp = (function (target args){ 1.38 + // x = args.x || null; 1.39 + // y = args.y || null; 1.40 + 1.41 + // if (x) { 1.42 + // if (target.getBBox().width > display.width * x){ 1.43 + // target.scale( 1.44 + // } 1.45 + // } 1.46 + 1.47 + // if (y) 1.48 + 1.49 + // }); 1.50 + 1.51 + var standard = (function (args){ 1.52 + var pt = args.pt || 20; 1.53 + var x = args.x || 0; 1.54 + var y = args.y || 0; 1.55 + var x_max = args.x_max || null; 1.56 + var y_max = args.y_max || null; 1.57 + var font = args.font || helvetica; 1.58 + var text = args.text || ""; 1.59 var scale_x = 0.00030*h*pt/20; 1.60 var scale_y = 0.00025*w*pt/20; 1.61 - return paper.print(h*x, w*y,text, font).scale( 1.62 - scale_x,scale_y,h*x,w*y);}); 1.63 + 1.64 + 1.65 + 1.66 + target = paper.print(h*x, w*y,text, font).scale( 1.67 + scale_x,scale_y,h*x,w*y).attr({"fill": default_color}); 1.68 + 1.69 + if (x_max){ 1.70 + var width = target.getBBox().width; 1.71 + var max_width = paper.width*x_max; 1.72 + if (width > max_width){ 1.73 + var x_mod = max_width/width; 1.74 + target.scale(scale_x*x_mod,scale_y,0,0); 1.75 + } 1.76 + } 1.77 + return target; 1.78 + }); 1.79 + 1.80 + 1.81 + 1.82 + 1.83 1.84 var bold = { 1.85 "name" :(function (text){ 1.86 - return standard(text, 0.2,0.1,20).attr({"fill" : "red"});}), 1.87 + return standard({x_max : 0.5, "text": text, x: 0.2, y: 0.1, pt: 20});}), 1.88 "email" : (function (text){ 1.89 - return standard(text, 0.2,0.4,20,helveticaI).attr( 1.90 - {"fill" : "red"});})}; 1.91 + return standard({"text": text, x: 0.2, y: 0.4,pt: 20,font: helveticaI});})}; 1.92 1.93 - 1.94 + 1.95 return { 1.96 "bold" : bold 1.97 }; 1.98 @@ -134,7 +186,7 @@ 1.99 1.100 var display_init = (function (){ 1.101 state_map["display"].ref = 1.102 - display.rect(1, 1 , display.width - 1, display.height - 2, 20).attr( 1.103 + display.rect(1, 1 , display.width - 1, display.height - 2, 15).attr( 1.104 state_map["display"].state); 1.105 }); 1.106 1.107 @@ -178,12 +230,12 @@ 1.108 1.109 1.110 var init = (function () { 1.111 - display = Raphael("card-display", 340 ,215); 1.112 + display = Raphael("card-display", 360 ,230); 1.113 color = Raphael("color-select", 300, 100); 1.114 1.115 - style.bold = Raphael("bold", 170, 107); 1.116 + style.bold = Raphael("bold", display.width/2, display.height/2); 1.117 1.118 - style.classic = Raphael("classic", 170 , 107); 1.119 + style.classic = Raphael("classic", display.width/2 , display.width/2); 1.120 1.121 helvetica = display.getFont('HelveticaNeue', 700); 1.122 helvetica_I = display.getFont('HelveticaNeue', 800);