Skip to content

Commit 7f15243

Browse files
committed
Add freetype support
1 parent 407d1b9 commit 7f15243

File tree

7 files changed

+90
-1
lines changed

7 files changed

+90
-1
lines changed

bin/imgui-java.dll

735 KB
Binary file not shown.

bin/imgui-java64.dll

773 KB
Binary file not shown.

bin/libimgui-java.so

-60 Bytes
Binary file not shown.

bin/libimgui-java64.so

-24 Bytes
Binary file not shown.

buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class GenerateLibs extends DefaultTask {
2424
// Copy ImGui h/cpp files
2525
project.copy { CopySpec spec ->
2626
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
27+
spec.from(project.rootProject.file('imgui/misc/freetype')) { CopySpec it -> it.include('*.h', '*.cpp') }
2728
spec.from(project.rootProject.file('imgui-binding/src/main/native'))
2829
spec.into(jniDir)
2930
}
@@ -37,6 +38,17 @@ class GenerateLibs extends DefaultTask {
3738
def linux32 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, false)
3839
def linux64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, true)
3940

41+
// Freetype Deps Config
42+
win32.cppFlags += " -fstack-protector -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
43+
win32.libraries += "-lfreetype -lbz2 -lssp"
44+
win64.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
45+
win64.libraries += "-lfreetype -lbz2 -lssp"
46+
linux32.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
47+
linux32.linkerFlags += " -lfreetype"
48+
linux64.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
49+
linux64.linkerFlags += " -lfreetype"
50+
// End
51+
4052
new AntScriptGenerator().generate(buildConfig, win32, win64, linux32, linux64)
4153

4254
// Generate native libraries
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package imgui;
2+
3+
/**
4+
* Read: https://raw.githubusercontent.com/ocornut/imgui/v1.76/misc/freetype/README.md
5+
*/
6+
public final class ImGuiFreeType {
7+
private ImGuiFreeType() {
8+
}
9+
10+
/*JNI
11+
#include <imgui.h>
12+
#include <imgui_freetype.h>
13+
*/
14+
15+
public static void buildFontAtlas(final ImFontAtlas atlas) {
16+
nBuildFontAtlas(atlas.ptr, 0);
17+
}
18+
19+
public static void buildFontAtlas(final ImFontAtlas atlas, int extraFlags) {
20+
nBuildFontAtlas(atlas.ptr, extraFlags);
21+
}
22+
23+
private static native void nBuildFontAtlas(long atlasPtr, int extraFlags); /*
24+
ImGuiFreeType::BuildFontAtlas((ImFontAtlas*)atlasPtr, (unsigned int)extraFlags);
25+
*/
26+
27+
/**
28+
* Hinting greatly impacts visuals (and glyph sizes).
29+
* When disabled, FreeType generates blurrier glyphs, more or less matches the stb's output.
30+
* The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
31+
* The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
32+
* <p>
33+
* You can set those flags on a per font basis in ImFontConfig::RasterizerFlags.
34+
* Use the 'extra_flags' parameter of BuildFontAtlas() to force a flag on all your fonts.
35+
*/
36+
public static final class RasterizerFlags {
37+
/**
38+
* By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
39+
* Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
40+
*/
41+
public static final int NoHinting = 1;
42+
/**
43+
* Disable auto-hinter.
44+
*/
45+
public static final int NoAutoHint = 1 << 1;
46+
/**
47+
* Indicates that the auto-hinter is preferred over the font's native hinter.
48+
*/
49+
public static final int ForceAutoHint = 1 << 2;
50+
/**
51+
* A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape.
52+
* This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis),
53+
* as is done by Microsoft's ClearType and Adobe's proprietary font renderer.
54+
* This preserves inter-glyph spacing in horizontal text.
55+
*/
56+
public static final int LightHinting = 1 << 3;
57+
/**
58+
* Strong hinting algorithm that should only be used for monochrome output.
59+
*/
60+
public static final int MonoHinting = 1 << 4;
61+
/**
62+
* Styling: Should we artificially embolden the font?
63+
*/
64+
public static final int Bold = 1 << 5;
65+
/**
66+
* Styling: Should we slant the font, emulating italic style?
67+
*/
68+
public static final int Oblique = 1 << 6;
69+
/**
70+
* Disable anti-aliasing. Combine this with MonoHinting for best results!
71+
*/
72+
public static final int Monochrome = 1 << 7;
73+
}
74+
}

imgui-lwjgl3/src/test/java/ImGuiGlfwExample.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import imgui.ImFontAtlas;
22
import imgui.ImFontConfig;
33
import imgui.ImGui;
4+
import imgui.ImGuiFreeType;
45
import imgui.ImGuiIO;
56
import imgui.callbacks.ImStrConsumer;
67
import imgui.callbacks.ImStrSupplier;
@@ -262,7 +263,7 @@ public String get() {
262263
// ------------------------------
263264
// Fonts from file/memory example
264265

265-
fontConfig.setRasterizerMultiply(1.2f); // This will make fonts a bit more readable
266+
// fontConfig.setRasterizerMultiply(1.2f); // This will make fonts a bit more readable
266267

267268
// We can add new fonts directly from file
268269
fontAtlas.addFontFromFileTTF("src/test/resources/DroidSans.ttf", 13, fontConfig);
@@ -276,6 +277,8 @@ public String get() {
276277

277278
fontConfig.destroy(); // After all fonts were added we don't need this config more
278279

280+
ImGuiFreeType.buildFontAtlas(fontAtlas, ImGuiFreeType.RasterizerFlags.LightHinting);
281+
279282
// Method initializes LWJGL3 renderer.
280283
// This method SHOULD be called after you've initialized your ImGui configuration (fonts and so on).
281284
// ImGui context should be created as well.

0 commit comments

Comments
 (0)