When I try to use TTF font, i get the following error
[xml]<text font = “arial.ttf” id=“text” size = “32” style=“nifty-label” color="#FFFFFF" text=“Instructions” align=“center” valign=“center”/>[/xml]
java.lang.IllegalStateException: No loader registered for type “ttf”
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:223)
at com.jme3.asset.DesktopAssetManager.loadFont(DesktopAssetManager.java:339)
at com.jme3.niftygui.RenderFontJme.(RenderFontJme.java:54)
at com.jme3.niftygui.RenderDeviceJme.createFont(RenderDeviceJme.java:116)
at de.lessvoid.nifty.render.NiftyRenderEngineImpl.createFont(NiftyRenderEngineImpl.java:166)
at de.lessvoid.nifty.loaderv2.types.apply.Convert.font(Convert.java:35)
at de.lessvoid.nifty.loaderv2.types.apply.ApplyRenderText.apply(ApplyRenderText.java:23)
at de.lessvoid.nifty.elements.Element.initializeFromAttributes(Element.java:338)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyAttributes(ElementType.java:217)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:171)
at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:143)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyChildren(ElementType.java:250)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:174)
at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:143)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyChildren(ElementType.java:250)
at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:174)
at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:143)
at de.lessvoid.nifty.loaderv2.types.ScreenType.create(ScreenType.java:71)
at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:137)
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:468)
at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:369)
at mygame.Main.initGUIText(Main.java:261)
at mygame.Main.simpleInitApp(Main.java:206)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:219)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:117)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:188)
at java.lang.Thread.run(Thread.java:619)
What font formats are supported with Nifty 1.3?
Only the fonts compatible with jME3, so AngelFonts. There are converters to select a system font and make it an angelfont file. I am also working on adding that to jMP so you just say New File… Font… Select the system font and its created for you.
What is the file format of AngleFont. Is it fnt?
Can you suggest me a converter for converting ttf to anglefont. I google about it, but didn’t see anything related to angle font.
ok, now i have the font file, but when I run the application the GUI is empty
I am using the following code:
[xml]<text id=“text” font =“Interface/C.fnt” style=“nifty-label” color="#FFFFFF" text=“Instructions” align=“center” valign=“center”/>[/xml]
No text…why?
But, if I try changing to the default font that comes with jMP…it works fine.
[xml]<text id=“text” font =“Interface/Fonts/Default.fnt” style=“nifty-label” color="#FFFFFF" text=“Instructions” align=“center” valign=“center”/>[/xml]
Font:
C.fnt Download Link
Did you copy the image too?
Yes, supply the PNGs next to the fnt-file and flip the images vertically because Hiero doesn’t output them correctly for JME
Yeh, Bitmap Font Generator wasn’t producing the png files for some unknown reason. But Hiero did it.
Anyway, anyone knows any bulk process to flip all of those images together? I am using Paint .NET and It dont have anything like that.
iamcreasy said:
Anyway, anyone knows any bulk process to flip all of those images together? I am using Paint .NET and It dont have anything like that.
Well, you could use Microsoft Office Picture Manager (if you have it) to do batch flippin' if you're still using the alternative Bitmap Font Generator (e.g. Hiero).
I can't find the FontCreator on the platform as well though I tried enabling the nightly-updates. Seems like it can't even do an update on the platform at the moment.
Thanks to this thread, i'm using Hiero too. it's working great as an alternative! :D ---but, you gotta batch-flip the .png files that comes together with it. This step doesn't really bother much actually.
iamcreasy said:
Yeh, Bitmap Font Generator wasn't producing the png files for some unknown reason.
What was it producing?
I don’t know if this is still in demand, but if you look up the ttf-font-loader by Kaelthas here in the forums, you can get a TTF Loader for jme3, which you’d just have to edit a little bit, so the nifty calls will not trigger the IllegalArgumentException in the load(AssetInfo) method.
I’ve already editted the file, so if you’re still interested, I could put the functions I’ve changed up here.
Cheers,
wiki
P.S.: The editing isn’t perfect, though, since I only edited it for test purposes at the moment. For now I use a standard color, size and type (white, 20 and bold). So you’d probably have to edit that, too, still.
Hi @wickermoon,
I think i could use your code so please post it. One question maybe before you do so : does using ttf avoid us to have one fnt file per size? If so I really would like it. Else : what is the real advantage then?
Many thanks in advance (and please don’t mind if I don’t answer quickly i’m far from home on Holidays).
Hey @shower,
I’m not absolutely sure what you mean by “avoiding to have one fnt file per size”. As far as I know, you can use one fnt-file for any size, or do you mean something else? Anyway, one advantage is that you can use true type fonts.
Also, to clarify, the TTFLoader is NOT my code! @Kaelthas wrote it and posted it somewhere here on the forums and allowed me to use it (in my project). Also, my project is only for testing purposes and not monetized in any shape, way or form, so I’m not sure about commercial use, IF that is one of your purposes (just saying). So, look up the code here on the forums (shouldn’t be too hard to find).
That being said, there are two functions I’ve adjusted for use with nifty:
The first one is the
[java]public Object load(AssetInfo assetInfo) throws IOException[/java] function:
[java]@Override
public Object load(AssetInfo assetInfo) throws IOException
{
if (assetInfo.getKey() instanceof FontKey)
{
return load(assetInfo, (FontKey) assetInfo.getKey());
}
else if(assetInfo.getKey().getExtension().equals(“ttf”))
{
FontKey convertedKey = new FontKey(assetInfo.getKey().getName(), Font.TRUETYPE_FONT, Color.WHITE, 20, Font.BOLD);
return load(assetInfo, convertedKey);
}
throw new IllegalArgumentException("The given asset key should be of type: " + FontKey.class.getName());
}
private Object load(AssetInfo assetInfo, FontKey fontKey) throws IOException
{
Graphics2D graphics = this.getGraphics();
Font font = this.getFont(assetInfo, fontKey);
graphics.setFont(font);
FontData fontData = this.calculateFontData(graphics, fontKey);
Texture t = this.prepareTexture(fontData, graphics, fontKey.getColor());
this.setPagesForFont(assetInfo, fontData.bitmapFont, t);
return fontData.bitmapFont;
}
[/java]
the second one is the [java]protected Font getFont(AssetInfo assetInfo) throws IOException[/java] function, to which I also added a short javadoc explanation, so that I’ll always know why I did this:
[java]/**
- This method loads AWT type font from the stream indicated by assetInfo.<br>
- <br>
- Even though the FontKey is usually contained in the {@link AssetInfo assetInfo},
- the supplied assetInfo via a nifty-gui-call will not have such a key. In order for this
- loader to be able to load ttf fonts for the nifty gui, this function got a second
- parameter, which is explicitely asking for the {@link FontKey fontKey}.
*
-
@param assetInfo The information about font asset
-
@param fontKey FontKey information
*
-
@return AWT type font
-
@throws IOException
-
an exception is thrown if there are problems with the stream<br />
-
itself or with the font type (it should be TrueType)<br />
*/
protected Font getFont(AssetInfo assetInfo, FontKey fontKey) throws IOException
{
try
{
return Font.createFont(fontKey.getType(), assetInfo.openStream()).deriveFont(fontKey.getStyle(), fontKey.getSize());
} catch (FontFormatException e)
{
throw new IOException(e.getMessage(), e);
}
}
[/java]
And that’s it. @Kaelthas I hope you’re okay with me posting the edited versions of your functions? If not, please let me know!
Cheers, wiki
P.S.: Again, I want to stress the point that the whole TTFLoader is a work of Kaelthas (I’m not sure if I’m allowed to use his real name (which is in the code), or if that’s name calling or something) and that I merely customized it very crudely!
Well I previously saw on a topic (http://hub.jmonkeyengine.org/groups/gui/forum/topic/fontsize/) that you needed one fnt file per size you would like :s
Didn’t test it on my own since this isn’t one of my main problems as for today ^^.
Could you please post also one example of how you call the ttf font once you have loaded it with your method. Its mainly to see if you really can implement “size” and also because i won’t try/implement this code before 2 or 3 weeks because of my developpment planning and holidays. I’d rather not revive the topic then.
Anyway thanks to Kaelthas (if he really does let us use his code ^^) and to you.