⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontutil.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.util;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;

// Referenced classes of package com.golden.gamedev.util:
//            ImageUtil

public class FontUtil
{

    public static Font createTrueTypeFont(URL url, int i, float f)
    {
        Font font;
        try
        {
            font = Font.createFont(0, url.openStream());
        }
        catch(IOException _ex)
        {
            System.err.println("ERROR: " + url + " is not found or can not be read");
            font = new Font("Verdana", 0, 0);
        }
        catch(FontFormatException _ex)
        {
            System.err.println("ERROR: " + url + " is not a valid true type font");
            font = new Font("Verdana", 0, 0);
        }
        return font.deriveFont(i, f);
    }

    public static BufferedImage createBitmapFont(Font font, Color color)
    {
        Graphics2D graphics2d;
        FontMetrics fontmetrics = (graphics2d = ImageUtil.createImage(1, 1).createGraphics()).getFontMetrics(font);
        graphics2d.dispose();
        byte abyte0[] = new byte[95];
        for(int i = 0; i < abyte0.length; i++)
            abyte0[i] = (byte)(32 + i);

        String s = new String(abyte0);
        int j = fontmetrics.stringWidth(s);
        int k = fontmetrics.getHeight();
        int l = s.length();
        int i1 = 0;
        int j1 = (k - fontmetrics.getDescent()) + 1;
        Color color1;
        if((color1 = Color.GREEN).equals(color))
            color1 = Color.YELLOW;
        BufferedImage bufferedimage;
        (graphics2d = (bufferedimage = ImageUtil.createImage(j, k, 2)).createGraphics()).setFont(font);
        for(int k1 = 0; k1 < l; k1++)
        {
            char c = s.charAt(k1);
            graphics2d.setColor(color1);
            graphics2d.drawLine(i1, 0, i1, 0);
            graphics2d.setColor(color);
            graphics2d.drawString(String.valueOf(c), i1, j1);
            i1 += fontmetrics.charWidth(c);
        }

        graphics2d.dispose();
        return bufferedimage;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -