naev 0.12.5
font.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "nstring.h"
7#include "opengl.h"
8
9#define FONT_COLOUR_CODE '#'
10
11#define FONT_FLAG_DONTREUSE \
12 ( 1 << 1 )
13
17typedef struct glFont_s {
18 int id;
19 int h;
20} glFont;
21extern glFont gl_defFont;
22extern glFont gl_smallFont;
24
28typedef struct glFontRestore_s {
29 const glColour *col;
31
44typedef struct glPrintLineIterator_s {
45 const char *text;
46 const glFont *ft_font;
47 int width;
48 int l_width;
49 size_t l_begin, l_end;
51 size_t l_next;
53 uint8_t dead;
57
58/*
59 * glFont loading / freeing
60 *
61 * if font is NULL it uses the internal default font same with gl_print
62 */
63int gl_fontInit( glFont *font, const char *fname, const unsigned int h,
64 const char *prefix, unsigned int flags );
65int gl_fontAddFallback( glFont *font, const char *fname, const char *prefix );
66int gl_fontAddFallbackFont( glFont *font, const glFont *f );
67void gl_freeFont( glFont *font );
68void gl_fontExit( void );
69
70/*
71 * const char printing
72 */
73void gl_printRaw( const glFont *ft_font, const double x, const double y,
74 const glColour *c, const double outlineR, const char *text );
75void gl_printRawH( const glFont *ft_font, const mat4 *H, const glColour *c,
76 const double outlineR, const char *text );
77int gl_printMaxRaw( const glFont *ft_font, const int max, const double x,
78 const double y, const glColour *c, const double outlineR,
79 const char *text );
80int gl_printMidRaw( const glFont *ft_font, const int width, double x,
81 const double y, const glColour *c, const double outlineR,
82 const char *text );
83int gl_printTextRaw( const glFont *ft_font, const int width, const int height,
84 double bx, double by, int line_height, const glColour *c,
85 const double outlineR, const char *text );
86void gl_printMarkerRaw( const glFont *ft_font, const double x, const double y,
87 const glColour *c, const char *text );
88
89/*
90 * printf style printing.
91 */
92/* prints text normally */
93PRINTF_FORMAT( 5, 6 )
94void gl_print( const glFont *ft_font, double x, double y, const glColour *c,
95 const char *fmt, ... );
96/* prints text to a max length */
97PRINTF_FORMAT( 6, 7 )
98int gl_printMax( const glFont *ft_font, const int max, double x, double y,
99 const glColour *c, const char *fmt, ... );
100/* prints text centered in width at x */
101PRINTF_FORMAT( 6, 7 )
102int gl_printMid( const glFont *ft_font, const int width, double x, double y,
103 const glColour *c, const char *fmt, ... );
104/* respects \n -> bx,by is TOP LEFT POSITION */
105PRINTF_FORMAT( 8, 9 )
106int gl_printText( const glFont *ft_font, int width, int height, double bx,
107 double by, int line_height, const glColour *c,
108 const char *fmt, ... );
109
110/* Dimension stuff. */
111void gl_printLineIteratorInit( glPrintLineIterator *iter, const glFont *ft_font,
112 const char *text, int width );
114int gl_printWidthRaw( const glFont *ft_font, const char *text );
115PRINTF_FORMAT( 2, 3 )
116int gl_printWidth( const glFont *ft_font, const char *fmt, ... );
117int gl_printHeightRaw( const glFont *ft_font, int width, const char *text );
118PRINTF_FORMAT( 3, 4 )
119int gl_printHeight( const glFont *ft_font, int width, const char *fmt, ... );
120int gl_printEndRaw( int *x, int *y, const glFont *ft_font, int width,
121 const char *text );
122PRINTF_FORMAT( 5, 6 )
123int gl_printEnd( int *x, int *y, const glFont *ft_font, int width,
124 const char *fmt, ... );
125int gl_printLinesRaw( const glFont *ft_font, int width, const char *text );
126PRINTF_FORMAT( 3, 4 )
127int gl_printLines( const glFont *ft_font, int width, const char *fmt, ... );
128
129/* Restore hacks. */
130void gl_printRestoreClear( void );
131void gl_printRestoreInit( glFontRestore *restore );
132void gl_printRestoreLast( void );
133void gl_printRestore( const glFontRestore *restore );
134void gl_printStoreMax( glFontRestore *restore, const char *text, int max );
135void gl_printStore( glFontRestore *restore, const char *text );
136
137/* Misc stuff. */
138void gl_fontSetFilter( const glFont *ft_font, GLint min, GLint mag );
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
Definition font.c:1050
int gl_printLines(const glFont *ft_font, const int width, const char *fmt,...)
Gets the number of lines of the text if it were printed.
Definition font.c:1232
void gl_printRestoreClear(void)
Clears the restoration.
Definition font.c:398
void gl_printRestoreInit(glFontRestore *restore)
Initializes a restore structure.
Definition font.c:416
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
Definition font.c:550
glFont gl_smallFont
Definition font.c:159
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
Definition font.c:646
int gl_printHeight(const glFont *ft_font, const int width, const char *fmt,...)
Gets the height of the text if it were printed.
Definition font.c:1082
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
Definition font.c:984
glFont gl_defFont
Definition font.c:158
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
Definition font.c:821
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
Definition font.c:725
int gl_fontAddFallback(glFont *font, const char *fname, const char *prefix)
Adds a fallback font to a font.
Definition font.c:1776
int gl_printTextRaw(const glFont *ft_font, const int width, const int height, double bx, double by, int line_height, const glColour *c, double outlineR, const char *text)
Prints a block of text that fits in the dimensions given.
Definition font.c:895
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
Definition font.c:1881
void gl_printRawH(const glFont *ft_font, const mat4 *H, const glColour *c, const double outlineR, const char *text)
Prints text on screen using a transformation matrix.
Definition font.c:680
int gl_printText(const glFont *ft_font, const int width, const int height, double bx, double by, int line_height, const glColour *c, const char *fmt,...)
Prints a block of text that fits in the dimensions given.
Definition font.c:956
void gl_printRestore(const glFontRestore *restore)
Restores last colour from a restore structure.
Definition font.c:425
int gl_printMax(const glFont *ft_font, const int max, double x, double y, const glColour *c, const char *fmt,...)
Behaves like gl_print but stops displaying text after reaching a certain length.
Definition font.c:792
int gl_printLinesRaw(const glFont *ft_font, const int width, const char *text)
Gets the number of lines of a non-formatted string.
Definition font.c:1203
void gl_printLineIteratorInit(glPrintLineIterator *iter, const glFont *ft_font, const char *text, int width)
Initialize an iterator object for breaking text into lines.
Definition font.c:528
int gl_printMaxRaw(const glFont *ft_font, const int max, double x, double y, const glColour *c, double outlineR, const char *text)
Behaves like gl_printRaw but stops displaying text after a certain distance.
Definition font.c:753
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1670
void gl_fontExit(void)
Frees all resources associated with the font system. This also resets font ID tracking,...
Definition font.c:1930
glFont gl_defFontMono
Definition font.c:160
void gl_printStoreMax(glFontRestore *restore, const char *text, int max)
Stores the colour information from a piece of text limited to max characters.
Definition font.c:440
void gl_printStore(glFontRestore *restore, const char *text)
Stores the colour information from a piece of text.
Definition font.c:463
int gl_printMid(const glFont *ft_font, const int width, double x, double y, const glColour *c, const char *fmt,...)
Displays text centered in position and width.
Definition font.c:863
void gl_printRestoreLast(void)
Restores last colour.
Definition font.c:406
void gl_fontSetFilter(const glFont *ft_font, GLint min, GLint mag)
Sets the minification and magnification filters for a font.
Definition font.c:1645
void gl_printMarkerRaw(const glFont *ft_font, double x, double y, const glColour *c, const char *text)
Wrapper for gl_printRaw for map overlay markers.
Definition font.c:708
int gl_printWidth(const glFont *ft_font, const char *fmt,...)
Gets the width that it would take to print some text.
Definition font.c:1026
int gl_printEndRaw(int *xo, int *yo, const glFont *ft_font, int width, const char *text)
Gets the position at which text would end writing.
Definition font.c:1107
static const double c[]
Definition rng.c:256
Evil hack to allow restoring, yes it makes me cry myself to sleep.
Definition font.h:28
const glColour * col
Definition font.h:29
Represents a font in memory.
Definition font.h:17
int h
Definition font.h:19
int id
Definition font.h:18
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Definition font.h:44
const char * text
Definition font.h:45
uint8_t no_soft_breaks
Definition font.h:54
const glFont * ft_font
Definition font.h:46
size_t l_next
Definition font.h:51
uint8_t dead
Definition font.h:53
Definition mat4.h:12