summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-09-11 16:56:49 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2015-06-29 14:18:14 -0400
commitc66ea2c1700520b9a4e5386a53082edcc39ed0dc (patch)
treef964b4803de6ad3c7e8c84d2859a5b3275a07709 /libs
parentdbe0d5a6495e4db90b0850d9f49ca9903e228a32 (diff)
add new Gtkmm2ext::pixel_size() to conveniently get width&height for a given font + string
Diffstat (limited to 'libs')
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/utils.h1
-rw-r--r--libs/gtkmm2ext/utils.cc12
2 files changed, 13 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h
index 5832c914f6..ab70464ea0 100644
--- a/libs/gtkmm2ext/gtkmm2ext/utils.h
+++ b/libs/gtkmm2ext/gtkmm2ext/utils.h
@@ -54,6 +54,7 @@ namespace Gtkmm2ext {
LIBGTKMM2EXT_API std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
LIBGTKMM2EXT_API std::pair<std::string, double> fit_to_pixels (cairo_t *, std::string, double);
LIBGTKMM2EXT_API int pixel_width (const std::string& str, Pango::FontDescription& font);
+ LIBGTKMM2EXT_API void pixel_size (const std::string& str, Pango::FontDescription& font, int& width, int& height);
LIBGTKMM2EXT_API void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>,
int& width, int& height);
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc
index 03396a4af9..6efa95ac1a 100644
--- a/libs/gtkmm2ext/utils.cc
+++ b/libs/gtkmm2ext/utils.cc
@@ -705,6 +705,18 @@ Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font)
return width;
}
+void
+Gtkmm2ext::pixel_size (const string& str, Pango::FontDescription& font, int& width, int& height)
+{
+ Gtk::Label foo;
+ Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
+
+ layout->set_font_description (font);
+ layout->set_text (str);
+
+ Gtkmm2ext::get_ink_pixel_size (layout, width, height);
+}
+
#if 0
string
Gtkmm2ext::fit_to_pixels (const string& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses)