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 <pangomm/fontdescription.h>
25 #include <pangomm/layout.h>
26 
27 #include "canvas/visibility.h"
28 #include "canvas/item.h"
29 
30 namespace ArdourCanvas {
31 
32 class LIBCANVAS_API Text : public Item
33 {
34 public:
35 	Text (Canvas*);
36 	Text (Item*);
37 	~Text();
38 
39 	void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
40 	void compute_bounding_box () const;
41 
color()42 	Gtkmm2ext::Color color () const { return _color; }
43 	void set_color (Gtkmm2ext::Color);
44 
45 	void set (std::string const &);
46 	void set_font_description (Pango::FontDescription);
47 	void set_alignment (Pango::Alignment);
48 
49 	void clamp_width (double);
50 
51 	double width() const;
52 	double height() const;
53 
54 	void set_size_chars (int nchars);
55 	void dump (std::ostream&) const;
56 
text()57 	std::string text() const { return _text; }
58 	double text_width() const;
59 
60 private:
61 	std::string             _text;
62 	Gtkmm2ext::Color        _color;
63 	Pango::FontDescription* _font_description;
64 	Pango::Alignment        _alignment;
65 	mutable Cairo::RefPtr<Cairo::ImageSurface> _image;
66 	mutable Duple           _origin;
67 	mutable double          _width;
68 	mutable double          _height;
69 	mutable bool            _need_redraw;
70 	mutable double          _width_correction;
71 	double                  _clamped_width;
72 
73 	void _redraw () const;
74 };
75 
76 }
77 
78 #endif /* __ardour_canvas_text_h__ */
79