dmd font 4x7

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
sniper100
Posts: 1
Joined: Fri Jan 05, 2018 4:40 pm

dmd font 4x7

Post by sniper100 » Fri Jan 05, 2018 4:46 pm

I tried to create a font for P10 matrix with GLCD fontcreator2. The result doesn't work.
Please help.
Attachments
fonts4x7.h
(5.19 KiB) Downloaded 165 times

User avatar
stryker
Posts: 270
Joined: Sat Jan 14, 2012 2:44 pm

Re: dmd font 4x7

Post by stryker » Sat Jan 06, 2018 6:17 am

I had a quick look at the other fixed width font that's included with the DMD library, the System5x7 and, like yours the size is defined as 0,0

Code: Select all

    0x0, 0x0, // size
but it has the interesting comment after the same data as follows

Code: Select all

    0x0, 0x0, // size of zero indicates fixed width font, actual length is width * height
and rather than including the width table for every character as yours does, it skips that and just has this comment

Code: Select all

    // Fixed width; char width table not used !!!!
which leads me to think yours won't work until you remove this block

Code: Select all

    // char widths
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
as that will be read as the first character data.

Hope that is the cause. Cheers ! Geoff

ankit_gupta
Posts: 7
Joined: Mon Mar 19, 2018 5:41 am

Re: dmd font 4x7

Post by ankit_gupta » Thu Apr 26, 2018 8:48 am

hey stryker, i wanted my 5x7 font to be of variable width so i entered a character width table and entered a non-zero value in size parameter, this allowed me to change the width of other characters but i am not able to do the same with space character, please can u help me with this i need to solve this urgently..!!!
i have atached my modified system5x7 library for variable width
Attachments
SystemFont5x7.h
(6.08 KiB) Downloaded 57 times

Brissieboy
Posts: 135
Joined: Fri Sep 20, 2013 7:25 am

Re: dmd font 4x7

Post by Brissieboy » Thu Apr 26, 2018 9:18 am

ankit_gupta,
The space character is treated as a special case because it is not always defined in some fonts - no idea why.
It is explicitly given the same width as an 'n' character.
If you are using the DMD library the space width is set in charWidth() in the file DMD.cpp.
Just comment out the line:

Code: Select all

    if (c == ' ') c = 'n';
NOTE that this will only work properly if the space character is properly defined in your variable width font - the same as any other character. This may not always be the case when using available fonts, but it is easy to fix.

If you are using the DMD2 library the charWidth() method in the DMD2_Text.cpp file. I cannot help you with this one as I have not delved deeply into it. However, I have had a play with the DMD2 library when it was first released and had a lot of issues with it - it had a lot of bugs. For that reason I have stayed with the original DMD library which I have heavily modified for my own needs.

ankit_gupta
Posts: 7
Joined: Mon Mar 19, 2018 5:41 am

Re: dmd font 4x7

Post by ankit_gupta » Thu Apr 26, 2018 9:50 am

thanks alot Brissieboy it worked, you saved my day..!!

Brissieboy
Posts: 135
Joined: Fri Sep 20, 2013 7:25 am

Re: dmd font 4x7

Post by Brissieboy » Thu Apr 26, 2018 10:33 am

This is safer solution which also allows for the case where the space is not defined in the font (giving it an 'n' width). Replace the entire charWidth() method in the DMD library with this or just make the relevant changes:

Code: Select all

//--------------------------------------------------------------------------------
// Returns the width (in the currently selected font) of the passed character
// Modified to also allow for a defined width for the space character if it
//   is defined within the font 
//--------------------------------------------------------------------------------
byte DMD::charWidth(const char letter)
{
  uint8_t width = 0;

  uint8_t firstChar = pgm_read_byte(this->Font + FONT_FIRST_CHAR);
  uint8_t charCount = pgm_read_byte(this->Font + FONT_CHAR_COUNT);

  uint16_t index = 0;

  char c = letter;
  // Space is often not included in font so use width of 'n' if this is the case
  if (c == ' ') {

    if (pgm_read_byte(this->Font + FONT_LENGTH) != 0
      || pgm_read_byte(this->Font + FONT_LENGTH + 1) != 0) {
      // non-zero length is variable width font so check to see is space width specified

      if (pgm_read_byte(this->Font + FONT_WIDTH_TABLE + (c - firstChar)) == 0) { // is 0 if space width not specified
        c = 'n';
      }
    }

    else c = 'n'; // make space the same size as 'n'
  }

  if (c < firstChar || c >= (firstChar + charCount)) {
    return 0;
  }
  c -= firstChar;

  if (pgm_read_byte(this->Font + FONT_LENGTH) == 0
    && pgm_read_byte(this->Font + FONT_LENGTH + 1) == 0) {
    // zero length is flag indicating fixed width font (array does not contain width data entries)
    width = pgm_read_byte(this->Font + FONT_FIXED_WIDTH);
  } 
  else {
    // variable width font, read width data
    width = pgm_read_byte(this->Font + FONT_WIDTH_TABLE + c);
  }
  return width;
}
That is for the original DMD library, but you could make similar changes in the DMD2 library as well.

Brissieboy
Posts: 135
Joined: Fri Sep 20, 2013 7:25 am

Re: dmd font 4x7

Post by Brissieboy » Tue May 08, 2018 4:55 am

I have made the appropriate changes to fix this issue for the DMD2 library. You can find the details here.

Post Reply