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 45 by isao-hara, Tue Jul 27 04:43:37 2010 UTC revision 46 by isao-hara, Tue Jul 27 08:29:10 2010 UTC
# Line 60  var svg_fill_color = '#ffffff'; Line 60  var svg_fill_color = '#ffffff';
60  var svg_line_width = 1;  var svg_line_width = 1;
61    
62  var editingTextObj = null;  var editingTextObj = null;
63  var svg_rotate_locked = true;  var svg_rotate_locked = false;
64  var svg_scale_locked = true;  var svg_scale_locked = false;
65    
66  var dupItems;  var dupItems;
67  var dupX;  var dupX;
# Line 1292  function togglePathType(){ Line 1292  function togglePathType(){
1292    var newpath = "";    var newpath = "";
1293    
1294    for(var i=0;i<path.length ;i++){    for(var i=0;i<path.length ;i++){
1295      if(path[i] == "L"){ path[i] = "C"; }      if(path[i] == "L"){ path[i] = "Q"; }
1296      else if(path[i] == "C"){ path[i] = "L"; }      else if(path[i] == "Q"){ path[i] = "L"; }
1297      newpath += path[i] + ' ';      newpath += path[i] + ' ';
1298    }    }
1299      if(((i-4) % 4) != 0) {
1300        newpath += path[i-2] + ' ';
1301        newpath += path[i-1] + ' ';
1302      }
1303        
1304    itm.setAttribute("d",trim(newpath));    itm.setAttribute("d",trim(newpath));
1305  }  }
1306    
1307  function scalePath(itm, scale){  function scalePath(itm, scale){
1308    var path = itm.getAttribute("d").split(' ');    var path = itm.getAttribute("d").split(' ');
1309      var bbox = itm.getBBox();
1310    var newpath = "";    var newpath = "";
1311      var sX=scale[0];
1312      var sY=scale[1];
1313      var isX=true;
1314      var dx = bbox.x - sX*bbox.x;
1315      var dy = bbox.y - sY*bbox.y;
1316    
1317    for(var i=0;i<path.length ;i++){    for(var i=0;i<path.length ;i++){
1318      if(path[i].match(/[0-9]+/)){      if(path[i].match(/[0-9]+/)){
1319        var val = parseInt(path[i]);        var val = parseInt(path[i]);
1320        path[i] =  Math.round(val*scale) ;        if(isX){
1321            path[i] =  Math.round(val*sX) + dx ;
1322            isX = false;
1323          }else{
1324            path[i] =  Math.round(val*sY) + dy ;
1325            isX = true;
1326          }  
1327      }      }
1328      newpath += path[i] + ' ';      newpath += path[i] + ' ';
1329    }    }
# Line 1316  function scalePath(itm, scale){ Line 1332  function scalePath(itm, scale){
1332  }  }
1333    
1334  function scaleLine(itm, scale){  function scaleLine(itm, scale){
1335      var sX=scale[0];
1336      var sY=scale[1];
1337    var x1 = parseInt(itm.getAttribute("x1"));    var x1 = parseInt(itm.getAttribute("x1"));
1338    var y1 = parseInt(itm.getAttribute("y1"));    var y1 = parseInt(itm.getAttribute("y1"));
1339    var x2 = parseInt(itm.getAttribute("x2"));    var x2 = parseInt(itm.getAttribute("x2"));
1340    var y2 = parseInt(itm.getAttribute("y2"));    var y2 = parseInt(itm.getAttribute("y2"));
1341      var bbox = itm.getBBox();
1342    itm.setAttribute("x1", Math.round(x1*scale));    var dx = bbox.x - sX*bbox.x;
1343    itm.setAttribute("y1", Math.round(y1*scale));    var dy = bbox.y - sY*bbox.y;
1344    itm.setAttribute("x2", Math.round(x2*scale));  
1345    itm.setAttribute("y2", Math.round(y2*scale));    itm.setAttribute("x1", Math.round(x1*sX)+dx);
1346      itm.setAttribute("y1", Math.round(y1*sY)+dy);
1347      itm.setAttribute("x2", Math.round(x2*sX)+dx);
1348      itm.setAttribute("y2", Math.round(y2*sY)+dy);
1349  }  }
1350    
1351  function appendSVGObj(obj){  function appendSVGObj(obj){
# Line 2134  function setRotate(obj,deg){ Line 2155  function setRotate(obj,deg){
2155    
2156  function getScale(obj){  function getScale(obj){
2157    var trans = obj.getAttribute("transform");    var trans = obj.getAttribute("transform");
2158    if(!trans || trans.indexOf("scale") < 0) return 1;    if(!trans || trans.indexOf("scale") < 0) return null;
2159    var strs = trans.split(' ');    var strs = trans.split(' ');
2160    for(var i=0; i<strs.length ;i++){    for(var i=0; i<strs.length ;i++){
2161      if(strs[i].indexOf("scale") >= 0){      if(strs[i].indexOf("scale") >= 0){
2162         var deg = strs[i].substr(6, strs[i].indexOf(")")-6);         var degs = strs[i].substr(6, strs[i].indexOf(")")-6);
2163         return parseFloat(deg);         var degs = degs.split(',');
2164           return new Array(parseFloat(degs[0]), parseFloat(degs[1]));
2165      }      }
2166    }    }
2167    return 1;    return null;
2168  }  }
2169    
2170  function setScale(obj,scale){  function setScale(obj,scaleX, scaleY){
2171    var trans = obj.getAttribute("transform");    var trans = obj.getAttribute("transform");
2172      var x = parseInt(svg_select.getAttribute("x"));
2173      var y = parseInt(svg_select.getAttribute("y"));
2174      var dx = x - scaleX*x;
2175      var dy = y - scaleY*y;
2176    
2177    if(!trans) trans="";    if(!trans) trans="";
2178    if(trans.indexOf("scale") < 0){    if(trans.indexOf("scale") < 0){
2179      trans = "scale("+scale+")";      trans = "scale("+scaleX+","+scaleY+")";
2180      obj.setAttribute("transform", trans);      obj.setAttribute("transform", trans);
2181    }else{    }else{
2182      var strs = trans.split(' ');      var strs = trans.split(' ');
2183      trans = "";      trans = "";
2184      for(var i=0; i<strs.length ;i++){      for(var i=0; i<strs.length ;i++){
2185        if(strs[i].indexOf("scale") >= 0){        if(strs[i].indexOf("scale") >= 0){
2186         if(scale==1) break;         if(scaleX==1 && scaleY==1) break;
2187          strs[i] = "scale("+scale+")"; i          strs[i] = "scale("+scaleX+","+scaleY+")";
       
2188        }        }
2189        trans += strs[i]+" ";        trans += strs[i]+" ";
2190      }      }
2191      obj.setAttribute("transform",trim(trans));      obj.setAttribute("transform",trim(trans));
2192    }    }
2193      replaceTranslate(obj, dx/scaleX, dy/scaleY);
2194    //    popupInfo(obj.getAttribute("transform"));
2195  }  }
2196    
2197  function onTouchMoveCode1(pageX, pageY){  function onTouchMoveCode1(pageX, pageY){
# Line 2444  function onGestureChange(e){ Line 2471  function onGestureChange(e){
2471           break;           break;
2472          case 'path':          case 'path':
2473          case 'line':          case 'line':
2474           setScale(targetItem, scale);           var scaleX = scale;
2475             var scaleY = scale;
2476             if(svg_scale_dir == 'x') scaleY=1;
2477             else if(svg_scale_dir == 'y') scaleX=1;
2478    
2479             setScale(targetItem, scaleX, scaleY);
2480           break;           break;
2481          defult:          defult:
2482           break;           break;
# Line 2467  function onGestureEnd(e){ Line 2499  function onGestureEnd(e){
2499    
2500    if(getElementTag(targetItem) == 'path'){    if(getElementTag(targetItem) == 'path'){
2501      var scale = getScale(targetItem);      var scale = getScale(targetItem);
2502      setScale(targetItem, 1);      if(scale){
2503      scalePath(targetItem, scale);        setScale(targetItem,1,1);
2504          scalePath(targetItem, scale);
2505        }
2506    }else if(getElementTag(targetItem) == 'line'){    }else if(getElementTag(targetItem) == 'line'){
2507      var scale = getScale(targetItem);      var scale = getScale(targetItem);
2508      setScale(targetItem, 1);      if(scale){
2509      scaleLine(targetItem, scale);        setScale(targetItem, 1,1);
2510          scaleLine(targetItem, scale);
2511        }
2512    }    }
2513  }  }
2514    
# Line 2668  function onMouseUp(e){ Line 2704  function onMouseUp(e){
2704    
2705    if(getElementTag(targetItem) == 'path'){    if(getElementTag(targetItem) == 'path'){
2706      var scale = getScale(targetItem);      var scale = getScale(targetItem);
2707      setScale(targetItem, 1);      setScale(targetItem, 1,1);
2708      scalePath(targetItem, scale);      scalePath(targetItem, scale);
2709    }else if(getElementTag(targetItem) == 'line'){    }else if(getElementTag(targetItem) == 'line'){
2710      var scale = getScale(targetItem);      var scale = getScale(targetItem);
2711      setScale(targetItem, 1);      setScale(targetItem, 1,1);
2712      scaleLine(targetItem, scale);      scaleLine(targetItem, scale);
2713    }    }
2714    

Legend:
Removed from v.45  
changed lines
  Added in v.46

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