1687N/A/*
3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
1687N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1687N/A *
1687N/A * This code is free software; you can redistribute it and/or modify it
1687N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1687N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1687N/A *
1687N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1687N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1687N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1687N/A * version 2 for more details (a copy is included in the LICENSE file that
1687N/A * accompanied this code).
1687N/A *
1687N/A * You should have received a copy of the GNU General Public License version
1687N/A * 2 along with this work; if not, write to the Free Software Foundation,
1687N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1687N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1687N/A */
1687N/A
1687N/A
1687N/Apackage sun.awt;
1687N/A
1687N/Aimport java.awt.FontFormatException;
1687N/Aimport java.awt.GraphicsEnvironment;
1687N/Aimport java.io.File;
1687N/Aimport java.security.AccessController;
1687N/Aimport java.security.PrivilegedAction;
1687N/Aimport java.util.ArrayList;
1687N/Aimport java.util.HashMap;
1687N/Aimport java.util.Locale;
1687N/Aimport java.util.NoSuchElementException;
1687N/Aimport java.util.StringTokenizer;
1687N/A
1687N/Aimport sun.awt.Win32GraphicsEnvironment;
1687N/Aimport sun.awt.windows.WFontConfiguration;
1687N/Aimport sun.font.FontManager;
1687N/Aimport sun.font.SunFontManager;
1687N/Aimport sun.font.TrueTypeFont;
1687N/Aimport sun.java2d.HeadlessGraphicsEnvironment;
1687N/Aimport sun.java2d.SunGraphicsEnvironment;
1687N/A
1687N/A/**
1687N/A * The X11 implementation of {@link FontManager}.
1687N/A */
1687N/Apublic class Win32FontManager extends SunFontManager {
1687N/A
1687N/A private static String[] defaultPlatformFont = null;
1687N/A
1687N/A private static TrueTypeFont eudcFont;
1687N/A
1687N/A static {
1687N/A
1687N/A AccessController.doPrivileged(new PrivilegedAction() {
1687N/A
1687N/A public Object run() {
1687N/A String eudcFile = getEUDCFontFile();
1687N/A if (eudcFile != null) {
1687N/A try {
3937N/A /* Must use Java rasteriser since GDI doesn't
3937N/A * enumerate (allow direct use) of EUDC fonts.
3937N/A */
1687N/A eudcFont = new TrueTypeFont(eudcFile, null, 0,
3937N/A true);
1687N/A } catch (FontFormatException e) {
1687N/A }
1687N/A }
1687N/A return null;
1687N/A }
1687N/A
1687N/A });
1687N/A }
1687N/A
1687N/A /* Used on Windows to obtain from the windows registry the name
1687N/A * of a file containing the system EUFC font. If running in one of
1687N/A * the locales for which this applies, and one is defined, the font
1687N/A * defined by this file is appended to all composite fonts as a
1687N/A * fallback component.
1687N/A */
1687N/A private static native String getEUDCFontFile();
1687N/A
3354N/A public TrueTypeFont getEUDCFont() {
3354N/A return eudcFont;
3354N/A }
3354N/A
1687N/A public Win32FontManager() {
1687N/A super();
1687N/A AccessController.doPrivileged(new PrivilegedAction() {
1687N/A public Object run() {
1687N/A
1687N/A /* Register the JRE fonts so that the native platform can
1687N/A * access them. This is used only on Windows so that when
1687N/A * printing the printer driver can access the fonts.
1687N/A */
1687N/A registerJREFontsWithPlatform(jreFontDirName);
1687N/A return null;
1687N/A }
1687N/A });
1687N/A }
1687N/A
3963N/A /**
3963N/A * Whether registerFontFile expects absolute or relative
3963N/A * font file names.
3963N/A */
3963N/A protected boolean useAbsoluteFontFileNames() {
3963N/A return false;
3963N/A }
3963N/A
1687N/A /* Unlike the shared code version, this expects a base file name -
1687N/A * not a full path name.
1687N/A * The font configuration file has base file names and the FontConfiguration
1687N/A * class reports these back to the GraphicsEnvironment, so these
1687N/A * are the componentFileNames of CompositeFonts.
1687N/A */
1687N/A protected void registerFontFile(String fontFileName, String[] nativeNames,
1687N/A int fontRank, boolean defer) {
1687N/A
1687N/A // REMIND: case compare depends on platform
1687N/A if (registeredFontFiles.contains(fontFileName)) {
1687N/A return;
1687N/A }
1687N/A registeredFontFiles.add(fontFileName);
1687N/A
1687N/A int fontFormat;
1687N/A if (getTrueTypeFilter().accept(null, fontFileName)) {
1687N/A fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
1687N/A } else if (getType1Filter().accept(null, fontFileName)) {
1687N/A fontFormat = SunFontManager.FONTFORMAT_TYPE1;
1687N/A } else {
1687N/A /* on windows we don't use/register native fonts */
1687N/A return;
1687N/A }
1687N/A
1687N/A if (fontPath == null) {
1687N/A fontPath = getPlatformFontPath(noType1Font);
1687N/A }
1687N/A
1687N/A /* Look in the JRE font directory first.
1687N/A * This is playing it safe as we would want to find fonts in the
1687N/A * JRE font directory ahead of those in the system directory
1687N/A */
1687N/A String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
1687N/A StringTokenizer parser = new StringTokenizer(tmpFontPath,
1687N/A File.pathSeparator);
1687N/A
1687N/A boolean found = false;
1687N/A try {
1687N/A while (!found && parser.hasMoreTokens()) {
1687N/A String newPath = parser.nextToken();
3348N/A boolean isJREFont = newPath.equals(jreFontDirName);
1687N/A File theFile = new File(newPath, fontFileName);
1687N/A if (theFile.canRead()) {
1687N/A found = true;
1687N/A String path = theFile.getAbsolutePath();
1687N/A if (defer) {
1687N/A registerDeferredFont(fontFileName, path,
1687N/A nativeNames,
3348N/A fontFormat, isJREFont,
1687N/A fontRank);
1687N/A } else {
1687N/A registerFontFile(path, nativeNames,
3348N/A fontFormat, isJREFont,
1687N/A fontRank);
1687N/A }
1687N/A break;
1687N/A }
1687N/A }
1687N/A } catch (NoSuchElementException e) {
1687N/A System.err.println(e);
1687N/A }
1687N/A if (!found) {
1687N/A addToMissingFontFileList(fontFileName);
1687N/A }
1687N/A }
1687N/A
1687N/A @Override
1687N/A protected FontConfiguration createFontConfiguration() {
1687N/A
1687N/A FontConfiguration fc = new WFontConfiguration(this);
1687N/A fc.init();
1687N/A return fc;
1687N/A }
1687N/A
1687N/A @Override
1687N/A public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
1687N/A boolean preferPropFonts) {
1687N/A
1687N/A return new WFontConfiguration(this,
1687N/A preferLocaleFonts,preferPropFonts);
1687N/A }
1687N/A
1687N/A protected void
1687N/A populateFontFileNameMap(HashMap<String,String> fontToFileMap,
1687N/A HashMap<String,String> fontToFamilyNameMap,
1687N/A HashMap<String,ArrayList<String>>
1687N/A familyToFontListMap,
1687N/A Locale locale) {
1687N/A
1687N/A populateFontFileNameMap0(fontToFileMap, fontToFamilyNameMap,
1687N/A familyToFontListMap, locale);
1687N/A
1687N/A }
1687N/A
1687N/A private static native void
1687N/A populateFontFileNameMap0(HashMap<String,String> fontToFileMap,
1687N/A HashMap<String,String> fontToFamilyNameMap,
1687N/A HashMap<String,ArrayList<String>>
1687N/A familyToFontListMap,
1687N/A Locale locale);
1687N/A
3354N/A protected synchronized native String getFontPath(boolean noType1Fonts);
1687N/A
1687N/A public String[] getDefaultPlatformFont() {
1687N/A
1687N/A if (defaultPlatformFont != null) {
1687N/A return defaultPlatformFont;
1687N/A }
1687N/A
1687N/A String[] info = new String[2];
1687N/A info[0] = "Arial";
1687N/A info[1] = "c:\\windows\\fonts";
1687N/A final String[] dirs = getPlatformFontDirs(true);
1687N/A if (dirs.length > 1) {
1687N/A String dir = (String)
1687N/A AccessController.doPrivileged(new PrivilegedAction() {
1687N/A public Object run() {
1687N/A for (int i=0; i<dirs.length; i++) {
1687N/A String path =
1687N/A dirs[i] + File.separator + "arial.ttf";
1687N/A File file = new File(path);
1687N/A if (file.exists()) {
1687N/A return dirs[i];
1687N/A }
1687N/A }
1687N/A return null;
1687N/A }
1687N/A });
1687N/A if (dir != null) {
1687N/A info[1] = dir;
1687N/A }
1687N/A } else {
1687N/A info[1] = dirs[0];
1687N/A }
1687N/A info[1] = info[1] + File.separator + "arial.ttf";
1687N/A defaultPlatformFont = info;
1687N/A return defaultPlatformFont;
1687N/A }
1687N/A
1687N/A /* register only TrueType/OpenType fonts
1687N/A * Because these need to be registed just for use when printing,
1687N/A * we defer the actual registration and the static initialiser
1687N/A * for the printing class makes the call to registerJREFontsForPrinting()
1687N/A */
1687N/A static String fontsForPrinting = null;
1687N/A protected void registerJREFontsWithPlatform(String pathName) {
1687N/A fontsForPrinting = pathName;
1687N/A }
1687N/A
1687N/A public static void registerJREFontsForPrinting() {
1687N/A final String pathName;
1687N/A synchronized (Win32GraphicsEnvironment.class) {
1687N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
1687N/A if (fontsForPrinting == null) {
1687N/A return;
1687N/A }
1687N/A pathName = fontsForPrinting;
1687N/A fontsForPrinting = null;
1687N/A }
1687N/A java.security.AccessController.doPrivileged(
1687N/A new java.security.PrivilegedAction() {
1687N/A public Object run() {
1687N/A File f1 = new File(pathName);
1687N/A String[] ls = f1.list(SunFontManager.getInstance().
1687N/A getTrueTypeFilter());
1687N/A if (ls == null) {
1687N/A return null;
1687N/A }
1687N/A for (int i=0; i <ls.length; i++ ) {
1687N/A File fontFile = new File(f1, ls[i]);
1687N/A registerFontWithPlatform(fontFile.getAbsolutePath());
1687N/A }
1687N/A return null;
1687N/A }
1687N/A });
1687N/A }
1687N/A
1687N/A protected static native void registerFontWithPlatform(String fontName);
1687N/A
1687N/A protected static native void deRegisterFontWithPlatform(String fontName);
1687N/A
3361N/A /**
3361N/A * populate the map with the most common windows fonts.
3361N/A */
3361N/A @Override
3361N/A public HashMap<String, FamilyDescription> populateHardcodedFileNameMap() {
3361N/A HashMap<String, FamilyDescription> platformFontMap
3361N/A = new HashMap<String, FamilyDescription>();
3361N/A FamilyDescription fd;
3361N/A
3361N/A /* Segoe UI is the default UI font for Vista and later, and
3361N/A * is used by the Win L&F which is used by FX too.
3361N/A * Tahoma is used for the Win L&F on XP.
3361N/A * Verdana is used in some FX UI controls.
3361N/A */
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "Segoe UI";
3361N/A fd.plainFullName = "Segoe UI";
3361N/A fd.plainFileName = "segoeui.ttf";
3361N/A fd.boldFullName = "Segoe UI Bold";
3361N/A fd.boldFileName = "segoeuib.ttf";
3361N/A fd.italicFullName = "Segoe UI Italic";
3361N/A fd.italicFileName = "segoeuii.ttf";
3361N/A fd.boldItalicFullName = "Segoe UI Bold Italic";
3361N/A fd.boldItalicFileName = "segoeuiz.ttf";
3361N/A platformFontMap.put("segoe", fd);
3361N/A
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "Tahoma";
3361N/A fd.plainFullName = "Tahoma";
3361N/A fd.plainFileName = "tahoma.ttf";
3361N/A fd.boldFullName = "Tahoma Bold";
3361N/A fd.boldFileName = "tahomabd.ttf";
3361N/A platformFontMap.put("tahoma", fd);
3361N/A
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "Verdana";
3361N/A fd.plainFullName = "Verdana";
3361N/A fd.plainFileName = "verdana.TTF";
3361N/A fd.boldFullName = "Verdana Bold";
3361N/A fd.boldFileName = "verdanab.TTF";
3361N/A fd.italicFullName = "Verdana Italic";
3361N/A fd.italicFileName = "verdanai.TTF";
3361N/A fd.boldItalicFullName = "Verdana Bold Italic";
3361N/A fd.boldItalicFileName = "verdanaz.TTF";
3361N/A platformFontMap.put("verdana", fd);
3361N/A
3361N/A /* The following are important because they are the core
3361N/A * members of the default "Dialog" font.
3361N/A */
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "Arial";
3361N/A fd.plainFullName = "Arial";
3361N/A fd.plainFileName = "ARIAL.TTF";
3361N/A fd.boldFullName = "Arial Bold";
3361N/A fd.boldFileName = "ARIALBD.TTF";
3361N/A fd.italicFullName = "Arial Italic";
3361N/A fd.italicFileName = "ARIALI.TTF";
3361N/A fd.boldItalicFullName = "Arial Bold Italic";
3361N/A fd.boldItalicFileName = "ARIALBI.TTF";
3361N/A platformFontMap.put("arial", fd);
3361N/A
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "Symbol";
3361N/A fd.plainFullName = "Symbol";
3361N/A fd.plainFileName = "Symbol.TTF";
3361N/A platformFontMap.put("symbol", fd);
3361N/A
3361N/A fd = new FamilyDescription();
3361N/A fd.familyName = "WingDings";
3361N/A fd.plainFullName = "WingDings";
3361N/A fd.plainFileName = "WINGDING.TTF";
3361N/A platformFontMap.put("wingdings", fd);
3361N/A
3361N/A return platformFontMap;
3361N/A }
1687N/A}