From d76fec130d15d74f3e2124374bbc00c78c5bd15c Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 9 Nov 2002 17:35:40 +0000 Subject: [PATCH] Added anti-aliasing and printing in Unicode to wxX11. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17781 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 7 +++++ src/generic/dcpsg.cpp | 22 +++++++++++----- src/x11/app.cpp | 14 +++++----- src/x11/dcclient.cpp | 2 +- src/x11/pango_x.cpp | 60 ++++++++++++++++++++++++++----------------- 5 files changed, 68 insertions(+), 37 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index cd65da7854..22051cdd91 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -185,6 +185,13 @@ Unix (Base/GUI): - don't include -I/usr/include nor -I/usr/local/include in wx-config output - shared library symbols are now versioned on platforms that support it (Linux) +wxGTK: +- Further work for GTK 2.0 and Unicode support. +- Addition of native frame site grip. + +wxX11: +- Unicode support through Pango library. + wxMSW: - fixed crashes in wxListCtrl under XP diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 0a2b1a8c16..25c72a2a11 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -204,7 +204,8 @@ static const char *wxPostScriptHeaderColourImage = "\ } ifelse %% end of 'false' case\n\ "; -#ifndef __WXGTK20__ +#if wxUSE_PANGO +#else static char wxPostScriptHeaderReencodeISO1[] = "\n/reencodeISO {\n" "dup dup findfont dup length dict begin\n" @@ -886,7 +887,8 @@ void wxPostScriptDC::SetFont( const wxFont& font ) m_font = font; -#ifndef __WXGTK20__ +#if wxUSE_PANGO +#else int Style = m_font.GetStyle(); int Weight = m_font.GetWeight(); @@ -1117,13 +1119,18 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) } } -#ifdef __WXGTK20__ +#if wxUSE_PANGO #define PANGO_ENABLE_ENGINE +#ifdef __WXGTK20__ #include "wx/gtk/private.h" -#include "wx/fontutil.h" #include "gtk/gtk.h" +#else +#include "wx/x11/private.h" +#endif + +#include "wx/fontutil.h" #include #include @@ -1233,7 +1240,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); -#ifdef __WXGTK20__ +#if wxUSE_PANGO int dpi = GetResolution(); dpi = 300; PangoContext *context = pango_ft2_get_context ( dpi, dpi ); @@ -1754,7 +1761,8 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) fprintf( m_pstream, wxPostScriptHeaderEllipse ); fprintf( m_pstream, wxPostScriptHeaderEllipticArc ); fprintf( m_pstream, wxPostScriptHeaderColourImage ); -#ifndef __WXGTK20__ +#if wxUSE_PANGO +#else fprintf( m_pstream, wxPostScriptHeaderReencodeISO1 ); fprintf( m_pstream, wxPostScriptHeaderReencodeISO2 ); #endif @@ -1972,7 +1980,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, return; } -#ifdef __WXGTK20__ +#if wxUSE_PANGO int dpi = GetResolution(); PangoContext *context = pango_ft2_get_context ( dpi, dpi ); diff --git a/src/x11/app.cpp b/src/x11/app.cpp index 12502ea7a7..5212e685e8 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -1110,6 +1110,14 @@ bool wxApp::OnInitGui() PangoContext* wxApp::GetPangoContext() { + static PangoContext *ret = NULL; + if (ret) + return ret; + + Display *xdisplay = (Display*) wxApp::GetDisplay(); + +#if 1 + int xscreen = DefaultScreen(xdisplay); static int use_xft = -1; if (use_xft == -1) { @@ -1117,12 +1125,6 @@ PangoContext* wxApp::GetPangoContext() use_xft = (val == L"1"); } - Display *xdisplay = (Display*) wxApp::GetDisplay(); - int xscreen = DefaultScreen(xdisplay); - - PangoContext *ret = NULL; - -#if 0 if (use_xft) ret = pango_xft_get_context( xdisplay, xscreen ); else diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 7e3ace973f..162a8c7153 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -1405,7 +1405,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) wxCoord height = h; // Draw layout. - x11_draw_layout( (Drawable) m_window, (GC) m_textGC, x, y, layout ); + x11_draw_layout( (Drawable) m_window, (GC) m_textGC, x, y, layout, m_textForegroundColour ); g_object_unref( G_OBJECT( layout ) ); diff --git a/src/x11/pango_x.cpp b/src/x11/pango_x.cpp index 17108cf60b..e3e12e3dec 100644 --- a/src/x11/pango_x.cpp +++ b/src/x11/pango_x.cpp @@ -12,7 +12,8 @@ x11_draw_glyphs( Drawable drawable, PangoFont *font, int x, int y, - PangoGlyphString *glyphs); + PangoGlyphString *glyphs, + wxColour &colour ); void x11_draw_layout_line_with_colors( Drawable drawable, @@ -20,8 +21,7 @@ x11_draw_layout_line_with_colors( Drawable drawable, int x, int y, PangoLayoutLine *line, - XColor *foreground, - XColor *background); + wxColour &colour ); void x11_draw_layout_with_colors( Drawable drawable, @@ -29,15 +29,15 @@ x11_draw_layout_with_colors( Drawable drawable, int x, int y, PangoLayout *layout, - XColor *foreground, - XColor *background); + wxColour &colour ); void x11_draw_layout( Drawable drawable, GC gc, int x, int y, - PangoLayout *layout); + PangoLayout *layout, + wxColour &colour); void x11_pango_get_item_properties( PangoItem *item, @@ -55,16 +55,32 @@ x11_pango_get_item_properties( PangoItem *item, /* Implementation */ void -x11_draw_glyphs( Drawable drawable, - GC gc, - PangoFont *font, - int x, - int y, - PangoGlyphString *glyphs) +x11_draw_glyphs( Drawable drawable, + GC gc, + PangoFont *font, + int x, + int y, + PangoGlyphString *glyphs, + wxColour &colour ) { if (PANGO_XFT_IS_FONT (font)) { - pango_xft_picture_render( wxGlobalDisplay(), drawable, drawable, font, glyphs, x, y ); + Display* xdisplay = wxGlobalDisplay(); + int xscreen = DefaultScreen( xdisplay ); + Visual* xvisual = DefaultVisual( xdisplay, xscreen ); + + Colormap xcolormap = DefaultColormapOfScreen( XScreenOfDisplay( xdisplay, xscreen ) ); + + XftDraw *draw = XftDrawCreate( xdisplay, drawable, xvisual, xcolormap ); + XftColor color; + color.pixel = 0; + color.color.red = colour.Red() << 8; + color.color.green = colour.Green() << 8; + color.color.blue = colour.Blue() << 8; + color.color.alpha = 65000; + pango_xft_render( draw, &color, font, glyphs, x, y ); + + XftDrawDestroy( draw ); } else { @@ -77,9 +93,8 @@ x11_draw_layout_line_with_colors( Drawable drawable, GC gc, int x, int y, - PangoLayoutLine *line, - XColor *foreground, - XColor *background) + PangoLayoutLine *line, + wxColour &colour ) { PangoRectangle overall_rect; PangoRectangle logical_rect; @@ -131,7 +146,7 @@ x11_draw_layout_line_with_colors( Drawable drawable, int gx = x + x_off / PANGO_SCALE; int gy = risen_y; - x11_draw_glyphs( drawable, gc, run->item->analysis.font, gx, gy, run->glyphs); + x11_draw_glyphs( drawable, gc, run->item->analysis.font, gx, gy, run->glyphs, colour ); } if (uline == PANGO_UNDERLINE_SINGLE) @@ -153,8 +168,7 @@ x11_draw_layout_with_colors( Drawable drawable, int x, int y, PangoLayout *layout, - XColor *foreground, - XColor *background) + wxColour &colour ) { PangoLayoutIter *iter = pango_layout_get_iter (layout); @@ -171,8 +185,7 @@ x11_draw_layout_with_colors( Drawable drawable, x + logical_rect.x / PANGO_SCALE, y + baseline / PANGO_SCALE, line, - foreground, - background); + colour ); } while (pango_layout_iter_next_line (iter)); @@ -184,11 +197,12 @@ x11_draw_layout( Drawable drawable, GC gc, int x, int y, - PangoLayout *layout) + PangoLayout *layout, + wxColour &colour) { wxCHECK_RET( layout, wxT("No layout") ); - x11_draw_layout_with_colors (drawable, gc, x, y, layout, NULL, NULL); + x11_draw_layout_with_colors (drawable, gc, x, y, layout, colour ); } void