| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.awt.Color; |
| 5 |
import java.io.IOException; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class LineStyle { |
| 15 |
|
| 16 |
public static final int CAP_ROUND = 0; |
| 17 |
public static final int CAP_NONE = 1; |
| 18 |
public static final int CAP_SQUARE = 2; |
| 19 |
|
| 20 |
public static final int JOIN_ROUND = 0; |
| 21 |
public static final int JOIN_BEVEL = 1; |
| 22 |
public static final int JOIN_MITER = 2; |
| 23 |
|
| 24 |
private int width, endWidth; |
| 25 |
private int startCapStyle, joinStyle, endCapStyle; |
| 26 |
private boolean hasFillFlag, noHScaleFlag, noVScaleFlag, pixelHintingFlag, noClose; |
| 27 |
private float miterLimitFactor; |
| 28 |
private FillStyle fillStyle; |
| 29 |
|
| 30 |
private Color color, endColor; |
| 31 |
|
| 32 |
public LineStyle(int width, Color color) { |
| 33 |
this.width = width; |
| 34 |
this.color = color; |
| 35 |
this.startCapStyle = CAP_ROUND; |
| 36 |
this.joinStyle = JOIN_ROUND; |
| 37 |
this.endCapStyle = CAP_ROUND; |
| 38 |
this.hasFillFlag = false; |
| 39 |
this.noHScaleFlag = false; |
| 40 |
this.noVScaleFlag = false; |
| 41 |
this.pixelHintingFlag = false; |
| 42 |
this.noClose = false; |
| 43 |
} |
| 44 |
|
| 45 |
public LineStyle(int width, int endWidth, Color color, Color endColor) { |
| 46 |
this(width, color); |
| 47 |
this.endWidth = endWidth; |
| 48 |
this.endColor = endColor; |
| 49 |
} |
| 50 |
|
| 51 |
public LineStyle(SWFInputStream input, boolean isMorphStyle, |
| 52 |
boolean hasAlpha, boolean hasStyles) throws IOException { |
| 53 |
|
| 54 |
width = input.readUnsignedShort(); |
| 55 |
if (isMorphStyle) { |
| 56 |
endWidth = input.readUnsignedShort(); |
| 57 |
} |
| 58 |
|
| 59 |
if (hasStyles) { |
| 60 |
startCapStyle = (int)input.readUBits(2); |
| 61 |
joinStyle = (int)input.readUBits(2); |
| 62 |
hasFillFlag = input.readBitFlag(); |
| 63 |
noHScaleFlag = input.readBitFlag(); |
| 64 |
noVScaleFlag = input.readBitFlag(); |
| 65 |
pixelHintingFlag = input.readBitFlag(); |
| 66 |
input.readUBits(5); |
| 67 |
noClose = input.readBitFlag(); |
| 68 |
endCapStyle = (int)input.readUBits(2); |
| 69 |
if (joinStyle == JOIN_MITER) { |
| 70 |
input.readFixed8(); |
| 71 |
} |
| 72 |
if (hasFillFlag) { |
| 73 |
fillStyle = new FillStyle(input, false, true); |
| 74 |
} else { |
| 75 |
color = input.readColor(true); |
| 76 |
} |
| 77 |
} else { |
| 78 |
color = input.readColor(hasAlpha); |
| 79 |
} |
| 80 |
if (isMorphStyle) { |
| 81 |
endColor = input.readColor(true); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { |
| 86 |
|
| 87 |
swf.writeUnsignedShort(width); |
| 88 |
if (isMorphStyle) { |
| 89 |
swf.writeUnsignedShort(endWidth); |
| 90 |
} |
| 91 |
|
| 92 |
if (hasStyles) { |
| 93 |
swf.writeUBits(startCapStyle, 2); |
| 94 |
swf.writeUBits(joinStyle, 2); |
| 95 |
swf.writeBitFlag(hasFillFlag); |
| 96 |
swf.writeBitFlag(noHScaleFlag); |
| 97 |
swf.writeBitFlag(noVScaleFlag); |
| 98 |
swf.writeBitFlag(pixelHintingFlag); |
| 99 |
swf.writeUBits(0, 5); |
| 100 |
swf.writeBitFlag(noClose); |
| 101 |
swf.writeUBits(endCapStyle, 2); |
| 102 |
if (joinStyle == JOIN_MITER) { |
| 103 |
swf.writeFixed8(miterLimitFactor); |
| 104 |
} |
| 105 |
if (hasFillFlag) { |
| 106 |
fillStyle.write(swf, isMorphStyle, true); |
| 107 |
} else { |
| 108 |
swf.writeColor(color, true); |
| 109 |
} |
| 110 |
} else { |
| 111 |
swf.writeColor(color, hasAlpha || isMorphStyle); |
| 112 |
if (isMorphStyle) { |
| 113 |
swf.writeColor(endColor, true); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
public String toString() { |
| 119 |
StringBuffer s = new StringBuffer("LineStyle " + width + ", " + color); |
| 120 |
if (endColor != null) |
| 121 |
s.append("; " + endWidth + ", " + endColor); |
| 122 |
return s.toString(); |
| 123 |
} |
| 124 |
} |