导航:首页 > 编程语言 > javattf

javattf

发布时间:2023-08-15 14:46:01

1. java中如何修改JDialog、JLable等汉字的显示字体

boundary.setFont(new Font("TimesRoman", Font.PLAIN, 13");
如果手头有ttf字体文件还可以通过加载字体文件自定义字体,如下:
Font font = Font.createFont(Font.TRUETYPE_FONT, new File(
"src/Font/minidy.ttf"));

AWT定义的五种逻辑字体:
* SansSerif
* Serif
* Monospaced
* Dialog
* DialogInput
这些字体被映射到客户机上的实际字体如在Windows下,SansSerif被映射到Arial。
Font helvb14 = new Font("Helvetica", Font.BOLD, 14);
第二个参数是字体风格
Font.PLAIN
Font.BOLD
Font.ITALIC
Font.BOLD+Font.ITALIC

提供字体名的位置也可以给出逻辑字体的名称,如
Font sansbold14 = new Font("SansSerif", Font.BOLD, 14);
boundary.setFont(sansbold14);

如果还不懂网络hi我就好!

2. java中如何读取ttf字体文件,生成Font数组

1.读取
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;

public class Loadfont
{
public static Font loadFont(String fontFileName, float fontSize) //第一个参数是外部字体名,第二个是字体大小
{
try
{
File file = new File(fontFileName);
FileInputStream aixing = new FileInputStream(file);
Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, aixing);
Font dynamicFontPt = dynamicFont.deriveFont(fontSize);
aixing.close();
return dynamicFontPt;
}
catch(Exception e)//异常处理
{
e.printStackTrace();
return new java.awt.Font("宋体", Font.PLAIN, 14);
}
}
public static java.awt.Font Font(){
String root=System.getProperty("user.dir");//项目根目录路径
Font font = Loadfont.loadFont(root+"/data/PRISTINA.ttf", 18f);//调用
return font;//返回字体
}
public static java.awt.Font Font2(){
String root=System.getProperty("user.dir");//项目根目录路径
Font font = Loadfont.loadFont(root+"/data/XXXX.ttf", 18f);
return font;//返回字体
}
}
2.转换:
public static String ascii2native(String ascii) {
int n = ascii.length() / 6;
StringBuilder sb = new StringBuilder(n);
for (int i = 0, j = 2; i < n; i++, j += 6) {
String code = ascii.substring(j, j + 4);
char ch = (char) Integer.parseInt(code, 16);
sb.append(ch);
}
return sb.toString();
}

3. java字体设置

写图形控件,如果不指定字体,将会用JRE在操作系统环境下的默认字体。
有源码的情况下,如果去更改JRE的字体,显然不够直接也会破坏统一的环境。

通常是在源码中从显示控件比如Label或JLabel的setFont指定一个统一的字体,比如"宋体"
然后把宋体的字体文件simsun.ttf作为资源文件打在jar中.,或者放在外面作为运行时调用。
这样能统一在各平台的字体效果。

默认情况JRE只提供拉丁字母集的跨平台字体,没有包括中文。

4. java相关,关于使用itext导出pdf后,中文字体设置的问题。

可以直接调用字体 写一个
BaseFont bf=BaseFont.createFont("字体",BaseFont.CP1250, BaseFont.EMBEDDED);
字体就设置,你的那个字体路径

5. java 如何读取otf字体急求高手解答。。

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));

document.open();
BaseFont bf = BaseFont.createFont("esl_gothic_shavian.otf", "Cp1252", BaseFont.EMBEDDED);
System.err.println(bf.getClass().getName());
Font font = new Font(bf, 12);
document.add(new Paragraph("abced"));
document.add(new Paragraph("this is a test", font));
document.close();
}
}

这段程序貌似是把pdf设置成otf字体输出,改一下就好!
这程序绝对经得起考研!从国外教程网站找到d!
把esl_gothic_shavian.otf换成你的字体

6. 如何获取android系统的字体名称

在java环境中有一个专门的获取ttf文件的头信息的Font类
Font f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("seguisym.ttf"));
String name = f.getName();
System.out.println(name);

但是在android环境下,我们无法直接用到该类去解析TTF文件,下面我将附上代码来解析ttf文件
TTFParser.Java

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

