if (ident == IdentValue.NORMAL) { // skip to avoid double set false positives
continue;
}
if (PrimitivePropertyBuilders.FONT_STYLES.get(ident.FS_ID)) {
if (fontStyle != null) {
throw new CSSParseException("font-style cannot be set twice", -1);
}
fontStyle = new PropertyDeclaration(CSSName.FONT_STYLE, value, important, origin);
} else if (PrimitivePropertyBuilders.FONT_VARIANTS.get(ident.FS_ID)) {
if (fontVariant != null) {
throw new CSSParseException("font-variant cannot be set twice", -1);
}
fontVariant = new PropertyDeclaration(CSSName.FONT_VARIANT, value, important, origin);
} else if (PrimitivePropertyBuilders.FONT_WEIGHTS.get(ident.FS_ID)) {
if (fontWeight != null) {
throw new CSSParseException("font-weight cannot be set twice", -1);
}
fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, value, important, origin);
} else {
keepGoing = true;
break;
}
} else if (type == CSSPrimitiveValue.CSS_NUMBER && value.getFloatValue() > 0) {
if (fontWeight != null) {
throw new CSSParseException("font-weight cannot be set twice", -1);
}
IdentValue weight = Conversions.getNumericFontWeight(value.getFloatValue());
if (weight == null) {
throw new CSSParseException(value + " is not a valid font weight", -1);
}
PropertyValue replacement = new PropertyValue(
CSSPrimitiveValue.CSS_IDENT, weight.toString(), weight.toString());
replacement.setIdentValue(weight);
fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, replacement, important, origin);
} else {
keepGoing = true;
break;
}
}
if (keepGoing) {
i.previous();
PropertyValue value = (PropertyValue)i.next();
if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
String lowerCase = value.getStringValue().toLowerCase();
value = new PropertyValue(CSSPrimitiveValue.CSS_IDENT, lowerCase, lowerCase);
}
PropertyBuilder fontSizeBuilder = CSSName.getPropertyBuilder(CSSName.FONT_SIZE);
List l = fontSizeBuilder.buildDeclarations(
CSSName.FONT_SIZE, Collections.singletonList(value), origin, important);
fontSize = (PropertyDeclaration)l.get(0);
if (i.hasNext()) {
value = (PropertyValue)i.next();
if (value.getOperator() == Token.TK_VIRGULE) {
PropertyBuilder lineHeightBuilder = CSSName.getPropertyBuilder(CSSName.LINE_HEIGHT);
l = lineHeightBuilder.buildDeclarations(
CSSName.LINE_HEIGHT, Collections.singletonList(value), origin, important);
lineHeight = (PropertyDeclaration)l.get(0);
} else {
i.previous();
}
}
if (i.hasNext()) {
List families = new ArrayList();
while (i.hasNext()) {
families.add(i.next());
}
PropertyBuilder fontFamilyBuilder = CSSName.getPropertyBuilder(CSSName.FONT_FAMILY);
l = fontFamilyBuilder.buildDeclarations(
CSSName.FONT_FAMILY, families, origin, important);
fontFamily = (PropertyDeclaration)l.get(0);
}
}
if (fontStyle == null) {
fontStyle = new PropertyDeclaration(
CSSName.FONT_STYLE, new PropertyValue(IdentValue.NORMAL), important, origin);
}
if (fontVariant == null) {
fontVariant = new PropertyDeclaration(
CSSName.FONT_VARIANT, new PropertyValue(IdentValue.NORMAL), important, origin);
}
if (fontWeight == null) {
fontWeight = new PropertyDeclaration(
CSSName.FONT_WEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);
}
if (fontSize == null) {
throw new CSSParseException("A font-size value is required", -1);
}
if (lineHeight == null) {
lineHeight = new PropertyDeclaration(
CSSName.LINE_HEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);