Getting "Font name not found" when loading new TTF fonts ...

740 views
Skip to first unread message

dgoyet...@gmail.com

unread,
Oct 21, 2013, 10:16:24 AM10/21/13
to codenameone...@googlegroups.com
Hi Guys,

I just got a new set of TTF fonts from our graphic designers.  I'm trying to register them with CodenameOne doing something like:

     Font f = Font.createTrueTypeFont("HelveticaNeue", "HelveticaNeue.ttf");

This results in my getting a "Font name not found" exception.   The font file is located in root of my source tree.

The full stack trace for the exception is shown below.  Now the graphic designers are Mac guys, but I assume a true-type font is a true type font regardless of platform.  On the creation of the font, does the CodenameOne code look inside to file to see whether the font names match?

Thanks,
     Dave

java.awt.FontFormatException: Font name not found
at sun.font.TrueTypeFont.init(TrueTypeFont.java:562)
at sun.font.TrueTypeFont.<init>(TrueTypeFont.java:191)
at sun.font.CFontManager.createFont2D(CFontManager.java:157)
at java.awt.Font.<init>(Font.java:614)
at java.awt.Font.createFont(Font.java:939)
at com.codename1.impl.javase.JavaSEPort.loadTrueTypeFont(JavaSEPort.java:3247)
at com.codename1.ui.Font.createTrueTypeFont(Font.java:201)
at org.techna.cip.AppContext.init(AppContext.java:44)
at org.techna.cip.CIPApp.init(CIPApp.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.codename1.impl.javase.Executor$1.run(Executor.java:70)
at com.codename1.ui.Display.processSerialCalls(Display.java:1051)
at com.codename1.ui.Display.mainEDTLoop(Display.java:871)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:119)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.codename1.impl.javase.Executor$1.run(Executor.java:70)
at com.codename1.ui.Display.processSerialCalls(Display.java:1051)
at com.codename1.ui.Display.mainEDTLoop(Display.java:871)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:119)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Caused by: java.lang.RuntimeException: java.awt.FontFormatException: Font name not found
at com.codename1.impl.javase.JavaSEPort.loadTrueTypeFont(JavaSEPort.java:3257)
at com.codename1.ui.Font.createTrueTypeFont(Font.java:201)
at org.techna.cip.AppContext.init(AppContext.java:44)
at org.techna.cip.CIPApp.init(CIPApp.java:28)
... 9 more
Caused by: java.awt.FontFormatException: Font name not found
at sun.font.TrueTypeFont.init(TrueTypeFont.java:562)
at sun.font.TrueTypeFont.<init>(TrueTypeFont.java:191)
at sun.font.CFontManager.createFont2D(CFontManager.java:157)
at java.awt.Font.<init>(Font.java:614)
at java.awt.Font.createFont(Font.java:939)
at com.codename1.impl.javase.JavaSEPort.loadTrueTypeFont(JavaSEPort.java:3247)
... 12 more

dgoyet...@gmail.com

unread,
Oct 21, 2013, 10:49:17 AM10/21/13
to codenameone...@googlegroups.com, dgoyet...@gmail.com
It appears to be related to the font file itself somehow.  I thought it might have to do with a mismatch between the "fontName" parameter on the createTrueTypeFont call and what was encoded in the font itself, but that does not appear to be the case (I verified this by selecting an old arial font TTF file that I had and just arbitrarily naming it "Helvetica", but that worked ok).

So the issue is somehow related to the font file itself.  Like I said, this file came from my mac designers.  Are there restrictions on the type/version of TTF file accepted by CodenameOne?  Do mac TTF fonts have a different encoding from what you are expecting (byte order, format, etc...).  

Dave

Shai Almog

unread,
Oct 21, 2013, 4:05:27 PM10/21/13
to codenameone...@googlegroups.com, dgoyet...@gmail.com
You can't package Helvetica in your app legally. You should have a serious talk with your designer about font copyright, ownership/liability ;-)

Check out the second portion of this post: http://www.codenameone.com/3/post/2013/07/spanning-caching-native-fonts-and-more.html

David Goyette

unread,
Oct 21, 2013, 4:26:25 PM10/21/13
to Shai Almog, codenameone...@googlegroups.com
Hello Shai,

I thought that might be part of the answer, so are you blocking registering of these fonts explicitly?  This is for an internal app, that is not being distributed externally.

Some followup questions:
- If I use "Font.createTrueTypeFont("HelveticaNeue", null)" on Android, will it fail then?
- Are all of the other derivatives also available natively on IOS and Android, namely:  Light, UltraLight, Bold, Condensed, etc...

Dave

dgoyet...@gmail.com

unread,
Oct 21, 2013, 4:59:23 PM10/21/13
to codenameone...@googlegroups.com, Shai Almog, dgoyet...@gmail.com
Hi Shai,

Doing some more reading, I see that I should probably only assume that HelveticaNeue (and its derivatives) is only available on IOS.  I guess that is fine for my application (we are only deploying to IOS to start).  

My related question then is how do I access the other forms of this font on the platform.  I understand that I can get the regular font via:

Font f = Font.createTrueTypeFont("HelveticaNeue", null).

From that, I assume I can derive the bold and italic versions.  However, how do get get access to the Condensed, Light, UltraLight (and all the combinations of the same).

Dave

Shai Almog

unread,
Oct 22, 2013, 1:46:53 AM10/22/13
to codenameone...@googlegroups.com, Shai Almog, dgoyet...@gmail.com
Hi,
we naturally never block anything like this.

You can use http://iosfonts.com/ and pick any name here for iOS fonts.

Rikard Lindgren

unread,
Oct 22, 2013, 2:59:28 PM10/22/13
to codenameone...@googlegroups.com, dgoyet...@gmail.com
Not sure if its related to your problem, but in the Designer you cannot get a font if its named .TTF, only works if its re-named to .ttf.

David Goyette

unread,
Oct 22, 2013, 3:47:11 PM10/22/13
to Rikard Lindgren, codenameone...@googlegroups.com
Thanks Rikard, but no, they were named .ttf (and also, I don't use the Designer, I code everything by hand).  I took Shai's advice and for IOS, simply use the HelveticaNeue fonts available natively. For other platforms, I am using a different set of publicly licensed fonts.

Dave
Reply all
Reply to author
Forward
0 new messages