提交 c7b8baac 编写于 作者: R rpatil

8208638: Instead of circle rendered in appl window, but ellipse is produced JEditor Pane

Reviewed-by: serb, psadhukhan
上级 7c590ec4
...@@ -734,20 +734,6 @@ public class ImageView extends View { ...@@ -734,20 +734,6 @@ public class ImageView extends View {
newState |= HEIGHT_FLAG; newState |= HEIGHT_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: // Make sure the image starts loading:
if ((newState & (WIDTH_FLAG | HEIGHT_FLAG)) != 0) { if ((newState & (WIDTH_FLAG | HEIGHT_FLAG)) != 0) {
Toolkit.getDefaultToolkit().prepareImage(newImage, newWidth, Toolkit.getDefaultToolkit().prepareImage(newImage, newWidth,
...@@ -909,6 +895,34 @@ public class ImageView extends View { ...@@ -909,6 +895,34 @@ public class ImageView extends View {
changed |= 2; changed |= 2;
} }
/**
* If the image properties (height and width) have been loaded,
* tehn 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) { synchronized(ImageView.this) {
if ((changed & 1) == 1 && (state & HEIGHT_FLAG) == 0) { if ((changed & 1) == 1 && (state & HEIGHT_FLAG) == 0) {
height = newHeight; height = newHeight;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 8195095 * @bug 8195095 8208638
* @summary Tests if Images are scaled correctly in JEditorPane. * @summary Tests if Images are scaled correctly in JEditorPane.
* @run main ImageViewTest * @run main ImageViewTest
*/ */
...@@ -39,25 +39,23 @@ import javax.swing.WindowConstants; ...@@ -39,25 +39,23 @@ import javax.swing.WindowConstants;
public class ImageViewTest { public class ImageViewTest {
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
private static JFrame f; private static JFrame f;
private static JEditorPane editorPane1; private static void test(Robot r, JEditorPane editorPane,
private static JEditorPane editorPane2; final int WIDTH, final int HEIGHT ) throws Exception {
private static JEditorPane editorPane3;
private static JEditorPane editorPane4;
private static void test(Robot r, JEditorPane editorPane) throws Exception {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
f = new JFrame(); f = new JFrame();
editorPane.setEditable(false); editorPane.setEditable(false);
f.add(editorPane); f.add(editorPane);
f.setSize(220,240); f.setSize(WIDTH + 20, HEIGHT + 40);
f.setLocationRelativeTo(null); f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 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); f.setVisible(true);
}); });
...@@ -108,34 +106,78 @@ public class ImageViewTest { ...@@ -108,34 +106,78 @@ public class ImageViewTest {
Robot r = new Robot(); Robot r = new Robot();
final JEditorPane[] editorPanes = new JEditorPane[11];
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
editorPane1 = new JEditorPane("text/html", editorPanes[0] = new JEditorPane("text/html",
"<img height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\""); "<img height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPane2 = new JEditorPane("text/html", editorPanes[1] = new JEditorPane("text/html",
"<img width=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\""); "<img width=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPane3 = new JEditorPane("text/html", editorPanes[2] = new JEditorPane("text/html",
"<img width=\"200\" height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\""); "<img width=\"200\" height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPane4 = new JEditorPane("text/html", editorPanes[3] = new JEditorPane("text/html",
"<img src=\"file:///" + ABSOLUTE_FILE_PATH + "\""); "<img src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[4] = new JEditorPane("text/html",
"<img width=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[5] = new JEditorPane("text/html",
"<img height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[6] = new JEditorPane("text/html",
"<img width=\"100\" height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[7] = new JEditorPane("text/html",
"<img width=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[8] = new JEditorPane("text/html",
"<img height=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[9] = new JEditorPane("text/html",
"<img width=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
editorPanes[10] = new JEditorPane("text/html",
"<img height=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");
}); });
r.waitForIdle(); r.waitForIdle();
System.out.println("Test with only height set to 200"); System.out.println("Test with only height set to 200");
test(r, editorPane1); test(r, editorPanes[0], 200, 200);
System.out.println("Test with only width set to 200"); System.out.println("Test with only width set to 200");
test(r, editorPane2); test(r, editorPanes[1], 200, 200);
System.out.println("Test with both of them set");
test(r, editorPanes[2], 200, 200);
System.out.println("Test with none of them set to 200");
test(r, editorPanes[3], 200, 200);
System.out.println("Test with only width set to 100");
test(r, editorPanes[4], 100, 100);
System.out.println("Test with only height set to 100");
test(r, editorPanes[5], 100, 100);
System.out.println("Test with both width and height set to 100");
test(r, editorPanes[6], 100, 100);
System.out.println("Test with only width set to 50");
test(r, editorPanes[7], 50, 50);
System.out.println("Test with only height set to 50");
test(r, editorPanes[8], 50, 50);
System.out.println("Test with none of them set"); System.out.println("Test with only width set to 300");
test(r, editorPane3); test(r, editorPanes[9], 300, 300);
System.out.println("Test with both of them set to 200"); System.out.println("Test with only height set to 300");
test(r, editorPane4); test(r, editorPanes[10], 300, 300);
System.out.println("Test Passed."); System.out.println("Test Passed.");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册