NativeFont.java revision 0
0N/A * Copyright 2003-2006 Sun Microsystems, Inc. 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 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun 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. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * Ideally there would be no native fonts used, and this class would be 0N/A * unneeded and removed. Presently it is still needed until such time 0N/A * as font configuration files (or the implementation equivalent) can have 0N/A * all references to fonts that are not handled via Java 2D removed. 0N/A * Currently there are two cases where this class is needed, both on 0N/A * Unix, primarily Solaris, but useful on Linux too if fonts have moved. 0N/A * 1. Some legacy F3 fonts are still referenced so that AWT "X/Motif" 0N/A * can get dingbats and symbols from them. This can be dispensed with when 0N/A * either AWT is based on 2D, or when the X font path is known to always 0N/A * contain a Type1 or TrueType font that can be used in font configuration 0N/A * files to replace the F3 fonts. 0N/A * 2. When location of font files by 2D fails, because of some system 0N/A * configuration problem, it is desirable to have a fall back to some 0N/A * functionality that lessens the immediate impact on users. Being able 0N/A * to perform limited operations by using bitmaps from X11 helps here. 0N/A * Verifies native font is accessible. 0N/A * @throws FontFormatException - if the font can't be located. 0N/A /* This is set true if this is an instance of a NativeFont 0N/A * created by some other font, to get native bitmaps. 0N/A * The delegating font will call this font only for "basic" 0N/A * cases - ie non-rotated, uniform scale, monochrome bitmaps. 0N/A * If this is false, then this instance may need to itself 0N/A * delegate to another font for non-basic cases. Since 0N/A * NativeFonts are used in that way only for symbol and dingbats 0N/A * we know its safe to delegate these to the JRE's default 0N/A * physical font (Lucida Sans Regular). 0N/A /* Valid XLFD has exactly 14 "-" chars. 0N/A * First run over the string to verify have at least this many 0N/A * At the same time record the locations of the hyphens 0N/A * so we can just pick the right substring later on 0N/A /* Capitalise words in the Family name */ 0N/A// familyName = "Unknown"; 0N/A// fullName = "Unknown"; 0N/A// style = Font.PLAIN; 0N/A// encoding = "iso8859-1"; 0N/A /* Wildcard all the size fields in the XLFD and retrieve a list of 0N/A * XLFD's that match. 0N/A * We only look for scaleable fonts, so we can just replace the 0's 0N/A * with *'s and see what we get back 0N/A * No matches means even the scaleable version wasn't found. This is 0N/A * means the X font path isn't set up for this font at all. 0N/A * One match means only the scaleable version we started with was found 0N/A * -monotype-arial-bold-i-normal--0-0-0-0-p-0-iso8859-1 0N/A * Two matches apparently means as well as the above, a scaleable 0N/A * specified for 72 dpi is found, not that there are bitmaps : eg 0N/A * -monotype-arial-bold-i-normal--0-0-72-72-p-0-iso8859-1 0N/A * So require at least 3 matches (no need to parse) to determine that 0N/A * there are external bitmaps. 0N/A /* Turn -monotype-arial-bold-i-normal--0-0-0-0-p-0-iso8859-1 0N/A * into -monotype-arial-bold-i-normal--*-*-*-*-p-*-iso8859-1 0N/A * by replacing all -0- substrings with -*- 0N/A /* we are a delegate */ 0N/A /* we need to delegate */ 0N/A /* If no FileFont's are found, delegate font may be 0N/A * a NativeFont, so we need to avoid recursing here. 0N/A /* Specify that the dpi is 72x72, as this corresponds to JDK's 0N/A * default user space. These are the 10th and 11th fields in the XLFD. 0N/A * ptSize in XLFD is in 10th's of a point so multiply by 10, 0N/A * Replace the 9th field in the XLFD (ie after the 8th hyphen) 0N/A * with this pt size (this corresponds to the field that's "%d" in the 0N/A * font configuration files). Wild card the other numeric fields. 0N/A * ie to request 12 pt Times New Roman italic font, use an XLFD like : 0N/A * -monotype-times new roman-regular-i---*-120-72-72-p-*-iso8859-1 0N/A /* work backwards so as to not invalidate the positions. */ 0N/A /* replace the 3 lines above with the next 3 lines to get the 1.4.2 0N/A// sb.replace(hPos[11]+1, hPos[12], "0"); 0N/A// sb.replace(hPos[9]+1, hPos[10], "0"); 0N/A// sb.replace(hPos[8]+1, hPos[9], "0"); 0N/A /* replace the 1 line above with the next line to get the 1.4.2 0N/A// sb.replace(hPos[6]+1, hPos[7], "0"); 0N/A /* comment out this block to the the 1.4.2 behaviour */ 0N/A /* null foundry name : some linux font configuration files have 0N/A * symbol font entries like this and its just plain wrong. 0N/A * Replace with a wild card. (Although those fonts should be 0N/A * located via disk access rather than X11).