/**
* TTF Font file parser
* <p>
* sample:
* <code><pre>
* File fs = new File("C:\\Windows\\Fonts");
* File[] files = fs.listFiles(new FilenameFilter() {
* public boolean accept(File dir, String name) {
* if (name.endsWith("ttf")){ return true;}
* return false;
* }
* });
* for (File file : files) {
* TTFParser parser = new TTFParser();
* parser.parse(file.getAbsolutePath());
* System.out.println("font name: " + parser.getFontName());
* }
* </pre></code>
* <p/>
* Copyright: Copyright (c) 12-8-6 下午3:51
* <p/>
* Version: 1.0
* <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 (fontProperties.containsKey(FULL_FONT_NAME)) {
return fontProperties.get(FULL_FONT_NAME);
} else if (fontProperties.containsKey(FAMILY_NAME)) {
return fontProperties.get(FAMILY_NAME);
} else {
return null;
}
}

/**
* 获取ttf属性
* @param nameID 属性标记,见静态变量
* @return 属性值
*/
public String getFontPropertie(int nameID) {
if (fontProperties.containsKey(nameID)) {
return fontProperties.get(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 {
fontProperties.clear();
RandomAccessFile f = null;
try {
f = new RandomAccessFile(fileName, "r");
parseInner(f);
} finally {
try {
f.close();
}catch (Exception e) {
//ignore;
}
}
}

private void parseInner(RandomAccessFile randomAccessFile) throws IOException {
int majorVersion = randomAccessFile.readShort();
int minorVersion = randomAccessFile.readShort();
int numOfTables = randomAccessFile.readShort();
if (majorVersion != 1 || minorVersion != 0) { return; }

//jump to TableDirectory struct
randomAccessFile.seek(12);

boolean found = false;
byte[] buff = new byte[4];
TbleDirectory tableDirectory = new TableDirectory();
for (int i = 0; i < numOfTables; i++) {
randomAccessFile.read(buff);
tableDirectory.name = new String(buff);
tableDirectory.checkSum = randomAccessFile.readInt();
tableDirectory.offset = randomAccessFile.readInt();
tableDirectory.length = randomAccessFile.readInt();
if ("name".equalsIgnoreCase(tableDirectory.name)) {
found = true;
break;
}else if (tableDirectory.name == null || tableDirectory.name.length() == 0) {
break;
}
}

// not found table of name
if (!found) { return; }
randomAccessFile.seek(tableDirectory.offset);
NameTableHeader nameTableHeader = new NameTableHeader();
nameTableHeader.fSelector = randomAccessFile.readShort();
nameTableHeader.nRCount = randomAccessFile.readShort();
nameTableHeader.storageOffset = randomAccessFile.readShort();
NameRecord nameRecord = new NameRecord();
for (int i = 0; i < nameTableHeader.nRCount; i++) {
nameRecord.platformID = randomAccessFile.readShort();
nameRecord.encodingID = randomAccessFile.readShort();
nameRecord.languageID = randomAccessFile.readShort();
nameRecord.nameID = randomAccessFile.readShort();
nameRecord.stringLength = randomAccessFile.readShort();
nameRecord.stringOffset = randomAccessFile.readShort();
long pos = randomAccessFile.getFilePointer();
byte[] bf = new byte[nameRecord.stringLength];
long vpos = tableDirectory.offset + nameRecord.stringOffset + nameTableHeader.storageOffset;
randomAccessFile.seek(vpos);
randomAccessFile.read(bf);
String temp = new String(bf, Charset.forName("utf-16"));
fontProperties.put(nameRecord.nameID, temp);
randomAccessFile.seek(pos);
}
}

@Override
public String toString() {
return fontProperties.toString();
}

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
}
}

阅读全文

与javattf相关的资料

热点内容
电子资料文件有哪些 浏览:241
猥琐猫表情教程 浏览:599
android音频文件格式 浏览:458
漫画脸app哪里可以下载 浏览:959
购买欢乐升级欢乐豆 浏览:282
学习智能机器人用什么编程最好 浏览:655
苹果手机如何管控app 浏览:633
mn文件夹 浏览:590
安卓平板通用刷机包下载 浏览:751
安卓获取内部存储路径 浏览:880
写代码两台显示器 浏览:327
unitypackage压缩文件 浏览:493
奕心安卓 浏览:563
使用土地的有关证明文件包含哪些 浏览:493
数据标注哪里可以接 浏览:482
在家自学编程下什么学 浏览:705
最近很火的app软件是什么软件 浏览:862
ai文字工具 浏览:157
兰博玩游戏路径怎么选择正确文件 浏览:972
淘宝直通车恢复老版本 浏览:510

友情链接