changeset 52237:170e876d529c

Merge
author prr
date Thu, 27 Sep 2018 11:46:28 -0700
parents afb3c0884bf1 2105d8064ca2
children b5afdf0bbd9e
files
diffstat 2 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java	Thu Sep 27 11:39:45 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java	Thu Sep 27 11:46:28 2018 -0700
@@ -776,32 +776,10 @@
 
             if (newWidth > 0) {
                 newState |= WIDTH_FLAG;
-                if (newHeight <= 0) {
-                    newHeight = newWidth;
-                    newState |= HEIGHT_FLAG;
-                }
             }
 
             if (newHeight > 0) {
                 newState |= HEIGHT_FLAG;
-                if (newWidth <= 0) {
-                    newWidth = newHeight;
-                    newState |= WIDTH_FLAG;
-                }
-            }
-
-            if (newWidth <= 0) {
-                newWidth = newImage.getWidth(imageObserver);
-                if (newWidth <= 0) {
-                    newWidth = DEFAULT_WIDTH;
-                }
-            }
-
-            if (newHeight <= 0) {
-                newHeight = newImage.getHeight(imageObserver);
-                if (newHeight <= 0) {
-                    newHeight = DEFAULT_HEIGHT;
-                }
             }
 
             // Make sure the image starts loading:
@@ -965,6 +943,35 @@
                     changed |= 2;
                 }
 
+                /**
+                 * If the image properties (height and width) have been loaded,
+                 * then figure out if scaling is necessary based on the
+                 * specified HTML attributes.
+                 */
+                if (((flags & ImageObserver.HEIGHT) != 0) &&
+                    ((flags & ImageObserver.WIDTH) != 0)) {
+                    double proportion = 0.0;
+                    final int specifiedWidth = getIntAttr(HTML.Attribute.WIDTH, -1);
+                    final int specifiedHeight = getIntAttr(HTML.Attribute.HEIGHT, -1);
+                    /**
+                     * If either of the attributes are not specified, then calculate the
+                     * proportion for the specified dimension wrt actual value, and then
+                     * apply the same proportion to the unspecified dimension as well,
+                     * so that the aspect ratio of the image is maintained.
+                     */
+                    if (specifiedWidth != -1 ^ specifiedHeight != -1) {
+                        if (specifiedWidth <= 0) {
+                            proportion = specifiedHeight / ((double)newHeight);
+                            newWidth = (int)(proportion * newWidth);
+                        }
+
+                        if (specifiedHeight <= 0) {
+                            proportion = specifiedWidth / ((double)newWidth);
+                            newHeight = (int)(proportion * newHeight);
+                        }
+                        changed |= 3;
+                    }
+                }
                 synchronized(ImageView.this) {
                     if ((changed & 1) == 1 && (state & HEIGHT_FLAG) == 0) {
                         height = newHeight;
--- a/test/jdk/javax/swing/JEditorPane/8195095/ImageViewTest.java	Thu Sep 27 11:39:45 2018 -0700
+++ b/test/jdk/javax/swing/JEditorPane/8195095/ImageViewTest.java	Thu Sep 27 11:46:28 2018 -0700
@@ -24,7 +24,7 @@
 /**
  * @test
  * @key headful
- * @bug 8195095 8206238
+ * @bug 8195095 8206238 8208638
  * @summary Tests if Images are scaled correctly in JEditorPane.
  * @run main ImageViewTest
  */
@@ -51,8 +51,11 @@
             f.add(editorPane);
             f.setSize(WIDTH + 20, HEIGHT + 40);
             f.setLocationRelativeTo(null);
-
             f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+            //This line will trigger the imageupdate, and consequently, the view
+            //will be populated with the appropriate color when the pixel color
+            //is queried by robot.
+            editorPane.getUI().getPreferredSize(editorPane);
             f.setVisible(true);
         });