Skip to content

Text and Fonts

xgraph edited this page Nov 23, 2016 · 6 revisions

The print stream is used to put text on the display. So you can use tft.print() and tft.println().

Below you'll find a whole list of functions to select fonts, define line & character spacing and control the cursor position. External fonts are included as C source files. There are several fonts included with the library and users can convert computer fonts with a conversation tool. The RA8875 driver (used in the 5.0" and 9.0" XG8800) also has a build-in 'internal' font and a font RAM to store up to 256 characters. The advantages of those build-in fonts is that they render quicker and don't require CPU memory space.

Select a font

Select the RA8875 internal font

void setFont(void)

Select an external font

void setFont(const tFont *font)

  • font: is a pointer to the font structure. You must include an external font C source file which includes this font structure. Several example fonts are included with the library.

Set the distance between text lines

void setFontInterline(uint8_t pix)

  • pix: number of pixels between text lines (0 ... 63)

Set font spacing

void setFontSpacing(uint8_t spc)

  • spc: the number of pixels in between characters (0 ... 63)

Set the font scale

void setFontScale(uint8_t scale)

void setFontScale(uint8_t xscale,uint8_t yscale)

  • scale: sets the scale for fonts.
  • xscale: sets the horizontal scale for fonts.
  • yscale: sets the vertical scale for fonts.

For internal fonts the scale is limited to (0 (1x) ... 3 (4x)

Get the width & height of the current font

uint8_t getFontWidth(boolean inColums)

uint8_t getFontHeight(boolean inRows)

Returns the current fonts width or height in pixels (parameter is FALSE) or columns/rows (parameter is TRUE). If the font is scaled it will use the scaled values.

Sets the cursor position

void setCursor(int16_t x, int16_t y,bool autocenter)

  • x: horizontal pixel position or CENTER (which will center the cursor in the horizontal direction)
  • y: vertical pixel position or CENTER (which will center the cursor in the vertical direction)
  • autocenter: FALSE: |ABCD
  • autocenter: TRUE: AB|CD

Gets the cursor position

void getCursorFast(int16_t &x, int16_t &y)

int16_t getCursorX(void)

int16_t getCursorY(void)

  • x: returns the horizontal position of the cursor in pixels
  • y: returns the vertical position of the cursor in pixels

Show cursor (RA8875 only)

void showCursor(enum RA8875tcursor c, bool blink)

  • c: cursor type: NOCURSOR, IBEAM, UNDER, BLOCK
  • blink: TRUE = blinking cursor

The cursor is only visible when the RA8875 internal font is used.

Change the cursor blink rate (RA8875 only)

void setCursorBlinkRate(uint8_t rate)

  • rate: changes the blink rate (fast 0 ... 255 slow)

Set cursor increment (for RA8875 internal font only)

void XGLCD::cursorIncrement(bool on)

  • bool: TRUE/FALSE: enable/disable auto-incrementation of the cursor

Enable/Disable the font full alignment (for RA8875 internal font only)

void setFontFullAlign(boolean align)

  • align: TRUE or FALSE

Select the internal font encoding (RA8875 only)

void setIntFontCoding(enum RA8875fontCoding f)

  • f: ISO_IEC_8859_1, ISO_IEC_8859_2, ISO_IEC_8859_3, ISO_IEC_8859_4

Refer to the RA8875 datasheet to understand the different font encodings. The default encoding is ISO_IEC_8859_1.

Upload a user character or symbol to the font RAM (RA8875 only)

void uploadUserChar(const uint8_t symbol[],uint8_t address)

  • symbol: a 16 byte array which contains the character graphical data
  • address: address to store the symbol in the font RAM (0 ... 255)

Print a user character or symbol to the screen (RA8875 only)

void showUserChar(uint8_t symbolAddrs,uint8_t wide)

  • symbolAddrs: address of the symbol in the font RAM (0 ... 255)
  • wide: number of consequent symbols to be shown. Several font RAM symbols can be combined to make one larger symbol (0 ... 255)