package fonts;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
/**
* Font测试
*
* 不同字体在不同操作系统是不一样的,更新
*
*
linux:
https://blog.csdn.net/spencer_tseng/article/details/135232675
windows:
https://blog.csdn.net/spencer_tseng/article/details/135191991
*
* @author ZengWenFeng
* @date 2023.12.26
* @email 117791303@qq.com
* @mobile 13805029595
*/
public class FontsTest
{
public FontsTest()
{
}
public static void main(String[] args)
{
// 获取GraphicsEnvironment实例
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// 获取所有系统字体的列表
Font[] allFonts = ge.getAllFonts();
// for (Font font : allFonts)
if (allFonts != null && allFonts.length > 0)
{
Font font = null;
for (int i = 0; i < allFonts.length; i++)
{
font = allFonts[i];
if (font == null)
{
continue;
}
System.out.println("Font Name: " + font.getName());
System.out.println("Font Style: " + font.getStyle());
System.out.println("Font Size: " + font.getSize());
System.out.println("---------------------------");
}
}
System.out.println("------------------------------------------------------");
// 创建一个Font对象
// widnows SourceHanSansCN-Light
// linux Source Han Sans CN Light
Font font = new Font("SourceHanSansCN-Light", Font.BOLD, 14);//windows
font = new Font("Source Han Sans CN Light", Font.BOLD, 14);//linux
// 获取并打印字体名称
String fontName = font.getName();
System.out.println("Font Name: " + fontName);
// 获取并打印字体风格
int fontStyle = font.getStyle();
System.out.println("Font Style: " + fontStyle);
// 获取并打印字体大小
int fontSize = font.getSize();
System.out.println("Font Size: " + fontSize);
}
}
linux:
Linux Fonts-CSDN博客
windows:
Windows Fonts-CSDN博客