wxASSERT_MSG( widget, wxT("DC needs a widget") );
#ifdef __WXGTK20__
- m_context = gtk_widget_get_pango_context( widget );
-
+ m_context = window->GtkGetPangoDefaultContext();
m_fontdesc = widget->style->font_desc;
#endif
wxCHECK_RET( Ok(), wxT("invalid window dc") );
if (!m_window) return;
+
+ if (text.empty()) return;
+#ifndef __WXGTK20__
GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_RET( font, wxT("invalid font") );
+#endif
-#if defined(__WXGTK20__)
+#ifdef __WXGTK20__
wxCHECK_RET( m_context, wxT("no Pango context") );
#endif
x = XLOG2DEV(x);
y = YLOG2DEV(y);
-#if defined(__WXGTK20__) && wxUSE_WCHAR_T
+#ifdef __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;
- pango_layout_line_get_extents(line, NULL, &rect);
- wxCoord width = rect.width;
- wxCoord height = rect.height;
+
+ // Measure layout.
+ int w,h;
+ pango_layout_get_pixel_size(layout, &w, &h);
+ wxCoord width = w;
+ wxCoord height = h;
+
+ // Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
+
+ g_object_unref( G_OBJECT( layout ) );
#else // GTK+ 1.x
wxCoord width = gdk_string_width( font, text.mbc_str() );
wxCoord height = font->ascent + font->descent;
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
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
- g_object_unref( G_OBJECT( layout ) );
-#endif
width = wxCoord(width / m_scaleX);
height = wxCoord(height / m_scaleY);
wxCoord *descent, wxCoord *externalLeading,
wxFont *theFont) const
{
+ if (string.IsEmpty())
+ {
+ if (width) (*width) = 0;
+ if (height) (*height) = 0;
+ return;
+ }
+
+#ifdef __WXGTK20__
+ // Create layout and set font description
+ PangoLayout *layout = pango_layout_new(m_context);
+ if (theFont)
+ pango_layout_set_font_description( layout, theFont->GetNativeFontInfo()->description );
+ else
+ pango_layout_set_font_description(layout, m_fontdesc);
+
+ // Set layout's text
+#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
+
+ // Measure text.
+ int w,h;
+ pango_layout_get_pixel_size(layout, &w, &h);
+
+ if (width) (*width) = (wxCoord) w;
+ if (height) (*height) = (wxCoord) h;
+ if (descent)
+ {
+ // Do something about metrics here. TODO.
+ (*descent) = 0;
+ }
+ if (externalLeading) (*externalLeading) = 0; // ??
+
+ g_object_unref( G_OBJECT( layout ) );
+#else
wxFont fontToUse = m_font;
if (theFont) fontToUse = *theFont;
-
+
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
{
+#ifdef __WXGTK20__
+ // There should be an easier way.
+ PangoLayout *layout = pango_layout_new(m_context);
+ pango_layout_set_font_description(layout, m_fontdesc);
+ pango_layout_set_text(layout, "H", 1 );
+ int w,h;
+ pango_layout_get_pixel_size(layout, &w, &h);
+ g_object_unref( G_OBJECT( layout ) );
+ return w;
+#else
GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord(gdk_string_width( font, "H" ) / m_scaleX);
+#endif
}
wxCoord wxWindowDC::GetCharHeight() const
{
+#ifdef __WXGTK20__
+ // There should be an easier way.
+ PangoLayout *layout = pango_layout_new(m_context);
+ pango_layout_set_font_description(layout, m_fontdesc);
+ pango_layout_set_text(layout, "H", 1 );
+ int w,h;
+ pango_layout_get_pixel_size(layout, &w, &h);
+ g_object_unref( G_OBJECT( layout ) );
+ return h;
+#else
GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord((font->ascent + font->descent) / m_scaleY);
+#endif
}
void wxWindowDC::Clear()
m_font = font;
#ifdef __WXGTK20__
- m_fontdesc = m_font.GetNativeFontInfo()->description;
+ if (m_font.Ok())
+ {
+ m_fontdesc = m_font.GetNativeFontInfo()->description;
+
+ if (m_owner)
+ {
+ if (m_font.GetNoAntiAliasing())
+ m_context = m_owner->GtkGetPangoX11Context();
+ else
+ m_context = m_owner->GtkGetPangoDefaultContext();
+ }
+ }
#endif
}
gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash );
}
}
-#endif
+#endif // GTK+ > 1.0
GdkCapStyle capStyle = GDK_CAP_ROUND;
switch (m_pen.GetCap())
if (!m_window)
return;
- GdkFunction mode = GDK_COPY;
+ GdkFunction mode;
switch (function)
{
case wxXOR: mode = GDK_XOR; break;
case wxINVERT: mode = GDK_INVERT; break;
-#if (GTK_MINOR_VERSION > 0)
+#if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
case wxCLEAR: mode = GDK_CLEAR; break;
// unsupported by GTK
case wxNOR: mode = GDK_COPY; break;
-#endif
+#endif // GTK+ > 1.0
default:
- {
wxFAIL_MSG( wxT("unsupported logical function") );
- break;
- }
+ mode = GDK_COPY;
}
m_logicalFunction = function;