I’m hoping someone can save me a learning curve here.  I’m messing with the Adafruit GFX library here with a view to making a subset of my normal MQTT-based code supporting the little 160*128 LCD displays. All of this is working – I can put text up directly from an MQTT message – no problem.

But I’m having trouble getting my head around the GFX fonts.

Firstly – there seems to be a source code command line tool for generating fonts – and I need an LCD-type font… but I cannot find a precompiled version of the tool or similar for Windows and reference to Windows is so vague in the GFX info I’m not sure I want to go experimenting. Has anyone successfully made fonts in Windows for this library?

Secondly font height. The cursor positioning is based on pixels – and it seems that if you want to go to line X of text you have to guess how many pixels you need to use as a multiplier – that can’t be right surely?  There is a function for figuring out the XY bounds of a string so you can use a block erase before writing but that too is in pixels and assumes you know the height of the font. Surely there must be a function somewhere that simply returns the height of the current font?

Pete.

## 17 thoughts on “Adafruit GFX”

1. mrshark says:

why don't you do the conversion on the raspberry? i think it's simpler than finding a windows binary... in the end, it's a one time job... or you can try to do a MAKE in that directory, using cygwin on windows

1. Excellent - the esp8266 of course has no I2c - it's all done in software. Interestingly I'm sitting playing with the Arduino/ESP8266 driver for the QTECH displays (160x120) - and they are SPI - which the ESP does have - and that is FAST.

2. Mike Leist says:

Towards the end of last year I wrote a whole load of extensions and enhancements to that library. In my case I was using a Nokia 5110 device, but that is neither here nor there.

I can let you have a copy of my changes if you would like, however the code isn't documented other than .h and .cpp comments which may make your life easier in some ways and more problematic in others. Let me know.

3. Mike Leist says:

I quickly had a look at the changes I made, and I made a big rewrite of the text/font handling including adding of functions to set/get text position X/Y (as character position, not pixel which you rightly state is all that is there in the Adafruit library).

1. Ok Mike - you definitely have my interest... look forward to it. Link here or direct to my email pete at scargill dot org.....

1. Mike Leist says:

I have sent you an email

1. Well, I tried. With a working Docker in Windows 10 Pro, I made sure the sepal/docker_fontconverter file existed with that github stuff in it and....

D:\tmp>docker run --rm -i -t -v pwd:/fonts sepal/docker_fontconverter fontconvert Inconsolata.otf 12 > Inconsolata.h
Unable to find image 'sepal/docker_fontconverter:latest' locally

1. Mmmm it should try to download the image if it's not locally.... works for me the first try in Mac OS.

Does the classic test works for you?

\$ docker run -it ubuntu bash

PS C:\Users\samstevens> docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
5a132a7e7af1: Pull complete
fd2731e4c50c: Pull complete
28a2f68d1120: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:4e85ebe01d056b43955250bbac22bdb8734271122e3c78d21e55ee235fc6802d

1. So when I tried that other program - it would not load the remote version.
Funny enough I'm getting the same with the Ubuntu - network timed out..

I'm running reasonably fast (6 meg down) internet and no firewall on Windows 10.

C:\Windows\System32>docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
Pulling repository docker.io/library/ubuntu
docker: Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/ubuntu/images. You may want to check your internet connection or if you are behind a proxy..
See 'docker run --help'.

C:\Windows\System32>

2. Ok I give up - finally got Docker to work - it was DNS lookup.... fix was on the site...

docker run --rm -i -t -v pwd:/fonts sepal/fontconverter fontconvert Inconsolata.otf 12 > Inconsolata.h

Getting an error - the font is there - makes a header with nothing but a short error message in it - anything you can see wrong with that command line?

1. Yes, the pwdis a unix command to print the current directory... try something like this:

docker run –rm -i -t -v c:\path\to\your\fontdir:/fonts sepal/fontconverter fontconvert Inconsolata.otf 12 > Inconsolata.h

1. Same error - what is ending up in the header is ...