[OpenJDK 2D-Dev] Pisces Dasher calculation issues
Omair Majid
omajid at redhat.com
Thu Apr 30 20:45:10 UTC 2009
Hi,
A bug was filed in the IcedTea bugzilla which pointed out a few issues
in java2d [1].
I am attaching example code and it's output to demonstrate one
particular issue. The attached program draws 5 horizontal lines with
different dash patterns. Using a BasicStroke with CAP_ROUND (or
CAP_SQUARE) and a very small value for length of the dash, no dashes are
drawn at the start of the line.
This seems to be the code responsible (Dasher.java line 221):
// ysplit = (int)(dysplit*65536.0);
// } else {
t = ((long)d << 16)/l;
xsplit = x0 + (int)(t*(x1 - x0) >> 16);
ysplit = y0 + (int)(t*(y1 - y0) >> 16);
'd' is the length of the dash, and 'l' is the distance between the
current location and the end location. Notice that the value of l
varies: as the current coordinate gets closer to the end of the line, l
becomes smaller. So if the value of d is very small, ((long)d << 16)/l
changes from 0 to a positive number. Hence dashes of length 0 are drawn
in the beginning and dashes of a non-zero length are drawn at the end of
the line.
The attached patch uses the total length of the line to calculate t, so
it wont change for the same value of d. However, this patch causes other
issues. The dash output now depends on the total length of the line. For
example, changing the size of the window in the test case changes the
value of the total length of the line. If total length becomes very
large, t becomes 0, and the dashes on the line disappear. If the window
is made small, the dashes appear on the line again.
Thanks,
Omair
[1] http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=197
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicStrokeDashTest.java
Type: text/x-java
Size: 2495 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20090430/efedc0e6/BasicStrokeDashTest.java>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dash-stroke-bug.png
Type: image/png
Size: 5192 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20090430/efedc0e6/dash-stroke-bug.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dasher-disappearing-dashes.patch
Type: text/x-patch
Size: 1592 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20090430/efedc0e6/dasher-disappearing-dashes.patch>
More information about the 2d-dev
mailing list