Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList Destruct(String path){
- ArrayList<Vector> list = new ArrayList<>();
- String s = "";
- Pattern p;
- Matcher m;
- try{
- s = new String(Files.readAllBytes(Paths.get(path)));
- }catch(IOException e){
- return list;
- }
- String pattern = "<[a-z][^\/]*\/>"; //Паттерн для нахождения фигур
- p = Pattern.compile(pattern);
- m = p.matcher(s);
- while (m.find()){
- String str = m.group().replaceAll("\s+", " "); //Убирает табулирование
- String[] words = str.split(" ");
- switch(words[0]){
- case "<path":;
- case "<rect": list.add(RectDestruct(words));
- case "<circle": list.add(CircleDestruct(words));
- case "<ellipse": list.add(EllipseDestruct(words));
- case "<line": list.add(LineDestruct(words));
- case "<polyline": list.add(PolylineDestruct(words, false));
- case "<polygon": list.add(PolygonDestruct(words));
- }
- }
- return list;
- }
- <?xml version="1.0" standalone="no"?>
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
- "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
- <svg width="12cm" height="4cm" viewBox="0 0 1200 400"
- xmlns="http://www.w3.org/2000/svg" version="1.1">
- <desc>Example rect01 - rectangle with sharp corners</desc>
- <!-- Show outline of canvas using 'rect' element -->
- <rect x="1" y="1" width="1198" height="398"
- fill="none" stroke="blue" stroke-width="2"/>
- <rect x="400" y="100" width="400" height="200"
- fill="yellow" stroke="navy" stroke-width="10" />
- </svg>
- public static Rect RectDestruct(String[] words){
- Rect rect = new Rect();
- for (String word : words) {
- if (word.contains("x")) {
- rect.posX = Double.parseDouble(word.replaceAll("\D+", ""));
- }else
- if (word.contains("y")) {
- rect.posY = Double.parseDouble(word.replaceAll("\D+", ""));
- }else
- if (word.contains("width")) {
- rect.width = Double.parseDouble(word.replaceAll("\D+", ""));
- }else
- if (word.contains("height")) {
- rect.height = Double.parseDouble(word.replaceAll("\D+", ""));
- }else
- if (word.contains("rx")) {
- rect.rx = Double.parseDouble(word.replaceAll("\D+", ""));
- }else
- if (word.contains("ry")) {
- rect.ry = Double.parseDouble(word.replaceAll("\D+", ""));
- }
- }
- return rect;
- }
Add Comment
Please, Sign In to add comment