Blender V4.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
11#include <cstdio>
12#include <cstdlib>
13#include <cstring>
14
15#include <ft2build.h>
16
17#include FT_FREETYPE_H
18#include FT_GLYPH_H
19
20#include "MEM_guardedalloc.h"
21
22#include "DNA_vec_types.h"
23
24#include "BLI_fileops.h"
25#include "BLI_string.h"
26
27#include "BLF_api.hh"
28#include "blf_internal.hh"
29
30char *blf_dir_metrics_search(const char *filepath)
31{
32 char *mfile;
33 char *s;
34
35 mfile = BLI_strdup(filepath);
36 s = strrchr(mfile, '.');
37 if (s) {
38 if (BLI_strnlen(s, 4) < 4) {
39 MEM_freeN(mfile);
40 return nullptr;
41 }
42 s++;
43 s[0] = 'a';
44 s[1] = 'f';
45 s[2] = 'm';
46
47 /* First check `.afm`. */
48 if (BLI_exists(mfile)) {
49 return mfile;
50 }
51
52 /* And now check `.pfm`. */
53 s[0] = 'p';
54
55 if (BLI_exists(mfile)) {
56 return mfile;
57 }
58 }
59 MEM_freeN(mfile);
60 return nullptr;
61}
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:350
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
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.c:909
Read Guarded memory(de)allocation.
char * blf_dir_metrics_search(const char *filepath)
Definition blf_dir.cc:30
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105