~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to vector/v.label.sa/font.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * from lib/driver/parse_ftcap.c
3
 
 * These functions are copied from the diplay driver lib,
4
 
 * so that we don't need to have an active display driver open,
5
 
 * to run this module.
6
 
 */
7
 
 
8
 
#include <stdio.h>
9
 
#include <stdlib.h>
10
 
#include <string.h>
11
 
#include <grass/gis.h>
12
 
#include <grass/glocale.h>
13
 
#include <grass/freetypecap.h>
14
 
#include "labels.h"
15
 
 
16
 
static int font_exists(const char *name);
17
 
 
18
 
static int font_exists(const char *name)
19
 
{
20
 
    FILE *fp;
21
 
 
22
 
    fp = fopen(name, "r");
23
 
    if (!fp)
24
 
        return 0;
25
 
 
26
 
    fclose(fp);
27
 
    return 1;
28
 
}
29
 
 
30
 
void free_freetypecap(struct GFONT_CAP *ftcap)
31
 
{
32
 
    if (ftcap == NULL)
33
 
        return;
34
 
    G_free(ftcap->name);
35
 
    G_free(ftcap->longname);
36
 
    G_free(ftcap->path);
37
 
    G_free(ftcap->encoding);
38
 
    G_free(ftcap);
39
 
 
40
 
    return;
41
 
}
42
 
 
43
 
struct GFONT_CAP *find_font_from_freetypecap(const char *font)
44
 
{
45
 
    char *capfile, file[GPATH_MAX];
46
 
    char buf[GPATH_MAX];
47
 
    FILE *fp;
48
 
    int fonts_count = 0;
49
 
    struct GFONT_CAP *font_cap = NULL;
50
 
 
51
 
    fp = NULL;
52
 
    if ((capfile = getenv("GRASS_FONT_CAP"))) {
53
 
        if ((fp = fopen(capfile, "r")) == NULL)
54
 
            G_warning(_
55
 
                      ("%s: Unable to read font definition file; use the default"),
56
 
                      capfile);
57
 
    }
58
 
    if (fp == NULL) {
59
 
        sprintf(file, "%s/etc/fontcap", G_gisbase());
60
 
        if ((fp = fopen(file, "r")) == NULL)
61
 
            G_warning(_("%s: No font definition file"), file);
62
 
    }
63
 
 
64
 
    if (fp != NULL) {
65
 
        while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
66
 
            char name[GNAME_MAX], longname[GNAME_MAX],
67
 
                path[GPATH_MAX], encoding[128];
68
 
            int type, index;
69
 
            char *p;
70
 
 
71
 
            p = strchr(buf, '#');
72
 
            if (p)
73
 
                *p = 0;
74
 
 
75
 
            if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
76
 
                       name, longname, &type, path, &index, encoding)
77
 
                != 6)
78
 
                continue;
79
 
            if (strcmp(name, font) != 0 && strcmp(longname, font) != 0)
80
 
                continue;
81
 
            if (!font_exists(path))
82
 
                continue;
83
 
 
84
 
            font_cap = (struct GFONT_CAP *)G_malloc(sizeof(struct GFONT_CAP));
85
 
 
86
 
            font_cap[fonts_count].name = G_store(name);
87
 
            font_cap[fonts_count].longname = G_store(longname);
88
 
            font_cap[fonts_count].type = type;
89
 
            font_cap[fonts_count].path = G_store(path);
90
 
            font_cap[fonts_count].index = index;
91
 
            font_cap[fonts_count].encoding = G_store(encoding);
92
 
 
93
 
        }
94
 
        fclose(fp);
95
 
    }
96
 
 
97
 
    return font_cap;
98
 
}