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

Regions do not draw background insets correctly when using a Shape

    XMLWordPrintable

    Details

      Description

      When you use a shape with Region such as a Arc that is used in PieChart implementation then specify that the background insets are not 0; You expect to make bigger and smaller version of the shape. This is much the same as stroking. NGRegion & SGRegion have simple implementations that just scale the shape. They should at least scale the shape around its center. At the moment they scale around the origin, this will never look right. Below is example fix for one of the code paths to make it scale around the center. Ideally region would use the same calculations as when we calculate a stroke.

          /**
           * Create a bigger or smaller version of shape. If not resizeShape then the shape is just centered rather
           * than resized. Proportions are not maintained when resizing.
           */
          private Shape createShape(Shape shape, float topOffset, float leftOffset,
                                             float bottomOffset, float rightOffset) {
              ......
              } else if (topOffset!=0 || rightOffset!=0 || bottomOffset!=0 || leftOffset!=0) {
                  // we have to resize as well because of offsets
                  float newW = (float)bounds.getWidth() - leftOffset - rightOffset;
                  float newH = (float)bounds.getHeight() - topOffset - bottomOffset;
                  double middleX = bounds.getMinX() + (bounds.getWidth()/2);
                  double middleY = bounds.getMinY() + (bounds.getHeight()/2);
                  transform.translate(middleX,middleY);
                  transform.scale(newW / bounds.getWidth(), newH / bounds.getHeight());
                  transform.translate(-middleX, -middleY);
              }
              return transform.isIdentity() ? shape : transform.createTransformedShape(shape);
          }

        Attachments

          Activity

            People

            Assignee:
            rbair Richard Bair (Inactive)
            Reporter:
            jasper Jasper Potts (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: