Proportional/TTF/OTF Fonts using UTFT and windows

Hi all,

I just wanted to let people know I have made a free library available that allows Proportional/TTF/OTF fonts to be displayed on Arduinos. It extends the UTFT library and adds ttf derived font capability. It includes a tool that runs on windows and converts any ttf/otf font into a compact proportional bitmap font for use on TFT displays.

I did it for my own needs, but have made it available in case it's useful to others.

It can be downloaded from:

Enjoy.

David.

Nice, I'm planning to do a similar program that outputs 8bpp (1 bit for ON/OFF and 7 bits for alpha channel) so I can use anti aliased fonts. Space is not really a problem because I soldered a 4Mb flash chip on the back of the display. Or I could reduce to 4bpp maybe.

So I have no use of your program, but good work anyway, it will help people :wink:

Edit: removed stupid comment about The Dot Factory.. :slight_smile:

Thanks Guix.

Yep, hopefully someone else can benefit. I was running out of screen space so needed a proportional font to tighten it up.

Ooooh. Anti-aliasing. Well at least your fonts will look nice and smooth (although I was really happy with Verdana on my TFT, without anti-aliasing).

I hadn't heard of the dot factory. I used freetype as the ttf/otf reader engine. Worked out nicely.

Hi David,

I don't know if you still follow your thread? I just wanted to say I was a little slow to the party but I am glad I discovered this thread!

I have pointed folks here from another thread, just thought you should know.

http://forum.arduino.cc/index.php?topic=164788.msg1885789#msg1885789

The major use for this that I can see, is people wishing to use the BVS fonts included in the Coldtears display font IC, that do not have that ic. So I located Bitstream Vera Sans.ttf and converted it using your ttf2c_vc2003 tool to all the sizes I know about, and this worked flawlessly thankyou!!

However one 'slight' niggle/suggestion if I may? Could you modify the tool slightly to use as the c array name? Such that

ttf2c 112 vera.ttf BVS_112.c

would yield a c array of the same name as the filename in this case BVS_112.c?

I am surprised a thread as old as this, offering the features you do, has not gotten more traffic or comments, so let me say a big thankyou! I for one certainly appreciate your efforts and can definitely see it receiving some use here.

Regards,

Graham

Hi Graham and others,

Thanks for the nice words. I'm glad it's useful to you.

To answer your questions:

  1. I don't follow the thread that often, but occasionally check in here. I looked today because someone posted a question to me through my website.
  2. Unfortunately it's a bit of a pain to change the code at the moment. It has to be built with particular (older) compilers to ensure it runs everywhere, and I don't have those on this computer (and I'm overseas for the next year or so). However, the behaviour you are after can be easily done using a script. For those who haven't done it before, a simple dos command line batch script would probably give you and others any specific behaviour they're after.

Something like (untested):
REM ttf2c_2003.exe %1 %2 %3.c
ttf2c_~1.exe %1 %2 %3.c
ren %3.c %3%1.c

Put that in ttf.bat, then instead of calling the exe file directly, call it through "ttf 18 font.ttf outname" (no .c extension on the last parameter).

Alternatively, use a scripting language of your choice for more complex manipulations.

I thought I would also take the opportunity to answer a couple of questions that have been posted to me at my website.

For those who are trying to use the ttf conversion utility, it is a DOS command line utility. So, to run it, you need to start a DOS command prompt, then change to the directory and run it. Doing so will print out the usage text.

Additionally, while I appreciate people taking the time to write comments to me, I don't tend to respond to general usage questions posted on my website. The appropriate place for those types of questions is here, in the forum. That way others can help, as well as other people in the same position as you get to see the answers. Please try your questions here, as Graham has done, and if that fails, by all means post through my website.

Thanks for everyone's interest, and I'm glad people are getting some benefit from this.

Cheers,

David.

arduinodlb:
2) Unfortunately it's a bit of a pain to change the code at the moment. It has to be built with particular (older) compilers to ensure it runs everywhere, and I don't have those on this computer (and I'm overseas for the next year or so). However, the behaviour you are after can be easily done using a script. For those who haven't done it before, a simple dos command line batch script would probably give you and others any specific behaviour they're after.

Something like (untested):
REM ttf2c_2003.exe %1 %2 %3.c
ttf2c_~1.exe %1 %2 %3.c
ren %3.c %3%1.c

Put that in ttf.bat, then instead of calling the exe file directly, call it through "ttf 18 font.ttf outname" (no .c extension on the last parameter).

Perfect! Thank you.

Regards,

Graham

Hello, good evening, first of all thanks for sharing this library !! and I wonder do those things .....

I have a question / problem, your library is compatible with this?

I tried but did not work (the example of your library).
Thank you!

flatron:
Hello, good evening, first of all thanks for sharing this library !! and I wonder do those things .....

I have a question / problem, your library is compatible with this?

GitHub - pantata/TFT9341SPI

I tried but did not work (the example of your library).
Thank you!

This library is a "bolt-on" for Henning Karlsen's wonderful UTFT suit of libraries, if your display works with those, then this library will work alongside to provide proportional fonts.

However.... Having looked at the link you provided, it is a modified version of the UTFT libraries, as such, there are incompatibilities. Would it be possible to use the UTFT libraries unmodified directly from Henning Karlsen? One of the modules supported by Henning that could be a suitable candidate is

TFT01_22SP

as the UTFT type which utilises the ILI9341 Controller? If you can make that work, then I suspect this library will work. Otherwise, you are out of luck due to the nature of the modifications in the pantata library.

Regards,

Graham

sorry but how to use your:

"ttf2c_2003.exe"

Hi kuestenkind,

Ok, let's talk you through this.

First, make a file called ttf.bat and copy this into it.

REM ttf2c_2003.exe %1 %2 %3.c
ttf2c_~1.exe %1 %2 %3.c
ren %3.c %3%1.c

Copy the ttf.bat file into your "\Arduino\libraries\UTFT_DLB\tools" folder.

Second, copy your font file into your "\Arduino\libraries\UTFT_DLB\tools" folder. eg Arial.ttf

Third, open windows command prompt (start >run >cmd)

You will need to go to the "\Arduino\libraries\UTFT_DLB\tools" folder. using command CD

eg. CD  \users\graham\my documents\arduino\libraries\utft_dlb\tools

This is my folder on Win7, yours will be different of course!! But you should be able to understand what to do......

Fourth, type DIR

You should see :- "ttf.bat" , "ttf2c_2003.exe" and "arial.ttf" files..........

Fifth, type this :-

ttf 16 arial.ttf arial

If everything went well, you will see a file called "arial16.c"

Sixth, Move "arial16.c" into your "\arduino\libraries\utft_dlb" folder.

It's not actually as complicated as it looks!!

Regards,

Graham

Kuestenkind:
sorry but how to use your:

"ttf2c_2003.exe"

You can do what Graham suggests if you want particular filenames, or you can just start a windows cmd.exe prompt, change to the directory that contains the "ttf2c_2003.exe" program, and type "ttf2c_2003.exe". It will then print out how to use it. You must do this from a windows command prompt. If you don't know what that is, then you may have to read a little about that on the internet.

Can anybody suggest how we might be able to modify this to work with UTFT_Buttons, such that we can have proportional font button labels?

Merry Christmas to all!!

Graham

OOOh..............

Since IDE V1.5.7 we appear to have a problem with ttf2c_2003.exe :cry: The generated fonts are now not allowed since font type is uint8_t, whereas it should be const uint8_t.

Could you possibly implement this change please?

Merry Christmas everyone,

Graham

Hi Graham,

UTFTDLB_Buttons already exists and can be downloaded from the same website. It also allows for different buttons to be different colours.

Unfortunately changing my program is a bit of a pain, so you'll have to add the const yourself, either using a scripting language like perl or python, or by hand.

Merry Christmas.

DB.

Hi there DB,

I would just like to say thanks for a wonderful add-on to my already favorite UTFT library!
It has provided me with much needed screen real estate.

Hi Dim,

Thanks for the post and the screenshot. It's always great to see people getting use out of these things.

Cheers,

DB.

Hi, you may be interested in this Instructable where I have published my solution with kerned proportional fonts.

Fonts have been added to the Adafruit_GFX library and it has been renamed Adafruit_GFX_AS

If you use a different display driver library then you just need to change the references in that library from Adafruit_GFX to Adafruit_GFX_AS.

Cheers,
Alan

Hi DB

I would also like to echo the sentiments of others and thank you for this great library - it makes everything look so much better!!

My question - UTFT_DLB works with the standard UTFT library but does it replace it? I note that you have a 'print' function in your library but there is nothing equivalent to the printNumI or printNumF functions found in the original library. When I try to use these functions nothing is displayed on the screen. I have been able to overcome this issue by converting the number using dtostrf and then using the print function but is this the best way to do it?

I am also using your button library - the original button library allows the use of bitmaps as buttons. Is it possible to use both button types in a sketch i.e. some bitmap buttons and some buttons using your proportional fonts? Or, can I only use one or the other?

Thanks

Hi Magic,

UTFT_DLB extends the UTFT library, but I didn't extend every function. I was trying to minimize the size of the additional code and as you discovered, decided that the functionality of printNumF and printNumI could be replicated by converting to a string. Yes, it's slower, but it makes the library smaller and I think in most cases, is a satisfactory solution. Alternatively, you could extend UTFT_DLB and add your own printNumF and printNumI functions, but I'd just do what you're doing. Or add a local printNumF/printNumI that converts it to a string and uses UTFT_DLB. The only disadvantage is slightly slower speed.

Good question about the buttons. My instinct says two things:

  1. You could probably mix them.
  2. More importantly, there is no reason to mix them. Just make them all UTFT_DLB buttons. UTFT_DLB buttons can use standard UTFT bitmaps, UTFT fonts, as well as UTFT_DLB type fonts as far as I can recall. Apart from proportional fonts in buttons, the library also allows the buttons to be different colours, which was important for my application.

Not sure how helpful that is, but my Arduino stuff is currently in another country.

If you test these combinations, please report back here with the results so we know for sure.

Cheers,

David.