ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Font.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for SDL3 and C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <SDL3_ttf/SDL_ttf.h>
27
28#include <Objectively/Enum.h>
29#include <Objectively/Array.h>
30#include <Objectively/Data.h>
31#include <Objectively/String.h>
32
35
36#define DEFAULT_FONT_FAMILY "Coda"
37#define DEFAULT_FONT_SIZE 16
38#define DEFAULT_FONT_STYLE FontStyleRegular
39
40#define DEFAULT_MONOSPACE_FONT_FAMILY "Share Tech Mono"
41
50typedef enum {
51 FontStyleRegular = TTF_STYLE_NORMAL,
52 FontStyleBold = TTF_STYLE_BOLD,
53 FontStyleItalic = TTF_STYLE_ITALIC,
54 FontStyleUnderline = TTF_STYLE_UNDERLINE,
55 FontStyleStrikeThrough = TTF_STYLE_STRIKETHROUGH
57
59
64typedef struct {
68 const char *family;
69
73 int size;
74
78 int style;
80
81typedef struct Font Font;
82typedef struct FontInterface FontInterface;
83
88struct Font {
89
93 Object object;
94
99 FontInterface *interface[0];
100
108
112 Data *data;
113
117 char *family;
118
122 TTF_Font *font;
123
129 char *iconPlaceholder;
130
135
140
144 int size;
145
149 int style;
150};
151
155struct FontInterface {
156
160 ObjectInterface objectInterface;
161
169 void (*cacheFont)(Data *data, const char *family);
170
177 void (*clearCache)(void);
178
187 Font *(*defaultFont)(void);
188
197 Font *(*defaultMonospaceFont)(void);
198
211 Font *(*fontWithName)(const char *name, float pixelDensity);
212
228 Font *(*fontWithAttributes)(const FontAttributes *attributes, float pixelDensity);
229
243 Font *(*initWithData)(Font *self, Data *data, const FontAttributes *attributes, float pixelDensity);
244
253 String *(*name)(const Font *self);
254
261 String *(*nameWithAttributes)(const FontAttributes *attributes);
262
276 void (*renderBitmapCharacters)(Font *self, const Renderer *renderer, const char *chars, SDL_Color color, int wrapWidth, const SDL_Point *origin, const ImageAtlas *icons);
277
288 SDL_Surface *(*renderCharacters)(const Font *self, const char *chars, SDL_Color color, int wrapWidth);
289
297 void (*renderDeviceWillReset)(Font *self);
298
310 void (*sizeBitmapCharacters)(const Font *self, const char *chars, int wrapWidth, const ImageAtlas *icons, int *w, int *h);
311
322 void (*sizeCharacters)(const Font *self, const char *chars, int *w, int *h);
323};
324
331OBJECTIVELYMVC_EXPORT Class *_Font(void);
Fixed-width Fonts baked into a glyph sheet, drawn as one quad per glyph.
static void cacheFont(Data *data, const char *family)
Definition Font.c:122
OBJECTIVELYMVC_EXPORT const EnumName FontStyleNames[]
Definition Font.h:58
FontStyle
Font styles.
Definition Font.h:50
@ FontStyleUnderline
Definition Font.h:54
@ FontStyleBold
Definition Font.h:52
@ FontStyleStrikeThrough
Definition Font.h:55
@ FontStyleRegular
Definition Font.h:51
@ FontStyleItalic
Definition Font.h:53
OBJECTIVELYMVC_EXPORT Class * _Font(void)
Definition Font.c:464
static ImageAtlas * icons(Theme *self)
Definition Theme.c:144
ObjectivelyMVC base types.
#define OBJECTIVELYMVC_EXPORT
Definition Types.h:40
The family, size and style attributes that identify a Font, independent of the pixel density at which...
Definition Font.h:64
const char * family
The family, or NULL for the default.
Definition Font.h:68
int style
The FontStyle, or -1 for the default.
Definition Font.h:78
int size
The point size, or 0 for the default.
Definition Font.h:73
A fixed-width Font's glyphs, baked into one sheet, drawn as one quad per glyph.
Definition Font+Bitmap.h:82
TrueType fonts.
Definition Font.h:88
float pixelDensity
The display pixel density scale, greater than 1.0 on high-density displays.
Definition Font.h:134
FontInterface * interface[0]
The interface type.
Definition Font.h:99
int renderSize
The render size, adjusted for pixel density.
Definition Font.h:139
char * family
The family name.
Definition Font.h:117
FontBitmap bitmap
The glyphs of a fixed-width Font, baked into one sheet; bitmap.surface is NULL for a proportional Fon...
Definition Font.h:107
int size
The point size.
Definition Font.h:144
TTF_Font * font
The backing font.
Definition Font.h:122
Data * data
The raw font data.
Definition Font.h:112
Object object
The superclass.
Definition Font.h:93
int style
The style.
Definition Font.h:149
Packs many Images into one sheet, backed by one Texture.
Definition ImageAtlas.h:49
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
Definition Renderer.h:75