Blender V5.0
blf_dir.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdlib>
12#include <cstring>
13
14#include <ft2build.h>
15
16#include FT_FREETYPE_H
17#include FT_GLYPH_H
18
19#include "MEM_guardedalloc.h"
20
21#include "BLI_fileops.h"
22#include "BLI_string.h"
23
24#include "blf_internal.hh"
25
26char *blf_dir_metrics_search(const char *filepath)
27{
28 char *mfile;
29 char *s;
30
31 mfile = BLI_strdup(filepath);
32 s = strrchr(mfile, '.');
33 if (s) {
34 if (BLI_strnlen(s, 4) < 4) {
35 MEM_freeN(mfile);
36 return nullptr;
37 }
38 s++;
39 s[0] = 'a';
40 s[1] = 'f';
41 s[2] = 'm';
42
43 /* First check `.afm`. */
44 if (BLI_exists(mfile)) {
45 return mfile;
46 }
47
48 /* And now check `.pfm`. */
49 s[0] = 'p';
50
51 if (BLI_exists(mfile)) {
52 return mfile;
53 }
54 }
55 MEM_freeN(mfile);
56 return nullptr;
57}
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:360
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:913
Read Guarded memory(de)allocation.
char * blf_dir_metrics_search(const char *filepath)
Definition blf_dir.cc:26
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113