|
Last change
on this file since 4792 was 4256, checked in by bastiK, 15 years ago |
|
see #6560 - basic svg support, includes kitfox svgsalamander, r 98, patched
|
|
File size:
2.0 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * PathUtil.java
|
|---|
| 3 | *
|
|---|
| 4 | * Created on May 10, 2005, 5:56 AM
|
|---|
| 5 | *
|
|---|
| 6 | * To change this template, choose Tools | Options and locate the template under
|
|---|
| 7 | * the Source Creation and Management node. Right-click the template and choose
|
|---|
| 8 | * Open. You can then make changes to the template in the Source Editor.
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | package com.kitfox.svg.pathcmd;
|
|---|
| 12 |
|
|---|
| 13 | import java.awt.geom.*;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | *
|
|---|
| 17 | * @author kitfox
|
|---|
| 18 | */
|
|---|
| 19 | public class PathUtil
|
|---|
| 20 | {
|
|---|
| 21 |
|
|---|
| 22 | /** Creates a new instance of PathUtil */
|
|---|
| 23 | public PathUtil()
|
|---|
| 24 | {
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Converts a GeneralPath into an SVG representation
|
|---|
| 29 | */
|
|---|
| 30 | public static String buildPathString(GeneralPath path)
|
|---|
| 31 | {
|
|---|
| 32 | float[] coords = new float[6];
|
|---|
| 33 |
|
|---|
| 34 | StringBuffer sb = new StringBuffer();
|
|---|
| 35 |
|
|---|
| 36 | for (PathIterator pathIt = path.getPathIterator(new AffineTransform()); !pathIt.isDone(); pathIt.next())
|
|---|
| 37 | {
|
|---|
| 38 | int segId = pathIt.currentSegment(coords);
|
|---|
| 39 |
|
|---|
| 40 | switch (segId)
|
|---|
| 41 | {
|
|---|
| 42 | case PathIterator.SEG_CLOSE:
|
|---|
| 43 | {
|
|---|
| 44 | sb.append(" Z");
|
|---|
| 45 | break;
|
|---|
| 46 | }
|
|---|
| 47 | case PathIterator.SEG_CUBICTO:
|
|---|
| 48 | {
|
|---|
| 49 | sb.append(" C " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3] + " " + coords[4] + " " + coords[5]);
|
|---|
| 50 | break;
|
|---|
| 51 | }
|
|---|
| 52 | case PathIterator.SEG_LINETO:
|
|---|
| 53 | {
|
|---|
| 54 | sb.append(" L " + coords[0] + " " + coords[1]);
|
|---|
| 55 | break;
|
|---|
| 56 | }
|
|---|
| 57 | case PathIterator.SEG_MOVETO:
|
|---|
| 58 | {
|
|---|
| 59 | sb.append(" M " + coords[0] + " " + coords[1]);
|
|---|
| 60 | break;
|
|---|
| 61 | }
|
|---|
| 62 | case PathIterator.SEG_QUADTO:
|
|---|
| 63 | {
|
|---|
| 64 | sb.append(" Q " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]);
|
|---|
| 65 | break;
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | return sb.toString();
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.