aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_get_default_font_name.c
blob: 5fe770410da907aa7c2b416aa5e3421a6fc88cfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* See LICENSE file for copyright and license details. */
#include "common.h"


ssize_t
libfonts_get_default_font_name(enum libfonts_default_font font, char *name, size_t size, size_t index)
{
	const char *alias;
	size_t len;

	if (font == LIBFONTS_DEFAULT_SANS_SERIF) {
		if (index == 0)
			alias = "sans-serif";
		else if (index == 1)
			alias = "sans serif";
		else if (index == 2)
			alias = "sans";
		else
			return 0;

	} else if (font == LIBFONTS_DEFAULT_SERIF) {
		if (index == 0)
			alias = "serif";
		else
			return 0;

	} else if (font == LIBFONTS_DEFAULT_MONOSPACE) {
		if (index == 0)
			alias = "monospace";
		else if (index == 1)
			alias = "monospaced";
		else
			return 0;

	} else {
		errno = EINVAL;
		return -1;
	}

	len = strlen(alias);
	if (size) {
		size -= 1;
		if (size > len)
			size = len;
		memcpy(name, alias, size);
		name[size] = '\0';
	}
	return (ssize_t)len;
}