|
|
@@ -15,6 +15,9 @@
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
#include <fmt/core.h>
|
|
|
+#include <cstdio>
|
|
|
+#include <memory>
|
|
|
+#include <array>
|
|
|
|
|
|
namespace lumacs {
|
|
|
|
|
|
@@ -28,6 +31,29 @@ static ::Color ToRLColor(const lumacs::Color& c) {
|
|
|
return RL_Color((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b);
|
|
|
}
|
|
|
|
|
|
+// Helper to get system monospace font path via fontconfig
|
|
|
+static std::string get_system_monospace_font_path() {
|
|
|
+ std::string result;
|
|
|
+ std::array<char, 128> buffer;
|
|
|
+ std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("fc-match monospace --format=\"%{file}\"", "r"), pclose);
|
|
|
+
|
|
|
+ if (!pipe) {
|
|
|
+ spdlog::warn("Failed to run fc-match to find system monospace font");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
|
|
+ result += buffer.data();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Trim newline if present
|
|
|
+ if (!result.empty() && result.back() == '\n') {
|
|
|
+ result.pop_back();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
RaylibEditor::RaylibEditor() {
|
|
|
}
|
|
|
|
|
|
@@ -47,15 +73,23 @@ void RaylibEditor::init() {
|
|
|
line_height_ = 20;
|
|
|
char_width_ = 10;
|
|
|
|
|
|
- const char* font_paths[] = {
|
|
|
- "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",
|
|
|
- "/usr/share/fonts/TTF/DejaVuSansMono.ttf",
|
|
|
- "resources/font.ttf"
|
|
|
- };
|
|
|
+ // Dynamic font path list
|
|
|
+ std::vector<std::string> font_paths;
|
|
|
+
|
|
|
+ // 1. Try system monospace font via fontconfig
|
|
|
+ std::string system_font = get_system_monospace_font_path();
|
|
|
+ if (!system_font.empty()) {
|
|
|
+ font_paths.push_back(system_font);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Fallback hardcoded paths
|
|
|
+ font_paths.push_back("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf");
|
|
|
+ font_paths.push_back("/usr/share/fonts/TTF/DejaVuSansMono.ttf");
|
|
|
+ font_paths.push_back("resources/font.ttf");
|
|
|
|
|
|
- for (const char* path : font_paths) {
|
|
|
- if (FileExists(path)) {
|
|
|
- Font loaded = LoadFontEx(path, font_size_, 0, 0);
|
|
|
+ for (const auto& path : font_paths) {
|
|
|
+ if (FileExists(path.c_str())) {
|
|
|
+ Font loaded = LoadFontEx(path.c_str(), font_size_, 0, 0);
|
|
|
if (loaded.texture.id != 0) {
|
|
|
font_ = loaded;
|
|
|
SetTextureFilter(font_.texture, TEXTURE_FILTER_BILINEAR);
|
|
|
@@ -223,7 +257,7 @@ void RaylibEditor::render() {
|
|
|
}
|
|
|
|
|
|
void RaylibEditor::draw_layout(LayoutNode* node, Rectangle area) {
|
|
|
- if (!node) return;
|
|
|
+ if (!node) return;
|
|
|
|
|
|
if (node->type == LayoutNode::Type::Leaf) {
|
|
|
if (node->window) {
|
|
|
@@ -342,4 +376,4 @@ std::unique_ptr<IEditorView> create_raylib_editor() {
|
|
|
return std::make_unique<RaylibEditor>();
|
|
|
}
|
|
|
|
|
|
-} // namespace lumacs
|
|
|
+} // namespace lumacs
|