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 #include <sigc++/functors/mem_fun.h>
19 
20 #include <iostream>
21 #include "font-size.h"
22 
23 FontSize* FontSize::s_instance = 0;
24 
getInstance()25 FontSize* FontSize::getInstance()
26 {
27   if (s_instance == 0)
28     s_instance = new FontSize();
29 
30   return s_instance;
31 }
32 
deleteInstance()33 void FontSize::deleteInstance()
34 {
35   if (s_instance)
36     delete s_instance;
37 
38   s_instance = 0;
39 }
40 
FontSize()41 FontSize::FontSize()
42 {
43   calculate_default_font_height_and_width ();
44 }
45 
recalculate()46 bool FontSize::recalculate ()
47 {
48   double height = d_height, width = d_width;
49   calculate_default_font_height_and_width ();
50   return d_height != height || d_width != width;
51 }
52 
calculate_default_font_height_and_width()53 void FontSize::calculate_default_font_height_and_width ()
54 {
55   Gtk::HBox *box = new Gtk::HBox ();
56   Glib::RefPtr <Pango::Context> cr = box->create_pango_context ();
57   Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (cr);
58   layout->set_text ("A");
59   Pango::Rectangle ink, logical;
60   layout->get_pixel_extents (ink, logical);
61   d_height = ink.get_height ();
62   d_width = ink.get_width ();
63   if (d_height == 0)
64     d_height = 11.0;
65   if (d_width == 0)
66     d_width = 7.0;
67 }
68 // End of file
69