static void parseShorthandFont(CSS css,
String value,
MutableAttributeSet attr) {
// font is of the form:
// [ < font-style > || < font-variant > || < font-weight > ]? < font-size >
// [ / < line-height > ]? < font-family >
String[] strings = CSS.parseStrings(value);
int count = strings.length;
int index = 0;
// bitmask, 1 for style, 2 for variant, 3 for weight
short found = 0;
int maxC = Math.min(3, count);
// Check for font-style font-variant font-weight
while (index < maxC) {
if ((found & 1) == 0 && isFontStyle(strings[index])) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_STYLE,
strings[index++]);
found |= 1;
}
else if ((found & 2) == 0 && isFontVariant(strings[index])) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_VARIANT,
strings[index++]);
found |= 2;
}
else if ((found & 4) == 0 && isFontWeight(strings[index])) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_WEIGHT,
strings[index++]);
found |= 4;
}
else if (strings[index].equals("normal")) {
index++;
}
else {
break;
}
}
if ((found & 1) == 0) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_STYLE,
"normal");
}
if ((found & 2) == 0) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_VARIANT,
"normal");
}
if ((found & 4) == 0) {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_WEIGHT,
"normal");
}
// string at index should be the font-size
if (index < count) {
String fontSize = strings[index];
int slashIndex = fontSize.indexOf('/");
if (slashIndex != -1) {
fontSize = fontSize.substring(0, slashIndex);
strings[index] = strings[index].substring(slashIndex);
}
else {
index++;
}
css.addInternalCSSValue(attr, CSS.Attribute.FONT_SIZE,
fontSize);
}
else {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_SIZE,
"medium");
}
// Check for line height
if (index < count && strings[index].startsWith("/")) {
String lineHeight = null;
if (strings[index].equals("/")) {
if (++index < count) {
lineHeight = strings[index++];
}
}
else {
lineHeight = strings[index++].substring(1);
}
// line height
if (lineHeight != null) {
css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
lineHeight);
}
else {
css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
"normal");
}
}
else {
css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
"normal");
}
// remainder of strings are font-family
if (index < count) {
String family = strings[index++];
while (index < count) {
family += " " + strings[index++];
}
css.addInternalCSSValue(attr, CSS.Attribute.FONT_FAMILY,
family);
}
else {
css.addInternalCSSValue(attr, CSS.Attribute.FONT_FAMILY,
Font.SANS_SERIF);
}
}
Parses the shorthand font string value, placing the
result in attr. |