2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2009 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup blf
|
2014-01-19 13:14:24 +01:00
|
|
|
*
|
|
|
|
* Manage search paths for font files.
|
2011-02-27 21:42:42 +01:00
|
|
|
*/
|
|
|
|
|
2023-07-22 03:27:25 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2009-02-09 08:15:22 +01:00
|
|
|
|
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
|
|
|
|
2012-08-21 11:45:30 +02:00
|
|
|
#include "BLI_fileops.h"
|
|
|
|
#include "BLI_string.h"
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2011-02-16 06:18:10 +01:00
|
|
|
#include "BLF_api.h"
|
2011-05-10 15:11:36 +02:00
|
|
|
#include "blf_internal.h"
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-03-24 06:33:32 +01:00
|
|
|
char *blf_dir_metrics_search(const char *filepath)
|
2009-05-08 23:24:58 +02:00
|
|
|
{
|
|
|
|
char *mfile;
|
|
|
|
char *s;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-24 06:33:32 +01:00
|
|
|
mfile = BLI_strdup(filepath);
|
2012-03-12 10:22:16 +01:00
|
|
|
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);
|
2023-07-20 10:41:36 +02:00
|
|
|
return nullptr;
|
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';
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-26 04:27:14 +02:00
|
|
|
/* First check `.afm`. */
|
2019-04-22 01:09:06 +02:00
|
|
|
if (BLI_exists(mfile)) {
|
2013-11-23 19:36:38 +01:00
|
|
|
return mfile;
|
2019-04-22 01:09:06 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-26 04:27:14 +02:00
|
|
|
/* And now check `.pfm`. */
|
2012-03-12 10:22:16 +01:00
|
|
|
s[0] = 'p';
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:09:06 +02:00
|
|
|
if (BLI_exists(mfile)) {
|
2013-11-23 19:36:38 +01:00
|
|
|
return mfile;
|
2019-04-22 01:09:06 +02:00
|
|
|
}
|
2009-05-08 23:24:58 +02:00
|
|
|
}
|
|
|
|
MEM_freeN(mfile);
|
2023-07-20 10:41:36 +02:00
|
|
|
return nullptr;
|
2009-05-08 23:24:58 +02:00
|
|
|
}
|