13
0

manually apply grygorii's API to manage a correction for pango errors in text size computation on OS X

This commit is contained in:
Paul Davis 2015-04-29 08:19:22 -04:00
parent 5ab699f898
commit a83050a255
2 changed files with 27 additions and 2 deletions

View File

@ -65,6 +65,7 @@ private:
mutable bool _need_redraw; mutable bool _need_redraw;
mutable double _width_correction; mutable double _width_correction;
double _clamped_width; double _clamped_width;
double _width_correction;
void _redraw (Cairo::RefPtr<Cairo::Context>) const; void _redraw (Cairo::RefPtr<Cairo::Context>) const;
void _redraw (Glib::RefPtr<Pango::Context>) const; void _redraw (Glib::RefPtr<Pango::Context>) const;

View File

@ -20,6 +20,7 @@
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <cairomm/cairomm.h> #include <cairomm/cairomm.h>
#include <gtkmm/window.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
#include "pbd/stacktrace.h" #include "pbd/stacktrace.h"
@ -32,8 +33,10 @@
using namespace std; using namespace std;
using namespace ArdourCanvas; using namespace ArdourCanvas;
Text::Text (Canvas* c) Text::Text (Canvas* c)
: Item (c) : Item (c)
, _width_correction (0)
, _color (0x000000ff) , _color (0x000000ff)
, _font_description (0) , _font_description (0)
, _alignment (Pango::ALIGN_LEFT) , _alignment (Pango::ALIGN_LEFT)
@ -47,6 +50,7 @@ Text::Text (Canvas* c)
Text::Text (Item* parent) Text::Text (Item* parent)
: Item (parent) : Item (parent)
, _width_correction (0)
, _color (0x000000ff) , _color (0x000000ff)
, _font_description (0) , _font_description (0)
, _alignment (Pango::ALIGN_LEFT) , _alignment (Pango::ALIGN_LEFT)
@ -110,12 +114,32 @@ Text::__redraw (Glib::RefPtr<Pango::Layout> layout) const
layout->set_alignment (_alignment); 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 w;
int h; int h;
layout->get_pixel_size (w, h); layout->get_pixel_size (w, h);
_width = w; _width = w + _width_correction;
_height = h; _height = h;
_image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _width, _height); _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _width, _height);