MajicDesigns / MD_Parola

Library for modular scrolling LED matrix text displays
GNU Lesser General Public License v2.1
438 stars 135 forks source link

MD_Parola.h #13

Closed mr-miky closed 7 years ago

mr-miky commented 7 years ago

in MD_Parola.h

  // Font character handling data and methods
  charDef_t *_userChars;  // the root of the list of user defined characters
  uint8_t   _cBuf[15];    // buffer for loading character font
  uint8_t   _charSpacing; // spacing in columns between characters
  uint8_t   _charCols;    // number of columns for this character
  int16_t   _countCols;   // count of number of columns already shown
  MD_MAX72XX::fontType_t  *_fontDef;  // font for this zone

cBuf [15] seems a bit risky. Would not it be better to ask the font which is its maximum width ???

In my case I use 22 pixels wide fonts ... and strange things happened before identifying this array of uint8_t .....

uint8_t MD_MAX72XX::getMaxFontWidth(void)
{
    uint8_t max = 0, charWidth;
    uint16_t    offset = 1;

    if (_fontIndex == NULL)
        return 0;

    PRINTS("\nFinding max font width");
    for (int16_t i=0; i<FONT_INDEX_SIZE; i++)
    {
        charWidth = pgm_read_byte(_fontData+offset);

        PRINT("\nASCII '", i);
        PRINT("' offset ", offset);
        PRINT("' max width ", max);

        if (charWidth > max)
            charWidth = max;
        offset += charWidth;
        offset++;
    }
    return max;
}
MajicDesigns commented 7 years ago

Removed hard coded limit in the buffer. Repo updated.