From df072b781c54bd0c6ba916c3c16f9b0f2daa1836 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 9 Apr 2009 10:16:31 +0000 Subject: [PATCH] slightly better font handling, enjoy! git-svn-id: svn://svn.icculus.org/netradiant/trunk@313 61c419a2-8eb2-4b30-bcec-8cead039b335 --- include/igl.h | 2 ++ libs/gtkutil/glfont.cpp | 16 ++++++++++------ libs/gtkutil/glfont.h | 12 +++++++++++- radiant/camwindow.cpp | 4 ++-- radiant/mainframe.cpp | 4 +++- radiant/xywindow.cpp | 3 ++- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/igl.h b/include/igl.h index 29bf5f80..b1753457 100644 --- a/include/igl.h +++ b/include/igl.h @@ -1999,6 +1999,8 @@ struct OpenGLBinding GLuint m_font; int m_fontHeight; + int m_fontAscent; + int m_fontDescent; /// \brief Renders \p string at the current raster-position of the current context. void drawString(const char* string) const diff --git a/libs/gtkutil/glfont.cpp b/libs/gtkutil/glfont.cpp index e46236d3..13d16fdb 100644 --- a/libs/gtkutil/glfont.cpp +++ b/libs/gtkutil/glfont.cpp @@ -107,7 +107,7 @@ void glfont_release(GLFont& font) GLFont glfont_create(const char* font_string) { GLuint font_list_base = glGenLists (256); - gint font_height = 0; + gint font_height = 0, font_ascent = 0, font_descent = 0; PangoFontDescription* font_desc = pango_font_description_from_string (font_string); @@ -117,8 +117,12 @@ GLFont glfont_create(const char* font_string) { PangoFontMetrics* font_metrics = pango_font_get_metrics (font, 0); - font_height = pango_font_metrics_get_ascent (font_metrics) + - pango_font_metrics_get_descent (font_metrics); + font_ascent = pango_font_metrics_get_ascent (font_metrics); + font_descent = pango_font_metrics_get_descent (font_metrics); + font_height = font_ascent + font_descent; + + font_ascent = PANGO_PIXELS (font_ascent); + font_descent = PANGO_PIXELS (font_descent); font_height = PANGO_PIXELS (font_height); pango_font_metrics_unref (font_metrics); @@ -127,15 +131,15 @@ GLFont glfont_create(const char* font_string) pango_font_description_free (font_desc); // fix for pango/gtkglext metrix bug - if(font_height > 16) + if(font_height > 256) font_height = 16; - return GLFont(font_list_base, font_height); + return GLFont(font_list_base, font_ascent, font_descent, font_height); } void glfont_release(GLFont& font) { glDeleteLists(font.getDisplayList(), 256); - font = GLFont(0, 0); + font = GLFont(0, 0, 0, 0); } #endif diff --git a/libs/gtkutil/glfont.h b/libs/gtkutil/glfont.h index 8c18afad..454c6a97 100644 --- a/libs/gtkutil/glfont.h +++ b/libs/gtkutil/glfont.h @@ -28,8 +28,10 @@ class GLFont { GLuint m_displayList; int m_pixelHeight; + int m_pixelAscent; + int m_pixelDescent; public: - GLFont(GLuint displayList, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight) + GLFont(GLuint displayList, int asc, int desc, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight), m_pixelAscent(asc), m_pixelDescent(desc) { } GLuint getDisplayList() const @@ -40,6 +42,14 @@ public: { return m_pixelHeight; } + int getPixelAscent() const + { + return m_pixelAscent; + } + int getPixelDescent() const + { + return m_pixelDescent; + } }; GLFont glfont_create(const char* font_string); diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index c26bc5b5..f1566abd 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1691,11 +1691,11 @@ void CamWnd::Cam_Draw() if(g_camwindow_globals_private.m_showStats) { - glRasterPos3f(1.0f, static_cast(m_Camera.height) - 1.0f, 0.0f); + glRasterPos3f(1.0f, static_cast(m_Camera.height) - GlobalOpenGL().m_fontDescent, 0.0f); extern const char* Renderer_GetStats(); GlobalOpenGL().drawString(Renderer_GetStats()); - glRasterPos3f(1.0f, static_cast(m_Camera.height) - 11.0f, 0.0f); + glRasterPos3f(1.0f, static_cast(m_Camera.height) - GlobalOpenGL().m_fontDescent - GlobalOpenGL().m_fontHeight, 0.0f); extern const char* Cull_GetStats(); GlobalOpenGL().drawString(Cull_GetStats()); } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index dd3a17b9..d6f467da 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -3305,7 +3305,7 @@ void GridStatus_onTextureLockEnabledChanged() namespace { - GLFont g_font(0, 0); + GLFont g_font(0, 0, 0, 0); } void GlobalGL_sharedContextCreated() @@ -3331,6 +3331,8 @@ void GlobalGL_sharedContextCreated() GlobalOpenGL().m_font = g_font.getDisplayList(); GlobalOpenGL().m_fontHeight = g_font.getPixelHeight(); + GlobalOpenGL().m_fontAscent = g_font.getPixelAscent(); + GlobalOpenGL().m_fontDescent = g_font.getPixelDescent(); } void GlobalGL_sharedContextDestroyed() diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 40162f4d..9e6c1664 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1842,7 +1842,8 @@ void XYWnd::XY_DrawGrid(void) { // draw coordinate text if needed if ( g_xywindow_globals_private.show_coordinates) { glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext)); - float offx = m_vOrigin[nDim2] + h - 6 / m_fScale, offy = m_vOrigin[nDim1] - w + 1 / m_fScale; + float offx = m_vOrigin[nDim2] + h - (1 + GlobalOpenGL().m_fontAscent) / m_fScale; + float offy = m_vOrigin[nDim1] - w + 1 / m_fScale; for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx) { glRasterPos2f (x, offx); sprintf (text, "%g", x); -- 2.39.2