Implemented GetTextExtent() for GTK 2.0.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16485 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1427,8 +1427,8 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
PangoLayout *layout = pango_layout_new(m_context);
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
pango_layout_set_font_description(layout, m_fontdesc);
|
pango_layout_set_font_description(layout, m_fontdesc);
|
||||||
{
|
{
|
||||||
const wxWX2MBbuf data = text.mb_str(wxConvUTF8);
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
|
||||||
pango_layout_set_text(layout, data, strlen(data));
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
}
|
}
|
||||||
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
PangoRectangle rect;
|
PangoRectangle rect;
|
||||||
@@ -1447,7 +1447,6 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
|
gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
|
||||||
}
|
}
|
||||||
gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
|
gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
|
||||||
#endif // GTK+ 2.0/1.x
|
|
||||||
|
|
||||||
/* CMB 17/7/98: simple underline: ignores scaling and underlying
|
/* CMB 17/7/98: simple underline: ignores scaling and underlying
|
||||||
X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
|
X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
|
||||||
@@ -1458,6 +1457,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
if (font->descent > 0) ul_y++;
|
if (font->descent > 0) ul_y++;
|
||||||
gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
|
gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
|
||||||
}
|
}
|
||||||
|
#endif // GTK+ 2.0/1.x
|
||||||
|
|
||||||
#if defined(__WXGTK20__) && wxUSE_WCHAR_T
|
#if defined(__WXGTK20__) && wxUSE_WCHAR_T
|
||||||
g_object_unref( G_OBJECT( layout ) );
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
@@ -1588,12 +1588,44 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
{
|
{
|
||||||
wxFont fontToUse = m_font;
|
wxFont fontToUse = m_font;
|
||||||
if (theFont) fontToUse = *theFont;
|
if (theFont) fontToUse = *theFont;
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
if (width) (*width) = 0;
|
||||||
|
if (height) (*height) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
|
||||||
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
|
pango_layout_set_font_description(layout, desc);
|
||||||
|
{
|
||||||
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
|
||||||
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
|
}
|
||||||
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
|
|
||||||
|
PangoRectangle rect;
|
||||||
|
pango_layout_line_get_extents(line, NULL, &rect);
|
||||||
|
|
||||||
|
|
||||||
|
if (width) (*width) = (wxCoord) rect.width;
|
||||||
|
if (height) (*height) = (wxCoord) rect.height;
|
||||||
|
if (descent)
|
||||||
|
{
|
||||||
|
// Do something about metrics here
|
||||||
|
(*descent) = 0;
|
||||||
|
}
|
||||||
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
|
||||||
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
|
#else
|
||||||
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
||||||
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
||||||
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
||||||
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord wxWindowDC::GetCharWidth() const
|
wxCoord wxWindowDC::GetCharWidth() const
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
|
#include "wx/fontutil.h"
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
@@ -3139,11 +3140,54 @@ void wxWindowGTK::GetTextExtent( const wxString& string,
|
|||||||
|
|
||||||
wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
|
wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
|
||||||
|
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
|
||||||
|
PangoContext *context = NULL;
|
||||||
|
if (m_widget)
|
||||||
|
gtk_widget_get_pango_context( m_widget );
|
||||||
|
|
||||||
|
if (!context)
|
||||||
|
{
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
|
||||||
|
PangoLayout *layout = pango_layout_new(context);
|
||||||
|
pango_layout_set_font_description(layout, desc);
|
||||||
|
{
|
||||||
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
|
||||||
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
|
}
|
||||||
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
|
|
||||||
|
PangoRectangle rect;
|
||||||
|
pango_layout_line_get_extents(line, NULL, &rect);
|
||||||
|
|
||||||
|
if (x) (*x) = (wxCoord) rect.width;
|
||||||
|
if (y) (*y) = (wxCoord) rect.height;
|
||||||
|
if (descent)
|
||||||
|
{
|
||||||
|
// Do something about metrics here
|
||||||
|
(*descent) = 0;
|
||||||
|
}
|
||||||
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
|
||||||
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
|
#else
|
||||||
GdkFont *font = fontToUse.GetInternalFont( 1.0 );
|
GdkFont *font = fontToUse.GetInternalFont( 1.0 );
|
||||||
if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
|
if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
|
||||||
if (y) (*y) = font->ascent + font->descent;
|
if (y) (*y) = font->ascent + font->descent;
|
||||||
if (descent) (*descent) = font->descent;
|
if (descent) (*descent) = font->descent;
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowGTK::SetFocus()
|
void wxWindowGTK::SetFocus()
|
||||||
|
@@ -1427,8 +1427,8 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
PangoLayout *layout = pango_layout_new(m_context);
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
pango_layout_set_font_description(layout, m_fontdesc);
|
pango_layout_set_font_description(layout, m_fontdesc);
|
||||||
{
|
{
|
||||||
const wxWX2MBbuf data = text.mb_str(wxConvUTF8);
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
|
||||||
pango_layout_set_text(layout, data, strlen(data));
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
}
|
}
|
||||||
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
PangoRectangle rect;
|
PangoRectangle rect;
|
||||||
@@ -1447,7 +1447,6 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
|
gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
|
||||||
}
|
}
|
||||||
gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
|
gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
|
||||||
#endif // GTK+ 2.0/1.x
|
|
||||||
|
|
||||||
/* CMB 17/7/98: simple underline: ignores scaling and underlying
|
/* CMB 17/7/98: simple underline: ignores scaling and underlying
|
||||||
X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
|
X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
|
||||||
@@ -1458,6 +1457,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
if (font->descent > 0) ul_y++;
|
if (font->descent > 0) ul_y++;
|
||||||
gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
|
gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
|
||||||
}
|
}
|
||||||
|
#endif // GTK+ 2.0/1.x
|
||||||
|
|
||||||
#if defined(__WXGTK20__) && wxUSE_WCHAR_T
|
#if defined(__WXGTK20__) && wxUSE_WCHAR_T
|
||||||
g_object_unref( G_OBJECT( layout ) );
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
@@ -1588,12 +1588,44 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
{
|
{
|
||||||
wxFont fontToUse = m_font;
|
wxFont fontToUse = m_font;
|
||||||
if (theFont) fontToUse = *theFont;
|
if (theFont) fontToUse = *theFont;
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
if (width) (*width) = 0;
|
||||||
|
if (height) (*height) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
|
||||||
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
|
pango_layout_set_font_description(layout, desc);
|
||||||
|
{
|
||||||
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
|
||||||
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
|
}
|
||||||
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
|
|
||||||
|
PangoRectangle rect;
|
||||||
|
pango_layout_line_get_extents(line, NULL, &rect);
|
||||||
|
|
||||||
|
|
||||||
|
if (width) (*width) = (wxCoord) rect.width;
|
||||||
|
if (height) (*height) = (wxCoord) rect.height;
|
||||||
|
if (descent)
|
||||||
|
{
|
||||||
|
// Do something about metrics here
|
||||||
|
(*descent) = 0;
|
||||||
|
}
|
||||||
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
|
||||||
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
|
#else
|
||||||
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
||||||
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
||||||
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
||||||
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord wxWindowDC::GetCharWidth() const
|
wxCoord wxWindowDC::GetCharWidth() const
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
|
#include "wx/fontutil.h"
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
@@ -3139,11 +3140,54 @@ void wxWindowGTK::GetTextExtent( const wxString& string,
|
|||||||
|
|
||||||
wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
|
wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
|
||||||
|
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
|
||||||
|
PangoContext *context = NULL;
|
||||||
|
if (m_widget)
|
||||||
|
gtk_widget_get_pango_context( m_widget );
|
||||||
|
|
||||||
|
if (!context)
|
||||||
|
{
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
if (x) (*y) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
|
||||||
|
PangoLayout *layout = pango_layout_new(context);
|
||||||
|
pango_layout_set_font_description(layout, desc);
|
||||||
|
{
|
||||||
|
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
|
||||||
|
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
|
||||||
|
}
|
||||||
|
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
|
||||||
|
|
||||||
|
PangoRectangle rect;
|
||||||
|
pango_layout_line_get_extents(line, NULL, &rect);
|
||||||
|
|
||||||
|
if (x) (*x) = (wxCoord) rect.width;
|
||||||
|
if (y) (*y) = (wxCoord) rect.height;
|
||||||
|
if (descent)
|
||||||
|
{
|
||||||
|
// Do something about metrics here
|
||||||
|
(*descent) = 0;
|
||||||
|
}
|
||||||
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
|
||||||
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
|
#else
|
||||||
GdkFont *font = fontToUse.GetInternalFont( 1.0 );
|
GdkFont *font = fontToUse.GetInternalFont( 1.0 );
|
||||||
if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
|
if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
|
||||||
if (y) (*y) = font->ascent + font->descent;
|
if (y) (*y) = font->ascent + font->descent;
|
||||||
if (descent) (*descent) = font->descent;
|
if (descent) (*descent) = font->descent;
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (externalLeading) (*externalLeading) = 0; // ??
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowGTK::SetFocus()
|
void wxWindowGTK::SetFocus()
|
||||||
|
Reference in New Issue
Block a user