Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11FontManager.java
32287 views
/*1* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.awt.GraphicsEnvironment;28import java.io.BufferedReader;29import java.io.File;30import java.io.FileReader;31import java.io.IOException;32import java.io.StreamTokenizer;33import java.util.HashMap;34import java.util.HashSet;35import java.util.Locale;36import java.util.Map;37import java.util.NoSuchElementException;38import java.util.StringTokenizer;39import java.util.Vector;4041import javax.swing.plaf.FontUIResource;42import sun.awt.motif.MFontConfiguration;43import sun.font.CompositeFont;44import sun.font.FontManager;45import sun.font.SunFontManager;46import sun.font.FontConfigManager;47import sun.font.FcFontConfiguration;48import sun.font.FontAccess;49import sun.font.FontUtilities;50import sun.font.NativeFont;51import sun.util.logging.PlatformLogger;5253/**54* The X11 implementation of {@link FontManager}.55*/56public final class X11FontManager extends FcFontManager {5758// constants identifying XLFD and font ID fields59private static final int FOUNDRY_FIELD = 1;60private static final int FAMILY_NAME_FIELD = 2;61private static final int WEIGHT_NAME_FIELD = 3;62private static final int SLANT_FIELD = 4;63private static final int SETWIDTH_NAME_FIELD = 5;64private static final int ADD_STYLE_NAME_FIELD = 6;65private static final int PIXEL_SIZE_FIELD = 7;66private static final int POINT_SIZE_FIELD = 8;67private static final int RESOLUTION_X_FIELD = 9;68private static final int RESOLUTION_Y_FIELD = 10;69private static final int SPACING_FIELD = 11;70private static final int AVERAGE_WIDTH_FIELD = 12;71private static final int CHARSET_REGISTRY_FIELD = 13;72private static final int CHARSET_ENCODING_FIELD = 14;7374/*75* fontNameMap is a map from a fontID (which is a substring of an XLFD like76* "-monotype-arial-bold-r-normal-iso8859-7")77* to font file path like78* /usr/openwin/lib/locale/iso_8859_7/X11/fonts/TrueType/ArialBoldItalic.ttf79* It's used in a couple of methods like80* getFileNameFomPlatformName(..) to help locate the font file.81* We use this substring of a full XLFD because the font configuration files82* define the XLFDs in a way that's easier to make into a request.83* E.g., the -0-0-0-0-p-0- reported by X is -*-%d-*-*-p-*- in the font84* configuration files. We need to remove that part for comparisons.85*/86private static Map fontNameMap = new HashMap();8788/*89* xlfdMap is a map from a platform path like90* /usr/openwin/lib/locale/ja/X11/fonts/TT/HG-GothicB.ttf to an XLFD like91* "-ricoh-hg gothic b-medium-r-normal--0-0-0-0-m-0-jisx0201.1976-0"92* Because there may be multiple native names, because the font is used93* to support multiple X encodings for example, the value of an entry in94* this map is always a vector where we store all the native names.95* For fonts which we don't understand the key isn't a pathname, its96* the full XLFD string like :-97* "-ricoh-hg gothic b-medium-r-normal--0-0-0-0-m-0-jisx0201.1976-0"98*/99private static Map xlfdMap = new HashMap();100101/* xFontDirsMap is also a map from a font ID to a font filepath.102* The difference from fontNameMap is just that it does not have103* resolved symbolic links. Normally this is not interesting except104* that we need to know the directory in which a font was found to105* add it to the X font server path, since although the files may106* be linked, the fonts.dir is different and specific to the encoding107* handled by that directory. This map is nulled out after use to free108* heap space. If the optimal path is taken, such that all fonts in109* font configuration files are referenced by filename, then the font110* dir can be directly derived as its parent directory.111* If a font is used by two XLFDs, each corresponding to a different112* X11 font directory, then precautions must be taken to include both113* directories.114*/115private static Map xFontDirsMap;116117/*118* This is the set of font directories needed to be on the X font path119* to enable AWT heavyweights to find all of the font configuration fonts.120* It is populated by :121* - awtfontpath entries in the fontconfig.properties122* - parent directories of "core" fonts used in the fontconfig.properties123* - looking up font dirs in the xFontDirsMap where the key is a fontID124* (cut down version of the XLFD read from the font configuration file).125* This set is nulled out after use to free heap space.126*/127private static HashSet<String> fontConfigDirs = null;128129/* These maps are used on Linux where we reference the Lucida oblique130* fonts in fontconfig files even though they aren't in the standard131* font directory. This explicitly remaps the XLFDs for these to the132* correct base font. This is needed to prevent composite fonts from133* defaulting to the Lucida Sans which is a bad substitute for the134* monospaced Lucida Sans Typewriter. Also these maps prevent the135* JRE from doing wasted work at start up.136*/137HashMap<String, String> oblmap = null;138139140/*141* Used to eliminate redundant work. When a font directory is142* registered it added to this list. Subsequent registrations for the143* same directory can then be skipped by checking this Map.144* Access to this map is not synchronised here since creation145* of the singleton GE instance is already synchronised and that is146* the only code path that accesses this map.147*/148private static HashMap registeredDirs = new HashMap();149150/* Array of directories to be added to the X11 font path.151* Used by static method called from Toolkits which use X11 fonts.152* Specifically this means MToolkit153*/154private static String[] fontdirs = null;155156public static X11FontManager getInstance() {157return (X11FontManager) SunFontManager.getInstance();158}159160/**161* Takes family name property in the following format:162* "-linotype-helvetica-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1"163* and returns the name of the corresponding physical font.164* This code is used to resolve font configuration fonts, and expects165* only to get called for these fonts.166*/167@Override168public String getFileNameFromPlatformName(String platName) {169170/* If the FontConfig file doesn't use xlfds, or its171* FcFontConfiguration, this may be already a file name.172*/173if (platName.startsWith("/")) {174return platName;175}176177String fileName = null;178String fontID = specificFontIDForName(platName);179180/* If the font filename has been explicitly assigned in the181* font configuration file, use it. This avoids accessing182* the wrong fonts on Linux, where different fonts (some183* of which may not be usable by 2D) may share the same184* specific font ID. It may also speed up the lookup.185*/186fileName = super.getFileNameFromPlatformName(platName);187if (fileName != null) {188if (isHeadless() && fileName.startsWith("-")) {189/* if it's headless, no xlfd should be used */190return null;191}192if (fileName.startsWith("/")) {193/* If a path is assigned in the font configuration file,194* it is required that the config file also specify using the195* new awtfontpath key the X11 font directories196* which must be added to the X11 font path to support197* AWT access to that font. For that reason we no longer198* have code here to add the parent directory to the list199* of font config dirs, since the parent directory may not200* be sufficient if fonts are symbolically linked to a201* different directory.202*203* Add this XLFD (platform name) to the list of known204* ones for this file.205*/206Vector xVal = (Vector) xlfdMap.get(fileName);207if (xVal == null) {208/* Try to be robust on Linux distros which move fonts209* around by verifying that the fileName represents a210* file that exists. If it doesn't, set it to null211* to trigger a search.212*/213if (getFontConfiguration().needToSearchForFile(fileName)) {214fileName = null;215}216if (fileName != null) {217xVal = new Vector();218xVal.add(platName);219xlfdMap.put(fileName, xVal);220}221} else {222if (!xVal.contains(platName)) {223xVal.add(platName);224}225}226}227if (fileName != null) {228fontNameMap.put(fontID, fileName);229return fileName;230}231}232233if (fontID != null) {234fileName = (String)fontNameMap.get(fontID);235/* On Linux check for the Lucida Oblique fonts */236if (fileName == null && FontUtilities.isLinux && !isOpenJDK()) {237if (oblmap == null) {238initObliqueLucidaFontMap();239}240String oblkey = getObliqueLucidaFontID(fontID);241if (oblkey != null) {242fileName = oblmap.get(oblkey);243}244}245if (fontPath == null &&246(fileName == null || !fileName.startsWith("/"))) {247if (FontUtilities.debugFonts()) {248FontUtilities.getLogger()249.warning("** Registering all font paths because " +250"can't find file for " + platName);251}252fontPath = getPlatformFontPath(noType1Font);253registerFontDirs(fontPath);254if (FontUtilities.debugFonts()) {255FontUtilities.getLogger()256.warning("** Finished registering all font paths");257}258fileName = (String)fontNameMap.get(fontID);259}260if (fileName == null && !isHeadless()) {261/* Query X11 directly to see if this font is available262* as a native font.263*/264fileName = getX11FontName(platName);265}266if (fileName == null) {267fontID = switchFontIDForName(platName);268fileName = (String)fontNameMap.get(fontID);269}270if (fileName != null) {271fontNameMap.put(fontID, fileName);272}273}274return fileName;275}276277@Override278protected String[] getNativeNames(String fontFileName,279String platformName) {280Vector nativeNames;281if ((nativeNames=(Vector)xlfdMap.get(fontFileName))==null) {282if (platformName == null) {283return null;284} else {285/* back-stop so that at least the name used in the286* font configuration file is known as a native name287*/288String []natNames = new String[1];289natNames[0] = platformName;290return natNames;291}292} else {293int len = nativeNames.size();294return (String[])nativeNames.toArray(new String[len]);295}296}297298/* NOTE: this method needs to be executed in a privileged context.299* The superclass constructor which is the primary caller of300* this method executes entirely in such a context. Additionally301* the loadFonts() method does too. So all should be well.302303*/304@Override305protected void registerFontDir(String path) {306/* fonts.dir file format looks like :-307* 47308* Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1309* Arial-Bold.ttf -monotype-arial-bold-r-normal--0-0-0-0-p-0-iso8859-1310* ...311*/312if (FontUtilities.debugFonts()) {313FontUtilities.getLogger().info("ParseFontDir " + path);314}315File fontsDotDir = new File(path + File.separator + "fonts.dir");316FileReader fr = null;317try {318if (fontsDotDir.canRead()) {319fr = new FileReader(fontsDotDir);320BufferedReader br = new BufferedReader(fr, 8192);321StreamTokenizer st = new StreamTokenizer(br);322st.eolIsSignificant(true);323int ttype = st.nextToken();324if (ttype == StreamTokenizer.TT_NUMBER) {325int numEntries = (int)st.nval;326ttype = st.nextToken();327if (ttype == StreamTokenizer.TT_EOL) {328st.resetSyntax();329st.wordChars(32, 127);330st.wordChars(128 + 32, 255);331st.whitespaceChars(0, 31);332333for (int i=0; i < numEntries; i++) {334ttype = st.nextToken();335if (ttype == StreamTokenizer.TT_EOF) {336break;337}338if (ttype != StreamTokenizer.TT_WORD) {339break;340}341int breakPos = st.sval.indexOf(' ');342if (breakPos <= 0) {343/* On TurboLinux 8.0 a fonts.dir file had344* a line with integer value "24" which345* appeared to be the number of remaining346* entries in the file. This didn't add to347* the value on the first line of the file.348* Seemed like XFree86 didn't like this line349* much either. It failed to parse the file.350* Ignore lines like this completely, and351* don't let them count as an entry.352*/353numEntries++;354ttype = st.nextToken();355if (ttype != StreamTokenizer.TT_EOL) {356break;357}358359continue;360}361if (st.sval.charAt(0) == '!') {362/* TurboLinux 8.0 comment line: ignore.363* can't use st.commentChar('!') to just364* skip because this line mustn't count365* against numEntries.366*/367numEntries++;368ttype = st.nextToken();369if (ttype != StreamTokenizer.TT_EOL) {370break;371}372continue;373}374String fileName = st.sval.substring(0, breakPos);375/* TurboLinux 8.0 uses some additional syntax to376* indicate algorithmic styling values.377* Ignore ':' separated files at the beginning378* of the fileName379*/380int lastColon = fileName.lastIndexOf(':');381if (lastColon > 0) {382if (lastColon+1 >= fileName.length()) {383continue;384}385fileName = fileName.substring(lastColon+1);386}387String fontPart = st.sval.substring(breakPos+1);388String fontID = specificFontIDForName(fontPart);389String sVal = (String) fontNameMap.get(fontID);390391if (FontUtilities.debugFonts()) {392PlatformLogger logger = FontUtilities.getLogger();393logger.info("file=" + fileName +394" xlfd=" + fontPart);395logger.info("fontID=" + fontID +396" sVal=" + sVal);397}398String fullPath = null;399try {400File file = new File(path,fileName);401/* we may have a resolved symbolic link402* this becomes important for an xlfd we403* still need to know the location it was404* found to update the X server font path405* for use by AWT heavyweights - and when 2D406* wants to use the native rasteriser.407*/408if (xFontDirsMap == null) {409xFontDirsMap = new HashMap();410}411xFontDirsMap.put(fontID, path);412fullPath = file.getCanonicalPath();413} catch (IOException e) {414fullPath = path + File.separator + fileName;415}416Vector xVal = (Vector) xlfdMap.get(fullPath);417if (FontUtilities.debugFonts()) {418FontUtilities.getLogger()419.info("fullPath=" + fullPath +420" xVal=" + xVal);421}422if ((xVal == null || !xVal.contains(fontPart)) &&423(sVal == null) || !sVal.startsWith("/")) {424if (FontUtilities.debugFonts()) {425FontUtilities.getLogger()426.info("Map fontID:"+fontID +427"to file:" + fullPath);428}429fontNameMap.put(fontID, fullPath);430if (xVal == null) {431xVal = new Vector();432xlfdMap.put (fullPath, xVal);433}434xVal.add(fontPart);435}436437ttype = st.nextToken();438if (ttype != StreamTokenizer.TT_EOL) {439break;440}441}442}443}444fr.close();445}446} catch (IOException ioe1) {447} finally {448if (fr != null) {449try {450fr.close();451} catch (IOException ioe2) {452}453}454}455}456457@Override458public void loadFonts() {459super.loadFonts();460/* These maps are greatly expanded during a loadFonts but461* can be reset to their initial state afterwards.462* Since preferLocaleFonts() and preferProportionalFonts() will463* trigger a partial repopulating from the FontConfiguration464* it has to be the inital (empty) state for the latter two, not465* simply nulling out.466* xFontDirsMap is a special case in that the implementation467* will typically not ever need to initialise it so it can be null.468*/469xFontDirsMap = null;470xlfdMap = new HashMap(1);471fontNameMap = new HashMap(1);472}473474private String getObliqueLucidaFontID(String fontID) {475if (fontID.startsWith("-lucidasans-medium-i-normal") ||476fontID.startsWith("-lucidasans-bold-i-normal") ||477fontID.startsWith("-lucidatypewriter-medium-i-normal") ||478fontID.startsWith("-lucidatypewriter-bold-i-normal")) {479return fontID.substring(0, fontID.indexOf("-i-"));480} else {481return null;482}483}484485private static String getX11FontName(String platName) {486String xlfd = platName.replaceAll("%d", "*");487if (NativeFont.fontExists(xlfd)) {488return xlfd;489} else {490return null;491}492}493494private void initObliqueLucidaFontMap() {495oblmap = new HashMap<String, String>();496oblmap.put("-lucidasans-medium",497jreLibDirName+"/fonts/LucidaSansRegular.ttf");498oblmap.put("-lucidasans-bold",499jreLibDirName+"/fonts/LucidaSansDemiBold.ttf");500oblmap.put("-lucidatypewriter-medium",501jreLibDirName+"/fonts/LucidaTypewriterRegular.ttf");502oblmap.put("-lucidatypewriter-bold",503jreLibDirName+"/fonts/LucidaTypewriterBold.ttf");504}505506private boolean isHeadless() {507GraphicsEnvironment ge =508GraphicsEnvironment.getLocalGraphicsEnvironment();509return GraphicsEnvironment.isHeadless();510}511512private String specificFontIDForName(String name) {513514int[] hPos = new int[14];515int hyphenCnt = 1;516int pos = 1;517518while (pos != -1 && hyphenCnt < 14) {519pos = name.indexOf('-', pos);520if (pos != -1) {521hPos[hyphenCnt++] = pos;522pos++;523}524}525526if (hyphenCnt != 14) {527if (FontUtilities.debugFonts()) {528FontUtilities.getLogger()529.severe("Font Configuration Font ID is malformed:" + name);530}531return name; // what else can we do?532}533534StringBuffer sb =535new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],536hPos[SETWIDTH_NAME_FIELD]));537sb.append(name.substring(hPos[CHARSET_REGISTRY_FIELD-1]));538String retval = sb.toString().toLowerCase (Locale.ENGLISH);539return retval;540}541542private String switchFontIDForName(String name) {543544int[] hPos = new int[14];545int hyphenCnt = 1;546int pos = 1;547548while (pos != -1 && hyphenCnt < 14) {549pos = name.indexOf('-', pos);550if (pos != -1) {551hPos[hyphenCnt++] = pos;552pos++;553}554}555556if (hyphenCnt != 14) {557if (FontUtilities.debugFonts()) {558FontUtilities.getLogger()559.severe("Font Configuration Font ID is malformed:" + name);560}561return name; // what else can we do?562}563564String slant = name.substring(hPos[SLANT_FIELD-1]+1,565hPos[SLANT_FIELD]);566String family = name.substring(hPos[FAMILY_NAME_FIELD-1]+1,567hPos[FAMILY_NAME_FIELD]);568String registry = name.substring(hPos[CHARSET_REGISTRY_FIELD-1]+1,569hPos[CHARSET_REGISTRY_FIELD]);570String encoding = name.substring(hPos[CHARSET_ENCODING_FIELD-1]+1);571572if (slant.equals("i")) {573slant = "o";574} else if (slant.equals("o")) {575slant = "i";576}577// workaround for #4471000578if (family.equals("itc zapfdingbats")579&& registry.equals("sun")580&& encoding.equals("fontspecific")){581registry = "adobe";582}583StringBuffer sb =584new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],585hPos[SLANT_FIELD-1]+1));586sb.append(slant);587sb.append(name.substring(hPos[SLANT_FIELD],588hPos[SETWIDTH_NAME_FIELD]+1));589sb.append(registry);590sb.append(name.substring(hPos[CHARSET_ENCODING_FIELD-1]));591String retval = sb.toString().toLowerCase (Locale.ENGLISH);592return retval;593}594595/**596* Returns the face name for the given XLFD.597*/598public String getFileNameFromXLFD(String name) {599String fileName = null;600String fontID = specificFontIDForName(name);601if (fontID != null) {602fileName = (String)fontNameMap.get(fontID);603if (fileName == null) {604fontID = switchFontIDForName(name);605fileName = (String)fontNameMap.get(fontID);606}607if (fileName == null) {608fileName = getDefaultFontFile();609}610}611return fileName;612}613614/* Register just the paths, (it doesn't register the fonts).615* If a font configuration file has specified a baseFontPath616* fontPath is just those directories, unless on usage we617* find it doesn't contain what we need for the logical fonts.618* Otherwise, we register all the paths on Solaris, because619* the fontPath we have here is the complete one from620* parsing /var/sadm/install/contents, not just621* what's on the X font path (may be this should be622* changed).623* But for now what it means is that if we didn't do624* this then if the font weren't listed anywhere on the625* less complete font path we'd trigger loadFonts which626* actually registers the fonts. This may actually be627* the right thing tho' since that would also set up628* the X font path without which we wouldn't be able to629* display some "native" fonts.630* So something to revisit is that probably fontPath631* here ought to be only the X font path + jre font dir.632* loadFonts should have a separate native call to633* get the rest of the platform font path.634*635* Registering the directories can now be avoided in the636* font configuration initialisation when filename entries637* exist in the font configuration file for all fonts.638* (Perhaps a little confusingly a filename entry is639* actually keyed using the XLFD used in the font entries,640* and it maps *to* a real filename).641* In the event any are missing, registration of all642* directories will be invoked to find the real files.643*644* But registering the directory performed other645* functions such as filling in the map of all native names646* for the font. So when this method isn't invoked, they still647* must be found. This is mitigated by getNativeNames now648* being able to return at least the platform name, but mostly649* by ensuring that when a filename key is found, that650* xlfd key is stored as one of the set of platform names651* for the font. Its a set because typical font configuration652* files reference the same CJK font files using multiple653* X11 encodings. For the code that adds this to the map654* see X11GE.getFileNameFromPlatformName(..)655* If you don't get all of these then some code points may656* not use the Xserver, and will not get the PCF bitmaps657* that are available for some point sizes.658* So, in the event that there is such a problem,659* unconditionally making this call may be necessary, at660* some cost to JRE start-up661*/662@Override663protected void registerFontDirs(String pathName) {664665StringTokenizer parser = new StringTokenizer(pathName,666File.pathSeparator);667try {668while (parser.hasMoreTokens()) {669String dirPath = parser.nextToken();670if (dirPath != null && !registeredDirs.containsKey(dirPath)) {671registeredDirs.put(dirPath, null);672registerFontDir(dirPath);673}674}675} catch (NoSuchElementException e) {676}677}678679// An X font spec (xlfd) includes an encoding. The same TrueType font file680// may be referenced from different X font directories in font.dir files681// to support use in multiple encodings by X apps.682// So for the purposes of font configuration logical fonts where AWT683// heavyweights need to access the font via X APIs we need to ensure that684// the directory for precisely the encodings needed by this are added to685// the x font path. This requires that we note the platform names686// specified in font configuration files and use that to identify the687// X font directory that contains a font.dir file for that platform name688// and add it to the X font path (if display is local)689// Here we make use of an already built map of xlfds to font locations690// to add the font location to the set of those required to build the691// x font path needed by AWT.692// These are added to the x font path later.693// All this is necessary because on Solaris the font.dir directories694// may contain not real font files, but symbolic links to the actual695// location but that location is not suitable for the x font path, since696// it probably doesn't have a font.dir at all and certainly not one697// with the required encodings698// If the fontconfiguration file is properly set up so that all fonts699// are mapped to files then we will never trigger initialising700// xFontDirsMap (it will be null). In this case the awtfontpath entries701// must specify all the X11 directories needed by AWT.702@Override703protected void addFontToPlatformFontPath(String platformName) {704// Lazily initialize fontConfigDirs.705getPlatformFontPathFromFontConfig();706if (xFontDirsMap != null) {707String fontID = specificFontIDForName(platformName);708String dirName = (String)xFontDirsMap.get(fontID);709if (dirName != null) {710fontConfigDirs.add(dirName);711}712}713return;714}715716private void getPlatformFontPathFromFontConfig() {717if (fontConfigDirs == null) {718fontConfigDirs = getFontConfiguration().getAWTFontPathSet();719if (FontUtilities.debugFonts() && fontConfigDirs != null) {720String[] names = fontConfigDirs.toArray(new String[0]);721for (int i=0;i<names.length;i++) {722FontUtilities.getLogger().info("awtfontpath : " + names[i]);723}724}725}726}727728@Override729protected void registerPlatformFontsUsedByFontConfiguration() {730// Lazily initialize fontConfigDirs.731getPlatformFontPathFromFontConfig();732if (fontConfigDirs == null) {733return;734}735if (FontUtilities.isLinux) {736fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts");737}738fontdirs = (String[])fontConfigDirs.toArray(new String[0]);739}740741// Implements SunGraphicsEnvironment.createFontConfiguration.742protected FontConfiguration createFontConfiguration() {743/* The logic here decides whether to use a preconfigured744* fontconfig.properties file, or synthesise one using platform APIs.745* On Solaris (as opposed to OpenSolaris) we try to use the746* pre-configured ones, but if the files it specifies are missing747* we fail-safe to synthesising one. This might happen if Solaris748* changes its fonts.749* For OpenSolaris I don't expect us to ever create fontconfig files,750* so it will always synthesise. Note that if we misidentify751* OpenSolaris as Solaris, then the test for the presence of752* Solaris-only font files will correct this.753* For Linux we require an exact match of distro and version to754* use the preconfigured file, and also that it points to755* existent fonts.756* If synthesising fails, we fall back to any preconfigured file757* and do the best we can. For the commercial JDK this will be758* fine as it includes the Lucida fonts. OpenJDK should not hit759* this as the synthesis should always work on its platforms.760*/761FontConfiguration mFontConfig = new MFontConfiguration(this);762if (FontUtilities.isOpenSolaris ||763(FontUtilities.isLinux &&764(!mFontConfig.foundOsSpecificFile() ||765!mFontConfig.fontFilesArePresent()) ||766(FontUtilities.isSolaris && !mFontConfig.fontFilesArePresent()))) {767FcFontConfiguration fcFontConfig =768new FcFontConfiguration(this);769if (fcFontConfig.init()) {770return fcFontConfig;771}772}773mFontConfig.init();774return mFontConfig;775}776public FontConfiguration777createFontConfiguration(boolean preferLocaleFonts,778boolean preferPropFonts) {779780return new MFontConfiguration(this,781preferLocaleFonts, preferPropFonts);782}783784protected synchronized String getFontPath(boolean noType1Fonts) {785isHeadless(); // make sure GE is inited, as its the X11 lock.786return getFontPathNative(noType1Fonts, true);787}788789@Override790protected FontUIResource getFontConfigFUIR(String family, int style, int size) {791792CompositeFont font2D = getFontConfigManager().getFontConfigFont(family, style);793794if (font2D == null) { // Not expected, just a precaution.795return new FontUIResource(family, style, size);796}797798/* The name of the font will be that of the physical font in slot,799* but by setting the handle to that of the CompositeFont it800* renders as that CompositeFont.801* It also needs to be marked as a created font which is the802* current mechanism to signal that deriveFont etc must copy803* the handle from the original font.804*/805FontUIResource fuir =806new FontUIResource(font2D.getFamilyName(null), style, size);807FontAccess.getFontAccess().setFont2D(fuir, font2D.handle);808FontAccess.getFontAccess().setCreatedFont(fuir);809return fuir;810}811}812813814