From 46eed000d666418b3ba5e98190056cc2e9be4c6a Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 6 Aug 2002 18:58:19 +0000 Subject: [PATCH] Further code for Pango fonts (work now) and some code for Pango prining. Doesn't work.. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16380 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/dcpsg.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++ src/gtk/dcclient.cpp | 1 + src/gtk/font.cpp | 21 +++++++++ src/gtk1/dcclient.cpp | 1 + src/gtk1/font.cpp | 21 +++++++++ 5 files changed, 150 insertions(+) diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 85774d8d32..c35da97387 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1168,10 +1168,115 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) } } +#ifdef __WXGTK20__ + +#include "wx/gtk/private.h" +#include "wx/fontutil.h" +#include "gtk/gtk.h" +#include + +#endif + void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); +#ifdef 0 + //__WXGTK20__ + + PangoContext *context = pango_ft2_get_context (150, 150); + + // What are these for? + pango_context_set_language (context, pango_language_from_string ("en_US")); + pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); + + // Set the font + pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description ); + + // Create layout + PangoLayout *layout = layout = pango_layout_new (context); +#if wxUSE_UNICODE + wxCharBuffer buffer = wxConvUTF8.cWC2MB( text ); +#else + wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ); +#endif + pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) ); + + // Find out extent for the bitmap + int height = 0; + int width = 0; + PangoRectangle logical_rect; + pango_layout_get_extents (layout, NULL, &logical_rect); + height = PANGO_PIXELS (logical_rect.height); + width = PANGO_PIXELS (logical_rect.width); + + // Allocate FreeType 2 bitmap + int byte_width = (width + 7)/8 * 8; + FT_Bitmap bitmap; + guchar *buf = (guchar*) g_malloc (byte_width * height); + memset (buf, 0x00, byte_width * height); + bitmap.rows = height; + bitmap.width = byte_width; + bitmap.pitch = byte_width; + bitmap.buffer = buf; + bitmap.num_grays = 256; + bitmap.pixel_mode = ft_pixel_mode_grays; + + // Render bitmap + pango_ft2_render_layout (&bitmap, layout, 0, 0); + + // Invert bitmap to get black text on white background + for (int pix_idx = 0; pix_idx < width * height; pix_idx++) + buf[pix_idx] = 255-buf[pix_idx]; + + // Write PS output + wxCoord xx = LogicalToDeviceX(x); + wxCoord yy = LogicalToDeviceY(y /*+ bitmap.GetHeight()*/ ); + + fprintf(m_pstream, "gsave\n"); + fprintf(m_pstream, "%d %d translate\n", xx, yy); + fprintf(m_pstream, "/img_width %d def\n", bitmap.width); + fprintf(m_pstream, "/img_height %d def\n", bitmap.rows); + fprintf(m_pstream, "/picstr img_width 8 idiv string def\n"); + + fprintf(m_pstream, + " img_width 72 150 div mul\n" + " img_height 72 150 div mul scale\n" + " 0 setgray\n" + " img_width img_height\n" + " true\n" + " [img_width 0 0 img_height neg 0 img_height 0.67 mul]\n" + " { currentfile\n" + " picstr readhexstring pop }\n" + " imagemask" + ); + + + for (int b_idx= 0; b_idx < bitmap.width/8 * bitmap.rows; b_idx++) + { + guchar packed_b = 0; + int bit_idx; + + if (b_idx % (bitmap.width/8) == 0) + fprintf(m_pstream, "\n"); + + for (bit_idx = 0; bit_idx < 8; bit_idx++) + { + guchar this_bit = bitmap.buffer[b_idx * 8+bit_idx]>128; + packed_b = (packed_b << 1) + this_bit; + } + + + fprintf(m_pstream, "%02x", packed_b); + } + + fprintf(m_pstream, "\ngrestore\n" ); + + + // Free memory + g_free( buf ); + +#else wxCoord text_w, text_h, text_descent; GetTextExtent(text, &text_w, &text_h, &text_descent); @@ -1276,6 +1381,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) CalcBoundingBox( x, y ); CalcBoundingBox( x + size * text.Length() * 2/3 , y ); +#endif } void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle ) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index eea9ffd7c3..00c939888e 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/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 diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 315cb82736..e8dbe802e5 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -178,6 +178,27 @@ void wxFontRefData::Init(int pointSize, m_underlined = underlined; m_encoding = encoding; + + + // Create native font info + m_nativeFontInfo.description = pango_font_description_new(); + + // And set its values + switch (m_family) + { + case wxFONTFAMILY_TELETYPE: + pango_font_description_set_family( m_nativeFontInfo.description, "monospaced" ); + break; + case wxFONTFAMILY_SWISS: + pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); + break; + default: + pango_font_description_set_family( m_nativeFontInfo.description, "sans" ); + break; + } + SetStyle( m_style ); + SetPointSize( m_pointSize ); + SetWeight( m_weight ); } wxFontRefData::wxFontRefData( const wxFontRefData& data ) diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index eea9ffd7c3..00c939888e 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 diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index 315cb82736..e8dbe802e5 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -178,6 +178,27 @@ void wxFontRefData::Init(int pointSize, m_underlined = underlined; m_encoding = encoding; + + + // Create native font info + m_nativeFontInfo.description = pango_font_description_new(); + + // And set its values + switch (m_family) + { + case wxFONTFAMILY_TELETYPE: + pango_font_description_set_family( m_nativeFontInfo.description, "monospaced" ); + break; + case wxFONTFAMILY_SWISS: + pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); + break; + default: + pango_font_description_set_family( m_nativeFontInfo.description, "sans" ); + break; + } + SetStyle( m_style ); + SetPointSize( m_pointSize ); + SetWeight( m_weight ); } wxFontRefData::wxFontRefData( const wxFontRefData& data ) -- 2.47.2