e652. Getting the Font Faces for a Font Family
To create a Font object to draw text, it is necessary to specify the font face name. This example demonstrates how to retrieve all the font face names from a font family name. Unfortunately, the method is somewhat inefficient since it involves creating one-point size Font objects for every available font in the system. The example caches all the information by 建立一个散列表 that maps a font family name to an array of font face names.
See also e651 列出所有可用字体. Note: J2SE 1.4 only support True Type fonts.
Map fontFaceNames = new HashMap();
// Get all available font faces names
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts();
// Process each font
for (int i=0; i<fonts.length; i++) {
// Get font's family and face
String familyName = fonts[i].getFamily();
String faceName = fonts[i].getName();
// Add font to table
java.util.List list = (java.util.List)fontFaceNames.get(familyName);
if (list == null) {
list = new ArrayList();
fontFaceNames.put(familyName, list);
}
list.add(faceName);
}
// Replace the face name lists with string arrays,
// which are more compact and convenient to use
for (Iterator it=fontFaceNames.keySet().iterator(); it.hasNext(); ) {
String familyName = (String)it.next();
java.util.List list = (java.util.List)fontFaceNames.get(familyName);
fontFaceNames.put(familyName, list.toArray(new String[list.size()]));
}
// Use the table
String[] faces = (String[])fontFaceNames.get("Verdana");
| Related Examples |
e652. Getting the Font Faces for a Font Family的更多相关文章
- [函数] Firemonkey Windows 重新计算 Font Baseline
计算字型 Baseline 是一个不常用的函数,但如果想要显示不同大小文字下方对齐,就得用它来计算字型的 Baseline 才行,如果计算不准,显示的文字就会高高低低不整齐. 在 Firemonkey ...
- java 引入自定义字体font后出现的硬盘吃光的问题
有个需求要用美术字体在图片上写字 用自定义的文字有两个方法: 1. Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, InputStream ...
- Android 使用Font Awesome 显示文字图标
Android 使用Font Awesome 显示文字图标 简单几步就可以完成 简单的效果图: 1. 创建 assets 文件夹 在Android Studio 上的创建步骤为: 在 src/main ...
- Label Font 字体样式设置
label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: Font Family: Amer ...
- Java基础之扩展GUI——使用字体对话框(Sketcher 5 displaying a font dialog)
控制台程序. 为了可以选择系统支持的字体,我们定义了一个FontDialog类: // Class to define a dialog to choose a font import java.aw ...
- iOS FONT字体名
下面这段代码可以查看ios中可用的字体,具体那些字体长什么样,可以查看字体册工具. NSArray *familyArray = [UIFont familyNames]; for (id famil ...
- css基础之 font的简写规则 以及 自定义 CSS3 @font-face详细用法
Part 1 font简写 CSS的命名规则是用英文字母 数字 和下划线(一般用小写)来命名.简写css font的好处有三:一是写起来方便(就像键盘快捷键):二是简化代码:三是帮助你熟悉和深刻理解c ...
- css font简写规则
是不是在很很多网站的公共样式中会看到这样的代码?font: 12px/150% Arial, Verdana, "\5b8b\4f53";意思为:字体大小/行高 字体族 " ...
- 【CSS】font样式简写(转)- 不是很建议简写
一.字体属性主要包括下面几个 font-family,font-style,font-variant,font-weight,font-size,font font-family(字体族): “Ari ...
随机推荐
- Okhttp常用方法示例
这是我用到的一个util类 public class HttpBaseService { private OkHttpClient client = new OkHttpClient(); priva ...
- CSU1256 天朝的单行道(spfa)
1256: 天朝的单行道 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 281 Solved: 92 [Submit][Status][pid=12 ...
- Angularjs 控制器controller的作用
我们在view中给模型的一个参数name赋值 “hello world” . 这是一种简单的赋值,我们可以在视图中通过 ng 指令(以ng-开头的指令)实现了简单的赋值,如果遇到复杂的逻辑运算操作,那 ...
- TCP通信的三次握手和四次撒手的详细流程(顿悟)
TCP(Transmission Control Protocol) 传输控制协议 三次握手 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位 ...
- openvpn中tun和tap的区别
openvpn有dev tun和dev tap模式的区别,cookbook的解释是:A TUN device is used mostly for VPN tunnels where only IP- ...
- Meta Blogging
Meta Blogging 由来 偶然想到说如果哪一天cnblogs挂了,那之前记录的随笔怎么办?可不可以把它们给download下来本地保存一份.正好看到有个库叫requests, 干嘛不试试看呢. ...
- [Linux]运维三十六计--腾讯两位大神的总结
这里是腾讯两位大神梁定安.周小军总记得运维DBA三十六计,So有道理
- sparkSQL1.1入门之四:深入了解sparkSQL执行计划
前面两章花了不少篇幅介绍了SparkSQL的执行过程,非常多读者还是认为当中的概念非常抽象.比方Unresolved LogicPlan.LogicPlan.PhysicalPlan是长得什么样子,没 ...
- Sql Server连接字符串
SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开. PropertyName1=Value1; ...
- 【java web】Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
javaweb报错如下:22:49:22.155 [http-nio-8081-exec-9] ERROR org.apache.struts2.dispatcher.DefaultDispatche ...