/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/*
* (C) Copyright IBM Corp. 1999, All rights reserved.
*/
/**
* This class maps an individual character to a Font family which can
* display it. The character-to-Font mapping does not depend on the
* character's context, so a particular character will be mapped to the
* same font family each time.
* <p>
* Typically, clients will call getIndexFor(char) for each character
* in a style run. When getIndexFor() returns a different value from
* ones seen previously, the characters up to that point will be assigned
* a font obtained from getFont().
*/
public final class FontResolver {
// An array of all fonts available to the runtime. The fonts
// will be searched in order.
private int[] supplementaryIndices;
// Default size of Fonts (if created from an empty Map, for instance).
// The results of previous lookups are cached in a two-level
// table. The value for a character c is found in:
// blocks[c>>SHIFT][c&MASK]
// although the second array is only allocated when needed.
// A 0 value means the character's font has not been looked up.
// A positive value means the character's font is in the allFonts
// array at index (value-1).
private FontResolver() {
}
allFonts =
}
}
return allFonts;
}
/**
* Search fonts in order, and return "1" to indicate its in the default
* font, (or not found at all), or the index of the first font
* which can display the given character, plus 2, if it is not
* in the default font.
*/
private int getIndexFor(char c) {
if (defaultFont.canDisplay(c)) {
return 1;
}
if (allFonts[i].canDisplay(c)) {
return i+2;
}
}
return 1;
}
if (supplementaryFonts == null) {
if (font2D.hasSupplementaryChars()) {
}
}
supplementaryIndices = new int[len];
for (int i=0; i<len; i++) {
}
}
return supplementaryFonts;
}
/* This method is called only for character codes >= 0x10000 - which
* are assumed to be legal supplementary characters.
* It looks first at the default font (to avoid calling getAllFonts if at
* all possible) and if that doesn't map the code point, it scans
* just the fonts that may contain supplementary characters.
* The index that is returned is into the "allFonts" array so that
* callers see the same value for both supplementary and base chars.
*/
return 1;
}
return supplementaryIndices[i]+2;
}
}
return 1;
}
/**
* Return an index for the given character. The index identifies a
* font family to getFont(), and has no other inherent meaning.
* @param c the character to map
* @return a value for consumption by getFont()
* @see #getFont
*/
public int getFontIndex(char c) {
int blockIndex = c>>SHIFT;
}
}
}
if (cp < 0x10000) {
return getFontIndex((char)cp);
}
return getIndexFor(cp);
}
/**
* Determines the font index for the code point at the current position in the
* iterator, then advances the iterator to the first code point that has
* a different index or until the iterator is DONE, and returns the font index.
* @param iter a code point iterator, this will be advanced past any code
* points that have the same font index
* @return the font index for the initial code point found, or 1 if the iterator
* was empty.
*/
int fontIndex = 1;
break;
}
}
}
return fontIndex;
}
/**
* Return a Font from a given font index with properties
* from attributes. The font index, which should have been produced
* by getFontIndex(), determines a font family. The size and style
* of the Font reflect the properties in attributes. Any Font or
* font family specifications in attributes are ignored, on the
* assumption that clients have already handled them.
* @param index an index from getFontIndex() which determines the
* font family
* @param attributes a Map from which the size and style of the Font
* are determined. The default size is 12 and the default style
* is Font.PLAIN
* @see #getFontIndex
*/
if (index >= 2) {
}
}
/**
* Return a shared instance of FontResolver.
*/
INSTANCE = new FontResolver();
}
return INSTANCE;
}
}