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
33
34#define DEFAULT_FONT_FAMILY "Coda"
35#define DEFAULT_FONT_SIZE 16
36#define DEFAULT_FONT_STYLE FontStyleRegular
37
46typedef enum {
47 FontStyleRegular = TTF_STYLE_NORMAL,
48 FontStyleBold = TTF_STYLE_BOLD,
49 FontStyleItalic = TTF_STYLE_ITALIC,
50 FontStyleUnderline = TTF_STYLE_UNDERLINE,
51 FontStyleStrikeThrough = TTF_STYLE_STRIKETHROUGH
53
55
56typedef struct Font Font;
57typedef struct FontInterface FontInterface;
58
63struct Font {
64
68 Object object;
69
74 FontInterface *interface;
75
79 Data *data;
80
84 char *family;
85
89 TTF_Font *font;
90
95
100 float scale;
101
105 int size;
106
110 int style;
111};
112
116struct FontInterface {
117
121 ObjectInterface objectInterface;
122
133 Font *(*cachedFont)(const char *family, int size, int style);
134
142 void (*cacheFont)(Data *data, const char *family);
143
150 void (*clearCache)(void);
151
158 Font *(*defaultFont)(void);
159
171 Font *(*initWithData)(Font *self, Data *data, const char *family, int size, int style);
172
183 SDL_Surface *(*renderCharacters)(const Font *self, const char *chars, SDL_Color color, int wrapWidth);
184
192 void (*renderDeviceDidReset)(Font *self);
193
204 void (*sizeCharacters)(const Font *self, const char *chars, int *w, int *h);
205};
206
213OBJECTIVELYMVC_EXPORT Class *_Font(void);
static void cacheFont(Data *data, const char *family)
Definition Font.c:118
OBJECTIVELYMVC_EXPORT const EnumName FontStyleNames[]
Definition Font.h:54
FontStyle
Font styles.
Definition Font.h:46
@ FontStyleUnderline
Definition Font.h:50
@ FontStyleBold
Definition Font.h:48
@ FontStyleStrikeThrough
Definition Font.h:51
@ FontStyleRegular
Definition Font.h:47
@ FontStyleItalic
Definition Font.h:49
OBJECTIVELYMVC_EXPORT Class * _Font(void)
Definition Font.c:355
static SDL_Size size(const Image *self)
Definition Image.c:181
ObjectivelyMVC base types.
#define OBJECTIVELYMVC_EXPORT
Definition Types.h:40
TrueType fonts.
Definition Font.h:63
FontInterface * interface
The interface.
Definition Font.h:74
float scale
The display pixel density scale (e.g. 2.0 on Retina). Updated by callers via the scale field before i...
Definition Font.h:100
int renderSize
The render size, adjusted for display density.
Definition Font.h:94
char * family
The family name.
Definition Font.h:84
int size
The point size.
Definition Font.h:105
TTF_Font * font
The backing font.
Definition Font.h:89
Data * data
The raw font data.
Definition Font.h:79
Object object
The superclass.
Definition Font.h:68
int style
The style.
Definition Font.h:110