1 18 19 package org.apache.batik.transcoder.wmf.tosvg; 20 21 import java.io.DataInputStream ; 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.Vector ; 25 26 import org.apache.batik.transcoder.wmf.WMFConstants; 27 28 34 public class RecordStore { 35 36 public RecordStore(){ 37 reset(); 38 } 39 40 43 public void reset(){ 44 numRecords = 0; 45 vpX = 0; 46 vpY = 0; 47 vpW = 1000; 48 vpH = 1000; 49 numObjects = 0; 50 records = new Vector ( 20, 20 ); 51 objectVector = new Vector (); 52 } 53 54 synchronized void setReading( boolean state ){ 55 bReading = state; 56 } 57 58 synchronized boolean isReading(){ 59 return bReading; 60 } 61 62 70 public boolean read( DataInputStream is ) throws IOException { 71 setReading( true ); 72 reset(); 73 74 int functionId = 0; 75 numRecords = 0; 76 77 numObjects = is.readShort(); 78 objectVector.ensureCapacity( numObjects ); 79 for ( int i = 0; i < numObjects; i++ ) { 80 objectVector.addElement( new GdiObject( i, false )); 81 } 82 83 while ( functionId != -1 ) { 84 functionId = is.readShort(); 85 if ( functionId == -1 ){ 86 break; 87 } 88 89 MetaRecord mr; 90 switch ( functionId ) { 91 case WMFConstants.META_TEXTOUT: 92 case WMFConstants.META_DRAWTEXT: 93 case WMFConstants.META_EXTTEXTOUT: 94 case WMFConstants.META_CREATEFONTINDIRECT:{ 95 short len = is.readShort(); 96 byte[] b = new byte[ len ]; 97 for ( int i = 0; i < len; i++ ) { 98 b[ i ] = is.readByte(); 99 } 100 String str = new String ( b ); 101 mr = new StringRecord( str ); 102 } 103 break; 104 105 default: 106 mr = new MetaRecord(); 107 break; 108 } 109 110 int numPts = is.readShort(); 111 mr.numPoints = numPts; 112 mr.functionId = functionId; 113 114 for ( int j = 0; j < numPts; j++ ){ 115 mr.AddElement( new Integer ( is.readShort())); 116 } 117 118 records.addElement( mr ); 119 120 numRecords++; 121 } 122 123 setReading( false ); 124 return true; 125 } 126 127 133 public void addObject( int type, Object obj ) 134 { 135 for ( int i = 0; i < numObjects; i++ ) { 136 GdiObject gdi = (GdiObject)objectVector.elementAt( i ); 137 if ( gdi.used == false ) { 138 gdi.Setup( type, obj ); 139 lastObjectIdx = i; 140 break; 141 } 142 } 143 } 144 145 152 public void addObjectAt( int type, Object obj, int idx ) { 153 if (( idx == 0 ) || ( idx > numObjects )) { 154 addObject( type, obj ); 155 return; 156 } 157 lastObjectIdx = idx; 158 for ( int i = 0; i < numObjects; i++ ) { 159 GdiObject gdi = (GdiObject)objectVector.elementAt( i ); 160 if ( i == idx ) { 161 gdi.Setup( type, obj ); 162 break; 163 } 164 } 165 } 166 167 170 public URL getUrl() { 171 return url; 172 } 173 174 177 public void setUrl( URL newUrl) { 178 url = newUrl; 179 } 180 181 184 public GdiObject getObject( int idx ) { 185 return (GdiObject)objectVector.elementAt( idx ); 186 } 187 188 191 public MetaRecord getRecord( int idx ) { 192 return (MetaRecord)records.elementAt( idx ); 193 } 194 195 198 public int getNumRecords() { 199 return numRecords; 200 } 201 202 205 public int getNumObjects() { 206 return numObjects; 207 } 208 209 212 public int getVpX() { 213 return vpX; 214 } 215 216 219 public int getVpY() { 220 return vpY; 221 } 222 223 226 public int getVpW() { 227 return vpW; 228 } 229 230 233 public int getVpH() { 234 return vpH; 235 } 236 237 240 public void setVpX( int newValue ) { 241 vpX = newValue; 242 } 243 244 247 public void setVpY( int newValue ) { 248 vpY = newValue; 249 } 250 251 254 public void setVpW( int newValue ) { 255 vpW = newValue; 256 } 257 258 261 public void setVpH( int newValue ) { 262 vpH = newValue; 263 } 264 265 transient private URL url; 266 267 transient protected int numRecords; 268 transient protected int numObjects; 269 transient public int lastObjectIdx; 270 transient protected int vpX, vpY, vpW, vpH; 271 transient protected Vector records; 272 transient protected Vector objectVector; 273 274 transient protected boolean bReading = false; 275 } 276 | Popular Tags |