label.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2010 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef LABEL_HPP
44 #define LABEL_HPP 1
45 
46 
47 #include <string>
48 #include <cairo.h>
49 
50 #include "color.hpp"
51 
52 
57 class Label
58 {
59  std::string _text;
61  double _size;
62  std::string _family;
63  cairo_font_slant_t _slant;
67  cairo_font_weight_t _weight;
71  Color _color;
73  double _xalign;
74  double _yalign;
75  bool _yzeroext;
76  double _rotation;
77  double _xlocation;
78  double _ylocation;
81  void process_parsed( cairo_t *cairo, const std::string &text, cairo_text_extents_t *extents0,
82  double x0, double y0, double &x, double &y ) const;
83  void parse_latex( cairo_t *cairo, const std::string &text, cairo_text_extents_t *extents0,
84  double x0, double y0, double &x, double &y ) const;
85 
86 public:
87 
88  Label();
89 
90  Label( const Label &label );
91 
92  Label( const std::string &text );
93 
94  ~Label();
95 
96  Label &operator=( const Label &label );
97 
100  void set_font_size( double size );
101 
104  double get_font_size( void ) const;
105 
108  void set_font_family( const std::string &family );
109 
112  void set_font_slant(cairo_font_slant_t slant );
113 
116  void set_font_weight( cairo_font_weight_t weight );
117 
120  void set_color( const Color &color );
121 
124  void set_location( double x, double y );
125 
131  void set_rotation( double angle );
132 
146  void set_alignment( double x, double y, bool yzeroext = false );
147 
150  void set_text( const std::string &text );
151 
154  std::string get_text( void ) const;
155 
158  void draw( cairo_t *cairo );
159 
164  void get_extents( cairo_t *cairo, cairo_text_extents_t *extents );
165 
172  void get_bbox( cairo_t *cairo, double bbox[4] ) const;
173 
174  friend std::ostream &operator<<( std::ostream &os, const Label &label );
175 };
176 
177 
178 #endif
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
Label & operator=(const Label &label)
void set_location(double x, double y)
Set label location.
void set_color(const Color &color)
Set label color.
double get_font_size(void) const
Get label font size.
friend std::ostream & operator<<(std::ostream &os, const Label &label)
void set_font_size(double size)
Set label font size.
Colors for plotting.
Class for labels in plots.
Definition: label.hpp:57
void set_font_weight(cairo_font_weight_t weight)
Set label font weight.
void get_bbox(cairo_t *cairo, double bbox[4]) const
Get bounding box of label.
std::string get_text(void) const
Get label text.
void set_font_slant(cairo_font_slant_t slant)
Set label font slant.
void set_font_family(const std::string &family)
Set label font family.
void set_rotation(double angle)
Set label rotation.
Color class for plotting.
Definition: color.hpp:53
void set_text(const std::string &text)
Set label text.
void get_extents(cairo_t *cairo, cairo_text_extents_t *extents)
Get text extents of label.
void draw(cairo_t *cairo)
Draw label.
void set_alignment(double x, double y, bool yzeroext=false)
Set label alignment.