Wish AdafruitGFX - setfont

Discussion in 'B4R Bugs & Wishlist' started by derez, Nov 5, 2019.

  1. derez

    derez Expert Licensed User

    The library has a setfont method which enables use of other than default fonts with inclusion of a font file.
    Can it be exposed to the rAdafruitGFX library or an inline C code supplied ?

    An example of the use in Arduino code:
    Code:
    #include "Adafruit_GFX.h"    // Core graphics library
    #include "MCUFRIEND_kbv.h"   // Hardware-specific library
    MCUFRIEND_kbv tft;
     
    #include "Ard_Logo.h"
     
    #define BLACK   0x0000
    #define RED     0xF800
    #define GREEN   0x07E0
    #define WHITE   0xFFFF
    #define GREY    0x8410
     
    #include "Fonts/FreeSans9pt7b.h"
    #include "Fonts/FreeSans12pt7b.h"
    #include "Fonts/FreeSerif12pt7b.h"
    #include "FreeDefaultFonts.h"
     
     
    void showmsgXY(int x, int y, int sz, 
    const GFXfont *f, const char *msg)
    {
      int16_t x1, y1;
      uint16_t wid, ht;
      tft.setFont(f);
      tft.setCursor(x, y);
      tft.setTextSize(sz);
      tft.println(msg);
    }
     
    uint8_t r = 255, g = 255, b = 255;
    uint16_t color;
     
    void setup()
    {
      Serial.begin(9600);
      uint16_t ID = tft.readID();
      tft.begin(ID);
      tft.invertDisplay(true);
      tft.setRotation(1);
    }
     
    void loop(void)
    {
      tft.invertDisplay(true);
      tft.fillScreen(WHITE);
     
      tft.drawRGBBitmap(100, 50, Logo, 350, 200);
    delay(1000);
      tft.setTextSize(2);
      for (int j = 0; j < 20; j++) {
        color = tft.color565(r -= 12, g -= 12, b -= 12);
        tft.setTextColor(color);
        showmsgXY(95, 280, 1, &FreeSans12pt7b, "ELECTROPEAK PRESENTS");
        delay(20);
      }
    delay(1000);
      for (int i = 0; i < 480; i++) {
        tft.vertScroll(0, 480, i);
        tft.drawFastVLine(i, 0, 320, 0xffff); // vertical line
        delay(5);}
      
        while (1);
      }
     
    Last edited: Nov 5, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Johan Hormaza likes this.
  3. derez

    derez Expert Licensed User

    It works. I'll soon write a tutorial how to make/change your own font, I made one for some Hebrew letters.
     
    Erel and inakigarm like this.
  4. derez

    derez Expert Licensed User

    I got Hebrew letters in a font file that I created. I have to use the original characters in the code, for example if I put the font for א in a, I have to draw "a" to get the "א".
    I want to locate the Hebrew letters higher in the ascii numbers where unused symbols are, write in the code the actual letters in Hebrew and use a sub to subtract the difference in the ascii code to point to the correct location.
    I have two problems:
    1. all the Hebrew characters' asc() method return -41
    2. what is the transverse function to asc() - to define the character by its ascii number (like chr() ) ?

    The workaround is of course to write a "dictionary" sub like a map: if st = "א" then draw("a")
     
    Last edited: Nov 7, 2019 at 7:03 AM
  5. Erel

    Erel Administrator Staff Member Licensed User

    A String in B4R is just a set of bytes so Chr is not needed:
    Code:
    Dim s As String = Array As Byte(404550)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice