*/
private AttributedCharacterIterator createModifiedACIForFontMatching(
TextNode node, AttributedCharacterIterator aci) {
aci.first();
AttributedCharacterSpanIterator acsi
= new AttributedCharacterSpanIterator(aci, aci.getBeginIndex(), aci.getEndIndex());
AttributedString as = new AttributedString(acsi);
aci.first();
boolean moreChunks = true;
while (moreChunks) {
int start = aci.getRunStart(GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
int end = aci.getRunLimit(GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
AttributedCharacterSpanIterator runaci = new AttributedCharacterSpanIterator(aci, start, end);
Vector fontFamilies = (Vector)runaci.getAttributes().get(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
if (fontFamilies == null) {
// no font families set, just return the same aci
return aci;
}
// resolve any unresolved font families in the list
Vector resolvedFontFamilies = new Vector();
for (int i = 0; i < fontFamilies.size(); i++) {
GVTFontFamily fontFamily = (GVTFontFamily) fontFamilies.get(i);
if (fontFamily instanceof UnresolvedFontFamily) {
GVTFontFamily resolvedFontFamily = FontFamilyResolver.resolve((UnresolvedFontFamily)fontFamily);
if (resolvedFontFamily != null) {
// font family was successfully resolved
resolvedFontFamilies.add(resolvedFontFamily);
}
} else {
// already resolved
resolvedFontFamilies.add(fontFamily);
}
}
// if could not resolve at least one of the fontFamilies then use
// the default faont
if (resolvedFontFamilies.size() == 0) {
resolvedFontFamilies.add(FontFamilyResolver.defaultFont);
}
// create a list of fonts of the correct size
Float fontSizeFloat = (Float)runaci.getAttributes().get(TextAttribute.SIZE);
float fontSize = 12;
if (fontSizeFloat != null) {
fontSize = fontSizeFloat.floatValue();
}
Vector gvtFonts = new Vector();
for (int i = 0; i < resolvedFontFamilies.size(); i++) {
GVTFont font = ((GVTFontFamily)resolvedFontFamilies.get(i)).deriveFont(fontSize, runaci);
gvtFonts.add(font);
}
// now for each char or group of chars in the string,
// find a font that can display it
int runaciLength = end-start;
boolean[] fontAssigned = new boolean[runaciLength];
for (int i = 0; i < runaciLength; i++) {
fontAssigned[i] = false;
}
for (int i = 0; i < gvtFonts.size(); i++) {
// assign this font to all characters it can display if it has
// not already been assigned
GVTFont font = (GVTFont)gvtFonts.get(i);
int currentRunIndex = runaci.getBeginIndex();
while (currentRunIndex < runaci.getEndIndex()) {
int displayUpToIndex = font.canDisplayUpTo(runaci, currentRunIndex, end);
if (displayUpToIndex == -1) {
// for each char, if not already assigned a font, assign this font to it
for (int j = currentRunIndex; j < end; j++) {
if (!fontAssigned[j - start]) {
as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT, font, j, j+1);
fontAssigned[j - start] = true;
}
}
currentRunIndex = runaci.getEndIndex();
} else if (displayUpToIndex > currentRunIndex) {
// could display some but not all
// for each char it can display, if not already assigned a font, assign this font to it
for (int j = currentRunIndex; j < displayUpToIndex; j++) {
if (!fontAssigned[j - start]) {
as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT, font, j, j+1);
fontAssigned[j - start] = true;
}
}
// set currentRunIndex to be one after the char couldn't display
currentRunIndex = displayUpToIndex+1;
} else {
// couldn't display the current char
currentRunIndex++;
}
}
}
// assign the first font to any chars haven't alreay been assigned
for (int i = 0; i < runaciLength; i++) {
if (!fontAssigned[i]) {
GVTFontFamily fontFamily = FontFamilyResolver.getFamilyThatCanDisplay(runaci.setIndex(start+i));
if (fontFamily != null) {
GVTFont font = fontFamily.deriveFont(fontSize, runaci);
as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT,
font, start+i, start+i+1);
} else {