diff options
author | Robin Gareus <robin@gareus.org> | 2015-09-06 16:39:08 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-09-06 16:39:08 +0200 |
commit | 57321bef35ac9ca98927e2fbb95845122d85303d (patch) | |
tree | 8df3056761d0acf5bd197df4d679cb04abb8a8ed /libs/gtkmm2ext/utils.cc | |
parent | 787fe69ff870e634dafcbe9a4b5f35b3e3395eea (diff) |
consistent pango-text layout size - fixes #6490
Use gdk_pango_layout() for all text-size calculations.
In Canvas::Text always use the same context (local image surface)
for layouting (prior to this, local and window-context mix resulted in
different sizes).
Diffstat (limited to 'libs/gtkmm2ext/utils.cc')
-rw-r--r-- | libs/gtkmm2ext/utils.cc | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index f1616f16a1..0a80825880 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -54,8 +54,8 @@ Gtkmm2ext::get_ink_pixel_size (Glib::RefPtr<Pango::Layout> layout, { Pango::Rectangle ink_rect = layout->get_ink_extents (); - width = (ink_rect.get_width() + PANGO_SCALE / 2) / PANGO_SCALE; - height = (ink_rect.get_height() + PANGO_SCALE / 2) / PANGO_SCALE; + width = PANGO_PIXELS(ink_rect.get_width()); + height = PANGO_PIXELS(ink_rect.get_height()); } void @@ -704,14 +704,28 @@ Gtkmm2ext::window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent) int Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font) { - Gtk::Label foo; - Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (""); + Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get()); + Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context); layout->set_font_description (font); layout->set_text (str); int width, height; Gtkmm2ext::get_ink_pixel_size (layout, width, height); + +#ifdef __APPLE__ + // Pango returns incorrect text width on some OS X + // So we have to make a correction + // To determine the correct indent take the largest symbol for which the width is correct + // and make the calculation + // + // see also libs/canvas/text.cc + int cor_width; + layout->set_text ("H"); + layout->get_pixel_size (cor_width, height); + width += cor_width * 1.5; +#endif + return width; } |