Develop and Download Open Source Software

Browse Subversion Repository

Diff of /SvgEditor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 43 by isao-hara, Tue Jul 27 02:50:49 2010 UTC revision 44 by isao-hara, Tue Jul 27 03:46:04 2010 UTC
# Line 1300  function togglePathType(){ Line 1300  function togglePathType(){
1300    itm.setAttribute("d",trim(newpath));    itm.setAttribute("d",trim(newpath));
1301  }  }
1302    
1303    function scalePath(itm, scale){
1304      var path = itm.getAttribute("d").split(' ');
1305      var newpath = "";
1306    
1307      for(var i=0;i<path.length ;i++){
1308        if(path[i].match(/[0-9]+/)){
1309          var val = parseInt(path[i]);
1310          path[i] =  Math.round(val*scale) ;
1311        }
1312        newpath += path[i] + ' ';
1313      }
1314      
1315      itm.setAttribute("d",trim(newpath));
1316    }
1317    
1318    function scaleLine(itm, scale){
1319      var x1 = parseInt(itm.getAttribute("x1"));
1320      var y1 = parseInt(itm.getAttribute("y1"));
1321      var x2 = parseInt(itm.getAttribute("x2"));
1322      var y2 = parseInt(itm.getAttribute("y2"));
1323    
1324      itm.setAttribute("x1", Math.round(x1*scale));
1325      itm.setAttribute("y1", Math.round(y1*scale));
1326      itm.setAttribute("x2", Math.round(x2*scale));
1327      itm.setAttribute("y2", Math.round(y2*scale));
1328    }
1329    
1330  function appendSVGObj(obj){  function appendSVGObj(obj){
1331    var svg_top = document.getElementById('svg_top');    var svg_top = document.getElementById('svg_top');
1332    if(!svg_top) return;    if(!svg_top) return;
# Line 2105  function setRotate(obj,deg){ Line 2132  function setRotate(obj,deg){
2132    }    }
2133  }  }
2134    
2135    function getScale(obj){
2136      var trans = obj.getAttribute("transform");
2137      if(!trans || trans.indexOf("scale") < 0) return 1;
2138      var strs = trans.split(' ');
2139      for(var i=0; i<strs.length ;i++){
2140        if(strs[i].indexOf("scale") >= 0){
2141           var deg = strs[i].substr(6, strs[i].indexOf(")")-6);
2142           return parseFloat(deg);
2143        }
2144      }
2145      return 1;
2146    }
2147    
2148    function setScale(obj,scale){
2149      var trans = obj.getAttribute("transform");
2150    
2151      if(!trans) trans="";
2152      if(trans.indexOf("scale") < 0){
2153        trans = "scale("+scale+")";
2154        obj.setAttribute("transform", trans);
2155      }else{
2156        var strs = trans.split(' ');
2157        trans = "";
2158        for(var i=0; i<strs.length ;i++){
2159          if(strs[i].indexOf("scale") >= 0){
2160           if(scale==1) break;
2161            strs[i] = "scale("+scale+")"; i
2162        
2163          }
2164          trans += strs[i]+" ";
2165        }
2166        obj.setAttribute("transform",trim(trans));
2167      }
2168    }
2169    
2170  function onTouchMoveCode1(pageX, pageY){  function onTouchMoveCode1(pageX, pageY){
2171    if(targetItem || selectedItems.length > 0){    if(targetItem || selectedItems.length > 0){
2172      switch(modeSVG){      switch(modeSVG){
# Line 2364  function onGestureChange(e){ Line 2426  function onGestureChange(e){
2426    if(targetItem){    if(targetItem){
2427      e.preventDefault();      e.preventDefault();
2428      if(!svg_scale_locked){      if(!svg_scale_locked){
2429        if (svg_wo && svg_scale_dir != 'y') targetItem.setAttribute("width", Math.round(svg_wo*scale ));        switch(getElementTag(targetItem)){
2430        if (svg_ho && svg_scale_dir != 'x') targetItem.setAttribute("height", Math.round(svg_ho*scale ));          case 'text':
2431        if (svg_ro) targetItem.setAttribute("r", Math.round(svg_ro*scale ));           if (svg_fsize) targetItem.setAttribute("font-size", Math.round(svg_fsize*scale) );
2432        if (svg_rxo && svg_scale_dir != 'y') targetItem.setAttribute("rx", Math.round(svg_rxo*scale) );           break;
2433        if (svg_ryo && svg_scale_dir != 'x') targetItem.setAttribute("ry", Math.round(svg_ryo*scale) );          case 'rect':
2434        if (svg_fsize) targetItem.setAttribute("font-size", Math.round(svg_fsize*scale) );          case 'image':
2435             if (svg_wo && svg_scale_dir != 'y') targetItem.setAttribute("width", Math.round(svg_wo*scale ));
2436             if (svg_ho && svg_scale_dir != 'x') targetItem.setAttribute("height", Math.round(svg_ho*scale ));
2437             break;
2438            case 'circle':
2439             if (svg_ro) targetItem.setAttribute("r", Math.round(svg_ro*scale ));
2440             break;
2441            case 'ellipse':
2442             if (svg_rxo && svg_scale_dir != 'y') targetItem.setAttribute("rx", Math.round(svg_rxo*scale) );
2443             if (svg_ryo && svg_scale_dir != 'x') targetItem.setAttribute("ry", Math.round(svg_ryo*scale) );
2444             break;
2445            case 'path':
2446            case 'line':
2447             setScale(targetItem, scale);
2448             break;
2449            defult:
2450             break;
2451          }
2452      }      }
2453      if (!svg_rotate_locked) setRotate(targetItem, rotation);      if (!svg_rotate_locked) setRotate(targetItem, rotation);
2454    
# Line 2385  function onGestureEnd(e){ Line 2464  function onGestureEnd(e){
2464    svg_rxo = null;    svg_rxo = null;
2465    svg_ryo = null;    svg_ryo = null;
2466    svg_fsize = null;    svg_fsize = null;
2467    
2468      if(getElementTag(targetItem) == 'path'){
2469        var scale = getScale(targetItem);
2470        setScale(targetItem, 1);
2471        scalePath(targetItem, scale);
2472      }else if(getElementTag(targetItem) == 'line'){
2473        var scale = getScale(targetItem);
2474        setScale(targetItem, 1);
2475        scaleLine(targetItem, scale);
2476      }
2477  }  }
2478    
2479  function onTouchStartColor(e){  function onTouchStartColor(e){

Legend:
Removed from v.43  
changed lines
  Added in v.44

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26