Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4394805

fillPolygon doesn't fill properly when called on a nested component's graphics

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      04
    • CPU:
      x86
    • OS:
      windows_nt

      Backports

        Description



        Name: boT120536 Date: 12/04/2000


        3 Dec 2000, eval112&@eng -- looks the same between 1.1.8_005 and 1.3.0 here.
        ------------
        Java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

        This code is stripped down from a object based drawing program that is an
        integral part of our product. We used to be developing in 1.1.6, and this code
        works fine there. Now in 1.2.2 or 1.3 the blue polygon is no longer filled
        correctly. Thanks in advance for your help!

        import javax.swing.JFrame;
        import javax.swing.JComponent;
        import java.awt.Graphics;
        import java.awt.Polygon;
        import java.awt.Color;

        public class TestPolyFill extends JFrame
        {
            Polygon p2 = new Polygon(
                    new int[]{57,104,0,57,57,11,95,57},
                    new int[]{0,79,106,0,12,97,76,12}, 8);

            class PolyWidget extends JComponent
            {
                Polygon p = new Polygon(
                    new int[]{57,104,0,57,57,11,95,57},
                    new int[]{0,79,106,0,12,97,76,12}, 8);

                public void paint(Graphics g)
                {
                    g.setColor(Color.blue);
                    g.setPaintMode();
                    g.fillPolygon(p);
                }
            }

            public TestPolyFill()
            {
                p2.translate(40,40);
                PolyWidget pw = new PolyWidget();
                getContentPane().setLayout(null);
                getContentPane().add(pw);
                pw.setBounds(220,20,130,130);
            }

            public void paint(Graphics g)
            {
                super.paint(g);

                g.setColor(Color.green);
                g.setPaintMode();
                g.fillPolygon(p2);
            }

            public static void main(String args[])
            {
                TestPolyFill frame = new TestPolyFill();
                frame.setSize(400,200);
                frame.setVisible(true);
            }
        }
        (Review ID: 111497)
        ======================================================================

        Name: boT120536 Date: 12/05/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
        ========================================================================
        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Classic VM (build 1.3.0-C, native threads, nojit)
        ========================================================================
        java version "1.2"
        HotSpot VM (1.0.1, mixed mode, build g)


        Some polygons are not filled correctly when using fillPolygon on an off-screen
        image. More specifically, the image is a sun.awt.image.OffScreenImage and its
        graphics context is a sun.awt.image.BufferedImageGraphics2D

        It seems to happen when a polygon is partially degenerate, i.e. when
        it has some coincident edges. In principle, the odd-even rule should handle
        these cases without any problems.

        The problem only occurs on Windows NT, not on Solaris.
        It happens in JDK 1.2, as well as JDK 1.3.0.
        Although this bug may be related to bug #4202279, the problem cases and the
        environments appear to be different.

        For example:


        import java.awt.*;

        public class Test extends Component {

          private static final int x[] = new int[] { 140, 310, 310, 310, 245, 90, 145, 90 };
          private static final int y[] = new int[] { 70, 130, 100, 130, 305, 305, 255, 205 };
          private static final int count = x.length;

          public void paint(Graphics g) {

            // We're drawing to an off-screen image.
            Image image = this.createImage(400, 400);
            Graphics image_graphics = image.getGraphics();

            // Fill the polygon.
            image_graphics.setColor(Color.cyan);
            image_graphics.fillPolygon(x, y, count);

            // Draw its outlines, so we can compare.
            image_graphics.setColor(Color.red);
            image_graphics.drawPolygon(x, y, count);

            // Now paint the image to the screen.
            g.drawImage(image, 0, 0, Color.black, null);

            image_graphics.dispose();
            image.flush();
          }

          public static void main(String[] args) {
            Component test = new Test();

            Frame frame = new Frame("Polygon Fill Test");
            frame.add(test, BorderLayout.CENTER);
            frame.setSize(400, 400);
            frame.setVisible(true);
          }
        }
        (Review ID: 111565)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  flar Jim Graham
                  Reporter:
                  bonealsunw Bret O'neal (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: