Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Classes | Macros | Functions
nbgl_draw_text.c File Reference

Implementation of middle-level API to draw text. More...

#include <string.h>
#include "nbgl_front.h"
#include "nbgl_draw.h"
#include "nbgl_fonts.h"
#include "nbgl_debug.h"
#include "nbgl_side.h"
#include "os_pic.h"
#include "os_utils.h"
Include dependency graph for nbgl_draw_text.c:

Go to the source code of this file.

Classes

struct  rle_context_t
 

Macros

#define MAX_FONT_HEIGHT   54
 
#define AVERAGE_CHAR_WIDTH   40
 
#define STATIC   static
 
#define COMBINED_HEIGHT   9
 
#define MAX_RLE_COPY_PIXELS   5
 
#define RLE_CMD_COPY_2   0x00
 
#define RLE_CMD_COPY_3   0x01
 
#define RLE_CMD_COPY_4   0x02
 
#define RLE_CMD_COPY_5   0x03
 
#define RLE_CMD_FILL_3   0x04
 
#define RLE_CMD_FILL_2   0x05
 
#define RLE_CMD_2PATTERN_INDEXED_B2W   0x06
 
#define RLE_CMD_2PATTERN_INDEXED_W2B   0x07
 
#define RLE_CMD_1PATTERN_B2W   0x08
 
#define RLE_CMD_1PATTERN_W2B   0x09
 
#define RLE_CMD_2PATTERN_B2W   0x0A
 
#define RLE_CMD_2PATTERN_W2B   0x0B
 
#define RLE_CMD_FILL_BLACK   0x0C
 
#define RLE_CMD_FILL_1   0x0D
 
#define RLE_CMD_FILL_WHITE   0x0E
 
#define RLE_CMD_FILL_WHITE_16   0x0F
 

Functions

STATIC void nbgl_draw4BPPImageRle (nbgl_area_t *area, const uint8_t *buffer, uint32_t buffer_len, const uint8_t *patterns, nbgl_area_t *buf_area, uint8_t *dst, uint8_t nb_skipped_bytes)
 Uncompress a 4BPP RLE-encoded glyph and draw it in a RAM buffer (we handle transparency, meaning when resulting pixel is 0xF we don't store it)
 
STATIC void update_char_info (character_info_t *char_info, const uint8_t **text, uint16_t *textLen, nbgl_unicode_ctx_t *unicode_ctx, const nbgl_font_t *font)
 
nbgl_font_id_e nbgl_drawText (const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
 This function draws the given single-line text, with the given parameters.
 

Detailed Description

Implementation of middle-level API to draw text.

Definition in file nbgl_draw_text.c.

Macro Definition Documentation

◆ AVERAGE_CHAR_WIDTH

#define AVERAGE_CHAR_WIDTH   40

Definition at line 28 of file nbgl_draw_text.c.

◆ COMBINED_HEIGHT

#define COMBINED_HEIGHT   9

Definition at line 41 of file nbgl_draw_text.c.

◆ MAX_FONT_HEIGHT

#define MAX_FONT_HEIGHT   54

Definition at line 27 of file nbgl_draw_text.c.

◆ MAX_RLE_COPY_PIXELS

#define MAX_RLE_COPY_PIXELS   5

Definition at line 44 of file nbgl_draw_text.c.

◆ RLE_CMD_1PATTERN_B2W

#define RLE_CMD_1PATTERN_B2W   0x08

Definition at line 55 of file nbgl_draw_text.c.

◆ RLE_CMD_1PATTERN_W2B

#define RLE_CMD_1PATTERN_W2B   0x09

Definition at line 56 of file nbgl_draw_text.c.

◆ RLE_CMD_2PATTERN_B2W

#define RLE_CMD_2PATTERN_B2W   0x0A

Definition at line 57 of file nbgl_draw_text.c.

◆ RLE_CMD_2PATTERN_INDEXED_B2W

#define RLE_CMD_2PATTERN_INDEXED_B2W   0x06

Definition at line 53 of file nbgl_draw_text.c.

◆ RLE_CMD_2PATTERN_INDEXED_W2B

#define RLE_CMD_2PATTERN_INDEXED_W2B   0x07

Definition at line 54 of file nbgl_draw_text.c.

◆ RLE_CMD_2PATTERN_W2B

#define RLE_CMD_2PATTERN_W2B   0x0B

Definition at line 58 of file nbgl_draw_text.c.

◆ RLE_CMD_COPY_2

#define RLE_CMD_COPY_2   0x00

Definition at line 47 of file nbgl_draw_text.c.

◆ RLE_CMD_COPY_3

#define RLE_CMD_COPY_3   0x01

Definition at line 48 of file nbgl_draw_text.c.

◆ RLE_CMD_COPY_4

#define RLE_CMD_COPY_4   0x02

Definition at line 49 of file nbgl_draw_text.c.

◆ RLE_CMD_COPY_5

#define RLE_CMD_COPY_5   0x03

Definition at line 50 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_1

#define RLE_CMD_FILL_1   0x0D

Definition at line 60 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_2

#define RLE_CMD_FILL_2   0x05

Definition at line 52 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_3

#define RLE_CMD_FILL_3   0x04

Definition at line 51 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_BLACK

#define RLE_CMD_FILL_BLACK   0x0C

Definition at line 59 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_WHITE

#define RLE_CMD_FILL_WHITE   0x0E

Definition at line 61 of file nbgl_draw_text.c.

◆ RLE_CMD_FILL_WHITE_16

#define RLE_CMD_FILL_WHITE_16   0x0F

Definition at line 62 of file nbgl_draw_text.c.

◆ STATIC

#define STATIC   static

Definition at line 35 of file nbgl_draw_text.c.

Function Documentation

◆ nbgl_draw4BPPImageRle()

STATIC void nbgl_draw4BPPImageRle ( nbgl_area_t area,
const uint8_t *  buffer,
uint32_t  buffer_len,
const uint8_t *  patterns,
nbgl_area_t buf_area,
uint8_t *  dst,
uint8_t  nb_skipped_bytes 
)

Uncompress a 4BPP RLE-encoded glyph and draw it in a RAM buffer (we handle transparency, meaning when resulting pixel is 0xF we don't store it)

4BPP RLE Decoder - The provided bytes contains:

  CMD + DATA:

  1000 + VVVV => Simple Pattern Black to White: 0x0, VVVV, 0xF
  1001 + VVVV => Simple Pattern White to Black: 0xF, VVVV, 0x0
  1010 + VVVV + WWWW => Double Pattern Black to White: 0x0, VVVV, WWWW, 0xF
  1011 + VVVV + WWWW => Double Pattern White to Black: 0xF, VVVV, WWWW, 0x0
  111R + RRRR => FILL White (max=32)
  1100 + RRRR => FILL Black (max=16)
  1101 + VVVV => Fill Value x 1

  00RR + VVVV + WWWW + XXXX + YYYY + ZZZZ => COPY Quartets
 - RR is repeat count - 2 of quartets (max=2+3 => 5 quartets)
  - VVVV: value of 1st 4BPP pixel
  - WWWW: value of 2nd 4BPP pixel
  - XXXX: value of 3rd 4BPP pixel
  - YYYY: value of 4th 4BPP pixel
  - ZZZZ: value of 5th 4BPP pixel

  0100 + VVVV + RRRR => FILL Value x Repeat+3 (max=18)
  0101 + VVVV => FILL Value x 2
  0110 + IIII => Double Pattern Indexed Black to White: 0x0, Val1, val2, 0xF
  0111 + IIII => Double Pattern Indexed White to Black: 0xF, Val2, Val1, 0x0
Parameters
areaarea information about where to display the text
bufferbuffer of RLE-encoded data
buffer_lenlength of buffer
buf_areaof the RAM buffer
dstRAM buffer on which the glyph will be drawn
nb_skipped_bytesnumber of bytes that was cropped

Definition at line 443 of file nbgl_draw_text.c.

◆ nbgl_drawText()

nbgl_font_id_e nbgl_drawText ( const nbgl_area_t area,
const char *  text,
uint16_t  textLen,
nbgl_font_id_e  fontId,
color_t  fontColor 
)

This function draws the given single-line text, with the given parameters.

Parameters
areaposition, size and background color to use for text
textarray of characters (UTF-8)
textLennumber of chars to draw
fontIdfont to be used
fontColorcolor to use for font

Definition at line 1072 of file nbgl_draw_text.c.

◆ update_char_info()

STATIC void update_char_info ( character_info_t char_info,
const uint8_t **  text,
uint16_t *  textLen,
nbgl_unicode_ctx_t unicode_ctx,
const nbgl_font_t font 
)

Definition at line 943 of file nbgl_draw_text.c.