本文整理汇总了Java中java.awt.Font.createFont方法的典型用法代码示例。如果您正苦于以下问题:Java Font.createFont方法的具体用法?Java Font.createFont怎么用?Java Font.createFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Font
的用法示例。
在下文中一共展示了Font.createFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBelwe
import java.awt.Font; //导入方法依赖的package包/类
public static Font getBelwe(int size) {
try {
Font font = Font.createFont(Font.TRUETYPE_FONT, Fontes.class.getResourceAsStream("/com/limagiran/hearthstone/util/belwe.ttf"));
font = font.deriveFont(Font.BOLD, size);
return font;
} catch (Exception ex) {
}
return new Font("Tahoma", Font.BOLD, size);
}
示例2: IconFactory
import java.awt.Font; //导入方法依赖的package包/类
/**
* Creates the icon factory
*/
public IconFactory() {
try {
fontAwesome = Font.createFont(Font.TRUETYPE_FONT, IconFactory.class.getResourceAsStream("/fontawesome-webfont.ttf"));
} catch (Exception e) {
ExceptionHandler.get().handle(e);
}
mapping = loadMapings();
}
示例3: updateFont
import java.awt.Font; //导入方法依赖的package包/类
private void updateFont()
{
try
{
Font mcfont = Font.createFont(Font.TRUETYPE_FONT,
this.getClass().getClassLoader()
.getResourceAsStream("assets/minecraft/font/mcfont.ttf"));
mcfont = mcfont.deriveFont(12F);
Font defaultFont = new Font("Monospaced", Font.PLAIN, 14);
spamArea.setFont(wurst.options.spamFont ? mcfont : defaultFont);
}catch(Exception e1)
{
e1.printStackTrace();
}
}
示例4: registerFont
import java.awt.Font; //导入方法依赖的package包/类
public static boolean registerFont(File fontFile) {
boolean b = false;
try {
Font f = Font.createFont(Font.TRUETYPE_FONT, fontFile);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(f);
b = true;
} catch (FontFormatException | IOException e) {
b = false;
}
return b;
}
示例5: loadResources
import java.awt.Font; //导入方法依赖的package包/类
public static void loadResources() {
try(InputStream mainFontIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntu.ttf");
InputStream mainFontBoldIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntuBold.ttf")) {
mainFont = Font.createFont(Font.TRUETYPE_FONT, mainFontIn);
mainFontBold = Font.createFont(Font.TRUETYPE_FONT, mainFontBoldIn);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(mainFont);
ge.registerFont(mainFontBold);
} catch (IOException | FontFormatException e) {
e.printStackTrace();
System.exit(-1);
}
}
示例6: tryLoadFontFromFile
import java.awt.Font; //导入方法依赖的package包/类
/**
* Will try to load a font from the specified ttf file.
* If successful, will correctly set drawing attributes.
* Otherwise will output an error, but will not halt the program.
* @param fName ttf file to load from.
*/
private void tryLoadFontFromFile(String fName) {
try {
Font temp = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fName));
fontName = fName;
dFont = temp;
loadedFonts.add(temp);
loadedFiles.add(fName);
}
catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR: EZText was unable to load a text from the specified file:" + fName);
System.out.println(" The change will not be applied.");
}
}
示例7: getFont
import java.awt.Font; //导入方法依赖的package包/类
private static Font getFont(String name, int size) {
try {
InputStream in = FlagInfoPanel.class.getResourceAsStream(name);
Font font = Font.createFont(Font.TRUETYPE_FONT, in);
return font.deriveFont((float)size);
} catch (Exception e) {
return null;
}
}
示例8: LoginPage
import java.awt.Font; //导入方法依赖的package包/类
/**
* Creates new form LoginPage
*/
public LoginPage() throws Exception {
initComponents();
logoSetup();
try {
InputStream is = LoginPage.class.getResourceAsStream("cac_champagne.ttf");
Font cac_champagne = Font.createFont(Font.TRUETYPE_FONT, is);
jLabel1.setFont(cac_champagne.deriveFont(Font.PLAIN, 48f)); // NOI18N
jLabel1.setForeground(new java.awt.Color(239, 239, 239));
jLabel1.setText("fodder");
is = LoginPage.class.getResourceAsStream("DAGGERSQUARE.otf");
Font DAGGERSQUARE = Font.createFont(Font.TRUETYPE_FONT, is);
jLabel5.setFont(DAGGERSQUARE.deriveFont(Font.PLAIN, 36f)); // NOI18N
jLabel5.setForeground(new java.awt.Color(101, 43, 215));
jLabel5.setText("Login");
} catch(IOException | FontFormatException e) {
System.out.println("Font not found");
}
Color borderColor = new Color(179, 193, 193);
jPanel1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.WHITE));
username1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
password1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
password1.setEchoChar((char)0);
password1.setText("Password");
usernameRegistration.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
password_registartion.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
password_registartion.setEchoChar((char)0);
password_registartion.setText("Password");
name.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
email.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
this.setLocationRelativeTo(null);
}
示例9: FontResource
import java.awt.Font; //导入方法依赖的package包/类
/**
* Do not use directly.
*
* @param resourceLocator The {@code URI} used when loading this
* resource.
* @exception IOException if unable to read the font.
*/
public FontResource(URI resourceLocator) throws IOException {
super(resourceLocator);
font = null;
try {
if (resourceLocator.getPath() != null
&& resourceLocator.getPath().endsWith(".ttf")) {
URL url = resourceLocator.toURL();
font = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
} else {
String name = resourceLocator.getSchemeSpecificPart();
font = Font.decode(name.substring(SCHEME.length()));
}
if (font != null) {
GraphicsEnvironment.getLocalGraphicsEnvironment()
.registerFont(font);
}
logger.info("Loaded font: " + font.getFontName()
+ " from: " + resourceLocator);
} catch (FontFormatException|IOException ex) {
logger.log(Level.WARNING,
"Failed loading font from: " + resourceLocator, ex);
throw new IOException(ex.getMessage());
}
}
示例10: main
import java.awt.Font; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
// The bug only happens with Type 1 fonts. The Ghostscript font files
// should be commonly available. From distro pacakge or
// ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz
// Pass pfa/pfb font file as argument
String path = args[0];
// Load
InputStream stream = new FileInputStream(path);
Font font = Font.createFont(Font.TYPE1_FONT,stream);
// Ensure native bits have been generated
BufferedImage img = new BufferedImage(100,100,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
FontRenderContext frc = g2d.getFontRenderContext();
font.getLineMetrics("derp",frc);
// Force disposal -
// System.gc() is not sufficient.
Field font2DHandleField = Font.class.getDeclaredField("font2DHandle");
font2DHandleField.setAccessible(true);
sun.font.Font2DHandle font2DHandle =
(sun.font.Font2DHandle)font2DHandleField.get(font);
sun.font.Font2D font2D = font2DHandle.font2D;
sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D;
Method getScalerMethod =
sun.font.Type1Font.class.getDeclaredMethod("getScaler");
getScalerMethod.setAccessible(true);
sun.font.FontScaler scaler =
(sun.font.FontScaler)getScalerMethod.invoke(type1Font);
// dispose should not crash due to double free
scaler.dispose();
}
示例11: writeImage
import java.awt.Font; //导入方法依赖的package包/类
public static void writeImage(File fontFile, File outputFile, String value) throws Exception {
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.BLACK);
Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
font = font.deriveFont(Font.PLAIN, 72f);
FontRenderContext frc = new FontRenderContext(null, false, false);
GlyphVector gv = font.createGlyphVector(frc, value);
g.drawGlyphVector(gv, 10, 80);
g.fill(gv.getOutline(10, 180));
ImageIO.write(image, "png", outputFile);
}
示例12: createFont
import java.awt.Font; //导入方法依赖的package包/类
public static TrueTypeFont createFont(ResourceLocation res, float defSize, boolean antialias, int type, char[] additionalChars) {
Font font;
TrueTypeFont out = null;
try {
font = Font.createFont(type, Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream());
font = font.deriveFont(defSize);
out = new TrueTypeFont(font, antialias, additionalChars);
} catch (Exception e) {
e.printStackTrace();
}
return out;
}
示例13: FontData
import java.awt.Font; //导入方法依赖的package包/类
/**
* Create a new font data element
*
* @param ttf The TTF file to read
* @param size The size of the new font
* @throws IOException Indicates a failure to
*/
private FontData(InputStream ttf, float size) throws IOException {
if (ttf.available() > MAX_FILE_SIZE) {
throw new IOException("Can't load font - too big");
}
byte[] data = IOUtils.toByteArray(ttf);
if (data.length > MAX_FILE_SIZE) {
throw new IOException("Can't load font - too big");
}
this.size = size;
try {
javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data));
TTFFile rawFont = new TTFFile();
if (!rawFont.readFont(new FontFileReader(data))) {
throw new IOException("Invalid font file");
}
upem = rawFont.getUPEM();
ansiKerning = rawFont.getAnsiKerning();
charWidth = rawFont.getAnsiWidth();
fontName = rawFont.getPostScriptName();
familyName = rawFont.getFamilyName();
String name = getName();
System.err.println("Loaded: "+name+" ("+data.length+")");
boolean bo = false;
boolean it = false;
if (name.indexOf(',') >= 0) {
name = name.substring(name.indexOf(','));
if (name.indexOf("Bold") >= 0) {
bo = true;
}
if (name.indexOf("Italic") >= 0) {
it = true;
}
}
if ((bo & it)) {
javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC);
} else if (bo) {
javaFont = javaFont.deriveFont(Font.BOLD);
} else if (it) {
javaFont = javaFont.deriveFont(Font.ITALIC);
}
} catch (FontFormatException e) {
IOException x = new IOException("Failed to read font");
x.initCause(e);
throw x;
}
}
示例14: SwingFrame
import java.awt.Font; //导入方法依赖的package包/类
/**
* Public constructor.
*
* @param screen the Screen that Backend talks to
*/
public SwingFrame(final SwingScreen screen) {
this.screen = screen;
setDOSColors();
// Figure out my cursor style
String cursorStyleString = System.getProperty(
"jexer.Swing.cursorStyle", "underline").toLowerCase();
if (cursorStyleString.equals("underline")) {
cursorStyle = CursorStyle.UNDERLINE;
} else if (cursorStyleString.equals("outline")) {
cursorStyle = CursorStyle.OUTLINE;
} else if (cursorStyleString.equals("block")) {
cursorStyle = CursorStyle.BLOCK;
}
if (System.getProperty("jexer.Swing.tripleBuffer") != null) {
if (System.getProperty("jexer.Swing.tripleBuffer").
equals("false")) {
SwingScreen.tripleBuffer = false;
}
}
setTitle("Jermit");
setBackground(Color.black);
try {
// Always try to use Terminus, the one decent font.
ClassLoader loader = Thread.currentThread().
getContextClassLoader();
InputStream in = loader.getResourceAsStream(FONTFILE);
Font terminusRoot = Font.createFont(Font.TRUETYPE_FONT, in);
Font terminus = terminusRoot.deriveFont(Font.PLAIN, 20);
setFont(terminus);
gotTerminus = true;
} catch (Exception e) {
e.printStackTrace();
// setFont(new Font("Liberation Mono", Font.PLAIN, 24));
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 24));
}
pack();
// Kill the X11 cursor
// Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16,
BufferedImage.TYPE_INT_ARGB);
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
cursorImg, new Point(0, 0), "blank cursor");
setCursor(blankCursor);
// Be capable of seeing Tab / Shift-Tab
setFocusTraversalKeysEnabled(false);
// Save the text cell width/height
getFontDimensions();
// Cache glyphs as they are rendered
glyphCacheBlink = new HashMap<Cell, BufferedImage>();
glyphCache = new HashMap<Cell, BufferedImage>();
// Setup triple-buffering
if (SwingScreen.tripleBuffer) {
setIgnoreRepaint(true);
createBufferStrategy(3);
bufferStrategy = getBufferStrategy();
}
}
示例15: Instructions
import java.awt.Font; //导入方法依赖的package包/类
public Instructions(JFrame f, int frameBoundX, int frameBoundY) {
// Font
InputStream is = Menu.class.getResourceAsStream("Cheap Potatoes.ttf");
try {
font = Font.createFont(Font.TRUETYPE_FONT, is);
} catch (FontFormatException | IOException e1) {
// TODO Auto-generated catch
// block
e1.printStackTrace();
}
//Main Panel of Instructions Section created here
JPanel instrPanel = new JPanel();
instrPanel.setLayout(null);
setBounds(0,0,frameBoundX, frameBoundY);
//Logo
JLabel logoLabel = new JLabel("GEOTRIX", SwingConstants.CENTER);
sizedFont = font.deriveFont(68f);
logoLabel.setFont(sizedFont);
logoLabel.setBounds(frameBoundX / 2 - 200, (frameBoundY-520)/ 2, 400, 190);
JButton backButton = new JButton("Back");
backButton.setBorderPainted(false);
backButton.setFocusPainted(false);
backButton.setContentAreaFilled(false);
sizedFont = font.deriveFont(Font.BOLD, 30f);
backButton.setFont(sizedFont);
backButton.setForeground(Color.RED);
backButton.setBounds(10, 10, 200, 100);
// when backButton clicked
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//remove panel
instrPanel.setVisible(false);
f.remove(instrPanel);
new MainMenu(f, frameBoundX, frameBoundY);
}
});
//Logo
JLabel instructionLabel = new JLabel("Arrow keys + Space button", SwingConstants.CENTER);
sizedFont = font.deriveFont(40f);
instructionLabel.setFont(sizedFont);
instructionLabel.setBounds(25, frameBoundY/2 - 100, frameBoundX - 50, 200);
instrPanel.add(instructionLabel);
//Background Icon
String img = "background_revision.jpg";
ImageIcon imgIc = new ImageIcon(this.getClass().getResource(img));
//Backgroud Label
JLabel bgLabel = new JLabel(imgIc);
bgLabel.setBounds(0, 0, frameBoundX, frameBoundY);
instrPanel.add(backButton);
instrPanel.add(logoLabel);
instrPanel.add(bgLabel);
f.add(instrPanel);
f.revalidate();
f.setVisible(true);
}