|
Java example source code file (Win32FontManager.java)
The Win32FontManager.java Java example source code
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import sun.awt.Win32GraphicsEnvironment;
import sun.awt.windows.WFontConfiguration;
import sun.font.FontManager;
import sun.font.SunFontManager;
import sun.font.TrueTypeFont;
import sun.java2d.HeadlessGraphicsEnvironment;
import sun.java2d.SunGraphicsEnvironment;
/**
* The X11 implementation of {@link FontManager}.
*/
public class Win32FontManager extends SunFontManager {
private static String[] defaultPlatformFont = null;
private static TrueTypeFont eudcFont;
static {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
String eudcFile = getEUDCFontFile();
if (eudcFile != null) {
try {
/* Must use Java rasteriser since GDI doesn't
* enumerate (allow direct use) of EUDC fonts.
*/
eudcFont = new TrueTypeFont(eudcFile, null, 0,
true);
} catch (FontFormatException e) {
}
}
return null;
}
});
}
/* Used on Windows to obtain from the windows registry the name
* of a file containing the system EUFC font. If running in one of
* the locales for which this applies, and one is defined, the font
* defined by this file is appended to all composite fonts as a
* fallback component.
*/
private static native String getEUDCFontFile();
public TrueTypeFont getEUDCFont() {
return eudcFont;
}
public Win32FontManager() {
super();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
/* Register the JRE fonts so that the native platform can
* access them. This is used only on Windows so that when
* printing the printer driver can access the fonts.
*/
registerJREFontsWithPlatform(jreFontDirName);
return null;
}
});
}
/**
* Whether registerFontFile expects absolute or relative
* font file names.
*/
protected boolean useAbsoluteFontFileNames() {
return false;
}
/* Unlike the shared code version, this expects a base file name -
* not a full path name.
* The font configuration file has base file names and the FontConfiguration
* class reports these back to the GraphicsEnvironment, so these
* are the componentFileNames of CompositeFonts.
*/
protected void registerFontFile(String fontFileName, String[] nativeNames,
int fontRank, boolean defer) {
// REMIND: case compare depends on platform
if (registeredFontFiles.contains(fontFileName)) {
return;
}
registeredFontFiles.add(fontFileName);
int fontFormat;
if (getTrueTypeFilter().accept(null, fontFileName)) {
fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
} else if (getType1Filter().accept(null, fontFileName)) {
fontFormat = SunFontManager.FONTFORMAT_TYPE1;
} else {
/* on windows we don't use/register native fonts */
return;
}
if (fontPath == null) {
fontPath = getPlatformFontPath(noType1Font);
}
/* Look in the JRE font directory first.
* This is playing it safe as we would want to find fonts in the
* JRE font directory ahead of those in the system directory
*/
String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
StringTokenizer parser = new StringTokenizer(tmpFontPath,
File.pathSeparator);
boolean found = false;
try {
while (!found && parser.hasMoreTokens()) {
String newPath = parser.nextToken();
boolean isJREFont = newPath.equals(jreFontDirName);
File theFile = new File(newPath, fontFileName);
if (theFile.canRead()) {
found = true;
String path = theFile.getAbsolutePath();
if (defer) {
registerDeferredFont(fontFileName, path,
nativeNames,
fontFormat, isJREFont,
fontRank);
} else {
registerFontFile(path, nativeNames,
fontFormat, isJREFont,
fontRank);
}
break;
}
}
} catch (NoSuchElementException e) {
System.err.println(e);
}
if (!found) {
addToMissingFontFileList(fontFileName);
}
}
@Override
protected FontConfiguration createFontConfiguration() {
FontConfiguration fc = new WFontConfiguration(this);
fc.init();
return fc;
}
@Override
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
boolean preferPropFonts) {
return new WFontConfiguration(this,
preferLocaleFonts,preferPropFonts);
}
protected void
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
HashMap<String,String> fontToFamilyNameMap,
HashMap<String,ArrayList
Other Java examples (source code examples)Here is a short list of links related to this Java Win32FontManager.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.