MCPcopy Index your code
hub / github.com/SpaiR/imgui-java / initFonts

Method initFonts

example/src/main/java/Main.java:45–74  ·  view source on GitHub ↗

Example of fonts configuration For more information read: https://github.com/ocornut/imgui/blob/33cdbe97b8fd233c6c12ca216e76398c2e89b0d8/docs/FONTS.md

(final ImGuiIO io)

Source from the content-addressed store, hash-verified

43 * For more information read: https://github.com/ocornut/imgui/blob/33cdbe97b8fd233c6c12ca216e76398c2e89b0d8/docs/FONTS.md
44 */
45 private void initFonts(final ImGuiIO io) {
46 // This enables FreeType font renderer, which is disabled by default.
47 io.getFonts().setFreeTypeRenderer(true);
48
49 // Add default font for latin glyphs
50 io.getFonts().addFontDefault();
51
52 // You can use the ImFontGlyphRangesBuilder helper to create glyph ranges based on text input.
53 // For example: for a game where your script is known, if you can feed your entire script to it (using addText) and only build the characters the game needs.
54 // Here we are using it just to combine all required glyphs in one place
55 final ImFontGlyphRangesBuilder rangesBuilder = new ImFontGlyphRangesBuilder(); // Glyphs ranges provide
56 rangesBuilder.addRanges(io.getFonts().getGlyphRangesDefault());
57 rangesBuilder.addRanges(io.getFonts().getGlyphRangesCyrillic());
58 rangesBuilder.addRanges(io.getFonts().getGlyphRangesJapanese());
59 rangesBuilder.addRanges(FontAwesomeIcons._IconRange);
60
61 // Font config for additional fonts
62 // This is a natively allocated struct so don't forget to call destroy after atlas is built
63 final ImFontConfig fontConfig = new ImFontConfig();
64 fontConfig.setMergeMode(true); // Enable merge mode to merge cyrillic, japanese and icons with default font
65
66 final short[] glyphRanges = rangesBuilder.buildRanges();
67 io.getFonts().addFontFromMemoryTTF(loadFromResources("Tahoma.ttf"), 14, fontConfig, glyphRanges); // cyrillic glyphs
68 io.getFonts().addFontFromMemoryTTF(loadFromResources("NotoSansCJKjp-Medium.otf"), 14, fontConfig, glyphRanges); // japanese glyphs
69 io.getFonts().addFontFromMemoryTTF(loadFromResources("fa-regular-400.ttf"), 14, fontConfig, glyphRanges); // font awesome
70 io.getFonts().addFontFromMemoryTTF(loadFromResources("fa-solid-900.ttf"), 14, fontConfig, glyphRanges); // font awesome
71 io.getFonts().build();
72
73 fontConfig.destroy();
74 }
75
76 @Override
77 public void process() {

Callers 1

initImGuiMethod · 0.95

Calls 13

addRangesMethod · 0.95
setMergeModeMethod · 0.95
buildRangesMethod · 0.95
loadFromResourcesMethod · 0.95
getFontsMethod · 0.80
addFontDefaultMethod · 0.80
addFontFromMemoryTTFMethod · 0.80
setFreeTypeRendererMethod · 0.45
getGlyphRangesDefaultMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected