#18 SVG draw/fillArc, draw/fillOval Bug

open
nobody
None
5
2003-12-17
2003-12-17
cmeyers
No

I think there are two Bugs in
cwi.SVGGraphics.SVGGraphics.
draw/fillArc and draw/fillOval give different results in SVG
compared to drawing in Java.
The size is twice, orientation is wrong in draw/fillArc,
fillArc does not fill.

Please correct me if I'm wrong.

Here my fixes:

private String ovalToString(float x, float y, float width,
float height)
{
StringBuffer retval = new StringBuffer();

// in awt (x,y) is the upper left corner
// in svg (cx, cy) is the center of the ellipse

float rx = ((float)width)/2;
float ry = ((float)height)/2;

retval.append("cx=\"" + flstr(x + rx) + "\" ");
retval.append("cy=\"" + flstr(y + ry) + "\" ");
retval.append("rx=\"" + flstr(rx) + "\" ");
retval.append("ry=\"" + flstr(ry) + "\" ");
return retval.toString();
}

private String arcToString(float x, float y, float width,
float height, float startAngle, float arcAngle, boolean
close)
{
// svg definition of angle is opposite of java
startAngle = -startAngle;
arcAngle = -arcAngle;

double alpha = Math.toRadians((double)startAngle);
double beta = Math.toRadians((double)arcAngle);

double rx = width/2.0;
double ry = height/2.0;

double x1 = x + rx + rx*Math.cos(alpha);
double y1 = y + ry + ry*Math.sin(alpha);
double x2 = x + rx + rx*Math.cos(alpha+beta);
double y2 = y + ry + ry*Math.sin(alpha+beta);

StringBuffer buff = new StringBuffer();
buff.append("d=\"");
buff.append("M" + flstr(x1) + " " + flstr(y1) + " ");
buff.append("A" + flstr(rx) + " " + flstr(ry) + " 0");
buff.append( ((Math.abs(arcAngle) > 180.0) ? " 1 " : "
0 ") );
buff.append( ((arcAngle > 0.0) ? " 1 " : " 0 ") );
buff.append( flstr(x2) + " " + flstr(y2));
if( close ) buff.append(" Z");
buff.append("\"");
return buff.toString();
}

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks