element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NFC/RFID
  • Challenges & Projects
  • Project14
  • NFC/RFID
  • More
  • Cancel
NFC/RFID
Blog NFC-Badge - Update your badge with your smartphone - The right font for the display
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NFC/RFID to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bernhardmayer
  • Date Created: 23 Jun 2019 4:25 PM Date Created
  • Views 1693 views
  • Likes 5 likes
  • Comments 0 comments
  • ttf
  • font
  • nfcrfidch
  • converter
  • badge
  • display
  • true type font
  • freetype
Related
Recommended

NFC-Badge - Update your badge with your smartphone - The right font for the display

bernhardmayer
bernhardmayer
23 Jun 2019

Choosing the right font for the display is always a difficult task. Especially for small displays there is only a limited number of fonts available and often they come from the display manufacturer and have some restrictions on their library. On the other hand there are nearly unlimited true type fonts available on your computer.

 

So I wrote a converter.

 

My display EA DOGM128-6 comes with a library. This library doesn't map the display content in its memory but writes it directly to the display and uses the memory of the display controller. The advantage of this behavior is that it only needs very little RAM. The downside is that always 8 vertical bits of the display have to be written. So everything is aligned to multiples of 8 and nothing overlaps.

 

This is also true for the font files. The fonts are always multiples of 8 high and additionally all characters have the same width (monospaced font).

 

