public Color stringToColor(final String colorNameOrHex) {
return CSS.ColorProperty.stringToColor(colorNameOrHex);
}
public AttributeSet translateHTMLToCSS(final AttributeSet htmlAttrSet) {
final Style result = addStyle(null, null);
// if (((Element)htmlAttrSet).isLeaf()) {
// return result;
// }
final Enumeration keys = htmlAttrSet.getAttributeNames();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = htmlAttrSet.getAttribute(key);
if (key instanceof CSS.Attribute) {
result.addAttribute(key, value);
} else {
Object cssKey = HTML_ATTRIBUTE_TO_CSS.get(key);
if (cssKey != null
&& ((Attribute)cssKey).getConverter() != null) {
if ((key == HTML.Attribute.HEIGHT
|| key == HTML.Attribute.WIDTH)
&& value instanceof String
&& !((String)value).endsWith("%")) {
value = ((Attribute)cssKey).getConverter()
.toCSS((String)value + /*"px"*/ "pt");
} else if (key == HTML.Attribute.BACKGROUND) {
value = ((Attribute)cssKey).getConverter()
.toCSS("url(" + value + ")");
} else {
value = ((Attribute)cssKey).getConverter().toCSS(value);
}
if (value != null) {
result.addAttribute(cssKey, value);
}
}
}
}
return result;