fix for defs don't exist

master
Mark MacKay 2012-08-26 12:35:26 -05:00
parent 702e4c4fbe
commit 8d2908cca2
5 changed files with 18 additions and 23 deletions

View File

@ -91,7 +91,7 @@ var f=Array(Math.floor((d.length+2)/3)*4),c,m,u,C,s,L,Q=0,K=0;do{c=d.charCodeAt(
d.length);return f.join("")};svgedit.utilities.decode64=function(d){if(window.atob)return window.atob(d);var f="",c,m,u="",C,s="",L=0;d=d.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));
c=c<<2|m>>4;m=(m&15)<<4|C>>2;u=(C&3)<<6|s;f+=String.fromCharCode(c);if(C!=64)f+=String.fromCharCode(m);if(s!=64)f+=String.fromCharCode(u)}while(L<d.length);return unescape(f)};svgedit.utilities.convertToXMLReferences=function(d){for(var f="",c=0;c<d.length;c++){var m=d.charCodeAt(c);if(m<128)f+=d[c];else if(m>127)f+="&#"+m+";"}return f};svgedit.utilities.text2xml=function(d){if(d.indexOf("<svg:svg")>=0)d=d.replace(/<(\/?)svg:/g,"<$1").replace("xmlns:svg","xmlns");var f;try{var c=window.DOMParser?
new DOMParser:new ActiveXObject("Microsoft.XMLDOM");c.async=false}catch(m){throw Error("XML Parser could not be instantiated");}try{f=c.loadXML?c.loadXML(d)?c:false:c.parseFromString(d,"text/xml")}catch(u){throw Error("Error parsing XML string");}return f};svgedit.utilities.bboxToObj=function(d){return{x:d.x,y:d.y,width:d.width,height:d.height}};svgedit.utilities.walkTree=function(d,f){if(d&&d.nodeType==1){f(d);for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f)}};
svgedit.utilities.walkTreePost=function(d,f){if(d&&d.nodeType==1){for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f);f(d)}};svgedit.utilities.getUrlFromAttr=function(d){if(d)if(d.indexOf('url("')===0)return d.substring(5,d.indexOf('"',6));else if(d.indexOf("url('")===0)return d.substring(5,d.indexOf("'",6));else if(d.indexOf("url(")===0)return d.substring(4,d.indexOf(")"));return null};svgedit.utilities.getHref=function(d){return d.getAttributeNS("http://www.w3.org/1999/xlink",
svgedit.utilities.walkTreePost=function(d,f){if(d&&d.nodeType==1){for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f);f(d)}};svgedit.utilities.getUrlFromAttr=function(d){if(d)if(d.indexOf('url("')===0)return d.substring(5,d.indexOf('"',6));else if(d.indexOf("url('")===0)return d.substring(5,d.indexOf("'",6));else if(d.indexOf("url(")===0)return d.substring(4,d.indexOf(")"));return null};svgedit.utilities.getHref=function(d){if(d)return d.getAttributeNS("http://www.w3.org/1999/xlink",
"href")};svgedit.utilities.setHref=function(d,f){d.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",f)};svgedit.utilities.findDefs=function(d){d=g.getSVGContent().documentElement;var f=d.getElementsByTagNameNS("http://www.w3.org/2000/svg","defs");return f=f.length>0?f[0]:d.insertBefore(d.ownerDocument.createElementNS("http://www.w3.org/2000/svg","defs"),d.firstChild.nextSibling)};svgedit.utilities.getPathBBox=function(d){var f=d.pathSegList,c=f.numberOfItems;d=[[],[]];var m=f.getItem(0),
u=[m.x,m.y];for(m=0;m<c;m++){var C=f.getItem(m);if(typeof C.x!="undefined"){d[0].push(u[0]);d[1].push(u[1]);if(C.x1){for(var s=[C.x1,C.y1],L=[C.x2,C.y2],Q=[C.x,C.y],K=0;K<2;K++){C=function(ga){return Math.pow(1-ga,3)*u[K]+3*Math.pow(1-ga,2)*ga*s[K]+3*(1-ga)*Math.pow(ga,2)*L[K]+Math.pow(ga,3)*Q[K]};var I=6*u[K]-12*s[K]+6*L[K],S=-3*u[K]+9*s[K]-9*L[K]+3*Q[K],R=3*s[K]-3*u[K];if(S==0){if(I!=0){I=-R/I;0<I&&I<1&&d[K].push(C(I))}}else{R=Math.pow(I,2)-4*R*S;if(!(R<0)){var N=(-I+Math.sqrt(R))/(2*S);0<N&&N<
1&&d[K].push(C(N));I=(-I-Math.sqrt(R))/(2*S);0<I&&I<1&&d[K].push(C(I))}}}u=Q}else{d[0].push(C.x);d[1].push(C.y)}}}f=Math.min.apply(null,d[0]);c=Math.max.apply(null,d[0])-f;m=Math.min.apply(null,d[1]);d=Math.max.apply(null,d[1])-m;return{x:f,y:m,width:c,height:d}};svgedit.utilities.getBBox=function(d){var f=d||g.getSelectedElements()[0];if(d.nodeType!=1)return null;d=null;var c=f.nodeName;switch(c){case "text":if(f.textContent===""){f.textContent="a";d=f.getBBox();f.textContent=""}else try{d=f.getBBox()}catch(m){}break;

View File

@ -298,7 +298,7 @@ svgedit.utilities.getUrlFromAttr = function(attrVal) {
// Function: svgedit.utilities.getHref
// Returns the given element's xlink:href value
svgedit.utilities.getHref = function(elem) {
return elem.getAttributeNS(XLINKNS, "href");
if (elem) return elem.getAttributeNS(XLINKNS, "href");
}
// Function: svgedit.utilities.setHref

View File

@ -123,10 +123,10 @@
<div class="menu">
<div class="menu_title">Object</div>
<div class="menu_list" id="object_menu">
<div class="menu_item action_selected disabled" id="tool_move_top">Bring to Front <span class="shortcut">⌘⇧&uarr;</span></div>
<div class="menu_item action_selected disabled" id="tool_move_up">Bring Forward <span class="shortcut">&uarr;</span></div>
<div class="menu_item action_selected disabled" id="tool_move_down">Send Backward <span class="shortcut">&darr;</span></div>
<div class="menu_item action_selected disabled" id="tool_move_bottom">Send to Back <span class="shortcut">⌘⇧&darr;</span></div>
<div class="menu_item action_selected disabled" id="tool_move_top">Bring to Front <span class="shortcut">⌘⇧</span></div>
<div class="menu_item action_selected disabled" id="tool_move_up">Bring Forward <span class="shortcut"></span></div>
<div class="menu_item action_selected disabled" id="tool_move_down">Send Backward <span class="shortcut"></span></div>
<div class="menu_item action_selected disabled" id="tool_move_bottom">Send to Back <span class="shortcut">⌘⇧</span></div>
<div class="separator"></div>
<div class="menu_item action_multi_selected disabled" id="tool_group">Group Elements <span class="shortcut">⌘G</span></div>
<div class="menu_item action_group_selected disabled" id="tool_ungroup">Ungroup Elements <span class="shortcut">⌘⇧G</span></div>
@ -322,7 +322,7 @@
<div class="caret"></div>
<input id="font_family" data-title="Change Font Family" size="12" type="hidden" />
<select id="font_family_dropdown">
<option value="Helvetica, Arial, sans-serif" selected>Helvetica</option>
<option value="Helvetica, Arial, sans-serif" selected="selected">Helvetica</option>
<!--<option value="Arvo, sans-serif">Arvo</option>
<option value="Euphoria, sans-serif">Euphoria</option>
<option value="Oswald, sans-serif">Oswald</option>
@ -348,11 +348,6 @@
<!-- formerly gsvg_panel -->
<div id="container_panel" class="context_panel clearfix">
<!-- Add viewBox field here? -->
<label id="group_title" data-title="Group identification label">
<h4>Group</h4>
</div>
<div id="use_panel" class="context_panel clearfix">
@ -395,7 +390,7 @@
<label class="draginput checkbox" id="tool_node_link" data-title="Link Control Points">
<span>Linked Control Points</span>
<div class="push_bottom"><input type="checkbox" checked></div>
<div class="push_bottom"><input type="checkbox" checked="checked" /></div>
</label>
<div class="clearfix"></div>
@ -462,7 +457,7 @@
<option id="page" value="page">Align to page</option>
</select>
</label>
<h4>&nbsp;</h4>
<h4>.</h4>
<div class="col last clear">
<div class="draginput_cell" id="tool_alignleft" title="Align Left"></div>
<div class="draginput_cell" id="tool_aligncenter" title="Align Center"></div>
@ -488,14 +483,14 @@
<div class="stroke_tool draginput">
<span>Stroke Dash</span>
<select id="stroke_style" data-title="Change stroke dash style">
<option selected="selected" value="none">&mdash;</option>
<option selected="selected" value="none"></option>
<option value="2,2">···</option>
<option value="5,5">- -</option>
<option value="5,2,2,2">-·-</option>
<option value="5,2,2,2,2,2">-··-</option>
</select>
<div class="caret"></div>
<label id="stroke_style_label">&mdash;</label>
<label id="stroke_style_label"></label>
</div>
<label style="display: none;">
@ -556,7 +551,7 @@
<option value="25">25%</option>
<option value="50">50%</option>
<option value="75">75%</option>
<option selected value="100">100%</option>
<option value="100" selected="selected">100%</option>
<option value="150">150%</option>
<option value="200">200%</option>
<option value="300">300%</option>
@ -625,10 +620,10 @@
<li class="separator"><a href="#delete">Delete<span class="shortcut"></span></a></li>
<li class="separator"><a href="#group">Group<span class="shortcut">⌘G</span></a></li>
<li><a href="#ungroup">Ungroup<span class="shortcut">⌘⇧G</span></a></li>
<li class="separator"><a href="#move_front">Bring to Front<span class="shortcut">⌘⇧&uarr;</span></a></li>
<li><a href="#move_up">Bring Forward<span class="shortcut">&uarr;</span></a></li>
<li><a href="#move_down">Send Backward<span class="shortcut">&darr;</span></a></li>
<li><a href="#move_back">Send to Back<span class="shortcut">⌘⇧&darr;</span></a></li>
<li class="separator"><a href="#move_front">Bring to Front<span class="shortcut">⌘⇧</span></a></li>
<li><a href="#move_up">Bring Forward<span class="shortcut"></span></a></li>
<li><a href="#move_down">Send Backward<span class="shortcut"></span></a></li>
<li><a href="#move_back">Send to Back<span class="shortcut">⌘⇧</span></a></li>
</ul>
</body>

View File

@ -91,7 +91,7 @@ var f=Array(Math.floor((d.length+2)/3)*4),c,m,u,C,s,L,Q=0,K=0;do{c=d.charCodeAt(
d.length);return f.join("")};svgedit.utilities.decode64=function(d){if(window.atob)return window.atob(d);var f="",c,m,u="",C,s="",L=0;d=d.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(d.charAt(L++));
c=c<<2|m>>4;m=(m&15)<<4|C>>2;u=(C&3)<<6|s;f+=String.fromCharCode(c);if(C!=64)f+=String.fromCharCode(m);if(s!=64)f+=String.fromCharCode(u)}while(L<d.length);return unescape(f)};svgedit.utilities.convertToXMLReferences=function(d){for(var f="",c=0;c<d.length;c++){var m=d.charCodeAt(c);if(m<128)f+=d[c];else if(m>127)f+="&#"+m+";"}return f};svgedit.utilities.text2xml=function(d){if(d.indexOf("<svg:svg")>=0)d=d.replace(/<(\/?)svg:/g,"<$1").replace("xmlns:svg","xmlns");var f;try{var c=window.DOMParser?
new DOMParser:new ActiveXObject("Microsoft.XMLDOM");c.async=false}catch(m){throw Error("XML Parser could not be instantiated");}try{f=c.loadXML?c.loadXML(d)?c:false:c.parseFromString(d,"text/xml")}catch(u){throw Error("Error parsing XML string");}return f};svgedit.utilities.bboxToObj=function(d){return{x:d.x,y:d.y,width:d.width,height:d.height}};svgedit.utilities.walkTree=function(d,f){if(d&&d.nodeType==1){f(d);for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f)}};
svgedit.utilities.walkTreePost=function(d,f){if(d&&d.nodeType==1){for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f);f(d)}};svgedit.utilities.getUrlFromAttr=function(d){if(d)if(d.indexOf('url("')===0)return d.substring(5,d.indexOf('"',6));else if(d.indexOf("url('")===0)return d.substring(5,d.indexOf("'",6));else if(d.indexOf("url(")===0)return d.substring(4,d.indexOf(")"));return null};svgedit.utilities.getHref=function(d){return d.getAttributeNS("http://www.w3.org/1999/xlink",
svgedit.utilities.walkTreePost=function(d,f){if(d&&d.nodeType==1){for(var c=d.childNodes.length;c--;)svgedit.utilities.walkTree(d.childNodes.item(c),f);f(d)}};svgedit.utilities.getUrlFromAttr=function(d){if(d)if(d.indexOf('url("')===0)return d.substring(5,d.indexOf('"',6));else if(d.indexOf("url('")===0)return d.substring(5,d.indexOf("'",6));else if(d.indexOf("url(")===0)return d.substring(4,d.indexOf(")"));return null};svgedit.utilities.getHref=function(d){if(d)return d.getAttributeNS("http://www.w3.org/1999/xlink",
"href")};svgedit.utilities.setHref=function(d,f){d.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",f)};svgedit.utilities.findDefs=function(d){d=g.getSVGContent().documentElement;var f=d.getElementsByTagNameNS("http://www.w3.org/2000/svg","defs");return f=f.length>0?f[0]:d.insertBefore(d.ownerDocument.createElementNS("http://www.w3.org/2000/svg","defs"),d.firstChild.nextSibling)};svgedit.utilities.getPathBBox=function(d){var f=d.pathSegList,c=f.numberOfItems;d=[[],[]];var m=f.getItem(0),
u=[m.x,m.y];for(m=0;m<c;m++){var C=f.getItem(m);if(typeof C.x!="undefined"){d[0].push(u[0]);d[1].push(u[1]);if(C.x1){for(var s=[C.x1,C.y1],L=[C.x2,C.y2],Q=[C.x,C.y],K=0;K<2;K++){C=function(ga){return Math.pow(1-ga,3)*u[K]+3*Math.pow(1-ga,2)*ga*s[K]+3*(1-ga)*Math.pow(ga,2)*L[K]+Math.pow(ga,3)*Q[K]};var I=6*u[K]-12*s[K]+6*L[K],S=-3*u[K]+9*s[K]-9*L[K]+3*Q[K],R=3*s[K]-3*u[K];if(S==0){if(I!=0){I=-R/I;0<I&&I<1&&d[K].push(C(I))}}else{R=Math.pow(I,2)-4*R*S;if(!(R<0)){var N=(-I+Math.sqrt(R))/(2*S);0<N&&N<
1&&d[K].push(C(N));I=(-I-Math.sqrt(R))/(2*S);0<I&&I<1&&d[K].push(C(I))}}}u=Q}else{d[0].push(C.x);d[1].push(C.y)}}}f=Math.min.apply(null,d[0]);c=Math.max.apply(null,d[0])-f;m=Math.min.apply(null,d[1]);d=Math.max.apply(null,d[1])-m;return{x:f,y:m,width:c,height:d}};svgedit.utilities.getBBox=function(d){var f=d||g.getSelectedElements()[0];if(d.nodeType!=1)return null;d=null;var c=f.nodeName;switch(c){case "text":if(f.textContent===""){f.textContent="a";d=f.getBBox();f.textContent=""}else try{d=f.getBBox()}catch(m){}break;

View File

@ -298,7 +298,7 @@ svgedit.utilities.getUrlFromAttr = function(attrVal) {
// Function: svgedit.utilities.getHref
// Returns the given element's xlink:href value
svgedit.utilities.getHref = function(elem) {
return elem.getAttributeNS(XLINKNS, "href");
if (elem) return elem.getAttributeNS(XLINKNS, "href");
}
// Function: svgedit.utilities.setHref