Interesting.
So if I wanted the fill and draw of the same shape to align properly, I
should stick to one type of Paint?
I coded up a simple test (code is below my signature) with 4 draw/fill
combinations of Color and GradientPaint.
Fill/Draw status
------------------------------------------------
Color/Color fine
Gradient/Color appears to be fine**
Color/Gradient gaps and overlaps under some conditions
Gradient/Gradient gaps and overlaps under some conditions
**Color/Color is the only one that is properly aligned on my charts.
There are gaps/overlaps with Gradient/Color, and your comments below
apply to this condition.
So it appears that I have a problem if I want to use GradientPaint. Any
insights? Thanks...
-Brian
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class DrawFillTestFrame extends JFrame {
public DrawFillTestFrame() throws HeadlessException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
double w = getWidth();
double h = getHeight();
g2.translate(0.53434, 0.55455);
Rectangle2D r1 = new Rectangle2D.Double(.05 * w, .05 *
h, .40 * w, .40 * h);
Rectangle2D r2 = new Rectangle2D.Double(.55 * w, .05 *
h, .40 * w, .40 * h);
Rectangle2D r3 = new Rectangle2D.Double(.05 * w, .55 *
h, .40 * w, .40 * h);
Rectangle2D r4 = new Rectangle2D.Double(.55 * w, .55 *
h, .40 * w, .40 * h);
// Rectangle2D r1 = new Rectangle2D.Double(10.1234,
10.5353, 200.81242, 100.18989);
// Rectangle2D r2 = new Rectangle2D.Double(220.25235,
10.9134, 200.989385, 100.324344);
// Rectangle2D r3 = new Rectangle2D.Double(10.91284,
120.123123, 200.982983, 100.12321);
// Rectangle2D r4 = new Rectangle2D.Double(220.09823,
120.1232, 200.89498, 100.12323);
g2.setPaint(Color.red);g2.fill(r1);g2.setPaint(Color.black);g2.draw(r1);
GradientPaint gp = new GradientPaint(1, 10, Color.black,
0, 400, Color.yellow);
GradientPaint gp2 = new GradientPaint(1, 10,
Color.black, 0, 400, Color.lightGray);
g2.setPaint(gp);g2.fill(r2);g2.setPaint(Color.red);g2.draw(r2);
g2.setPaint(gp);g2.fill(r3);g2.setPaint(gp2);g2.draw(r3);
g2.setPaint(Color.red);g2.fill(r4);g2.setPaint(gp2);g2.draw(r4);
}
};
panel.setBackground(Color.white);
panel.setPreferredSize(new Dimension(450, 250));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
pack();
}
public static void main(String[] args) {
DrawFillTestFrame frame = new DrawFillTestFrame();
frame.show();
}
}
-----Original Message-----
From: Discussion list for Java 2D API
[mailto:[EMAIL PROTECTED] On Behalf Of Jim Graham
Sent: Thursday, February 12, 2004 3:15 PM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA2D] draw/fill mismatch on 1.4.2_02
> Rectangle2D bar = ...;
> g2.setPaint(gradientPaint);
> g2.fill(bar);
> g2.setColor(Color.black);
> g2.draw(bar);
The issue here is that we could use completely different implementations
to handle gradients vs. solid colors and while each of those pipelines
enforces consistency between its own fills and draws, they may do so in
different ways.
In particular, if this is drawing to the screen or to an accelerated
offscreen, the draw with the black color may be handled by GDI or X11 or
some other platform rendering API, but the Gradients are not handled
directly by most of those platform APIs so we need to switch to software
to do it. Most of the platform APIs use "round subpixel coordinates to
the nearest integer because the API only allows int coordinates in the
first place" as their technique for controlling the stroke consistency
whereas our software renderers use a more sophisticated "normalize the
coords to a specific sub-pixel offset that will tend to create less
pigeon-holing of wide-line widths" (similar to the processing done to
improve consistency of strokes in other floating-point capable rendering
APIs)...
...jim
========================================================================
===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body of the message "signoff JAVA2D-INTEREST". For general help, send
email to [EMAIL PROTECTED] and include in the body of the message
"help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".