manually apply grygorii's API to manage a correction for pango errors in text size computation on OS X
This commit is contained in:
parent
5ab699f898
commit
a83050a255
@ -65,7 +65,8 @@ private:
|
||||
mutable bool _need_redraw;
|
||||
mutable double _width_correction;
|
||||
double _clamped_width;
|
||||
|
||||
double _width_correction;
|
||||
|
||||
void _redraw (Cairo::RefPtr<Cairo::Context>) const;
|
||||
void _redraw (Glib::RefPtr<Pango::Context>) const;
|
||||
void __redraw (Glib::RefPtr<Pango::Layout>) const;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user