From 2fb67053a14ff4d1e7d40a18b0e165e214adfb16 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 28 Dec 2025 23:15:30 +0100 Subject: Fixes Code Viewer widget height calculation --- FL/Fl_Text_Display.H | 2 +- util/code_snapshot.cxx | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index c997f9ce2..d1975c851 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -86,7 +86,7 @@ public: NORMAL_CURSOR, /**< I-beam */ CARET_CURSOR, /**< caret under the text */ DIM_CURSOR, /**< dim I-beam */ - BLOCK_CURSOR, /**< unfille box under the current character */ + BLOCK_CURSOR, /**< unfilled box under the current character */ HEAVY_CURSOR, /**< thick I-beam */ SIMPLE_CURSOR /**< as cursor as Fl_Input cursor */ }; diff --git a/util/code_snapshot.cxx b/util/code_snapshot.cxx index a8a2f2cae..6613d5b51 100644 --- a/util/code_snapshot.cxx +++ b/util/code_snapshot.cxx @@ -24,8 +24,6 @@ // PDF documentation instead of the code segments with UTF-8 characters. // -#include - #include #include #include @@ -37,9 +35,14 @@ #include "../fluid/widgets/Code_Viewer.h" #include "../fluid/widgets/Style_Parser.h" +#include +#include + + Fl_Window* window = nullptr; Fl_Group* group = nullptr; fld::widget::Code_Viewer* code_viewer = nullptr; +int line_height = 10; void create_window() { window = new Fl_Window(1024, 100); @@ -51,9 +54,19 @@ void create_window() { code_viewer->box(FL_FLAT_BOX); code_viewer->color(0xf7f7ff00); code_viewer->textsize(30); + //code_viewer->cursor_style(CARET_CURSOR); window->resizable(group); group->resizable(code_viewer); + + // Make sure the display is opened. + Fl_Display_Device::display_device(); + + line_height = fl_height(code_viewer->textfont(), code_viewer->textsize()); + line_height = std::max(line_height, fl_height(FL_COURIER, code_viewer->textsize())); + line_height = std::max(line_height, fl_height(FL_COURIER_BOLD, code_viewer->textsize())); + line_height = std::max(line_height, fl_height(FL_COURIER_ITALIC, code_viewer->textsize())); + line_height = std::max(line_height, fl_height(FL_COURIER_BOLD_ITALIC, code_viewer->textsize())); } void save_snapshot(const char* code, const char* filename) @@ -64,7 +77,7 @@ void save_snapshot(const char* code, const char* filename) int n_lines = 1; for (const char* s=code; *s; ++s) if (*s == '\n') n_lines++; // 300 dpi for 7 inches = 2000 pixels - window->size(2100, 6 + 34*n_lines ); + window->size(2100, (line_height * n_lines) + 18 ); // Generate the Image Surface Fl_Image_Surface *srfc = new Fl_Image_Surface(window->w(), window->h()); -- cgit v1.2.3