Skip to content

Commit

Permalink
Fixed use references inloop#30
Browse files Browse the repository at this point in the history
  • Loading branch information
yuraj11 committed Dec 21, 2015
1 parent a1e4fc6 commit a9ff1b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3>Android SVG to VectorDrawable</h3>
<div class="nouploadinfo small">No file will be uploaded - uses only JavaScript HTML5 FileReader.<br /><br /></div>

<div class="nouploadinfo small alert alert-warning" style="display: inline-block"><b>Now supports path, line, rect, circle, ellipse, polyline and polygon elements.</b><br/>
Keep in mind that Android does support svg files only partially.</div>
Keep in mind that Android does support svg files only partially.<br/>Please report wrongly converted SVGs by filling an issue on github.</div>
</div>
</div>

Expand Down Expand Up @@ -131,7 +131,7 @@ <h4 class="modal-title">Multiple SVG files (<span id="files-count"></span> files
<script src="js/svg_shape_converter.js"></script>
<script src="js/flatten.js"></script>
<script src="js/jszip.min.js"></script>
<script src="js/main.js?v=19"></script>
<script src="js/main.js?v=20"></script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
21 changes: 13 additions & 8 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,17 @@ function recursiveTreeWalk(parent, groupLevel) {
printPath(ShapeConverter.convertPolygon(current, false), getStyles(current), groupLevel);
} else if (current.is("text")) {
pushUnique(warnings, "<i>text</i> element is not supported, export all text into path");
} else if (current.is("use")) {
parseUseRef(parent, current, groupLevel);
}
});
}

function preprocessReferences(svg, grouplevel) {
svg.find("use").each(function () {
var current = $(this);
substituteUseRef(svg, current);
});
}

function getStyles(el) {
var styles = parseStyles(el);

Expand All @@ -229,7 +234,7 @@ function getStyles(el) {
return [styles, parentStyles];
}

function parseUseRef(parent, current, groupLevel) {
function substituteUseRef(parent, current) {
var href = current.attr("xlink:href");
if (typeof href !== "undefined") {
href = href.trim();
Expand All @@ -238,16 +243,14 @@ function parseUseRef(parent, current, groupLevel) {
//Find definition in svg
var defs = $(parent).find("[id='" + href.substr(1) + "']");
if (defs.length) {
defs = defs.clone();

//Copy overriding attributes into children
$.each(current.prop("attributes"), function () {
defs.attr(this.name, this.value);
});

if (defs.children().length == 0) {
recursiveTreeWalk($("<g></g>").append(defs), groupLevel);
} else {
recursiveTreeWalk(defs, groupLevel);
}
current.replaceWith(defs);
} else {
console.warn("Found <use> tag but did not found appropriate block in <defs> for id " + href);
}
Expand Down Expand Up @@ -472,6 +475,8 @@ function generateCode(inputXml) {

var svg = xml.find("svg");

preprocessReferences(svg);

if (toBool(localStorage.bakeTransforms)) {
try {
flatten(svg[0], false, true);
Expand Down

0 comments on commit a9ff1b2

Please sign in to comment.