1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include "fastfetch.h"
#include "terminalfont.h"
#include "detection/terminalshell/terminalshell.h"
#include "common/io.h"
#ifdef FF_HAVE_FREETYPE
#include "common/library.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
#define FF_TERMUX_FONT_PATH FASTFETCH_TARGET_DIR_HOME "/.termux/font.ttf"
const char* detectTermux(FFTerminalFontResult* terminalFont) {
if (!ffPathExists(FF_TERMUX_FONT_PATH, FF_PATHTYPE_FILE)) {
ffFontInitCopy(&terminalFont->font, "monospace");
return NULL;
}
#ifdef FF_HAVE_FREETYPE
FF_LIBRARY_LOAD_MESSAGE(freetype, "libfreetype" FF_LIBRARY_EXTENSION, 2)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Init_FreeType);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_New_Face);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Done_Face);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Done_FreeType);
FT_Library library = NULL;
FT_Face face = NULL;
const char* error = NULL;
if (ffFT_Init_FreeType(&library)) {
error = "FT_Init_FreeType() failed";
goto exit;
}
if (ffFT_New_Face(library, FF_TERMUX_FONT_PATH, 0, &face)) {
error = "FT_NEW_Face(" FF_TERMUX_FONT_PATH ") failed";
goto exit;
}
ffFontInitCopy(&terminalFont->font, face->family_name);
exit:
if (face) {
ffFT_Done_Face(face);
}
if (library) {
ffFT_Done_FreeType(library);
}
return error;
#else
FF_UNUSED(terminalFont);
return "Fastfetch was built without freetype2 support";
#endif
}
bool ffDetectTerminalFontPlatform(const FFTerminalResult* terminal, FFTerminalFontResult* terminalFont) {
if (ffStrbufEqualS(&terminal->processName, "com.termux")) {
ffStrbufSetS(&terminalFont->error, detectTermux(terminalFont));
} else {
bool ffDetectTerminalFontPlatformLinux(const FFTerminalResult* terminal, FFTerminalFontResult* terminalFont);
return ffDetectTerminalFontPlatformLinux(terminal, terminalFont);
}
return true;
}
|