Go Down

Topic: U8g2 Fonts Diplay a . as a little + (Read 332 times) previous topic - next topic

koosjr

I am using my ST7920 Display to show a couple of line of data, and I am limited a font of 7 pixels high.

I tried a few fonts, even larger ones, and with all of them a . is displayed as a little +. I simply cannot understand why the conventional little square made up by 4 pixels were used.

This makes floating point numbers look a bit funny and a : looks plain ugly.

Are there any fonts where these characters are displayed as one see on all displays?

olikraus

I am confused. You say, that the dot (.) is displayed as a little plus (+). I just checked the 6x12 font:


I would say, it is not like this. Can you send a screenshot with the corresponding code?

Oliver

koosjr

Hi Oliver.

I am a little red faced here since you responded on the same day and I missed it. I think my email alerts are not working.

Her is an image from Google. Have a look after number 9. This is that it looks like.



david_prentice

#3
Jun 14, 2018, 12:23 pm Last Edit: Jun 14, 2018, 12:27 pm by david_prentice
You have limited choices when creating bitmaps for a small font.  e.g. a period
Code: [Select]

 O    OO
OOO   OO    OO
 O          OO

Most people choose the four-pixel version.    Likewise for a colon.
Yes, the font in Oliver's GraphicsTest example uses 5 pixels.    I got out the magnifying glass.
I am viewing it on a 0.96" OLED.   I have not been offended.

It does not look attractive on your big ST7920 display.

Personally,   I find the regular 7x5 System font which is the default in Adafruit_GFX libraries to be a good compromise.   It is acceptable x2.   It looks blocky at any other magnifications.

Oliver provides a massive choice of fonts with u8g2.
Of course you are unlikely to select large fonts on a tiny display.

David.

olikraus

#4
Jun 14, 2018, 05:46 pm Last Edit: Jun 14, 2018, 07:42 pm by olikraus
I think David has descibed the problem very well.

For me as author of U8g2, I just add existing bitmap font. Of course I do review the fonts before adding them to U8g2, but I never change the font. The shape of each glyph had been a decision of the font author and I respect this decision. However in U8g2 there are many other fonts, so I am sure you will find a suitable font for yourself.

The font list (https://github.com/olikraus/u8g2/wiki/fntlistall) might be a good starting point. Click on the font to see the details.

Oliver

david_prentice

I wrote a little program to show some fonts.    It runs on a Uno.   Change constructor for your display.

Code: [Select]

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup()
{
    // put your setup code here, to run once:
    u8g2.begin();
    u8g2.setFontRefHeightExtendedText();
    u8g2.setDrawColor(1);
    u8g2.setFontPosTop();
    u8g2.setFontDirection(0);

}

#define B(x) { x, #x }

typedef struct {
    const uint8_t *font;
    const char name[30];
} font_t;

const font_t PROGMEM fonts[] = {
    B(u8g2_font_6x10_mr),
    B(u8g2_font_6x12_mr),
    B(u8g2_font_mozart_nbp_tr),
    B(u8g2_font_roentgen_nbp_tr),
    B(u8g2_font_timR08_tr),
    B(u8g2_font_artossans8_8r),

    B(u8g2_font_artosserif8_8r),
    B(u8g2_font_torussansbold8_8r),
    B(u8g2_font_victoriabold8_8r),
    B(u8g2_font_victoriamedium8_8r),
    B(u8g2_font_lucasfont_alternate_tr),
    B(u8g2_font_haxrcorp4089_tr),

    B(u8g2_font_pxplusibmcgathin_8r),
    B(u8g2_font_pxplusibmcga_8r),
    B(u8g2_font_pxplustandynewtv_8r),
    B(u8g2_font_amstrad_cpc_extended_8r),
    B(u8g2_font_t0_11_tr),
    B(u8g2_font_t0_11b_tr),

    B(u8g2_font_t0_11b_tr),
    B(u8g2_font_t0_12_tr),
    B(u8g2_font_t0_12b_tr),

};

void loop()
{
    font_t *f;
    char buf[32];   //to copy PROGMEM strings
    int sz = sizeof(fonts) / sizeof(fonts[0]);
    for (int idx = 0; idx < sz; idx += 6) {
        u8g2.clearBuffer();
        for (int i = 0; i < 6; i++) {
            if (idx + i >= sz) break;
            f = fonts + idx + i;
            u8g2.setFont(pgm_read_ptr(&f->font));
#if 1
            u8g2.drawStr( 0, i * 10, strcpy_P(buf, f->name + 10));
#else
            u8g2.setCursor( 0, i * 10);
            u8g2.print(idx + i);
            u8g2.print(" :;.,");
#endif
        }
        u8g2.sendBuffer();
        delay(5000);
    }
}

It gives you an idea of what the fonts look like.   Repeat the loop with index number and ":.;" to see what you like.

Incidentally,  most of the fonts that I selected use a 4-pixel period.

David.

olikraus

#6
Jun 14, 2018, 07:45 pm Last Edit: Jun 14, 2018, 07:46 pm by olikraus
Cool  :smiley-cool: Nice use of the stingizing operator: Karma+

Oliver

koosjr


Go Up