/* * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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. */ package sun.font; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.font.TextAttribute; import java.util.ArrayList; import java.util.Map; import sun.text.CodePointIterator; /** * 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. *
* 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 Font[] allFonts;
private Font[] supplementaryFonts;
private int[] supplementaryIndices;
// Default size of Fonts (if created from an empty Map, for instance).
private static final int DEFAULT_SIZE = 12; // from Font
private Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, DEFAULT_SIZE);
// 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 static final int SHIFT = 9;
private static final int BLOCKSIZE = 1<<(16-SHIFT);
private static final int MASK = BLOCKSIZE-1;
private int[][] blocks = new int[1<