提交 3dc07b8c 编写于 作者: R rupashka

7030332: Default borders in tables looks incorrect JEditorPane

Reviewed-by: peterz
上级 31d11eaa
......@@ -806,15 +806,11 @@ public class CSS implements Serializable {
// translate border width into the cells, if it has non-zero value.
AttributeSet tableAttr = elem.getParentElement().
getParentElement().getAttributes();
int borderWidth;
try {
borderWidth = Integer.parseInt(
(String) tableAttr.getAttribute(HTML.Attribute.BORDER));
} catch (NumberFormatException e) {
borderWidth = 0;
}
int borderWidth = getTableBorder(tableAttr);
if (borderWidth > 0) {
translateAttribute(HTML.Attribute.BORDER, tableAttr, cssAttrSet);
// If table contains the BORDER attribute cells should have border width equals 1
translateAttribute(HTML.Attribute.BORDER, "1", cssAttrSet);
}
String pad = (String)tableAttr.getAttribute(HTML.Attribute.CELLPADDING);
if (pad != null) {
......@@ -850,6 +846,21 @@ public class CSS implements Serializable {
return cssAttrSet;
}
private static int getTableBorder(AttributeSet tableAttr) {
String borderValue = (String) tableAttr.getAttribute(HTML.Attribute.BORDER);
if (borderValue == HTML.NULL_ATTRIBUTE_VALUE || "".equals(borderValue)) {
// Some browsers accept <TABLE BORDER> and <TABLE BORDER=""> with the same semantics as BORDER=1
return 1;
}
try {
return Integer.parseInt(borderValue);
} catch (NumberFormatException e) {
return 0;
}
}
private static final Hashtable<String, Attribute> attributeMap = new Hashtable<String, Attribute>();
private static final Hashtable<String, Value> valueMap = new Hashtable<String, Value>();
......@@ -1400,17 +1411,20 @@ public class CSS implements Serializable {
}
}
} else {
/*
* The html size attribute has a mapping in the CSS world only
* if it is par of a font or base font tag.
*/
if (key == HTML.Attribute.SIZE && !isHTMLFontTag(tag)) {
continue;
/*
* The html size attribute has a mapping in the CSS world only
* if it is par of a font or base font tag.
*/
} else if (tag == HTML.Tag.TABLE && key == HTML.Attribute.BORDER) {
int borderWidth = getTableBorder(htmlAttrSet);
if (borderWidth > 0) {
translateAttribute(HTML.Attribute.BORDER, Integer.toString(borderWidth), cssAttrSet);
}
} else {
translateAttribute(key, (String) htmlAttrSet.getAttribute(key), cssAttrSet);
}
translateAttribute(key, htmlAttrSet, cssAttrSet);
}
} else if (name instanceof CSS.Attribute) {
cssAttrSet.addAttribute(name, htmlAttrSet.getAttribute(name));
......@@ -1419,7 +1433,7 @@ public class CSS implements Serializable {
}
private void translateAttribute(HTML.Attribute key,
AttributeSet htmlAttrSet,
String htmlAttrValue,
MutableAttributeSet cssAttrSet) {
/*
* In the case of all remaining HTML.Attribute's they
......@@ -1427,8 +1441,6 @@ public class CSS implements Serializable {
*/
CSS.Attribute[] cssAttrList = getCssAttribute(key);
String htmlAttrValue = (String)htmlAttrSet.getAttribute(key);
if (cssAttrList == null || htmlAttrValue == null) {
return;
}
......
......@@ -242,7 +242,8 @@ import javax.swing.text.*;
if (lv != null) {
cellSpacing = (int) lv.getValue();
} else {
cellSpacing = 0;
// Default cell spacing equals 2
cellSpacing = 2;
}
lv = (CSS.LengthValue)
attr.getAttribute(CSS.Attribute.BORDER_TOP_WIDTH);
......@@ -251,8 +252,7 @@ import javax.swing.text.*;
} else {
borderWidth = 0;
}
}
}
}
/**
......
<html>
<body>
<applet code="bug7030332.class" width=600 height=400></applet>
Compare Golden Images with rendered JEditorPane.
They should looks simalar in each line. Pay attention to:
1. Border width around tables
2. Border width around cells
</body>
</html>
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@bug 7030332
@summary Default borders in tables looks incorrect JEditorPane
@author Pavel Porvatov
* @run applet/manual=yesno bug7030332.html
*/
import javax.swing.*;
import java.awt.*;
import java.net.URL;
public class bug7030332 extends JApplet {
public static final String[] HTML_SAMPLES = new String[]{
"<table border><tr><th>Column1</th><th>Column2</th></tr></table>",
"<table border=\"\"><tr><th>Column1</th><th>Column2</th></tr></table>",
"<table border=\"1\"><tr><th>Column1</th><th>Column2</th></tr></table>",
"<table border=\"2\"><tr><th>Column1</th><th>Column2</th></tr></table>",
};
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setContentPane(createContentPane());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setContentPane(createContentPane());
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static Container createContentPane() {
JPanel result = new JPanel(new GridLayout(HTML_SAMPLES.length + 1, 3, 10, 10));
result.add(new JLabel("Html code"));
result.add(new JLabel("Golden image"));
result.add(new JLabel("JEditorPane"));
for (int i = 0; i < HTML_SAMPLES.length; i++) {
String htmlSample = HTML_SAMPLES[i];
JTextArea textArea = new JTextArea(htmlSample);
textArea.setLineWrap(true);
result.add(textArea);
String imageName = "sample" + i + ".png";
URL resource = bug7030332.class.getResource(imageName);
result.add(resource == null ? new JLabel(imageName + " not found") :
new JLabel(new ImageIcon(resource), SwingConstants.LEFT));
result.add(new JEditorPane("text/html", htmlSample));
}
return result;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册