Created
August 6, 2021 09:55
-
-
Save HydrangeaPurple/2da4024ddace3ee68c00c49136be83ab to your computer and use it in GitHub Desktop.
java版本加载字体
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * 全局加载jvm黑体字体 | |
| * | |
| * @author chengyq | |
| * | |
| */ | |
| @Component | |
| @Order(1) | |
| public class FontLoaderRunner implements CommandLineRunner { | |
| @Override | |
| public void run(String... args) throws Exception { | |
| ClassPathResource classPathResource = new ClassPathResource("simhei.ttf"); | |
| InputStream inputStream = classPathResource.getInputStream(); | |
| Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream); | |
| GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
| ge.registerFont(font); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment