As you can see some fonts are affected more than others. A few have over half the line cut off. I started digging into the code that displays the text. I figured out the code is determining the height and width of the text and then turning the text into an image to be displayed on the screen. This is done so text can easily be rotated on the display.
Line number 17 in this snippet of code is where the height and width is determined before making the image.
The Adafruit library is using PIL (Python Image Library) to create an image from the text. Ubuntu 14.04 actually uses a fork of PIL called Pillow. I did some google searches and discovered that the textsize function has a bug that does not account for the font offsets which causes the clipping on some fonts. The Ubuntu 14.04 I installed on my BBB came with Pillow 2.3.0 which was broken. I updated it to latest available package which was Pillow 2.5.3 and it was still broken. I looked at the bug fix on the master branch of Pillow and it was just a small change to one file, PIL/ImageFont.py, so I decided to apply that change to my 2.5.3 install of Pillow.
Here is how I fixed it.
cd /usr/local/lib/python2.7/dist-packages/PIL
sudo vi ImageFont.py
At about line 142 look for the getsize function. Here is what it looked like before the change.
And here it is after the change.
Save the file and then you need to compile it into python byte-code.
sudo pycompile ImageFont.py
This creates an ImageFont.pyc file. Now to test it again.All fixed! I'm sure that fix to getsize will be pushed out soon so this won't be a problem in the future but until then this will let me continue my experimentation.
I am using nanopi neo air development board. I am working with ubuntu 15.10 OS. I would like to connect adafruit 2.4 inch pitft via spi. It is worked fine with matrix library provided by nanopineo board. The display got worked. But it outputs the mirror image of the desktop and also half of the display is out of the screen.What could be the reason for this error?. Could you please tell me a way to solve out this problem?
ReplyDelete