13
0

allow pixbuf_from_string() to return the full size pixbuf, with optional padding

This commit is contained in:
Paul Davis 2015-11-19 10:39:29 -05:00
parent 336d321a1b
commit 51d403d485
3 changed files with 21 additions and 9 deletions

View File

@ -380,15 +380,15 @@ ARDOUR_UI::tabs_page_added (Widget*,guint)
editor_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (editor->name(), editor_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (editor->name(),
Pango::FontDescription ("Sans 24"), Pango::FontDescription ("Sans 24"),
40, 20, 0, 0,
Gdk::Color ("red"))); Gdk::Color ("red")));
mixer_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (mixer->name(), mixer_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (mixer->name(),
Pango::FontDescription ("Sans 24"), Pango::FontDescription ("Sans 24"),
40, 20, 0, 0,
Gdk::Color ("red"))); Gdk::Color ("red")));
prefs_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (rc_option_editor->name(), prefs_visibility_button.drag_source_set_icon (Gtkmm2ext::pixbuf_from_string (rc_option_editor->name(),
Pango::FontDescription ("Sans 24"), Pango::FontDescription ("Sans 24"),
40, 20, 0, 0,
Gdk::Color ("red"))); Gdk::Color ("red")));
} }
} }

View File

@ -54,8 +54,8 @@ 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::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 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 int pixel_width (const std::string& str, const Pango::FontDescription& font);
LIBGTKMM2EXT_API void pixel_size (const std::string& str, Pango::FontDescription& font, int& width, int& height); LIBGTKMM2EXT_API void pixel_size (const std::string& str, const Pango::FontDescription& font, int& width, int& height);
LIBGTKMM2EXT_API void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>, LIBGTKMM2EXT_API void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>,
int& width, int& height); int& width, int& height);

View File

@ -272,6 +272,18 @@ Gtkmm2ext::pixbuf_from_string(const string& name, const Pango::FontDescription&
return *empty_pixbuf; return *empty_pixbuf;
} }
if (clip_width <= 0 || clip_height <= 0) {
/* negative values mean padding around natural size */
int width, height;
pixel_size (name, font, width, height);
if (clip_width <= 0) {
clip_width = width - clip_width;
}
if (clip_height <= 0) {
clip_height = height - clip_height;
}
}
Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, clip_width, clip_height); Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, clip_width, clip_height);
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clip_width, clip_height); cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clip_width, clip_height);
@ -678,7 +690,7 @@ Gtkmm2ext::window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent)
} }
int int
Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font) Gtkmm2ext::pixel_width (const string& str, const Pango::FontDescription& font)
{ {
Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get()); Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get());
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context); Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
@ -706,7 +718,7 @@ Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font)
} }
void void
Gtkmm2ext::pixel_size (const string& str, Pango::FontDescription& font, int& width, int& height) Gtkmm2ext::pixel_size (const string& str, const Pango::FontDescription& font, int& width, int& height)
{ {
Gtk::Label foo; Gtk::Label foo;
Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (""); Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
@ -732,9 +744,9 @@ Gtkmm2ext::fit_to_pixels (const string& str, int pixel_width, Pango::FontDescrip
layout->set_width (pixel_width * PANGO_SCALE); layout->set_width (pixel_width * PANGO_SCALE);
if (with_ellipses) { if (with_ellipses) {
layout->set_ellipsize (Pango::ELLIPSIZE_END); layout->set_ellipsize (Pango::ELLIPSIZE_END);
} else { } else {
layout->set_wrap (Pango::WRAP_CHAR); layout->set_wrap (Pango::WRAP_CHAR);
} }
line = layout->get_line (0); line = layout->get_line (0);