1 50 51 package org.openlaszlo.iv.flash.api.shape; 52 53 import java.awt.geom.*; 54 import java.io.PrintStream ; 55 56 import org.openlaszlo.iv.flash.parser.*; 57 import org.openlaszlo.iv.flash.util.*; 58 import org.openlaszlo.iv.flash.api.*; 59 60 public class LazyMorphShape extends LazyShape { 61 62 public Rectangle2D endBounds; 63 64 public LazyMorphShape() {} 65 66 private static void extractBitmaps( Parser p, LazyMorphShape shape ) { 67 int pos = p.getPos(); 68 69 p.skip(4); 71 int nFills = p.getUByte(); 73 if( nFills == 255 ) { 74 nFills = p.getUWord(); 75 } 76 77 for( int i=0; i<nFills; i++ ) { 79 int fillStyle = p.getUByte(); 80 if( (fillStyle&0x10) != 0 ) { p.skipMatrix(); 82 p.skipMatrix(); 83 int nColors = p.getUByte(); 85 for( int j=0; j<nColors; j++ ) { 87 p.skip(1); AlphaColor.skip(p); 89 p.skip(1); AlphaColor.skip(p); 91 } 92 } else if( (fillStyle&0x40) != 0 ) { int id_pos = p.getPos()-pos; 94 int id = p.getUWord(); 95 FlashDef def = p.getDef(id); 96 shape.addBitmap(def, id_pos); 98 p.skipMatrix(); 99 p.skipMatrix(); 100 } else { AlphaColor.skip(p); 102 AlphaColor.skip(p); 103 } 104 } 105 } 106 107 public static FlashDef parse( Parser p ) { 108 FlashFile file = p.getFile(); 109 if( file.isFullParsing() ) { 110 MorphShape shape = MorphShape.parse(p); 111 return shape; 112 } else { 113 LazyMorphShape shape = new LazyMorphShape(); 114 shape.tagCode = p.getTagCode(); 115 shape.setID( p.getUWord() ); 116 shape.bounds = p.getRect(); 117 shape.endBounds = p.getRect(); 118 shape.data = new DataMarker( p.getBuf(), p.getPos(), p.getTagEndPos() ); 120 extractBitmaps( p, shape ); 121 return shape; 122 } 123 } 124 125 public void write( FlashOutput fob ) { 126 fob.writeTag( tagCode, 127 2 + 128 GeomHelper.getSize(bounds) + 129 GeomHelper.getSize(endBounds) + 130 data.length() 131 ); 132 fob.writeDefID( this ); 133 fob.write(bounds); 134 fob.write(endBounds); 135 int pos = fob.getPos(); 136 data.write( fob ); 137 if( bitmaps != null ) { 138 for( int i=0; i<bitmaps.size(); i++ ) { 139 BitmapRef ref = (BitmapRef) bitmaps.elementAt(i); 140 fob.writeWordAt( fob.getDefID(ref.bitmap), pos+ref.offset ); 141 } 142 } 143 } 144 145 public boolean isConstant() { 146 return true; 147 } 148 149 public Rectangle2D getBounds() { 150 Rectangle2D dst = GeomHelper.newRectangle(); 151 Rectangle2D.union( bounds, endBounds, dst ); 152 return dst; 153 } 154 155 public void printContent( PrintStream out, String indent ) { 156 out.println( indent+"LazyMorphShape: id="+getID()+", name='"+getName()+"'" ); 157 out.println( indent+" "+bounds ); 158 out.println( indent+" "+endBounds ); 159 if( bitmaps != null ) { 160 out.print( indent+" bitmaps used: " ); 161 for( int i=0; i<bitmaps.size(); i++ ) { 162 BitmapRef ref = (BitmapRef) bitmaps.elementAt(i); 163 out.print( "id["+i+"]="+ref.bitmap.getID()+" " ); 164 } 165 out.println(); 166 } 167 } 168 169 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 170 super.copyInto( item, copier ); 171 ((LazyMorphShape)item).endBounds = (Rectangle2D) endBounds.clone(); 172 return item; 173 } 174 175 public FlashItem getCopy( ScriptCopier copier ) { 176 return copyInto( new LazyMorphShape(), copier ); 177 } 178 } 179 | Popular Tags |