if ("".equals(name))
return Color.NONE;
try {
// Try hex string first
String str = name.startsWith("#") ? name : "#" + name;
return new RGBColor(java.awt.Color.decode(str));
} catch (Exception e1) {
try {
// If that does not work, try accessing the static Color.NAME field
Field field = java.awt.Color.class.getField(name.toUpperCase());
return new RGBColor((java.awt.Color) field.get(java.awt.Color.class));
} catch (Exception e2) {
}
}
} else if (reader.isArray()) {
int size = reader.size();
if (size == 4) {
// CMYK
return new CMYKColor(
reader.readFloat(0),
reader.readFloat(0),
reader.readFloat(0),
reader.readFloat(0)
);
} else if (size == 3) {
// RGB
return new RGBColor(
reader.readFloat(0),
reader.readFloat(0),
reader.readFloat(0)
);
} else if (size == 1) {
// Gray
return new GrayColor(
reader.readFloat(0)
);
}
} else if (reader.isMap()) {
if (reader.has("red")) {
return new RGBColor(
reader.readFloat("red", 0),
reader.readFloat("green", 0),
reader.readFloat("blue", 0),
reader.readFloat("alpha", 1)
);