olikraus / U8g2_for_Adafruit_GFX

Add U8g2 fonts to any Adafruit GFX based graphics library.
Other
117 stars 35 forks source link

newline handling and Adafruit_GFX cursor update missing? #5

Closed ZinggJM closed 6 years ago

ZinggJM commented 6 years ago

Oliver, thank you for this welcome library!

I am still starting my tests, but it looks like: println() does not start a new line getCursorX() and getCursorY() of the referenced display class do not report the actual cursor. (not needed, as tx and ty are public).

thank you

Jean-Marc

olikraus commented 6 years ago

println() does not start a new line

Yes, because I do not know what should be done here. Maybe you should specify this more clearer in terms of what should happen to tx/ty.

Actually I did not implement any newline behaviour in u8g2 because it does not make so much sense on a graphical interface. So my question: What shell happen when there is a newline? How do you define "newline"?

getCursorX() and getCursorY() of the referenced display class do not report the actual cursor. (not needed, as tx and ty are public).

hmm.. thats sounds like a do it or leave it... The question is more, you want it or not? ;-)

ZinggJM commented 6 years ago

newline should set tx to zero and increase ty with height of glyph + some spacing. more exactly \r should set tx to zero, \n should set tx to zero and increase ty. I can't be more specific, would need to look what Adafruit_GFX does (in its own write() method, if not overridden).

On second thought, U8g2_for_Adafruit_GFX could provide getCursorX() and getCursorY() read accessors to tx and ty, would look familiar to Adafruit_GFX users.

Thank you.

ZinggJM commented 6 years ago

Thank you for the additions.

What about newline handling? This is what Adafruit_GFX does:

if ARDUINO >= 100

size_t Adafruit_GFX::write(uint8_t c) {

else

void Adafruit_GFX::write(uint8_t c) {

endif

if(!gfxFont) { // 'Classic' built-in font

    if(c == '\n') {                        // Newline?
        cursor_x  = 0;                     // Reset x to zero,
        cursor_y += textsize * 8;          // advance y one line
    } else if(c != '\r') {                 // Ignore carriage returns
        if(wrap && ((cursor_x + textsize * 6) > _width)) { // Off right?
            cursor_x  = 0;                 // Reset x to zero,
            cursor_y += textsize * 8;      // advance y one line
        }
        drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
        cursor_x += textsize * 6;          // Advance x one char
    }

} else { // Custom font

    if(c == '\n') {
        cursor_x  = 0;
        cursor_y += (int16_t)textsize *
                    (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
    } else if(c != '\r') {
        uint8_t first = pgm_read_byte(&gfxFont->first);
olikraus commented 6 years ago

yes, something like this. But I did not intend to support wrapping.

FrenchLab47 commented 6 years ago

Hello Oliver,

I am testing U8g2_for_Adafruit_GFX on an ESP32 with an RGB matrix, and it works pretty well. I am delighted to finally be able to display French accents on dynamic and scrollable texts. Congratulations for your work.

I have just a question: With the originals fonts of Adafruit GFX, I can display all basic colors. But if I select a U8g2 font, it can not be displayed in blue, or in colors that contain blue. I guess there must be a little oversight somewhere in the code. Do you have an idea ? Thank you very much.

I also asked the same thing on the Arduino forum :)

olikraus commented 6 years ago

I saw the forum post, but we can discuss here also. I had started with a 8 bit color value, but switched to 16 bit color value now. Maybe the stable release is not aware about the change.

Hm... it should be fixed in release 1.1.0: https://github.com/olikraus/U8g2_for_Adafruit_GFX/issues/1

Color is passed here as 16 bit value: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/src/U8g2_for_Adafruit_GFX.h#L133 it is passed to the c function: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/src/U8g2_for_Adafruit_GFX.cpp#L578 and stored in fg_color, which is also 16-bit: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/src/U8g2_for_Adafruit_GFX.h#L91 then fg_color is passed to the hv line procedure: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/src/U8g2_for_Adafruit_GFX.cpp#L319 AHHH and here is the mistake: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/src/U8g2_for_Adafruit_GFX.cpp#L229 color argument is a byte only....

this needs to be fixed.

olikraus commented 6 years ago

ok, fixed and released...