ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Font.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU 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 <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 ident font;
90
95
99 int size;
100
104 int style;
105};
106
110struct FontInterface {
111
115 ObjectInterface objectInterface;
116
127 Font *(*cachedFont)(const char *family, int size, int style);
128
136 void (*cacheFont)(Data *data, const char *family);
137
144 void (*clearCache)(void);
145
152 Font *(*defaultFont)(void);
153
165 Font *(*initWithData)(Font *self, Data *data, const char *family, int size, int style);
166
177 SDL_Surface *(*renderCharacters)(const Font *self, const char *chars, SDL_Color color, int wrapWidth);
178
185 void (*renderDeviceDidReset)(Font *self);
186
196 void (*sizeCharacters)(const Font *self, const char *chars, int *w, int *h);
197};
198
205OBJECTIVELYMVC_EXPORT Class *_Font(void);
static void sizeCharacters(const Font *self, const char *chars, int *w, int *h)
Definition: Font.c:272
static void clearCache(void)
Definition: Font.c:170
static void renderDeviceDidReset(Font *self)
Definition: Font.c:247
static void cacheFont(Data *data, const char *family)
Definition: Font.c:116
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
static SDL_Size size(const Image *self)
Definition: Image.c:181
ObjectivelyMVC base types.
#define OBJECTIVELYMVC_EXPORT
Definition: Types.h:39
TrueType fonts.
Definition: Font.h:63
FontInterface * interface
The interface.
Definition: Font.h:74
ident font
The backing font.
Definition: Font.h:89
int renderSize
The render size, adjusted for display density.
Definition: Font.h:94
char * family
The family name.
Definition: Font.h:84
Class * _Font(void)
The Font archetype.
Definition: Font.c:353
int size
The point size.
Definition: Font.h:99
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:104