File: Font.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (111 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <string.h>

#include <grass/gis.h>
#include "driver.h"
#include "driverlib.h"

static int font_type = GFONT_STROKE;

static void stroke_set(const char *filename)
{
    if (font_init(filename) == 0)
	font_type = GFONT_STROKE;
}

static void freetype_set(const char *filename, int index)
{
    if (font_init_freetype(filename, index) == 0)
	font_type = GFONT_FREETYPE;
}

void COM_Font_get(const char *name)
{
    if (G_is_absolute_path(name)) {
	if (!font_exists(name))
	    return;

	freetype_set(name, 0);
    }
    else {
	int i;

	/* check if freetype font is available in freetypecap */
	for (i = 0; ftcap[i].name; i++)
	    if (strcmp(name, ftcap[i].name) == 0) {
		switch (ftcap[i].type) {
		case GFONT_FREETYPE:
		    freetype_set(ftcap[i].path, ftcap[i].index);
		    font_init_charset(ftcap[i].encoding);
		    break;
		case GFONT_STROKE:
		    stroke_set(ftcap[i].name);
		    break;
		}
		return;
	    }

	stroke_set("romans");
    }
}

void COM_Font_init_charset(const char *charset)
{
    font_init_charset(charset);
}

int font_is_freetype(void)
{
    return font_type == GFONT_FREETYPE;
}

static void font_list(char ***list, int *count, int verbose)
{
    char **fonts;
    int num_fonts;
    int i;

    for (i = 0; ftcap[i].name; i++) ;

    num_fonts = i;

    fonts = G_malloc(num_fonts * sizeof(const char *));

    for (i = 0; i < num_fonts; i++) {
	struct GFONT_CAP *p = &ftcap[i];

	if (verbose) {
	    char buf[GPATH_MAX];

	    sprintf(buf, "%s|%s|%d|%s|%d|%s|",
		    p->name, p->longname, p->type,
		    p->path, p->index, p->encoding);

	    fonts[i] = G_store(buf);
	}
	else
	    fonts[i] = G_store(p->name);
    }

    *list = fonts;
    *count = num_fonts;
}

void COM_Font_list(char ***list, int *count)
{
    font_list(list, count, 0);
}

void COM_Font_info(char ***list, int *count)
{
    font_list(list, count, 1);
}

void free_font_list(char **fonts, int count)
{
    int i;

    for (i = 0; i < count; i++)
	G_free(fonts[i]);
    G_free(fonts);
}