Guest User

Untitled

a guest
Feb 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. public static ArrayList Destruct(String path){
  2. ArrayList<Vector> list = new ArrayList<>();
  3. String s = "";
  4. Pattern p;
  5. Matcher m;
  6.  
  7. try{
  8. s = new String(Files.readAllBytes(Paths.get(path)));
  9. }catch(IOException e){
  10. return list;
  11. }
  12.  
  13. String pattern = "<[a-z][^\/]*\/>"; //Паттерн для нахождения фигур
  14. p = Pattern.compile(pattern);
  15. m = p.matcher(s);
  16.  
  17. while (m.find()){
  18. String str = m.group().replaceAll("\s+", " "); //Убирает табулирование
  19. String[] words = str.split(" ");
  20. switch(words[0]){
  21. case "<path":;
  22. case "<rect": list.add(RectDestruct(words));
  23. case "<circle": list.add(CircleDestruct(words));
  24. case "<ellipse": list.add(EllipseDestruct(words));
  25. case "<line": list.add(LineDestruct(words));
  26. case "<polyline": list.add(PolylineDestruct(words, false));
  27. case "<polygon": list.add(PolygonDestruct(words));
  28. }
  29. }
  30. return list;
  31.  
  32. }
  33.  
  34. <?xml version="1.0" standalone="no"?>
  35. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  36. "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  37. <svg width="12cm" height="4cm" viewBox="0 0 1200 400"
  38. xmlns="http://www.w3.org/2000/svg" version="1.1">
  39. <desc>Example rect01 - rectangle with sharp corners</desc>
  40.  
  41. <!-- Show outline of canvas using 'rect' element -->
  42. <rect x="1" y="1" width="1198" height="398"
  43. fill="none" stroke="blue" stroke-width="2"/>
  44.  
  45. <rect x="400" y="100" width="400" height="200"
  46. fill="yellow" stroke="navy" stroke-width="10" />
  47. </svg>
  48.  
  49. public static Rect RectDestruct(String[] words){
  50. Rect rect = new Rect();
  51. for (String word : words) {
  52. if (word.contains("x")) {
  53. rect.posX = Double.parseDouble(word.replaceAll("\D+", ""));
  54. }else
  55. if (word.contains("y")) {
  56. rect.posY = Double.parseDouble(word.replaceAll("\D+", ""));
  57. }else
  58. if (word.contains("width")) {
  59. rect.width = Double.parseDouble(word.replaceAll("\D+", ""));
  60. }else
  61. if (word.contains("height")) {
  62. rect.height = Double.parseDouble(word.replaceAll("\D+", ""));
  63. }else
  64. if (word.contains("rx")) {
  65. rect.rx = Double.parseDouble(word.replaceAll("\D+", ""));
  66. }else
  67. if (word.contains("ry")) {
  68. rect.ry = Double.parseDouble(word.replaceAll("\D+", ""));
  69. }
  70. }
  71. return rect;
  72. }
Add Comment
Please, Sign In to add comment