diff awesome_js/robert.js @ 48:b2a11435a89b laserkard

[svn r49] implemented resizing text :)
author rlm
date Sun, 31 Jan 2010 20:26:16 -0500
parents 4431dc7d4bb5
children 5eb11cf654de
line wrap: on
line diff
     1.1 --- a/awesome_js/robert.js	Sun Jan 31 14:21:14 2010 -0500
     1.2 +++ b/awesome_js/robert.js	Sun Jan 31 20:26:16 2010 -0500
     1.3 @@ -1,6 +1,7 @@
     1.4  
     1.5  descHash = new Object();
     1.6  
     1.7 +prevVal = "";
     1.8  
     1.9  
    1.10  
    1.11 @@ -64,7 +65,10 @@
    1.12  if (typeof values.posy != 'undefined'){posy = values.posy;}
    1.13  if (typeof values.center != 'undefined'){center = values.center;}
    1.14  if (typeof values.font != 'undefined'){font = values.font;}
    1.15 +if (typeof values.face != 'undefined'){face = values.face;}
    1.16 +if (typeof values.width != 'undefined'){width = values.width;}
    1.17  if (typeof values.weirdFlip != 'undefined'){weirdFlip = values.weirdFlip;}
    1.18 +if (typeof values.resize != 'undefined'){resize = values.resize;}
    1.19  }
    1.20  
    1.21  
    1.22 @@ -76,6 +80,8 @@
    1.23  function smallRedraw(style,field)
    1.24  {
    1.25  
    1.26 +
    1.27 +
    1.28  var JSONtext = document.getElementById('formValues').innerHTML;
    1.29  var hash = new Object();
    1.30  hash = eval('(' + JSONtext + ')');
    1.31 @@ -84,15 +90,22 @@
    1.32  
    1.33   content = unescape(content);
    1.34  
    1.35 +if (prevVal == content){return;}
    1.36 +
    1.37  posx = 10;
    1.38  posy = 10;
    1.39  center = 0;
    1.40  font = 10;
    1.41  face = 700;
    1.42  weirdFlip = 0;
    1.43 +resize = 1;
    1.44 +width = 450;
    1.45  
    1.46  getPosition(style, field);
    1.47  
    1.48 +
    1.49 +
    1.50 +
    1.51  target = "d_" + field;
    1.52  
    1.53  
    1.54 @@ -102,11 +115,57 @@
    1.55  
    1.56  eval ( target + " = raphe.print(posx, posy, content , raphe.getFont('HelveticaNeue', face), font);" );
    1.57  
    1.58 - 
    1.59 -eval ( target +".attr('stroke', '#6a6a6a');");
    1.60 +
    1.61 +var sizzle = eval(target+".getBBox().width;");
    1.62 +
    1.63 +document.getElementById('output').innerHTML = sizzle;
    1.64 +
    1.65 +
    1.66 +if (resize == 1)
    1.67 +	
    1.68 +{
    1.69 +	
    1.70 +	
    1.71 +
    1.72 +	
    1.73 +	//base case
    1.74 +	if ((sizzle) > width) 
    1.75 +	{
    1.76 +		
    1.77 +		mul = .9;
    1.78 +		
    1.79 +		
    1.80 +			mul = (width/sizzle);
    1.81 +		
    1.82 +				
    1.83 +		font = font * mul; 
    1.84 +		
    1.85 +		//eval( target + ".scale(mul,mul)" );
    1.86 +		
    1.87 +		eval ( target + ".remove();");
    1.88 +		eval ( target + " = raphe.print(posx, posy, content , raphe.getFont('HelveticaNeue', face), font);" );
    1.89 +
    1.90 +		
    1.91 +	}
    1.92 +	
    1.93 +	
    1.94 +	
    1.95 +}
    1.96 +
    1.97 +
    1.98 +
    1.99 +var sizzle = eval(target+".getBBox().width;");
   1.100 +
   1.101 +document.getElementById('output').innerHTML = sizzle;
   1.102 +
   1.103 +eval ( target +".attr('stroke', '#fefefe');");
   1.104 +//eval ( target +".attr('stroke', '#fbafcd');");
   1.105 +
   1.106  eval ( target +".attr('fill', 'none');");
   1.107  
   1.108  
   1.109 +
   1.110 +
   1.111  if (center == 1)
   1.112  {
   1.113  eval ("var c = " + target+".getBBox().width; " + target + ".translate((485 - c)/2,0);");
   1.114 @@ -123,6 +182,8 @@
   1.115  
   1.116  
   1.117  
   1.118 +prevVal = content;
   1.119 +
   1.120  
   1.121  
   1.122  }
   1.123 @@ -169,8 +230,8 @@
   1.124  
   1.125  
   1.126  d_lineArt = raphe.path("M 2 272 L 258 272");
   1.127 -d_lineArt.attr('stroke', '#6a6a6a');
   1.128 -	
   1.129 +d_lineArt.attr('stroke', '#fefefe');
   1.130 +
   1.131  }
   1.132  
   1.133  
   1.134 @@ -201,7 +262,7 @@
   1.135  smallRedraw("direct","Website");
   1.136  
   1.137  d_lineArt = raphe.path("M 350 165 L 512 165  M 350 173 L 512 173  M 350 181 L 512 181  M 350 189 L 512 189 M 350 197 L 512 197 M 350 213 L 512 213 M 350 205 L 512 205 M 350 221 L 512 221");
   1.138 -d_lineArt.attr('stroke', '#6a6a6a');
   1.139 +d_lineArt.attr('stroke', '#fefefe');
   1.140  
   1.141  
   1.142