]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dcpsg.cpp
removed src/gtk/eggtrayicon.h
[wxWidgets.git] / src / generic / dcpsg.cpp
index 8f7d2b07de9c1c6aac35ca7e8a707bb9bc6c5beb..2e423e5501557b4f70021b7828eb9b72b01325e3 100644 (file)
@@ -36,6 +36,7 @@
 #include "wx/log.h"
 #include "wx/generic/dcpsg.h"
 #include "wx/prntbase.h"
+#include "wx/generic/prntdlgg.h"
 #include "wx/paper.h"
 #include "wx/filefn.h"
 #if WXWIN_COMPATIBILITY_2_2
@@ -1285,6 +1286,25 @@ void draw_bezier_outline(wxPostScriptDC* caller,
 
 #endif
 
+
+#if wxUSE_PANGO
+static void InitializePangoContext(PangoContext *context)
+{
+#ifdef __WXGTK__
+    pango_context_set_base_dir(context,
+                               gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR ?
+                    PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
+    pango_context_set_language(context, gtk_get_default_language());
+#else
+    // FIXME: assuming LTR is incorrect!
+    pango_context_set_base_dir(context, PANGO_DIRECTION_LTR);
+    wxString lang = wxGetLocale()->GetCanonicalName();
+    pango_context_set_language(context,
+                               pango_language_from_string(lang.ToAscii()));
+#endif
+}
+#endif
+
 void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
 {
     wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
@@ -1333,13 +1353,12 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
     int ps_dpi = 72;
     int pango_dpi = 600;
     PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
+    
+    InitializePangoContext(context);
 
     double scale = (double)pango_dpi / (double)ps_dpi;
     scale /= m_userScaleY;
 
-    pango_context_set_language (context, pango_language_from_string ("en_US"));
-    pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
-
     pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description );
 
     PangoLayout *layout = pango_layout_new (context);
@@ -1781,8 +1800,8 @@ wxSize wxPostScriptDC::GetPPI(void) const
 bool wxPostScriptDC::StartDoc( const wxString& message )
 {
     wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
-
-    if ( m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
+    
+    if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
     {
         if (m_printData.GetFilename() == wxEmptyString)
         {
@@ -1945,13 +1964,16 @@ void wxPostScriptDC::EndDoc ()
     PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
 #endif
 
-#if defined(__X__) || defined(__WXGTK__)
+#ifndef __WXMSW__
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
     if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
     {
         wxString command;
-        command += m_printData.GetPrinterCommand();
+        command += data->GetPrinterCommand();
         command += wxT(" ");
-        command += m_printData.GetPrinterOptions();
+        command += data->GetPrinterOptions();
         command += wxT(" ");
         command += m_printData.GetFilename();
 
@@ -1980,11 +2002,14 @@ void wxPostScriptDC::StartPage()
     wxCoord translate_x, translate_y;
     double scale_x, scale_y;
 
-    translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
-    translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    translate_x = (wxCoord)data->GetPrinterTranslateX();
+    translate_y = (wxCoord)data->GetPrinterTranslateY();
 
-    scale_x = m_printData.GetPrinterScaleX();
-    scale_y = m_printData.GetPrinterScaleY();
+    scale_x = data->GetPrinterScaleX();
+    scale_y = data->GetPrinterScaleY();
 
     if (m_printData.GetOrientation() == wxLANDSCAPE)
     {
@@ -2069,12 +2094,11 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
     int pango_dpi = 600;
     PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
 
+    InitializePangoContext(context);
+
     double scale = pango_dpi / wx_dpi;
     scale /= m_userScaleY;
 
-    pango_context_set_language (context, pango_language_from_string ("en_US"));
-    pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
-
     PangoLayout *layout = pango_layout_new (context);
 
     PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description;
@@ -2086,17 +2110,18 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
     const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
 #endif
     pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
-    PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
 
     PangoRectangle rect;
-    pango_layout_line_get_extents(line, NULL, &rect);
+    pango_layout_get_extents(layout, NULL, &rect);
 
-    if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale );
-    if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale );
+    if (x) (*x) = (wxCoord) ( PANGO_PIXELS(rect.width) / scale );
+    if (y) (*y) = (wxCoord) ( PANGO_PIXELS(rect.height) / scale );
     if (descent)
     {
-        // Do something about metrics here
-        (*descent) = 0;
+        PangoLayoutIter *iter = pango_layout_get_iter(layout);
+        int baseline = pango_layout_iter_get_baseline(iter);
+        pango_layout_iter_free(iter);
+        *descent = wxCoord(*y - PANGO_PIXELS(baseline) / scale);
     }
     if (externalLeading) (*externalLeading) = 0;  // ??
 
@@ -2227,11 +2252,14 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
 
         FILE *afmFile = NULL;
 
+        wxPostScriptPrintNativeData *data = 
+            (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+            
         // Get the directory of the AFM files
         wxString afmName;
-        if (!m_printData.GetFontMetricPath().IsEmpty())
+        if (!data->GetFontMetricPath().IsEmpty())
         {
-            afmName = m_printData.GetFontMetricPath();
+            afmName = data->GetFontMetricPath();
             afmName << wxFILE_SEP_PATH << name;
             afmFile = wxFopen(afmName,wxT("r"));
         }
@@ -2447,13 +2475,16 @@ void wxPostScriptDC::PsPrintf( const wxChar* fmt, ... )
 
 void wxPostScriptDC::PsPrint( const char* psdata )
 {
-    switch( m_printData.GetPrintMode() )
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+        
+    switch (m_printData.GetPrintMode())
     {
 #if wxUSE_STREAMS
         // append to output stream
         case wxPRINT_MODE_STREAM:
             {
-                wxOutputStream* outputstream = m_printData.GetOutputStream();
+                wxOutputStream* outputstream = data->GetOutputStream();
                 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
                 outputstream->Write( psdata, strlen( psdata ) );
             }
@@ -2469,13 +2500,16 @@ void wxPostScriptDC::PsPrint( const char* psdata )
 
 void wxPostScriptDC::PsPrint( int ch )
 {
-    switch( m_printData.GetPrintMode() )
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+        
+    switch (m_printData.GetPrintMode())
     {
 #if wxUSE_STREAMS
         // append to output stream
         case wxPRINT_MODE_STREAM:
             {
-                wxOutputStream* outputstream = m_printData.GetOutputStream();
+                wxOutputStream* outputstream = data->GetOutputStream();
                 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
                 outputstream->PutC( ch );
             }