fs = fs * ctx.getUserAgent().getPixelToMM() * 72f / 25.4f;
result.put(TextAttribute.SIZE, new Float(fs));
// Font family
CSSValueList ff = (CSSValueList)cssDecl.getPropertyCSSValue
(CSS_FONT_FAMILY_PROPERTY);
String s = null;
for (int i = 0; s == null && i < ff.getLength(); i++) {
v = (CSSPrimitiveValue)ff.item(i);
s = (String)fonts.get(v.getStringValue());
}
s = (s == null) ? "SansSerif" : s;
result.put(TextAttribute.FAMILY, s);
// Font weight
// TODO: improve support for relative values
// (e.g. "lighter", "bolder")
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_FONT_WEIGHT_PROPERTY);
if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
if (v.getStringValue().charAt(0) == 'n') {
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_REGULAR);
} else if (v.getStringValue().charAt(0) == 'l') {
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_LIGHT);
} else {
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_BOLD);
}
} else {
switch ((int)v.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)) {
case 100:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_EXTRA_LIGHT);
break;
case 200:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_LIGHT);
break;
case 300:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_DEMILIGHT);
break;
case 400:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_REGULAR);
break;
case 500:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_SEMIBOLD);
break;
case 600:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_DEMIBOLD);
break;
case 700:
result.put(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_BOLD);
break;
case 800:
result.put(TextAttribute.WEIGHT,
//TextAttribute.WEIGHT_EXTRABOLD);
TextAttribute.WEIGHT_BOLD);
break;
case 900:
result.put(TextAttribute.WEIGHT,
//TextAttribute.WEIGHT_ULTRABOLD);
TextAttribute.WEIGHT_BOLD);
}
}
// Text baseline adjustment.
// TODO: support for <percentage> and <length> values.
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_BASELINE_SHIFT_PROPERTY);
if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
s = v.getStringValue();
switch (s.charAt(2)) {
case 'p': //suPerscript
result.put(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUPER);
break;
case 'b': //suBscript
result.put(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB);
break;
case 's': //baSeline
result.put(TextAttribute.SUPERSCRIPT,
new Integer(0)); // XXX: jdk1.2 doesn't define
// SUPERSCRIPT_NONE, 1.3 does
break;
}
} else {
// TODO
float f = v.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
// result.put(TextAttribute.TRANSFORM,
// CSSUtilities.convertFloatToTranslation(0f, f));
}
// Unicode-bidi mode
// XXX: below supports single override level only,
// full support requires revision: see comments
// below regarding 'direction'
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_UNICODE_BIDI_PROPERTY);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'e':
result.put(TextAttribute.BIDI_EMBEDDING,
new Integer(1));
break;
case 'b':
result.put(TextAttribute.BIDI_EMBEDDING,
new Integer(-1));
break;
case 'n':
result.put(TextAttribute.BIDI_EMBEDDING,
new Integer(0));
}
// Text direction
// XXX: this needs to coordinate with the unicode-bidi
// property, so that when an explicit reversal
// occurs, the BIDI_EMBEDDING level is
// appropriately incremented or decremented.
// Note that direction is implicitly handled by unicode
// BiDI algorithm in most cases, this property
// is only needed when one wants to override the
// normal writing direction for a string/substring.
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_DIRECTION_PROPERTY);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'l':
result.put(TextAttribute.RUN_DIRECTION,
TextAttribute.RUN_DIRECTION_LTR);
break;
case 'r':
result.put(TextAttribute.RUN_DIRECTION,
TextAttribute.RUN_DIRECTION_RTL);
break;
}
// Writing mode
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_WRITING_MODE_PROPERTY);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'l':
result.put(TextAttribute.RUN_DIRECTION,
TextAttribute.RUN_DIRECTION_LTR);
break;
case 'r':
result.put(TextAttribute.RUN_DIRECTION,
TextAttribute.RUN_DIRECTION_RTL);
break;
case 't':
break;
}
// Font style
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_FONT_STYLE_PROPERTY);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'n':
result.put(TextAttribute.POSTURE,
TextAttribute.POSTURE_REGULAR);
break;
case 'o':
case 'i':
result.put(TextAttribute.POSTURE,
TextAttribute.POSTURE_OBLIQUE);
}
// Font stretch
v = (CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_FONT_STRETCH_PROPERTY);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'u':
if (s.charAt(6) == 'c') {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_CONDENSED);
} else {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_EXTENDED);
}
break;
case 'e':
if (s.charAt(6) == 'c') {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_CONDENSED);
} else {
if (s.length() == 8) {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_SEMI_EXTENDED);
} else {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_EXTENDED);
}
}
break;
case 's':
if (s.charAt(6) == 'c') {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_SEMI_CONDENSED);
} else {
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_SEMI_EXTENDED);
}
break;
default:
result.put(TextAttribute.WIDTH,
TextAttribute.WIDTH_REGULAR);
}
// Opacity
CSSPrimitiveValue opacityVal =
(CSSPrimitiveValue)cssDecl.getPropertyCSSValue(ATTR_OPACITY);
if (opacityVal != null) {
Composite composite =
CSSUtilities.convertOpacityToComposite(opacityVal);
result.put(GVTAttributedCharacterIterator.TextAttribute.OPACITY,
composite);
}
// Fill
Paint p = CSSUtilities.convertFillToPaint((SVGElement)element,
node,
ctx,
cssDecl,
uctx);
if (p != null) {
result.put(TextAttribute.FOREGROUND, p);
}
// Stroke Paint
Paint sp = CSSUtilities.convertStrokeToPaint((SVGElement)element,
node,
ctx,
cssDecl,
uctx);
if (sp != null) {
result.put
(GVTAttributedCharacterIterator.TextAttribute.STROKE_PAINT, sp);
}
// Stroke
Stroke stroke
= CSSUtilities.convertStrokeToBasicStroke((SVGElement)element,
ctx,
cssDecl,
uctx);
if(stroke != null){
result.put(GVTAttributedCharacterIterator.TextAttribute.STROKE,
stroke);
}
// Text decoration
CSSValue cssVal = cssDecl.getPropertyCSSValue
(CSS_TEXT_DECORATION_PROPERTY);
short t = cssVal.getCssValueType();
if (t == CSSValue.CSS_VALUE_LIST) {
CSSValueList lst = (CSSValueList)cssVal;
for (int i = 0; i < lst.getLength(); i++) {
v = (CSSPrimitiveValue)lst.item(i);
s = v.getStringValue();
switch (s.charAt(0)) {
case 'u':
result.put(
GVTAttributedCharacterIterator.TextAttribute.UNDERLINE,