summaryrefslogtreecommitdiff
path: root/libs/canvas/text.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2015-04-29 08:19:22 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2015-04-29 08:19:22 -0400
commita83050a2552827c6224df07017ea4f6f32efd258 (patch)
tree5e1aa070640fbcbd2fcd186c8b1a54f80b20cc2a /libs/canvas/text.cc
parent5ab699f8986456ae9bd43e83f5ba0a3411802e28 (diff)
manually apply grygorii's API to manage a correction for pango errors in text size computation on OS X
Diffstat (limited to 'libs/canvas/text.cc')
-rw-r--r--libs/canvas/text.cc26
1 files changed, 25 insertions, 1 deletions
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);