Skip to content

Commit

Permalink
Added warning when fill/stroke uses gradient/pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Juraj Novák committed Oct 30, 2014
1 parent 1b49df6 commit 204acde
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
8 changes: 8 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ footer {
background-color: lightblue;
}

.info-items td {
vertical-align:top;
}

.info-items td:first-child {
width:90px;
}

#header {
background: #e0f2f1;
color: #7FB6B4;
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h3>Android SVG to VectorDrawable (Alpha)</h3>
<script src="js/cssjson.js"></script>
<script src='js/filereader.js'></script>
<script src='js/filesaver.min.js'></script>
<script src="js/main.js"></script>
<script src="js/main.js?v=1"></script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
40 changes: 36 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ String.prototype.f = function () {
return s;
};

String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
Array.prototype.pushUnique = function (item){
if(this.indexOf(item) == -1) {
this.push(item);
return true;
}
return false;
};

if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}

if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function (str){
return this.indexOf(str) == 0;
};
}

/* ------ */
var lastFileName = "";

Expand Down Expand Up @@ -73,6 +89,7 @@ function parseFile(inputXml) {
var START_PATH = "M";
var END_PATH = "Z";
var stylesJson = [];
var warnings = [];
var groupTransform = null;
var transformSet = false;

Expand All @@ -81,8 +98,8 @@ function parseFile(inputXml) {
var parentTag = $(paths[i]).parent().get(0);

if (path.match(/-?\d*\.?\d+e[+-]?\d+/g)) {
setMessage("<b>Warning:</b> found some numbers with scientific E notation in pathData which Android probably does not support. " +
"Please fix It manually by editing your editor precision or manually by editing pathData.", "alert-warning");
warnings.pushUnique("found some numbers with scientific E notation in pathData which Android probably does not support. " +
"Please fix It manually by editing your editor precision or manually by editing pathData");
}

//Check If parent is group, apply transform
Expand Down Expand Up @@ -145,6 +162,10 @@ function parseFile(inputXml) {
for (var key in cssAttributes) {
if (cssAttributes.hasOwnProperty(key)) {
stylesJson[i][key] = cssAttributes[key];

if ((key == "fill" || key == "stroke") && cssAttributes[key].startsWith("url")) {
warnings.pushUnique("found fill(s) or stroke(s) which uses <i>url()</i> (gradients and patterns are not supported in Android)");
}
}
}
} else {
Expand All @@ -164,6 +185,17 @@ function parseFile(inputXml) {
$(".nouploadinfo").hide();
$("#dropzone").animate({ height: 50}, 500);
$("#success-box").show();

//Show warnings If set
if (warnings.length == 1) {
setMessage("<b>Warning:</b> " + warnings[0], "alert-warning")
} else if (warnings.length > 1) {
var warnText = "";
warnings.forEach(function (w, i) {
warnText += "<tr><td><b>Warning #" + (i+1) + ":</b></td><td>" + w + "</td></tr>";
});
setMessage("<table class='info-items'>" + warnText + "</table>", "alert-warning")
}
}
}

Expand Down

0 comments on commit 204acde

Please sign in to comment.