1313import java .awt .Stroke ;
1414import java .awt .geom .AffineTransform ;
1515import java .awt .geom .Area ;
16+ import java .awt .geom .Ellipse2D ;
17+ import java .awt .geom .Line2D ;
1618import java .awt .geom .Path2D ;
19+ import java .awt .geom .Point2D ;
1720import java .awt .geom .RoundRectangle2D ;
1821import java .io .IOException ;
1922import java .net .URL ;
@@ -106,25 +109,116 @@ public ElementProcessor setValue(ElementProcessor value) {
106109 case "M" -> {
107110 path .moveTo (scanner .nextFloat (), scanner .nextFloat ());
108111 }
112+ case "m" -> {
113+ Point2D current = path .getCurrentPoint ();
114+ double x = scanner .nextFloat () + current .getX ();
115+ double y = scanner .nextFloat () + current .getY ();
116+ path .moveTo (x , y );
117+ }
109118 case "Q" -> {
110119 path .quadTo (scanner .nextFloat (), scanner .nextFloat (),
111120 scanner .nextFloat (), scanner .nextFloat ());
112121 }
122+ case "q" -> {
123+ Point2D current = path .getCurrentPoint ();
124+ double x1 = scanner .nextFloat () + current .getX ();
125+ double y1 = scanner .nextFloat () + current .getY ();
126+ double x2 = scanner .nextFloat () + current .getX ();
127+ double y2 = scanner .nextFloat () + current .getY ();
128+ path .quadTo (x1 , y1 , x2 , y2 );
129+ }
130+ case "C" -> {
131+ path .curveTo (scanner .nextFloat (), scanner .nextFloat (),
132+ scanner .nextFloat (), scanner .nextFloat (),
133+ scanner .nextFloat (), scanner .nextFloat ());
134+ }
135+ case "c" -> {
136+ Point2D current = path .getCurrentPoint ();
137+ double x1 = scanner .nextFloat () + current .getX ();
138+ double y1 = scanner .nextFloat () + current .getY ();
139+ double x2 = scanner .nextFloat () + current .getX ();
140+ double y2 = scanner .nextFloat () + current .getY ();
141+ double x3 = scanner .nextFloat () + current .getX ();
142+ double y3 = scanner .nextFloat () + current .getY ();
143+ path .curveTo (x1 , y1 , x2 , y2 , x3 , y3 );
144+ }
113145 case "L" -> {
114146 path .lineTo (scanner .nextFloat (), scanner .nextFloat ());
115147 }
148+ case "l" -> {
149+ Point2D current = path .getCurrentPoint ();
150+ double x = scanner .nextFloat () + current .getX ();
151+ double y = scanner .nextFloat () + current .getY ();
152+ path .lineTo (x , y );
153+ }
116154 case "V" -> {
117155 path .lineTo (path .getCurrentPoint ().getX (), scanner .nextFloat ());
118156 }
157+ case "v" -> {
158+ Point2D current = path .getCurrentPoint ();
159+ path .lineTo (current .getX (), scanner .nextFloat () + current .getY ());
160+ }
119161 case "H" -> {
120162 path .lineTo (scanner .nextFloat (), path .getCurrentPoint ().getY ());
121163 }
122- case "Z" -> {
164+ case "h" -> {
165+ Point2D current = path .getCurrentPoint ();
166+ path .lineTo (scanner .nextFloat () + current .getX (), current .getY ());
167+ }
168+ case "Z" , "z" -> {
123169 path .closePath ();
124170 }
171+ case "S" , "s" , "T" , "t" -> {
172+ System .err .println ("Curve extension not supported" );
173+ }
174+ case "A" , "a" -> {
175+ System .err .println ("Arcs not supported" );
176+ }
177+ default -> {
178+ System .err .println ("Operation not supported" );
179+ }
125180 }
126181 }
127182 return path ;
183+ }),
184+ new ElementProcessor ("polyline" , (Element node ) -> {
185+ Path2D path = new Path2D .Float ();
186+ Scanner scanner = new Scanner (node .getAttribute ("points" ));
187+ path .moveTo (scanner .nextFloat (), scanner .nextFloat ());
188+ while (scanner .hasNext ()) {
189+ path .lineTo (scanner .nextFloat (), scanner .nextFloat ());
190+ }
191+ return path ;
192+ }),
193+ new ElementProcessor ("polygon" , (Element node ) -> {
194+ Path2D path = new Path2D .Float ();
195+ Scanner scanner = new Scanner (node .getAttribute ("points" ));
196+ path .moveTo (scanner .nextFloat (), scanner .nextFloat ());
197+ while (scanner .hasNext ()) {
198+ path .lineTo (scanner .nextFloat (), scanner .nextFloat ());
199+ }
200+ path .closePath ();
201+ return path ;
202+ }),
203+ new ElementProcessor ("circle" , (Element node ) -> {
204+ float x = Float .parseFloat (node .getAttribute ("cx" ));
205+ float y = Float .parseFloat (node .getAttribute ("cy" ));
206+ float r = Float .parseFloat (node .getAttribute ("r" ));
207+ return new Ellipse2D .Float (x - r , y - r , r * 2 , r * 2 );
208+ }),
209+ new ElementProcessor ("ellipse" , (Element node ) -> {
210+ float x = Float .parseFloat (node .getAttribute ("cx" ));
211+ float y = Float .parseFloat (node .getAttribute ("cy" ));
212+ float rx = Float .parseFloat (node .getAttribute ("rx" ));
213+ float ry = Float .parseFloat (node .getAttribute ("ry" ));
214+ return new Ellipse2D .Float (x - rx , y - ry , rx * 2 , ry * 2 );
215+ }),
216+ new ElementProcessor ("line" , (Element node ) -> {
217+ float x1 = Float .parseFloat (node .getAttribute ("x1" ));
218+ float y1 = Float .parseFloat (node .getAttribute ("y1" ));
219+ float x2 = Float .parseFloat (node .getAttribute ("x2" ));
220+ float y2 = Float .parseFloat (node .getAttribute ("y2" ));
221+ return new Line2D .Float (x1 , y1 , x2 , y2 );
128222 })
129223 );
130224 public SVGImage (URL url ) {
@@ -148,7 +242,7 @@ public SVGImage(URL url) {
148242 }
149243 }
150244 } catch (ParserConfigurationException | SAXException | IOException e ) {
151- System .out .println (e );
245+ System .err .println (e );
152246 }
153247 }
154248 public Icon getIcon (int width , int height ) {
0 commit comments