2011-02-23 11:52:22 +01:00
|
|
|
/*
|
2009-02-09 08:15:22 +01:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-09 08:15:22 +01:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 21:42:42 +01:00
|
|
|
/** \file blender/blenfont/intern/blf_dir.c
|
|
|
|
* \ingroup blf
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-09 08:15:22 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-02-17 17:56:29 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_GLYPH_H
|
|
|
|
|
2009-02-09 08:15:22 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-02-17 17:56:29 +01:00
|
|
|
#include "DNA_vec_types.h"
|
2009-02-09 08:15:22 +01:00
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
2009-02-17 17:56:29 +01:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
2011-02-16 06:18:10 +01:00
|
|
|
#include "BLF_api.h"
|
2009-02-09 08:15:22 +01:00
|
|
|
#include "blf_internal_types.h"
|
2011-05-10 15:11:36 +02:00
|
|
|
#include "blf_internal.h"
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
static ListBase global_font_dir = { NULL, NULL };
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2009-09-14 18:52:06 +02:00
|
|
|
static DirBLF *blf_dir_find(const char *path)
|
2009-02-09 08:15:22 +01:00
|
|
|
{
|
|
|
|
DirBLF *p;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
p = global_font_dir.first;
|
2009-02-09 08:15:22 +01:00
|
|
|
while (p) {
|
2011-04-06 08:03:48 +02:00
|
|
|
if (BLI_path_cmp(p->path, path) == 0)
|
2011-09-18 12:34:13 +02:00
|
|
|
return p;
|
2012-03-12 10:22:16 +01:00
|
|
|
p = p->next;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
2011-09-18 12:34:13 +02:00
|
|
|
return NULL;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BLF_dir_add(const char *path)
|
|
|
|
{
|
|
|
|
DirBLF *dir;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
dir = blf_dir_find(path);
|
2009-02-09 08:15:22 +01:00
|
|
|
if (dir) /* already in the list ? just return. */
|
|
|
|
return;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add");
|
|
|
|
dir->path = BLI_strdup(path);
|
2009-02-09 08:15:22 +01:00
|
|
|
BLI_addhead(&global_font_dir, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLF_dir_rem(const char *path)
|
|
|
|
{
|
|
|
|
DirBLF *dir;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
dir = blf_dir_find(path);
|
2009-02-09 08:15:22 +01:00
|
|
|
if (dir) {
|
|
|
|
BLI_remlink(&global_font_dir, dir);
|
|
|
|
MEM_freeN(dir->path);
|
|
|
|
MEM_freeN(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char **BLF_dir_get(int *ndir)
|
|
|
|
{
|
|
|
|
DirBLF *p;
|
|
|
|
char **dirs;
|
|
|
|
char *path;
|
|
|
|
int i, count;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
count = BLI_countlist(&global_font_dir);
|
2009-02-09 08:15:22 +01:00
|
|
|
if (!count)
|
2011-09-18 12:34:13 +02:00
|
|
|
return NULL;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
dirs = (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get");
|
|
|
|
p = global_font_dir.first;
|
|
|
|
i = 0;
|
2009-02-09 08:15:22 +01:00
|
|
|
while (p) {
|
2012-03-12 10:22:16 +01:00
|
|
|
path = BLI_strdup(p->path);
|
|
|
|
dirs[i] = path;
|
|
|
|
p = p->next;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
2012-03-12 10:22:16 +01:00
|
|
|
*ndir = i;
|
2011-09-18 12:34:13 +02:00
|
|
|
return dirs;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BLF_dir_free(char **dirs, int count)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int i;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
path = dirs[i];
|
2009-02-09 08:15:22 +01:00
|
|
|
MEM_freeN(path);
|
|
|
|
}
|
|
|
|
MEM_freeN(dirs);
|
|
|
|
}
|
|
|
|
|
2010-11-11 08:51:12 +01:00
|
|
|
char *blf_dir_search(const char *file)
|
2009-02-09 08:15:22 +01:00
|
|
|
{
|
|
|
|
DirBLF *dir;
|
2011-11-26 05:07:38 +01:00
|
|
|
char full_path[FILE_MAX];
|
2012-03-12 10:22:16 +01:00
|
|
|
char *s = NULL;
|
2011-02-13 04:21:27 +01:00
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
for (dir = global_font_dir.first; dir; dir = dir->next) {
|
2011-02-13 04:21:27 +01:00
|
|
|
BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file);
|
2011-10-22 00:33:41 +02:00
|
|
|
if (BLI_exists(full_path)) {
|
2012-03-12 10:22:16 +01:00
|
|
|
s = BLI_strdup(full_path);
|
2009-02-09 08:15:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-13 04:21:27 +01:00
|
|
|
|
2009-02-09 08:15:22 +01:00
|
|
|
if (!s) {
|
|
|
|
/* check the current directory, why not ? */
|
2011-10-22 00:33:41 +02:00
|
|
|
if (BLI_exists(file))
|
2012-03-12 10:22:16 +01:00
|
|
|
s = BLI_strdup(file);
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
2011-09-18 12:34:13 +02:00
|
|
|
|
|
|
|
return s;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
#if 0 /* UNUSED */
|
2009-02-09 08:15:22 +01:00
|
|
|
int blf_dir_split(const char *str, char *file, int *size)
|
|
|
|
{
|
2009-08-15 18:36:25 +02:00
|
|
|
int i, len;
|
|
|
|
char *s;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
|
|
|
/* Window, Linux or Mac, this is always / */
|
2012-03-12 10:22:16 +01:00
|
|
|
s = strrchr(str, '/');
|
2009-02-09 08:15:22 +01:00
|
|
|
if (s) {
|
2012-03-12 10:22:16 +01:00
|
|
|
len = s - str;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
file[i] = str[i];
|
|
|
|
|
|
|
|
file[i] = '.';
|
2012-05-11 18:11:52 +02:00
|
|
|
file[i + 1] = 't';
|
|
|
|
file[i + 2] = 't';
|
|
|
|
file[i + 3] = 'f';
|
|
|
|
file[i + 4] = '\0';
|
2009-02-09 08:15:22 +01:00
|
|
|
s++;
|
2012-03-12 10:22:16 +01:00
|
|
|
*size = atoi(s);
|
2011-09-18 12:34:13 +02:00
|
|
|
return 1;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
2011-09-18 12:34:13 +02:00
|
|
|
return 0;
|
2009-02-09 08:15:22 +01:00
|
|
|
}
|
2011-05-10 15:11:36 +02:00
|
|
|
#endif
|
2009-05-08 23:24:58 +02:00
|
|
|
|
|
|
|
/* Some font have additional file with metrics information,
|
|
|
|
* in general, the extension of the file is: .afm or .pfm
|
|
|
|
*/
|
2010-11-11 08:51:12 +01:00
|
|
|
char *blf_dir_metrics_search(const char *filename)
|
2009-05-08 23:24:58 +02:00
|
|
|
{
|
|
|
|
char *mfile;
|
|
|
|
char *s;
|
|
|
|
|
2012-03-12 10:22:16 +01:00
|
|
|
mfile = BLI_strdup(filename);
|
|
|
|
s = strrchr(mfile, '.');
|
2009-05-08 23:24:58 +02:00
|
|
|
if (s) {
|
2011-09-18 13:25:50 +02:00
|
|
|
if (BLI_strnlen(s, 4) < 4) {
|
2009-05-08 23:24:58 +02:00
|
|
|
MEM_freeN(mfile);
|
2011-09-18 12:34:13 +02:00
|
|
|
return NULL;
|
2009-05-08 23:24:58 +02:00
|
|
|
}
|
|
|
|
s++;
|
2012-03-12 10:22:16 +01:00
|
|
|
s[0] = 'a';
|
|
|
|
s[1] = 'f';
|
|
|
|
s[2] = 'm';
|
2009-05-08 23:24:58 +02:00
|
|
|
|
|
|
|
/* first check .afm */
|
2011-10-22 00:33:41 +02:00
|
|
|
if (BLI_exists(s))
|
2011-09-18 12:34:13 +02:00
|
|
|
return s;
|
2009-05-08 23:24:58 +02:00
|
|
|
|
|
|
|
/* and now check .pfm */
|
2012-03-12 10:22:16 +01:00
|
|
|
s[0] = 'p';
|
2009-05-08 23:24:58 +02:00
|
|
|
|
2011-10-22 00:33:41 +02:00
|
|
|
if (BLI_exists(s))
|
2011-09-18 12:34:13 +02:00
|
|
|
return s;
|
2009-05-08 23:24:58 +02:00
|
|
|
}
|
|
|
|
MEM_freeN(mfile);
|
2011-09-18 12:34:13 +02:00
|
|
|
return NULL;
|
2009-05-08 23:24:58 +02:00
|
|
|
}
|