我想将一个新字体导入我的Angular 5项目.
我试过了:
1)将文件复制到assets/fonts /
2)将其添加到.angular-cli.json样式中
但我已经检查过该文件不是a .css,它是一个.otf像.exe(它是一个安装程序)的工具,所以我真的不知道如何导入它.任何的想法?
在我的系统上,我需要注册两个外部字体.TTF文件:
HamletOrNot.ttf (74 KB)
MorrisRoman-Black.ttf (67 KB)
Run Code Online (Sandbox Code Playgroud)
在创建Font()对象之前,我使用以下命令进行记录:
/* Set full path of font */
String path = filesPath + fileName;
/* Read file */
Resource resource = applicationContext.getResource( path );
File fontFile = resource.getFile();
/* Load font */
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fontFile ));
Run Code Online (Sandbox Code Playgroud)
然后我创建了对象(我创建了多个Font()因为格式不同):
Font font = new Font( "HamletOrNot" , Font.TRUETYPE_FONT , 10 );
Font font = new Font( "HamletOrNot" , Font.TRUETYPE_FONT , 12 );
Font font = new Font( "MorrisRoman-Black" , Font.TRUETYPE_FONT , 20 ); …Run Code Online (Sandbox Code Playgroud)