Open arinurcahyo opened 6 years ago
I am painfully aware of the lack of support for variable width fonts.
I've created a milestone to work towards, shouldn't be too hard, some clever users on the freetronics forums have apparently already figured this out, with their permission I may test and merge their contributions.
I found a little solution for my issue using charWidth function. I had to change this code:
if (col == -5) { // -5 used as a buffer when char is hiding after most left column of the display col = 1; // -5 is used since we use fixed font 5x7 charIndexChanged = true; charIndex += 1; }
into this :
if (col == -(thisCharIndexWidth)) { col = 1; charIndexChanged = true; charIndex += 1; Serial.print("Char Index = "); Serial.println(charIndex); thisCharIndexWidth = dmd.charWidth(teks[charIndex]); }
Now it can scroll any variable width fonts.
However I don't know yet whether the performance is good or not. At least it fulfill my needs, using 2x2 panel, it can pixel scroll a (very) long text and can scroll 2 text at same time and I didn't see noticeable slowdown.
Look forward to your work.
I make a sketch that run a long text pixel by pixel using only 2 panel defined in softDMD dmd.
` / Sketch for displaying running text per column for long text. however i could only make it run use fixed width font only (ex: SystemFont5x7.h) /
include
include
include <fonts/SystemFont5x7.h>
include <fonts/Arial_Black_16.h>
SoftDMD dmd(2, 1, 9, 8, 7, 4, 5, 3); //2 panels width, 1 panel height, 8,7,4,5,3 are my defined pins DMD_TextBox box(dmd, 0, 0, 64, 16); DMD_TextBox box2(dmd, 0, 8, 64, 16); char teks[] = "Lazy Brown Fox Is Jumping Completely Over A Bunch of Straws Without Getting Down "; // text to display int colLength; long currentMillis; long previousTextMillis; int textScrollingInterval = 200; int col = 64; int charIndex = 0; boolean charIndexChanged = true; int sizeOfTeks; // the setup routine runs once when you press reset: void setup() { Serial.begin(9600); dmd.setBrightness(100); dmd.selectFont(SystemFont5x7); dmd.begin();
Serial.println("begin"); Serial.print("teks = <"); Serial.print(teks); Serial.println(">"); Serial.print("jumlah char = "); Serial.println(sizeof(teks) - 1);
// trimming function // code below is used to trim excessed space at the end of the text, must find 2 or more space to be identified as excessive space. // just comment the code to unuse it.
char * p = strstr (teks, " ");
// end of trimming function
sizeOfTeks = (p - teks + 1) - 1;
Serial.print("text = <"); Serial.print(teks); Serial.println(">"); Serial.print("jumlah char = "); Serial.println(sizeof(teks) - 1);
colLength = ((sizeof(teks) - 1) * 5) + (sizeof(teks) - 2); Serial.print("total kolom = "); Serial.print(colLength); }
// the loop routine runs over and over again forever:
void loop() { currentMillis = millis();
if (charIndexChanged) { charIndexChanged = false; box2.clear(); box2.print(F("Index = ")); box2.print(charIndex); }
if (currentMillis - previousTextMillis >= textScrollingInterval) { // using several things at the same time technique dmd.drawString(col , 0, &teks[charIndex]); // begin draw text from first index running from most right column of the display if (col == -5) { // -5 used as a buffer when char is hiding after most left column of the display col = 1; // -5 is used since we use fixed font 5x7 charIndexChanged = true; charIndex += 1; } if (charIndex == sizeOfTeks) { // after all text is hiding to left column of the display col = 65; // index will reset so text will display again from most right column charIndex = 0; box.clear(); box2.clear(); } col--; previousTextMillis += textScrollingInterval; } } `
However it can only run for a font that have a fixed width such as systemfont5x7. I am unable to retrieve a font data width from font file that have a dynamic width due to my lack of programming skill. Any ideas?