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