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 ...
随机推荐
- oracle序列sequence操作汇总(命令)--待续
1.创建sequence 2.删除sequence 3.查询有哪些sequence select * from user_objects where object_type='SEQUENCE'; 4 ...
- tp表单的提交与验证
一.控制器如下 引用use app\index\model\User; //注意模型类名不能和控制器类名相同 public function index(){ return $this->fet ...
- hdu4901The Romantic Hero
#include<iostream> #include<map> #include<string> #include<cstring> #include ...
- HDU 1260 Tickets (动规)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- Linux下修改时间时区的方法介绍
点评:在Linux中,用于时钟查看和设置的命令主要有date.hwclock和clock.其中,clock和 hwclock用法相近,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件 ...
- [svc]samba服务搭建
说实话搞这些很蛋疼, 没啥技术含量. What is Samba? 这个历史悠久了 Since 1992, Samba has provided secure, stable and fast fil ...
- 用Visual Studio Code写Node和调试代码
介绍 vsc的宣传语是: 一个运行于 Mac OS X.Windows和 Linux 之上的,针对于编写现代 Web 和云应用的跨平台源代码编辑器. 按它说的,vsc特别适合来作为前端开发编辑器. 内 ...
- 某人在企业中遇到的Spark问题记录[持续更新]
https://github.com/ssg-7max/ssg 目前 ssg内公司内部 spark streaming 处理数据源是kafka 目前遇到最大的问题是,会延迟,例如我们配置1分钟让窗口计 ...
- js事件委托及其原理
1,什么是事件委托:通俗的讲,事件就是onclick,onmouseover,onmouseout,等就是事件,委托呢,就是让别人来做,这个事件本来是加在某些元素上的,然而你却加到别人身上来做,完成这 ...
- PLSQL Developer新手使用教程(图文教程)
PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能,下面简单的介 ...