Skip to content

Commit

Permalink
release 1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
misakuo committed Mar 30, 2016
1 parent c8a4c85 commit c42a10e
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 45 deletions.
4 changes: 3 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>com.moxun.plugin.s2v</id>
<name>SVG2VectorDrawable</name>
<version>1.4.2</version>
<version>1.4.3</version>
<vendor email="[email protected]">moxun</vendor>

<description><![CDATA[
Expand All @@ -13,6 +13,8 @@
]]></description>

<change-notes><![CDATA[
<b>1.4.3</b><br>
Fix bug on merge transform attributes.<br>
<b>1.4.2</b><br>
Optimizing for SVG that exported by Sketch.<br>
<b>1.4.1</b><br>
Expand Down
6 changes: 3 additions & 3 deletions src/com/moxun/s2v/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiManager;
import com.intellij.psi.impl.file.PsiDirectoryFactory;
import com.intellij.psi.xml.XmlFile;
import com.moxun.s2v.message.ErrorMessage;
import com.moxun.s2v.utils.Logger;
import com.moxun.s2v.utils.ModulesUtil;
import com.moxun.s2v.utils.MyCellRender;
import com.moxun.s2v.utils.UpdateUtil;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class GUI {

public GUI(Project project) {
this.project = project;
frame = new JFrame("SVG to VectorDrawable (1.4.2)");
frame = new JFrame("SVG to VectorDrawable (1.4.3)");
modulesUtil = new ModulesUtil(project);
distDirList.clear();
svgPath.setFocusable(false);
Expand Down
5 changes: 0 additions & 5 deletions src/com/moxun/s2v/S2V.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.moxun.s2v;

import com.intellij.ide.actions.CreateFileFromTemplateDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.psi.PsiElement;
import com.jetbrains.cidr.lang.actions.newFile.OCNewFileActionBase;
import com.moxun.s2v.utils.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Created by moxun on 15/12/14.
Expand Down
10 changes: 10 additions & 0 deletions src/com/moxun/s2v/SVGParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public List<XmlTag> getGroupChildes(String groupName) {
return childes;
}

public List<XmlTag> getSubGroups(XmlTag parent) {
List<XmlTag> list = new ArrayList<XmlTag>();
for (XmlTag tag : parent.getSubTags()) {
if (tag.getName().equals("g")) {
list.add(tag);
}
}
return list;
}

public List<XmlTag> getSVGChildes() {
List<XmlTag> childes = new ArrayList<XmlTag>();
if (svg.getDocument() != null) {
Expand Down
61 changes: 38 additions & 23 deletions src/com/moxun/s2v/Transformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,7 @@ public void transforming() {
//generate group
if (svgParser.hasGroupTag()) {
for (XmlTag g : svgParser.getGroups()) {
XmlTag group = rootTag.createChildTag("group", rootTag.getNamespace(), null, false);
//set group's attrs
Map<String, String> svgGroupAttrs = svgParser.getChildAttrs(g);
for (String key : svgGroupAttrs.keySet()) {
if (key.equals("fill")) {
//<group> tag not support color attr
continue;
}
if (AttrMapper.getAttrName(key) != null) {
group.setAttribute(AttrMapper.getAttrName(key), svgGroupAttrs.get(key));
}
}

if (svgGroupAttrs.keySet().contains("transform")) {
Map<String, String> trans = AttrMapper.getTranslateAttrs(svgGroupAttrs.get("transform"));
for (String key : trans.keySet()) {
group.setAttribute(key, trans.get(key));
}
}

//add child tags
parseShapeNode(g, group);
rootTag.addSubTag(group, false);
parseGroup(g, rootTag);
}
} else {
Logger.warn("Root tag has no subTag named 'group'");
Expand All @@ -102,6 +80,43 @@ public void transforming() {
}
}

private void parseGroup(XmlTag svgTag, XmlTag target) {
XmlTag group = target.createChildTag("group", target.getNamespace(), null, false);
//set group's attrs
Map<String, String> svgGroupAttrs = svgParser.getChildAttrs(svgTag);
for (String key : svgGroupAttrs.keySet()) {
if (key.equals("fill")) {
//<group> tag not support color attr
continue;
}
if (AttrMapper.getAttrName(key) != null) {
group.setAttribute(AttrMapper.getAttrName(key), svgGroupAttrs.get(key));
}
}

if (svgGroupAttrs.keySet().contains("transform")) {
Map<String, String> trans = AttrMapper.getTranslateAttrs(svgGroupAttrs.get("transform"));
for (String key : trans.keySet()) {
group.setAttribute(key, trans.get(key));
}
}

//add child tags
//<g> was processed.
parseShapeNode(svgTag, group);
processSubGroups(svgTag, group);
target.addSubTag(group, false);
}

private void processSubGroups(XmlTag svgTag, XmlTag parent) {
Map<String, String> trans = AttrMapper.getTranslateAttrs(svgTag.getAttributeValue("transform"));
Logger.debug("Translate for sub groups:" + trans.toString());
XmlTag merged = AttrMergeUtil.mergeAttrs((XmlTag) svgTag.copy(), trans);
for (XmlTag tag : svgParser.getSubGroups(merged)) {
parseGroup(tag, parent);
}
}

private void parseShapeNode(XmlTag srcTag, XmlTag distTag) {
List<XmlTag> childes = svgParser.getShapeTags(srcTag);
for (XmlTag child : childes) {
Expand Down
9 changes: 5 additions & 4 deletions src/com/moxun/s2v/utils/AttrMapper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.moxun.s2v.utils;

import com.intellij.openapi.util.text.StringUtil;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* http://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html
Expand Down Expand Up @@ -53,7 +50,8 @@ public static String getAttrName(String svgAttrName) {

public static Map<String, String> getTranslateAttrs(String transAttr) {
Map<String, String> result = new HashMap<String, String>();
String tmp = transAttr.replaceAll(" ", ",");
String tmp = transAttr.replaceAll(" ", ",");
tmp = tmp.replaceAll(",,", ",");
String translate = StringUtils.substringBetween(tmp, "translate(", ")");
String scale = StringUtils.substringBetween(tmp, "scale(", ")");
String rotate = StringUtils.substringBetween(tmp, "rotate(", ")");
Expand Down Expand Up @@ -91,12 +89,15 @@ public static Map<String, String> getTranslateAttrs(String transAttr) {
result.put("android:pivotY", rxy[2]);
}
}
Logger.debug("Attrs Transformer: " + transAttr + " ===> " + result.toString());
return result;
}

//test case
public static void main(String args[]) {
String s = "translate(100 50),scale(0.5)rotate(30,100,100)";
System.out.println(getTranslateAttrs(s));
String s1 = "translate(14.000000, 14.000000)";
System.out.println(getTranslateAttrs(s1));
}
}
19 changes: 14 additions & 5 deletions src/com/moxun/s2v/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Logger {
public static final int WARN = 1;
public static final int ERROR = 0;

public static void init(String name,int level) {
public static void init(String name, int level) {
NAME = name;
LEVEL = level;
NotificationsConfiguration.getNotificationsConfiguration().register(NAME, NotificationDisplayType.NONE);
Expand All @@ -24,28 +24,37 @@ public static void init(String name,int level) {
public static void debug(String text) {
if (LEVEL >= DEBUG) {
Notifications.Bus.notify(
new Notification(NAME, NAME + " [DEBUG]", text, NotificationType.INFORMATION));
new Notification(NAME, NAME + " [DEBUG]", redirect(text), NotificationType.INFORMATION));
}
}

public static void info(String text) {
if (LEVEL > INFO) {
Notifications.Bus.notify(
new Notification(NAME, NAME + " [INFO]", text, NotificationType.INFORMATION));
new Notification(NAME, NAME + " [INFO]", redirect(text), NotificationType.INFORMATION));
}
}

public static void warn(String text) {
if (LEVEL > WARN) {
Notifications.Bus.notify(
new Notification(NAME, NAME + " [WARN]", text, NotificationType.WARNING));
new Notification(NAME, NAME + " [WARN]", redirect(text), NotificationType.WARNING));
}
}

public static void error(String text) {
if (LEVEL > ERROR) {
Notifications.Bus.notify(
new Notification(NAME, NAME + " [ERROR]", text, NotificationType.ERROR));
new Notification(NAME, NAME + " [ERROR]", redirect(text), NotificationType.ERROR));
}
}

private static String redirect(String text) {
if (LEVEL == DEBUG) {
StackTraceElement ste = new Throwable().getStackTrace()[2];
String tail = "\t\t\t at " + ste.toString();
System.err.println(text + tail);
}
return text;
}
}
1 change: 0 additions & 1 deletion src/com/moxun/s2v/utils/MyCellRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import javax.swing.*;
import java.awt.*;
import java.util.HashSet;
import java.util.Set;

/**
Expand Down
Binary file modified svg2android.jar
Binary file not shown.
Binary file added svg2android_1.4.2.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version":"1.4.2",
"versionCode":5,
"desc":"Optimized for Sketch exported file."
"version":"1.4.3",
"versionCode":6,
"desc":"Fix bug on merge transform attributes."
}

0 comments on commit c42a10e

Please sign in to comment.