From 9b010ed41733d3d2ffb36f8614912d2b13942771 Mon Sep 17 00:00:00 2001 From: GZharun Date: Fri, 5 Sep 2014 15:29:41 +0300 Subject: [PATCH] [Summary] Fixed name width issue on MAC applying a workaround. It's a response on Pango bug which will be fixed by Paul Davis --- gtk2_ardour/time_axis_view_item.cc | 31 +++++++----------------------- libs/canvas/canvas/text.h | 3 +++ libs/canvas/text.cc | 26 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index cba9320fde..09469aa802 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -59,13 +59,10 @@ using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; using namespace Gtkmm2ext; -// GZ: Should be moved to config #ifdef _WIN32 Pango::FontDescription TimeAxisViewItem::NAME_FONT("Arial 12"); - const double TimeAxisViewItem::NAME_WIDTH_CORRECTION = 0; #else Pango::FontDescription TimeAxisViewItem::NAME_FONT("Helvetica 12"); - const double TimeAxisViewItem::NAME_WIDTH_CORRECTION = 17; #endif const double TimeAxisViewItem::NAME_HIGHLIGHT_Y_INDENT = 2.0; @@ -563,10 +560,9 @@ TimeAxisViewItem::set_name_text(const string& new_name) if (!name_text) { return; } - // This is a workaround. - // Pango returns incorrect width values 1.5*NAME_HIGHLIGHT_X_INDENT - name_text_width = pixel_width (new_name, NAME_FONT) + NAME_WIDTH_CORRECTION; + name_text->set (new_name); + name_text_width = name_text->text_width(); manage_name_highlight(); } @@ -681,22 +677,9 @@ TimeAxisViewItem::set_name_text_color () return; } - - uint32_t f; - - if (Config->get_show_name_highlight()) { - /* name text will always be on top of name highlight, which - will always use our fill color. - */ - f = fill_color; - } else { - /* name text will be on top of the item, whose color - may vary depending on various conditions. - */ - f = get_fill_color (); - } - - name_text->set_color (ArdourCanvas::contrasting_text_color (f)); + // GZ FIXME:change in config instead of following + uint32_t text_color = ArdourCanvas::rgba_to_color (255.0, 255.0, 255.0, 1.0); + name_text->set_color (text_color); } uint32_t @@ -722,14 +705,14 @@ TimeAxisViewItem::fill_opacity () const uint32_t TimeAxisViewItem::get_fill_color () const { - uint32_t f; + uint32_t f; uint32_t o; o = fill_opacity (); if (_selected) { - f = ARDOUR_UI::config()->get_canvasvar_SelectedFrameBase(); + f = ARDOUR_UI::config()->get_canvasvar_SelectedFrameBase(); if (o == 0) { /* some condition of this item has set fill opacity to diff --git a/libs/canvas/canvas/text.h b/libs/canvas/canvas/text.h index 85262ee984..d4dacbfa4f 100644 --- a/libs/canvas/canvas/text.h +++ b/libs/canvas/canvas/text.h @@ -49,8 +49,11 @@ public: void dump (std::ostream&) const; std::string text() const { return _text; } + double text_width() const { return _width; } private: + double _width_correction; + std::string _text; uint32_t _color; Pango::FontDescription* _font_description; diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index 6fa1d30d31..0ce3f1d737 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include "pbd/stacktrace.h" @@ -31,8 +32,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) @@ -46,6 +49,7 @@ Text::Text (Canvas* c) Text::Text (Item* parent) : Item (parent) + , _width_correction (0) , _color (0x000000ff) , _font_description (0) , _alignment (Pango::ALIGN_LEFT) @@ -109,12 +113,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);