add new Gtkmm2ext::pixel_size() to conveniently get width&height for a given font...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Sep 2014 20:56:49 +0000 (16:56 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 29 Jun 2015 18:18:14 +0000 (14:18 -0400)
libs/gtkmm2ext/gtkmm2ext/utils.h
libs/gtkmm2ext/utils.cc

index 5832c914f600977a618637411805b814a35e9842..ab70464ea0c0f92cb2dec024304d3829ed578bb4 100644 (file)
@@ -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);
index 03396a4af921e773862f9d503b0a291a6eba7d2a..6efa95ac1a36e83ae57ea703a386d4ddf2f5a439 100644 (file)
@@ -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)