| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.io.IOException; |
| 5 |
import java.util.Vector; |
| 6 |
|
| 7 |
import org.freehep.graphicsio.CubicToQuadPathConstructor; |
| 8 |
import org.freehep.graphicsio.swf.SWFShape.Record; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class SWFPathConstructor extends CubicToQuadPathConstructor implements |
| 15 |
SWFConstants { |
| 16 |
private Vector<Record> path; |
| 17 |
|
| 18 |
|
| 19 |
private int x0, y0; |
| 20 |
|
| 21 |
private int xc, yc; |
| 22 |
|
| 23 |
private int stroke, fill0, fill1; |
| 24 |
|
| 25 |
public SWFPathConstructor(Vector<Record> path, int stroke, int fill0, int fill1) { |
| 26 |
|
| 27 |
this(path, stroke, fill0, fill1, 0.5 / TWIPS); |
| 28 |
} |
| 29 |
|
| 30 |
public SWFPathConstructor(Vector<Record> path, int stroke, int fill0, int fill1, |
| 31 |
double resolution) { |
| 32 |
super(resolution); |
| 33 |
this.path = path; |
| 34 |
this.stroke = stroke; |
| 35 |
this.fill0 = fill0; |
| 36 |
this.fill1 = fill1; |
| 37 |
} |
| 38 |
|
| 39 |
public void move(double x, double y) throws IOException { |
| 40 |
x0 = toInt(x); |
| 41 |
y0 = toInt(y); |
| 42 |
xc = x0; |
| 43 |
yc = y0; |
| 44 |
path.add(new SWFShape.ShapeRecord(true, xc, yc, fill0, fill1, stroke)); |
| 45 |
super.move(x, y); |
| 46 |
} |
| 47 |
|
| 48 |
public void line(double x, double y) throws IOException { |
| 49 |
int dx = toInt(x) - xc; |
| 50 |
int dy = toInt(y) - yc; |
| 51 |
path.add(new SWFShape.EdgeRecord(dx, dy)); |
| 52 |
xc += dx; |
| 53 |
yc += dy; |
| 54 |
super.line(x, y); |
| 55 |
} |
| 56 |
|
| 57 |
public void quad(double x1, double y1, double x2, double y2) |
| 58 |
throws IOException { |
| 59 |
int cdx = toInt(x1) - xc; |
| 60 |
int cdy = toInt(y1) - yc; |
| 61 |
int dx = toInt(x2 - x1); |
| 62 |
int dy = toInt(y2 - y1); |
| 63 |
path.add(new SWFShape.EdgeRecord(cdx, cdy, dx, dy)); |
| 64 |
xc += dx + cdx; |
| 65 |
yc += dy + cdy; |
| 66 |
|
| 67 |
|
| 68 |
currentX = x2; |
| 69 |
currentY = y2; |
| 70 |
} |
| 71 |
|
| 72 |
public void closePath(double xd0, double yd0) throws IOException { |
| 73 |
if ((xc != x0) || (yc != y0)) { |
| 74 |
|
| 75 |
path.add(new SWFShape.EdgeRecord(x0 - xc, y0 - yc)); |
| 76 |
} |
| 77 |
super.closePath(xd0, yd0); |
| 78 |
} |
| 79 |
|
| 80 |
private int toInt(double d) { |
| 81 |
return (int) (d * TWIPS); |
| 82 |
} |
| 83 |
} |