1 //  Copyright (C) 2020 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #pragma once
19 #ifndef FONT_SIZE_H
20 #define FONT_SIZE_H
21 
22 #include <map>
23 #include <gtkmm.h>
24 
25 //! A utility class to get the height of the font
26 /**
27  * we need to know how tall a font is so that we can properly size
28  * some buttons and graphics later on.
29  *
30  */
31 class FontSize
32 {
33     public:
34         //! Returns the singleton instance. Creates a new one if required.
35         static FontSize* getInstance();
36 
37         //! Explicitly deletes the singleton instance.
38         static void deleteInstance();
39 
40         //! Return the height of the default font in pixels.
get_height()41         double get_height () { return d_height; }
42 
43         //! Return the width in pixels of one character in the default font.
get_width()44         double get_width () { return d_width; }
45 
46         //! Return true if it changed.
47         bool recalculate ();
48 
49     protected:
50 
51 	// Constructor.
52         FontSize();
53 
54 	//! Destructor.
~FontSize()55         ~FontSize() {};
56 
57     private:
58 
59         //! Calculate the height of the default font in pixels.
60         void calculate_default_font_height_and_width ();
61 
62 	// DATA
63         double d_height;
64         double d_width;
65 
66         static FontSize * s_instance;
67 };
68 
69 #endif // FONT_SIZE_H
70 
71 // End of file
72