diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-29 08:19:22 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-29 08:19:22 -0400 |
commit | a83050a2552827c6224df07017ea4f6f32efd258 (patch) | |
tree | 5e1aa070640fbcbd2fcd186c8b1a54f80b20cc2a /libs | |
parent | 5ab699f8986456ae9bd43e83f5ba0a3411802e28 (diff) |
manually apply grygorii's API to manage a correction for pango errors in text size computation on OS X
Diffstat (limited to 'libs')
-rw-r--r-- | libs/canvas/canvas/text.h | 3 | ||||
-rw-r--r-- | libs/canvas/text.cc | 26 |
2 files changed, 27 insertions, 2 deletions
diff --git a/libs/canvas/canvas/text.h b/libs/canvas/canvas/text.h index ee22a3ecda..8e93e25c3c 100644 --- a/libs/canvas/canvas/text.h +++ b/libs/canvas/canvas/text.h @@ -65,7 +65,8 @@ private: mutable bool _need_redraw; mutable double _width_correction; double _clamped_width; - + double _width_correction; + void _redraw (Cairo::RefPtr<Cairo::Context>) const; void _redraw (Glib::RefPtr<Pango::Context>) const; void __redraw (Glib::RefPtr<Pango::Layout>) const; diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index 86d8aa9136..488e0c1540 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -20,6 +20,7 @@ #include <gdk/gdk.h> #include <cairomm/cairomm.h> +#include <gtkmm/window.h> #include <gtkmm/label.h> #include "pbd/stacktrace.h" @@ -32,8 +33,10 @@ using namespace std; using namespace ArdourCanvas; + Text::Text (Canvas* c) : Item (c) + , _width_correction (0) , _color (0x000000ff) , _font_description (0) , _alignment (Pango::ALIGN_LEFT) @@ -47,6 +50,7 @@ Text::Text (Canvas* c) Text::Text (Item* parent) : Item (parent) + , _width_correction (0) , _color (0x000000ff) , _font_description (0) , _alignment (Pango::ALIGN_LEFT) @@ -110,12 +114,32 @@ Text::__redraw (Glib::RefPtr<Pango::Layout> layout) const layout->set_alignment (_alignment); + // Pango returns incorrect text width on some platforms + // 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 + Gtk::Window win; + Gtk::Label foo; + win.add (foo); + + int width = 0; + int height = 0; + Glib::RefPtr<Pango::Layout> test_layout = foo.create_pango_layout ("H"); + test_layout->set_font_description (*_font_description); + test_layout->get_pixel_size (width, height); + +#ifdef __APPLE__ + double _width_correction = width*1.5; +#else if + double _width_correction = 0; +#endif + int w; int h; layout->get_pixel_size (w, h); - _width = w; + _width = w + _width_correction; _height = h; _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _width, _height); |