FontFinderpublic class FontFinder extends Object This class chooses the default font for the given text.
If it finds the character which current font is unable to display
it starts the next font run and looks for the font which is able to
display the current character. It also caches the font mappings
(index in the array containing all fonts) for the characters,
using that fact that scripts are mainly contiguous in the UTF-16 encoding
and there's a high probability that the upper byte will be the same for the
next character as for the previous. This allows to save the space used for the cache. |
Fields Summary |
---|
private static final float | DEFAULT_FONT_SIZE | private static final Font[] | fonts | private static final int | NUM_BLOCKS | private static final int | BLOCK_SIZE | private static final int | INDEX_MASK | private static final int | BLOCK_SHIFT | private static final int[] | blocks |
Methods Summary |
---|
static java.awt.Font | findFontForChar(char c)Finds the font which is able to display the given character
and saves the font mapping for this character
int blockNum = c >> BLOCK_SHIFT;
int index = c & INDEX_MASK;
if (blocks[blockNum] == null) {
blocks[blockNum] = new int[BLOCK_SIZE];
}
if (blocks[blockNum][index] == 0) {
blocks[blockNum][index] = 1;
for (int i=0; i<fonts.length; i++) {
if (fonts[i].canDisplay(c)) {
blocks[blockNum][index] = i+1;
break;
}
}
}
return getDefaultSizeFont(blocks[blockNum][index]-1);
| static void | findFonts(char[] text, int runStart, int runLimit, java.util.List runStarts, java.util.Map fonts)Assigns default fonts for the given text run.
First three parameters are input, last three are output.
Font prevFont = null;
Font currFont;
for (int i = runStart; i < runLimit; i++) {
currFont = findFontForChar(text[i]);
if (currFont != prevFont) {
prevFont = currFont;
Integer idx = new Integer(i);
fonts.put(idx, currFont);
if (i != runStart) {
runStarts.add(idx);
}
}
}
| static java.awt.Font | getDefaultSizeFont(int i)Derives the default size font
if (fonts[i].getSize() != DEFAULT_FONT_SIZE) {
fonts[i] = fonts[i].deriveFont(DEFAULT_FONT_SIZE);
}
return fonts[i];
|
|