Really cheesy attempt to make wxDC::DrawText() utilize gtk+ 1.3.1's
multilingual text rendering engine to draw Unicode text (doubt this works on wxMemoryDC, but at least it makes the generic listctrl show unicode text). But I suspect that the text engine really should be abstracted at a higher level in wxWindows... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -119,6 +119,10 @@ public:
|
|||||||
wxWindow *m_owner;
|
wxWindow *m_owner;
|
||||||
wxRegion m_currentClippingRegion;
|
wxRegion m_currentClippingRegion;
|
||||||
wxRegion m_paintClippingRegion;
|
wxRegion m_paintClippingRegion;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
PangoContext *m_context;
|
||||||
|
PangoFontDescription *m_fontdesc;
|
||||||
|
#endif
|
||||||
|
|
||||||
void SetUpDC();
|
void SetUpDC();
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
@@ -119,6 +119,10 @@ public:
|
|||||||
wxWindow *m_owner;
|
wxWindow *m_owner;
|
||||||
wxRegion m_currentClippingRegion;
|
wxRegion m_currentClippingRegion;
|
||||||
wxRegion m_paintClippingRegion;
|
wxRegion m_paintClippingRegion;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
PangoContext *m_context;
|
||||||
|
PangoFontDescription *m_fontdesc;
|
||||||
|
#endif
|
||||||
|
|
||||||
void SetUpDC();
|
void SetUpDC();
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
|
#include <gdk/gdkprivate.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -78,24 +79,48 @@ void gdk_wx_draw_bitmap (GdkDrawable *drawable,
|
|||||||
gint width,
|
gint width,
|
||||||
gint height)
|
gint height)
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
gint src_width, src_height;
|
||||||
|
#else
|
||||||
GdkWindowPrivate *drawable_private;
|
GdkWindowPrivate *drawable_private;
|
||||||
GdkWindowPrivate *src_private;
|
GdkWindowPrivate *src_private;
|
||||||
GdkGCPrivate *gc_private;
|
GdkGCPrivate *gc_private;
|
||||||
|
#endif
|
||||||
|
|
||||||
g_return_if_fail (drawable != NULL);
|
g_return_if_fail (drawable != NULL);
|
||||||
g_return_if_fail (src != NULL);
|
g_return_if_fail (src != NULL);
|
||||||
g_return_if_fail (gc != NULL);
|
g_return_if_fail (gc != NULL);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
if (GDK_WINDOW_DESTROYED(drawable) || GDK_WINDOW_DESTROYED(src))
|
||||||
|
return;
|
||||||
|
|
||||||
|
gdk_drawable_get_size(src, &src_width, &src_height);
|
||||||
|
#else
|
||||||
drawable_private = (GdkWindowPrivate*) drawable;
|
drawable_private = (GdkWindowPrivate*) drawable;
|
||||||
src_private = (GdkWindowPrivate*) src;
|
src_private = (GdkWindowPrivate*) src;
|
||||||
if (drawable_private->destroyed || src_private->destroyed)
|
if (drawable_private->destroyed || src_private->destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
src_width = src_private->width;
|
||||||
|
src_height = src_private->height;
|
||||||
|
|
||||||
gc_private = (GdkGCPrivate*) gc;
|
gc_private = (GdkGCPrivate*) gc;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (width == -1) width = src_private->width;
|
if (width == -1) width = src_width;
|
||||||
if (height == -1) height = src_private->height;
|
if (height == -1) height = src_height;
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
XCopyPlane( GDK_WINDOW_XDISPLAY(drawable),
|
||||||
|
GDK_WINDOW_XID(src),
|
||||||
|
GDK_WINDOW_XID(drawable),
|
||||||
|
GDK_GC_XGC(gc),
|
||||||
|
xsrc, ysrc,
|
||||||
|
width, height,
|
||||||
|
xdest, ydest,
|
||||||
|
1 );
|
||||||
|
#else
|
||||||
XCopyPlane( drawable_private->xdisplay,
|
XCopyPlane( drawable_private->xdisplay,
|
||||||
src_private->xwindow,
|
src_private->xwindow,
|
||||||
drawable_private->xwindow,
|
drawable_private->xwindow,
|
||||||
@@ -104,6 +129,7 @@ void gdk_wx_draw_bitmap (GdkDrawable *drawable,
|
|||||||
width, height,
|
width, height,
|
||||||
xdest, ydest,
|
xdest, ydest,
|
||||||
1 );
|
1 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -205,6 +231,10 @@ wxWindowDC::wxWindowDC()
|
|||||||
m_isMemDC = FALSE;
|
m_isMemDC = FALSE;
|
||||||
m_isScreenDC = FALSE;
|
m_isScreenDC = FALSE;
|
||||||
m_owner = (wxWindow *)NULL;
|
m_owner = (wxWindow *)NULL;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
m_context = (PangoContext *)NULL;
|
||||||
|
m_fontdesc = (PangoFontDescription *)NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindowDC::wxWindowDC( wxWindow *window )
|
wxWindowDC::wxWindowDC( wxWindow *window )
|
||||||
@@ -234,6 +264,11 @@ wxWindowDC::wxWindowDC( wxWindow *window )
|
|||||||
|
|
||||||
wxASSERT_MSG( widget, wxT("DC needs a widget") );
|
wxASSERT_MSG( widget, wxT("DC needs a widget") );
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
m_context = gtk_widget_get_pango_context( widget );
|
||||||
|
m_fontdesc = widget->style->font_desc;
|
||||||
|
#endif
|
||||||
|
|
||||||
GtkPizza *pizza = GTK_PIZZA( widget );
|
GtkPizza *pizza = GTK_PIZZA( widget );
|
||||||
m_window = pizza->bin_window;
|
m_window = pizza->bin_window;
|
||||||
|
|
||||||
@@ -1197,34 +1232,57 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
|
|
||||||
wxCHECK_RET( font, wxT("invalid font") );
|
wxCHECK_RET( font, wxT("invalid font") );
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
wxCHECK_RET( m_context, wxT("no Pango context") );
|
||||||
|
#endif
|
||||||
|
|
||||||
x = XLOG2DEV(x);
|
x = XLOG2DEV(x);
|
||||||
y = YLOG2DEV(y);
|
y = YLOG2DEV(y);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
/* FIXME: the layout engine should probably be abstracted at a higher level in wxDC... */
|
||||||
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
|
pango_layout_set_font_description(layout, m_fontdesc);
|
||||||
|
{
|
||||||
|
wxWX2MBbuf data = text.mb_str(wxConvUTF8);
|
||||||
|
pango_layout_set_text(layout, data, strlen(data));
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
gdk_draw_layout( m_window, m_textGC, x, y, layout );
|
||||||
|
#else
|
||||||
|
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
||||||
|
wxCoord height = font->ascent + font->descent;
|
||||||
/* CMB 21/5/98: draw text background if mode is wxSOLID */
|
/* CMB 21/5/98: draw text background if mode is wxSOLID */
|
||||||
if (m_backgroundMode == wxSOLID)
|
if (m_backgroundMode == wxSOLID)
|
||||||
{
|
{
|
||||||
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
|
||||||
wxCoord height = font->ascent + font->descent;
|
|
||||||
gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
|
gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
|
||||||
gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
|
gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
|
||||||
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
|
||||||
|
|
||||||
/* 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
|
||||||
properties (see wxXt implementation) */
|
properties (see wxXt implementation) */
|
||||||
if (m_font.GetUnderlined())
|
if (m_font.GetUnderlined())
|
||||||
{
|
{
|
||||||
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
|
||||||
wxCoord ul_y = y + font->ascent;
|
wxCoord ul_y = y + font->ascent;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord w, h;
|
#ifdef __WXGTK20__
|
||||||
GetTextExtent (text, &w, &h);
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
CalcBoundingBox (x + w, y + h);
|
#endif
|
||||||
|
|
||||||
|
width = wxCoord(width / m_scaleX);
|
||||||
|
height = wxCoord(height / m_scaleY);
|
||||||
|
CalcBoundingBox (x + width, y + height);
|
||||||
CalcBoundingBox (x, y);
|
CalcBoundingBox (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1405,6 +1463,9 @@ void wxWindowDC::Clear()
|
|||||||
void wxWindowDC::SetFont( const wxFont &font )
|
void wxWindowDC::SetFont( const wxFont &font )
|
||||||
{
|
{
|
||||||
m_font = font;
|
m_font = font;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
// fix fontdesc?
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowDC::SetPen( const wxPen &pen )
|
void wxWindowDC::SetPen( const wxPen &pen )
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
|
#include <gdk/gdkprivate.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -78,24 +79,48 @@ void gdk_wx_draw_bitmap (GdkDrawable *drawable,
|
|||||||
gint width,
|
gint width,
|
||||||
gint height)
|
gint height)
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
gint src_width, src_height;
|
||||||
|
#else
|
||||||
GdkWindowPrivate *drawable_private;
|
GdkWindowPrivate *drawable_private;
|
||||||
GdkWindowPrivate *src_private;
|
GdkWindowPrivate *src_private;
|
||||||
GdkGCPrivate *gc_private;
|
GdkGCPrivate *gc_private;
|
||||||
|
#endif
|
||||||
|
|
||||||
g_return_if_fail (drawable != NULL);
|
g_return_if_fail (drawable != NULL);
|
||||||
g_return_if_fail (src != NULL);
|
g_return_if_fail (src != NULL);
|
||||||
g_return_if_fail (gc != NULL);
|
g_return_if_fail (gc != NULL);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
if (GDK_WINDOW_DESTROYED(drawable) || GDK_WINDOW_DESTROYED(src))
|
||||||
|
return;
|
||||||
|
|
||||||
|
gdk_drawable_get_size(src, &src_width, &src_height);
|
||||||
|
#else
|
||||||
drawable_private = (GdkWindowPrivate*) drawable;
|
drawable_private = (GdkWindowPrivate*) drawable;
|
||||||
src_private = (GdkWindowPrivate*) src;
|
src_private = (GdkWindowPrivate*) src;
|
||||||
if (drawable_private->destroyed || src_private->destroyed)
|
if (drawable_private->destroyed || src_private->destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
src_width = src_private->width;
|
||||||
|
src_height = src_private->height;
|
||||||
|
|
||||||
gc_private = (GdkGCPrivate*) gc;
|
gc_private = (GdkGCPrivate*) gc;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (width == -1) width = src_private->width;
|
if (width == -1) width = src_width;
|
||||||
if (height == -1) height = src_private->height;
|
if (height == -1) height = src_height;
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
XCopyPlane( GDK_WINDOW_XDISPLAY(drawable),
|
||||||
|
GDK_WINDOW_XID(src),
|
||||||
|
GDK_WINDOW_XID(drawable),
|
||||||
|
GDK_GC_XGC(gc),
|
||||||
|
xsrc, ysrc,
|
||||||
|
width, height,
|
||||||
|
xdest, ydest,
|
||||||
|
1 );
|
||||||
|
#else
|
||||||
XCopyPlane( drawable_private->xdisplay,
|
XCopyPlane( drawable_private->xdisplay,
|
||||||
src_private->xwindow,
|
src_private->xwindow,
|
||||||
drawable_private->xwindow,
|
drawable_private->xwindow,
|
||||||
@@ -104,6 +129,7 @@ void gdk_wx_draw_bitmap (GdkDrawable *drawable,
|
|||||||
width, height,
|
width, height,
|
||||||
xdest, ydest,
|
xdest, ydest,
|
||||||
1 );
|
1 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -205,6 +231,10 @@ wxWindowDC::wxWindowDC()
|
|||||||
m_isMemDC = FALSE;
|
m_isMemDC = FALSE;
|
||||||
m_isScreenDC = FALSE;
|
m_isScreenDC = FALSE;
|
||||||
m_owner = (wxWindow *)NULL;
|
m_owner = (wxWindow *)NULL;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
m_context = (PangoContext *)NULL;
|
||||||
|
m_fontdesc = (PangoFontDescription *)NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindowDC::wxWindowDC( wxWindow *window )
|
wxWindowDC::wxWindowDC( wxWindow *window )
|
||||||
@@ -234,6 +264,11 @@ wxWindowDC::wxWindowDC( wxWindow *window )
|
|||||||
|
|
||||||
wxASSERT_MSG( widget, wxT("DC needs a widget") );
|
wxASSERT_MSG( widget, wxT("DC needs a widget") );
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
m_context = gtk_widget_get_pango_context( widget );
|
||||||
|
m_fontdesc = widget->style->font_desc;
|
||||||
|
#endif
|
||||||
|
|
||||||
GtkPizza *pizza = GTK_PIZZA( widget );
|
GtkPizza *pizza = GTK_PIZZA( widget );
|
||||||
m_window = pizza->bin_window;
|
m_window = pizza->bin_window;
|
||||||
|
|
||||||
@@ -1197,34 +1232,57 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
|
|
||||||
wxCHECK_RET( font, wxT("invalid font") );
|
wxCHECK_RET( font, wxT("invalid font") );
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
wxCHECK_RET( m_context, wxT("no Pango context") );
|
||||||
|
#endif
|
||||||
|
|
||||||
x = XLOG2DEV(x);
|
x = XLOG2DEV(x);
|
||||||
y = YLOG2DEV(y);
|
y = YLOG2DEV(y);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
/* FIXME: the layout engine should probably be abstracted at a higher level in wxDC... */
|
||||||
|
PangoLayout *layout = pango_layout_new(m_context);
|
||||||
|
pango_layout_set_font_description(layout, m_fontdesc);
|
||||||
|
{
|
||||||
|
wxWX2MBbuf data = text.mb_str(wxConvUTF8);
|
||||||
|
pango_layout_set_text(layout, data, strlen(data));
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
gdk_draw_layout( m_window, m_textGC, x, y, layout );
|
||||||
|
#else
|
||||||
|
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
||||||
|
wxCoord height = font->ascent + font->descent;
|
||||||
/* CMB 21/5/98: draw text background if mode is wxSOLID */
|
/* CMB 21/5/98: draw text background if mode is wxSOLID */
|
||||||
if (m_backgroundMode == wxSOLID)
|
if (m_backgroundMode == wxSOLID)
|
||||||
{
|
{
|
||||||
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
|
||||||
wxCoord height = font->ascent + font->descent;
|
|
||||||
gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
|
gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
|
||||||
gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
|
gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
|
||||||
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
|
||||||
|
|
||||||
/* 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
|
||||||
properties (see wxXt implementation) */
|
properties (see wxXt implementation) */
|
||||||
if (m_font.GetUnderlined())
|
if (m_font.GetUnderlined())
|
||||||
{
|
{
|
||||||
wxCoord width = gdk_string_width( font, text.mbc_str() );
|
|
||||||
wxCoord ul_y = y + font->ascent;
|
wxCoord ul_y = y + font->ascent;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord w, h;
|
#ifdef __WXGTK20__
|
||||||
GetTextExtent (text, &w, &h);
|
g_object_unref( G_OBJECT( layout ) );
|
||||||
CalcBoundingBox (x + w, y + h);
|
#endif
|
||||||
|
|
||||||
|
width = wxCoord(width / m_scaleX);
|
||||||
|
height = wxCoord(height / m_scaleY);
|
||||||
|
CalcBoundingBox (x + width, y + height);
|
||||||
CalcBoundingBox (x, y);
|
CalcBoundingBox (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1405,6 +1463,9 @@ void wxWindowDC::Clear()
|
|||||||
void wxWindowDC::SetFont( const wxFont &font )
|
void wxWindowDC::SetFont( const wxFont &font )
|
||||||
{
|
{
|
||||||
m_font = font;
|
m_font = font;
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
// fix fontdesc?
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowDC::SetPen( const wxPen &pen )
|
void wxWindowDC::SetPen( const wxPen &pen )
|
||||||
|
Reference in New Issue
Block a user