diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 9f0d685..a056005 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.moxun.plugin.s2v SVG2VectorDrawable - 1.4.2 + 1.4.3 moxun 1.4.3
+ Fix bug on merge transform attributes.
1.4.2
Optimizing for SVG that exported by Sketch.
1.4.1
diff --git a/src/com/moxun/s2v/GUI.java b/src/com/moxun/s2v/GUI.java index 368c9b6..f9f3472 100644 --- a/src/com/moxun/s2v/GUI.java +++ b/src/com/moxun/s2v/GUI.java @@ -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.*; @@ -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); diff --git a/src/com/moxun/s2v/S2V.java b/src/com/moxun/s2v/S2V.java index d77bf57..5ace458 100644 --- a/src/com/moxun/s2v/S2V.java +++ b/src/com/moxun/s2v/S2V.java @@ -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. diff --git a/src/com/moxun/s2v/SVGParser.java b/src/com/moxun/s2v/SVGParser.java index d65815c..aa96c2a 100644 --- a/src/com/moxun/s2v/SVGParser.java +++ b/src/com/moxun/s2v/SVGParser.java @@ -110,6 +110,16 @@ public List getGroupChildes(String groupName) { return childes; } + public List getSubGroups(XmlTag parent) { + List list = new ArrayList(); + for (XmlTag tag : parent.getSubTags()) { + if (tag.getName().equals("g")) { + list.add(tag); + } + } + return list; + } + public List getSVGChildes() { List childes = new ArrayList(); if (svg.getDocument() != null) { diff --git a/src/com/moxun/s2v/Transformer.java b/src/com/moxun/s2v/Transformer.java index 9bfedc1..55f4f8d 100644 --- a/src/com/moxun/s2v/Transformer.java +++ b/src/com/moxun/s2v/Transformer.java @@ -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 svgGroupAttrs = svgParser.getChildAttrs(g); - for (String key : svgGroupAttrs.keySet()) { - if (key.equals("fill")) { - // 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 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'"); @@ -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 svgGroupAttrs = svgParser.getChildAttrs(svgTag); + for (String key : svgGroupAttrs.keySet()) { + if (key.equals("fill")) { + // 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 trans = AttrMapper.getTranslateAttrs(svgGroupAttrs.get("transform")); + for (String key : trans.keySet()) { + group.setAttribute(key, trans.get(key)); + } + } + + //add child tags + // was processed. + parseShapeNode(svgTag, group); + processSubGroups(svgTag, group); + target.addSubTag(group, false); + } + + private void processSubGroups(XmlTag svgTag, XmlTag parent) { + Map 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 childes = svgParser.getShapeTags(srcTag); for (XmlTag child : childes) { diff --git a/src/com/moxun/s2v/utils/AttrMapper.java b/src/com/moxun/s2v/utils/AttrMapper.java index 77dc164..b481b31 100644 --- a/src/com/moxun/s2v/utils/AttrMapper.java +++ b/src/com/moxun/s2v/utils/AttrMapper.java @@ -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 @@ -53,7 +50,8 @@ public static String getAttrName(String svgAttrName) { public static Map getTranslateAttrs(String transAttr) { Map result = new HashMap(); - 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(", ")"); @@ -91,6 +89,7 @@ public static Map getTranslateAttrs(String transAttr) { result.put("android:pivotY", rxy[2]); } } + Logger.debug("Attrs Transformer: " + transAttr + " ===> " + result.toString()); return result; } @@ -98,5 +97,7 @@ public static Map getTranslateAttrs(String transAttr) { 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)); } } diff --git a/src/com/moxun/s2v/utils/Logger.java b/src/com/moxun/s2v/utils/Logger.java index daeb37d..d892169 100644 --- a/src/com/moxun/s2v/utils/Logger.java +++ b/src/com/moxun/s2v/utils/Logger.java @@ -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); @@ -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; + } } diff --git a/src/com/moxun/s2v/utils/MyCellRender.java b/src/com/moxun/s2v/utils/MyCellRender.java index 126130b..f7f2bba 100644 --- a/src/com/moxun/s2v/utils/MyCellRender.java +++ b/src/com/moxun/s2v/utils/MyCellRender.java @@ -2,7 +2,6 @@ import javax.swing.*; import java.awt.*; -import java.util.HashSet; import java.util.Set; /** diff --git a/svg2android.jar b/svg2android.jar index 259a8dd..bc71db6 100644 Binary files a/svg2android.jar and b/svg2android.jar differ diff --git a/svg2android_1.4.2.jar b/svg2android_1.4.2.jar new file mode 100644 index 0000000..259a8dd Binary files /dev/null and b/svg2android_1.4.2.jar differ diff --git a/version.js b/version.js index 5a9d637..7e12944 100644 --- a/version.js +++ b/version.js @@ -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." }