pom.xml0000644000175000017500000000245711344043673011434 0ustar user03user03 vectorgraphics org.freehep 2.1.1 4.0.0 org.freehep freehep-graphicsio-swf FreeHEP SWF (Flash) Driver FreeHEP SWF (Flash) Driver freehep-maven Maven FreeHEP http://java.freehep.org/maven2 org.freehep freehep-graphicsio 2.1.1 org.freehep freehep-graphicsio-tests 2.1.1 junit junit hep.aida aida test runtest.sh0000644000175000017500000000144511343262557012156 0ustar user03user03java -classpath target/classes:target/test-classes:/Users/duns/.m2/repository/org/freehep/freehep-graphicsio-tests/2.0-SNAPSHOT/freehep-graphicsio-tests-2.0-SNAPSHOT.jar:/Users/duns/.m2/repository/junit/junit/3.8.2/junit-3.8.2.jar:/Users/duns/.m2/repository/org/freehep/freehep-io/2.0/freehep-io-2.0.jar:/Users/duns/.m2/repository/org/freehep/freehep-graphics2d/2.0-SNAPSHOT/freehep-graphics2d-2.0-SNAPSHOT.jar:/Users/duns/.m2/repository/org/freehep/freehep-graphicsio/2.0-SNAPSHOT/freehep-graphicsio-2.0-SNAPSHOT.jar:/Users/duns/.m2/repository/org/freehep/freehep-util/2.0/freehep-util-2.0.jar:/Users/duns/.m2/repository/org/freehep/freehep-swing/2.0/freehep-swing-2.0.jar:/Users/duns/.m2/repository/org/freehep/freehep-export/2.0.1/freehep-export-2.0.1.jar org.freehep.graphicsio.swf.test.SWFTestSuite src/0000700000175000017500000000000011343262531010657 5ustar user03user03src/examples/0000700000175000017500000000000011343262532012476 5ustar user03user03src/examples/basic/0000700000175000017500000000000011343262532013557 5ustar user03user03src/examples/basic/readme.txt0000644000175000017500000000136011343262532015567 0ustar user03user03TestFiles ok [test2] (206 bytes) End ShowFrame DefineShape PlaceObject SetBackgroundColor PlaceObject2 ok [button] (562 bytes) DefineShape2 ButtonRecord ok [textbox] (776 bytes) DefineFont DefineText DefineFontInfo DefineEditText ok [test] (2 k) DefineBits JPEGTables ok [firstrun] (2 k) RemoveObject ok [sound3] (4 k) DefineSound StartSound SoundStreamHead SoundStreamHead2 ok [profero] (27 k) DefineButton DoAction Protect RemoveObject2 DefineButton2 ok [test3] (61 k) DefineBitsJPEG2 ok [sound] (148 k) DefineButtonSound ok [lossless] (1993 k) DefineBitsLossless DefineShape3 DefineText2 ok [animation] (10 k) ok [anim_flash] (11 k)src/examples/image/0000700000175000017500000000000011343262532013560 5ustar user03user03src/examples/extended/0000700000175000017500000000000011343262532014276 5ustar user03user03src/test/0000700000175000017500000000000011343262531011636 5ustar user03user03src/test/resources/0000700000175000017500000000000011343262531013650 5ustar user03user03src/test/resources/swf/0000700000175000017500000000000011343262531014447 5ustar user03user03src/test/java/0000700000175000017500000000000011343262531012557 5ustar user03user03src/test/java/org/0000700000175000017500000000000011343262531013346 5ustar user03user03src/test/java/org/freehep/0000700000175000017500000000000011343262531014764 5ustar user03user03src/test/java/org/freehep/graphicsio/0000700000175000017500000000000011343262531017114 5ustar user03user03src/test/java/org/freehep/graphicsio/swf/0000700000175000017500000000000011343262531017713 5ustar user03user03src/test/java/org/freehep/graphicsio/swf/test/0000700000175000017500000000000011343262531020672 5ustar user03user03src/test/java/org/freehep/graphicsio/swf/test/SWFAnalyze.java0000644000175000017500000000337211343262531023537 0ustar user03user03// Copyright 2003, FreeHEP. package org.freehep.graphicsio.swf.test; import hep.aida.IAnalysisFactory; import hep.aida.ITree; import hep.aida.ITuple; import hep.aida.ITupleFactory; import java.io.FileInputStream; import java.io.IOException; import org.freehep.graphicsio.swf.SWFHeader; import org.freehep.graphicsio.swf.SWFInputStream; import org.freehep.util.io.Tag; /** * @author Mark Donszelmann * @version $Id: SWFAnalyze.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFAnalyze { public static void main(String[] args) { try { IAnalysisFactory af = IAnalysisFactory.create(); ITree tree = af.createTreeFactory().create("SWFAnalyze.aida", "xml", false, true); ITupleFactory tf = af.createTupleFactory(tree); ITuple tuple = tf.create("SWF", "TagType", new String[] { "Tag", "TagSize" }, new Class[] { String.class, int.class }); FileInputStream fis = new FileInputStream(args[0]); SWFInputStream swf = new SWFInputStream(fis); long start = System.currentTimeMillis(); SWFHeader header = swf.readHeader(); System.out.println(header); Tag tag = swf.readTag(); while (tag != null) { // System.out.println(tag); tuple.fill(0, tag.getName()); System.out.print(" " + tag.getName()); tuple.addRow(); tag = swf.readTag(); // FIXME add tagSize } tree.commit(); System.out.println("Analyzed file in: " + (System.currentTimeMillis() - start) + " ms."); } catch (IOException e) { e.printStackTrace(); } } } src/test/java/org/freehep/graphicsio/swf/test/package.html0000644000175000017500000000006311343262531023164 0ustar user03user03 Tests for the SWF Reader and Writer. src/test/java/org/freehep/graphicsio/swf/test/SWFTestSuite.java0000644000175000017500000000101311343262531024053 0ustar user03user03// Copyright 2005, FreeHEP. package org.freehep.graphicsio.swf.test; import org.freehep.graphicsio.test.TestSuite; /** * @author Mark Donszelmann * @version $Id: SWFTestSuite.java 9198 2006-10-20 22:37:10Z duns $ */ public class SWFTestSuite extends TestSuite { public static TestSuite suite() { SWFTestSuite suite = new SWFTestSuite(); suite.addTests("SWF"); return suite; } public static void main(String[] args) { new junit.textui.TestRunner().doRun(suite()); } } src/test/java/org/freehep/graphicsio/swf/test/SWFDump.java0000644000175000017500000000243211343262531023035 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf.test; import java.io.FileInputStream; import java.io.IOException; import org.freehep.graphicsio.swf.SWFHeader; import org.freehep.graphicsio.swf.SWFInputStream; import org.freehep.util.io.Tag; /** * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFDump.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFDump { public static void main(String[] args) { try { if (args.length != 1) { System.err.println("Usage: SWFDump file.swf"); System.exit(1); } FileInputStream fis = new FileInputStream(args[0]); SWFInputStream swf = new SWFInputStream(fis); long start = System.currentTimeMillis(); SWFHeader header = swf.readHeader(); System.out.println(header); Tag tag = swf.readTag(); while (tag != null) { System.out.println(tag); tag = swf.readTag(); } // System.out.println(swf.getDictionary()); System.out.println("Parsed file in: " + (System.currentTimeMillis() - start) + " ms."); } catch (IOException e) { e.printStackTrace(); } } } src/main/0000700000175000017500000000000011343262531011603 5ustar user03user03src/main/resources/0000700000175000017500000000000011343262531013615 5ustar user03user03src/main/resources/META-INF/0000700000175000017500000000000011343262531014755 5ustar user03user03src/main/resources/META-INF/services/0000700000175000017500000000000011343262531016600 5ustar user03user03src/main/resources/META-INF/services/org.freehep.util.export.ExportFileType0000644000175000017500000000005511343262531026157 0ustar user03user03org.freehep.graphicsio.swf.SWFExportFileType src/main/java/0000700000175000017500000000000011343262531012524 5ustar user03user03src/main/java/overview.html0000644000175000017500000000012711343262531015272 0ustar user03user03 This is the API specification of the FreeHEP VectorGraphics package. src/main/java/org/0000700000175000017500000000000011343262531013313 5ustar user03user03src/main/java/org/freehep/0000700000175000017500000000000011343262531014731 5ustar user03user03src/main/java/org/freehep/graphicsio/0000700000175000017500000000000011343262531017061 5ustar user03user03src/main/java/org/freehep/graphicsio/swf/0000700000175000017500000000000011343262531017660 5ustar user03user03src/main/java/org/freehep/graphicsio/swf/RemoveObject.java0000644000175000017500000000212411343262531023120 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * RemoveObject TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: RemoveObject.java 8584 2006-08-10 23:06:37Z duns $ */ public class RemoveObject extends ControlTag { private int depth; private int character; public RemoveObject(int depth, int id) { this(); this.depth = depth; character = id; } public RemoveObject() { super(5, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { RemoveObject tag = new RemoveObject(); tag.character = swf.readUnsignedShort(); tag.depth = swf.readUnsignedShort(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUnsignedShort(depth); } public String toString() { return super.toString() + "\n" + " depth: " + depth + "\n" + " character: " + character; } } src/main/java/org/freehep/graphicsio/swf/EnableDebugger.java0000644000175000017500000000220311343262531023365 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * EnableDebugger TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: EnableDebugger.java 8584 2006-08-10 23:06:37Z duns $ */ public class EnableDebugger extends ControlTag { private String password; public EnableDebugger(String password) { this(); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] b = md5.digest(password.getBytes()); this.password = new String(b); } catch (NoSuchAlgorithmException nsae) { this.password = password; } } public EnableDebugger() { super(58, 5); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { EnableDebugger tag = new EnableDebugger(); tag.password = swf.readString(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeString(password); } } src/main/java/org/freehep/graphicsio/swf/SWFAction.java0000644000175000017500000010072011343262531022332 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.EOFException; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.Action; import org.freehep.util.io.TaggedInputStream; import org.freehep.util.io.TaggedOutputStream; /** * SWF Abstract Action Class. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFAction.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class SWFAction extends Action { private int version; protected SWFAction(int code, int version) { super(code); this.version = version; } public int getVersion() { return version; } public Action read(int actionCode, TaggedInputStream input, int length) throws IOException { return read(actionCode, (SWFInputStream) input, length); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { return this; } public void write(int actionCode, TaggedOutputStream input) throws IOException { write(actionCode, (SWFOutputStream) input); } public void write(int actionCode, SWFOutputStream swf) throws IOException { // empty } /** * Goto Frame Action. */ public static class GotoFrame extends SWFAction { private int frame; public GotoFrame(int frame) { this(); this.frame = frame; } public GotoFrame() { super(0x81, 3); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { GotoFrame action = new GotoFrame(); action.frame = swf.readUnsignedShort(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(frame); } public String toString() { return super.toString() + ", frame " + frame; } } /** * Get URL Action. */ public static class GetURL extends SWFAction { private String url; private String window; public GetURL(String url, String window) { this(); this.url = url; this.window = window; } public GetURL() { super(0x83, 3); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { GetURL action = new GetURL(); action.url = swf.readString(); action.window = swf.readString(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeString(url); swf.writeString(window); } public String toString() { return super.toString() + ", URL " + url + ", window " + window; } } /** * Next Frame Action. */ public static class NextFrame extends SWFAction { public NextFrame() { super(0x04, 3); } } /** * Previous Frame Action. */ public static class PreviousFrame extends SWFAction { public PreviousFrame() { super(0x05, 3); } } /** * Play Action. */ public static class Play extends SWFAction { public Play() { super(0x06, 3); } } /** * Stop Action. */ public static class Stop extends SWFAction { public Stop() { super(0x07, 3); } } /** * Toggle Quality Action. */ public static class ToggleQuality extends SWFAction { public ToggleQuality() { super(0x08, 3); } } /** * Stop Sounds Action. */ public static class StopSounds extends SWFAction { public StopSounds() { super(0x09, 3); } } /** * Wait For Frame Action. */ public static class WaitForFrame extends SWFAction { private int frame; private int skip; public WaitForFrame(int frame, int skip) { this(); this.frame = frame; this.skip = skip; } public WaitForFrame() { super(0x8a, 3); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { WaitForFrame action = new WaitForFrame(); action.frame = swf.readUnsignedShort(); action.skip = swf.readUnsignedByte(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(frame); swf.writeUnsignedByte(skip); } public String toString() { return super.toString() + ", frame " + frame + ", skip " + skip; } } /** * Set Target Action. */ public static class SetTarget extends SWFAction { private String target; public SetTarget(String target) { this(); this.target = target; } public SetTarget() { super(0x8b, 3); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { SetTarget action = new SetTarget(); action.target = swf.readString(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeString(target); } public String toString() { return super.toString() + ", target " + target; } } /** * Goto Label Action. */ public static class GotoLabel extends SWFAction { private String label; public GotoLabel(String label) { this(); this.label = label; } public GotoLabel() { super(0x8c, 3); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { GotoLabel action = new GotoLabel(); action.label = swf.readString(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeString(label); } public String toString() { return super.toString() + ", label " + label; } } // Flash 4 Actions Set /** * Add Action. */ public static class Add extends SWFAction { public Add() { super(0x0a, 4); } } /** * Subtract Action. */ public static class Subtract extends SWFAction { public Subtract() { super(0x0b, 4); } } /** * Multiply Action. */ public static class Multiply extends SWFAction { public Multiply() { super(0x0c, 4); } } /** * Divide Action. */ public static class Divide extends SWFAction { public Divide() { super(0x0d, 4); } } /** * WaitForFrame2 Action. */ public static class WaitForFrame2 extends SWFAction { private int skip; public WaitForFrame2(int skip) { this(); this.skip = skip; } public WaitForFrame2() { super(0x8D, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { WaitForFrame2 action = new WaitForFrame2(); action.skip = swf.readUnsignedByte(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeUnsignedByte(skip); } public String toString() { return super.toString() + ", skipCount:" + skip; } } /** * Equals Action. */ public static class Equals extends SWFAction { public Equals() { super(0x0e, 4); } } /** * Less Action. */ public static class Less extends SWFAction { public Less() { super(0x0f, 4); } } /** * And Action. */ public static class And extends SWFAction { public And() { super(0x10, 4); } } /** * Or Action. */ public static class Or extends SWFAction { public Or() { super(0x11, 4); } } /** * Not Action. */ public static class Not extends SWFAction { public Not() { super(0x12, 4); } } /** * StringEquals Action. */ public static class StringEquals extends SWFAction { public StringEquals() { super(0x13, 4); } } /** * StringLength Action. */ public static class StringLength extends SWFAction { public StringLength() { super(0x14, 4); } } /** * StringExtract Action. */ public static class StringExtract extends SWFAction { public StringExtract() { super(0x15, 4); } } /** * Push Action. */ public static class Push extends SWFAction { public static final int STRING = 0; public static final int FLOAT = 1; public static final int NULL = 2; public static final int UNDEFINED = 3; public static final int REGISTER = 4; public static final int BOOLEAN = 5; public static final int DOUBLE = 6; public static final int INTEGER = 7; public static final int LOOKUP = 8; public static final int LOOKUP2 = 9; private Vector values; public static class Value { private byte type; private Object value; private byte[] data; public Value(String s) { type = STRING; value = s; } public Value(float f) { type = FLOAT; value = new Float(f); } public Value(Object x) { type = NULL; value = null; } public Value(byte r) { type = REGISTER; value = new Byte(r); } public Value(boolean b) { type = BOOLEAN; value = new Boolean(b); } public Value(double d) { type = DOUBLE; value = new Double(d); } public Value(int i) { type = INTEGER; value = new Integer(i); } public Value(short index) { type = LOOKUP; value = new Short(index); } public Value(byte type, byte[] data) { this.type = type; this.data = data; } public static Value read(SWFInputStream swf) throws IOException { byte type = swf.readByte(); switch (type) { case STRING: return new Value(swf.readString()); case FLOAT: return new Value(swf.readFloat()); case NULL: return new Value(null); case REGISTER: return new Value((byte) swf.readUnsignedByte()); case BOOLEAN: return new Value((swf.readByte() != 0) ? true : false); case DOUBLE: return new Value(swf.readDouble()); case INTEGER: return new Value(swf.readInt()); case LOOKUP: return new Value((short) swf.readUnsignedByte()); case LOOKUP2: return new Value((byte) LOOKUP2, swf.readByte(2)); default: return new Value(type, swf.readByte((int) swf.getLength())); } } public void write(SWFOutputStream swf) throws IOException { swf.writeByte(type); switch (type) { case STRING: swf.writeString((String) value); break; case FLOAT: swf.writeFloat(((Float) value).floatValue()); break; case NULL: break; case UNDEFINED: break; case REGISTER: swf.writeUnsignedByte(((Byte) value).byteValue()); break; case BOOLEAN: swf.writeBoolean(((Boolean) value).booleanValue()); break; case DOUBLE: swf.writeDouble(((Double) value).doubleValue()); break; case INTEGER: swf.writeInt(((Integer) value).intValue()); break; case LOOKUP: swf.writeUnsignedByte(((Short) value).shortValue()); break; case LOOKUP2: swf.writeShort(((Short) value).shortValue()); break; default: swf.writeByte(data); break; } } public String toString() { StringBuffer s = new StringBuffer("PushValue "); if ((type < 0) || (type > 9)) { s.append("Unknown Data Type " + type + " with length " + data.length); } else { s.append(value); } return s.toString(); } } public Push() { super(0x96, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { Push action = new Push(); action.values = new Vector(); try { while (true) { action.values.add(Value.read(swf)); } } catch (EOFException e) { } return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { for (int i = 0; i < values.size(); i++) { ((Value) values.get(i)).write(swf); } } public String toString() { StringBuffer s = new StringBuffer(super.toString()); s.append("\n"); for (int i = 0; i < values.size(); i++) { s.append(" "); s.append(values.get(i)); s.append("\n"); } return s.toString(); } } /** * Pop Action. */ public static class Pop extends SWFAction { public Pop() { super(0x17, 4); } } /** * ToInteger Action. */ public static class ToInteger extends SWFAction { public ToInteger() { super(0x18, 4); } } /** * Jump Action. */ public static class Jump extends SWFAction { private short offset; public Jump(short offset) { this(); this.offset = offset; } public Jump() { super(0x99, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { Jump action = new Jump(); action.offset = swf.readShort(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeShort(offset); } public String toString() { return super.toString() + ", " + offset; } } /** * GetURL2 Action. */ public static class GetURL2 extends SWFAction { private byte method; public static final int NONE = 0; public static final int GET = 1; public static final int POST = 2; public GetURL2(byte method) { this(); this.method = method; } public GetURL2() { super(0x9A, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { GetURL2 action = new GetURL2(); action.method = swf.readByte(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeByte(method); } public String toString() { return super.toString() + ", " + method; } } /** * GetVariable Action. */ public static class GetVariable extends SWFAction { public GetVariable() { super(0x1c, 4); } } /** * SetVariable Action. */ public static class SetVariable extends SWFAction { public SetVariable() { super(0x1d, 4); } } /** * If Action. */ public static class If extends SWFAction { private short offset; public If(short offset) { this(); this.offset = offset; } public If() { super(0x9d, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { If action = new If(); action.offset = swf.readShort(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeShort(offset); } public String toString() { return super.toString() + ", " + offset; } } /** * Call Action. */ public static class Call extends SWFAction { public Call() { super(0x9e, 4); } } /** * GotoFrame2 Action. */ public static class GotoFrame2 extends SWFAction { private byte play; public GotoFrame2(byte play) { this(); this.play = play; } public GotoFrame2() { super(0x9f, 4); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { GotoFrame2 action = new GotoFrame2(); action.play = swf.readByte(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeByte(play); } public String toString() { return super.toString() + ", " + play; } } /** * SetTarget2 Action. */ public static class SetTarget2 extends SWFAction { public SetTarget2() { super(0x20, 4); } } /** * StringAdd Action. */ public static class StringAdd extends SWFAction { public StringAdd() { super(0x21, 4); } } /** * GetProperty Action. */ public static class GetProperty extends SWFAction { public GetProperty() { super(0x22, 4); } } /** * SetProperty Action. */ public static class SetProperty extends SWFAction { public SetProperty() { super(0x23, 4); } } /** * CloneSprite Action. */ public static class CloneSprite extends SWFAction { public CloneSprite() { super(0x24, 4); } } /** * RemoveSprite Action. */ public static class RemoveSprite extends SWFAction { public RemoveSprite() { super(0x25, 4); } } /** * Trace Action. */ public static class Trace extends SWFAction { public Trace() { super(0x26, 4); } } /** * StartDrag Action. */ public static class StartDrag extends SWFAction { public StartDrag() { super(0x27, 4); } } /** * EndDrag Action. */ public static class EndDrag extends SWFAction { public EndDrag() { super(0x28, 4); } } /** * StringLess Action. */ public static class StringLess extends SWFAction { public StringLess() { super(0x29, 4); } } /** * RandomNumber Action. */ public static class RandomNumber extends SWFAction { public RandomNumber() { super(0x30, 4); } } /** * MBStringLength Action. */ public static class MBStringLength extends SWFAction { public MBStringLength() { super(0x31, 4); } } /** * CharToAscii Action. */ public static class CharToAscii extends SWFAction { public CharToAscii() { super(0x32, 4); } } /** * AsciiToChar Action. */ public static class AsciiToChar extends SWFAction { public AsciiToChar() { super(0x33, 4); } } /** * GetTime Action. */ public static class GetTime extends SWFAction { public GetTime() { super(0x34, 4); } } /** * MBStringExtract Action. */ public static class MBStringExtract extends SWFAction { public MBStringExtract() { super(0x35, 4); } } /** * MBCharToAscii Action. */ public static class MBCharToAscii extends SWFAction { public MBCharToAscii() { super(0x36, 4); } } /** * MBAsciiToChar Action. */ public static class MBAsciiToChar extends SWFAction { public MBAsciiToChar() { super(0x37, 4); } } // Flash 5 actions. /** * StoreRegister Action. */ public static class StoreRegister extends SWFAction { private byte number; public StoreRegister(byte number) { this(); this.number = number; } public StoreRegister() { super(0x87, 5); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { StoreRegister action = new StoreRegister(); action.number = swf.readByte(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeByte(number); } public String toString() { return super.toString() + ", " + number; } } /** * ConstantPool Action. */ public static class ConstantPool extends SWFAction { private String[] pool; public ConstantPool(String[] pool) { this(); this.pool = pool; } public ConstantPool() { super(0x88, 5); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { ConstantPool action = new ConstantPool(); action.pool = new String[swf.readUnsignedShort()]; for (int i = 0; i < action.pool.length; i++) { action.pool[i] = swf.readString(); } return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(pool.length); for (int i = 0; i < pool.length; i++) { swf.writeString(pool[i]); } } public String toString() { StringBuffer s = new StringBuffer(super.toString()); s.append("["); for (int i = 0; i < pool.length; i++) { if (i != 0) s.append(", "); s.append(pool[i]); } s.append("]"); return s.toString(); } } /** * With Action. */ public static class With extends SWFAction { private int size; private String block; public With(int size, String block) { this(); this.size = size; this.block = block; } public With() { super(0x94, 5); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { With action = new With(); action.size = swf.readUnsignedShort(); action.block = swf.readString(); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(size); swf.writeString(block); } public String toString() { return super.toString() + ", " + size + ", " + block; } } /** * DefineFunction Action. */ public static class DefineFunction extends SWFAction { private String name; private String[] params; private byte[] code; public DefineFunction(String name, String[] params, byte[] code) { this(); this.name = name; this.params = params; this.code = code; } public DefineFunction() { super(0x9b, 5); } public SWFAction read(int actionCode, SWFInputStream swf, int length) throws IOException { DefineFunction action = new DefineFunction(); action.name = swf.readString(); int n = swf.readUnsignedShort(); for (int i = 0; i < n; i++) { action.params[i] = swf.readString(); } int cs = swf.readUnsignedShort(); action.code = swf.readByte(cs); return action; } public void write(int actionCode, SWFOutputStream swf) throws IOException { swf.writeString(name); swf.writeUnsignedShort(params.length); for (int i = 0; i < params.length; i++) { swf.writeString(params[i]); } swf.writeUnsignedShort(code.length); swf.writeByte(code); } public String toString() { return super.toString() + ", " + name + ", " + (new String(code)); } } /** * Delete Action. */ public static class Delete extends SWFAction { public Delete() { super(0x3a, 5); } } /** * Delete2 Action. */ public static class Delete2 extends SWFAction { public Delete2() { super(0x3b, 5); } } /** * DefineLocal Action. */ public static class DefineLocal extends SWFAction { public DefineLocal() { super(0x3c, 5); } } /** * CallFunction Action. */ public static class CallFunction extends SWFAction { public CallFunction() { super(0x3d, 5); } } /** * Return Action. */ public static class Return extends SWFAction { public Return() { super(0x3e, 5); } } /** * Modulo Action. */ public static class Modulo extends SWFAction { public Modulo() { super(0x3f, 5); } } /** * NewObject Action. */ public static class NewObject extends SWFAction { public NewObject() { super(0x40, 5); } } /** * DefineLocal2 Action. */ public static class DefineLocal2 extends SWFAction { public DefineLocal2() { super(0x41, 5); } } /** * InitArray Action. */ public static class InitArray extends SWFAction { public InitArray() { super(0x42, 5); } } /** * InitObject Action. */ public static class InitObject extends SWFAction { public InitObject() { super(0x43, 5); } } /** * TypeOf Action. */ public static class TypeOf extends SWFAction { public TypeOf() { super(0x44, 5); } } /** * TargetPath Action. */ public static class TargetPath extends SWFAction { public TargetPath() { super(0x45, 5); } } /** * Enumerate Action. */ public static class Enumerate extends SWFAction { public Enumerate() { super(0x46, 5); } } /** * Add2 Action. */ public static class Add2 extends SWFAction { public Add2() { super(0x47, 5); } } /** * Less2 Action. */ public static class Less2 extends SWFAction { public Less2() { super(0x48, 5); } } /** * Equals2 Action. */ public static class Equals2 extends SWFAction { public Equals2() { super(0x49, 5); } } /** * ToNumber Action. */ public static class ToNumber extends SWFAction { public ToNumber() { super(0x4a, 5); } } /** * ToString Action. */ public static class ToString extends SWFAction { public ToString() { super(0x4b, 5); } } /** * PushDuplicate Action. */ public static class PushDuplicate extends SWFAction { public PushDuplicate() { super(0x4c, 5); } } /** * StackSwap Action. */ public static class StackSwap extends SWFAction { public StackSwap() { super(0x4d, 5); } } /** * GetMember Action. */ public static class GetMember extends SWFAction { public GetMember() { super(0x4e, 5); } } /** * SetMember Action. */ public static class SetMember extends SWFAction { public SetMember() { super(0x4f, 5); } } /** * Increment Action. */ public static class Increment extends SWFAction { public Increment() { super(0x50, 5); } } /** * Decrement Action. */ public static class Decrement extends SWFAction { public Decrement() { super(0x51, 5); } } /** * CallMethod Action. */ public static class CallMethod extends SWFAction { public CallMethod() { super(0x52, 5); } } /** * NewMethod Action. */ public static class NewMethod extends SWFAction { public NewMethod() { super(0x53, 5); } } /** * BitAnd Action. */ public static class BitAnd extends SWFAction { public BitAnd() { super(0x60, 5); } } /** * BitOr Action. */ public static class BitOr extends SWFAction { public BitOr() { super(0x61, 5); } } /** * BitXor Action. */ public static class BitXor extends SWFAction { public BitXor() { super(0x62, 5); } } /** * BitLShift Action. */ public static class BitLShift extends SWFAction { public BitLShift() { super(0x63, 5); } } /** * BitRShift Action. */ public static class BitRShift extends SWFAction { public BitRShift() { super(0x64, 5); } } /** * BitURShift Action. */ public static class BitURShift extends SWFAction { public BitURShift() { super(0x65, 5); } } /** * InstanceOf Action. */ public static class InstanceOf extends SWFAction { public InstanceOf() { super(0x54, 6); } } /** * Enumerate2 Action. */ public static class Enumerate2 extends SWFAction { public Enumerate2() { super(0x55, 6); } } /** * StrictEquals Action. */ public static class StrictEquals extends SWFAction { public StrictEquals() { super(0x66, 6); } } /** * Greater Action. */ public static class Greater extends SWFAction { public Greater() { super(0x67, 6); } } /** * StringGreater Action. */ public static class StringGreater extends SWFAction { public StringGreater() { super(0x68, 6); } } } src/main/java/org/freehep/graphicsio/swf/DefineShape2.java0000644000175000017500000000200311343262531022765 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineShape2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineShape2.java 9976 2006-11-27 18:25:46Z duns $ */ public class DefineShape2 extends DefineShape { public DefineShape2(int id, Rectangle2D bounds, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape shape) { this(); character = id; this.bounds = bounds; this.fillStyles = fillStyles; this.lineStyles = lineStyles; this.shape = shape; } public DefineShape2() { super(22, 2); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineShape2 tag = new DefineShape2(); tag.read(tagID, swf, false); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf, true); } } src/main/java/org/freehep/graphicsio/swf/DefineMorphShape.java0000644000175000017500000000544311343262531023724 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineMorphShape TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineMorphShape.java 9979 2006-11-27 22:51:07Z duns $ */ public class DefineMorphShape extends DefinitionTag { private int character; private Rectangle2D startBounds, endBounds; protected FillStyleArray fillStyles; protected LineStyleArray lineStyles; protected SWFShape startEdges, endEdges; public DefineMorphShape(int id, Rectangle2D startBounds, Rectangle2D endBounds, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape startEdges, SWFShape endEdges) { this(); character = id; this.startBounds = startBounds; this.endBounds = endBounds; this.fillStyles = fillStyles; this.lineStyles = lineStyles; this.startEdges = startEdges; this.endEdges = endEdges; } public DefineMorphShape() { super(46, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineMorphShape tag = new DefineMorphShape(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.startBounds = swf.readRect(); tag.endBounds = swf.readRect(); // ignored /* long offset = */ swf.readUnsignedInt(); fillStyles = new FillStyleArray(swf, true, true); lineStyles = new LineStyleArray(swf, true, true, false); startEdges = new SWFShape(swf, fillStyles, lineStyles, true, true, false); endEdges = new SWFShape(swf, fillStyles, lineStyles, true, true, false); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeRect(startBounds); swf.writeRect(endBounds); swf.pushBuffer(); fillStyles.write(swf, true, true); lineStyles.write(swf, true, true, false); startEdges.write(swf, true, true, false); int offset = swf.popBuffer(); swf.writeUnsignedInt(offset); swf.append(); endEdges.write(swf, true, true, false); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" startBounds: " + startBounds + "\n"); s.append(" endBounds: " + endBounds + "\n"); s.append(fillStyles.toString()); s.append(lineStyles.toString()); s.append(" startEdges: " + startEdges + "\n"); s.append(" endEdges: " + endEdges + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/JPEGTables.java0000644000175000017500000000151611343262531022420 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * JPEGTables TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: JPEGTables.java 8584 2006-08-10 23:06:37Z duns $ */ public class JPEGTables extends DefinitionTag { private byte[] table; public JPEGTables() { super(8, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { JPEGTables tag = new JPEGTables(); tag.table = swf.readByte(len); swf.setJPEGTable(tag.table); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeByte(table); } public String toString() { return super.toString() + "\n" + " length: " + table.length + "\n"; } } src/main/java/org/freehep/graphicsio/swf/DefineButton2.java0000644000175000017500000000616111343262531023211 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; /** * DefineButton2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineButton2.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineButton2 extends DefinitionTag { private int character; private boolean trackAsMenu; private Vector buttons; private Vector conditions; public DefineButton2(int id, boolean trackAsMenu, Vector buttons, Vector conditions) { this(); character = id; this.trackAsMenu = trackAsMenu; this.buttons = buttons; this.conditions = conditions; } public DefineButton2() { super(34, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { System.out.println(len); DefineButton2 tag = new DefineButton2(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); /* int reserved = (int) */ swf.readUBits(7); trackAsMenu = swf.readBitFlag(); // ignored int offset = swf.readUnsignedShort(); tag.buttons = new Vector(); ButtonRecord record = new ButtonRecord(swf, true); while (!record.isEndRecord()) { tag.buttons.add(record); record = new ButtonRecord(swf, true); } tag.conditions = new Vector(); if (offset != 0) { int actionOffset; do { actionOffset = swf.readUnsignedShort(); System.err.println("AO " + actionOffset); tag.conditions.add(new ButtonCondAction(swf)); } while (actionOffset != 0); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUBits(0, 7); swf.writeBitFlag(trackAsMenu); swf.pushBuffer(); for (int i = 0; i < buttons.size(); i++) { ButtonRecord b = (ButtonRecord) buttons.get(i); b.write(swf); } swf.writeUnsignedByte(0); int offset = swf.popBuffer(); swf.writeUnsignedShort(offset); swf.append(); for (int i = 0; i < conditions.size(); i++) { swf.pushBuffer(); ButtonCondAction c = (ButtonCondAction) conditions.get(i); c.write(swf); int actionOffset = swf.popBuffer(); swf.writeUnsignedShort((i == conditions.size() - 1) ? 0 : actionOffset); swf.append(); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" menu: " + trackAsMenu + "\n"); for (int i = 0; i < buttons.size(); i++) { s.append(" " + buttons.get(i) + "\n"); } for (int i = 0; i < conditions.size(); i++) { s.append(" " + conditions.get(i) + "\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFGraphics2D.java0000644000175000017500000005474611343262531023063 0ustar user03user03// Copyright 2000-2006 FreeHEP package org.freehep.graphicsio.swf; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.TexturePaint; import java.awt.font.GlyphVector; import java.awt.geom.AffineTransform; import java.awt.geom.Area; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import java.util.Vector; import org.freehep.graphics2d.PrintColor; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphics2d.font.FontEncoder; import org.freehep.graphicsio.AbstractVectorGraphicsIO; import org.freehep.graphicsio.ImageConstants; import org.freehep.graphicsio.PageConstants; import org.freehep.util.UserProperties; import org.freehep.util.Value; /** * SWF Graphics 2D driver. * * @author Mark Donszelmann * @version $Id: SWFGraphics2D.java 9981 2006-11-28 00:22:04Z duns $ */ public class SWFGraphics2D extends AbstractVectorGraphicsIO implements SWFConstants { private static final int SWF_VERSION = 8; // for cyclic gradients private static final String rootKey = SWFGraphics2D.class.getName(); public static final String TRANSPARENT = rootKey + "." + PageConstants.TRANSPARENT; public static final String BACKGROUND = rootKey + "." + PageConstants.BACKGROUND; public static final String BACKGROUND_COLOR = rootKey + "." + PageConstants.BACKGROUND_COLOR; public static final String WRITE_IMAGES_AS = rootKey + "." + ImageConstants.WRITE_IMAGES_AS; private static final UserProperties defaultProperties = new UserProperties(); static { defaultProperties.setProperty(TRANSPARENT, true); defaultProperties.setProperty(BACKGROUND, false); defaultProperties.setProperty(BACKGROUND_COLOR, Color.GRAY); defaultProperties.setProperty(WRITE_IMAGES_AS, ImageConstants.SMALLEST); // Seems not to work yet... defaultProperties.setProperty(CLIP, false); defaultProperties.setProperty(TEXT_AS_SHAPES, true); } public static Properties getDefaultProperties() { return defaultProperties; } public static void setDefaultProperties(Properties newProperties) { defaultProperties.setProperties(newProperties); } public final static String version = "$Revision: 9981 $"; private OutputStream ros; private SWFOutputStream os; private Value id; private Value depth; private static final float frameRate = 20.0f; private boolean compress = true; private LineStyleArray lineStyles; private FillStyleArray fillStyles; // keeps the color for text, which cannot be a paint private Color textColor; // keeps the last clip which has not been written yet, its ID and depth private Shape unwrittenClip = null; private AffineTransform clipTransform = null; private int clipID, clipDepthID, showClipID, showClipDepthID; // for rendering shapes boolean fillStroke; // for debugging private static final boolean showBounds = false; /* * ================================================================================ * Table of Contents: ------------------ 1. Constructors & Factory Methods * 2. Document Settings 3. Header, Trailer, Multipage & Comments 3.1 Header & * Trailer 3.2 MultipageDocument methods 4. Create & Dispose 5. Drawing * Methods 5.1. shapes (draw/fill) 5.1.1. lines, rectangles, round * rectangles 5.1.2. polylines, polygons 5.1.3. ovals, arcs 5.1.4. shapes * 5.2. Images 5.3. Strings 6. Transformations 7. Clipping 8. Graphics State / * Settings 8.1. stroke/linewidth 8.2. paint/color 8.3. font 8.4. rendering * hints 9. Auxiliary 10. Private/Utility Methos * ================================================================================ */ /* * ================================================================================ * 1. Constructors & Factory Methods * ================================================================================ */ public SWFGraphics2D(File file, Dimension size) throws FileNotFoundException { this(new FileOutputStream(file), size); } public SWFGraphics2D(File file, Component component) throws FileNotFoundException { this(new FileOutputStream(file), component); } public SWFGraphics2D(OutputStream os, Dimension size) { super(size, true); init(os); } public SWFGraphics2D(OutputStream os, Component component) { super(component, true); init(os); } private void init(OutputStream os) { initProperties(getDefaultProperties()); ros = os; id = new Value().set(1); depth = new Value().set(1); textColor = getColor(); fillStroke = true; } protected SWFGraphics2D(SWFGraphics2D graphics, boolean doRestoreOnDispose) { super(graphics, doRestoreOnDispose); // Create a graphics context from a given graphics context. // This constructor is used by the system to clone a given graphics // context. // doRestoreOnDispose is used to call writeGraphicsRestore(), // when the graphics context is being disposed off. os = graphics.os; id = graphics.id; depth = graphics.depth; lineStyles = new LineStyleArray(); lineStyles.add(graphics.lineStyles.get(0)); if (showBounds || isProperty(CLIP)) { lineStyles.add(graphics.lineStyles.get(1)); lineStyles.add(graphics.lineStyles.get(2)); } fillStyles = new FillStyleArray(); fillStyles.add(graphics.fillStyles.get(0)); textColor = graphics.textColor; fillStroke = graphics.fillStroke; } /* * ================================================================================ | * 2. Document Settings * ================================================================================ */ /* * ================================================================================ | * 3. Header, Trailer, Multipage & Comments * ================================================================================ */ /* 3.1 Header & Trailer */ public void writeHeader() throws IOException { os = new SWFOutputStream(new BufferedOutputStream(ros), SWF_VERSION, getSize(), frameRate, compress); String description = getCreator() + ":" + getClass().getName(); if (!isDeviceIndependent()) { description += " " + version.substring(1, version.length() - 1); } // FIXME no way to write out a comment... } public void writeBackground() throws IOException { if (isProperty(TRANSPARENT)) { setBackground(null); } else if (isProperty(BACKGROUND)) { setBackground(getPropertyColor(BACKGROUND_COLOR)); clearRect(0.0, 0.0, getSize().width, getSize().height); } else { setBackground(getComponent() != null ? getComponent() .getBackground() : Color.WHITE); clearRect(0.0, 0.0, getSize().width, getSize().height); } } public void writeTrailer() throws IOException { os.writeTag(new ShowFrame()); os.writeTag(new End()); } public void closeStream() throws IOException { os.close(); } /* 3.2 MultipageDocument methods */ /* * ================================================================================ * 4. Create & Dispose * ================================================================================ */ public Graphics create() { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. return new SWFGraphics2D(this, true); } public Graphics create(double x, double y, double width, double height) { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. VectorGraphics graphics = new SWFGraphics2D(this, true); graphics.translate(x, y); graphics.clipRect(0, 0, width, height); return graphics; } protected void writeGraphicsSave() throws IOException { } protected void writeGraphicsRestore() throws IOException { popStreamAndWriteClip(); } /* * ================================================================================ | * 5. Drawing Methods * ================================================================================ */ /* 5.1.4. shapes */ public void draw(Shape shape) { Shape strokedShape = getStroke().createStrokedShape(shape); if (fillStroke) { // do this for dashed lines and non-round linejoins and linecaps fill(new Area(strokedShape)); return; } try { Rectangle2D bounds = strokedShape.getBounds2D(); SWFShape swfShape = createShape(shape, 1, 0, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfShape)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); if (showBounds) { SWFShape swfBounds = createShape(bounds, 2, 0, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfBounds)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); } } catch (IOException e) { handleException(e); } } public void fill(Shape shape) { try { Rectangle2D bounds = new BasicStroke().createStrokedShape(shape) .getBounds2D(); SWFShape swfShape = createShape(shape, 0, 1, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfShape)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); if (showBounds) { SWFShape swfBounds = createShape(bounds, 2, 0, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfBounds)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); } boolean eo = SWFPathConstructor.isEvenOdd(shape); if (!eo) { writeWarning(getClass() + ": cannot fill using non-zero winding rule, used even-odd instead."); } } catch (IOException e) { handleException(e); } } public void fillAndDraw(Shape shape, Color fillColor) { try { setFillColor(fillColor); fill(shape); setFillColor(getColor()); draw(shape); } catch (IOException e) { handleException(e); } } /* 5.2. Images */ public void copyArea(int x, int y, int width, int height, int dx, int dy) { writeWarning(getClass() + ": copyArea(int, int, int, int, int, int) not implemented."); // Mostly unimplemented. } protected void writeImage(RenderedImage image, AffineTransform xform, Color bkg) throws IOException { // define image int imageID = id.getInt(); os.writeTag(getImageTag(imageID, image, bkg)); id.set(id.getInt() + 1); // define shape for image Shape shape = xform.createTransformedShape(new Rectangle(0, 0, image .getWidth(), image.getHeight())); AffineTransform imageTransform = new AffineTransform(TWIPS, 0, 0, TWIPS, 0, 0); xform.concatenate(imageTransform); // create fill from shape SWFShape imageShape = createShape(shape, 0, 0, 1); FillStyleArray imageFill = new FillStyleArray(); imageFill.add(new FillStyle(imageID, false, xform)); LineStyleArray imageLine = new LineStyleArray(); Rectangle bounds = shape.getBounds(); os.writeTag(new DefineShape4(id.getInt(), bounds, imageFill, imageLine, imageShape)); // place image os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); if (showBounds) { SWFShape swfBounds = createShape(bounds, 2, 0, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfBounds)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); } } private final static Properties replaceFonts = new Properties(); static { replaceFonts.setProperty("Symbol", "Serif"); replaceFonts.setProperty("ZapfDingbats", "Serif"); } /* 5.3. Strings */ protected void writeString(String string, double x, double y) throws IOException { // for special fonts (Symbol, ZapfDingbats) we choose a standard font // and // encode using unicode. String fontName = getFont().getName(); string = FontEncoder.getEncodedString(string, fontName); fontName = replaceFonts.getProperty(fontName, null); Font font = (fontName == null) ? getFont() : new Font(fontName, getFont().getStyle(), getFont().getSize()); Font font1024 = font.deriveFont((float) (1024.0 / TWIPS)); GlyphVector glyphs = font1024.createGlyphVector(getFontRenderContext(), string); Rectangle2D bounds = font.createGlyphVector(getFontRenderContext(), string).getVisualBounds(); bounds.setRect(bounds.getX() + x, bounds.getY() + y, bounds.getWidth(), bounds.getHeight()); // define the Glyphs int fontID = id.getInt(); DefineFont swfFont = new DefineFont(fontID); id.set(id.getInt() + 1); // define Text Vector text = new Vector(); DefineText2.RecordType1 record1 = new DefineText2.RecordType1(fontID, textColor, (int) (x * TWIPS), (int) (y * TWIPS), (int) (font .getSize2D() * TWIPS)); DefineText2.RecordType0 record0 = new DefineText2.RecordType0(); text.add(record1); text.add(record0); int textID = id.getInt(); DefineText2 swfText = new DefineText2(textID, bounds, new AffineTransform(), text); id.set(id.getInt() + 1); // hook font and text for (int i = 0; i < glyphs.getNumGlyphs(); i++) { // add filled shapes to font swfFont.add(createShape(glyphs.getGlyphOutline(i), -1, 1, -1)); // add glyphs to text // float advance = glyphs.getGlyphMetrics(i).getAdvance(); record0.add(new DefineText2.GlyphEntry(i, 0)); // (int)(advance*TWIPS))); } // write font and text os.writeTag(swfFont); os.writeTag(swfText); // place String os.writeTag(new PlaceObject2(textID, depth.getInt(), getTransform())); depth.set(depth.getInt() + 1); if (showBounds) { SWFShape swfBounds = createShape(bounds, 2, 0, -1); os.writeTag(new DefineShape4(id.getInt(), bounds, fillStyles, lineStyles, swfBounds)); os.writeTag(new PlaceObject2(id.getInt(), depth.getInt(), getTransform())); id.set(id.getInt() + 1); depth.set(depth.getInt() + 1); } } /* * ================================================================================ | * 6. Transformations * ================================================================================ */ protected void writeTransform(AffineTransform t) throws IOException { // Transforms written when needed } protected void writeSetTransform(AffineTransform t) throws IOException { // Transforms written when needed } /* * ================================================================================ | * 7. Clipping * ================================================================================ */ protected void writeSetClip(Shape s) throws IOException { writeClip(s); } protected void writeClip(Shape s) throws IOException { // we assume we can write nested clips popStreamAndWriteClip(); unwrittenClip = s; clipTransform = (unwrittenClip != null) ? new AffineTransform( getTransform()) : null; if (unwrittenClip != null) { // reserve IDs clipID = id.getInt(); id.set(id.getInt() + 1); clipDepthID = depth.getInt(); depth.set(depth.getInt() + 1); if (isProperty(CLIP)) { showClipID = id.getInt(); id.set(id.getInt() + 1); showClipDepthID = depth.getInt(); depth.set(depth.getInt() + 1); } os.pushBuffer(); } else { clipID = 0; clipDepthID = 0; if (isProperty(CLIP)) { showClipID = 0; showClipDepthID = 0; } } } /* * ================================================================================ | * 8. Graphics State * ================================================================================ */ protected void writeStroke(Stroke stroke) throws IOException { fillStroke = true; if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; setPen(bs, getColor()); if (bs.getLineWidth() == 0) { fillStroke = false; } } } /* 8.2. paint/color */ public void setPaintMode() { writeWarning(getClass() + ": setPaintMode() not implemented."); // Mostly unimplemented. } public void setXORMode(Color c1) { writeWarning(getClass() + ": setXORMode(Color) not implemented."); // Mostly unimplemented. } protected void writePaint(Color p) throws IOException { setPen((BasicStroke) getStroke(), p); setFillColor(p); textColor = PrintColor.createPrintColor(p); } protected void writePaint(GradientPaint p) throws IOException { Gradient[] gradient = new Gradient[2]; gradient[0] = new Gradient(0, p.getColor1()); gradient[1] = new Gradient(255, p.getColor2()); double x0 = p.getPoint1().getX(); double y0 = p.getPoint1().getY(); double dx = p.getPoint2().getX() - x0; double dy = p.getPoint2().getY() - y0; double scale = p.getPoint1().distance(p.getPoint2()) * TWIPS / 32768; double angle = Math.atan2(dy, dx); AffineTransform transform = new AffineTransform(scale, 0, 0, scale, dx / 2 + x0, dy / 2 + y0); transform.rotate(angle); int spreadMode = p.isCyclic() ? FillStyle.SPREAD_MODE_REFLECT : FillStyle.SPREAD_MODE_PAD; fillStyles = new FillStyleArray(); fillStyles.add(new FillStyle(gradient, FillStyle.LINEAR_GRADIENT, spreadMode, FillStyle.INTERPOLATION_MODE_NORMAL_RGB, 0.0f, transform)); textColor = PrintColor.mixColor(p.getColor1(), p.getColor2()); } protected void writePaint(TexturePaint p) throws IOException { // define image BufferedImage image = p.getImage(); int imageID = id.getInt(); os.writeTag(getImageTag(imageID, image, null)); id.set(id.getInt() + 1); // setup image as fill Rectangle2D a = p.getAnchorRect(); double sx = a.getWidth() / image.getWidth(); double sy = a.getHeight() / image.getHeight(); fillStyles = new FillStyleArray(); fillStyles.add(new FillStyle(imageID, true, new AffineTransform(sx * TWIPS, 0, 0, sy * TWIPS, a.getX(), a.getY()))); textColor = PrintColor.black; } protected void writePaint(Paint p) throws IOException { writeWarning(getClass() + ": writePaint(Paint) not implemented for " + p.getClass()); // Write out the paint. writePaint(Color.BLACK); } /* 8.3. font */ protected void writeFont(Font font) throws IOException { // written when needed } /* 8.4. rendering hints */ /* * ================================================================================ | * 9. Auxiliary * ================================================================================ */ public GraphicsConfiguration getDeviceConfiguration() { writeWarning(getClass() + ": getDeviceConfiguration() not implemented."); // Mostly unimplemented return null; } public boolean hit(Rectangle rect, Shape s, boolean onStroke) { writeWarning(getClass() + ": hit(Rectangle, Shape, boolean) not implemented."); // Mostly unimplemented return false; } public void writeComment(String comment) throws IOException { writeWarning(getClass() + ": writeComment(String) not implemented."); // Write out the comment. } public String toString() { return "SWFGraphics2D"; } /* * Private methods */ SWFShape createShape(Shape shape, int stroke, int fill0, int fill1) throws IOException { // use a resolution compatible with the current transform AffineTransform t = getTransform(); double resolution = 0.5 / (TWIPS * Math.min(t.getScaleX(), t .getScaleY())); Vector path = new Vector(); SWFPathConstructor pc = new SWFPathConstructor(path, stroke, fill0, fill1, resolution); pc.addPath(shape); return new SWFShape(path); } private void setPen(BasicStroke stroke, Color color) throws IOException { lineStyles = new LineStyleArray(); lineStyles.add(new LineStyle((int) (stroke.getLineWidth() * TWIPS), getPrintColor(color))); if (showBounds || isProperty(CLIP)) { lineStyles.add(new LineStyle(TWIPS, Color.cyan)); lineStyles.add(new LineStyle(TWIPS, Color.orange)); } } private void setFillColor(Color color) throws IOException { fillStyles = new FillStyleArray(); fillStyles.add(new FillStyle(getPrintColor(color))); } private void popStreamAndWriteClip() throws IOException { if (unwrittenClip == null) return; if ((clipID == 0) || (clipDepthID == 0)) { System.err .println("SWFGraphics2D: internal error, invalid clipID or clipDepthID"); return; } // pop buffer os.popBuffer(); Rectangle2D bounds = unwrittenClip.getBounds2D(); SWFShape clipShape = createShape(unwrittenClip, 0, 1, -1); os.writeTag(new DefineShape4(clipID, bounds, fillStyles, lineStyles, clipShape)); int clipDepth = depth.getInt() - 1; os.writeTag(new PlaceObject2(clipID, clipDepthID, clipTransform, clipDepth)); // System.out.println("Clip "+clipID+" at depth "+clipDepthID+" for // clipDepth "+clipDepth+": "+unwrittenClip); if (isProperty(CLIP)) { if ((showClipID == 0) || (showClipDepthID == 0)) { System.err .println("SWFGraphics2D: internal error, invalid showClipID or showClipDepthID"); return; } SWFShape swfBounds = createShape(bounds, 3, 0, -1); os.writeTag(new DefineShape4(showClipID, bounds, fillStyles, lineStyles, swfBounds)); os.writeTag(new PlaceObject(showClipID, showClipDepthID, clipTransform)); } // append popped buffer; os.append(); } private SWFTag getImageTag(int imageID, RenderedImage image, Color bkg) throws IOException { String writeAs = getProperty(WRITE_IMAGES_AS); DefineBitsLossless2 flateTag = null; if (writeAs.equals(ImageConstants.ZLIB) || writeAs.equals(ImageConstants.SMALLEST)) { flateTag = new DefineBitsLossless2(imageID, image, bkg); } DefineBitsJPEG3 jpgTag = null; if (writeAs.equals(ImageConstants.JPG) || writeAs.equals(ImageConstants.SMALLEST)) { jpgTag = new DefineBitsJPEG3(imageID, image, bkg, new Properties()); } SWFTag imageTag; if (writeAs.equals(ImageConstants.ZLIB)) { imageTag = flateTag; } else if (writeAs.equals(ImageConstants.JPG)) { imageTag = jpgTag; } else { imageTag = (jpgTag.getLength() < 0.5 * flateTag.getLength()) ? (SWFTag) jpgTag : (SWFTag) flateTag; } return imageTag; } } src/main/java/org/freehep/graphicsio/swf/ControlTag.java0000644000175000017500000000106611343262531022614 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; /** * Abstract Control TAG. All control tags derive from this tag. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ControlTag.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class ControlTag extends SWFTag { protected ControlTag(int tagID, int version) { super(tagID, version); } public int getTagType() { return CONTROL; } public String toString() { return "Control: " + getName() + " (" + getTag() + ")"; } } src/main/java/org/freehep/graphicsio/swf/SoundStreamBlock.java0000644000175000017500000000201711343262531023754 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SoundStreamBlock TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SoundStreamBlock.java 8584 2006-08-10 23:06:37Z duns $ */ public class SoundStreamBlock extends DefinitionTag { private int[] data; public SoundStreamBlock(int[] data) { this(); this.data = data; } public SoundStreamBlock() { super(19, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { SoundStreamBlock tag = new SoundStreamBlock(); tag.data = swf.readUnsignedByte(len); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedByte(data); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" length" + data.length + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFHeader.java0000644000175000017500000000667211343262531022320 0ustar user03user03// Copyright 2001-2005, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Dimension; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * SWF File Header. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFHeader.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFHeader implements SWFConstants { private int version; private long length; private Dimension size; private float rate; private int count; private boolean compress; public SWFHeader(int version, long length, Dimension size, float rate, int count, boolean compress) { this.version = version; this.length = length; this.size = size; this.rate = rate; this.count = count; this.compress = compress; } public SWFHeader(SWFInputStream swf) throws IOException { // NOTE: page 8 and 13 are in conflict about the HEADER for compressed // files. // the tag that can be read by Flash is CWS (and not FWC). int s = swf.readUnsignedByte(); if (((int) 'F' != s) && ((int) 'C' != s)) throw new IOException(); if ((int) 'W' != swf.readUnsignedByte()) throw new IOException(); if ((int) 'S' != swf.readUnsignedByte()) throw new IOException(); version = swf.readUnsignedByte(); length = swf.readUnsignedInt(); compress = (version >= 6) && ((int) 'C' == s); if (compress) swf.startDecompressing(); Rectangle2D frame = swf.readRect(); size = new Dimension((int) frame.getMaxX(), (int) frame.getMaxY()); rate = (float) swf.readUnsignedShort() / 256f; count = swf.readUnsignedShort(); } public void write(SWFOutputStream swf) throws IOException { // NOTE: page 8 and 13 are in conflict about the HEADER for compressed // files. // the tag that can be read by Flash is CWS (and not FWC). if ((version >= 6) && compress) { swf.writeUnsignedByte('C'); } else { swf.writeUnsignedByte('F'); } swf.writeUnsignedByte('W'); swf.writeUnsignedByte('S'); swf.writeUnsignedByte(version); swf.writeUnsignedInt(length); if ((version >= 6) && compress) swf.startCompressing(); // the rectangle seems to may be 16 bits instead of 15... Rectangle2D frame = new Rectangle2D.Double(0, 0, size.width, size.height); swf.writeRect(frame); swf.writeUnsignedShort((int) (rate * 256f)); swf.writeUnsignedShort(count); } public static int size() { return 21; // this is fixed } public int getVersion() { return version; } public long getLength() { return length; } public boolean isCompressed() { return compress; } public Dimension getSize() { return size; } public float getRate() { return rate; } public int getCount() { return count; } public String toString() { StringBuffer s = new StringBuffer("SWF Header\n"); s.append(" version: " + version + "\n"); s.append(" length: " + length + "\n"); s.append(" compress: " + compress + "\n"); s.append(" size: " + size + "\n"); s.append(" rate: " + rate + "\n"); s.append(" count: " + count); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/package.html0000644000175000017500000000424011343262531022153 0ustar user03user03

