From a83050a2552827c6224df07017ea4f6f32efd258 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 29 Apr 2015 08:19:22 -0400 Subject: manually apply grygorii's API to manage a correction for pango errors in text size computation on OS X --- libs/canvas/text.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libs/canvas/text.cc') 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 #include +#include #include #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 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 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); -- cgit v1.2.3