FontConfigManager.java revision 3346
0N/A * Copyright (c) 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 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/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. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Small utility class to manage FontConfig. 0N/A /* This is populated by native */ 0N/A /* Begin support for GTK Look and Feel - query libfontconfig and 0N/A * return a composite Font to Swing that uses the desktop font(s). 0N/A /* These next three classes are just data structures. public int style;
// eg 0=PLAIN //boolean preferBitmaps; // if embedded bitmaps preferred over AA /* fontconfig recognises slants roman, italic, as well as oblique, * and a slew of weights, where the ones that matter here are * To fully qualify what we want, we can for example ask for (eg) * Font.PLAIN : "serif:regular:roman" * Font.BOLD : "serif:bold:roman" * Font.ITALIC : "serif:regular:italic" * Font.BOLD|Font.ITALIC : "serif:bold:italic" "monospace:regular:roman",
"monospace:regular:italic",
/* This array has the array elements created in Java code and is * passed down to native to be filled in. * Instantiates a new FontConfigManager getting the default instance * of FontManager from the FontManagerFactory. /* Called from code that needs to know what are the AA settings * that apps using FC would pick up for the default desktop font. * Note apps can change the default desktop font. etc, so this * isn't certain to be right but its going to correct for most cases. * Native return values map to the text aa values in sun.awt.SunHints. * which is used to look up the renderinghint value object. /* This is public solely so that for debugging purposes it can be called * with other names, which might (eg) include a size, eg "sans-24" * The return value is a text aa rendering hint value. * Normally we should call the no-args version. /* This does cause the native libfontconfig to be loaded and unloaded, * but it does not incur the overhead of initialisation of its * data structures, so shouldn't have a measurable impact. /* This can be made public if it's needed to force a re-read * rather than using the cached values. The re-read would be needed * only if some event signalled that the fontconfig has changed. * In that event this method would need to return directly the array * to be used by the caller in case it subsequently changed. /* If don't find anything (eg no libfontconfig), then just return */ logger.
info(
"Fontconfig returned no fonts at all.");
+ ((
t1 -
t0) /
1000000) +
"ms.");
/* If it's a TTC file we need to know that as we will need to * make sure we return the right font */ /* If this file is already registered, can just return its font. * However we do need to check in case it's a TTC as we need * a specific font, so rather than directly returning it, let * findFont2D resolve that. /* If the font may hide a JRE font (eg fontconfig says it is * Lucida Sans), we want to use the JRE version, so make it /* It is also possible the font file is on the "deferred" list, * in which case we can just initialise it now. /* use findFont2D to get the right font from TTC's */ /* In the majority of cases we reach here, and need to determine * the type and rank to register the font. * We need to return a Composite font which has as the font in * its first slot one obtained from fontconfig. /* jdkFont is going to be used for slots 1..N and as a fallback. * Slot 0 will be the physical font from fontconfig. /* First, see if the family and exact style is already registered. * If it is, use it. If it's not, then try to register it. * If that registration fails (signalled by null) just return the * Algorithmically styled fonts won't match on exact style, so * will fall through this code, but the regisration code will * find that file already registered and return its font. /* Now register the fonts in the family (the other styles) after * checking that they aren't already registered and are actually in * a different file. They may be the same file in CJK cases. * For cases where they are different font files - eg as is common for * Latin fonts, then we rely on fontconfig to report these correctly. * Assume that all styles of this font are found by fontconfig, * so we can find all the family members which must be registered * together to prevent synthetic styling. /* Now we have a physical font. We will back this up with the JDK * logical font (sansserif, serif, or monospaced) that corresponds /* Return an array of FcCompFont structs describing the primary private static native int