1 50 51 package org.openlaszlo.iv.flash.api.shape; 52 53 import org.openlaszlo.iv.flash.util.*; 54 import org.openlaszlo.iv.flash.api.*; 55 import org.openlaszlo.iv.flash.parser.*; 56 import java.io.PrintStream ; 57 58 63 public final class MorphShapeStyles extends FlashItem { 64 65 68 public IVVector fillStyles; 69 70 73 public IVVector lineStyles; 74 75 78 public MorphShapeStyles() { 79 this(new IVVector(), new IVVector()); 80 } 81 82 public MorphShapeStyles( IVVector fillStyles, IVVector lineStyles ) { 83 this.fillStyles = fillStyles; 84 this.lineStyles = lineStyles; 85 } 86 87 93 public int addFillStyle( MorphFillStyle fs ) { 94 fillStyles.addElement(fs); 95 return fillStyles.size(); 96 } 97 98 104 public int addLineStyle( MorphLineStyle ls ) { 105 lineStyles.addElement(ls); 106 return lineStyles.size(); 107 } 108 109 115 public int getFillStyleIndex( MorphFillStyle fs ) { 116 for( int i=0; i<fillStyles.size(); i++ ) { 117 MorphFillStyle ffs = (MorphFillStyle) fillStyles.elementAt(i); 118 if( ffs == fs ) return i+1; 119 } 120 return -1; 121 } 122 123 129 public int getLineStyleIndex( MorphLineStyle ls ) { 130 for( int i=0; i<lineStyles.size(); i++ ) { 131 MorphLineStyle lls = (MorphLineStyle) lineStyles.elementAt(i); 132 if( lls == ls ) return i+1; 133 } 134 return -1; 135 } 136 137 143 public MorphLineStyle getLineStyle( int index ) { 144 return (MorphLineStyle) lineStyles.elementAt(index); 145 } 146 147 153 public MorphFillStyle getFillStyle( int index ) { 154 return (MorphFillStyle) fillStyles.elementAt(index); 155 } 156 157 162 public int calcNFillBits() { 163 return Util.getMinBitsU( fillStyles.size() ); 164 } 165 166 171 public int calcNLineBits() { 172 return Util.getMinBitsU( lineStyles.size() ); 173 } 174 175 public void collectDeps( DepsCollector dc ) { 176 int fillStyleSize = fillStyles.size(); 177 for( int i=0; i<fillStyleSize; i++ ) { 178 MorphFillStyle fillStyle = (MorphFillStyle) fillStyles.elementAt(i); 179 if( fillStyle.getBitmap() != null ) dc.addDep(fillStyle.getBitmap()); 180 } 181 } 182 183 public void write( FlashOutput fob ) { 184 int fillStyleSize = fillStyles.size(); 185 if( fillStyleSize > 254 ) { 186 fob.writeByte(255); 187 fob.writeWord(fillStyleSize); 188 } else { 189 fob.writeByte(fillStyleSize); 190 } 191 fillStyles.write(fob); 192 int lineStyleSize = lineStyles.size(); 193 if( lineStyleSize > 254 ) { 194 fob.writeByte(255); 195 fob.writeWord(lineStyleSize); 196 } else { 197 fob.writeByte(lineStyleSize); 198 } 199 lineStyles.write(fob); 200 } 201 202 public static MorphShapeStyles parse( Parser p ) { 203 int nFills = p.getUByte(); 205 if( nFills == 255 ) { 206 nFills = p.getUWord(); 207 } 208 IVVector fillStyles = new IVVector(nFills); 209 210 for( int i=0; i<nFills; i++ ) { 212 fillStyles.addElement( MorphFillStyle.parse(p) ); 213 } 214 215 int nLines = p.getUByte(); 216 if( nLines == 255 ) { 217 nLines = p.getUWord(); 218 } 219 IVVector lineStyles = new IVVector(nLines); 220 221 for( int i=0; i<nLines; i++ ) { 223 lineStyles.addElement( MorphLineStyle.parse(p) ); 224 } 225 226 return new MorphShapeStyles(fillStyles, lineStyles); 227 } 228 229 public void printContent( PrintStream out, String indent ) { 230 out.println( indent+"MorphShapeStyles:" ); 231 fillStyles.printContent(out, indent+" "); 232 lineStyles.printContent(out, indent+" "); 233 } 234 235 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 236 ((MorphShapeStyles)item).fillStyles = fillStyles.getCopy(copier); 237 ((MorphShapeStyles)item).lineStyles = lineStyles.getCopy(copier); 238 return item; 239 } 240 241 public FlashItem getCopy( ScriptCopier copier ) { 242 return copyInto( new MorphShapeStyles(null, null), copier ); 243 } 244 } 245 246 | Popular Tags |