Need some help with the _FONT_ data structure

128x128 pixel 1.5" full colour OLED display with MicroSD card slot. [Product page]
Post Reply
krt
Posts: 15
Joined: Tue Jan 07, 2014 7:45 am
Location: Lake Macquarie, NSW

Need some help with the _FONT_ data structure

Post by krt » Tue Jan 14, 2014 9:46 pm

G'day,

Could I get some help with the font file data structure format please ~

I'm trying to make a cut-down version of "Droid-Sans-36", where it has only the glyphs needed to display temperature values (0 to 9 +-. CKF), thereby reducing the required memory.

I've re-arranged the font OK, but I'm unsure as to what those first four octets in the structure represent.

The first is font_Size_in_Bytes_over_all_included_Size_it_self a uint16_t. Originally this is 0xc9bb. But I just don't understand what to give it. I'd guess it's the count of everything in the font array - but is it?

The next two, width & height - font_Width_in_Pixel_for_fixed_drawing and font_Height_in_Pixel_for_all_characters. How do these work? This glyph byte-size is not fixed, since there's more bytes for some glyphs than others (e.g.: '!' vs '%').

thanks,
-krt

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need some help with the _FONT_ data structure

Post by angusgr » Wed Jan 15, 2014 3:39 am

Hi krt,

By far the easiest thing you can do is use GLCD Font Creator to edit the fonts. I think it can do what you need (stripping out unwanted characters.)

I'm not sure where you got the names for the fields from, but I'll refer back to the field names used in FTOLED (this is the header at the very start of the font data.)

Code: Select all

struct FontHeader {
  uint16_t size;
  uint8_t fixedWidth;
  uint8_t height;
  uint8_t firstChar;
  uint8_t charCount;
};
- size - in FTOLED is only actually used to determine if the font is fixed width or not. 0 means fixed width (unsure why, ask whoever originally designed this format!) Leaving 0xc9bb should be fine.

- fixedWidth - is ignored in non-fixed-width fonts, so safe to leave it as zero.

- height - is the height (in pixels) of each glyph. Same for all glyphs.

- firstChar is the ASCII code for the first glyph represented in the font.

- charCount is the total number of glyphs in the font.

In a non-fixed-width font, the widths of each glyph are encoded immediately after the header. Each byte after the header corresponds to the width of the coreesponding glyph (starting at 'firstChar' and proceeding for 'charCount' characters. Then after the width entries come 'charCount' glyph bitmaps, where the size of each bitmap is determined by that glyph's width in pixels (width in pixels * number of bytes per column.)

If the are "gaps" in the ASCII range of glyphs you want to include, then you should be able to encode their width as 0 in the width header and then insert no bitmap for those glyphs.

Hope that is of some help,


Angus

krt
Posts: 15
Joined: Tue Jan 07, 2014 7:45 am
Location: Lake Macquarie, NSW

Re: Need some help with the _FONT_ data structure

Post by krt » Wed Jan 15, 2014 10:02 pm

How do you convert the output from the GLCD Font Creator to the OLED128 font structure format? I took a stab at it, but it looks like GLCD row-encodes the bits, rather than column encoding (which is what the oled128 seems to use)?

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need some help with the _FONT_ data structure

Post by angusgr » Thu Jan 16, 2014 2:09 am

Oops, sorry - I linked to a different tool with the same name.

Try this tool: http://code.google.com/p/glcd-arduino/d ... eator2.zip

I'll fix the link on the wiki as well.

krt
Posts: 15
Joined: Tue Jan 07, 2014 7:45 am
Location: Lake Macquarie, NSW

Re: Need some help with the _FONT_ data structure

Post by krt » Thu Jan 16, 2014 7:06 am

Ah, there's two "GLCD Font Creators" - the Arduino one with output for OLED128 is http://code.google.com/p/glcd-arduino/d ... eator2.zip

This creates files immediately useful for the OLED128.

EDIT: Ah, I see you've responded the same.

krt
Posts: 15
Joined: Tue Jan 07, 2014 7:45 am
Location: Lake Macquarie, NSW

Re: Need some help with the _FONT_ data structure

Post by krt » Thu Jan 16, 2014 7:57 am

So... with your help *it works!*

What this is, is a large-format font, but it supports only the symbols necessary for displaying numeric temperature values. So included are +,.,-,0 to 9,C,F,K and a degrees-symbol under "O" (capital Oh). Using this instead of the whole font saves you 5778 bytes. Not an earth-shatteringly-large amount, but that's nearly 20% of your Program Memory.
font_test.jpg
Photo of font test through a plastic lid (You would think being able to program and make circuits, that drilling holes in a lunch-box lid would be easy ... *sigh*)
This test code is largely based on the font demo:

Code: Select all

#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Droid_Sans_36_temperature.h>

// Test the large Temperature Display Font
// The font supports: +, ., -, 0 to 9, C, F, K and O paints as a degrees symbol

const byte pin_cs    = 7;
const byte pin_dc    = 5; // changed from the default of 2
const byte pin_reset = 6; // changed from the default of 3

OLED oled(pin_cs, pin_dc, pin_reset);

void setup() 
{
    oled.begin();
    oled.selectFont(Droid_Sans_36_Temperature);
    oled.drawString(6,80,F("+47.96OC"),RED,BLACK);
    oled.drawString(6,50,F("-23.81OF"),CORNFLOWERBLUE,BLACK);  
    oled.drawString(6,20,F("50OK"),YELLOWGREEN,BLACK);  

    String msg = "Sketch ran in\n";
    msg += millis();
    msg += " ms";
    oled.selectFont(SystemFont5x7);
    oled.drawString(6,8,msg,OLDLACE,BLACK);
}

void loop() 
{
     // Do nothing, we're finished!
}
And the font itself:

Code: Select all

/*
 * Droid Sans 36 - Temperature Display Character Only
 * Includes:  +, ., -, 0 to 9, C, F, K and O paints as a degrees symbol
 *
 * created with FontCreator written by F. Maximilian Thiele
 * http://www.apetech.de/fontCreator me@apetech.de
 * 
 */

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef Droid_Sans_36_Temperature_H
#define Droid_Sans_36_Temperature_H

#define DS36_WIDTH 10
#define DS36_HEIGHT 37

static uint8_t Droid_Sans_36_Temperature[] PROGMEM = 
{
    0x24, 0x28, // size of the font in bytes 0x2428 == 9256
    0x0A, // font width
    0x25, // font height
    43,   // first char (is '+')
    37,   // char count - but 20 of them are empty place holders (which waste a byte!)
    
    // char widths
    0x10, // +
    0x00, // no ","
    0x0A, // -
    0x04, // .
    0x00, // No "/"
    0x10, // 0
    0x09, // 1
    0x10, // 2
    0x11, // 3
    0x13, // 4
    0x10, // 5
    0x10, // 6
    0x10, // 7
    0x10, // 8
    0x10, // 9
    0,0,0,0,0,0,0,0,0,  // No : ; < = > ? @ A B
    0x13, // C
    0,0,                // No D E
    0x0D, // F
    0,0,0,0,            // No G H I J
    0x11, // K
    0,0,0,             // No L M N 
    0x0D, // "O" maps to the Degrees Symbol
    
    // font data
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x7F, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 33
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0x1F, 0x0E, 0x00, 0x00, 0x00, 0x00, // 34
    0x00, 0xC0, 0xF0, 0xF8, 0x78, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xE0, 0xC0, 0x00, 0xFE, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFE, 0x1F, 0xFF, 0xFF, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x01, 0x07, 0x07, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 35
    0x80, 0xC0, 0xE0, 0xF0, 0x78, 0x3C, 0xFC, 0xFC, 0xFC, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 36
    0x60, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF8, 0x7F, 0x3F, 0x0F, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0x78, 0x3C, 0x1E, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0F, 0x0F, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 37
    0x00, 0x70, 0x38, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF8, 0xBC, 0x9F, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xC7, 0xFF, 0xFF, 0x7C, 0x07, 0x07, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 38
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0x7C, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF8, 0x3C, 0x1F, 0x07, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3E, 0x3F, 0x3F, 0x39, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xFF, 0xFF, 0xFF, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 39
    0x00, 0x00, 0xFC, 0xFC, 0xFC, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x7F, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xFF, 0xFF, 0x7E, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 40
    0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x78, 0x38, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xC1, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x1F, 0xFF, 0xFF, 0xE3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 41
    0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0xFC, 0xFC, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0xFC, 0x7F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFE, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 42
    0x00, 0xC0, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x38, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x9F, 0xBC, 0xF8, 0xF0, 0xE0, 0xE0, 0xF0, 0xF8, 0xBC, 0x9F, 0x0F, 0x07, 0x00, 0xF8, 0xFE, 0xFF, 0x87, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x87, 0xFF, 0xFE, 0xF8, 0x00, 0x03, 0x07, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 43
    0x80, 0xE0, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF0, 0xE0, 0xC0, 0x00, 0x3F, 0xFF, 0xFF, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xF1, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x81, 0xE0, 0xFF, 0xFF, 0x3F, 0x07, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 44
    0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x78, 0x38, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x38, 0x30, 0x00, 0xF8, 0xFF, 0xFF, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0xFF, 0xFF, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 45
    0xFC, 0xFC, 0xFC, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 46
    0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF8, 0x7C, 0x1C, 0x0C, 0x04, 0xFF, 0xFF, 0xFF, 0x80, 0xE0, 0xF0, 0xF8, 0xFE, 0xDF, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0x01, 0x03, 0x0F, 0x3F, 0x7E, 0xF8, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0x0F, 0x0E, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 47
    0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x70, 0x70, 0x70, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x3F, 0x38, 0x70, 0x70, 0x70, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 48

    
};

#endif  //#ifndef Droid_Sans_36_Temperature_H

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need some help with the _FONT_ data structure

Post by angusgr » Fri Jan 17, 2014 2:08 am

Nice work, thanks for posting this!

krt
Posts: 15
Joined: Tue Jan 07, 2014 7:45 am
Location: Lake Macquarie, NSW

Re: Need some help with the _FONT_ data structure

Post by krt » Fri Jan 17, 2014 10:51 pm

Update: I added 2 pixels of space around the "1", as it seemed a little thin.
I'm a bit happier with this one.

One thing to note, if you're doing one of these yourself: It might be handy to include a space character too, so when the digits change, it's easy to just add a space character to the string to erase the little bits left over by the change in pixel-width of the new text. It does waste a quite few bytes though.

Code: Select all

/*
 * Droid Sans 36 - Temperature Display Character Only
 * Includes:  +, -, 0 to 9, C, F, K and O paints as a degrees symbol
 *
 * created with FontCreator written by F. Maximilian Thiele
 * http://www.apetech.de/fontCreator me@apetech.de
 * 
 */

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef Droid_Sans_36_Temperature_H
#define Droid_Sans_36_Temperature_H

#define DS36_WIDTH 10
#define DS36_HEIGHT 37

static uint8_t Droid_Sans_36_Temperature[] PROGMEM = 
{
    0x24, 0xA8, // size of the font in bytes 0x2428 == 9256
    0x0A, // font width
    0x25, // font height
    43,   // first char (is '+')
    37,   // char count - but 20 of them are empty place holders (which waste a byte!)
    
    // char widths
    0x10, // +
    0x00, // no ","
    0x0A, // -
    0x04, // .
    0x00, // No "/"
    0x10, // 0
    0x0D, // 1
    0x10, // 2
    0x11, // 3
    0x13, // 4
    0x10, // 5
    0x10, // 6
    0x10, // 7
    0x10, // 8
    0x10, // 9
    0,0,0,0,0,0,0,0,0,  // No : ; < = > ? @ A B
    0x13, // C
    0,0,                // No D E
    0x0D, // F
    0,0,0,0,            // No G H I J
    0x11, // K
    0,0,0,             // No L M N G
    0x0D, // "O" maps to the Degrees Symbol
    
    // font data
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x7F, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 33
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0x1F, 0x0E, 0x00, 0x00, 0x00, 0x00, // 34
    0x00, 0xC0, 0xF0, 0xF8, 0x78, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xE0, 0xC0, 0x00, 0xFE, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFE, 0x1F, 0xFF, 0xFF, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x01, 0x07, 0x07, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 35
0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x78, 0x3C, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 36
    0x60, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF8, 0x7F, 0x3F, 0x0F, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0x78, 0x3C, 0x1E, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0F, 0x0F, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 37
    0x00, 0x70, 0x38, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF8, 0xBC, 0x9F, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xC7, 0xFF, 0xFF, 0x7C, 0x07, 0x07, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 38
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0x7C, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF8, 0x3C, 0x1F, 0x07, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3E, 0x3F, 0x3F, 0x39, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xFF, 0xFF, 0xFF, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 39
    0x00, 0x00, 0xFC, 0xFC, 0xFC, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x7F, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xFF, 0xFF, 0x7E, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 40
    0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x78, 0x38, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xC1, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x1F, 0xFF, 0xFF, 0xE3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 41
    0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0xFC, 0xFC, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0xFC, 0x7F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFE, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 42
    0x00, 0xC0, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x38, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x9F, 0xBC, 0xF8, 0xF0, 0xE0, 0xE0, 0xF0, 0xF8, 0xBC, 0x9F, 0x0F, 0x07, 0x00, 0xF8, 0xFE, 0xFF, 0x87, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x87, 0xFF, 0xFE, 0xF8, 0x00, 0x03, 0x07, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 43
    0x80, 0xE0, 0xF0, 0xF8, 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, 0x78, 0xF0, 0xE0, 0xC0, 0x00, 0x3F, 0xFF, 0xFF, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xF1, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x81, 0xE0, 0xFF, 0xFF, 0x3F, 0x07, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 44
    0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x78, 0x38, 0x3C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x38, 0x30, 0x00, 0xF8, 0xFF, 0xFF, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0xFF, 0xFF, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 45
    0xFC, 0xFC, 0xFC, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 46
    0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF8, 0x7C, 0x1C, 0x0C, 0x04, 0xFF, 0xFF, 0xFF, 0x80, 0xE0, 0xF0, 0xF8, 0xFE, 0xDF, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0x01, 0x03, 0x0F, 0x3F, 0x7E, 0xF8, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0x0F, 0x0E, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 47
    0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x70, 0x70, 0x70, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x3F, 0x38, 0x70, 0x70, 0x70, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 48

    
};

#endif  //#ifndef Droid_Sans_36_Temperature_H

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need some help with the _FONT_ data structure

Post by angusgr » Sun Jan 19, 2014 10:25 pm

krt wrote: One thing to note, if you're doing one of these yourself: It might be handy to include a space character too, so when the digits change, it's easy to just add a space character to the string to erase the little bits left over by the change in pixel-width of the new text. It does waste a quite few bytes though.
Good point. For what it's worth, FTOLED actually uses the width of the 'n' character to approximate the width of the space character. So you might find just having a space doesn't help, but having an 'n' character defined does.

EDIT: I just changed FTOLED should it should be smarter about fonts that don't contain 'n' but do contain a space character, so this should work fine now.

The other thing you could do is use the stringWidth function to detect when the width of text changes, and erase a small area at the end of the string with the drawFilledBox() function.

Thanks for all your input on FTOLED!

- Angus

Post Reply