OldSchool Library
Text functions

Text functions in OSLib. More...

Data Structures

struct  OSL_FONT
 Loaded font structure. More...
 
struct  OSL_FONTINFO
 Font information type. More...
 
struct  OSL_FONT_FORMAT_HEADER
 Header of a .oft file (Oslib FonT). More...
 

Macros

#define oslSetFont(f)
 Sets the current font.
 
#define OSL_FONT_OFT   1
 Font type for OFT.
 
#define OSL_FONT_INTRA   2
 Font type for INTRA.
 
#define OSL_TEXT_CHARPOSXY(f, i)
 Returns the position of a character 'i' in the font 'f' texture as a pair (x, y).
 
#define oslDrawStringf(x, y, ...)
 Draws a formatted string literal at the specified position.
 

Functions

void oslInitConsole ()
 Initializes the console.
 
OSL_FONToslLoadFontFile (const char *filename)
 Loads a font from a file.
 
OSL_FONToslLoadFont (OSL_FONTINFO *fi)
 Loads a font from a OSL_FONTINFO file (located in RAM).
 
void oslDrawChar (int x, int y, unsigned char c)
 Draws a character at the specified position.
 
void oslDrawString (int x, int y, const char *str)
 Draws a string literal at the specified position.
 
void oslDrawStringLimited (int x, int y, int width, const char *str)
 Draws a string literal at the specified position, limited to a given width.
 
void oslConsolePrint (const char *str)
 Outputs a text to the console at the current cursor position.
 
void oslSetTextColor (OSL_COLOR color)
 Sets the current text color.
 
void oslSetBkColor (OSL_COLOR color)
 Sets the text background color.
 
void oslDrawTextBox (int x0, int y0, int x1, int y1, const char *text, int format)
 Draws a text box with automatic line wrapping.
 
void oslDrawTextBoxByWords (int x0, int y0, int x1, int y1, const char *text, int format)
 Draws a text box with automatic word wrapping.
 
void oslDeleteFont (OSL_FONT *f)
 Deletes a font.
 
int oslGetStringWidth (const char *str)
 Returns the width of a string in pixels.
 
int oslGetTextBoxHeight (int width, int maxHeight, const char *text, int format)
 Returns the height of a text box.
 
int oslIntraFontInit (unsigned int options)
 Initializes intraFont.
 
OSL_FONToslLoadIntraFontFile (const char *filename, unsigned int options)
 Loads a font from a pgf file (intraFont).
 
void oslLoadAltIntraFontFile (OSL_FONT *font, const char *filename)
 Loads an alternative intraFont file.
 
void oslIntraFontSetStyle (OSL_FONT *f, float size, unsigned int color, unsigned int shadowColor, float angle, unsigned int options)
 Sets the style for a pgf font.
 
float oslIntraFontPrintColumn (OSL_FONT *f, float x, float y, float width, const char *text)
 Draws text along the baseline starting at x, y.
 
void oslIntraFontShutdown ()
 Shuts down intraFont.
 

Variables

OSL_FONTosl_curFont
 
int osl_consolePosX
 
int osl_consolePosY
 
OSL_FONTosl_sceFont
 System OSLib font.
 
OSL_FONTINFO osl_sceFontInfo
 Font to be loaded.
 

Detailed Description

Text functions in OSLib.

This module provides various text-related functionalities, including font management, text drawing, and intraFont handling.

Macro Definition Documentation

◆ oslSetFont

#define oslSetFont ( f)
Value:
OSL_FONT * osl_curFont

Sets the current font.

Sets the current font to the specified font. Use this function instead of directly modifying osl_curFont for forward compatibility.

Parameters
fPointer to the new font to be set as the current font.
// Save the current font
OSL_FONT *oldFont = osl_curFont;
// Temporarily set another font
oslSetFont(newFont);
oslPrintf("Using the new font.\n");
// Restore the old font
oslSetFont(oldFont);
oslPrintf("Using the normal font.\n");
#define oslPrintf(format...)
Prints formatted text to the current position of the cursor.
Definition oslib.h:652
#define oslSetFont(f)
Sets the current font.
Definition text.h:101
Loaded font structure.
Definition text.h:30

◆ OSL_TEXT_CHARPOSXY

#define OSL_TEXT_CHARPOSXY ( f,
i )
Value:
(f)->charPositions[i]&(OSL_TEXT_TEXWIDTH-1), ((f)->charPositions[i]>>OSL_TEXT_TEXDECAL)*(f)->charHeight

Returns the position of a character 'i' in the font 'f' texture as a pair (x, y).

Parameters
fThe font structure.
iThe character index.

◆ oslDrawStringf

#define oslDrawStringf ( x,
y,
... )
Value:
{ char __str[1000]; sprintf(__str , __VA_ARGS__); oslDrawString(x, y, __str); }
void oslDrawString(int x, int y, const char *str)
Draws a string literal at the specified position.

Draws a formatted string literal at the specified position.

This function allows you to format a string and draw it at the specified coordinates (x, y).

Parameters
xX position on the screen.
yY position on the screen.
...The formatted string to draw.
oslDrawStringf(0, 0, "Test string %i", 1);
#define oslDrawStringf(x, y,...)
Draws a formatted string literal at the specified position.
Definition text.h:205

Function Documentation

◆ oslInitConsole()

void oslInitConsole ( )
extern

Initializes the console.

This function is automatically called by oslInitGfx, so manual initialization of the console is not required.

◆ oslLoadFontFile()

OSL_FONT * oslLoadFontFile ( const char * filename)
extern

Loads a font from a file.

Loads a font file (.oft format) from the specified file path.

Parameters
filenameThe path to the .oft font file.
Returns
A pointer to the loaded font.
OSL_FONT *f = oslLoadFontFile("verdana.oft");
oslDrawString(0, 0, "Hello world using verdana!");
OSL_FONT * oslLoadFontFile(const char *filename)
Loads a font from a file.

◆ oslLoadFont()

OSL_FONT * oslLoadFont ( OSL_FONTINFO * fi)
extern

Loads a font from a OSL_FONTINFO file (located in RAM).

Use this ONLY with OFT fonts (doesn't work with intraFont). It is recommended to use oslLoadFontFile, which is more user-friendly.

Parameters
fiA pointer to the OSL_FONTINFO structure in RAM.
Returns
A pointer to the loaded font.

◆ oslDrawChar()

void oslDrawChar ( int x,
int y,
unsigned char c )
extern

Draws a character at the specified position.

This function draws a single character at the given coordinates (x, y). For drawing multiple characters, use oslDrawString for better performance.

Parameters
xX position on the screen.
yY position on the screen.
cThe character to draw.

◆ oslDrawString()

void oslDrawString ( int x,
int y,
const char * str )
extern

Draws a string literal at the specified position.

This function draws a string at the given coordinates (x, y).

Parameters
xX position on the screen.
yY position on the screen.
strThe string to draw.
oslDrawString(0, 0, "Test string");

◆ oslDrawStringLimited()

void oslDrawStringLimited ( int x,
int y,
int width,
const char * str )
extern

Draws a string literal at the specified position, limited to a given width.

This function draws a string at the given coordinates (x, y) but limits the drawing to a specified width.

Parameters
xX position on the screen.
yY position on the screen.
widthThe maximum width for the string.
strThe string to draw.
oslDrawStringLimited(0, 0, 200, "Test string");
void oslDrawStringLimited(int x, int y, int width, const char *str)
Draws a string literal at the specified position, limited to a given width.

◆ oslConsolePrint()

void oslConsolePrint ( const char * str)
extern

Outputs a text to the console at the current cursor position.

This function prints a string to the console at the current cursor position and moves the cursor. It is intended for debugging purposes.

Parameters
strThe string to print.

◆ oslSetTextColor()

void oslSetTextColor ( OSL_COLOR color)
extern

Sets the current text color.

Sets the color of the text to be drawn. This function does not work with intraFont (use oslIntraFontSetStyle instead).

Parameters
colorThe color to set for the text.

◆ oslSetBkColor()

void oslSetBkColor ( OSL_COLOR color)
extern

Sets the text background color.

Sets the background color for the text. Setting a transparent color (e.g., RGBA(0, 0, 0, 0)) will disable the background, resulting in faster text rendering. This function does not work with intraFont (use oslIntraFontSetStyle instead).

Parameters
colorThe background color to set.

◆ oslDrawTextBox()

void oslDrawTextBox ( int x0,
int y0,
int x1,
int y1,
const char * text,
int format )
extern

Draws a text box with automatic line wrapping.

Draws text within a rectangle defined by (x0, y0) and (x1, y1). The text will automatically wrap at the end of a line and move to the next line.

Parameters
x0X position of the top-left corner.
y0Y position of the top-left corner.
x1X position of the bottom-right corner.
y1Y position of the bottom-right corner.
textThe text to be drawn. Can contain
characters for line breaks.
formatReserved, set to 0.

◆ oslDrawTextBoxByWords()

void oslDrawTextBoxByWords ( int x0,
int y0,
int x1,
int y1,
const char * text,
int format )
extern

Draws a text box with automatic word wrapping.

Similar to oslDrawTextBox, but wraps the text by words instead of characters.

Parameters
x0X position of the top-left corner.
y0Y position of the top-left corner.
x1X position of the bottom-right corner.
y1Y position of the bottom-right corner.
textThe text to be drawn. Can contain
characters for line breaks.
formatReserved, set to 0.

◆ oslDeleteFont()

void oslDeleteFont ( OSL_FONT * f)
extern

Deletes a font.

Deletes the specified font. Ensure that the font to be deleted is not currently selected (i.e., f != osl_curFont), or the program will crash the next time you attempt to draw a character.

Parameters
fThe font to be deleted.

◆ oslGetStringWidth()

int oslGetStringWidth ( const char * str)
extern

Returns the width of a string in pixels.

Calculates the width of a string using the currently selected font. To center text horizontally or align it at the bottom of the screen, use this function to get the width.

Parameters
strThe string whose width is to be calculated.
Returns
The width of the string in pixels.
const char *text = "© 2007 Brunni";
int width = oslGetStringWidth(text);
oslDrawString((SCREEN_WIDTH - width) / 2, SCREEN_HEIGHT - osl_curFont->charHeight, text);
int oslGetStringWidth(const char *str)
Returns the width of a string in pixels.
int charHeight
Height of characters (constant).
Definition text.h:36

◆ oslGetTextBoxHeight()

int oslGetTextBoxHeight ( int width,
int maxHeight,
const char * text,
int format )
extern

Returns the height of a text box.

Calculates the height (in pixels) required to draw a text box with the specified width, maxHeight, and format.

Parameters
widthThe width of the text box.
maxHeightThe maximum height of the text box.
textThe text to be drawn.
formatReserved, set to 0.
Returns
The height of the text box in pixels.

◆ oslIntraFontInit()

int oslIntraFontInit ( unsigned int options)
extern

Initializes intraFont.

Must be called before loading any pgf font. The same options will be applied to all intraFonts.

Parameters
optionsINTRAFONT_XXX flags as defined in the code above.
Returns
0 on success, non-zero on failure.

◆ oslLoadIntraFontFile()

OSL_FONT * oslLoadIntraFontFile ( const char * filename,
unsigned int options )
extern

Loads a font from a pgf file (intraFont).

Use this function to load a pgf font with options different from those passed to oslIntraFontInit.

Parameters
filenameThe path to the pgf font file.
optionsThe options for loading the font.
Returns
A pointer to the loaded font.
OSL_FONT *f = oslLoadIntraFontFile("verdana.pgf", INTRAFONT_CACHE_ALL | INTRAFONT_STRING_UTF8);
oslDrawString(0, 0, "Hello world using verdana!");
OSL_FONT * oslLoadIntraFontFile(const char *filename, unsigned int options)
Loads a font from a pgf file (intraFont).

◆ oslLoadAltIntraFontFile()

void oslLoadAltIntraFontFile ( OSL_FONT * font,
const char * filename )
extern

Loads an alternative intraFont file.

Use this function to load an alternative font file for an existing font.

Parameters
fontThe font structure to update.
filenameThe path to the alternative font file.

◆ oslIntraFontSetStyle()

void oslIntraFontSetStyle ( OSL_FONT * f,
float size,
unsigned int color,
unsigned int shadowColor,
float angle,
unsigned int options )
extern

Sets the style for a pgf font.

Applies the specified style to the pgf font. Works only with pgf fonts.

Parameters
fThe font structure.
sizeThe size of the font.
colorThe color of the text.
shadowColorThe color of the text shadow.
angleThe rotation angle of the text.
optionsAdditional style options.

◆ oslIntraFontPrintColumn()

float oslIntraFontPrintColumn ( OSL_FONT * f,
float x,
float y,
float width,
const char * text )
extern

Draws text along the baseline starting at x, y.

Draws text along the baseline starting at the specified (x, y) coordinates.

Parameters
fA valid OSL_FONT with type OSL_FONT_INTRA.
xX position on the screen.
yY position on the screen.
widthColumn width for automatic line breaking (intraFontPrintColumn versions only).
textThe text to draw (ASCII & extended ASCII, S-JIS, or UTF-8 encoded).
Returns
The x position after the last character.

◆ oslIntraFontShutdown()

void oslIntraFontShutdown ( )
extern

Shuts down intraFont.

Cleans up and shuts down intraFont, freeing any allocated resources.

Variable Documentation

◆ osl_curFont

OSL_FONT* osl_curFont
extern

Current font.

This pointer holds the currently selected font for text rendering. You can read from it, but use oslSetFont to modify it.

◆ osl_consolePosX

int osl_consolePosX
extern

Console horizontal position (in pixels). Use oslMoveTo to move the cursor.

◆ osl_consolePosY

int osl_consolePosY
extern

Console vertical position (in pixels).

◆ osl_sceFont

OSL_FONT* osl_sceFont
extern

System OSLib font.

A pointer to the system font used by OSLib.

◆ osl_sceFontInfo

OSL_FONTINFO osl_sceFontInfo
extern

Font to be loaded.

Holds information about the system font to be loaded.