SWF (Macromedia Flash) Input and Output Format.

SWF is a Vector Graphics Animation format, defined by MacroMedia, also known as the Flash Format.

This package provides a low-level reader and writer for SWF files:

and an implementation of VectorGraphics:

The current implementation supports Version 3 of SWF.

SWF files can be imported by the following applications:

In all these applications both online viewing and printing are supported.

The following Limitations exist:

@status Not Ready. src/main/java/org/freehep/graphicsio/swf/End.java0000644000175000017500000000067311343262531021251 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * End TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: End.java 8584 2006-08-10 23:06:37Z duns $ */ public class End extends ControlTag { public End() { super(0, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { return this; } } src/main/java/org/freehep/graphicsio/swf/ButtonRecord.java0000644000175000017500000000534011343262531023151 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.AffineTransform; import java.io.IOException; /** * SWF Button Record * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ButtonRecord.java 8584 2006-08-10 23:06:37Z duns $ */ public class ButtonRecord { public final static int UP = 0x01; public final static int OVER = 0x02; public final static int DOWN = 0x04; public final static int HIT = 0x08; private boolean hitTest; private boolean down; private boolean over; private boolean up; private int id; private int depth; private AffineTransform matrix; private ColorXform cxform; public ButtonRecord(boolean hitTest, boolean down, boolean over, boolean up, int id, int depth, AffineTransform matrix, ColorXform cxform) { this.hitTest = hitTest; this.down = down; this.over = over; this.up = up; this.id = id; this.depth = depth; this.matrix = matrix; this.cxform = cxform; } public ButtonRecord(boolean hitTest, boolean down, boolean over, boolean up, int id, int depth, AffineTransform matrix) { this(hitTest, down, over, up, id, depth, matrix, null); } public ButtonRecord(SWFInputStream input, boolean hasColorXform) throws IOException { /* int reserved = (int) */ input.readUBits(4); hitTest = input.readBitFlag(); down = input.readBitFlag(); over = input.readBitFlag(); up = input.readBitFlag(); if (isEndRecord()) return; id = input.readUnsignedShort(); depth = input.readUnsignedShort(); matrix = input.readMatrix(); if (hasColorXform) { cxform = new ColorXform(input, true); } else { // NOTE: it may be just alignment, FREEHEP-535 input.readUnsignedByte(); } } public void write(SWFOutputStream swf) throws IOException { swf.writeUBits(0, 4); swf.writeBitFlag(hitTest); swf.writeBitFlag(down); swf.writeBitFlag(over); swf.writeBitFlag(up); swf.writeUnsignedShort(id); swf.writeUnsignedShort(depth); swf.writeMatrix(matrix); if (cxform != null) { cxform.write(swf, true); } else { // NOTE: it may be just alignment, FREEHEP-535 swf.writeUnsignedByte(0); } } public boolean isEndRecord() { return !(hitTest || down || over || up); } public String toString() { return "ButtonRecord char:" + id + " depth:" + depth + " " + matrix + " " + ((cxform != null) ? "" + cxform : ""); } } src/main/java/org/freehep/graphicsio/swf/SetBackgroundColor.java0000644000175000017500000000171411343262531024272 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.io.IOException; /** * SetBackgroundColor TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SetBackgroundColor.java 8584 2006-08-10 23:06:37Z duns $ */ public class SetBackgroundColor extends ControlTag { private Color color; public SetBackgroundColor(Color color) { this(); this.color = color; } public SetBackgroundColor() { super(9, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { SetBackgroundColor tag = new SetBackgroundColor(); tag.color = swf.readColor(false); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeColor(color, false); } public String toString() { return super.toString() + "\n" + " bkg.color=" + color; } } src/main/java/org/freehep/graphicsio/swf/SWFOutputStream.java0000644000175000017500000001525511343262531023601 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.Dimension; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.OutputStream; import org.freehep.util.io.ActionHeader; import org.freehep.util.io.TagHeader; import org.freehep.util.io.TaggedOutputStream; /** * This class extends the TaggedOutputStream with several methods to write SWF * primitives to the stream and to write TagHeaders. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFOutputStream.java 9976 2006-11-27 18:25:46Z duns $ */ public class SWFOutputStream extends TaggedOutputStream implements SWFConstants { private Dimension size; private float frameRate; private int frameCount = 0; private boolean compress; private final static AffineTransform identityMatrix = new AffineTransform(); public SWFOutputStream(OutputStream os, Dimension size, float frameRate, boolean compress) throws IOException { this(os, DEFAULT_VERSION, size, frameRate, compress); } public SWFOutputStream(OutputStream os, int version, Dimension size, float frameRate, boolean compress) throws IOException { this(os, new SWFTagSet(version), new SWFActionSet(version), size, frameRate, compress); } public SWFOutputStream(OutputStream os, SWFTagSet tagSet, SWFActionSet actionSet, Dimension size, float frameRate, boolean compress) throws IOException { // SWF is little-endian super(os, tagSet, actionSet, true); this.size = size; this.frameRate = frameRate; this.compress = compress; // will be popped by close() pushBuffer(); // add FileAttributes writeTag(new FileAttributes()); } public void close() throws IOException { long len = popBuffer() + SWFHeader.size(); SWFHeader header = new SWFHeader(getVersion(), len, size, frameRate, frameCount, compress); writeHeader(header); append(); super.close(); } public void writeTag(ShowFrame tag) throws IOException { frameCount++; super.writeTag(tag); } public void writeFixed(double d) throws IOException { byteAlign(); long whole = (long) d; long frac = (long) ((d - whole) * 0x10000); long fixed = ((whole & 0xFFFF) << 16) | (frac & 0xFFFF); writeUnsignedInt(fixed); } public void writeFixed8(double d) throws IOException { byteAlign(); int whole = (int) d; int frac = (int) ((d - whole) * 0x100); int fixed = ((whole & 0xFF) << 8) | (frac & 0xFF); writeUnsignedShort(fixed); } public void writeRect(Rectangle2D rect) throws IOException { int nbits = 0; nbits = Math.max(nbits, minBits((int) (rect.getMinX() * TWIPS), true)); nbits = Math.max(nbits, minBits((int) (rect.getMaxX() * TWIPS), true)); nbits = Math.max(nbits, minBits((int) (rect.getMinY() * TWIPS), true)); nbits = Math.max(nbits, minBits((int) (rect.getMaxY() * TWIPS), true)); writeRect(rect, nbits); } public void writeRect(Rectangle2D rect, int nbits) throws IOException { byteAlign(); writeUBits(nbits, 5); writeSBits((int) (rect.getMinX() * TWIPS), nbits); writeSBits((int) (rect.getMaxX() * TWIPS), nbits); writeSBits((int) (rect.getMinY() * TWIPS), nbits); writeSBits((int) (rect.getMaxY() * TWIPS), nbits); } public void writeColor(Color color, boolean alpha) throws IOException { byteAlign(); writeUnsignedByte(color.getRed()); writeUnsignedByte(color.getGreen()); writeUnsignedByte(color.getBlue()); if (alpha) writeUnsignedByte(color.getAlpha()); } public void writeMatrix(AffineTransform matrix) throws IOException { if (matrix == null) matrix = identityMatrix; byteAlign(); // Get the scale bits. if ((matrix.getScaleX() != 1.f) || (matrix.getScaleY() != 1.f)) { writeBitFlag(true); int nbits = 0; nbits = Math.max(nbits, minBits((float) matrix.getScaleX())); nbits = Math.max(nbits, minBits((float) matrix.getScaleY())); writeUBits(nbits, 5); writeFBits((float) matrix.getScaleX(), nbits); writeFBits((float) matrix.getScaleY(), nbits); } else { writeBitFlag(false); } // Rotate or skew values. if ((matrix.getShearX() != 0.f) || (matrix.getShearY() != 0.f)) { writeBitFlag(true); int nbits = 0; nbits = Math.max(nbits, minBits((float) matrix.getShearY())); nbits = Math.max(nbits, minBits((float) matrix.getShearX())); writeUBits(nbits, 5); writeFBits((float) matrix.getShearY(), nbits); writeFBits((float) matrix.getShearX(), nbits); } else { writeBitFlag(false); } // Translation values. int nbits = 0; nbits = Math.max(nbits, minBits((int) (matrix.getTranslateX() * TWIPS), true)); nbits = Math.max(nbits, minBits((int) (matrix.getTranslateY() * TWIPS), true)); writeUBits(nbits, 5); writeSBits((int) (matrix.getTranslateX() * TWIPS), nbits); writeSBits((int) (matrix.getTranslateY() * TWIPS), nbits); } public void writeString(String s) throws IOException { if (getVersion() >= 6) { writeUTF(s); writeByte(0); } else { writeAsciiZString(s); } } public void writeLanguageCode(int code) throws IOException { writeUnsignedByte(code); } protected void writeTagHeader(TagHeader tagHeader) throws IOException { byteAlign(); int th = (tagHeader.getTag() << 6); if (tagHeader.getLength() >= 0x3f) { th |= 0x3f; writeUnsignedShort(th); writeUnsignedInt(tagHeader.getLength()); } else { th |= tagHeader.getLength(); writeUnsignedShort(th); } } protected void writeActionHeader(ActionHeader header) throws IOException { int actionCode = header.getAction(); long length = header.getLength(); writeUnsignedByte(actionCode); if ((actionCode & 0x80) > 0) { writeUnsignedShort((int) length); } } public void writeHeader(SWFHeader header) throws IOException { header.write(this); } public int getVersion() { return ((SWFTagSet) tagSet).getVersion(); } }src/main/java/org/freehep/graphicsio/swf/SWFExportFileType.java0000644000175000017500000000407511343262531024046 0ustar user03user03// Copyright 2003-2007, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Component; import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import javax.swing.JLabel; import javax.swing.JPanel; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphicsio.ImageConstants; import org.freehep.graphicsio.exportchooser.AbstractExportFileType; import org.freehep.graphicsio.exportchooser.BackgroundPanel; import org.freehep.graphicsio.exportchooser.ImageTypePanel; import org.freehep.graphicsio.exportchooser.OptionPanel; import org.freehep.swing.layout.TableLayout; import org.freehep.util.UserProperties; /** * // FIXME, check all options * * @author Mark Donszelmann * @version $Id: SWFExportFileType.java 12753 2007-06-12 22:32:31Z duns $ */ public class SWFExportFileType extends AbstractExportFileType { public String getDescription() { return "MacroMedia Flash File Format"; } public String[] getExtensions() { return new String[] { "swf" }; } public String[] getMIMETypes() { return new String[] { "application/x-shockwave-flash" }; } public boolean hasOptionPanel() { return true; } public JPanel createOptionPanel(Properties user) { UserProperties options = new UserProperties(user, SWFGraphics2D .getDefaultProperties()); String rootKey = SWFGraphics2D.class.getName(); // Make the full panel. OptionPanel optionsPanel = new OptionPanel(); optionsPanel.add("0 0 [5 5 5 5] wt", new BackgroundPanel(options, rootKey, true)); optionsPanel.add("0 1 [5 5 5 5] wt", new ImageTypePanel(options, rootKey, new String[] { ImageConstants.SMALLEST, ImageConstants.ZLIB, ImageConstants.JPG })); optionsPanel.add(TableLayout.COLUMN_FILL, new JLabel()); return optionsPanel; } public VectorGraphics getGraphics(OutputStream os, Component target) throws IOException { return new SWFGraphics2D(os, target); } public VectorGraphics getGraphics(OutputStream os, Dimension dimension) throws IOException { return new SWFGraphics2D(os, dimension); } } src/main/java/org/freehep/graphicsio/swf/DefineSound.java0000644000175000017500000000526611343262531022751 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineSound TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineSound.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineSound extends DefinitionTag { public final static int NONE = 0; public final static int ADPCM = 1; public final static int MP3 = 2; public final static int NELLYMOSER = 3; public final static int RATE_5_5 = 0; public final static int RATE_11 = 1; public final static int RATE_22 = 2; public final static int RATE_44 = 3; public final static int BYTE = 0; public final static int SHORT = 1; public final static int MONO = 0; public final static int STEREO = 1; private int character; private int format; private int rate; private int size; private boolean stereo; private long samples; private int[] data; public DefineSound(int id, int format, int rate, int size, boolean stereo, long samples, int[] data) { this(); character = id; this.format = format; this.rate = rate; this.size = size; this.stereo = stereo; this.samples = samples; this.data = data; } public DefineSound() { super(14, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineSound tag = new DefineSound(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.format = (int) swf.readUBits(4); tag.rate = (int) swf.readUBits(2); tag.size = swf.readBitFlag() ? SHORT : BYTE; tag.stereo = swf.readBitFlag(); tag.samples = swf.readUnsignedInt(); tag.data = swf.readUnsignedByte(len - 7); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUBits(format, 4); swf.writeUBits(rate, 2); swf.writeBitFlag(size == SHORT); swf.writeBitFlag(stereo); swf.writeUnsignedInt(samples); swf.writeUnsignedByte(data); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" format:" + format + "\n"); s.append(" rate:" + rate + "\n"); s.append(" size:" + size + "\n"); s.append(" stereo:" + stereo + "\n"); s.append(" samples:" + samples + "\n"); s.append(" length:" + data.length + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFConstants.java0000644000175000017500000000147211343262531023075 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; /** * SWF Constants. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFConstants.java 9979 2006-11-27 22:51:07Z duns $ */ public interface SWFConstants { /** * This defines the control tag type. */ public static final int CONTROL = 1; /** * This defines the definition tag type. */ public static final int DEFINITION = 2; public static final int DEFAULT_VERSION = 8; public static final int TWIPS = 20; public static final int LANGUAGE_LATIN = 1; public static final int LANGUAGE_JAPANESE = 2; public static final int LANGUAGE_KOREAN = 3; public static final int LANGUAGE_SIMPLIFIED_CHINESE = 4; public static final int LANGUAGE_TRADITIONAL_CHINESE = 5; } src/main/java/org/freehep/graphicsio/swf/SWFInputStream.java0000644000175000017500000001265011343262531023374 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.InputStream; import org.freehep.util.io.ActionHeader; import org.freehep.util.io.TagHeader; import org.freehep.util.io.TaggedInputStream; /** * This class extends the TaggedInputStream with several methods to read SWF * primitives from the stream and to read TagHeaders. It also handles the * management of the SWFDictionary. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFInputStream.java 9979 2006-11-27 22:51:07Z duns $ */ public class SWFInputStream extends TaggedInputStream implements SWFConstants { private SWFDictionary dictionary; private byte[] jpegTable; public SWFInputStream(InputStream is) throws IOException { this(is, DEFAULT_VERSION); } public SWFInputStream(InputStream is, int version) throws IOException { this(is, new SWFTagSet(version), new SWFActionSet(version)); } public SWFInputStream(InputStream is, SWFSpriteTagSet tagSet, SWFActionSet actionSet) throws IOException { // SWF is little-endian super(is, tagSet, actionSet, true); dictionary = new SWFDictionary(); } /** * Read a fixed point value (16.16). */ public float readFixed() throws IOException { byteAlign(); int frac = readUnsignedByte(); frac |= readUnsignedByte() << 8; int whole = readUnsignedByte(); whole |= readUnsignedByte() << 8; return ((float) whole) + ((float) frac) / ((float) 0x10000); } /** * Read a fixed point value (8.8). */ public float readFixed8() throws IOException { byteAlign(); int frac = readUnsignedByte(); int whole = readUnsignedByte(); return ((float) whole) + ((float) frac) / ((float) 0x100); } /** * Read a rectangle from the stream. */ public Rectangle2D readRect() throws IOException { byteAlign(); int nbits = (int) readUBits(5); int xmin = (int) readSBits(nbits); int xmax = (int) readSBits(nbits); int ymin = (int) readSBits(nbits); int ymax = (int) readSBits(nbits); return new Rectangle2D.Double(xmin / TWIPS, ymin / TWIPS, (xmax - xmin) / TWIPS, (ymax - ymin) / TWIPS); } /** * Read an RGB value from the stream. */ public Color readColor(boolean alpha) throws IOException { int r = readUnsignedByte(); int g = readUnsignedByte(); int b = readUnsignedByte(); int a = (alpha) ? readUnsignedByte() : 255; return new Color(r, g, b, a); } /** * Read a matrix from the stream. */ public AffineTransform readMatrix() throws IOException { byteAlign(); // Set default values. float sx = 1.f; float sy = 1.f; float kx = 0.f; float ky = 0.f; float tx = 0.f; float ty = 0.f; // Get the scale bits. if (readBitFlag()) { int nbits = (int) readUBits(5); sx = readFBits(nbits); sy = readFBits(nbits); } // Rotate or skew values. if (readBitFlag()) { int nbits = (int) readUBits(5); kx = readFBits(nbits); ky = readFBits(nbits); } // Translation values. int nbits = (int) readUBits(5); tx = (float) readSBits(nbits) / TWIPS; ty = (float) readSBits(nbits) / TWIPS; return new AffineTransform(sx, ky, kx, sy, tx, ty); } /** * Read a string from the stream. */ public String readString() throws IOException { if (getVersion() >= 6) { String s = readUTF(); readByte(); return s; } else { return readAsciiZString(); } } public int readLanguageCode() throws IOException { return readUnsignedByte(); } protected TagHeader readTagHeader() throws IOException { // Read the tag. byteAlign(); int temp = read(); // End of stream if (temp == -1) return null; temp |= readUnsignedByte() << 8; int tagID = temp >> 6; long length = temp & FIELD_MASK[5]; if (length == 0x3f) length = readUnsignedInt(); return new TagHeader(tagID, length); } protected ActionHeader readActionHeader() throws IOException { int actionCode = readUnsignedByte(); if (actionCode == 0) return null; int length = 0; if ((actionCode & 0x80) > 0) { length = readUnsignedShort(); } return new ActionHeader(actionCode, length); } private SWFHeader header; public SWFHeader readHeader() throws IOException { if (header == null) { header = new SWFHeader(this); int version = header.getVersion(); tagSet = new SWFTagSet(version); actionSet = new SWFActionSet(version); } return header; } public SWFDictionary getDictionary() { return dictionary; } public void setJPEGTable(byte[] table) { jpegTable = table; } public byte[] getJPEGTable() { return jpegTable; } public int getVersion() { return ((SWFSpriteTagSet) tagSet).getVersion(); } } src/main/java/org/freehep/graphicsio/swf/DefineBitsLossless.java0000644000175000017500000001270711343262531024310 0ustar user03user03// Copyright 2001-2007, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.image.RenderedImage; import java.awt.image.WritableRaster; import java.io.IOException; import java.util.zip.InflaterInputStream; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.ImageConstants; import org.freehep.util.images.ImageUtilities; import org.freehep.util.io.ByteOrderInputStream; /** * DefineBitsLossless TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineBitsLossless.java 10269 2007-01-09 00:32:55Z duns $ */ public class DefineBitsLossless extends DefinitionTag { protected int character; protected RenderedImage image; protected Color bkg; public DefineBitsLossless(int id, Image image, Color bkg, ImageObserver observer) { this(id, ImageUtilities.createRenderedImage(image, observer, bkg), bkg); } public DefineBitsLossless(int id, RenderedImage image, Color bkg) { this(); character = id; this.image = image; this.bkg = bkg; } public DefineBitsLossless() { super(20, 2); } protected DefineBitsLossless(int tagID, int version) { super(tagID, version); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineBitsLossless tag = new DefineBitsLossless(); tag.read(tagID, swf, len, false); return tag; } protected void read(int tagID, SWFInputStream swf, int len, boolean hasAlpha) throws IOException { character = swf.readUnsignedShort(); swf.getDictionary().put(character, this); int format = swf.readUnsignedByte(); int width = swf.readUnsignedShort(); int height = swf.readUnsignedShort(); int colorTableSize = (format == 3) ? swf.readUnsignedByte() + 1 : 0; InflaterInputStream zip = new InflaterInputStream(swf); ByteOrderInputStream bois = new ByteOrderInputStream(zip, true); int[][] colors = new int[colorTableSize][hasAlpha ? 4 : 3]; for (int i = 0; i < colorTableSize; i++) { colors[i][0] = zip.read(); colors[i][1] = zip.read(); colors[i][2] = zip.read(); if (hasAlpha) { colors[i][3] = zip.read(); } } BufferedImage bi = new BufferedImage(width, height, (hasAlpha) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); WritableRaster raster = bi.getRaster(); int[] rgba = new int[hasAlpha ? 4 : 3]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { switch (format) { default: System.out .println("ERROR: unknown format in LossLess image: " + format); return; case 3: raster.setPixel(x, y, colors[bois.readUnsignedByte()]); break; case 4: if (hasAlpha) { System.out .println("ERROR: unknown format in LossLess2 image: 4"); return; } bois.readUBits(1); rgba[0] = (int) bois.readUBits(5); rgba[1] = (int) bois.readUBits(5); rgba[2] = (int) bois.readUBits(5); raster.setPixel(x, y, rgba); break; case 5: if (hasAlpha) { rgba[3] = bois.readUnsignedByte(); } else { bois.readUnsignedByte(); } rgba[0] = bois.readUnsignedByte(); rgba[1] = bois.readUnsignedByte(); rgba[2] = bois.readUnsignedByte(); raster.setPixel(x, y, rgba); break; } // FIXME padding not taken into account. } } image = bi; } public void write(int tagID, SWFOutputStream swf) throws IOException { write(tagID, swf, false); } protected void write(int tagID, SWFOutputStream swf, boolean hasAlpha) throws IOException { swf.writeUnsignedShort(character); swf.writeUnsignedByte(5); // fixed to format 5 swf.writeUnsignedShort(image.getWidth()); swf.writeUnsignedShort(image.getHeight()); swf.write(getImageBytes()); } public int getLength() throws IOException { return getImageBytes().length + 7; } private byte[] imageBytes; private byte[] getImageBytes() throws IOException { if (imageBytes == null) { // calculate bytes imageBytes = ImageGraphics2D.toByteArray( image, ImageConstants.RAW, ImageConstants.ENCODING_FLATE, ImageGraphics2D.getRAWProperties(bkg, ImageConstants.COLOR_MODEL_ARGB)); } return imageBytes; } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character); s.append(" image: " + image); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/ExportAssets.java0000644000175000017500000000232611343262531023204 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * ExportAssets TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ExportAssets.java 8584 2006-08-10 23:06:37Z duns $ */ public class ExportAssets extends ControlTag { private int[] tags; private String[] assets; public ExportAssets(int[] tags, String[] assets) { this(); this.tags = tags; this.assets = assets; } public ExportAssets() { super(56, 5); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { ExportAssets tag = new ExportAssets(); int n = swf.readUnsignedShort(); tag.tags = new int[n]; tag.assets = new String[n]; for (int i = 0; i < n; i++) { tag.tags[i] = swf.readUnsignedShort(); tag.assets[i] = swf.readString(); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(tags.length); for (int i = 0; i < tags.length; i++) { swf.writeUnsignedShort(tags[i]); swf.writeString(assets[i]); } } } src/main/java/org/freehep/graphicsio/swf/LineStyle.java0000644000175000017500000000756311343262531022460 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.io.IOException; /** * SWF LineStyle. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: LineStyle.java 9979 2006-11-27 22:51:07Z duns $ */ public class LineStyle { public static final int CAP_ROUND = 0; public static final int CAP_NONE = 1; public static final int CAP_SQUARE = 2; public static final int JOIN_ROUND = 0; public static final int JOIN_BEVEL = 1; public static final int JOIN_MITER = 2; private int width, endWidth; private int startCapStyle, joinStyle, endCapStyle; private boolean hasFillFlag, noHScaleFlag, noVScaleFlag, pixelHintingFlag, noClose; private float miterLimitFactor; private FillStyle fillStyle; private Color color, endColor; public LineStyle(int width, Color color) { this.width = width; this.color = color; this.startCapStyle = CAP_ROUND; this.joinStyle = JOIN_ROUND; this.endCapStyle = CAP_ROUND; this.hasFillFlag = false; this.noHScaleFlag = false; this.noVScaleFlag = false; this.pixelHintingFlag = false; this.noClose = false; } public LineStyle(int width, int endWidth, Color color, Color endColor) { this(width, color); this.endWidth = endWidth; this.endColor = endColor; } public LineStyle(SWFInputStream input, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { width = input.readUnsignedShort(); if (isMorphStyle) { endWidth = input.readUnsignedShort(); } if (hasStyles) { startCapStyle = (int)input.readUBits(2); joinStyle = (int)input.readUBits(2); hasFillFlag = input.readBitFlag(); noHScaleFlag = input.readBitFlag(); noVScaleFlag = input.readBitFlag(); pixelHintingFlag = input.readBitFlag(); input.readUBits(5); noClose = input.readBitFlag(); endCapStyle = (int)input.readUBits(2); if (joinStyle == JOIN_MITER) { input.readFixed8(); } if (hasFillFlag) { fillStyle = new FillStyle(input, false, true); } else { color = input.readColor(true); } } else { color = input.readColor(hasAlpha); } if (isMorphStyle) { endColor = input.readColor(true); } } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { swf.writeUnsignedShort(width); if (isMorphStyle) { swf.writeUnsignedShort(endWidth); } if (hasStyles) { swf.writeUBits(startCapStyle, 2); swf.writeUBits(joinStyle, 2); swf.writeBitFlag(hasFillFlag); swf.writeBitFlag(noHScaleFlag); swf.writeBitFlag(noVScaleFlag); swf.writeBitFlag(pixelHintingFlag); swf.writeUBits(0, 5); swf.writeBitFlag(noClose); swf.writeUBits(endCapStyle, 2); if (joinStyle == JOIN_MITER) { swf.writeFixed8(miterLimitFactor); } if (hasFillFlag) { fillStyle.write(swf, isMorphStyle, true); } else { swf.writeColor(color, true); } } else { swf.writeColor(color, hasAlpha || isMorphStyle); if (isMorphStyle) { swf.writeColor(endColor, true); } } } public String toString() { StringBuffer s = new StringBuffer("LineStyle " + width + ", " + color); if (endColor != null) s.append("; " + endWidth + ", " + endColor); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineText2.java0000644000175000017500000000175111343262531022662 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.util.Vector; /** * DefineText2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineText2.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineText2 extends DefineText { public DefineText2(int id, Rectangle2D bounds, AffineTransform matrix, Vector text) { this(); character = id; this.bounds = bounds; this.matrix = matrix; this.text = text; } public DefineText2() { super(33, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineText2 tag = new DefineText2(); tag.read(tagID, swf, len, true); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf, true); } } src/main/java/org/freehep/graphicsio/swf/SWFSpriteTagSet.java0000644000175000017500000000257211343262531023501 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import org.freehep.util.io.TagSet; /** * Defines the tags in the MiniTag (Sprite) structure * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFSpriteTagSet.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFSpriteTagSet extends TagSet { private int version; public SWFSpriteTagSet(int version) { super(); this.version = version; // Initialize tags // Version 1 if (version >= 1) { addTag(new End()); // 0 addTag(new ShowFrame()); // 1 addTag(new PlaceObject()); // 4 addTag(new RemoveObject()); // 5 addTag(new DoAction()); // 12 addTag(new StartSound()); // 15 addTag(new SoundStreamHead()); // 18 addTag(new SoundStreamBlock()); // 19 } // Version 2 if (version >= 2) { } // Version 3 if (version >= 3) { addTag(new PlaceObject2()); // 26 addTag(new RemoveObject2()); // 28 addTag(new FrameLabel()); // 43 } // version 4 if (version >= 4) { } // version 5 if (version >= 5) { } // version 6 if (version >= 6) { } } public int getVersion() { return version; } } src/main/java/org/freehep/graphicsio/swf/DefineBitsJPEG2.java0000644000175000017500000000530611343262531023305 0ustar user03user03// Copyright 2001-2007, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.Image; import java.awt.image.ImageObserver; import java.awt.image.RenderedImage; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Properties; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.ImageConstants; import org.freehep.util.images.ImageUtilities; /** * DefineBitsJPEG2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineBitsJPEG2.java 10269 2007-01-09 00:32:55Z duns $ */ public class DefineBitsJPEG2 extends DefinitionTag { protected int character; protected RenderedImage image; protected Properties options; public DefineBitsJPEG2(int id, Image image, Properties options, Color bkg, ImageObserver observer) { this(id, ImageUtilities.createRenderedImage(image, observer, bkg), bkg, options); } public DefineBitsJPEG2(int id, RenderedImage image, Color bkg, Properties options) { this(); character = id; this.image = image; this.options = options; } public DefineBitsJPEG2() { super(21, 2); } protected DefineBitsJPEG2(int tag, int level) { super(tag, level); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineBitsJPEG2 tag = new DefineBitsJPEG2(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); byte[] data = swf.readByte(len - 2); ByteArrayInputStream bais = new ByteArrayInputStream(data); tag.image = ImageGraphics2D.readImage(ImageConstants.JPG.toLowerCase(), bais); if (bais.available() > 0) System.err.println("DefineBitsJPEG2: not all bytes read: " + bais.available()); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.write(getImageBytes()); } public int getLength() throws IOException { return getImageBytes().length + 2; } private byte[] imageBytes; private byte[] getImageBytes() throws IOException { if (imageBytes == null) { imageBytes = ImageGraphics2D.toByteArray( image, ImageConstants.JPG, null, options); } return imageBytes; } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" image: " + image + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/ColorXform.java0000644000175000017500000000752511343262531022640 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.io.IOException; import org.freehep.util.io.BitOutputStream; /** * SWF Color Transform * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ColorXform.java 8584 2006-08-10 23:06:37Z duns $ */ public class ColorXform { private int rx = 0x0100; private int gx = 0x0100; private int bx = 0x0100; private int ax = 0x0100; private int rp = 0; private int gp = 0; private int bp = 0; private int ap = 0; public ColorXform(int rx, int gx, int bx, int ax, int rp, int gp, int bp, int ap) { this.rx = rx; this.gx = gx; this.bx = bx; this.ax = ax; this.rp = rp; this.gp = gp; this.bp = bp; this.ap = ap; } /** * Read a color transform from the stream. */ public ColorXform(SWFInputStream swf, boolean hasAlpha) throws IOException { swf.byteAlign(); boolean add = swf.readBitFlag(); boolean mult = swf.readBitFlag(); int nbits = (int) swf.readUBits(4); if (mult) { rx = (int) swf.readSBits(nbits); gx = (int) swf.readSBits(nbits); bx = (int) swf.readSBits(nbits); if (hasAlpha) ax = (int) swf.readSBits(nbits); } if (add) { rp = (int) swf.readSBits(nbits); gp = (int) swf.readSBits(nbits); bp = (int) swf.readSBits(nbits); if (hasAlpha) ap = (int) swf.readSBits(nbits); } } public Color transform(Color c) { int red = (int) Math.max(0, Math.min(((c.getRed() * rx) / 256.0) + rp, 255)); int green = (int) Math.max(0, Math.min(((c.getGreen() * gx) / 256.0) + gp, 255)); int blue = (int) Math.max(0, Math.min( ((c.getBlue() * bx) / 256.0) + bp, 255)); int alpha = (int) Math.max(0, Math.min(((c.getAlpha() * ax) / 256.0) + ap, 255)); return new Color(red, green, blue, alpha); } public void write(SWFOutputStream swf, boolean hasAlpha) throws IOException { swf.byteAlign(); boolean add = (rp != 0) || (gp != 0) || (bp != 0) || (hasAlpha && (ap != 0)); boolean mult = (rx != 1) || (gx != 1) || (bx != 1) || (hasAlpha && (ax != 1)); int nbits = 0; if (mult) { nbits = Math.max(nbits, BitOutputStream.minBits(rx, true)); nbits = Math.max(nbits, BitOutputStream.minBits(gx, true)); nbits = Math.max(nbits, BitOutputStream.minBits(bx, true)); if (hasAlpha) { nbits = Math.max(nbits, BitOutputStream.minBits(ax, true)); } } if (add) { nbits = Math.max(nbits, BitOutputStream.minBits(rp, true)); nbits = Math.max(nbits, BitOutputStream.minBits(gp, true)); nbits = Math.max(nbits, BitOutputStream.minBits(bp, true)); if (hasAlpha) { nbits = Math.max(nbits, BitOutputStream.minBits(ap, true)); } } swf.writeBitFlag(add); swf.writeBitFlag(mult); swf.writeUBits(nbits, 4); if (mult) { swf.writeSBits(rx, nbits); swf.writeSBits(gx, nbits); swf.writeSBits(bx, nbits); if (hasAlpha) swf.writeSBits(ax, nbits); } if (add) { swf.writeSBits(rp, nbits); swf.writeSBits(gp, nbits); swf.writeSBits(bp, nbits); if (hasAlpha) swf.writeSBits(ap, nbits); } } public String toString() { return "CXForm(" + rx + ", " + gx + ", " + bx + ", " + ax + " : " + rp + ", " + gp + ", " + bp + ", " + ap + ")"; } } src/main/java/org/freehep/graphicsio/swf/DefineShape3.java0000644000175000017500000000200211343262531022765 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineShape3 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineShape3.java 9976 2006-11-27 18:25:46Z duns $ */ public class DefineShape3 extends DefineShape { public DefineShape3(int id, Rectangle2D bounds, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape shape) { this(); character = id; this.bounds = bounds; this.fillStyles = fillStyles; this.lineStyles = lineStyles; this.shape = shape; } public DefineShape3() { super(32, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineShape3 tag = new DefineShape3(); tag.read(tagID, swf, true); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf, true); } } src/main/java/org/freehep/graphicsio/swf/SoundEnvelope.java0000644000175000017500000000207511343262531023327 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SWF SoundEnvelope. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SoundEnvelope.java 8584 2006-08-10 23:06:37Z duns $ */ public class SoundEnvelope { private long pos44; private int leftLevel, rightLevel; public SoundEnvelope(long pos44, int leftLevel, int rightLevel) { this.pos44 = pos44; this.leftLevel = leftLevel; this.rightLevel = rightLevel; } public SoundEnvelope(SWFInputStream input) throws IOException { pos44 = input.readUnsignedInt(); leftLevel = input.readUnsignedShort(); rightLevel = input.readUnsignedShort(); } public void write(SWFOutputStream swf) throws IOException { swf.writeUnsignedInt(pos44); swf.writeUnsignedShort(leftLevel); swf.writeUnsignedShort(rightLevel); } public String toString() { return "SoundEnvelope pos44: " + pos44 + ", level(L,R): " + leftLevel + ", " + rightLevel; } } src/main/java/org/freehep/graphicsio/swf/PlaceObject2.java0000644000175000017500000001215611343262531022777 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.AffineTransform; import java.io.IOException; import java.util.Vector; /** * PlaceObject2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: PlaceObject2.java 8584 2006-08-10 23:06:37Z duns $ */ public class PlaceObject2 extends ControlTag { private boolean move; private int depth; private int character = -1; private AffineTransform matrix = null; private ColorXform cxform = null; private int ratio = -1; private String name = null; private int clipDepth = -1; private ClipEventFlags allEventFlags = null; private Vector clipActionRecords = null; public PlaceObject2(int id, int depth, AffineTransform matrix) { this(false, depth, id, matrix, null, 0, null, 0); } public PlaceObject2(int id, int depth, AffineTransform matrix, int clipDepth) { this(false, depth, id, matrix, null, 0, null, clipDepth); } public PlaceObject2(boolean move, int depth, int id, AffineTransform matrix, ColorXform cxform, int ratio, String name, int clipDepth) { this(); this.move = move; this.depth = depth; character = id; this.matrix = matrix; this.cxform = cxform; this.ratio = ratio; this.name = name; this.clipDepth = clipDepth; } public PlaceObject2() { super(26, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { PlaceObject2 tag = new PlaceObject2(); boolean hasClipActions = swf.readBitFlag(); boolean hasClipDepth = swf.readBitFlag(); boolean hasName = swf.readBitFlag(); boolean hasRatio = swf.readBitFlag(); boolean hasColorXform = swf.readBitFlag(); boolean hasMatrix = swf.readBitFlag(); boolean hasCharacter = swf.readBitFlag(); move = swf.readBitFlag(); tag.depth = swf.readUnsignedShort(); if (hasCharacter) tag.character = swf.readUnsignedShort(); if (hasMatrix) tag.matrix = swf.readMatrix(); if (hasColorXform) tag.cxform = new ColorXform(swf, true); if (hasRatio) tag.ratio = swf.readUnsignedShort(); if (hasName) tag.name = swf.readString(); if (hasClipDepth) tag.clipDepth = swf.readUnsignedShort(); if (hasClipActions) { swf.readUnsignedShort(); // always 0 tag.allEventFlags = new ClipEventFlags(swf); tag.clipActionRecords = new Vector(); ClipActionRecord clipActionRecord = new ClipActionRecord(swf); while (clipActionRecord.isEndRecord()) { tag.clipActionRecords.add(clipActionRecord); clipActionRecord = new ClipActionRecord(swf); } } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeBitFlag(allEventFlags != null); swf.writeBitFlag(clipDepth > 0); swf.writeBitFlag(name != null); swf.writeBitFlag(ratio >= 0); swf.writeBitFlag(cxform != null); swf.writeBitFlag(matrix != null); swf.writeBitFlag(character >= 0); swf.writeBitFlag(move); swf.writeUnsignedShort(depth); if (character >= 0) swf.writeUnsignedShort(character); if (matrix != null) swf.writeMatrix(matrix); if (cxform != null) cxform.write(swf, true); if (ratio >= 0) swf.writeUnsignedShort(ratio); if (name != null) swf.writeString(name); if (clipDepth > 0) swf.writeUnsignedShort(clipDepth); if (allEventFlags != null) { swf.writeUnsignedShort(0); // always 0 allEventFlags.write(swf); for (int i = 0; i < clipActionRecords.size(); i++) { ClipActionRecord clipActionRecord = (ClipActionRecord) clipActionRecords .get(i); clipActionRecord.write(swf); } swf.writeUnsignedInt(0); // end } } public String toString() { StringBuffer s = new StringBuffer(super.toString() + "\n"); if (move) s.append(" move\n"); s.append(" depth: " + depth + "\n"); if (character >= 0) s.append(" character: " + character + "\n"); if (matrix != null) s.append(" matrix: " + matrix + "\n"); if (cxform != null) s.append(" xform: " + cxform + "\n"); if (ratio >= 0) s.append(" ratio: " + ratio + "\n"); if (name != null) s.append(" name: " + name + "\n"); if (clipDepth > 0) s.append(" clipDepth: " + clipDepth + "\n"); if (allEventFlags != null) { s.append(" allEventFlags: " + allEventFlags + "\n"); for (int i = 0; i < clipActionRecords.size(); i++) { s.append(" " + clipActionRecords.get(i) + "\n"); } } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineVideoStream.java0000644000175000017500000000152011343262531024070 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineVideoStream TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineVideoStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineVideoStream extends DefinitionTag { private byte[] data; public DefineVideoStream() { super(60, 6); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineVideoStream tag = new DefineVideoStream(); tag.data = swf.readByte(len); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeByte(data); } public String toString() { return super.toString() + "\n" + " length: " + data.length + "\n"; } } src/main/java/org/freehep/graphicsio/swf/DefineBitsLossless2.java0000644000175000017500000000236211343262531024366 0ustar user03user03// Copyright 2001-2003, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.Image; import java.awt.image.ImageObserver; import java.awt.image.RenderedImage; import java.io.IOException; import org.freehep.util.images.ImageUtilities; /** * DefineBitsLossless2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineBitsLossless2.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineBitsLossless2 extends DefineBitsLossless { public DefineBitsLossless2(int id, Image image, Color bkg, ImageObserver observer) { this(id, ImageUtilities.createRenderedImage(image, observer, bkg), bkg); } public DefineBitsLossless2(int id, RenderedImage image, Color bkg) { this(); character = id; this.image = image; this.bkg = bkg; } public DefineBitsLossless2() { super(36, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineBitsLossless2 tag = new DefineBitsLossless2(); tag.read(tagID, swf, len, true); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { write(tagID, swf, true); } } src/main/java/org/freehep/graphicsio/swf/DefineButton.java0000644000175000017500000000452311343262531023127 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.Action; /** * DefineButton TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineButton.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineButton extends DefinitionTag { private int character; private Vector buttons; private Vector actions; public DefineButton(int id, Vector buttons, Vector actions) { this(); character = id; this.buttons = buttons; this.actions = actions; } public DefineButton() { super(7, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineButton tag = new DefineButton(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.buttons = new Vector(); ButtonRecord record = new ButtonRecord(swf, false); while (!record.isEndRecord()) { tag.buttons.add(record); record = new ButtonRecord(swf, false); } tag.actions = new Vector(); Action action = swf.readAction(); while (action != null) { tag.actions.add(action); action = swf.readAction(); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); for (int i = 0; i < buttons.size(); i++) { ButtonRecord b = (ButtonRecord) buttons.get(i); b.write(swf); } swf.writeUnsignedByte(0); for (int i = 0; i < actions.size(); i++) { Action a = (Action) actions.get(i); swf.writeAction(a); } swf.writeAction(null); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); for (int i = 0; i < buttons.size(); i++) { s.append(" "); s.append(buttons.get(i)); s.append("\n"); } for (int i = 0; i < actions.size(); i++) { s.append(" "); s.append(actions.get(i)); s.append("\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFTag.java0000644000175000017500000000202711343262531021631 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import org.freehep.util.io.Tag; import org.freehep.util.io.TaggedInputStream; import org.freehep.util.io.TaggedOutputStream; /** * SWF Tag, superclass of all SWF Tags. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFTag.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class SWFTag extends Tag implements SWFConstants { protected SWFTag(int tagID, int version) { super(tagID, version); } public Tag read(int tagID, TaggedInputStream input, int len) throws IOException { return read(tagID, (SWFInputStream) input, len); } public abstract SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException; public void write(int tagID, TaggedOutputStream output) throws IOException { write(tagID, (SWFOutputStream) output); } public void write(int tagID, SWFOutputStream swf) throws IOException { // empty } } src/main/java/org/freehep/graphicsio/swf/SWFDictionary.java0000644000175000017500000000177311343262531023232 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.util.Enumeration; import java.util.Hashtable; /** * SWF Definition Dictionary, which stores definitions being read from a stream. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFDictionary.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFDictionary extends Hashtable { public void put(int id, DefinitionTag tag) { put(new Integer(id), tag); } public DefinitionTag get(int id) { return (DefinitionTag) get(new Integer(id)); } public void remove(int id) { remove(new Integer(id)); } public String toString() { StringBuffer s = new StringBuffer("SWF Dictionary\n"); for (Enumeration e = keys(); e.hasMoreElements();) { Integer key = (Integer) e.nextElement(); s.append(" [" + key.intValue() + "] "); s.append(get(key)); s.append("\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineFontInfo2.java0000644000175000017500000000457511343262531023467 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineFontInfo2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineFontInfo2.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineFontInfo2 extends DefineFontInfo { int languageCode; public DefineFontInfo2(int fontID, String name, boolean italic, boolean bold, int languageCode, int[] codes) { super(fontID, name, false, false, italic, bold, true, codes); this.languageCode = languageCode; } public DefineFontInfo2() { super(62, 6); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineFontInfo2 tag = new DefineFontInfo2(); tag.fontID = swf.readUnsignedShort(); // associate this fontinfo with font DefineFont font = (DefineFont) swf.getDictionary().get(tag.fontID); int numGlyphs = font.getGlyphCount(); font.setFontInfo(tag); /* int nameLength = */ swf.readUnsignedByte(); tag.name = swf.readUTF(); /* int reserved = (int) */ swf.readUBits(3); tag.shiftJIS = swf.readBitFlag(); tag.ansi = swf.readBitFlag(); tag.italic = swf.readBitFlag(); tag.bold = swf.readBitFlag(); tag.wideCodes = swf.readBitFlag(); tag.languageCode = swf.readLanguageCode(); tag.codes = swf.readUnsignedShort(numGlyphs); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(fontID); swf.writeUnsignedByte(name.length()); swf.writeUTF(name); swf.writeUBits(0, 3); swf.writeBitFlag(false); swf.writeBitFlag(false); swf.writeBitFlag(italic); swf.writeBitFlag(bold); swf.writeBitFlag(true); swf.writeLanguageCode(languageCode); swf.writeUnsignedShort(codes); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" name: " + name + "\n"); s.append(" numGlyphs: " + codes.length + "\n"); s.append(" "); for (int i = 0; i < codes.length; i++) { s.append("[" + codes[i] + ",'" + ((char) codes[i]) + "'] "); } s.append("\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFPathConstructor.java0000644000175000017500000000441611343262531024264 0ustar user03user03// Copyright 2001-2004 FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.graphicsio.CubicToQuadPathConstructor; /** * @author Mark Donszelmann * @version $Id: SWFPathConstructor.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFPathConstructor extends CubicToQuadPathConstructor implements SWFConstants { private Vector path; // to avoid rounding errors we keep all values in TWIPS. private int x0, y0; private int xc, yc; private int stroke, fill0, fill1; public SWFPathConstructor(Vector path, int stroke, int fill0, int fill1) { // resolution equals .5 twips this(path, stroke, fill0, fill1, 0.5 / TWIPS); } public SWFPathConstructor(Vector path, int stroke, int fill0, int fill1, double resolution) { super(resolution); this.path = path; this.stroke = stroke; this.fill0 = fill0; this.fill1 = fill1; } public void move(double x, double y) throws IOException { x0 = toInt(x); y0 = toInt(y); xc = x0; yc = y0; path.add(new SWFShape.ShapeRecord(true, xc, yc, fill0, fill1, stroke)); super.move(x, y); } public void line(double x, double y) throws IOException { int dx = toInt(x) - xc; int dy = toInt(y) - yc; path.add(new SWFShape.EdgeRecord(dx, dy)); xc += dx; yc += dy; super.line(x, y); } public void quad(double x1, double y1, double x2, double y2) throws IOException { int cdx = toInt(x1) - xc; int cdy = toInt(y1) - yc; int dx = toInt(x2 - x1); int dy = toInt(y2 - y1); path.add(new SWFShape.EdgeRecord(cdx, cdy, dx, dy)); xc += dx + cdx; yc += dy + cdy; // important for cubic method currentX = x2; currentY = y2; } public void closePath(double xd0, double yd0) throws IOException { if ((xc != x0) || (yc != y0)) { // due to rounding we may miss the closing, so we do it by hand path.add(new SWFShape.EdgeRecord(x0 - xc, y0 - yc)); } super.closePath(xd0, yd0); } private int toInt(double d) { return (int) (d * TWIPS); } } src/main/java/org/freehep/graphicsio/swf/DefineBitsJPEG3.java0000644000175000017500000000760211343262531023307 0ustar user03user03// Copyright 2001-2007, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.image.RenderedImage; import java.awt.image.WritableRaster; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Properties; import java.util.zip.InflaterInputStream; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.ImageConstants; import org.freehep.util.images.ImageUtilities; /** * DefineBitsJPEG3 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineBitsJPEG3.java 10269 2007-01-09 00:32:55Z duns $ */ public class DefineBitsJPEG3 extends DefineBitsJPEG2 { public DefineBitsJPEG3(int id, Image image, Properties options, Color bkg, ImageObserver observer) { this(id, ImageUtilities.createRenderedImage(image, observer, bkg), bkg, options); } public DefineBitsJPEG3(int id, RenderedImage image, Color bkg, Properties options) { this(); character = id; this.image = image; this.options = options; } public DefineBitsJPEG3() { super(35, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineBitsJPEG3 tag = new DefineBitsJPEG3(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); int jpegLen = (int) swf.readUnsignedInt(); byte[] data = swf.readByte(jpegLen); ByteArrayInputStream bais = new ByteArrayInputStream(data); BufferedImage bi = ImageGraphics2D.readImage(ImageConstants.JPG.toLowerCase(), bais); if (bais.available() > 0) System.err.println("DefineBitsJPEG3: not all bytes read: " + bais.available()); int width = bi.getWidth(); int height = bi.getHeight(); InflaterInputStream zip = new InflaterInputStream(swf); byte[] alpha = new byte[width * height]; zip.read(alpha); WritableRaster raster = bi.getAlphaRaster(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { raster.setPixel(x, y, new int[] { alpha[y * width + x] }); } } tag.image = bi; return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUnsignedInt(imageLength); swf.write(getImageBytes()); } public int getLength() throws IOException { return getImageBytes().length + 2; } private byte[] imageBytes; private int imageLength; private byte[] getImageBytes() throws IOException { if (imageBytes == null) { // calculate jpg bytes byte[] jpgBytes = ImageGraphics2D.toByteArray( image, ImageConstants.JPG, null, null); imageLength = jpgBytes.length; // calculate raw bytes byte[] rawBytes = ImageGraphics2D.toByteArray( image, ImageConstants.RAW, ImageConstants.ENCODING_FLATE, ImageGraphics2D.getRAWProperties(Color.black, ImageConstants.COLOR_MODEL_A)); // write jpgBytes and rawBytes into the imageBytes imageBytes = new byte[jpgBytes.length + rawBytes.length]; System.arraycopy(jpgBytes, 0, imageBytes, 0, jpgBytes.length); System.arraycopy(rawBytes, 0, imageBytes, jpgBytes.length, rawBytes.length); } return imageBytes; } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" image: " + image + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineFontInfo.java0000644000175000017500000000615411343262531023400 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineFontInfo TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineFontInfo.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineFontInfo extends DefinitionTag { protected int fontID; protected String name; protected boolean shiftJIS, ansi; protected boolean italic, bold; protected boolean wideCodes; protected int[] codes; public DefineFontInfo(int fontID, String name, boolean shiftJIS, boolean ansi, boolean italic, boolean bold, boolean wideCodes, int[] codes) { this(); this.fontID = fontID; this.name = name; this.shiftJIS = shiftJIS; this.ansi = ansi; this.italic = italic; this.bold = bold; this.wideCodes = wideCodes; this.codes = codes; } public DefineFontInfo() { super(13, 1); } protected DefineFontInfo(int code, int version) { super(code, version); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineFontInfo tag = new DefineFontInfo(); tag.fontID = swf.readUnsignedShort(); // associate this fontinfo with font DefineFont font = (DefineFont) swf.getDictionary().get(tag.fontID); int numGlyphs = font.getGlyphCount(); font.setFontInfo(tag); int nameLength = swf.readUnsignedByte(); if (swf.getVersion() >= 6) { tag.name = swf.readUTF(); } else { tag.name = new String(swf.readByte(nameLength)); } /* int reserved = (int) */ swf.readUBits(3); tag.shiftJIS = swf.readBitFlag(); tag.ansi = swf.readBitFlag(); tag.italic = swf.readBitFlag(); tag.bold = swf.readBitFlag(); tag.wideCodes = swf.readBitFlag(); tag.codes = (tag.wideCodes) ? swf.readUnsignedShort(numGlyphs) : swf .readUnsignedByte(numGlyphs); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(fontID); swf.writeUnsignedByte(name.length()); if (swf.getVersion() >= 6) { swf.writeUTF(name); } else { swf.writeByte(name.getBytes()); } swf.writeUBits(0, 3); swf.writeBitFlag(shiftJIS); swf.writeBitFlag(ansi); swf.writeBitFlag(italic); swf.writeBitFlag(bold); swf.writeBitFlag(wideCodes); if (wideCodes) { swf.writeUnsignedShort(codes); } else { swf.writeUnsignedByte(codes); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" name: " + name + "\n"); s.append(" numGlyphs: " + codes.length + "\n"); s.append(" "); for (int i = 0; i < codes.length; i++) { s.append("[" + codes[i] + ",'" + ((char) codes[i]) + "'] "); } s.append("\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFShape.java0000644000175000017500000003276411343262531022171 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.BitOutputStream; /** * Shape TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFShape.java 9979 2006-11-27 22:51:07Z duns $ */ public class SWFShape { private int numFillBits; private int numLineBits; protected FillStyleArray fillStyles; protected LineStyleArray lineStyles; private Vector records; public SWFShape(Vector records) { this.records = records; } // for font shapes public SWFShape(SWFInputStream input) throws IOException { this(input, null, null, false, false, false); } public SWFShape(SWFInputStream input, FillStyleArray fillStyles, LineStyleArray lineStyles, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { this.fillStyles = fillStyles; this.lineStyles = lineStyles; input.byteAlign(); numFillBits = (int) input.readUBits(4); numLineBits = (int) input.readUBits(4); records = new Vector(); boolean endOfShape = false; do { boolean edge = input.readBitFlag(); if (edge) { // Edge Record records.add(new EdgeRecord(input)); } else { // Shape Record int state = (int) input.readUBits(5); if (state == 0) { endOfShape = true; } else { records.add(new ShapeRecord(this, input, numFillBits, numLineBits, isMorphStyle, hasAlpha, hasStyles, state)); } } } while (!endOfShape); } // for font shapes public void write(SWFOutputStream swf) throws IOException { write(swf, false, false, false); // FIXME, false for hasStyles is a guess. } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { swf.byteAlign(); int numFillBits = 0; int numLineBits = 0; for (int i = 0; i < records.size(); i++) { Record r = (Record) records.get(i); if (r instanceof ShapeRecord) { ShapeRecord s = (ShapeRecord) r; numFillBits = Math.max(numFillBits, s.getNumFillBits()); numLineBits = Math.max(numLineBits, s.getNumLineBits()); } } swf.writeUBits(numFillBits, 4); swf.writeUBits(numLineBits, 4); for (int i = 0; i < records.size(); i++) { Record r = (Record) records.get(i); r.write(swf, numFillBits, numLineBits, isMorphStyle, hasAlpha, hasStyles); } swf.writeUBits(0, 6); // End of Shape swf.byteAlign(); // make sure any offset calculations will be correct } void setNumFillBits(int numFillBits) { this.numFillBits = numFillBits; } void setNumLineBits(int numLineBits) { this.numLineBits = numLineBits; } void setFillStyles(FillStyleArray fillStyles) { this.fillStyles = fillStyles; } void setLineStyles(LineStyleArray lineStyles) { this.lineStyles = lineStyles; } public String toString() { StringBuffer s = new StringBuffer(); for (int i = 0; i < records.size(); i++) { s.append(" "); s.append(i); s.append(":"); s.append(records.get(i)); s.append("\n"); } s.append(" End of shape\n"); return s.toString(); } /** * Abstract superclass for Records. */ public static abstract class Record { public abstract void write(SWFOutputStream swf, int numFillBits, int numLineBits, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException; } /** * Shape Record, specifying style, move, ... */ public static class ShapeRecord extends Record { private static final int MOVE = 0x01; private static final int FILLSTYLE0 = 0x02; private static final int FILLSTYLE1 = 0x04; private static final int LINESTYLE = 0x08; private static final int NEWSTYLES = 0x10; private boolean move; private int moveX = 0; private int moveY = 0; private int fillStyle0 = -1; private int fillStyle1 = -1; private int lineStyle = -1; private FillStyleArray newFillStyles; private LineStyleArray newLineStyles; public ShapeRecord(boolean move, int moveX, int moveY, int fillStyle0, int fillStyle1, int lineStyle) { this.move = move; this.moveX = moveX; this.moveY = moveY; this.fillStyle0 = fillStyle0; this.fillStyle1 = fillStyle1; this.lineStyle = lineStyle; } ShapeRecord(SWFShape shape, SWFInputStream input, int numFillBits, int numLineBits, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles, int state) throws IOException { if ((state & MOVE) > 0) { move = true; int numMoveBits = (int) input.readUBits(5); moveX = (int) input.readSBits(numMoveBits); moveY = (int) input.readSBits(numMoveBits); } if ((state & FILLSTYLE0) > 0) fillStyle0 = (int) input.readUBits(numFillBits); if ((state & FILLSTYLE1) > 0) fillStyle1 = (int) input.readUBits(numFillBits); if ((state & LINESTYLE) > 0) lineStyle = (int) input.readUBits(numLineBits); if ((state & NEWSTYLES) > 0) { newFillStyles = new FillStyleArray(input, isMorphStyle, hasAlpha); shape.setFillStyles(newFillStyles); newLineStyles = new LineStyleArray(input, isMorphStyle, hasAlpha, hasStyles); shape.setLineStyles(newLineStyles); numFillBits = (int) input.readUBits(4); shape.setNumFillBits(numFillBits); numLineBits = (int) input.readUBits(4); shape.setNumLineBits(numLineBits); } } public void write(SWFOutputStream swf, int numFillBits, int numLineBits, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { int state = 0x00; if (newFillStyles != null) state |= NEWSTYLES; if (lineStyle != -1) state |= LINESTYLE; if (fillStyle1 != -1) state |= FILLSTYLE1; if (fillStyle0 != -1) state |= FILLSTYLE0; if (move) state |= MOVE; swf.writeUBits(state, 6); if (move) { int numMoveBits = Math.max(BitOutputStream.minBits(moveX, true), BitOutputStream .minBits(moveY, true)); swf.writeUBits(numMoveBits, 5); swf.writeSBits(moveX, numMoveBits); swf.writeSBits(moveY, numMoveBits); } if (fillStyle0 != -1) swf.writeUBits(fillStyle0, numFillBits); if (fillStyle1 != -1) swf.writeUBits(fillStyle1, numFillBits); if (lineStyle != -1) swf.writeUBits(lineStyle, numLineBits); if (newFillStyles != null) { newFillStyles.write(swf, isMorphStyle, hasAlpha); newLineStyles.write(swf, isMorphStyle, hasAlpha, hasStyles); swf.writeUBits(numFillBits, 4); swf.writeUBits(numLineBits, 4); } } public int getNumFillBits() { int numFillBits = 0; if (fillStyle0 != -1) numFillBits = Math.max(numFillBits, BitOutputStream .minBits(fillStyle0)); if (fillStyle1 != -1) numFillBits = Math.max(numFillBits, BitOutputStream .minBits(fillStyle1)); return numFillBits; } public int getNumLineBits() { return (lineStyle != -1) ? BitOutputStream.minBits(lineStyle) : 0; } public String toString() { StringBuffer s = new StringBuffer(); if (move) s.append("moveto(" + moveX + ", " + moveY + "); "); if (fillStyle0 != -1) s.append("fillStyle0=" + fillStyle0 + "; "); if (fillStyle1 != -1) s.append("fillStyle1=" + fillStyle1 + "; "); if (lineStyle != -1) s.append("lineStyle=" + lineStyle + "; "); if ((newFillStyles != null) || (newLineStyles != null)) s.append("More Styles;\n"); if (newFillStyles != null) s.append(newFillStyles.toString()); if (newLineStyles != null) s.append(newLineStyles.toString()); return s.toString(); } } /** * Edge Record, specifying lines, curves, ... */ public static class EdgeRecord extends Record { boolean curve; int controlDeltaX, controlDeltaY, anchorDeltaX, anchorDeltaY; int deltaX, deltaY; public EdgeRecord(int controlDeltaX, int controlDeltaY, int anchorDeltaX, int anchorDeltaY) { curve = true; this.controlDeltaX = controlDeltaX; this.controlDeltaY = controlDeltaY; this.anchorDeltaX = anchorDeltaX; this.anchorDeltaY = anchorDeltaY; } public EdgeRecord(int deltaX, int deltaY) { curve = false; this.deltaX = deltaX; this.deltaY = deltaY; } EdgeRecord(SWFInputStream input) throws IOException { curve = !input.readBitFlag(); int numBits = (int) input.readUBits(4) + 2; if (curve) { controlDeltaX = (int) input.readSBits(numBits); controlDeltaY = (int) input.readSBits(numBits); anchorDeltaX = (int) input.readSBits(numBits); anchorDeltaY = (int) input.readSBits(numBits); } else { if (input.readBitFlag()) { // general line deltaX = (int) input.readSBits(numBits); deltaY = (int) input.readSBits(numBits); } else { if (input.readBitFlag()) { // vertical deltaX = 0; deltaY = (int) input.readSBits(numBits); } else { // horizontal deltaX = (int) input.readSBits(numBits); deltaY = 0; } } } } public void write(SWFOutputStream swf, int numFillBits, int numLineBits, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { swf.writeBitFlag(true); swf.writeBitFlag(!curve); int numBits = 0; if (curve) { numBits = Math.max(numBits, BitOutputStream.minBits(controlDeltaX, true)); numBits = Math.max(numBits, BitOutputStream.minBits(controlDeltaY, true)); numBits = Math.max(numBits, BitOutputStream.minBits(anchorDeltaX, true)); numBits = Math.max(numBits, BitOutputStream.minBits(anchorDeltaY, true)); } else { if ((deltaX != 0) && (deltaY != 0)) { numBits = Math.max(numBits, BitOutputStream.minBits(deltaX, true)); numBits = Math.max(numBits, BitOutputStream.minBits(deltaY, true)); } else { if (deltaX == 0) { // vertical numBits = Math.max(numBits, BitOutputStream.minBits(deltaY, true)); } else { // horizontal numBits = Math.max(numBits, BitOutputStream.minBits(deltaX, true)); } } } swf.writeUBits(numBits - 2, 4); if (curve) { swf.writeSBits(controlDeltaX, numBits); swf.writeSBits(controlDeltaY, numBits); swf.writeSBits(anchorDeltaX, numBits); swf.writeSBits(anchorDeltaY, numBits); } else { if ((deltaX != 0) && (deltaY != 0)) { // general line swf.writeBitFlag(true); swf.writeSBits(deltaX, numBits); swf.writeSBits(deltaY, numBits); } else { swf.writeBitFlag(false); if (deltaX == 0) { // vertical swf.writeBitFlag(true); swf.writeSBits(deltaY, numBits); } else { // horizontal swf.writeBitFlag(false); swf.writeSBits(deltaX, numBits); } } } } public String toString() { if (curve) { return "rcurveto(" + controlDeltaX + ", " + controlDeltaY + ", " + anchorDeltaX + ", " + anchorDeltaY + ")"; } else { return "rlineto(" + deltaX + ", " + deltaY + ")"; } } } } src/main/java/org/freehep/graphicsio/swf/VideoFrame.java0000644000175000017500000000144611343262531022563 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * VideoFrame TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: VideoFrame.java 8584 2006-08-10 23:06:37Z duns $ */ public class VideoFrame extends DefinitionTag { private byte[] data; public VideoFrame() { super(61, 6); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { VideoFrame tag = new VideoFrame(); tag.data = swf.readByte(len); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeByte(data); } public String toString() { return super.toString() + "\n" + " length: " + data.length + "\n"; } } src/main/java/org/freehep/graphicsio/swf/ShowFrame.java0000644000175000017500000000072211343262531022431 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * ShowFrame TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ShowFrame.java 8584 2006-08-10 23:06:37Z duns $ */ public class ShowFrame extends ControlTag { public ShowFrame() { super(1, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { return this; } } src/main/java/org/freehep/graphicsio/swf/DoAction.java0000644000175000017500000000257411343262531022245 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.Action; /** * DoAction TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DoAction.java 8584 2006-08-10 23:06:37Z duns $ */ public class DoAction extends ControlTag { private Vector actions; public DoAction(Vector actions) { this(); this.actions = actions; } public DoAction() { super(12, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DoAction tag = new DoAction(); tag.actions = new Vector(); Action action = swf.readAction(); while (action != null) { tag.actions.add(action); action = swf.readAction(); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { for (int i = 0; i < actions.size(); i++) { Action a = (Action) actions.get(i); swf.writeAction(a); } swf.writeAction(null); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); for (int i = 0; i < actions.size(); i++) { s.append(" " + actions.get(i) + "\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/EnableDebugger2.java0000644000175000017500000000231511343262531023453 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * EnableDebugger TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: EnableDebugger2.java 8584 2006-08-10 23:06:37Z duns $ */ public class EnableDebugger2 extends ControlTag { private String password; public EnableDebugger2(String password) { this(); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] b = md5.digest(password.getBytes()); this.password = new String(b); } catch (NoSuchAlgorithmException nsae) { this.password = password; } } public EnableDebugger2() { super(64, 6); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { EnableDebugger2 tag = new EnableDebugger2(); swf.readUnsignedShort(); tag.password = swf.readString(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(0); swf.writeString(password); } } src/main/java/org/freehep/graphicsio/swf/DefineShape.java0000644000175000017500000000464311343262531022717 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineShape TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineShape.java 9979 2006-11-27 22:51:07Z duns $ */ public class DefineShape extends DefinitionTag { protected int character; protected Rectangle2D bounds; protected FillStyleArray fillStyles; protected LineStyleArray lineStyles; protected SWFShape shape; public DefineShape(int id, Rectangle2D bounds, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape shape) { this(); character = id; this.bounds = bounds; this.fillStyles = fillStyles; this.lineStyles = lineStyles; this.shape = shape; } public DefineShape() { super(2, 1); } protected DefineShape(int tagID, int version) { super(tagID, version); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineShape tag = new DefineShape(); tag.read(tagID, swf, false); return tag; } protected void read(int tagID, SWFInputStream swf, boolean hasAlpha) throws IOException { character = swf.readUnsignedShort(); swf.getDictionary().put(character, this); bounds = swf.readRect(); fillStyles = new FillStyleArray(swf, false, hasAlpha); lineStyles = new LineStyleArray(swf, false, hasAlpha, false); shape = new SWFShape(swf, fillStyles, lineStyles, false, hasAlpha, false); } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf, false); } public void write(SWFOutputStream swf, boolean hasAlpha) throws IOException { swf.writeUnsignedShort(character); swf.writeRect(bounds); fillStyles.write(swf, false, hasAlpha); lineStyles.write(swf, false, hasAlpha, false); shape.write(swf, false, hasAlpha, false); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(fillStyles.toString()); s.append(lineStyles.toString()); s.append(" shape: \n"); s.append((shape != null) ? shape.toString() : "null"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/ImportAssets.java0000644000175000017500000000252511343262531023176 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * ImportAssets TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ImportAssets.java 8584 2006-08-10 23:06:37Z duns $ */ public class ImportAssets extends ControlTag { private String url; private int[] tags; private String[] assets; public ImportAssets(String url, int[] tags, String[] assets) { this(); this.url = url; this.tags = tags; this.assets = assets; } public ImportAssets() { super(57, 5); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { ImportAssets tag = new ImportAssets(); tag.url = swf.readString(); int n = swf.readUnsignedShort(); tag.tags = new int[n]; tag.assets = new String[n]; for (int i = 0; i < n; i++) { tag.tags[i] = swf.readUnsignedShort(); tag.assets[i] = swf.readString(); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeString(url); swf.writeUnsignedShort(tags.length); for (int i = 0; i < tags.length; i++) { swf.writeUnsignedShort(tags[i]); swf.writeString(assets[i]); } } } src/main/java/org/freehep/graphicsio/swf/RemoveObject2.java0000644000175000017500000000161611343262531023207 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * RemoveObject2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: RemoveObject2.java 8584 2006-08-10 23:06:37Z duns $ */ public class RemoveObject2 extends ControlTag { private int depth; public RemoveObject2(int depth) { this(); this.depth = depth; } public RemoveObject2() { super(28, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { RemoveObject2 tag = new RemoveObject2(); tag.depth = swf.readUnsignedShort(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(depth); } public String toString() { return super.toString() + "\n" + " depth: " + depth; } } src/main/java/org/freehep/graphicsio/swf/DefineBits.java0000644000175000017500000000222611343262531022553 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineBits TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineBits.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineBits extends DefinitionTag { private int character; private byte[] data; // private BufferedImage image; public DefineBits() { super(6, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineBits tag = new DefineBits(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.data = swf.readByte(len - 2); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeByte(data); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" length: " + data.length + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineMovie.java0000644000175000017500000000233511343262531022732 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineMovie TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineMovie.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineMovie extends DefinitionTag { private int character; private String name; public DefineMovie(int id, String name) { this(); character = id; this.name = name; } public DefineMovie() { super(38, 4); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineMovie tag = new DefineMovie(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.name = swf.readString(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeString(name); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" name: " + name); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineFont.java0000644000175000017500000000473411343262531022566 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * DefineFont TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineFont.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineFont extends DefinitionTag { private int character; private List /* SWFShape */shapes; private DefineFontInfo info; public DefineFont(int id) { this(); character = id; this.shapes = new ArrayList(); } public void add(SWFShape shape) { shapes.add(shape); } public DefineFont() { super(10, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineFont tag = new DefineFont(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); int offset0 = swf.readUnsignedShort(); int glyphCount = offset0 / 2; // read offsets but ignore them int[] offsets = new int[glyphCount]; offsets[0] = offset0; for (int i = 1; i < glyphCount; i++) { offsets[i] = swf.readUnsignedShort(); } tag.shapes = new ArrayList(); for (int i = 0; i < glyphCount; i++) { tag.shapes.add(new SWFShape(swf)); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.pushBuffer(); int[] offsets = new int[shapes.size()]; for (int i = 0; i < shapes.size(); i++) { offsets[i] = swf.getBufferLength(); ((SWFShape) shapes.get(i)).write(swf); } swf.popBuffer(); for (int i = 0; i < shapes.size(); i++) { swf.writeUnsignedShort(shapes.size() * 2 + offsets[i]); } swf.append(); } public int getGlyphCount() { return shapes.size(); } public void setFontInfo(DefineFontInfo info) { this.info = info; } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" glyphcount: " + shapes.size() + "\n"); for (int i = 0; i < shapes.size(); i++) { s.append(shapes.get(i) + "\n"); } s.append(" fontInfo: " + info + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineFont2.java0000644000175000017500000003022211343262531022637 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineFont2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @author Steve Hannah * @version $Id: DefineFont2.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineFont2 extends DefinitionTag implements SWFConstants { private int character; private boolean shiftJIS = false; private boolean ansi = false; private boolean wideOffsets = false; private boolean wideCodes = false; private boolean italic = false; private boolean bold = false; private int languageCode; private String name; private long[] offsets; private long codeOffset; private SWFShape[] shapes; private int[] codes; private int ascent, descent, leading; private short[] advances; private Rectangle2D[] bounds; private KerningRecord[] kerning = new KerningRecord[0]; public DefineFont2() { super(48, 3); } public DefineFont2(int character, boolean italic, boolean bold, String name, SWFShape[] shapes, int[] codes) { this(character, false, false, italic, bold, true, true, LANGUAGE_LATIN, name, shapes, codes, 0, 0, 0, null, null, null); } public DefineFont2(int character, boolean shiftJIS, boolean ansi, boolean italic, boolean bold, boolean wideOffsets, boolean wideCodes, int languageCode, String name, SWFShape[] shapes, int[] codes, int ascent, int descent, int leading, short[] advances, Rectangle2D[] bounds, KerningRecord[] kerning) { this(); this.character = character; this.shiftJIS = shiftJIS; this.ansi = ansi; this.italic = italic; this.bold = bold; this.wideOffsets = wideOffsets; this.wideCodes = wideCodes; this.languageCode = languageCode; this.name = name; this.shapes = shapes; this.codes = codes; this.ascent = ascent; this.descent = descent; this.leading = leading; this.advances = advances; this.bounds = bounds; this.kerning = kerning; } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineFont2 tag = new DefineFont2(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); boolean hasLayout = swf.readBitFlag(); tag.shiftJIS = swf.readBitFlag(); /* boolean reserved = */ swf.readBitFlag(); tag.ansi = swf.readBitFlag(); tag.wideOffsets = swf.readBitFlag(); tag.wideCodes = swf.readBitFlag(); tag.italic = swf.readBitFlag(); tag.bold = swf.readBitFlag(); tag.languageCode = swf.readLanguageCode(); int nameLength = swf.readUnsignedByte(); if (swf.getVersion() >= 6) { tag.name = swf.readUTF(); } else { tag.name = new String(swf.readByte(nameLength)); } int glyphCount = swf.readUnsignedShort(); tag.offsets = new long[glyphCount]; for (int i = 0; i < glyphCount; i++) { tag.offsets[i] = (tag.wideOffsets) ? swf.readUnsignedInt() : (long) swf.readUnsignedShort(); } tag.codeOffset = (tag.wideOffsets) ? swf.readUnsignedInt() : (long) swf .readUnsignedShort(); tag.shapes = new SWFShape[glyphCount]; for (int i = 0; i < glyphCount; i++) { tag.shapes[i] = new SWFShape(swf); } tag.codes = (tag.wideCodes) ? swf.readUnsignedShort(glyphCount) : swf .readUnsignedByte(glyphCount); if (hasLayout) { tag.ascent = swf.readShort(); tag.descent = swf.readShort(); tag.leading = swf.readShort(); tag.advances = swf.readShort(glyphCount); tag.bounds = new Rectangle2D[glyphCount]; for (int i = 0; i < glyphCount; i++) { tag.bounds[i] = swf.readRect(); } int kerningCount = swf.readUnsignedShort(); tag.kerning = new KerningRecord[kerningCount]; for (int i = 0; i < kerningCount; i++) { tag.kerning[i] = new KerningRecord(swf, tag.wideCodes); } } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { boolean hasLayout = (ascent != 0) || (descent != 0) || (leading != 0) || (advances != null) || (bounds != null) || (kerning != null); swf.writeUnsignedShort(character); swf.writeBitFlag(hasLayout); swf.writeBitFlag(shiftJIS); swf.writeUBits(0, 1); // reserved swf.writeBitFlag(ansi); swf.writeBitFlag(wideOffsets); swf.writeBitFlag(wideCodes); swf.writeBitFlag(italic); swf.writeBitFlag(bold); if (swf.getVersion() >= 6) { swf.writeLanguageCode(languageCode); } else { swf.writeUnsignedByte(0); } swf.writeUnsignedByte(name.length()); if (swf.getVersion() >= 6) { swf.writeUTF(name); } else { swf.writeByte(name.getBytes()); } // Shapes swf.pushBuffer(); int[] offsets = new int[shapes.length]; int inc = wideOffsets ? 4 : 2; inc = (offsets.length + 1) * inc; for (int i = 0; i < shapes.length; i++) { offsets[i] = swf.getBufferLength() + inc; shapes[i].write(swf); swf.byteAlign(); } codeOffset = swf.getBufferLength() + inc; swf.popBuffer(); swf.writeUnsignedShort(offsets.length); // Offset Table for (int i = 0; i < offsets.length; i++) { if (wideOffsets) { swf.writeUnsignedInt(offsets[i]); } else { swf.writeUnsignedShort((int) offsets[i]); } } if (wideOffsets) { swf.writeUnsignedInt(codeOffset); } else { swf.writeUnsignedShort((int) codeOffset); } swf.append(); if (wideCodes) { for (int i = 0; i < offsets.length; i++) { swf.writeUnsignedShort(codes[i]); } } else { for (int i = 0; i < offsets.length; i++) { swf.writeUnsignedByte(codes[i]); } } if (hasLayout) { swf.writeShort(ascent); swf.writeShort(descent); swf.writeShort(leading); for (int i = 0; i < offsets.length; i++) { swf.writeShort(advances[i]); } for (int i = 0; i < bounds.length; i++) { swf.writeRect(bounds[i]); } swf.writeUnsignedShort(kerning.length); for (int i = 0; i < kerning.length; i++) { kerning[i].write(swf, wideCodes); } } } public long getId() { return character; } public boolean getShiftJIS() { return shiftJIS; } public boolean isAnsi() { return ansi; } public boolean isItalic() { return italic; } public boolean isBold() { return bold; } public boolean hasWideOffsets() { return wideOffsets; } public boolean hasWideCodes() { return wideCodes; } public String getName() { return name; } public SWFShape[] getShapes() { return shapes; } public int[] getCodes() { return codes; } public int getAscent() { return ascent; } public int getDescent() { return descent; } public int getLeading() { return leading; } public short[] getAdvances() { return advances; } public Rectangle2D[] getBounds() { return bounds; } public KerningRecord[] getKerning() { return kerning; } public void setId(int id) { this.character = id; } public void setShiftJIS(boolean shiftJIS) { this.shiftJIS = shiftJIS; } public void setAnsi(boolean ansi) { this.ansi = ansi; } public void setItalic(boolean italic) { this.italic = italic; } public void setBold(boolean bold) { this.bold = bold; } public void setWideOffsets(boolean wideOffsets) { this.wideOffsets = wideOffsets; } public void setWideCodes(boolean wideCodes) { this.wideCodes = wideCodes; } public void setName(String name) { this.name = name; } public void setCodes(int[] codes) { this.codes = codes; } public void setShapes(SWFShape[] shapes) { this.shapes = shapes; } public void setAscent(int ascent) { this.ascent = ascent; } public void setDescent(int descent) { this.descent = descent; } public void setLeading(int leading) { this.leading = leading; } public void setAdvances(short[] advances) { this.advances = advances; } public void setAdvances(int[] advances) { short[] s = new short[advances.length]; for (int i = 0; i < s.length; i++) { s[i] = (short) advances[i]; } setAdvances(s); } public void setBounds(Rectangle2D[] bounds) { this.bounds = bounds; } public void setKerning(KerningRecord[] kerning) { this.kerning = kerning; } public String toString() { // FIXME: add other stuff... StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" name: " + name + "\n"); if (shiftJIS) s.append(" shiftJIS\n"); if (ansi) s.append(" ansi\n"); if (italic) s.append(" italic\n"); if (bold) s.append(" bold\n"); if (wideOffsets) s.append(" wideOffsets\n"); if (wideCodes) s.append(" wideCodes\n"); if (languageCode > 0) s.append(" languageCode: " + languageCode + "\n"); if (ascent != 0) s.append(" ascent: " + ascent + "\n"); if (descent != 0) s.append(" descent: " + descent + "\n"); if (leading != 0) s.append(" leading: " + leading + "\n"); if (advances != null) { for (int i = 0; i < advances.length; i++) { s.append(" advances[" + i + "]: " + advances[i] + "\n"); } } if (bounds != null) { for (int i = 0; i < bounds.length; i++) { s.append(" bounds[" + i + "]: " + bounds[i] + "\n"); } } s.append(" glyphCount: " + shapes.length + "\n"); for (int i = 0; i < shapes.length; i++) { s.append(" >>> Shape " + i + "\n"); s.append(shapes[i] + "\n"); } return s.toString(); } public static class KerningRecord { private int code1, code2; private int adjustment; public KerningRecord(int code1, int code2, int adjustment) { this.code1 = code1; this.code2 = code2; this.adjustment = adjustment; } public KerningRecord(SWFInputStream input, boolean wideCodes) throws IOException { code1 = (wideCodes) ? input.readUnsignedShort() : input .readUnsignedByte(); code2 = (wideCodes) ? input.readUnsignedShort() : input .readUnsignedByte(); adjustment = input.readShort(); } public void write(SWFOutputStream swf, boolean wideCodes) throws IOException { if (wideCodes) swf.writeUnsignedShort(code1); else swf.writeUnsignedByte(code1); if (wideCodes) swf.writeUnsignedShort(code2); else swf.writeUnsignedByte(code2); swf.writeShort(adjustment); } public String toString() { return "Kerning[" + code1 + ", " + code2 + ", " + adjustment + "]"; } } } src/main/java/org/freehep/graphicsio/swf/FileAttributes.java0000644000175000017500000000236511343262531023471 0ustar user03user03// Copyright 2006, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * FileAttributes TAG. * * @author Mark Donszelmann * @version $Id: DefineBits.java 4973 2005-12-05 00:59:43Z duns $ */ public class FileAttributes extends ControlTag { private boolean hasMetadata; private boolean useNetwork; public FileAttributes() { super(69, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { FileAttributes tag = new FileAttributes(); swf.readUBits(2); tag.hasMetadata = swf.readBitFlag(); swf.readUBits(3); tag.useNetwork = swf.readBitFlag(); swf.readUBits(24); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUBits(0, 2); swf.writeBitFlag(hasMetadata); swf.writeUBits(0, 3); swf.writeBitFlag(useNetwork); swf.writeUBits(0, 24); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" hasMetaData: " + hasMetadata + "\n"); s.append(" useNetwork: " + useNetwork + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineShape4.java0000644000175000017500000000464611343262531023006 0ustar user03user03// Copyright 2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineShape4 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineShape3.java 4973 2005-12-05 00:59:43Z duns $ */ public class DefineShape4 extends DefineShape { protected Rectangle2D edgeBounds; protected boolean usesNonScalingStrokes; protected boolean usesScalingStrokes = true; public DefineShape4(int id, Rectangle2D bounds, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape shape) { this(id, bounds, bounds, false, true, fillStyles, lineStyles, shape); } public DefineShape4(int id, Rectangle2D bounds, Rectangle2D edgeBounds, boolean usesNonScalingStrokes, boolean usesScalingStrokes, FillStyleArray fillStyles, LineStyleArray lineStyles, SWFShape shape) { this(); character = id; this.bounds = bounds; this.edgeBounds = edgeBounds; this.usesNonScalingStrokes = usesNonScalingStrokes; this.usesScalingStrokes = usesScalingStrokes; this.fillStyles = fillStyles; this.lineStyles = lineStyles; this.shape = shape; } public DefineShape4() { super(83, 8); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineShape4 tag = new DefineShape4(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); bounds = swf.readRect(); tag.edgeBounds = swf.readRect(); swf.readUBits(6); tag.usesNonScalingStrokes = swf.readBitFlag(); tag.usesScalingStrokes = swf.readBitFlag(); tag.fillStyles = new FillStyleArray(swf, false, true); tag.lineStyles = new LineStyleArray(swf, false, true, true); tag.shape = new SWFShape(swf, tag.fillStyles, tag.lineStyles, false, true, false); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeRect(bounds); swf.writeRect(edgeBounds); swf.writeUBits(0, 6); swf.writeBitFlag(usesNonScalingStrokes); swf.writeBitFlag(usesScalingStrokes); fillStyles.write(swf, false, true); lineStyles.write(swf, false, true, true); shape.write(swf, false, true, true); } } src/main/java/org/freehep/graphicsio/swf/DefineButtonCxform.java0000644000175000017500000000232511343262531024304 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * DefineButtonCxform TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineButtonCxform.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineButtonCxform extends DefinitionTag { private int character; private ColorXform cxform; public DefineButtonCxform(int id, ColorXform cxform) { this(); character = id; this.cxform = cxform; } public DefineButtonCxform() { super(23, 2); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineButtonCxform tag = new DefineButtonCxform(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.cxform = new ColorXform(swf, false); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); cxform.write(swf, false); } public String toString() { return super.toString() + "\n" + " character: " + character + "\n" + " cxform: " + cxform + "\n"; } } src/main/java/org/freehep/graphicsio/swf/DoInitAction.java0000644000175000017500000000263011343262531023062 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.Action; /** * DoInitAction TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DoInitAction.java 8584 2006-08-10 23:06:37Z duns $ */ public class DoInitAction extends ControlTag { private Vector actions; public DoInitAction(Vector actions) { this(); this.actions = actions; } public DoInitAction() { super(59, 6); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DoInitAction tag = new DoInitAction(); tag.actions = new Vector(); Action action = swf.readAction(); while (action != null) { tag.actions.add(action); action = swf.readAction(); } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { for (int i = 0; i < actions.size(); i++) { Action a = (Action) actions.get(i); swf.writeAction(a); } swf.writeAction(null); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); for (int i = 0; i < actions.size(); i++) { s.append(" " + actions.get(i) + "\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/StartSound.java0000644000175000017500000000207611343262531022650 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * StartSound TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: StartSound.java 8584 2006-08-10 23:06:37Z duns $ */ public class StartSound extends ControlTag { private int character; private SoundInfo info; public StartSound(int id, SoundInfo info) { this(); character = id; this.info = info; } public StartSound() { super(15, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { StartSound tag = new StartSound(); tag.character = swf.readUnsignedShort(); tag.info = new SoundInfo(swf); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); info.write(swf); } public String toString() { return super.toString() + "\n" + " character: " + character + "\n" + " soundinfo: " + info; } } src/main/java/org/freehep/graphicsio/swf/DefineEditText.java0000644000175000017500000000732711343262531023413 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.geom.Rectangle2D; import java.io.IOException; /** * DefineEditText TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineEditText.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineEditText extends DefinitionTag { private int character; private Rectangle2D bounds; private boolean disableEditting; private boolean password; private boolean multiLine; private boolean wordWrap; private boolean drawBox; private boolean disableSelection; private int fontID; private int height; private Color color; private int maxLength = -1; private int alignment; private int leftMargin; private int rightMargin; private int indent; private int lineSpace; private String variable; private String initialText; // FIXME: constructor public DefineEditText() { super(37, 4); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineEditText tag = new DefineEditText(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.bounds = swf.readRect(); int flags = swf.readUnsignedShort(); boolean hasLength = ((flags & 0x0002) > 0); tag.disableEditting = ((flags & 0x0008) > 0); tag.password = ((flags & 0x0010) > 0); tag.multiLine = ((flags & 0x0020) > 0); tag.wordWrap = ((flags & 0x0040) > 0); boolean hasText = ((flags & 0x0080) > 0); tag.drawBox = ((flags & 0x0800) > 0); tag.disableSelection = ((flags & 0x1000) > 0); tag.fontID = swf.readUnsignedShort(); tag.height = swf.readUnsignedShort(); tag.color = swf.readColor(true); if (hasLength) tag.maxLength = swf.readUnsignedShort(); tag.alignment = swf.readUnsignedByte(); tag.leftMargin = swf.readUnsignedShort(); tag.rightMargin = swf.readUnsignedShort(); tag.indent = swf.readUnsignedShort(); tag.lineSpace = swf.readUnsignedShort(); tag.variable = swf.readString(); if (hasText) tag.initialText = swf.readString(); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeRect(bounds); int flags = 0; if (maxLength >= 0) flags |= 0x0002; if (disableEditting) flags |= 0x0008; if (password) flags |= 0x0010; if (multiLine) flags |= 0x0020; if (wordWrap) flags |= 0x0040; if (initialText != null) flags |= 0x0080; if (drawBox) flags |= 0x0800; if (disableSelection) flags |= 0x1000; swf.writeUnsignedShort(flags); swf.writeUnsignedShort(fontID); swf.writeUnsignedShort(height); swf.writeColor(color, true); if (maxLength >= 0) swf.writeUnsignedShort(maxLength); swf.writeUnsignedByte(alignment); swf.writeUnsignedShort(leftMargin); swf.writeUnsignedShort(rightMargin); swf.writeUnsignedShort(indent); swf.writeUnsignedShort(lineSpace); swf.writeString(variable); if (initialText != null) swf.writeString(initialText); } public String toString() { // FIXME: add other stuff... StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" ...\n"); return s.toString(); } }src/main/java/org/freehep/graphicsio/swf/DefineButtonSound.java0000644000175000017500000000400611343262531024134 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.EOFException; import java.io.IOException; /** * DefineButtonSound TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineButtonSound.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineButtonSound extends DefinitionTag { private int character; private int[] soundID; private SoundInfo[] info; public DefineButtonSound(int id, int[] soundID, SoundInfo[] info) { this(); character = id; this.soundID = soundID; this.info = info; } public DefineButtonSound() { super(17, 2); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineButtonSound tag = new DefineButtonSound(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.soundID = new int[4]; tag.info = new SoundInfo[4]; try { for (int i = 0; i < 4; i++) { tag.soundID[i] = swf.readUnsignedShort(); tag.info[i] = new SoundInfo(swf); } } catch (EOFException e) { /* seems not always 4 are filled */ } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); for (int i = 0; i < 4; i++) { swf.writeUnsignedShort(soundID[i]); if (info[i] != null) info[i].write(swf); else swf.writeUnsignedByte(0); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); for (int i = 0; i < soundID.length; i++) { s.append(" "); s.append(soundID[i]); s.append(": "); s.append(info[i]); s.append("\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/DefineText.java0000644000175000017500000002645611343262531022611 0ustar user03user03// Copyright 2001-2005, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.BitOutputStream; /** * DefineText TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineText.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineText extends DefinitionTag { protected int character; protected Rectangle2D bounds; protected AffineTransform matrix; protected Vector /* TextRecord */text; public DefineText(int id, Rectangle2D bounds, AffineTransform matrix, Vector /* TextRecord */text) { this(); character = id; this.bounds = bounds; this.matrix = matrix; this.text = text; } public DefineText() { super(11, 1); } protected DefineText(int tagID, int version) { super(tagID, version); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineText tag = new DefineText(); tag.read(tagID, swf, len, false); return tag; } protected void read(int tagID, SWFInputStream swf, int len, boolean hasAlpha) throws IOException { character = swf.readUnsignedShort(); swf.getDictionary().put(character, this); bounds = swf.readRect(); matrix = swf.readMatrix(); int glyphBits = swf.readUnsignedByte(); int advanceBits = swf.readUnsignedByte(); text = new Vector(); boolean type1 = swf.readBitFlag(); Record record = type1 ? (Record) new RecordType1(swf, glyphBits, advanceBits, hasAlpha) : (Record) new RecordType0(swf, glyphBits, advanceBits); while (!record.isEndRecord()) { text.add(record); type1 = swf.readBitFlag(); record = type1 ? (Record) new RecordType1(swf, glyphBits, advanceBits, hasAlpha) : (Record) new RecordType0(swf, glyphBits, advanceBits); } } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf, false); } protected void write(SWFOutputStream swf, boolean hasAlpha) throws IOException { swf.writeUnsignedShort(character); swf.writeRect(bounds); swf.writeMatrix(matrix); int glyphBits = 0; int advanceBits = 0; for (int i = 0; i < text.size(); i++) { Record t = (Record) text.get(i); if (t instanceof RecordType0) { RecordType0 t0 = (RecordType0) t; glyphBits = Math.max(glyphBits, t0.getGlyphBits()); advanceBits = Math.max(advanceBits, t0.getAdvanceBits()); } } swf.writeUnsignedByte(glyphBits); swf.writeUnsignedByte(advanceBits); for (int i = 0; i < text.size(); i++) { Record t = (Record) text.get(i); t.write(swf, glyphBits, advanceBits, hasAlpha); } swf.writeUnsignedByte(0); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" bounds: " + bounds + "\n"); s.append(" matrix: " + matrix + "\n"); s.append(" texts: " + text.size() + "\n"); for (int i = 0; i < text.size(); i++) { s.append(text.get(i) + "\n"); } return s.toString(); } /** * Abstract Superclass for Text Records. */ public static abstract class Record { public abstract void write(SWFOutputStream swf, int glyphBits, int advanceBits, boolean hasAlpha) throws IOException; public abstract boolean isEndRecord(); } /** * Text0 Record, for the actual glyphs. */ public static class RecordType0 extends Record { private Vector /* GlyphEntry */glyphs = null; public RecordType0() { this.glyphs = new Vector(); } public void add(GlyphEntry glyph) { glyphs.add(glyph); } RecordType0(SWFInputStream swf, int glyphBits, int advanceBits) throws IOException { int glyphCount = (int) swf.readUBits(7); if (glyphCount == 0) return; // end record glyphs = new Vector(); for (int i = 0; i < glyphCount; i++) { GlyphEntry entry = new GlyphEntry(swf, glyphBits, advanceBits); glyphs.add(entry); } swf.byteAlign(); } public void write(SWFOutputStream swf, int glyphBits, int advanceBits, boolean hasAlpha) throws IOException { swf.writeUBits(0, 1); // type 0 swf.writeUBits(glyphs.size(), 7); for (int i = 0; i < glyphs.size(); i++) { ((GlyphEntry) glyphs.get(i)).write(swf, glyphBits, advanceBits); } swf.byteAlign(); } public boolean isEndRecord() { return glyphs == null; } public int getGlyphBits() { int glyphBits = 0; for (int i = 0; i < glyphs.size(); i++) { glyphBits = Math.max(glyphBits, ((GlyphEntry) glyphs.get(i)) .getGlyphBits()); } return glyphBits; } public int getAdvanceBits() { int advanceBits = 0; for (int i = 0; i < glyphs.size(); i++) { advanceBits = Math.max(advanceBits, ((GlyphEntry) glyphs.get(i)).getAdvanceBits()); } return advanceBits; } public String toString() { StringBuffer s = new StringBuffer(); s.append(" glyphCount: " + glyphs.size() + "\n"); s.append(" "); for (int i = 0; i < glyphs.size(); i++) { s.append(glyphs.get(i) + " "); } s.append("\n"); return s.toString(); } } /** * Text1 Record, for the attributes of the text. */ public static class RecordType1 extends Record { private int fontID = -1; private Color color; private int xOffset, yOffset; private int height; // in TWIPS // only for swf >= 7 private Vector /* GlyphEntry */glyphs = null; public RecordType1(int fontID, Color color, int xOffset, int yOffset, int height) { this.fontID = fontID; this.color = color; this.xOffset = xOffset; this.yOffset = yOffset; this.height = height; glyphs = new Vector(); } // only for swf >= 7 public void add(GlyphEntry glyph) { glyphs.add(glyph); } RecordType1(SWFInputStream input, int glyphBits, int advanceBits, boolean hasAlpha) throws IOException { /* int reserved = (int) */ input.readUBits(3); boolean hasFont = input.readBitFlag(); boolean hasColor = input.readBitFlag(); boolean hasYOffset = input.readBitFlag(); boolean hasXOffset = input.readBitFlag(); if (hasFont) fontID = input.readUnsignedShort(); if (hasColor) color = input.readColor(hasAlpha); if (hasXOffset) xOffset = input.readShort(); if (hasYOffset) yOffset = input.readShort(); if (hasFont) height = input.readUnsignedShort(); glyphs = new Vector(); if (input.getVersion() >= 7) { int glyphCount = (int) input.readUnsignedByte(); for (int i = 0; i < glyphCount; i++) { glyphs.add(new GlyphEntry(input, glyphBits, advanceBits)); } } } public void write(SWFOutputStream swf, int glyphBits, int advanceBits, boolean hasAlpha) throws IOException { swf.writeBitFlag(true); swf.writeUBits(0, 3); swf.writeBitFlag(fontID >= 0); swf.writeBitFlag(color != null); swf.writeBitFlag(yOffset != 0); swf.writeBitFlag(xOffset != 0); if (fontID >= 0) swf.writeUnsignedShort(fontID); if (color != null) swf.writeColor(color, hasAlpha); if (xOffset != 0) swf.writeShort(xOffset); if (yOffset != 0) swf.writeShort(yOffset); if (fontID >= 0) swf.writeUnsignedShort(height); if (swf.getVersion() >= 7) { swf.writeUnsignedByte(glyphs.size()); for (int i = 0; i < glyphs.size(); i++) { ((GlyphEntry) glyphs.get(i)).write(swf, glyphBits, advanceBits); } } } public int getGlyphBits() { int glyphBits = 0; for (int i = 0; i < glyphs.size(); i++) { glyphBits = Math.max(glyphBits, ((GlyphEntry) glyphs.get(i)) .getGlyphBits()); } return glyphBits; } public int getAdvanceBits() { int advanceBits = 0; for (int i = 0; i < glyphs.size(); i++) { advanceBits = Math.max(advanceBits, ((GlyphEntry) glyphs.get(i)).getAdvanceBits()); } return advanceBits; } public boolean isEndRecord() { return false; } public String toString() { StringBuffer s = new StringBuffer(); s.append(" FontID: " + fontID + "\n"); s.append(" Color: " + color + "\n"); s.append(" xOffset: " + xOffset + "\n"); s.append(" yOffset: " + yOffset + "\n"); s.append(" height: " + height + "\n"); s.append(" glyphCount (swf >= 7): " + glyphs.size() + "\n"); s.append(" "); for (int i = 0; i < glyphs.size(); i++) { s.append(glyphs.get(i) + " "); } s.append("\n"); return s.toString(); } } public static class GlyphEntry { private int index; private int advance; public GlyphEntry(int index, int advance) { this.index = index; this.advance = advance; } public GlyphEntry(SWFInputStream input, int glyphBits, int advanceBits) throws IOException { index = (int) input.readUBits(glyphBits); advance = (int) input.readSBits(advanceBits); } public void write(SWFOutputStream swf, int glyphBits, int advanceBits) throws IOException { swf.writeUBits(index, glyphBits); swf.writeSBits(advance, advanceBits); } public int getGlyphBits() { return BitOutputStream.minBits(index, false); } public int getAdvanceBits() { return BitOutputStream.minBits(advance, true); } public String toString() { return "GlyphEntry[" + index + "," + advance + "]"; } } } src/main/java/org/freehep/graphicsio/swf/Gradient.java0000644000175000017500000000271011343262531022272 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.io.IOException; /** * SWF Gradient. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: Gradient.java 9979 2006-11-27 22:51:07Z duns $ */ public class Gradient { private int ratio, endRatio; private Color color, endColor; public Gradient(int ratio, Color color) { this.ratio = ratio; this.color = color; } public Gradient(int ratio, int endRatio, Color color, Color endColor) { this(ratio, color); this.endRatio = endRatio; this.endColor = endColor; } public Gradient(SWFInputStream input, boolean isMorphStyle, boolean hasAlpha) throws IOException { ratio = input.readUnsignedByte(); color = input.readColor(hasAlpha); if (isMorphStyle) { endRatio = input.readUnsignedByte(); endColor = input.readColor(true); } } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha) throws IOException { swf.writeUnsignedByte(ratio); swf.writeColor(color, hasAlpha); if (isMorphStyle) { swf.writeUnsignedByte(endRatio); swf.writeColor(endColor, true); } } public String toString() { return "Gradient " + ratio + ", " + color + ((endColor != null) ? ", " + endRatio + ", " + endColor : ""); } } src/main/java/org/freehep/graphicsio/swf/Protect.java0000644000175000017500000000251111343262531022154 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Protect TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: Protect.java 8584 2006-08-10 23:06:37Z duns $ */ public class Protect extends ControlTag { private String password; public Protect(String password) { this(); this.password = password; if (password != null) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] b = md5.digest(password.getBytes()); this.password = new String(b); } catch (NoSuchAlgorithmException nsae) { } } } public Protect() { super(24, 2); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { if (len != 0) { Protect tag = new Protect(); tag.password = new String(swf.readByte(len)); return tag; } else { return this; } } public void write(int tagID, SWFOutputStream swf) throws IOException { if ((password != null) && (swf.getVersion() >= 5)) { swf.writeByte(password.getBytes()); } } } src/main/java/org/freehep/graphicsio/swf/ClipActionRecord.java0000644000175000017500000000345411343262531023727 0ustar user03user03// Copyright 2003, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; /** * SWF Clip Action Record * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ClipActionRecord.java 8584 2006-08-10 23:06:37Z duns $ */ public class ClipActionRecord { private ClipEventFlags eventFlags; private long actionRecordSize; private int keyCode; private Vector actions; /** * Read a ClipActionRecord from the stream. */ public ClipActionRecord(SWFInputStream swf) throws IOException { eventFlags = new ClipEventFlags(swf); if (eventFlags.isEndFlag()) return; actionRecordSize = swf.readUnsignedInt(); // FIXME is actually a long (unsigned int) swf.pushBuffer((int) (actionRecordSize - 4)); if (eventFlags.isKeyPress()) keyCode = swf.readUnsignedByte(); while (swf.getLength() > 0) { actions.add(swf.readAction()); } byte[] rest = swf.popBuffer(); if (rest != null) { System.err.println("Corrupted ClipActionRecord, " + rest.length + " bytes leftoever."); } } public void write(SWFOutputStream swf) throws IOException { eventFlags.write(swf); // FIXME, should do PushBuffer and calculate this size... swf.writeUnsignedInt(actionRecordSize); if (eventFlags.isKeyPress()) swf.writeUnsignedByte(keyCode); for (int i = 0; i < actions.size(); i++) { SWFAction a = (SWFAction) actions.get(i); swf.writeAction(a); } } public boolean isEndRecord() { return eventFlags.isEndFlag(); } public String toString() { return "ClipActionRecord " + actions.size(); } } src/main/java/org/freehep/graphicsio/swf/DefineSprite.java0000644000175000017500000000361711343262531023125 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; /** * DefineSprite TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefineSprite.java 8584 2006-08-10 23:06:37Z duns $ */ public class DefineSprite extends DefinitionTag { private int character; private int frameCount; private Vector tags; public DefineSprite(int id, int frameCount, Vector tags) { this(); character = id; this.frameCount = frameCount; this.tags = tags; } public DefineSprite() { super(39, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { DefineSprite tag = new DefineSprite(); tag.character = swf.readUnsignedShort(); swf.getDictionary().put(tag.character, tag); tag.frameCount = swf.readUnsignedShort(); int version = swf.getVersion(); SWFInputStream sprite = new SWFInputStream(swf, new SWFSpriteTagSet( version), new SWFActionSet(version)); tag.tags = new Vector(); SWFTag miniTag; do { miniTag = (SWFTag) sprite.readTag(); tag.tags.add(miniTag); } while (!(miniTag instanceof End)); return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUnsignedShort(frameCount); for (int i = 0; i < tags.size(); i++) { swf.writeTag((SWFTag) tags.get(i)); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString() + "\n"); s.append(" character: " + character + "\n"); s.append(" frameCount: " + frameCount + "\n"); s.append(" tags: " + tags.size() + "\n"); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/LineStyleArray.java0000644000175000017500000000371411343262531023451 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * SWF LineStyleArray. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: LineStyleArray.java 9979 2006-11-27 22:51:07Z duns $ */ public class LineStyleArray { protected List /* LineStyle */lineStyles; public LineStyleArray() { this.lineStyles = new ArrayList(); } public LineStyleArray(SWFInputStream swf, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { this(); int lineStyleCount = swf.readUnsignedByte(); if (lineStyleCount == 0xFF) { lineStyleCount = swf.readUnsignedShort(); } for (int i = 0; i < lineStyleCount; i++) { lineStyles.add(new LineStyle(swf, isMorphStyle, hasAlpha, hasStyles)); } } public void add(LineStyle lineStyle) { lineStyles.add(lineStyle); } public LineStyle get(int index) { return (LineStyle) lineStyles.get(index); } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha, boolean hasStyles) throws IOException { if (lineStyles.size() >= 0xFF) { swf.writeUnsignedByte(0xFF); swf.writeUnsignedShort(lineStyles.size()); } else { swf.writeUnsignedByte(lineStyles.size()); } for (Iterator i = lineStyles.iterator(); i.hasNext();) { ((LineStyle) i.next()).write(swf, isMorphStyle, hasAlpha, hasStyles); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(" lineStyles: " + lineStyles.size() + "\n"); int n = 0; for (Iterator i = lineStyles.iterator(); i.hasNext();) { s.append(" " + (n + 1) + " " + (i.next()) + "\n"); n++; } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/ClipEventFlags.java0000644000175000017500000000523511343262531023410 0ustar user03user03// Copyright 2003, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SWF Clip Event Flags * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ClipEventFlags.java 8584 2006-08-10 23:06:37Z duns $ */ public class ClipEventFlags { private boolean keyPress, dragOut, dragOver, rollOut, rollOver; private boolean releaseOutside, release, press, initialize, data; private boolean keyUp, keyDown, mouseUp, mouseDown, mouseMove; private boolean unload, enterFrame, load; /** * Read a ClipEventFlags from the stream. */ public ClipEventFlags(SWFInputStream swf) throws IOException { if (swf.getVersion() >= 6) { swf.readUBits(14); keyPress = swf.readBitFlag(); dragOut = swf.readBitFlag(); } dragOver = swf.readBitFlag(); rollOut = swf.readBitFlag(); rollOver = swf.readBitFlag(); releaseOutside = swf.readBitFlag(); release = swf.readBitFlag(); press = swf.readBitFlag(); initialize = swf.readBitFlag(); data = swf.readBitFlag(); keyUp = swf.readBitFlag(); keyDown = swf.readBitFlag(); mouseUp = swf.readBitFlag(); mouseDown = swf.readBitFlag(); mouseMove = swf.readBitFlag(); unload = swf.readBitFlag(); enterFrame = swf.readBitFlag(); load = swf.readBitFlag(); } public void write(SWFOutputStream swf) throws IOException { if (swf.getVersion() >= 6) { swf.writeUBits(0, 14); swf.writeBitFlag(keyPress); swf.writeBitFlag(dragOut); } swf.writeBitFlag(dragOver); swf.writeBitFlag(rollOut); swf.writeBitFlag(rollOver); swf.writeBitFlag(releaseOutside); swf.writeBitFlag(release); swf.writeBitFlag(press); swf.writeBitFlag(initialize); swf.writeBitFlag(data); swf.writeBitFlag(keyUp); swf.writeBitFlag(keyDown); swf.writeBitFlag(mouseUp); swf.writeBitFlag(mouseDown); swf.writeBitFlag(mouseMove); swf.writeBitFlag(unload); swf.writeBitFlag(enterFrame); swf.writeBitFlag(load); } public boolean isKeyPress() { return keyPress; } public boolean isEndFlag() { // All bits were 0? return !(keyPress || dragOut || dragOver || rollOut || rollOver || releaseOutside || release || press || initialize || data || keyUp || keyDown || mouseUp || mouseDown || mouseMove || unload || enterFrame || load); } public String toString() { return "ClipEventFlags"; } } src/main/java/org/freehep/graphicsio/swf/FrameLabel.java0000644000175000017500000000233011343262531022525 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * FrameLabel TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: FrameLabel.java 8584 2006-08-10 23:06:37Z duns $ */ public class FrameLabel extends ControlTag { private String label; private boolean anchor; public FrameLabel(String label) { this(label, false); } public FrameLabel(String label, boolean anchor) { this(); this.label = label; this.anchor = anchor; } public FrameLabel() { super(43, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { FrameLabel tag = new FrameLabel(); tag.label = swf.readString(); anchor = (swf.getVersion() > 6) ? (swf.readUnsignedByte() != 0) : false; return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeString(label); swf.writeUnsignedByte((swf.getVersion() > 6) ? anchor ? 1 : 0 : 0); } public String toString() { return super.toString() + "\n" + " frame label: " + label + "\n" + " anchor: " + anchor; } } src/main/java/org/freehep/graphicsio/swf/SoundStreamHead2.java0000644000175000017500000000214211343262531023644 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SoundStreamHead2 TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SoundStreamHead2.java 8584 2006-08-10 23:06:37Z duns $ */ public class SoundStreamHead2 extends SoundStreamHead { public SoundStreamHead2(int playbackSoundRate, boolean playbackSoundStereo, int streamSoundRate, boolean streamSoundStereo, int samples) { this(); this.playbackSoundRate = playbackSoundRate; this.playbackSoundSize16 = true; this.playbackSoundStereo = playbackSoundStereo; this.streamSoundCompression = 1; this.streamSoundRate = streamSoundRate; this.streamSoundSize16 = true; this.streamSoundStereo = streamSoundStereo; this.samples = samples; } public SoundStreamHead2() { super(45, 3); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { SoundStreamHead2 tag = new SoundStreamHead2(); tag.read(swf, len); return tag; } } src/main/java/org/freehep/graphicsio/swf/SoundInfo.java0000644000175000017500000000602111343262531022440 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SWF SoundInfo * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SoundInfo.java 8584 2006-08-10 23:06:37Z duns $ */ public class SoundInfo { private boolean syncStop; private boolean syncNoMultiple; private long inPoint = -1; private long outPoint = -1; private int loop = -1; private SoundEnvelope[] envelope; public SoundInfo(boolean syncStop, boolean syncNoMultiple, long inPoint, long outPoint, int loop, SoundEnvelope[] envelope) { this.syncStop = syncStop; this.syncNoMultiple = syncNoMultiple; this.inPoint = inPoint; this.outPoint = outPoint; this.loop = loop; this.envelope = envelope; } public SoundInfo(SWFInputStream input) throws IOException { input.readUBits(2); syncStop = input.readBitFlag(); syncNoMultiple = input.readBitFlag(); boolean hasEnvelope = input.readBitFlag(); boolean hasLoops = input.readBitFlag(); boolean hasOutPoint = input.readBitFlag(); boolean hasInPoint = input.readBitFlag(); if (hasInPoint) { inPoint = input.readUnsignedInt(); } if (hasOutPoint) { outPoint = input.readUnsignedInt(); } if (hasLoops) { loop = input.readUnsignedShort(); } if (hasEnvelope) { int numPoints = input.readUnsignedByte(); envelope = new SoundEnvelope[numPoints]; for (int i = 0; i < numPoints; i++) { envelope[i] = new SoundEnvelope(input); } } } public void write(SWFOutputStream swf) throws IOException { swf.writeUBits(0, 2); swf.writeBitFlag(syncStop); swf.writeBitFlag(syncNoMultiple); swf.writeBitFlag(envelope != null); swf.writeBitFlag(loop >= 0); swf.writeBitFlag(outPoint >= 0); swf.writeBitFlag(inPoint >= 0); if (inPoint >= 0) { swf.writeUnsignedInt(inPoint); } if (outPoint >= 0) { swf.writeUnsignedInt(outPoint); } if (loop >= 0) { swf.writeUnsignedShort(loop); } if (envelope != null) { swf.writeUnsignedByte(envelope.length); for (int i = 0; i < envelope.length; i++) { envelope[i].write(swf); } } } public String toString() { StringBuffer s = new StringBuffer("SoundInfo "); s.append("syncStop: " + syncStop); s.append(", syncNoMultiple: " + syncNoMultiple); s.append(", in: " + inPoint); s.append(", out: " + outPoint); s.append(", loop: " + loop); if (envelope != null) { s.append(" ["); for (int i = 0; i < envelope.length; i++) { s.append(envelope[i]); s.append(" "); } s.append("]"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFActionSet.java0000644000175000017500000001346211343262531023014 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import org.freehep.util.io.ActionSet; /** * Defines the actions for SWF. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFActionSet.java 8584 2006-08-10 23:06:37Z duns $ */ public class SWFActionSet extends ActionSet { public SWFActionSet(int version) { super(); // Initialize actions // version 3 if (version >= 3) { addAction(new SWFAction.GotoFrame()); addAction(new SWFAction.GetURL()); addAction(new SWFAction.NextFrame()); addAction(new SWFAction.PreviousFrame()); addAction(new SWFAction.Play()); addAction(new SWFAction.Stop()); addAction(new SWFAction.ToggleQuality()); addAction(new SWFAction.StopSounds()); addAction(new SWFAction.WaitForFrame()); addAction(new SWFAction.SetTarget()); addAction(new SWFAction.GotoLabel()); } // version 4 if (version >= 4) { addAction(new SWFAction.Add()); // 0x0a addAction(new SWFAction.Subtract()); // 0x0b addAction(new SWFAction.Multiply()); // 0x0c addAction(new SWFAction.Divide()); // 0x0d addAction(new SWFAction.WaitForFrame2()); // 0x8d addAction(new SWFAction.Equals()); // 0x0e addAction(new SWFAction.Less()); // 0x0f addAction(new SWFAction.And()); // 0x10 addAction(new SWFAction.Or()); // 0x11 addAction(new SWFAction.Not()); // 0x12 addAction(new SWFAction.StringEquals()); // 0x13 addAction(new SWFAction.StringLength()); // 0x14 addAction(new SWFAction.StringExtract()); // 0x15 addAction(new SWFAction.Push()); // 0x96 addAction(new SWFAction.Pop()); // 0x17 addAction(new SWFAction.ToInteger()); // 0x18 addAction(new SWFAction.Jump()); // 0x99 addAction(new SWFAction.GetURL2()); // 0x9a addAction(new SWFAction.GetVariable()); // 0x1c addAction(new SWFAction.SetVariable()); // 0x1d addAction(new SWFAction.If()); // 0x9d addAction(new SWFAction.Call()); // 0x9e addAction(new SWFAction.GotoFrame2()); // 0x9f addAction(new SWFAction.SetTarget2()); // 0x20 addAction(new SWFAction.StringAdd()); // 0x21 addAction(new SWFAction.GetProperty()); // 0x22 addAction(new SWFAction.SetProperty()); // 0x23 addAction(new SWFAction.CloneSprite()); // 0x24 addAction(new SWFAction.RemoveSprite()); // 0x25 addAction(new SWFAction.Trace()); // 0x26 addAction(new SWFAction.StartDrag()); // 0x27 addAction(new SWFAction.EndDrag()); // 0x28 addAction(new SWFAction.StringLess()); // 0x29 addAction(new SWFAction.RandomNumber()); // 0x30 addAction(new SWFAction.MBStringLength()); // 0x31 addAction(new SWFAction.CharToAscii()); // 0x32 addAction(new SWFAction.AsciiToChar()); // 0x33 addAction(new SWFAction.GetTime()); // 0x34 addAction(new SWFAction.MBStringExtract()); // 0x35 addAction(new SWFAction.MBCharToAscii()); // 0x36 addAction(new SWFAction.MBAsciiToChar()); // 0x37 } // version 5 if (version >= 5) { addAction(new SWFAction.StoreRegister()); // 0x87 addAction(new SWFAction.ConstantPool()); // 0x88 addAction(new SWFAction.With()); // 0x94 addAction(new SWFAction.DefineFunction()); // 0x9b addAction(new SWFAction.Delete()); // 0x3a addAction(new SWFAction.Delete2()); // 0x3b addAction(new SWFAction.DefineLocal()); // 0x3c addAction(new SWFAction.CallFunction()); // 0x3d addAction(new SWFAction.Return()); // 0x3e addAction(new SWFAction.Modulo()); // 0x3f addAction(new SWFAction.NewObject()); // 0x40 addAction(new SWFAction.DefineLocal2()); // 0x41 addAction(new SWFAction.InitArray()); // 0x42 addAction(new SWFAction.InitObject()); // 0x43 addAction(new SWFAction.TypeOf()); // 0x44 addAction(new SWFAction.TargetPath()); // 0x45 addAction(new SWFAction.Enumerate()); // 0x46 addAction(new SWFAction.Add2()); // 0x47 addAction(new SWFAction.Less2()); // 0x48 addAction(new SWFAction.Equals2()); // 0x49 addAction(new SWFAction.ToNumber()); // 0x4a addAction(new SWFAction.ToString()); // 0x4b addAction(new SWFAction.PushDuplicate()); // 0x4c addAction(new SWFAction.StackSwap()); // 0x4d addAction(new SWFAction.GetMember()); // 0x4e addAction(new SWFAction.SetMember()); // 0x4f addAction(new SWFAction.Increment()); // 0x50 addAction(new SWFAction.Decrement()); // 0x51 addAction(new SWFAction.CallMethod()); // 0x52 addAction(new SWFAction.NewMethod()); // 0x53 addAction(new SWFAction.BitAnd()); // 0x60 addAction(new SWFAction.BitOr()); // 0x61 addAction(new SWFAction.BitXor()); // 0x62 addAction(new SWFAction.BitLShift()); // 0x63 addAction(new SWFAction.BitRShift()); // 0x64 addAction(new SWFAction.BitURShift()); // 0x65 } // version 6 if (version >= 6) { addAction(new SWFAction.InstanceOf()); // 0x54 addAction(new SWFAction.Enumerate2()); // 0x55 addAction(new SWFAction.StrictEquals()); // 0x66 addAction(new SWFAction.Greater()); // 0x67 addAction(new SWFAction.StringGreater()); // 0x68 } } } src/main/java/org/freehep/graphicsio/swf/PlaceObject.java0000644000175000017500000000342611343262531022715 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.geom.AffineTransform; import java.io.EOFException; import java.io.IOException; /** * PlaceObject TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: PlaceObject.java 8584 2006-08-10 23:06:37Z duns $ */ public class PlaceObject extends ControlTag { private int character; private int depth; private AffineTransform matrix; private ColorXform cxform = null; public PlaceObject(int id, int depth, AffineTransform matrix) { this(id, depth, matrix, null); } public PlaceObject(int id, int depth, AffineTransform matrix, ColorXform cxform) { this(); character = id; this.depth = depth; this.matrix = matrix; this.cxform = cxform; } public PlaceObject() { super(4, 1); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { PlaceObject tag = new PlaceObject(); tag.character = swf.readUnsignedShort(); tag.depth = swf.readUnsignedShort(); tag.matrix = swf.readMatrix(); try { tag.cxform = new ColorXform(swf, false); } catch (EOFException e) { } return tag; } public void write(int tagID, SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(character); swf.writeUnsignedShort(depth); swf.writeMatrix(matrix); if (cxform != null) { cxform.write(swf, false); } } public String toString() { return super.toString() + "\n" + " depth: " + depth + "\n" + " character: " + character + "\n" + " matrix: " + matrix + "\n" + " xform: " + cxform; } } src/main/java/org/freehep/graphicsio/swf/FillStyleArray.java0000644000175000017500000000362111343262531023445 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * SWF FillStyleArray. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: FillStyleArray.java 9979 2006-11-27 22:51:07Z duns $ */ public class FillStyleArray { protected List /* FillStyle */fillStyles; public FillStyleArray() { this.fillStyles = new ArrayList(); } public FillStyleArray(SWFInputStream swf, boolean isMorphStyle, boolean hasAlpha) throws IOException { this(); int fillStyleCount = swf.readUnsignedByte(); if (fillStyleCount == 0xFF) { fillStyleCount = swf.readUnsignedShort(); } for (int i = 0; i < fillStyleCount; i++) { fillStyles.add(new FillStyle(swf, isMorphStyle, hasAlpha)); } } public void add(FillStyle fillStyle) { this.fillStyles.add(fillStyle); } public FillStyle get(int index) { return (FillStyle) fillStyles.get(index); } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha) throws IOException { if (fillStyles.size() >= 0xFF) { swf.writeUnsignedByte(0xFF); swf.writeUnsignedShort(fillStyles.size()); } else { swf.writeUnsignedByte(fillStyles.size()); } for (Iterator i = fillStyles.iterator(); i.hasNext();) { ((FillStyle) i.next()).write(swf, isMorphStyle, hasAlpha); } } public String toString() { StringBuffer s = new StringBuffer(); s.append(" fillStyles: " + fillStyles.size() + "\n"); int n = 0; for (Iterator i = fillStyles.iterator(); i.hasNext();) { s.append(" " + (n + 1) + " " + (i.next()) + "\n"); n++; } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/ButtonCondAction.java0000644000175000017500000000274011343262531023755 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; import java.util.Vector; import org.freehep.util.io.Action; /** * SWF Button Condition Action * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ButtonCondAction.java 8584 2006-08-10 23:06:37Z duns $ */ public class ButtonCondAction { private int condition; private Vector actions; public ButtonCondAction(int condition, Vector actions) { this.condition = condition; this.actions = actions; } public ButtonCondAction(SWFInputStream input) throws IOException { condition = input.readUnsignedShort(); actions = new Vector(); Action action = input.readAction(); while (action != null) { actions.add(action); action = input.readAction(); } } public void write(SWFOutputStream swf) throws IOException { swf.writeUnsignedShort(condition); for (int i = 0; i < actions.size(); i++) { Action a = (Action) actions.get(i); swf.writeAction(a); } swf.writeAction(null); } public String toString() { StringBuffer s = new StringBuffer(); s.append("ButtonCondAction " + condition + "\n"); s.append(" actions: " + actions.size() + "\n"); for (int i = 0; i < actions.size(); i++) { s.append(" " + actions.get(i) + "\n"); } return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SoundStreamHead.java0000644000175000017500000000563211343262531023571 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; import java.io.IOException; /** * SoundStreamHead TAG. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SoundStreamHead.java 8584 2006-08-10 23:06:37Z duns $ */ public class SoundStreamHead extends DefinitionTag { protected int playbackSoundRate; protected boolean playbackSoundSize16; protected boolean playbackSoundStereo; protected int streamSoundCompression; protected int streamSoundRate; protected boolean streamSoundSize16; protected boolean streamSoundStereo; protected int samples; protected int latencySeek; public SoundStreamHead(int playbackSoundRate, boolean playbackSoundStereo, int streamSoundRate, boolean streamSoundStereo, int samples) { this(); this.playbackSoundRate = playbackSoundRate; this.playbackSoundSize16 = true; this.playbackSoundStereo = playbackSoundStereo; this.streamSoundCompression = 1; this.streamSoundRate = streamSoundRate; this.streamSoundSize16 = true; this.streamSoundStereo = streamSoundStereo; this.samples = samples; } public SoundStreamHead() { super(18, 1); } protected SoundStreamHead(int tagID, int version) { super(tagID, version); } public SWFTag read(int tagID, SWFInputStream swf, int len) throws IOException { SoundStreamHead tag = new SoundStreamHead(); tag.read(swf, len); return tag; } protected void read(SWFInputStream swf, int len) throws IOException { /* int reserved = (int) */ swf.readUBits(4); playbackSoundRate = (int) swf.readUBits(2); playbackSoundSize16 = swf.readBitFlag(); playbackSoundStereo = swf.readBitFlag(); streamSoundCompression = (int) swf.readUBits(4); streamSoundRate = (int) swf.readUBits(2); streamSoundSize16 = swf.readBitFlag(); streamSoundStereo = swf.readBitFlag(); samples = swf.readUnsignedShort(); if (streamSoundCompression == 2) latencySeek = swf.readShort(); } public void write(int tagID, SWFOutputStream swf) throws IOException { write(swf); } protected void write(SWFOutputStream swf) throws IOException { swf.writeUBits(0, 4); swf.writeUBits(playbackSoundRate, 2); swf.writeBitFlag(playbackSoundSize16); swf.writeBitFlag(playbackSoundStereo); swf.writeUBits(streamSoundCompression, 4); swf.writeUBits(streamSoundRate, 2); swf.writeBitFlag(streamSoundSize16); swf.writeBitFlag(streamSoundStereo); swf.writeUnsignedShort(samples); if (streamSoundCompression == 2) swf.writeShort(latencySeek); } public String toString() { StringBuffer s = new StringBuffer(); s.append(super.toString()); return s.toString(); } } src/main/java/org/freehep/graphicsio/swf/SWFTagSet.java0000644000175000017500000000637211343262531022314 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; /** * Defines the tags for SWF. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: SWFTagSet.java 9979 2006-11-27 22:51:07Z duns $ */ public class SWFTagSet extends SWFSpriteTagSet { public SWFTagSet(int version) { super(version); // The following tags do NOT exist: // 3, 16, 25, 27, 29, 30, 31, 40-42, 44, 47, 49-55 and 63 // Initialize tags // Version 1 if (version >= 1) { addTag(new DefineShape()); // 2 addTag(new DefineBits()); // 6 addTag(new DefineButton()); // 7 addTag(new JPEGTables()); // 8 addTag(new SetBackgroundColor()); // 9 addTag(new DefineFont()); // 10 addTag(new DefineText()); // 11 addTag(new DefineFontInfo()); // 13 addTag(new DefineSound()); // 14 // added in version 8, just skipped in earlier versions addTag(new FileAttributes()); // 69 } // Version 2 if (version >= 2) { addTag(new DefineButtonSound()); // 17 addTag(new DefineBitsLossless()); // 20 addTag(new DefineBitsJPEG2()); // 21 addTag(new DefineShape2()); // 22 addTag(new DefineButtonCxform()); // 23 addTag(new Protect()); // 24 } // Version 3 if (version >= 3) { addTag(new DefineShape3()); // 32 addTag(new DefineText2()); // 33 addTag(new DefineButton2()); // 34 addTag(new DefineBitsJPEG3()); // 35 addTag(new DefineBitsLossless2()); // 36 addTag(new DefineSprite()); // 39 addTag(new SoundStreamHead2()); // 45 addTag(new DefineMorphShape()); // 46 addTag(new DefineFont2()); // 48 } // version 4 if (version >= 4) { addTag(new DefineEditText()); // 37 addTag(new DefineMovie()); // 38 } // version 5 if (version >= 5) { addTag(new ExportAssets()); // 56 addTag(new ImportAssets()); // 57 } if (version == 5) { addTag(new EnableDebugger()); // 58 } // version 6 if (version >= 6) { addTag(new DoInitAction()); // 59 addTag(new DefineVideoStream()); // 60 addTag(new VideoFrame()); // 61 addTag(new DefineFontInfo2()); // 62 addTag(new EnableDebugger2()); // 64 } // version 7 if (version >= 7) { // addTag(new ScriptLimits()); // 65 // addTag(new SetTabIndex()); // 66 } // version 8 if (version >= 8) { // NOTE: FileAttributes (69) under version 1. // addTag(new PlaceObject3()); // 70 // addTag(new Import2()); // 71 // addTag(new DefineFontAlignZoned()); // 73 // addTag(new CSMTextSettings()); // 74 // addTag(new DefineFont3()); // 75 // addTag(new Metadata()); // 77 // addTag(new DefineScalingGrid()); // 78 addTag(new DefineShape4()); // 83 // addTag(new DefineMorphShape2()); // 84 } } } src/main/java/org/freehep/graphicsio/swf/DefinitionTag.java0000644000175000017500000000111611343262531023260 0ustar user03user03// Copyright 2001, FreeHEP. package org.freehep.graphicsio.swf; /** * Abstract Definition TAG. All definition tags inherit from this class. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: DefinitionTag.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class DefinitionTag extends SWFTag { protected DefinitionTag(int tagID, int version) { super(tagID, version); } public int getTagType() { return DEFINITION; } public String toString() { return "Definition: " + getName() + " (" + getTag() + ")"; } } src/main/java/org/freehep/graphicsio/swf/FillStyle.java0000644000175000017500000001524711343262531022455 0ustar user03user03// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.swf; import java.awt.Color; import java.awt.geom.AffineTransform; import java.io.IOException; /** * SWF FillStyle. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: FillStyle.java 9979 2006-11-27 22:51:07Z duns $ */ public class FillStyle { public static final int SOLID = 0x00; public static final int LINEAR_GRADIENT = 0x10; public static final int RADIAL_GRADIENT = 0x12; public static final int FOCAL_GRADIENT = 0x13; public static final int TILED_BITMAP = 0x40; public static final int CLIPPED_BITMAP = 0x41; public static final int TILED_BITMAP_NOT_SMOOTHED = 0x42; public static final int CLIPPED_BITMAP_NOT_SMOOTHED = 0x43; public static final int SPREAD_MODE_PAD = 0; public static final int SPREAD_MODE_REFLECT = 1; public static final int SPREAD_MODE_REPEAT = 2; public static final int INTERPOLATION_MODE_NORMAL_RGB = 0; public static final int INTERPOLATION_MODE_LINEAR_RGB = 1; private int type; private Color color, endColor; private AffineTransform matrix, endMatrix; private Gradient[] gradient; private int spreadMode; private int interpolationMode; private float focalPoint; private int bitmap; public FillStyle(Color color) { type = SOLID; this.color = color; } public FillStyle(Color color, Color endColor) { this(color); this.endColor = endColor; } public FillStyle(Gradient[] gradient, boolean linear, AffineTransform matrix) { this(gradient, LINEAR_GRADIENT, SPREAD_MODE_PAD, INTERPOLATION_MODE_NORMAL_RGB, 0, matrix); } public FillStyle(Gradient[] gradient, int gradientType, int spreadMode, int interpolationMode, float focalPoint, AffineTransform matrix) { this.type = gradientType; this.gradient = gradient; this.spreadMode = spreadMode; this.interpolationMode = interpolationMode; this.focalPoint = focalPoint; this.matrix = matrix; } public FillStyle(Gradient[] gradient, boolean linear, AffineTransform matrix, AffineTransform endMatrix) { this(gradient, linear, matrix); this.endMatrix = endMatrix; } public FillStyle(int bitmap, boolean tiled, AffineTransform matrix) { type = (tiled) ? TILED_BITMAP : CLIPPED_BITMAP; this.bitmap = bitmap; this.matrix = matrix; } public FillStyle(int bitmap, boolean tiled, AffineTransform matrix, AffineTransform endMatrix) { this(bitmap, tiled, matrix); this.endMatrix = endMatrix; } public FillStyle(SWFInputStream input, boolean isMorphStyle, boolean hasAlpha) throws IOException { type = input.readUnsignedByte(); switch (type) { case SOLID: color = input.readColor(hasAlpha); if (isMorphStyle) endColor = input.readColor(hasAlpha); break; case LINEAR_GRADIENT: case RADIAL_GRADIENT: case FOCAL_GRADIENT: matrix = input.readMatrix(); if (isMorphStyle) endMatrix = input.readMatrix(); input.byteAlign(); spreadMode = (int)input.readUBits(2); interpolationMode = (int)input.readUBits(2); int gradientCount = (int)input.readUBits(4); gradient = new Gradient[gradientCount]; for (int i = 0; i < gradientCount; i++) { gradient[i] = new Gradient(input, isMorphStyle, hasAlpha); } if (type == FOCAL_GRADIENT) { focalPoint = input.readFixed8(); } break; case TILED_BITMAP: case CLIPPED_BITMAP: case TILED_BITMAP_NOT_SMOOTHED: case CLIPPED_BITMAP_NOT_SMOOTHED: bitmap = input.readUnsignedShort(); matrix = input.readMatrix(); if (isMorphStyle) endMatrix = input.readMatrix(); break; default: System.err.println("FillStyle type " + type + " not implemented."); break; } } public int getType() { return type; } public void write(SWFOutputStream swf, boolean isMorphStyle, boolean hasAlpha) throws IOException { swf.writeUnsignedByte(type); switch (type) { case SOLID: swf.writeColor(color, hasAlpha || (endColor != null)); if (endColor != null) swf.writeColor(endColor, true); break; case LINEAR_GRADIENT: case RADIAL_GRADIENT: case FOCAL_GRADIENT: swf.writeMatrix(matrix); if (isMorphStyle) swf.writeMatrix(endMatrix); swf.byteAlign(); swf.writeUBits(spreadMode, 2); swf.writeUBits(interpolationMode, 2); swf.writeUBits(gradient.length, 4); for (int i = 0; i < gradient.length; i++) { gradient[i].write(swf, isMorphStyle, hasAlpha); } if (type == FOCAL_GRADIENT) { swf.writeFixed8(focalPoint); } break; case TILED_BITMAP: case CLIPPED_BITMAP: case TILED_BITMAP_NOT_SMOOTHED: case CLIPPED_BITMAP_NOT_SMOOTHED: swf.writeUnsignedShort(bitmap); swf.writeMatrix(matrix); if (isMorphStyle) swf.writeMatrix(endMatrix); break; default: System.err.println("FillStyle type " + type + " not implemented."); break; } } public String toString() { StringBuffer s = new StringBuffer(); switch (type) { case SOLID: s.append("Solid: "); s.append(color); if (endColor != null) s.append("; " + endColor); break; case LINEAR_GRADIENT: case RADIAL_GRADIENT: s.append("Gradient: "); for (int i = 0; i < gradient.length; i++) { s.append(gradient[i]); s.append("; "); } s.append(matrix); if (endMatrix != null) s.append("; " + endMatrix); break; case TILED_BITMAP: case CLIPPED_BITMAP: s.append("BitMap: "); s.append(bitmap); s.append(", "); s.append(matrix); if (endMatrix != null) s.append("; " + endMatrix); break; default: s.append("Unknown Type:"); s.append(type); break; } return s.toString(); } } src/site/0000700000175000017500000000000011343262531011623 5ustar user03user03src/site/apt/0000700000175000017500000000000011343262531012407 5ustar user03user03src/site/site.xml0000644000175000017500000000174711343262531013334 0ustar user03user03 FreeHEP GraphicsIO SWF (Flash) http://java.freehep.org/mvn/freehep-graphicsio-swf FreeHEP http://java.freehep.org/images/sm-freehep.gif http://java.freehep.org/