17 namespace visualization {
26 return IM_COL32(
int(std::round(255.0f *
color.GetRed())),
27 int(std::round(255.0f *
color.GetGreen())),
28 int(std::round(255.0f *
color.GetBlue())),
29 int(std::round(255.0f *
color.GetAlpha())));
35 std::vector<std::string> kNormalSuffixes = {
36 " Regular.ttf",
" Regular.ttc",
" Regular.otf",
" Normal.ttf",
37 " Normal.ttc",
" Normal.otf",
" Medium.ttf",
" Medium.ttc",
38 " Medium.otf",
" Narrow.ttf",
" Narrow.ttc",
" Narrow.otf",
39 "-Regular.ttf",
"-Regular.ttc",
"-Regular.otf",
"-Normal.ttf",
40 "-Normal.ttc",
"-Normal.otf",
"-Medium.ttf",
"-Medium.ttc",
41 "-Medium.otf",
"-Narrow.ttf",
"-Narrow.ttc",
"-Narrow.otf",
42 "Regular.ttf",
"-Regular.ttc",
"-Regular.otf",
"Normal.ttf",
43 "Normal.ttc",
"Normal.otf",
"Medium.ttf",
"Medium.ttc",
44 "Medium.otf",
"Narrow.ttf",
"Narrow.ttc",
"Narrow.otf"};
46 std::vector<std::string> suffixes;
49 suffixes = kNormalSuffixes;
52 suffixes = {
" Bold.ttf",
70 suffixes = {
" Italic.ttf",
106 suffixes = {
" Bold Italic.ttf",
133 for (
auto &suf : kNormalSuffixes) {
134 if (font.rfind(suf) != std::string::npos) {
135 font = font.substr(0, font.size() - suf.size());
141 font = font.substr(0, font.size() - 4);
144 for (
auto &suf : suffixes) {
145 std::string candidate = font + suf;
156 char *raw_home = getenv(
"HOME");
160 std::vector<std::string> system_font_paths = {
162 "/System/Library/Fonts",
"/Library/Fonts", home +
"/Library/Fonts"
172 std::vector<std::string> font_ext = {
".ttf",
".ttc",
".otf"};
173 for (
auto &font_path : system_font_paths) {
175 for (
auto &ext : font_ext) {
176 std::string candidate = font_path +
"/" + font + ext;
183 for (
auto &font_path : system_font_paths) {
184 for (
auto &suf : suffixes) {
185 std::string candidate = font_path +
"/" + font + suf;
193 std::string font_ttf = font +
".ttf";
194 std::string font_ttc = font +
".ttc";
195 std::string font_otf = font +
".otf";
196 auto is_match = [font, &font_ttf, &font_ttc,
197 &font_otf](
const std::string &
path) {
200 if (ext !=
"ttf" && ext !=
"ttc" && ext !=
"otf") {
213 for (
auto &font_dir : system_font_paths) {
216 for (
auto &m : matches) {
223 for (
auto &m : matches) {
225 for (
auto &suf : suffixes) {
226 std::string candidate = dir + font + suf;
227 if (m == candidate) {
static const std::string path
std::vector< std::string > FindFilesRecursively(const std::string &directory, std::function< bool(const std::string &)> is_match)
std::string GetFileParentDirectory(const std::string &filename)
std::string GetFileNameWithoutExtension(const std::string &filename)
std::string GetFileExtensionInLowerCase(const std::string &filename)
bool FileExists(const std::string &filename)
std::string GetFileNameWithoutDirectory(const std::string &filename)
uint32_t colorToImguiRGBA(const Color &color)
std::string FindFontPath(std::string font, FontStyle style)
ImVec4 colorToImgui(const Color &color)
Generic file read and write utility for python interface.