1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "gprint.h"
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/gtk/gnome/gprint.h"
23 #if wxUSE_LIBGNOMEPRINT
27 #include "wx/fontutil.h"
28 #include "wx/printdlg.h"
29 #include "wx/gtk/private.h"
30 #include "wx/module.h"
32 #include <libgnomeprint/gnome-print.h>
33 #include <libgnomeprint/gnome-print-pango.h>
34 #include <libgnomeprintui/gnome-print-dialog.h>
35 #include <libgnomeprintui/gnome-print-job-preview.h>
36 #include <libgnomeprintui/gnome-print-paper-selector.h>
38 //----------------------------------------------------------------------------
39 // wxGnomePrintNativeData
40 //----------------------------------------------------------------------------
42 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
44 wxGnomePrintNativeData::wxGnomePrintNativeData()
46 m_config
= gnome_print_config_default();
47 m_job
= gnome_print_job_new( m_config
);
50 wxGnomePrintNativeData::~wxGnomePrintNativeData()
52 g_object_unref (G_OBJECT (m_config
));
53 g_object_unref (G_OBJECT (m_job
));
56 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
62 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
68 //----------------------------------------------------------------------------
69 // wxGnomePrintFactory
70 //----------------------------------------------------------------------------
72 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
74 return new wxGnomePrinter( data
);
77 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
79 wxPrintDialogData
*data
)
81 return new wxPostScriptPrintPreview( preview
, printout
, data
);
84 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
88 return new wxPostScriptPrintPreview( preview
, printout
, data
);
91 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
92 wxPrintDialogData
*data
)
94 return new wxGnomePrintDialog( parent
, data
);
97 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
100 return new wxGnomePrintDialog( parent
, data
);
103 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
104 wxPageSetupDialogData
* data
)
106 return new wxGnomePageSetupDialog( parent
, data
);
109 bool wxGnomePrintFactory::HasPrintSetupDialog()
114 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
119 bool wxGnomePrintFactory::HasOwnPrintToFile()
124 bool wxGnomePrintFactory::HasPrinterLine()
129 wxString
wxGnomePrintFactory::CreatePrinterLine()
132 return wxEmptyString
;
135 bool wxGnomePrintFactory::HasStatusLine()
141 wxString
wxGnomePrintFactory::CreateStatusLine()
144 return wxEmptyString
;
147 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
149 return new wxGnomePrintNativeData
;
152 //----------------------------------------------------------------------------
153 // wxGnomePrintSetupDialog
154 //----------------------------------------------------------------------------
156 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
158 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
159 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
160 wxPoint(0, 0), wxSize(600, 600),
161 wxDEFAULT_DIALOG_STYLE
|
165 m_printDialogData
= *data
;
170 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
171 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
172 wxPoint(0, 0), wxSize(600, 600),
173 wxDEFAULT_DIALOG_STYLE
|
177 m_printDialogData
= *data
;
182 void wxGnomePrintDialog::Init()
184 wxPrintData data
= m_printDialogData
.GetPrintData();
186 wxGnomePrintNativeData
*native
=
187 (wxGnomePrintNativeData
*) data
.GetNativeData();
189 m_widget
= gnome_print_dialog_new( native
->GetPrintJob(),
191 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
194 if (m_printDialogData
.GetEnableSelection())
195 flag
|= GNOME_PRINT_RANGE_SELECTION
;
196 if (m_printDialogData
.GetEnablePageNumbers())
197 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
199 gnome_print_dialog_construct_range_page( GNOME_PRINT_DIALOG( m_widget
),
201 m_printDialogData
.GetMinPage(),
202 m_printDialogData
.GetMaxPage(),
207 wxGnomePrintDialog::~wxGnomePrintDialog()
212 int wxGnomePrintDialog::ShowModal()
214 // Transfer data from m_printDalogData to dialog here
216 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
218 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
220 gtk_widget_destroy(m_widget
);
227 gboolean collate
= false;
228 gnome_print_dialog_get_copies( GNOME_PRINT_DIALOG(m_widget
), &copies
, &collate
);
229 m_printDialogData
.SetNoCopies( copies
);
230 m_printDialogData
.SetCollate( collate
);
232 switch (gnome_print_dialog_get_range( GNOME_PRINT_DIALOG(m_widget
) ))
234 case GNOME_PRINT_RANGE_SELECTION
:
235 m_printDialogData
.SetSelection( true );
237 case GNOME_PRINT_RANGE_ALL
:
238 m_printDialogData
.SetAllPages( true );
239 m_printDialogData
.SetFromPage( 0 );
240 m_printDialogData
.SetToPage( 9999 );
242 case GNOME_PRINT_RANGE_RANGE
:
245 gnome_print_dialog_get_range_page( GNOME_PRINT_DIALOG(m_widget
), &start
, &end
);
246 m_printDialogData
.SetFromPage( start
);
247 m_printDialogData
.SetToPage( end
);
251 gtk_widget_destroy(m_widget
);
254 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
260 wxDC
*wxGnomePrintDialog::GetPrintDC()
266 bool wxGnomePrintDialog::Validate()
271 bool wxGnomePrintDialog::TransferDataToWindow()
276 bool wxGnomePrintDialog::TransferDataFromWindow()
281 //----------------------------------------------------------------------------
282 // wxGnomePageSetupDialog
283 //----------------------------------------------------------------------------
285 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
287 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
288 wxPageSetupDialogData
* data
)
291 m_pageDialogData
= *data
;
293 wxGnomePrintNativeData
*native
=
294 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
296 m_widget
= gtk_dialog_new();
298 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
300 GtkWidget
*main
= gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
301 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
302 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
303 gtk_widget_show (main
);
305 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
307 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
309 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
310 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
311 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
314 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
318 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
322 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
324 return m_pageDialogData
;
327 int wxGnomePageSetupDialog::ShowModal()
329 // Transfer data from m_pageDialogData to native dialog
331 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
333 if (ret
== GTK_RESPONSE_OK
)
335 // Transfer data back to m_pageDialogData
344 gtk_widget_destroy( m_widget
);
350 bool wxGnomePageSetupDialog::Validate()
355 bool wxGnomePageSetupDialog::TransferDataToWindow()
360 bool wxGnomePageSetupDialog::TransferDataFromWindow()
365 //----------------------------------------------------------------------------
367 //----------------------------------------------------------------------------
369 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
371 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
372 wxPrinterBase( data
)
375 m_native_preview
= false;
378 wxGnomePrinter::~wxGnomePrinter()
382 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
386 sm_lastError
= wxPRINTER_ERROR
;
390 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
391 wxGnomePrintNativeData
*data
=
392 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
394 // The GnomePrintJob is temporarily stored in the
395 // native print data as the native print dialog
396 // needs to access it.
397 GnomePrintJob
*job
= data
->GetPrintJob();
398 m_gpc
= gnome_print_job_get_context (job
);
400 printout
->SetIsPreview(false);
402 if (m_printDialogData
.GetMinPage() < 1)
403 m_printDialogData
.SetMinPage(1);
404 if (m_printDialogData
.GetMaxPage() < 1)
405 m_printDialogData
.SetMaxPage(9999);
409 dc
= PrintDialog( parent
);
411 dc
= new wxGnomePrintDC( this );
413 if (m_native_preview
)
414 printout
->SetIsPreview(true);
418 gnome_print_job_close( job
);
419 sm_lastError
= wxPRINTER_ERROR
;
423 wxSize ScreenPixels
= wxGetDisplaySize();
424 wxSize ScreenMM
= wxGetDisplaySizeMM();
426 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
427 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
428 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
429 wxGnomePrintDC::GetResolution() );
435 printout
->SetPageSizePixels((int)w
, (int)h
);
436 dc
->GetSizeMM(&w
, &h
);
437 printout
->SetPageSizeMM((int)w
, (int)h
);
439 printout
->OnPreparePrinting();
441 // Get some parameters from the printout, if defined
442 int fromPage
, toPage
;
443 int minPage
, maxPage
;
444 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
448 sm_lastError
= wxPRINTER_ERROR
;
452 printout
->OnBeginPrinting();
454 int minPageNum
= minPage
, maxPageNum
= maxPage
;
456 if ( !m_printDialogData
.GetAllPages() )
458 minPageNum
= m_printDialogData
.GetFromPage();
459 maxPageNum
= m_printDialogData
.GetToPage();
465 copyCount
<= m_printDialogData
.GetNoCopies();
468 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
470 wxLogError(_("Could not start printing."));
471 sm_lastError
= wxPRINTER_ERROR
;
476 for ( pn
= minPageNum
;
477 pn
<= maxPageNum
&& printout
->HasPage(pn
);
481 printout
->OnPrintPage(pn
);
485 printout
->OnEndDocument();
486 printout
->OnEndPrinting();
489 gnome_print_job_close( job
);
490 if (m_native_preview
)
492 wxString
title( _("Print preview") );
493 gtk_widget_show( gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
497 gnome_print_job_print( job
);
502 return (sm_lastError
== wxPRINTER_NO_ERROR
);
505 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
507 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
508 int ret
= dialog
.ShowModal();
509 if (ret
== wxID_CANCEL
)
511 sm_lastError
= wxPRINTER_ERROR
;
515 m_native_preview
= ret
== wxID_PREVIEW
;
517 m_printDialogData
= dialog
.GetPrintDialogData();
518 return new wxGnomePrintDC( this );
521 bool wxGnomePrinter::Setup( wxWindow
*parent
)
526 //-----------------------------------------------------------------------------
528 //-----------------------------------------------------------------------------
530 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
532 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
536 m_gpc
= printer
->GetPrintContext();
538 m_layout
= gnome_print_pango_create_layout( m_gpc
);
539 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
545 m_signX
= 1; // default x-axis left to right
546 m_signY
= -1; // default y-axis bottom up -> top down
549 wxGnomePrintDC::~wxGnomePrintDC()
553 bool wxGnomePrintDC::Ok() const
558 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
563 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
568 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
570 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
574 gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
575 gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
576 gnome_print_stroke ( m_gpc
);
578 CalcBoundingBox( x1
, y1
);
579 CalcBoundingBox( x2
, y2
);
582 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
586 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
590 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
594 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
598 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
602 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
606 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
610 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
612 if (m_brush
.GetStyle () != wxTRANSPARENT
)
616 gnome_print_newpath( m_gpc
);
617 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
618 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
619 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
620 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
621 gnome_print_closepath( m_gpc
);
622 gnome_print_fill( m_gpc
);
624 CalcBoundingBox( x
, y
);
625 CalcBoundingBox( x
+ width
, y
+ height
);
628 if (m_pen
.GetStyle () != wxTRANSPARENT
)
632 gnome_print_newpath( m_gpc
);
633 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
634 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
635 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
636 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
637 gnome_print_closepath( m_gpc
);
638 gnome_print_stroke( m_gpc
);
640 CalcBoundingBox( x
, y
);
641 CalcBoundingBox( x
+ width
, y
+ height
);
645 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
649 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
653 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
657 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
658 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
659 wxCoord xsrcMask
, wxCoord ysrcMask
)
664 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
666 DoDrawBitmap( icon
, x
, y
, true );
669 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
671 if (!bitmap
.Ok()) return;
673 if (bitmap
.HasPixbuf())
675 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
676 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
677 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
678 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
679 int height
= gdk_pixbuf_get_height( pixbuf
);
680 int width
= gdk_pixbuf_get_width( pixbuf
);
682 gnome_print_gsave( m_gpc
);
684 matrix
[0] = XLOG2DEVREL(width
);
687 matrix
[3] = YLOG2DEVREL(height
);
688 matrix
[4] = XLOG2DEV(x
);
689 matrix
[5] = YLOG2DEV(y
+height
);
690 gnome_print_concat( m_gpc
, matrix
);
691 gnome_print_moveto( m_gpc
, 0, 0 );
693 gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
695 gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
696 gnome_print_grestore( m_gpc
);
700 wxImage image
= bitmap
.ConvertToImage();
702 if (!image
.Ok()) return;
704 gnome_print_gsave( m_gpc
);
706 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
709 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
710 matrix
[4] = XLOG2DEV(x
);
711 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
712 gnome_print_concat( m_gpc
, matrix
);
713 gnome_print_moveto( m_gpc
, 0, 0 );
714 gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
715 gnome_print_grestore( m_gpc
);
719 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
721 DoDrawRotatedText( text
, x
, y
, 0.0 );
724 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
729 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
732 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
734 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
737 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
740 size_t datalen
= strlen((const char*)data
);
741 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
745 PangoAttrList
*attrs
= pango_attr_list_new();
746 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
748 a
->end_index
= datalen
;
749 pango_attr_list_insert(attrs
, a
);
750 pango_layout_set_attributes(m_layout
, attrs
);
751 pango_attr_list_unref(attrs
);
754 if (m_textForegroundColour
.Ok())
756 unsigned char red
= m_textForegroundColour
.Red();
757 unsigned char blue
= m_textForegroundColour
.Blue();
758 unsigned char green
= m_textForegroundColour
.Green();
760 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
762 double redPS
= (double)(red
) / 255.0;
763 double bluePS
= (double)(blue
) / 255.0;
764 double greenPS
= (double)(green
) / 255.0;
766 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
769 m_currentBlue
= blue
;
770 m_currentGreen
= green
;
776 if (fabs(m_scaleY
- 1.0) > 0.00001)
778 // If there is a user or actually any scale applied to
779 // the device context, scale the font.
781 // scale font description
782 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
783 double size
= oldSize
;
784 size
= size
* m_scaleY
;
785 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
787 // actually apply scaled font
788 pango_layout_set_font_description( m_layout
, m_fontdesc
);
790 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
792 if ( m_backgroundMode
== wxSOLID
)
794 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
795 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
796 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
800 gnome_print_moveto (m_gpc
, x
, y
);
801 if (fabs(angle
) > 0.00001)
803 gnome_print_gsave( m_gpc
);
804 gnome_print_rotate( m_gpc
, angle
);
805 gnome_print_pango_layout( m_gpc
, m_layout
);
806 gnome_print_grestore( m_gpc
);
810 gnome_print_pango_layout( m_gpc
, m_layout
);
813 // reset unscaled size
814 pango_font_description_set_size( m_fontdesc
, oldSize
);
816 // actually apply unscaled font
817 pango_layout_set_font_description( m_layout
, m_fontdesc
);
821 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
823 if ( m_backgroundMode
== wxSOLID
)
825 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
826 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
827 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
831 gnome_print_moveto (m_gpc
, x
, y
);
832 if (fabs(angle
) > 0.00001)
834 gnome_print_gsave( m_gpc
);
835 gnome_print_rotate( m_gpc
, angle
);
836 gnome_print_pango_layout( m_gpc
, m_layout
);
837 gnome_print_grestore( m_gpc
);
841 gnome_print_pango_layout( m_gpc
, m_layout
);
847 // undo underline attributes setting:
848 pango_layout_set_attributes(m_layout
, NULL
);
851 CalcBoundingBox (x
+ w
, y
+ h
);
854 void wxGnomePrintDC::Clear()
858 void wxGnomePrintDC::SetFont( const wxFont
& font
)
865 pango_font_description_free( m_fontdesc
);
867 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
869 pango_layout_set_font_description( m_layout
, m_fontdesc
);
873 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
875 if (!pen
.Ok()) return;
877 // TODO: support for pen styles other than solid (use gnome_print_setdash)
881 gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
883 unsigned char red
= m_pen
.GetColour().Red();
884 unsigned char blue
= m_pen
.GetColour().Blue();
885 unsigned char green
= m_pen
.GetColour().Green();
887 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
889 double redPS
= (double)(red
) / 255.0;
890 double bluePS
= (double)(blue
) / 255.0;
891 double greenPS
= (double)(green
) / 255.0;
893 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
896 m_currentBlue
= blue
;
897 m_currentGreen
= green
;
901 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
903 if (!brush
.Ok()) return;
908 unsigned char red
= m_brush
.GetColour().Red();
909 unsigned char blue
= m_brush
.GetColour().Blue();
910 unsigned char green
= m_brush
.GetColour().Green();
914 // Anything not white is black
915 if (! (red
== (unsigned char) 255 &&
916 blue
== (unsigned char) 255 &&
917 green
== (unsigned char) 255) )
919 red
= (unsigned char) 0;
920 green
= (unsigned char) 0;
921 blue
= (unsigned char) 0;
926 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
928 double redPS
= (double)(red
) / 255.0;
929 double bluePS
= (double)(blue
) / 255.0;
930 double greenPS
= (double)(green
) / 255.0;
932 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
935 m_currentBlue
= blue
;
936 m_currentGreen
= green
;
940 void wxGnomePrintDC::SetLogicalFunction( int function
)
944 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
948 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
952 void wxGnomePrintDC::DestroyClippingRegion()
956 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
958 SetDeviceOrigin( 0,0 );
963 void wxGnomePrintDC::EndDoc()
967 void wxGnomePrintDC::StartPage()
969 gnome_print_beginpage( m_gpc
, (const guchar
*) "1" );
972 void wxGnomePrintDC::EndPage()
974 gnome_print_showpage( m_gpc
);
977 wxCoord
wxGnomePrintDC::GetCharHeight() const
979 pango_layout_set_text( m_layout
, "H", 1 );
982 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
987 wxCoord
wxGnomePrintDC::GetCharWidth() const
989 pango_layout_set_text( m_layout
, "H", 1 );
992 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
997 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
999 wxCoord
*externalLeading
,
1000 wxFont
*theFont
) const
1008 if ( externalLeading
)
1009 *externalLeading
= 0;
1011 if (string
.IsEmpty())
1016 // Set new font description
1018 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1020 // Set layout's text
1022 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1023 const char *dataUTF8
= (const char *)data
;
1025 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1028 if (width
) (*width
) = 0;
1029 if (height
) (*height
) = 0;
1032 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1033 const char *dataUTF8
= (const char *)data
;
1038 // hardly ideal, but what else can we do if conversion failed?
1042 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1045 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1048 *width
= (wxCoord
) w
;
1050 *height
= (wxCoord
) h
;
1053 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1054 int baseline
= pango_layout_iter_get_baseline(iter
);
1055 pango_layout_iter_free(iter
);
1056 *descent
= h
- PANGO_PIXELS(baseline
);
1059 // Reset old font description
1061 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1064 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1066 // No idea if that is efficient
1067 GnomePrintConfig
*config
= gnome_print_config_default();
1070 bool result
= gnome_print_config_get_page_size( config
, &w
, &h
);
1074 // Standard PS resolution DIN A4 size.
1085 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1089 /// Later, for now DIN A4
1099 wxSize
wxGnomePrintDC::GetPPI() const
1101 return wxSize(72,72);
1104 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1106 m_signX
= (xLeftRight
? 1 : -1);
1107 m_signY
= (yBottomUp
? 1 : -1);
1109 ComputeScaleAndOrigin();
1112 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1118 wxDC::SetDeviceOrigin( x
, h
-y
);
1121 void wxGnomePrintDC::SetResolution(int ppi
)
1125 int wxGnomePrintDC::GetResolution()
1131 class wxGnomePrintModule
: public wxModule
1134 wxGnomePrintModule() {}
1135 bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
); return true; }
1139 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1142 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1145 // wxUSE_LIBGNOMEPRINT