在java环境中有一个专门的获取ttf文件的头信息的Font类
Font f = FontcreateFont(FontTRUETYPE_FONT, new FileInputStream("seguisymttf"));
String name = fgetName();
Systemoutprintln(name);
但是在android环境下,我们无法直接用到该类去解析TTF文件,下面我将附上代码来解析ttf文件
TTFParserJava
import javaioIOException;
import javaioRandomAccessFile;
import javaniocharsetCharset;
import javautilHashMap;
import javautilMap;
/
TTF Font file parser
<p>
sample:
<code><pre>
File fs = new File("C:\\Windows\\Fonts");
File[] files = fslistFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (nameendsWith("ttf")){ return true;}
return false;
}
});
for (File file : files) {
TTFParser parser = new TTFParser();
parserparse(filegetAbsolutePath());
Systemoutprintln("font name: " + parsergetFontName());
}
</pre></code>
<p/>
Copyright: Copyright (c) 12-8-6 下午3:51
<p/>
Version: 10
<p/>
/
public class TTFParser {
public static int COPYRIGHT = 0;
public static int FAMILY_NAME = 1;
public static int FONT_SUBFAMILY_NAME = 2;
public static int UNIQUE_FONT_IDENTIFIER = 3;
public static int FULL_FONT_NAME = 4;
public static int VERSION = 5;
public static int POSTSCRIPT_NAME = 6;
public static int TRADEMARK = 7;
public static int MANUFACTURER = 8;
public static int DESIGNER = 9;
public static int DESCRIPTION = 10;
public static int URL_VENDOR = 11;
public static int URL_DESIGNER = 12;
public static int LICENSE_DESCRIPTION = 13;
public static int LICENSE_INFO_URL = 14;
private Map<Integer, String> fontProperties = new HashMap<Integer, String>();
/
获取ttf font name
@return
/
public String getFontName() {
if (fontPropertiescontainsKey(FULL_FONT_NAME)) {
return fontPropertiesget(FULL_FONT_NAME);
} else if (fontPropertiescontainsKey(FAMILY_NAME)) {
return fontPropertiesget(FAMILY_NAME);
} else {
return null;
}
}
/
获取ttf属性
@param nameID 属性标记,见静态变量
@return 属性值
/
public String getFontPropertie(int nameID) {
if (fontPropertiescontainsKey(nameID)) {
return fontPropertiesget(nameID);
} else { return null; }
}
/
获取ttf属性集合
@return 属性集合(MAP)
/
public Map<Integer, String> getFontProperties() { return fontProperties; }
/
执行解析
@param fileName ttf文件名
@throws IOException
/
public void parse(String fileName) throws IOException {
fontPropertiesclear();
RandomAccessFile f = null;
try {
f = new RandomAccessFile(fileName, "r");
parseInner(f);
} finally {
try {
fclose();
}catch (Exception e) {
//ignore;
}
}
}
private void parseInner(RandomAccessFile randomAccessFile) throws IOException {
int majorVersion = randomAccessFilereadShort();
int minorVersion = randomAccessFilereadShort();
int numOfTables = randomAccessFilereadShort();
if (majorVersion != 1 || minorVersion != 0) { return; }
//jump to TableDirectory struct
randomAccessFileseek(12);
boolean found = false;
byte[] buff = new byte[4];
TbleDirectory tableDirectory = new TableDirectory();
for (int i = 0; i < numOfTables; i++) {
randomAccessFileread(buff);
tableDirectoryname = new String(buff);
tableDirectorycheckSum = randomAccessFilereadInt();
tableDirectoryoffset = randomAccessFilereadInt();
tableDirectorylength = randomAccessFilereadInt();
if ("name"equalsIgnoreCase(tableDirectoryname)) {
found = true;
break;
}else if (tableDirectoryname == null || tableDirectorynamelength() == 0) {
break;
}
}
// not found table of name
if (!found) { return; }
randomAccessFileseek(tableDirectoryoffset);
NameTableHeader nameTableHeader = new NameTableHeader();
nameTableHeaderfSelector = randomAccessFilereadShort();
nameTableHeadernRCount = randomAccessFilereadShort();
nameTableHeaderstorageOffset = randomAccessFilereadShort();
NameRecord nameRecord = new NameRecord();
for (int i = 0; i < nameTableHeadernRCount; i++) {
nameRecordplatformID = randomAccessFilereadShort();
nameRecordencodingID = randomAccessFilereadShort();
nameRecordlanguageID = randomAccessFilereadShort();
nameRecordnameID = randomAccessFilereadShort();
nameRecordstringLength = randomAccessFilereadShort();
nameRecordstringOffset = randomAccessFilereadShort();
long pos = randomAccessFilegetFilePointer();
byte[] bf = new byte[nameRecordstringLength];
long vpos = tableDirectoryoffset + nameRecordstringOffset + nameTableHeaderstorageOffset;
randomAccessFileseek(vpos);
randomAccessFileread(bf);
String temp = new String(bf, CharsetforName("utf-16"));
fontPropertiesput(nameRecordnameID, temp);
randomAccessFileseek(pos);
}
}
@Override
public String toString() {
return fontPropertiestoString();
}
private static class TableDirectory {
String name; //table name
int checkSum; //Check sum
int offset; //Offset from beginning of file
int length; //length of the table in bytes
}
private static class NameTableHeader {
int fSelector; //format selector Always 0
int nRCount; //Name Records count
int storageOffset; //Offset for strings storage,
}
private static class NameRecord {
int platformID;
int encodingID;
int languageID;
int nameID;
int stringLength;
int stringOffset; //from start of storage area
}
}
接着点击access数据库的文件菜单。
然后找到文件菜单下的“选项”,点击它。
如图,接着就会打开access选项面板,在这里找到“对象设计器”。
如图,在对象设计器的右边,可以修改查询设计界面的字体。
在这里设置好字体的大小,然后点击下方的确定按钮就可以应用这个字体大小了。
最后,我们需要重启一下access数据库,这样,才可以显示修改后的字体大小哦。
不好意思Access是不能保存您的设置信息的。Access只是存储信息、检索信息。而且您完全没有必要这么做。因为在使用Access的报表功能时,在报表窗体内是支持设置数据格式的,包括字体的大小、颜色、样式等等信息的。
具体效果您可以看图。
首先点击该设计界面右上角的极大化按钮将设计界面窗口极大化(或者将光标移到窗体右下角处,当出现两边有小黑箭头的符号时向外拖动鼠标,设置窗体设计窗口的大小到你满意为止)。
其实名片窗体的大小是由“主体”部分设定的。现在我们将光标移到“窗体页脚”的上边框处,当出现上下箭头时,往下(或上)拖到合适的地方;再将光标移到“主体”内容的右边框处,当出现左右箭头时,往右(或左)拖到合适的地方。
以上就是关于如何获取android系统的字体名称全部的内容,包括:如何获取android系统的字体名称、access数据库怎样修改字体大小、在ACCESS中,如何设置让一个字段可以保存word中的字体信息。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)