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 ShapeStyles extends FlashItem { 64 65 68 public IVVector fillStyles; 69 70 73 public IVVector lineStyles; 74 75 78 public ShapeStyles() { 79 this(new IVVector(), new IVVector()); 80 } 81 82 public ShapeStyles( IVVector fillStyles, IVVector lineStyles ) { 83 this.fillStyles = fillStyles; 84 this.lineStyles = lineStyles; 85 } 86 87 93 public int addFillStyle( FillStyle fs ) { 94 fillStyles.addElement(fs); 95 return fillStyles.size(); 96 } 97 98 104 public int addLineStyle( LineStyle ls ) { 105 lineStyles.addElement(ls); 106 return lineStyles.size(); 107 } 108 109 115 public int getFillStyleIndex( FillStyle fs ) { 116 for( int i=0; i<fillStyles.size(); i++ ) { 117 FillStyle ffs = (FillStyle) fillStyles.elementAt(i); 118 if( ffs == fs ) return i+1; 119 } 120 return -1; 121 } 122 123 129 public int getLineStyleIndex( LineStyle ls ) { 130 for( int i=0; i<lineStyles.size(); i++ ) { 131 LineStyle lls = (LineStyle) lineStyles.elementAt(i); 132 if( lls == ls ) return i+1; 133 } 134 return -1; 135 } 136 137 143 public LineStyle getLineStyle( int index ) { 144 return (LineStyle) lineStyles.elementAt(index); 145 } 146 147 153 public FillStyle getFillStyle( int index ) { 154 return (FillStyle) 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 FillStyle fillStyle = (FillStyle) fillStyles.elementAt(i); 179 if( fillStyle.getBitmap() != null ) dc.addDep(fillStyle.getBitmap()); 180 } 181 } 182 183 public static ShapeStyles parse( Parser p, boolean withAlpha ) { 184 int nFills = p.getUByte(); 186 if( nFills == 255 ) { 187 nFills = p.getUWord(); 188 } 189 IVVector fillStyles = new IVVector(nFills); 190 191 for( int i=0; i<nFills; i++ ) { 193 fillStyles.addElement( FillStyle.parse(p, withAlpha) ); 194 } 195 196 int nLines = p.getUByte(); 197 if( nLines == 255 ) { 198 nLines = p.getUWord(); 199 } 200 IVVector lineStyles = new IVVector(nLines); 201 202 for( int i=0; i<nLines; i++ ) { 204 lineStyles.addElement( LineStyle.parse(p, withAlpha) ); 205 } 206 207 return new ShapeStyles(fillStyles, lineStyles); 208 } 209 210 public void write( FlashOutput fob ) { 211 int fillStyleSize = fillStyles.size(); 212 if( fillStyleSize > 254 ) { 213 fob.writeByte(255); 214 fob.writeWord(fillStyleSize); 215 } else { 216 fob.writeByte(fillStyleSize); 217 } 218 fillStyles.write(fob); 219 int lineStyleSize = lineStyles.size(); 220 if( lineStyleSize > 254 ) { 221 fob.writeByte(255); 222 fob.writeWord(lineStyleSize); 223 } else { 224 fob.writeByte(lineStyleSize); 225 } 226 lineStyles.write(fob); 227 } 228 229 public void printContent( PrintStream out, String indent ) { 230 out.println( indent+"ShapeStyles:" ); 231 fillStyles.printContent(out, indent+" "); 232 lineStyles.printContent(out, indent+" "); 233 } 234 235 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 236 ((ShapeStyles)item).fillStyles = fillStyles.getCopy(copier); 237 ((ShapeStyles)item).lineStyles = lineStyles.getCopy(copier); 238 return item; 239 } 240 241 public FlashItem getCopy( ScriptCopier copier ) { 242 return copyInto( new ShapeStyles(null, null), copier ); 243 } 244 } 245 | Popular Tags |