diff -r fd16c54261b3 -r 90ce3da70b43 jdk/src/share/classes/sun/font/FontResolver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/sun/font/FontResolver.java Sat Dec 01 00:00:00 2007 +0000 @@ -0,0 +1,246 @@ +/* + * Portions Copyright 1999-2005 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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<