[Summary] Fixed name width issue on MAC applying a workaround. It's a response on Pango bug which will be fixed by Paul Davis

This commit is contained in:
GZharun 2014-09-05 15:29:41 +03:00
parent 8f213aefb0
commit 9b010ed417
3 changed files with 35 additions and 25 deletions

View file

@ -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

View file

@ -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;

View file

@ -20,6 +20,7 @@
#include <gdk/gdk.h>
#include <cairomm/cairomm.h>
#include <gtkmm/window.h>
#include <gtkmm/label.h>
#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<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);