Draw the character of the ASCII code.

Dependents:   mbed-os_Watson-IoT_ZXing_sample mbed-os_Watson-IoT_ZXing_sample MovPlayer GR-PEACH_HVC-P2_sample_client ... more

Fork of AsciiFont by Daiki Kato

Embed: (wiki syntax)

« Back to documentation index

AsciiFont Class Reference

Draw the character of the ASCII code. More...

#include <AsciiFont.h>

Public Member Functions

 AsciiFont (uint8_t *p_buf, int width, int height, int stride, int byte_per_pixel, uint32_t const colour=0)
 Constructor: Initializes AsciiFont.
void Erase ()
 Erase text field.
void Erase (uint32_t const colour)
 Erase text field.
void Erase (uint32_t const colour, int x, int y, int width, int height)
 Erase text field.
int DrawStr (const char *str, int x, int y, uint32_t const colour, int font_size=1, uint16_t const max_char_num=0xffff)
 Draw a string.
bool DrawChar (char c, int x, int y, uint32_t const colour, int font_size=1)
 Draw a character.

Static Public Attributes

static const int CHAR_PIX_WIDTH = 6
 The pixel width of a character.
static const int CHAR_PIX_HEIGHT = 8
 The pixel height of a character.

Detailed Description

Draw the character of the ASCII code.

Example

 #include "mbed.h"
 #include "AsciiFont.h"
 
 #define WIDTH           (12)
 #define HEIGHT          (16)
 #define BYTE_PER_PIXEL  (1u)
 #define STRIDE          (((WIDTH * BYTE_PER_PIXEL) + 7u) & ~7u) //multiple of 8
 
 uint8_t text_field[STRIDE * HEIGHT];
 
 //for debug
 void print_text_field() {
     int idx = 0;
 
     for (int i = 0; i < HEIGHT; i++) {
         for (int j = 0; j < STRIDE; j++) {
             printf("%02x", text_field[idx++]);
         }
         printf("\r\n");
     }
     printf("\r\n");
 }
 
 int main() {
     AsciiFont ascii_font(text_field, WIDTH, HEIGHT, STRIDE, BYTE_PER_PIXEL);
 
     ascii_font.Erase(0xcc);
     ascii_font.DrawStr("AB", 0, 0, 0x11, 1);
     ascii_font.DrawChar('C', AsciiFont::CHAR_PIX_WIDTH,
                         AsciiFont::CHAR_PIX_HEIGHT, 0x22, 1);
     print_text_field(); //debug print
 
     ascii_font.Erase();
     ascii_font.DrawStr("D", 0, 0, 0xef, 2);
     print_text_field(); //debug print
 
     ascii_font.Erase(0x11, 6, 0, 6, 8);
     print_text_field(); //debug print
 }

Definition at line 57 of file AsciiFont.h.


Constructor & Destructor Documentation

AsciiFont ( uint8_t *  p_buf,
int  width,
int  height,
int  stride,
int  byte_per_pixel,
uint32_t const   colour = 0 
)

Constructor: Initializes AsciiFont.

Parameters:
p_bufText field address
widthText field width
heightText field height
strideBuffer stride
colourBackground color
byte_per_pixelByte per pixel

Definition at line 5 of file AsciiFont.cpp.


Member Function Documentation

bool DrawChar ( char  c,
int  x,
int  y,
uint32_t const   colour,
int  font_size = 1 
)

Draw a character.

Parameters:
xDrawing start position of x coordinate
yDrawing start position of y coordinate
colorFont color
font_sizeFont size (>=1)
Returns:
true if successfull

Definition at line 57 of file AsciiFont.cpp.

int DrawStr ( const char *  str,
int  x,
int  y,
uint32_t const   colour,
int  font_size = 1,
uint16_t const   max_char_num = 0xffff 
)

Draw a string.

Parameters:
strString
xDrawing start position of x coordinate
yDrawing start position of y coordinate
colorFont color
font_sizeFont size (>=1)
max_char_numThe maximum number of characters
Returns:
The drawn number of characters

Definition at line 40 of file AsciiFont.cpp.

void Erase ( uint32_t const   colour )

Erase text field.

Parameters:
colourBackground color

Definition at line 14 of file AsciiFont.cpp.

void Erase ( uint32_t const   colour,
int  x,
int  y,
int  width,
int  height 
)

Erase text field.

Parameters:
colourBackground color
xErase start position of x coordinate
yErase start position of y coordinate
widthErase field width
heightErase field height

Definition at line 18 of file AsciiFont.cpp.

void Erase (  )

Erase text field.

Definition at line 10 of file AsciiFont.cpp.


Field Documentation

const int CHAR_PIX_HEIGHT = 8 [static]

The pixel height of a character.

(font_size=1)

Definition at line 122 of file AsciiFont.h.

const int CHAR_PIX_WIDTH = 6 [static]

The pixel width of a character.

(font_size=1)

Definition at line 117 of file AsciiFont.h.