14 #ifndef ECOLAB_PANGO_H 15 #define ECOLAB_PANGO_H 18 #include <pango/pangocairo.h> 28 PangoFontDescription* fd;
30 void operator=(
const Pango&);
34 static const char *defaultFamily;
35 Pango(cairo_t* cairo):
36 cairo(cairo), layout(pango_cairo_create_layout(cairo)), angle(0)
38 fd=pango_font_description_copy(pango_layout_get_font_description(layout));
41 fd=pango_font_description_copy
42 (pango_context_get_font_description(pango_layout_get_context(layout)));
45 pango_font_description_set_family(fd,defaultFamily);
46 pango_layout_set_font_description(layout, fd);
48 ~Pango() {pango_font_description_free(fd); g_object_unref(layout); }
49 void setMarkup(
const std::string& markup) {
50 pango_layout_set_markup(layout, markup.c_str(), -1);
51 pango_layout_get_extents(layout,0,&bbox);
53 void setFontSize(
double sz) {
54 if (gint(sz*PANGO_SCALE)<=0)
return;
55 pango_font_description_set_size(fd, gint(sz*PANGO_SCALE));
56 pango_layout_set_font_description(layout, fd);
58 void setFontFamily(
const char* family) {
59 pango_font_description_set_family(fd,family);
60 pango_layout_set_font_description(layout, fd);
62 double getFontSize()
const {
63 return pango_font_description_get_size(fd)/double(PANGO_SCALE);
74 cairo_identity_matrix(cairo);
75 cairo_rotate(cairo, angle);
76 cairo_rel_move_to(cairo,
left(),
top());
77 pango_cairo_update_layout(cairo, layout);
78 pango_cairo_show_layout(cairo, layout);
82 double width()
const {
return double(bbox.width)/PANGO_SCALE;}
84 double height()
const {
return double(bbox.height)/PANGO_SCALE;}
86 double left()
const {
return double(bbox.x)/PANGO_SCALE;}
88 double top()
const {
return double(bbox.y)/PANGO_SCALE;}
90 #else // fall back to basic Cairo text handling 95 cairo_text_extents_t bbox;
98 void operator=(
const Pango&);
102 Pango(cairo_t* cairo):
103 cairo(cairo), fontSize(10), angle(0) {}
104 void setMarkup(
const std::string& markup) {
106 cairo_text_extents(cairo,markup.c_str(),&bbox);
109 void setFontSize(
unsigned sz) {
111 cairo_set_font_size(cairo, sz);
113 double getFontSize()
const {
118 cairo_identity_matrix(cairo);
119 cairo_rotate(cairo, angle);
120 cairo_rel_move_to(cairo,
left(),-
top());
121 cairo_show_text(cairo, markup.c_str());
122 cairo_restore(cairo);
125 double width()
const {
return bbox.width;}
127 double height()
const {
return bbox.height;}
129 double left()
const {
return bbox.x_bearing;}
131 double top()
const {
return bbox.y_bearing;}
double height() const
height of rendered text
Definition: pango.h:127
double left() const
x-coordinate of left hand side of the rendered text
Definition: pango.h:129
double top() const
y-coordinate of the top of the rendered text
Definition: pango.h:131
_OPENMP
Definition: accessor.h:16
double width() const
width of rendered text
Definition: pango.h:125