Java uses TTF fonts directly to solve differences between WINDOW and Linux

xiaoxiao2021-03-06  82

In order to solve the Chinese problem on Linux, I searched a circle on Google today, I found that I need to add fonts globally in Linux, reference to the Java to solve. Not dead, because the TTF font can be used directly in the original PHP program, and there is found in the Java class library.

Oh, don't write, directly test the original code.

Import java.io.file; import java.aw. *;

Public class testfont {

Private static string fontpath = "d: // Work // Work // fonts //"; private static java.io.file file = new java.io.file (fontpath "simhei.ttf");

Public TestFont () {}

Public static void main (string args []) {

IF (! file.exists ()) {system.out.println ("File Not Found"); return;} try {java.io.fileinputStream Fi = new java.io.fileinputStream (file); java.io.bufferedInputStream FB = new java.io.bufferedInputStream (Fi); font nf = font.createfont (font.tribyle_font, fb);

NF = nf.derivefont (font.bold, 10); system.out.println (nf.getfontname ()); system.out.println (nf.getsize ());} catch (Exception E) {system.out. PRINTLN (E.getMessage ());}}

}

转载请注明原文地址:https://www.9cbs.com/read-121958.html

New Post(0)