Blender V5.3
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.hh"
22#include "BLI_string.hh"
23
24#include "blf_internal.hh"
25
26namespace blender {
27
28char *blf_dir_metrics_search(const char *filepath)
29{
30 char *mfile;
31 char *s;
32
33 mfile = BLI_strdup(filepath);
34 s = strrchr(mfile, '.');
35 if (s) {
36 if (BLI_strnlen(s, 4) < 4) {
37 MEM_delete(mfile);
38 return nullptr;
39 }
40 s++;
41 s[0] = 'a';
42 s[1] = 'f';
43 s[2] = 'm';
44
45 /* First check `.afm`. */
46 if (BLI_exists(mfile)) {
47 return mfile;
48 }
49
50 /* And now check `.pfm`. */
51 s[0] = 'p';
52
53 if (BLI_exists(mfile)) {
54 return mfile;
55 }
56 }
57 MEM_delete(mfile);
58 return nullptr;
59}
60
61} // namespace blender
File and directory operations.
Read Blender memory allocation and freeing.
BMesh Iterators.
char * blf_dir_metrics_search(const char *filepath)
Definition blf_dir.cc:28
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC