From 957becbe2836d1bc4a8be76b7ca4abb445a181f3 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Wed, 21 Feb 2024 09:38:24 +0100 Subject: [PATCH] Fix: fl_height(int, int) decreases the font size after each call (#915) --- FL/Fl_Graphics_Driver.H | 1 + src/Fl_Graphics_Driver.cxx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H index 49d6d4fc4..3adf6d6c9 100644 --- a/FL/Fl_Graphics_Driver.H +++ b/FL/Fl_Graphics_Driver.H @@ -410,6 +410,7 @@ struct Fl_Fontdesc { In the future, it may also be used by other platforms. */ class FL_EXPORT Fl_Scalable_Graphics_Driver : public Fl_Graphics_Driver { + Fl_Fontsize fontsize_; // scale-independent font size value public: Fl_Scalable_Graphics_Driver(); // This function aims to compute accurately int(x * s) in diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index 4ef37e33f..6142c8672 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -745,6 +745,7 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { Fl_Scalable_Graphics_Driver::Fl_Scalable_Graphics_Driver() : Fl_Graphics_Driver() { line_width_ = 0; + fontsize_ = -1; } void Fl_Scalable_Graphics_Driver::rect(int x, int y, int w, int h) @@ -862,6 +863,7 @@ void Fl_Scalable_Graphics_Driver::circle(double x, double y, double r) { void Fl_Scalable_Graphics_Driver::font(Fl_Font face, Fl_Fontsize size) { if (!font_descriptor()) fl_open_display(); // to catch the correct initial value of scale_ font_unscaled(face, Fl_Fontsize(size * scale())); + fontsize_ = size; } Fl_Font Fl_Scalable_Graphics_Driver::font() { @@ -878,7 +880,7 @@ double Fl_Scalable_Graphics_Driver::width(unsigned int c) { Fl_Fontsize Fl_Scalable_Graphics_Driver::size() { if (!font_descriptor() ) return -1; - return Fl_Fontsize(size_unscaled()/scale()); + return fontsize_; } void Fl_Scalable_Graphics_Driver::text_extents(const char *str, int n, int &dx, int &dy, int &w, int &h) {