libtonc
Tonc Text Engine

A generalized raster text system. More...

Modules

 Operations
 Basic operations.
 
 Attributes
 Basic getters and setters.
 
 Console IO
 Stdio functionality.
 
 Tilemap text
 Text for regular and affine tilemaps.
 
 Character text, column-major
 Text on surface composed of 4bpp tiles, mapped in column-major order.
 
 Character text, row-major
 Text on surface composed of 4bpp tiles, mapped in row-major order.
 
 Bitmap text
 Text for 16bpp and 8bpp bitmap surfaces: modes 3, 4 and 5.
 
 Object text
 Text using objects.
 

Data Structures

struct  TFont
 Font description struct. More...
 
struct  TTC
 TTE context struct. More...
 

Macros

#define TTE_TAB_WIDTH   24
 

Default initializers

typedef void(* fnDrawg) (uint gid)
 Glyph render function format.
 
typedef void(* fnErase) (int left, int top, int right, int bottom)
 Erase rectangle function format.
 
typedef struct TFont TFont
 Font description struct.
 
typedef struct TTC TTC
 TTE context struct.
 
TTCgp_tte_context
 Glyph render function format.
 
#define tte_init_se_default(bgnr, bgcnt)    tte_init_se( bgnr, bgcnt, 0xF000, CLR_YELLOW, 0, &fwf_default, NULL)
 Glyph render function format.
 
#define tte_init_ase_default(bgnr, bgcnt)    tte_init_ase(bgnr, bgcnt, 0x0000, CLR_YELLOW, 0, &fwf_default, NULL)
 Glyph render function format.
 
#define tte_init_chr4c_default(bgnr, bgcnt)
 Glyph render function format.
 
#define tte_init_chr4r_default(bgnr, bgcnt)
 Glyph render function format.
 
#define tte_init_chr4c_b4_default(bgnr, bgcnt)
 Glyph render function format.
 
#define tte_init_bmp_default(mode)    tte_init_bmp(mode, &vwf_default, NULL)
 Glyph render function format.
 
#define tte_init_obj_default(pObj)    tte_init_obj(pObj, 0, 0, 0xF000, CLR_YELLOW, 0, &fwf_default, NULL)
 Glyph render function format.
 

Internal fonts

const TFont sys8Font
 System font ' '-127. FWF 8x 8@1.
 
const TFont verdana9Font
 Verdana 9 ' '-'ÿ'. VWF 8x12@1.
 
const TFont verdana9bFont
 Verdana 9 bold ' '-'ÿ'. VWF 8x12@1.
 
const TFont verdana9iFont
 Verdana 9 italic ' '-'ÿ'. VWF 8x12@1.
 
const TFont verdana10Font
 Verdana 10 ' '-'ÿ'. VWF 16x14@1.
 
const TFont verdana9_b4Font
 Verdana 9 ' '-'ÿ'. VWF 8x12@4.
 
const unsigned int sys8Glyphs [192]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned int verdana9Glyphs [896]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned char verdana9Widths [224]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned int verdana9bGlyphs [896]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned char verdana9bWidths [224]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned int verdana9iGlyphs [896]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned char verdana9iWidths [224]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned int verdana10Glyphs [1792]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned char verdana10Widths [224]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned int verdana9_b4Glyphs [3584]
 System font ' '-127. FWF 8x 8@1.
 
const unsigned char verdana9_b4Widths [224]
 System font ' '-127. FWF 8x 8@1.
 

Color lut indices

#define TTE_INK   0
 
#define TTE_SHADOW   1
 
#define TTE_PAPER   2
 
#define TTE_SPECIAL   3
 

drawg helper macros

#define TTE_BASE_VARS(_tc, _font)
 Declare and define base drawg variables.
 
#define TTE_CHAR_VARS(font, gid, src_t, _sD, _sL, _chW, _chH)
 Declare and define basic source drawg variables.
 
#define TTE_DST_VARS(tc, dst_t, _dD, _dL, _dP, _x, _y)
 Declare and define basic destination drawg variables.
 

Default fonts

#define fwf_default   sys8Font
 Default fixed-width font.
 
#define vwf_default   verdana9Font
 Default vairable-width font.
 

Default glyph renderers

#define ase_drawg_default   ((fnDrawg)ase_drawg_s)
 
#define bmp8_drawg_default   ((fnDrawg)bmp8_drawg_b1cts)
 
#define bmp16_drawg_default   ((fnDrawg)bmp16_drawg_b1cts)
 
#define chr4c_drawg_default   ((fnDrawg)chr4c_drawg_b1cts)
 
#define chr4r_drawg_default   ((fnDrawg)chr4r_drawg_b1cts)
 
#define obj_drawg_default   ((fnDrawg)obj_drawg)
 
#define se_drawg_default   ((fnDrawg)se_drawg_s)
 

Detailed Description

A generalized raster text system.

As of v1.3, Tonc has a completely new way of handling text. It can handle (practically) all modes, VRAM types and font sizes and brings them together under a unified interface. It uses function pointers to store drawg and erase functions of each rendering family. The families currently supported are:

Each of these consists of an initializer, tte_init_foo, and one or more glyph rendering functions, foo_puts_bar, The bar part of the renderer denotes the style of the particular renderer, which can indicate:

- Expected bitdepth of font data (\c b1 for 1bpp, etc)
- Expected sizes of the character (\c w8 and h8, for example).
- Application of system colors (\c c ).
- Transparent or opaque background pixels (\c t or \c o ).
- Whether the font-data is in 'strip' layout (\c s )

The included renderers here are usually transparent, recolored, using 1bpp strip glyphs (_b1cts ). The initializer takes a bunch of options specific to each family, as well as font and renderer pointers. You can provide your own font and renderers, provided they're formatted correcty. For the default font/renderers, use NULL.

After the calling the initializer, you can write utf-8 encoded text with tte_write() or tte_write_ex(). You can also enable stdio-related functions by calling tte_init_con().

The system also supposed rudimentary scripting for positions, colors, margins and erases. See tte_cmd_default() and con_cmd_parse() for details.

See also
Surface functions

Macro Definition Documentation

◆ TTE_BASE_VARS

#define TTE_BASE_VARS (   _tc,
  _font 
)
Value:
TTC *_tc= tte_get_context(); \
TFont *_font= tc->font; \
INLINE TTC * tte_get_context()
Get the master text-system.
Definition tonc_tte.h:610
Font description struct.
Definition tonc_tte.h:285
TTE context struct.
Definition tonc_tte.h:303

Declare and define base drawg variables.

Each drawg renderer usually starts with the same thing:

  • Get the system and font pointers.
  • Translate from ascii-character to glyph offset.
  • Get the glyph (and glyph-cell) dimensions.
  • Get the source and destination pointers and positions. These macros will make declarint and defining that easier.

◆ TTE_CHAR_VARS

#define TTE_CHAR_VARS (   font,
  gid,
  src_t,
  _sD,
  _sL,
  _chW,
  _chH 
)
Value:
src_t *_sD= (src_t*)(font->data+gid*font->cellSize), *_sL= _sD; \
uint _chW= font->widths ? font->widths[gid] : font->charW; \
uint _chH= font->charH;

Declare and define basic source drawg variables.

◆ TTE_DST_VARS

#define TTE_DST_VARS (   tc,
  dst_t,
  _dD,
  _dL,
  _dP,
  _x,
  _y 
)
Value:
uint _x= tc->cursorX, _y= tc->cursorY, _dP= tc->dst.pitch; \
dst_t *_dD= (dst_t*)(tc->dst.data+_y*_dP), *_dL;

Declare and define basic destination drawg variables.

◆ tte_init_chr4c_b4_default

#define tte_init_chr4c_b4_default (   bgnr,
  bgcnt 
)
Value:
tte_init_chr4c(bgnr, bgcnt, 0xF000, 0x0201, CLR_ORANGE<<16|CLR_YELLOW, \
void chr4c_drawg_b4cts(uint gid)
Initialize text system for 4bpp tiled, column-major surfaces.
Definition chr4c_drawg_b4cts.c:18
void tte_init_chr4c(int bgnr, u16 bgcnt, u16 se0, u32 cattrs, u32 clrs, const TFont *font, fnDrawg proc)
Initialize text system for 4bpp tiled, column-major surfaces.
Definition tte_init_chr4c.c:39
const TFont verdana9_b4Font
Verdana 9 ' '-'ÿ'. VWF 8x12@4.
#define CLR_ORANGE
Rotate nclrs colors at clrs to the right by ror.
Definition tonc_video.h:118

Glyph render function format.

◆ tte_init_chr4c_default

#define tte_init_chr4c_default (   bgnr,
  bgcnt 
)
Value:
tte_init_chr4c(bgnr, bgcnt, 0xF000, 0x0201, CLR_ORANGE<<16|CLR_YELLOW, \
&vwf_default, NULL)
#define vwf_default
Default vairable-width font.
Definition tonc_tte.h:204

Glyph render function format.

◆ tte_init_chr4r_default

#define tte_init_chr4r_default (   bgnr,
  bgcnt 
)
Value:
tte_init_chr4r(bgnr, bgcnt, 0xF000, 0x0201, CLR_ORANGE<<16|CLR_YELLOW, \
&vwf_default, NULL)
void tte_init_chr4r(int bgnr, u16 bgcnt, u16 se0, u32 cattrs, u32 clrs, const TFont *font, fnDrawg proc)
Initialize text system for 4bpp tiled, column-major surfaces.
Definition tte_init_chr4r.c:39

Glyph render function format.

Typedef Documentation

◆ TFont

typedef struct TFont TFont

Font description struct.

The TFont contains a description of the font, including pointers to the glyph data and width data (for VWF fonts), an ascii-offset for when the first glyph isn't for ascii-null (which is likely. Usually it starts at ' ' (32)).
The font-bitmap is a stack of cells, each containing one glyph each. The cells and characters need not be the same size, but the character glyph must fit within the cell.

The formatting of the glyphs themselves should fit the rendering procedure. The default renderers use 1bpp 8x8 tiled graphics, where for multi-tiled cells the tiles are in a vertical 'strip' format. In an 16x16 cell, the 4 tiles would be arranged as:

0 2
1 3