X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/db16cab4610b294c3412f6508754b55ef4a42895..7291c37aa8f406b9487963a1b7fd6ee45b2e0b34:/src/gtk1/dcclient.cpp diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index eea9ffd7c3..2b469dfbea 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -331,6 +331,7 @@ wxWindowDC::wxWindowDC( wxWindow *window ) #ifdef __WXGTK20__ m_context = gtk_widget_get_pango_context( widget ); + m_fontdesc = widget->style->font_desc; #endif @@ -1421,13 +1422,19 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) x = XLOG2DEV(x); y = YLOG2DEV(y); -#if defined(__WXGTK20__) && wxUSE_WCHAR_T +#if defined(__WXGTK20__) // TODO: the layout engine should be abstracted at a higher level! PangoLayout *layout = pango_layout_new(m_context); pango_layout_set_font_description(layout, m_fontdesc); { - const wxWX2MBbuf data = text.mb_str(wxConvUTF8); - pango_layout_set_text(layout, data, strlen(data)); +#if wxUSE_UNICODE + const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); + pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); +#else + const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); + const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); + pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); +#endif } PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; PangoRectangle rect; @@ -1446,7 +1453,6 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); } 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 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS @@ -1457,8 +1463,9 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) if (font->descent > 0) 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__) g_object_unref( G_OBJECT( layout ) ); #endif @@ -1556,7 +1563,7 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, // don't use DrawPoint() because it uses the current pen // colour, and we don't need it here gdk_draw_point( m_window, m_textGC, - XLOG2DEV(x + dstX), YLOG2DEV(y + dstY) ); + XLOG2DEV(x) + dstX, YLOG2DEV(y) + dstY ); } } } @@ -1587,12 +1594,48 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, { wxFont fontToUse = m_font; 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); +#if wxUSE_UNICODE + const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); + pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); +#else + const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); + const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); + pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); +#endif + 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 / PANGO_SCALE); + if (height) (*height) = (wxCoord) (rect.height / PANGO_SCALE); + 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 ); if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX); if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY); if (descent) (*descent) = wxCoord(font->descent / m_scaleY); if (externalLeading) (*externalLeading) = 0; // ?? +#endif } wxCoord wxWindowDC::GetCharWidth() const