public static Object createScaler() throws ReflectiveOperationException { // these APIs are used to reproduce the specific case I encountered // as closely as possible Font2D font = FontUtilities.getFont2D(new Font("Noto Sans CJK JP Black", 0, 12)); // this is a reconstruction of what happens at the end of a call stack like: // - BasicListUI.updateLayoutState() // - JComponent.getPreferredSize() // - JComponent.getFontMetrics(Font) // - TrueTypeFont.getScaler Constructor<?> constructor = Class .forName("sun.font.T2KFontScaler") .getConstructor(Font2D.class, int.class, boolean.class, int.class); constructor.setAccessible(true); return constructor.newInstance(font, 0, true, 18604592); }
public FontConfiguration(SunFontManager fm) { if (FontUtilities.debugFonts()) { FontUtilities.getLogger() .info("Creating standard Font Configuration"); } if (FontUtilities.debugFonts() && logger == null) { logger = PlatformLogger.getLogger("sun.awt.FontConfiguration"); } fontManager = fm; setOsNameAndVersion(); /* static initialization */ setEncoding(); /* static initialization */ /* Separating out the file location from the rest of the * initialisation, so the caller has the option of doing * something else if a suitable file isn't found. */ findFontConfigFile(); }
public FontConfiguration(SunFontManager fm, boolean preferLocaleFonts, boolean preferPropFonts) { fontManager = fm; if (FontUtilities.debugFonts()) { FontUtilities.getLogger() .info("Creating alternate Font Configuration"); } this.preferLocaleFonts = preferLocaleFonts; this.preferPropFonts = preferPropFonts; /* fontConfig should be initialised by default constructor, and * its data tables can be shared, since readFontConfigFile doesn't * update any other state. Also avoid a doPrivileged block. */ initFontConfig(); }
private boolean strNeedsTextLayout(String str, Font font) { char[] chars = str.toCharArray(); boolean isComplex = FontUtilities.isComplexText(chars, 0, chars.length); if (!isComplex) { return false; } else if (!useGDITextLayout) { return true; } else { if (preferGDITextLayout || (isXP() && FontUtilities.textLayoutIsCompatible(font))) { return false; } else { return true; } } }
protected FontConfiguration createFontConfiguration() { /* The logic here decides whether to use a preconfigured * fontconfig.properties file, or synthesise one using platform APIs. * On Solaris we try to use the * pre-configured ones, but if the files it specifies are missing * we fail-safe to synthesising one. This might happen if Solaris * changes its fonts. * For Linux we require an exact match of distro and version to * use the preconfigured file. * If synthesising fails, we fall back to any preconfigured file * and do the best we can. For the commercial JDK this will be * fine as it includes the Lucida fonts. OpenJDK should not hit * this as the synthesis should always work on its platforms. */ FontConfiguration mFontConfig = new MFontConfiguration(this); if ((FontUtilities.isLinux && !mFontConfig.foundOsSpecificFile()) || (FontUtilities.isSolaris && !mFontConfig.fontFilesArePresent())) { FcFontConfiguration fcFontConfig = new FcFontConfiguration(this); if (fcFontConfig.init()) { return fcFontConfig; } } mFontConfig.init(); return mFontConfig; }
private static FontRenderContext getFRCProperty(JComponent c) { if (c != null) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); AffineTransform tx = (gc == null) ? null : gc.getDefaultTransform(); // [tav] workaround deadlock on MacOSX until fixed, JRE-226 if (!FontUtilities.isMacOSX && tx == null && !GraphicsEnvironment.isHeadless()) { tx = GraphicsEnvironment .getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .getDefaultTransform(); } AATextInfo info = (AATextInfo)c.getClientProperty(AA_TEXT_PROPERTY_KEY); if (info != null) { return info.getFRC(tx); } } return null; }