Ardour  9.0-pre0-582-g084a23a80d
text.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2013-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_canvas_text_h__
22 #define __ardour_canvas_text_h__
23 
24 #include <map>
25 
26 #include <pangomm/fontdescription.h>
27 #include <pangomm/layout.h>
28 
29 #include "canvas/visibility.h"
30 #include "canvas/item.h"
31 
32 namespace ArdourCanvas {
33 
34 class LIBCANVAS_API Text : public Item
35 {
36 public:
38  Text (Item*);
39  ~Text();
40 
41  void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
42  void compute_bounding_box () const;
43  void _size_allocate (Rect const&);
44 
45  Gtkmm2ext::Color color () const { return _color; }
47 
48  void set (std::string const &);
49  void set_font_description (Pango::FontDescription);
50  void set_alignment (Pango::Alignment);
51 
52  void clamp_width (double);
53 
54  double width() const;
55  double height() const;
56 
57  void set_size_chars (int nchars);
58  void dump (std::ostream&) const;
59 
60  std::string text() const { return _text; }
61  double text_width() const;
62  double text_height() const;
63 
65 
66  static int font_size_for_height (Distance height, std::string const & font_family, Glib::RefPtr<Pango::Context> const &);
67  static void drop_height_maps ();
68 
69 private:
70  std::string _text;
72  Pango::FontDescription* _font_description;
73  Pango::Alignment _alignment;
74  mutable Cairo::RefPtr<Cairo::ImageSurface> _image;
75  mutable Duple _origin;
76  mutable double _width;
77  mutable double _height;
78  mutable bool _need_redraw;
79  mutable double _width_correction;
82 
83  void _redraw () const;
84 
85  typedef std::map<Distance,int> FontSizeMap;
86  typedef std::map<std::string,FontSizeMap> FontSizeMaps;
87 
89 };
90 
91 }
92 
93 #endif /* __ardour_canvas_text_h__ */
#define LIBCANVAS_API
void set_color(Gtkmm2ext::Color)
bool _height_based_on_allocation
Definition: text.h:81
double height() const
static int font_size_for_height(Distance height, std::string const &font_family, Glib::RefPtr< Pango::Context > const &)
double _clamped_width
Definition: text.h:80
std::string _text
Definition: text.h:70
Pango::Alignment _alignment
Definition: text.h:73
void render(Rect const &, Cairo::RefPtr< Cairo::Context >) const
Duple _origin
Definition: text.h:75
void set(std::string const &)
Gtkmm2ext::Color color() const
Definition: text.h:45
std::string text() const
Definition: text.h:60
void _size_allocate(Rect const &)
void set_height_based_on_allocation(bool yn)
double text_height() const
static void drop_height_maps()
void dump(std::ostream &) const
double width() const
double _width_correction
Definition: text.h:79
void set_font_description(Pango::FontDescription)
double text_width() const
std::map< std::string, FontSizeMap > FontSizeMaps
Definition: text.h:86
static FontSizeMaps font_size_maps
Definition: text.h:88
void _redraw() const
Cairo::RefPtr< Cairo::ImageSurface > _image
Definition: text.h:74
std::map< Distance, int > FontSizeMap
Definition: text.h:85
void set_size_chars(int nchars)
double _height
Definition: text.h:77
Gtkmm2ext::Color _color
Definition: text.h:71
void set_alignment(Pango::Alignment)
Pango::FontDescription * _font_description
Definition: text.h:72
bool _need_redraw
Definition: text.h:78
double _width
Definition: text.h:76
void compute_bounding_box() const
void clamp_width(double)
uint32_t Color
Definition: colors.h:33
gint height
Definition: xcursors.h:1