1 package org.apache.batik.transcoder.wmf.tosvg; 18 19 import java.awt.BasicStroke ; 20 import java.awt.Color ; 21 import java.awt.Font ; 22 import java.awt.Graphics ; 23 import java.awt.Graphics2D ; 24 import java.awt.Polygon ; 25 import java.awt.Shape ; 26 import java.awt.font.FontRenderContext ; 27 import java.awt.font.TextLayout ; 28 import java.awt.geom.AffineTransform ; 29 import java.awt.geom.GeneralPath ; 30 import java.awt.geom.Point2D ; 31 import java.io.BufferedInputStream ; 32 import java.util.Stack ; 33 import java.util.Vector ; 34 35 import org.apache.batik.transcoder.wmf.WMFConstants; 36 37 45 public class WMFPainter { 46 private static final String WMF_FILE_EXTENSION = ".wmf"; 47 48 51 private static final int INPUT_BUFFER_SIZE = 30720; 52 53 private static BasicStroke solid 54 = new BasicStroke ( 1.0f, 55 BasicStroke.CAP_BUTT, 56 BasicStroke.JOIN_ROUND ); 57 58 61 public WMFPainter(WMFRecordStore currentStore) { 62 setRecordStore(currentStore); 63 } 64 65 68 public void paint( Graphics g ) { 69 int fontHeight = 10; 71 int fontAngle = 0; 72 int penWidth = 0; 73 int startX = 0; 74 int startY = 0; 75 int brushObject = -1; 76 int penObject = -1; 77 int fontObject = -1; 78 Color frgdColor; 79 Color bkgdColor; 80 Font font = null; 81 int vpX, vpY, vpW, vpH; 82 Stack dcStack = new Stack (); 83 84 int numRecords = currentStore.getNumRecords(); 85 int numObjects = currentStore.getNumObjects(); 86 vpX = currentStore.getVpX(); 87 vpY = currentStore.getVpY(); 88 vpW = currentStore.getVpW(); 89 vpH = currentStore.getVpH(); 90 91 if ( !currentStore.isReading()) { 92 GdiObject gdiObj; 93 int gdiIndex; 94 g.setPaintMode(); 95 96 brushObject = -1; 97 penObject = -1; 98 fontObject = -1; 99 frgdColor = null; 100 bkgdColor = null; 101 for ( int i = 0; i < numObjects; i++ ) { 102 gdiObj = currentStore.getObject( i ); 103 gdiObj.Clear(); 104 } 105 106 int w = vpW; 107 int h = vpH; 108 109 g.setColor( Color.white ); 110 g.fillRect( 0, 0, w, h ); 111 g.setColor( Color.black ); 112 113 double scaleX = (double)w / vpW; 114 double scaleY = (double)h / vpH; 115 116 for ( int iRec = 0; iRec < numRecords; iRec++ ) { 117 MetaRecord mr = currentStore.getRecord( iRec ); 118 119 switch ( mr.functionId ) { 120 case WMFConstants.META_SETWINDOWORG: 121 currentStore.setVpX( vpX = -mr.ElementAt( 0 ).intValue()); 122 currentStore.setVpY( vpY = -mr.ElementAt( 1 ).intValue()); 123 break; 124 125 case WMFConstants.META_SETWINDOWORG_EX: case WMFConstants.META_SETWINDOWEXT: 127 currentStore.setVpW( vpW = mr.ElementAt( 0 ).intValue()); 128 currentStore.setVpH( vpH = mr.ElementAt( 1 ).intValue()); 129 scaleX = (double)w / vpW; 130 scaleY = (double)h / vpH; 131 132 break; 134 135 case WMFConstants.META_SETVIEWPORTORG: 136 case WMFConstants.META_SETVIEWPORTEXT: 137 case WMFConstants.META_OFFSETWINDOWORG: 138 case WMFConstants.META_SCALEWINDOWEXT: 139 case WMFConstants.META_OFFSETVIEWPORTORG: 140 case WMFConstants.META_SCALEVIEWPORTEXT: 141 break; 142 143 144 case WMFConstants.META_SETPOLYFILLMODE: 145 break; 146 147 case WMFConstants.META_CREATEPENINDIRECT: 148 { 149 int objIndex = 0; 150 try { 151 objIndex = mr.ElementAt( 5 ).intValue(); 152 } 153 catch ( Exception e ) {} 154 int penStyle = mr.ElementAt( 0 ).intValue(); 155 Color newClr; 156 if ( penStyle == 5 ) { 157 newClr = new Color ( 255, 255, 255 ); 158 objIndex = numObjects + 8; 159 addObjectAt( currentStore, NULL_PEN, newClr, objIndex ); 160 } 161 else { 162 newClr = new Color ( mr.ElementAt( 1 ).intValue(), 163 mr.ElementAt( 2 ).intValue(), 164 mr.ElementAt( 3 ).intValue()); 165 addObjectAt( currentStore, PEN, newClr, objIndex ); 166 } 167 penWidth = mr.ElementAt( 4 ).intValue(); 168 } 169 break; 170 171 case WMFConstants.META_CREATEBRUSHINDIRECT: 172 { 173 int objIndex = 0; 174 try { 175 objIndex = mr.ElementAt( 5 ).intValue(); 176 } 177 catch ( Exception e ) {} 178 int brushStyle = mr.ElementAt( 0 ).intValue(); 179 if ( brushStyle == 0 ) { 180 addObjectAt(currentStore, BRUSH, 181 new Color (mr.ElementAt( 1 ).intValue(), 182 mr.ElementAt( 2 ).intValue(), 183 mr.ElementAt( 3 ).intValue()), 184 objIndex ); 185 } 186 else 187 addObjectAt( currentStore, NULL_BRUSH, new Color ( 0,0,0 ), objIndex ); 188 } 189 break; 190 191 case WMFConstants.META_CREATEFONTINDIRECT: 192 { 193 int style =(mr.ElementAt( 1 ).intValue() > 0 ? Font.ITALIC : Font.PLAIN ); 194 style |= (mr.ElementAt( 2 ).intValue() > 400 ? Font.BOLD : Font.PLAIN ); 195 196 int size = (int)( scaleY * ( mr.ElementAt( 0 ).intValue())); 197 String face = ((StringRecord)mr).text; 198 if ( size < 0 ) 199 size = (int)(size * -1.3 ); 200 int objIndex = 0; 201 try { 202 objIndex = mr.ElementAt( 3 ).intValue(); 203 } 204 catch ( Exception e ) {} 205 fontHeight = size; 206 addObjectAt( currentStore, FONT, font = new Font ( face, style, size ), objIndex ); 210 } 211 break; 212 213 case WMFConstants.META_DIBCREATEPATTERNBRUSH: 214 case WMFConstants.META_CREATEBRUSH: 215 case WMFConstants.META_CREATEPATTERNBRUSH: 216 case WMFConstants.META_CREATEBITMAPINDIRECT: 217 case WMFConstants.META_CREATEBITMAP: 218 case WMFConstants.META_CREATEREGION: 219 case WMFConstants.META_CREATEPALETTE: 220 addObjectAt( currentStore, PALETTE, new Integer ( 0 ), 0 ); 221 break; 222 223 case WMFConstants.META_SELECTPALETTE: 224 case WMFConstants.META_REALIZEPALETTE: 225 case WMFConstants.META_ANIMATEPALETTE: 226 case WMFConstants.META_SETPALENTRIES: 227 case WMFConstants.META_RESIZEPALETTE: 228 break; 229 230 case WMFConstants.META_SELECTOBJECT: 231 gdiIndex = mr.ElementAt( 0 ).intValue(); 232 if (( gdiIndex & 0x80000000 ) != 0 ) break; 234 if ( gdiIndex >= numObjects ) { 235 gdiIndex -= numObjects; 236 switch ( gdiIndex ) { 237 case WMFConstants.META_OBJ_NULL_BRUSH: 238 brushObject = -1; 239 break; 240 case WMFConstants.META_OBJ_NULL_PEN: 241 penObject = -1; 242 break; 243 case WMFConstants.META_OBJ_WHITE_BRUSH: 244 case WMFConstants.META_OBJ_LTGRAY_BRUSH: 245 case WMFConstants.META_OBJ_GRAY_BRUSH: 246 case WMFConstants.META_OBJ_DKGRAY_BRUSH: 247 case WMFConstants.META_OBJ_BLACK_BRUSH: 248 case WMFConstants.META_OBJ_WHITE_PEN: 249 case WMFConstants.META_OBJ_BLACK_PEN: 250 case WMFConstants.META_OBJ_OEM_FIXED_FONT: 251 case WMFConstants.META_OBJ_ANSI_FIXED_FONT: 252 case WMFConstants.META_OBJ_ANSI_VAR_FONT: 253 case WMFConstants.META_OBJ_SYSTEM_FONT: 254 case WMFConstants.META_OBJ_DEVICE_DEFAULT_FONT: 255 case WMFConstants.META_OBJ_DEFAULT_PALETTE: 256 case WMFConstants.META_OBJ_SYSTEM_FIXED_FONT: 257 break; 258 } 259 break; 260 } 261 gdiObj = currentStore.getObject( gdiIndex ); 262 if ( !gdiObj.used ) 263 break; 264 switch( gdiObj.type ) { 265 case PEN: 266 g.setColor( (Color )gdiObj.obj ); 267 penObject = gdiIndex; 268 break; 269 case BRUSH: 270 g.setColor( (Color )gdiObj.obj ); 271 brushObject = gdiIndex; 272 break; 273 case FONT: 274 g.setFont( font = (Font )gdiObj.obj ); 275 fontObject = gdiIndex; 276 break; 277 case NULL_PEN: 278 penObject = -1; 279 break; 280 case NULL_BRUSH: 281 brushObject = -1; 282 break; 283 } 284 break; 285 286 case WMFConstants.META_DELETEOBJECT: 287 gdiIndex = mr.ElementAt( 0 ).intValue(); 288 gdiObj = currentStore.getObject( gdiIndex ); 289 if ( gdiIndex == brushObject ) 290 brushObject = -1; 291 else if ( gdiIndex == penObject ) 292 penObject = -1; 293 else if ( gdiIndex == fontObject ) 294 fontObject = -1; 295 gdiObj.Clear(); 296 break; 297 298 case WMFConstants.META_POLYPOLYGON: 299 { 300 int numPolygons = mr.ElementAt( 0 ).intValue(); 301 int[] pts = new int[ numPolygons ]; 302 for ( int ip = 0; ip < numPolygons; ip++ ) 303 pts[ ip ] = mr.ElementAt( ip + 1 ).intValue(); 304 305 GeneralPath gp = new GeneralPath (); 306 int offset = numPolygons+1; 307 for ( int j = 0; j < numPolygons; j++ ) { 308 int count = pts[ j ]; 309 int[] xpts = new int[ count ]; 310 int[] ypts = new int[ count ]; 311 for ( int k = 0; k < count; k++ ) { 312 xpts[k] = (int)( scaleX * ( vpX + mr.ElementAt( offset + k*2 ).intValue())); 313 ypts[k] = (int)( scaleY * ( vpY + mr.ElementAt( offset + k*2+1 ).intValue())); 314 } 315 offset += count; 316 Polygon p = new Polygon (xpts, ypts, count); 317 gp.append( p, true ); 318 } 319 if ( brushObject >= 0 ) { 320 setBrushColor( currentStore, g, brushObject ); 321 ( (Graphics2D ) g).fill(gp); 322 } 323 setPenColor( currentStore, g, penObject ); 324 ( (Graphics2D ) g).draw(gp); 325 } 326 break; 327 328 case WMFConstants.META_POLYGON: 329 { 330 int count = mr.ElementAt( 0 ).intValue(); 331 int[] _xpts = new int[ count+1 ]; 332 int[] _ypts = new int[ count+1 ]; 333 for ( int k = 0; k < count; k++ ) { 334 _xpts[k] = (int)( scaleX * ( vpX + mr.ElementAt( k*2+1 ).intValue())); 335 _ypts[k] = (int)( scaleY * ( vpY + mr.ElementAt( k*2+2 ).intValue())); 336 } 337 _xpts[count] = _xpts[0]; 338 _ypts[count] = _ypts[0]; 339 if ( brushObject >= 0 ) { 340 setBrushColor( currentStore, g, brushObject ); 341 g.fillPolygon( _xpts, _ypts, count ); 342 } 343 setPenColor( currentStore, g, penObject ); 344 g.drawPolygon( _xpts, _ypts, count+1 ); 345 } 346 break; 347 348 case WMFConstants.META_MOVETO: 349 startX = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 350 startY = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 351 break; 352 353 case WMFConstants.META_LINETO: 354 { 355 int endX = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 356 int endY = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 357 setPenColor( currentStore, g, penObject ); 358 g.drawLine( startX, startY, endX, endY ); 359 startX = endX; 360 startY = endY; 361 } 362 break; 363 364 case WMFConstants.META_POLYLINE: 365 { 366 setPenColor( currentStore, g, penObject ); 367 int count = mr.ElementAt( 0 ).intValue(); 368 int endX, endY; 369 int _startX, _startY; 370 _startX = (int)( scaleX * ( vpX + mr.ElementAt( 1 ).intValue())); 371 _startY = (int)( scaleY * ( vpY + mr.ElementAt( 2 ).intValue())); 372 for ( int j = 1; j < count; j++ ) { 373 endX = (int)( scaleX * ( vpX + mr.ElementAt( j*2+1 ).intValue())); 374 endY = (int)( scaleY * ( vpY + mr.ElementAt( j*2+2 ).intValue())); 375 g.drawLine( _startX, _startY, endX, endY ); 376 _startX = endX; 377 _startY = endY; 378 } 379 } 380 break; 381 382 case WMFConstants.META_RECTANGLE: 383 { 384 int x1, y1, x2, y2; 385 x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 386 x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue())); 387 y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 388 y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue())); 389 390 if ( brushObject >= 0 ) { 391 setBrushColor( currentStore, g, brushObject ); 392 g.fillRect( x1, y1, x2-x1-1, y2-y1-1 ); 393 } 394 setPenColor( currentStore, g, penObject ); 395 g.drawRect( x1, y1, x2-x1-1, y2-y1-1 ); 396 } 397 break; 398 399 case WMFConstants.META_ROUNDRECT: 400 { 401 int x1, y1, x2, y2, x3, y3; 402 x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 403 x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue())); 404 x3 = (int)( scaleX * ( mr.ElementAt( 4 ).intValue())); 405 y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 406 y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue())); 407 y3 = (int)( scaleY * ( mr.ElementAt( 5 ).intValue())); 408 409 if ( brushObject >= 0 ) { 410 setBrushColor( currentStore, g, brushObject ); 411 g.fillRoundRect( x1, y1, x2-x1, y2-y1, x3, y3 ); 412 } 413 setPenColor( currentStore, g, penObject ); 414 g.drawRoundRect( x1, y1, x2-x1, y2-y1, x3, y3 ); 415 } 416 break; 417 418 case WMFConstants.META_ELLIPSE: 419 { 420 int x1, y1, x2, y2; 421 x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 422 x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue())); 423 y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 424 y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue())); 425 426 if ( brushObject >= 0 ) { 427 setBrushColor( currentStore, g, brushObject ); 428 g.fillOval( x1, y1, x2-x1, y2-y1 ); 429 } 430 setPenColor( currentStore, g, penObject ); 431 g.drawOval( x1, y1, x2-x1-1, y2-y1-1 ); 432 } 433 break; 434 435 case WMFConstants.META_SETTEXTCOLOR: 436 frgdColor = new Color (mr.ElementAt( 0 ).intValue(), 437 mr.ElementAt( 1 ).intValue(), 438 mr.ElementAt( 2 ).intValue()); 439 break; 440 441 case WMFConstants.META_SETBKCOLOR: 442 bkgdColor = new Color (mr.ElementAt( 0 ).intValue(), 443 mr.ElementAt( 1 ).intValue(), 444 mr.ElementAt( 2 ).intValue()); 445 break; 446 447 case WMFConstants.META_EXTTEXTOUT: 448 case WMFConstants.META_TEXTOUT: 449 case WMFConstants.META_DRAWTEXT: 450 try 451 { 452 Graphics2D g2 = (Graphics2D )g; 453 int x, y; 454 x = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 455 y = (int)( fontHeight + scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 456 if ( frgdColor != null ) 457 g.setColor( frgdColor ); 458 else 459 g.setColor( Color.black ); 460 StringRecord sr = (StringRecord)mr; 461 462 FontRenderContext frc = g2.getFontRenderContext(); 463 464 Point2D.Double pen = new Point2D.Double ( 0, 0 ); 465 GeneralPath gp = new GeneralPath ( GeneralPath.WIND_NON_ZERO ); 466 TextLayout layout = new TextLayout ( sr.text, font, frc ); 467 pen.y += layout.getAscent(); 468 469 if (( fontAngle != 0 ) || sr.text.startsWith("Sono una scala verticale di prevalenza") ) { 470 AffineTransform at = new AffineTransform (); 471 float height = (float)layout.getBounds().getHeight(); 472 473 AffineTransform textAt = new AffineTransform (); 474 textAt.translate( x, y); 475 textAt.rotate(Math.toRadians(270)); 476 textAt.translate(0, height); 477 Shape shape = layout.getOutline(textAt); 478 gp.append( at.createTransformedShape( shape ), false ); 479 g2.draw( shape ); 480 } 481 else 482 g.drawString( sr.text, x, y ); 483 } 484 catch ( Exception e ) 485 { 486 } 487 break; 488 489 case WMFConstants.META_ARC: 490 case WMFConstants.META_PIE: 491 { 492 int x1, y1, x2, y2, x3, y3, x4, y4; 493 x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue())); 494 x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue())); 495 x3 = (int)( scaleX * ( mr.ElementAt( 4 ).intValue())); 496 x4 = (int)( scaleX * ( mr.ElementAt( 6 ).intValue())); 497 y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue())); 498 y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue())); 499 y3 = (int)( scaleY * ( mr.ElementAt( 5 ).intValue())); 500 y4 = (int)( scaleY * ( mr.ElementAt( 7 ).intValue())); 501 setBrushColor( currentStore, g, brushObject ); 502 503 int mx = x1+(x2-x1)/2; 504 int my = y1+(y2-y1)/2; 505 int startAngle = (int)Math.atan( (y3-my)/(x3-mx)); 506 int endAngle = (int)Math.atan( (y4-my)/(x4-mx)); 507 if ( mr.functionId == 0x0817 ) 508 g.drawArc( x1, y1, x2-x1, y2-y1, startAngle, endAngle ); 509 else 510 g.fillArc( x1, y1, x2-x1, y2-y1, startAngle, endAngle ); 511 512 } 513 break; 514 515 516 case WMFConstants.META_CHORD: 517 break; 518 519 case WMFConstants.META_SAVEDC: 520 dcStack.push( new Integer ( penWidth )); 521 dcStack.push( new Integer ( startX )); 522 dcStack.push( new Integer ( startY )); 523 dcStack.push( new Integer ( brushObject )); 524 dcStack.push( new Integer ( penObject )); 525 dcStack.push( new Integer ( fontObject )); 526 dcStack.push( frgdColor ); 527 dcStack.push( bkgdColor ); 528 break; 529 530 case WMFConstants.META_RESTOREDC: 531 bkgdColor = (Color )dcStack.pop(); 532 frgdColor = (Color )dcStack.pop(); 533 fontObject = ((Integer )(dcStack.pop())).intValue(); 534 penObject = ((Integer )(dcStack.pop())).intValue(); 535 brushObject = ((Integer )(dcStack.pop())).intValue(); 536 startY = ((Integer )(dcStack.pop())).intValue(); 537 startX = ((Integer )(dcStack.pop())).intValue(); 538 penWidth = ((Integer )(dcStack.pop())).intValue(); 539 break; 540 541 case WMFConstants.META_POLYBEZIER16: 542 try 543 { 544 Graphics2D g2 = (Graphics2D )g; 545 setPenColor( currentStore, g, penObject ); 546 547 int pointCount = mr.ElementAt( 0 ).intValue(); 548 int bezierCount = ( pointCount-1 ) / 3; 549 float endX, endY; 550 float cp1X, cp1Y; 551 float cp2X, cp2Y; 552 float _startX, _startY; 553 _startX = (float)( scaleX * ( vpX + mr.ElementAt( 1 ).intValue())); 554 _startY = (float)( scaleY * ( vpY + mr.ElementAt( 2 ).intValue())); 555 556 GeneralPath gp = new GeneralPath ( GeneralPath.WIND_NON_ZERO ); 557 gp.moveTo( _startX, _startY ); 558 559 for ( int j = 0; j < bezierCount; j++ ) { 560 cp1X = (float)( scaleX * ( vpX + mr.ElementAt( j*6+3 ).intValue())); 561 cp1Y = (float)( scaleY * ( vpY + mr.ElementAt( j*6+4 ).intValue())); 562 563 cp2X = (float)( scaleX * ( vpX + mr.ElementAt( j*6+5 ).intValue())); 564 cp2Y = (float)( scaleY * ( vpY + mr.ElementAt( j*6+6 ).intValue())); 565 566 endX = (float)( scaleX * ( vpX + mr.ElementAt( j*6+7 ).intValue())); 567 endY = (float)( scaleY * ( vpY + mr.ElementAt( j*6+8 ).intValue())); 568 569 gp.curveTo( cp1X, cp1Y, cp2X, cp2Y, endX, endY ); 570 _startX = endX; 571 _startY = endY; 572 } 573 g2.setStroke( solid ); 575 g2.draw( gp ); 576 } 577 catch ( Exception e ) { 578 System.out.println( "Unable to draw static text as a 2D graphics context is required" ); 579 } 580 break; 581 582 case WMFConstants.META_EXCLUDECLIPRECT: 583 case WMFConstants.META_INTERSECTCLIPRECT: 584 585 case WMFConstants.META_OFFSETCLIPRGN: 586 case WMFConstants.META_SELECTCLIPREGION: 587 588 case WMFConstants.META_SETBKMODE: 589 case WMFConstants.META_SETMAPMODE: 590 case WMFConstants.META_SETROP2: 591 case WMFConstants.META_SETRELABS: 592 case WMFConstants.META_SETSTRETCHBLTMODE: 593 case WMFConstants.META_SETTEXTCHAREXTRA: 594 case WMFConstants.META_SETTEXTJUSTIFICATION: 595 case WMFConstants.META_FLOODFILL: 596 case WMFConstants.META_PATBLT: 597 case WMFConstants.META_SETPIXEL: 598 case WMFConstants.META_BITBLT: 599 case WMFConstants.META_STRETCHBLT: 600 case WMFConstants.META_ESCAPE: 601 case WMFConstants.META_FILLREGION: 602 case WMFConstants.META_FRAMEREGION: 603 case WMFConstants.META_INVERTREGION: 604 case WMFConstants.META_PAINTREGION: 605 case WMFConstants.META_SETTEXTALIGN: 606 case WMFConstants.META_SETMAPPERFLAGS: 607 case WMFConstants.META_SETDIBTODEV: 608 case WMFConstants.META_DIBBITBLT: 609 case WMFConstants.META_DIBSTRETCHBLT: 610 case WMFConstants.META_STRETCHDIB: 611 default: 612 { 613 } 621 break; 623 } 624 } 625 626 } 627 } 628 629 private void setPenColor( WMFRecordStore currentStore, Graphics g, int penObject) { 630 if ( penObject >= 0 ) { 631 GdiObject gdiObj = currentStore.getObject( penObject ); 632 g.setColor( (Color )gdiObj.obj ); 633 penObject = -1; 634 } 635 } 636 637 private void setBrushColor( WMFRecordStore currentStore, Graphics g, int brushObject) { 638 if ( brushObject >= 0 ) { 639 GdiObject gdiObj = currentStore.getObject( brushObject ); 640 g.setColor( (Color )gdiObj.obj ); 641 brushObject = -1; 642 } 643 } 644 645 648 public void setRecordStore(WMFRecordStore currentStore){ 649 if(currentStore == null){ 650 throw new IllegalArgumentException (); 651 } 652 653 this.currentStore = currentStore; 654 } 655 656 659 public WMFRecordStore getRecordStore(){ 660 return currentStore; 661 } 662 663 private void addObject( WMFRecordStore currentStore, int type, Object obj ) { 664 currentStore.addObject( type, obj ); 665 } 666 667 private void addObjectAt( WMFRecordStore currentStore, int type, Object obj, int idx ) { 668 currentStore.addObjectAt( type, obj, idx ); 669 } 670 671 public static final int PEN = 1; 672 public static final int BRUSH = 2; 673 public static final int FONT = 3; 674 public static final int NULL_PEN = 4; 675 public static final int NULL_BRUSH = 5; 676 public static final int PALETTE = 6; 677 678 private WMFRecordStore currentStore; 679 transient private boolean bReadingWMF = true; 680 transient private BufferedInputStream bufStream = null; 681 682 } 683 684 685 class MetaRecord 686 { 687 public int functionId; 688 public int numPoints; 689 690 private Vector ptVector; 691 692 public MetaRecord() 693 { 694 ptVector = new Vector (); 695 } 696 697 public void EnsureCapacity( int cc ) 698 { 699 ptVector.ensureCapacity( cc ); 700 } 701 702 public void AddElement( Object obj ) 703 { 704 ptVector.addElement( obj ); 705 } 706 707 public Integer ElementAt( int offset ) 708 { 709 return (Integer )ptVector.elementAt( offset ); 710 } 711 } 712 713 class StringRecord extends MetaRecord 714 { 715 public String text; 716 717 public StringRecord( String newText ) 718 { 719 text = new String ( newText ); 720 } 721 } 722 723 class GdiObject 724 { 725 GdiObject( int _id, boolean _used ) 726 { 727 id = _id; 728 used = _used; 729 type = 0; 730 } 731 732 public void Clear() 733 { 734 used = false; 735 type = 0; 736 } 737 738 public void Setup( int _type, Object _obj ) 739 { 740 obj = _obj; 741 type = _type; 742 used = true; 743 } 744 745 int id; 746 boolean used; 747 Object obj; 748 int type = 0; 749 } 750 751 752 | Popular Tags |