vhardy 2002/09/19 00:36:50
Modified: sources/org/apache/batik/transcoder/wmf/tosvg
WMFPainter.java
Log:
Fix from Luan for his WMFPainter.java
Revision Changes Path
1.3 +123 -107
xml-batik/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java
Index: WMFPainter.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WMFPainter.java 10 Apr 2002 07:50:39 -0000 1.2
+++ WMFPainter.java 19 Sep 2002 07:36:50 -0000 1.3
@@ -40,7 +40,8 @@
* @version $Id$
* @author <a href="mailto:[EMAIL PROTECTED]">Luan O'Carroll</a>
*/
-public class WMFPainter {
+public class WMFPainter
+{
private static final String WMF_FILE_EXTENSION = ".wmf";
/**
@@ -376,18 +377,20 @@
case WMFConstants.META_RECTANGLE:
{
- int x1, y1, x2, y2;
- x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
- x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
- y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
- y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
+ int x1, y1, x2, y2;
+ x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
+ x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
+ y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
+ y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
- if ( brushObject >= 0 ) {
- setBrushColor( currentStore, g, brushObject );
- g.fillRect( x1, y1, x2-x1-1, y2-y1-1 );
- }
- setPenColor( currentStore, g, penObject );
- g.drawRect( x1, y1, x2-x1-1, y2-y1-1 );
+ if ( brushObject >= 0 ) {
+ setBrushColor( currentStore, g, brushObject );
+ g.fillRect( x1, y1, x2-x1, y2-y1 );
+ }
+ setPenColor( currentStore, g, penObject );
+
+ if ( penObject >= 0 )
+ g.drawRect( x1, y1, x2-x1, y2-y1 );
}
break;
@@ -412,17 +415,18 @@
case WMFConstants.META_ELLIPSE:
{
- int x1, y1, x2, y2;
- x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
- x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
- y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
- y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
+ int x1, y1, x2, y2;
+ x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
+ x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
+ y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
+ y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
+
+ setBrushColor( currentStore, g, brushObject );
+ if ( brushObject >= 0 )
+ g.fillOval( x1, y1, x2-x1, y2-y1 );
- if ( brushObject >= 0 ) {
- setBrushColor( currentStore, g, brushObject );
- g.fillOval( x1, y1, x2-x1, y2-y1 );
- }
- setPenColor( currentStore, g, penObject );
+ setPenColor( currentStore, g, penObject );
+ if ( penObject >= 0 )
g.drawOval( x1, y1, x2-x1-1, y2-y1-1 );
}
break;
@@ -462,7 +466,7 @@
TextLayout layout = new TextLayout( sr.text, font, frc
);
pen.y += layout.getAscent();
- if (( fontAngle != 0 ) || sr.text.startsWith("Sono una
scala verticale di prevalenza") ) {
+ if ( fontAngle != 0 ) {
AffineTransform at = new AffineTransform();
float width = (float)layout.getBounds().getWidth();
float height =
(float)layout.getBounds().getHeight();
@@ -486,26 +490,34 @@
case WMFConstants.META_ARC:
case WMFConstants.META_PIE:
{
- int x1, y1, x2, y2, x3, y3, x4, y4;
- x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
- x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
- x3 = (int)( scaleX * ( mr.ElementAt( 4 ).intValue()));
- x4 = (int)( scaleX * ( mr.ElementAt( 6 ).intValue()));
- y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
- y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
- y3 = (int)( scaleY * ( mr.ElementAt( 5 ).intValue()));
- y4 = (int)( scaleY * ( mr.ElementAt( 7 ).intValue()));
+ int x1, y1, x2, y2, x3, y3, x4, y4;
+ x1 = (int)( scaleX * ( vpX + mr.ElementAt( 0 ).intValue()));
+ x2 = (int)( scaleX * ( vpX + mr.ElementAt( 2 ).intValue()));
+ x3 = (int)( scaleX * ( mr.ElementAt( 4 ).intValue()));
+ x4 = (int)( scaleX * ( mr.ElementAt( 6 ).intValue()));
+ y1 = (int)( scaleY * ( vpY + mr.ElementAt( 1 ).intValue()));
+ y2 = (int)( scaleY * ( vpY + mr.ElementAt( 3 ).intValue()));
+ y3 = (int)( scaleY * ( mr.ElementAt( 5 ).intValue()));
+ y4 = (int)( scaleY * ( mr.ElementAt( 7 ).intValue()));
+
+ int mx = x1+(x2-x1)/2;
+ int my = y1+(y2-y1)/2;
+ int startAngle = (int)Math.toDegrees( Math.atan2(
-1.0*(y3-my), 1.0*(x3-mx)));
+ int endAngle = (int)Math.toDegrees( Math.atan2( -1.0*(y4-my),
1.0*(x4-mx)));
+ if ( mr.functionId == 0x081A ) {
setBrushColor( currentStore, g, brushObject );
-
- int mx = x1+(x2-x1)/2;
- int my = y1+(y2-y1)/2;
- int startAngle = (int)Math.atan( (y3-my)/(x3-mx));
- int endAngle = (int)Math.atan( (y4-my)/(x4-mx));
- if ( mr.functionId == 0x0817 )
- g.drawArc( x1, y1, x2-x1, y2-y1, startAngle, endAngle );
- else
- g.fillArc( x1, y1, x2-x1, y2-y1, startAngle, endAngle );
-
+ if ( brushObject >= 0 )
+ g.fillArc( x1, y1, x2-x1, y2-y1, startAngle, endAngle );
+ }
+
+ setPenColor( currentStore, g, penObject );
+ if ( startAngle < 0 ) startAngle = 360+startAngle;
+ if ( endAngle < 0 ) endAngle = 360+endAngle;
+ int len = Math.abs( endAngle - startAngle );
+ if ( endAngle < startAngle )
+ len = 360 - startAngle + endAngle;
+ if ( penObject >= 0 )
+ g.drawArc( x1, y1, x2-x1, y2-y1, startAngle, len );
}
break;
@@ -623,26 +635,30 @@
}
}
- private void setPenColor( RecordStore currentStore, Graphics g, int penObject) {
- if ( penObject >= 0 ) {
- GdiObject gdiObj = currentStore.getObject( penObject );
- g.setColor( (Color)gdiObj.obj );
- penObject = -1;
- }
+ private void setPenColor( RecordStore currentStore, Graphics g, int penObject)
+ {
+ if ( penObject >= 0 ) {
+ GdiObject gdiObj = currentStore.getObject( penObject );
+ g.setColor( (Color)gdiObj.obj );
+ //penObject = -1;
+ }
}
- private void setBrushColor( RecordStore currentStore, Graphics g, int
brushObject) {
- if ( brushObject >= 0 ) {
- GdiObject gdiObj = currentStore.getObject( brushObject );
- g.setColor( (Color)gdiObj.obj );
- brushObject = -1;
- }
+
+ private void setBrushColor( RecordStore currentStore, Graphics g, int
brushObject)
+ {
+ if ( brushObject >= 0 ) {
+ GdiObject gdiObj = currentStore.getObject( brushObject );
+ g.setColor( (Color)gdiObj.obj );
+ //brushObject = -1;
+ }
}
/**
* Sets the RecordStore this WMFPainter should use to render
*/
- public void setRecordStore(RecordStore currentStore){
+ public void setRecordStore(RecordStore currentStore)
+ {
if(currentStore == null){
throw new IllegalArgumentException();
}
@@ -681,68 +697,68 @@
class MetaRecord /*implements Serializable*/
{
- public int functionId;
- public int numPoints;
+ public int functionId;
+ public int numPoints;
+
+ private Vector ptVector;
+
+ public MetaRecord()
+ {
+ ptVector = new Vector();
+ }
- private Vector ptVector;
+ public void EnsureCapacity( int cc )
+ {
+ ptVector.ensureCapacity( cc );
+ }
+
+ public void AddElement( Object obj )
+ {
+ ptVector.addElement( obj );
+ }
- public MetaRecord()
- {
- ptVector = new Vector();
- }
-
- public void EnsureCapacity( int cc )
- {
- ptVector.ensureCapacity( cc );
- }
-
- public void AddElement( Object obj )
- {
- ptVector.addElement( obj );
- }
-
- public Integer ElementAt( int offset )
- {
- return (Integer)ptVector.elementAt( offset );
- }
+ public Integer ElementAt( int offset )
+ {
+ return (Integer)ptVector.elementAt( offset );
+ }
}
class StringRecord extends MetaRecord /*implements Serializable*/
{
- public String text;
+ public String text;
- public StringRecord( String newText )
- {
- text = new String( newText );
- }
+ public StringRecord( String newText )
+ {
+ text = new String( newText );
+ }
}
class GdiObject /*implements Serializable*/
{
- GdiObject( int _id, boolean _used )
- {
- id = _id;
- used = _used;
- type = 0;
- }
-
- public void Clear()
- {
- used = false;
- type = 0;
- }
-
- public void Setup( int _type, Object _obj )
- {
- obj = _obj;
- type = _type;
- used = true;
- }
-
- int id;
- boolean used;
- Object obj;
- int type = 0;
+ GdiObject( int _id, boolean _used )
+ {
+ id = _id;
+ used = _used;
+ type = 0;
+ }
+
+ public void Clear()
+ {
+ used = false;
+ type = 0;
+ }
+
+ public void Setup( int _type, Object _obj )
+ {
+ obj = _obj;
+ type = _type;
+ used = true;
+ }
+
+ int id;
+ boolean used;
+ Object obj;
+ int type = 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]