2014-02-24 4 views
1

이 프로그램에서 특정 유니 코드를 제공하고 유니 코드의이 위치에서 문자를 반환하도록 글꼴 파일을 읽는 프로그램을 만들어야합니다 (글꼴에 따라).Java에서 글꼴 파일을 읽는 방법

+0

에게 도움이 될 것입니다. – DaImTo

답변

2
import java.awt.Font; 
import java.io.InputStream; 
import java.util.Map; 
import java.util.concurrent.ConcurrentHashMap; 
public class DemoFonts { 

    private static String[] names = { "A.ttf" }; 

    private static Map<String, Font> cache = new ConcurrentHashMap<String, Font>(names.length); 
    static { 
    for (String name : names) { 
     cache.put(name, getFont(name)); 
    } 
    } 

    public static Font getFont(String name) { 
    Font font = null; 
    if (cache != null) { 
     if ((font = cache.get(name)) != null) { 
     return font; 
     } 
    } 
    String fName = "/fonts/" + name; 
    try { 
     InputStream is = DemoFonts.class.getResourceAsStream(fName); 
     font = Font.createFont(Font.TRUETYPE_FONT, is); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
     System.err.println(fName + " not loaded. Using serif font."); 
     font = new Font("serif", Font.PLAIN, 24); 
    } 
    return font; 
    } 
} 

당신이 TTF 파일에서 읽을하려는 경우 다음이 당신을 당신은 우리가 도움이 될 수 있습니다 전에 시도 것을 우리에게 보여줄 필요가

+0

귀여운 멋진 남자 – Leo

관련 문제