Skip to content

Commit b49f77c

Browse files
authored
Export built-in fonts as j3o to remove PNG loader dependency in jme3-core (#2832)
* Initial plan * Export Default.fnt and Console.fnt as j3o with embedded image data The fonts Default.fnt and Console.fnt reference PNG textures (Default.png, Console.png) which require StbImageLoader from jme3-plugins to load. jme3-android and jme3-ios include General.cfg (which registers StbImageLoader) but only depend on jme3-core, not jme3-plugins, causing failures when the engine tries to display the default stats/UI. Fix: export both fonts as .j3o binary files with the texture image data embedded directly (no asset key, so no PNG loader needed at runtime). Update all jme3-core load sites to use the .j3o variants. Add DefaultFontJ3oTest to verify Default.j3o loads without a PNG loader. * Add Console.j3o test and refactor DefaultFontJ3oTest helper * Remove unnecessary loader registrations from DefaultFontJ3oTest --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent f5a37ff commit b49f77c

8 files changed

Lines changed: 53 additions & 6 deletions

File tree

jme3-core/src/main/java/com/jme3/app/DetailedProfilerState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ protected void initialize(Application app) {
108108

109109
ui.attachChild(darkenStats);
110110
ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0);
111-
font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt");
112-
bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
111+
font = app.getAssetManager().loadFont("Interface/Fonts/Console.j3o");
112+
bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.j3o");
113113
prof.setRenderer(app.getRenderer());
114114
rootLine = new StatLineView("Frame");
115115
rootLine.attachTo(ui);

jme3-core/src/main/java/com/jme3/app/SimpleApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void setShowSettings(boolean showSettings) {
248248
* @return the loaded BitmapFont
249249
*/
250250
protected BitmapFont loadGuiFont() {
251-
return assetManager.loadFont("Interface/Fonts/Default.fnt");
251+
return assetManager.loadFont("Interface/Fonts/Default.j3o");
252252
}
253253

254254
@Override

jme3-core/src/main/java/com/jme3/app/StatsAppState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void initialize(AppStateManager stateManager, Application app) {
155155
}
156156

157157
if (guiFont == null) {
158-
guiFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
158+
guiFont = app.getAssetManager().loadFont("Interface/Fonts/Default.j3o");
159159
}
160160

161161
loadFpsText();

jme3-core/src/main/java/com/jme3/app/StatsView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public StatsView(String name, AssetManager manager, Statistics stats) {
8282
statLabels = statistics.getLabels();
8383
statData = new int[statLabels.length];
8484

85-
BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
85+
BitmapFont font = manager.loadFont("Interface/Fonts/Console.j3o");
8686
statText = new BitmapText(font);
8787
statText.setLocalTranslation(0, statText.getLineHeight() * statLabels.length, 0);
8888
attachChild(statText);

jme3-core/src/main/java/com/jme3/input/virtual/VirtualJoystickTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public class VirtualJoystickTheme implements Savable {
4747

48-
private static final String DEFAULT_FONT = "Interface/Fonts/Default.fnt";
48+
private static final String DEFAULT_FONT = "Interface/Fonts/Default.j3o";
4949

5050
public enum TextureKey {
5151
BUTTON,
261 KB
Binary file not shown.
266 KB
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.jme3.asset;
2+
3+
import com.jme3.asset.plugins.ClasspathLocator;
4+
import com.jme3.export.binary.BinaryLoader;
5+
import com.jme3.font.BitmapFont;
6+
import com.jme3.material.plugins.J3MLoader;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertNotNull;
10+
11+
/**
12+
* Verifies that Default.j3o (with embedded image data) can be loaded using only
13+
* the loaders available in jme3-core, without depending on the PNG loader from
14+
* jme3-plugins. This is needed for Android/iOS which don't depend on jme3-plugins.
15+
*/
16+
public class DefaultFontJ3oTest {
17+
18+
private static DesktopAssetManager createCoreOnlyAssetManager() {
19+
DesktopAssetManager assetManager = new DesktopAssetManager(false);
20+
assetManager.registerLocator("/", ClasspathLocator.class);
21+
assetManager.registerLoader(BinaryLoader.class, "j3o", "j3f");
22+
assetManager.registerLoader(J3MLoader.class, "j3m", "j3md");
23+
return assetManager;
24+
}
25+
26+
private static void assertFontLoaded(DesktopAssetManager assetManager, String path) {
27+
BitmapFont font = assetManager.loadFont(path);
28+
assertNotNull(font, path + " should load without a PNG loader");
29+
assertNotNull(font.getPage(0), path + " should have at least one material page");
30+
assertNotNull(font.getPage(0).getTextureParam("ColorMap"),
31+
path + " material page should have a ColorMap texture");
32+
assertNotNull(font.getPage(0).getTextureParam("ColorMap").getTextureValue().getImage(),
33+
path + " texture should have embedded image data (no key needed)");
34+
}
35+
36+
@Test
37+
public void testDefaultFontJ3oLoadsWithoutPngLoader() {
38+
// This should succeed: Default.j3o has embedded image data (no PNG loader needed)
39+
assertFontLoaded(createCoreOnlyAssetManager(), "Interface/Fonts/Default.j3o");
40+
}
41+
42+
@Test
43+
public void testConsoleFontJ3oLoadsWithoutPngLoader() {
44+
// This should succeed: Console.j3o has embedded image data (no PNG loader needed)
45+
assertFontLoaded(createCoreOnlyAssetManager(), "Interface/Fonts/Console.j3o");
46+
}
47+
}

0 commit comments

Comments
 (0)