if (values.size() == 1) {
CSSPrimitiveValue value = (CSSPrimitiveValue)values.get(0);
checkInheritAllowed(value, inheritAllowed);
if (value.getCssValueType() == CSSPrimitiveValue.CSS_INHERIT) {
return Collections.singletonList(
new PropertyDeclaration(cssName, value, important, origin));
}
}
// Both Opera and Firefox parse "Century Gothic" Arial sans-serif as
// [Century Gothic], [Arial sans-serif] (i.e. the comma is assumed
// after a string). Seems wrong per the spec, but FF (at least)
// does it in standards mode so we do too.
List consecutiveIdents = new ArrayList();
List normalized = new ArrayList(values.size());
for (Iterator i = values.iterator(); i.hasNext(); ) {
PropertyValue value = (PropertyValue)i.next();
Token operator = value.getOperator();
if (operator != null && operator != Token.TK_COMMA) {
throw new CSSParseException("Invalid font-family definition", -1);
}
if (operator != null) {
if (consecutiveIdents.size() > 0) {
normalized.add(concat(consecutiveIdents, ' '));
consecutiveIdents.clear();
}
}
checkInheritAllowed(value, false);
short type = value.getPrimitiveType();
if (type == CSSPrimitiveValue.CSS_STRING) {
if (consecutiveIdents.size() > 0) {
normalized.add(concat(consecutiveIdents, ' '));
consecutiveIdents.clear();
}
normalized.add(value.getStringValue());
} else if (type == CSSPrimitiveValue.CSS_IDENT) {
consecutiveIdents.add(value.getStringValue());
} else {
throw new CSSParseException("Invalid font-family definition", -1);
}
}
if (consecutiveIdents.size() > 0) {
normalized.add(concat(consecutiveIdents, ' '));
}
String text = concat(normalized, ',');
PropertyValue result = new PropertyValue(
CSSPrimitiveValue.CSS_STRING, text, text); // HACK cssText can be wrong
result.setStringArrayValue((String[]) normalized.toArray(new String[normalized.size()]));
return Collections.singletonList(
new PropertyDeclaration(cssName, result, important, origin));
}