[dasher: 6/43] Gtk2: fix text rendering position



commit 7cd8c4234f7837975b06ed3963d18d952f5735b2
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Tue Apr 26 14:36:37 2011 +0100

    Gtk2: fix text rendering position
    
    Correct way to get text at (x,y) is to use the (x,y) members of PangoRectangle,
    _not_ to subtract height/2 (as previous)!
    
    Also make PangoRectangle into local var not on heap, as just a four-int struct

 Src/Gtk2/Canvas.cpp |   18 ++++++++++--------
 Src/Gtk2/Canvas.h   |    6 ------
 2 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/Src/Gtk2/Canvas.cpp b/Src/Gtk2/Canvas.cpp
index bcb194e..64fbeec 100644
--- a/Src/Gtk2/Canvas.cpp
+++ b/Src/Gtk2/Canvas.cpp
@@ -61,7 +61,6 @@ CCanvas::CCanvas(GtkWidget *pCanvas, CPangoCache *pPangoCache,
 
 #endif
 
-  m_pPangoInk = new PangoRectangle;
   gtk_widget_add_events(m_pCanvas, GDK_ALL_EVENTS_MASK);
 }
 
@@ -86,7 +85,6 @@ CCanvas::~CCanvas() {
 #if WITH_CAIRO
   delete[] cairo_colours;
 #endif
-  delete m_pPangoInk;
 }
 
 void CCanvas::Blank() {
@@ -421,13 +419,16 @@ void CCanvas::DrawString(const std::string &String, screenint x1, screenint y1,
   PangoLayout *pLayout(m_pPangoCache->GetLayout(GTK_WIDGET(m_pCanvas), String, size));
 #endif
 
-  pango_layout_get_pixel_extents(pLayout, m_pPangoInk, NULL);
+  PangoRectangle sPangoInk;
 
+  pango_layout_get_pixel_extents(pLayout, &sPangoInk, NULL);
+  x1 -= sPangoInk.x;
+  y1 -= sPangoInk.y;
 #if WITH_CAIRO
-  cairo_translate(cr, x1, y1-(int)m_pPangoInk->height/2);
+  cairo_translate(cr, x1, y1);
   pango_cairo_show_layout(cr, pLayout);
 #else
-  gdk_draw_layout(m_pOffscreenBuffer, graphics_context, x1, y1 - m_pPangoInk->height / 2, pLayout);
+  gdk_draw_layout(m_pOffscreenBuffer, graphics_context, x1, y1, pLayout);
 #endif
 
   END_DRAWING;
@@ -440,10 +441,11 @@ void CCanvas::TextSize(const std::string &String, screenint *Width, screenint *H
   PangoLayout *pLayout(m_pPangoCache->GetLayout(GTK_WIDGET(m_pCanvas), String, size));
 #endif
 
-  pango_layout_get_pixel_extents(pLayout, m_pPangoInk, NULL);
+  PangoRectangle sPangoInk;
+  pango_layout_get_pixel_extents(pLayout, &sPangoInk, NULL);
 
-  *Width = m_pPangoInk->width;
-  *Height = m_pPangoInk->height;
+  *Width = sPangoInk.width;
+  *Height = sPangoInk.height;
 }
 
 void CCanvas::SendMarker(int iMarker) {
diff --git a/Src/Gtk2/Canvas.h b/Src/Gtk2/Canvas.h
index 610f4b0..0d9f78d 100644
--- a/Src/Gtk2/Canvas.h
+++ b/Src/Gtk2/Canvas.h
@@ -257,12 +257,6 @@ private:
 
   CPangoCache *m_pPangoCache;
 
-  ///
-  /// Holder for Pango layout extents.
-  ///
-
-  PangoRectangle *m_pPangoInk;
-
 #if WITH_CAIRO
   cairo_t *display_cr;
   cairo_t *decoration_cr;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]