The converter uses the FreeType library (https://www.freetype.org/ ) and is intended to run on Linux. On my machine I use Ubuntu.

 

The converter accepts any font which is supported by FreeType. This should be any font available on a Linux system. Also most of these fonts come with an open source license. So licensing shouldn't be an issue any more. Generating display fonts which are only 8 bits high is a little bit tricky as most fonts don't scale down very good. Generating fonts with 16 bit height works very well. The converter accepts the following arguments

 

usage: 
-f <path to file>      path to file with font
-n <name>              name for header file with font and name of font constant
-s <number>            font-size
-b <number>            baseline for the font in pixels from top
-g <number>            height of font in bytes for generated file
-d                     printf debug messages
-h                     print this help

 

Name is only the name for the generated file and font and can be chosen randomly. Font size should be chosen according to the height of the font in bits. If the font is 16 bits high a font size of 16 is a good start. But not all fonts scale evenly and this has to be adjusted to get the optimal size. Also the baseline of the font can be set. The baseline should be somewhere in the lower quarter of the hieght. So if the font is 16 bits high then the baseline should be at the 12th bit from top. But this can also be adjusted for optimal size.

 

The source code and makefile for the converter are available on github: https://github.com/generationmake/freetypeconverter

 

This is an example font file (16 bit high) generated from the font UbuntuMono-B.ttf:

 

/* file generated by freetype converter 0.1 - 2019-06-23 */
/* find the latest version on https://github.com/generationmake/freetypeconverter */
/* converter called with: */
/* ./freetypeconverter -n UBUNTUMONO_B_16 -f /usr/share/fonts/truetype/ubuntu/UbuntuMono-B.ttf  */

#define UBUNTUMONO_B_16_LEN 1528
const byte UBUNTUMONO_B_16[UBUNTUMONO_B_16_LEN] __attribute__((section(".progmem.data"))) = 
{
70,86,0x20,0x7E,8,16,2,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,0x00,0x00,0x00,
0x3E,0x3E,0x00,0x3E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x30,0xF0,0x3C,0xF0,0xFC,0x3C,0x30,0x03,0x0F,0x03,0x0F,0x0F,0x03,0x03,0x03,
0x70,0xF8,0xDE,0xDE,0x98,0x18,0x00,0x00,0x06,0x0C,0x3C,0x3D,0x0F,0x07,0x00,0x00,
0x3C,0x24,0x3C,0xC0,0x30,0x08,0x04,0x00,0x08,0x06,0x01,0x00,0x0F,0x09,0x0F,0x00,
0x00,0xB8,0x7C,0xCC,0xBC,0x18,0xC0,0x00,0x07,0x0F,0x0C,0x0C,0x0F,0x07,0x0F,0x0C,
0x3E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xE0,0xF8,0x1C,0x06,0x02,0x00,0x00,0x00,0x07,0x1F,0x38,0x70,0x20,0x00,0x00,0x00,
0x02,0x06,0x0C,0x18,0xF0,0xE0,0x00,0x00,0x00,0x60,0x30,0x3C,0x0F,0x07,0x00,0x00,
0x30,0xB0,0xE0,0x7C,0xE0,0xB0,0x30,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
0x80,0x80,0x80,0xF0,0xF0,0x80,0x80,0x80,0x01,0x01,0x01,0x0F,0x0F,0x01,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x6E,0x3E,0x1E,0x00,0x00,0x00,0x00,
0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x0E,0x04,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xF8,0x3E,0x06,0x00,0x00,0x60,0x7E,0x1F,0x01,0x00,0x00,0x00,0x00,
0xF0,0xFC,0xCC,0xCC,0xFC,0xF0,0x00,0x00,0x03,0x0F,0x0C,0x0C,0x0F,0x03,0x00,0x00,
0x10,0x18,0x18,0xFC,0xFC,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0F,0x0F,0x0C,0x0C,0x00,
0x08,0x0C,0x8C,0xCC,0x7C,0x38,0x00,0x00,0x0E,0x0F,0x0D,0x0C,0x0C,0x0C,0x00,0x00,
0x08,0xCC,0xCC,0xCC,0xFC,0x38,0x00,0x00,0x0C,0x0C,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0x80,0xC0,0x70,0x18,0xFC,0xFC,0x00,0x00,0x03,0x03,0x03,0x03,0x0F,0x0F,0x03,0x00,
0x00,0x7C,0x7C,0xEC,0xEC,0xCC,0x00,0x00,0x0C,0x0C,0x0C,0x0C,0x07,0x07,0x00,0x00,
0xE0,0xF0,0xD8,0xCC,0xCC,0x8C,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0x0C,0x0C,0x8C,0xEC,0x3C,0x1C,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00,0x00,
0xB8,0xFC,0xCC,0xCC,0xFC,0xB8,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0x78,0xFC,0xCC,0xCC,0xFC,0xF0,0x00,0x00,0x00,0x0C,0x0C,0x06,0x07,0x01,0x00,0x00,
0x20,0x70,0x20,0x00,0x00,0x00,0x00,0x00,0x04,0x0E,0x04,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x70,0x20,0x00,0x00,0x00,0x00,0x40,0x6E,0x3E,0x1E,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF8,0x9C,0x0C,0x0E,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x07,0x00,0x00,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x00,0x00,
0x0E,0x0C,0x9C,0xF8,0xF0,0xF0,0x00,0x00,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x00,
0x08,0x8C,0x8C,0xCC,0x7C,0x38,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,0x00,0x00,
0xE0,0x18,0xCC,0xEC,0x6C,0xFC,0xF8,0x00,0x07,0x18,0x37,0x2F,0x2C,0x2F,0x2F,0x00,
0x00,0x80,0xF0,0x3C,0x3C,0xF8,0xC0,0x00,0x0C,0x0F,0x07,0x03,0x03,0x07,0x0F,0x0C,
0xFC,0xFC,0xCC,0xCC,0xFC,0xB8,0x00,0x00,0x0F,0x0F,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0xF0,0xF8,0x1C,0x0C,0x0C,0x0C,0x18,0x00,0x03,0x07,0x0E,0x0C,0x0C,0x0C,0x06,0x00,
0xFC,0xFC,0x0C,0x0C,0x1C,0xF8,0xF0,0x00,0x0F,0x0F,0x0C,0x0C,0x0E,0x07,0x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0x0F,0x03,0x07,0x0E,0x08,0x00,0x00,
0x78,0x7C,0xEC,0xCC,0xCC,0x98,0x00,0x00,0x06,0x0C,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0x0C,0x0C,0x0C,0xFC,0xFC,0x0C,0x0C,0x0C,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,
0xFC,0xFC,0x00,0x00,0xFC,0xFC,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0x3C,0xFC,0xC0,0x00,0xE0,0xFC,0x3C,0x00,0x00,0x01,0x0F,0x0C,0x0F,0x01,0x00,0x00,
0xFC,0xFC,0x80,0x80,0x80,0xFC,0xFC,0x00,0x07,0x0F,0x0F,0x01,0x0F,0x0F,0x07,0x00,
0x04,0x0C,0xB8,0xF0,0xF0,0xBC,0x0C,0x04,0x08,0x0E,0x07,0x01,0x01,0x07,0x0E,0x08,
0x04,0x1C,0x78,0xC0,0xC0,0x78,0x1C,0x04,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,
0x0C,0x0C,0xCC,0x7C,0x1C,0x0C,0x00,0x00,0x0C,0x0F,0x0D,0x0C,0x0C,0x0C,0x00,0x00,
0xFE,0xFE,0x06,0x06,0x00,0x00,0x00,0x00,0x7F,0x7F,0x60,0x60,0x00,0x00,0x00,0x00,
0x06,0x3E,0xF8,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1F,0x7C,0x60,0x00,0x00,
0x06,0x06,0xFE,0xFE,0x00,0x00,0x00,0x00,0x60,0x60,0x7F,0x7F,0x00,0x00,0x00,0x00,
0x00,0x70,0x38,0x1C,0x1C,0x38,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
0x04,0x06,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xB0,0xB0,0xB0,0xB0,0xF0,0xE0,0x00,0x07,0x0F,0x0D,0x0D,0x0D,0x0F,0x0F,0x00,
0xFE,0xFE,0x30,0x30,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x0C,0x0C,0x07,0x03,0x00,0x00,
0xC0,0xE0,0x70,0x30,0x30,0x30,0x00,0x00,0x03,0x07,0x0E,0x0C,0x0C,0x0C,0x00,0x00,
0xC0,0xF0,0x30,0x30,0x30,0xFE,0xFE,0x00,0x03,0x07,0x0E,0x0C,0x0C,0x0F,0x0F,0x00,
0xC0,0xE0,0xB0,0xB0,0xB0,0xF0,0xC0,0x00,0x03,0x07,0x0D,0x0D,0x0D,0x0D,0x0D,0x00,
0x30,0x30,0xFC,0xFE,0x36,0x36,0x36,0x06,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,
0xC0,0xE0,0x70,0x30,0x30,0xF0,0xF0,0x00,0x03,0x6F,0x6C,0x6C,0x6C,0x7F,0x3F,0x00,
0xFE,0xFE,0x30,0x30,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,0x00,
0x30,0x36,0xF6,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x0C,0x00,
0x00,0x30,0x30,0x30,0xF6,0xF6,0x00,0x00,0x00,0x70,0x60,0x60,0x7F,0x3F,0x00,0x00,
0xFE,0xFE,0x80,0xE0,0x70,0x30,0x10,0x00,0x0F,0x0F,0x01,0x03,0x07,0x0C,0x08,0x00,
0x06,0x06,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x00,0x00,
0xF0,0xF0,0x30,0xF0,0x30,0xF0,0xE0,0x00,0x0F,0x0F,0x00,0x01,0x00,0x0F,0x0F,0x00,
0xF0,0xF0,0x30,0x30,0x30,0xF0,0xE0,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,
0xC0,0xE0,0x30,0x30,0x30,0xE0,0xC0,0x00,0x03,0x07,0x0C,0x0C,0x0C,0x07,0x03,0x00,
0xF0,0xF0,0x30,0x30,0xF0,0xC0,0x00,0x00,0x7F,0x7F,0x0C,0x0C,0x0F,0x07,0x00,0x00,
0xC0,0xE0,0x30,0x30,0xF0,0xF0,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x7F,0x7F,0x00,0x00,
0xF0,0xF0,0x30,0x30,0x30,0x30,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0xE0,0xF0,0xB0,0xB0,0x30,0x30,0x00,0x00,0x06,0x0C,0x0D,0x0D,0x0F,0x07,0x00,0x00,
0x30,0x30,0xFC,0xFC,0x30,0x30,0x30,0x00,0x00,0x00,0x07,0x0F,0x0C,0x0C,0x0C,0x00,
0xF0,0xF0,0x00,0x00,0x00,0xF0,0xF0,0x00,0x07,0x0F,0x0C,0x0C,0x0C,0x0F,0x0F,0x00,
0x30,0xF0,0xC0,0x00,0xC0,0xF0,0x30,0x00,0x00,0x01,0x07,0x0E,0x07,0x01,0x00,0x00,
0xF0,0xF0,0x00,0xC0,0xC0,0x00,0xF0,0xF0,0x01,0x0F,0x0F,0x01,0x01,0x0F,0x0F,0x01,
0x10,0x30,0x70,0xE0,0xC0,0xF0,0x30,0x10,0x08,0x0C,0x0E,0x03,0x03,0x07,0x0E,0x08,
0x00,0x30,0xF0,0xC0,0x00,0xC0,0xF0,0x30,0x60,0x60,0x61,0x77,0x3E,0x0F,0x01,0x00,
0x30,0x30,0xB0,0xF0,0x70,0x30,0x00,0x00,0x0C,0x0E,0x0F,0x0C,0x0C,0x0C,0x00,0x00,
0x80,0x80,0xFC,0x7E,0x06,0x06,0x00,0x00,0x01,0x01,0x3F,0x7E,0x60,0x60,0x00,0x00,
0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x06,0x7E,0xFC,0x80,0x80,0x00,0x00,0x60,0x60,0x7E,0x3F,0x01,0x01,0x00,0x00,
0x80,0xC0,0xC0,0xC0,0x80,0xC0,0xC0,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00
};

 

On the display it looks like this:

 

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube