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"
31 #include "wx/generic/prntdlgg.h"
33 #include <libgnomeprint/gnome-print.h>
34 #include <libgnomeprint/gnome-print-pango.h>
35 #include <libgnomeprint/gnome-print-config.h>
36 #include <libgnomeprintui/gnome-print-dialog.h>
37 #include <libgnomeprintui/gnome-print-job-preview.h>
38 #include <libgnomeprintui/gnome-print-paper-selector.h>
40 //----------------------------------------------------------------------------
41 // wxGnomePrintNativeData
42 //----------------------------------------------------------------------------
44 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
46 wxGnomePrintNativeData::wxGnomePrintNativeData()
48 m_config
= gnome_print_config_default();
49 m_job
= gnome_print_job_new( m_config
);
52 wxGnomePrintNativeData::~wxGnomePrintNativeData()
54 g_object_unref (G_OBJECT (m_config
));
55 g_object_unref (G_OBJECT (m_job
));
58 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
64 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
70 //----------------------------------------------------------------------------
71 // wxGnomePrintFactory
72 //----------------------------------------------------------------------------
74 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
76 return new wxGnomePrinter( data
);
79 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
81 wxPrintDialogData
*data
)
83 return new wxPostScriptPrintPreview( preview
, printout
, data
);
86 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
90 return new wxPostScriptPrintPreview( preview
, printout
, data
);
93 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
94 wxPrintDialogData
*data
)
96 return new wxGnomePrintDialog( parent
, data
);
99 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
102 return new wxGnomePrintDialog( parent
, data
);
105 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
106 wxPageSetupDialogData
* data
)
108 // The native page setup dialog is broken. It
109 // miscalculates newly entered values for the
110 // margins if you have not chose "points" but
113 // return new wxGnomePageSetupDialog( parent, data );
115 return new wxGenericPageSetupDialog( parent
, data
);
118 bool wxGnomePrintFactory::HasPrintSetupDialog()
123 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
128 bool wxGnomePrintFactory::HasOwnPrintToFile()
133 bool wxGnomePrintFactory::HasPrinterLine()
138 wxString
wxGnomePrintFactory::CreatePrinterLine()
141 return wxEmptyString
;
144 bool wxGnomePrintFactory::HasStatusLine()
150 wxString
wxGnomePrintFactory::CreateStatusLine()
153 return wxEmptyString
;
156 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
158 return new wxGnomePrintNativeData
;
161 //----------------------------------------------------------------------------
162 // wxGnomePrintSetupDialog
163 //----------------------------------------------------------------------------
165 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
167 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
168 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
169 wxPoint(0, 0), wxSize(600, 600),
170 wxDEFAULT_DIALOG_STYLE
|
174 m_printDialogData
= *data
;
179 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
180 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
181 wxPoint(0, 0), wxSize(600, 600),
182 wxDEFAULT_DIALOG_STYLE
|
186 m_printDialogData
= *data
;
191 void wxGnomePrintDialog::Init()
193 wxPrintData data
= m_printDialogData
.GetPrintData();
195 wxGnomePrintNativeData
*native
=
196 (wxGnomePrintNativeData
*) data
.GetNativeData();
198 m_widget
= gnome_print_dialog_new( native
->GetPrintJob(),
200 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
203 if (m_printDialogData
.GetEnableSelection())
204 flag
|= GNOME_PRINT_RANGE_SELECTION
;
205 if (m_printDialogData
.GetEnablePageNumbers())
206 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
208 gnome_print_dialog_construct_range_page( GNOME_PRINT_DIALOG( m_widget
),
210 m_printDialogData
.GetMinPage(),
211 m_printDialogData
.GetMaxPage(),
216 wxGnomePrintDialog::~wxGnomePrintDialog()
221 int wxGnomePrintDialog::ShowModal()
223 // Transfer data from m_printDalogData to dialog here
225 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
227 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
229 gtk_widget_destroy(m_widget
);
236 gboolean collate
= false;
237 gnome_print_dialog_get_copies( GNOME_PRINT_DIALOG(m_widget
), &copies
, &collate
);
238 m_printDialogData
.SetNoCopies( copies
);
239 m_printDialogData
.SetCollate( collate
);
241 switch (gnome_print_dialog_get_range( GNOME_PRINT_DIALOG(m_widget
) ))
243 case GNOME_PRINT_RANGE_SELECTION
:
244 m_printDialogData
.SetSelection( true );
246 case GNOME_PRINT_RANGE_ALL
:
247 m_printDialogData
.SetAllPages( true );
248 m_printDialogData
.SetFromPage( 0 );
249 m_printDialogData
.SetToPage( 9999 );
251 case GNOME_PRINT_RANGE_RANGE
:
254 gnome_print_dialog_get_range_page( GNOME_PRINT_DIALOG(m_widget
), &start
, &end
);
255 m_printDialogData
.SetFromPage( start
);
256 m_printDialogData
.SetToPage( end
);
260 gtk_widget_destroy(m_widget
);
263 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
269 wxDC
*wxGnomePrintDialog::GetPrintDC()
275 bool wxGnomePrintDialog::Validate()
280 bool wxGnomePrintDialog::TransferDataToWindow()
285 bool wxGnomePrintDialog::TransferDataFromWindow()
290 //----------------------------------------------------------------------------
291 // wxGnomePageSetupDialog
292 //----------------------------------------------------------------------------
294 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
296 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
297 wxPageSetupDialogData
* data
)
300 m_pageDialogData
= *data
;
302 wxGnomePrintNativeData
*native
=
303 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
305 m_widget
= gtk_dialog_new();
307 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
309 GtkWidget
*main
= gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
310 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
311 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
312 gtk_widget_show (main
);
314 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
316 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
318 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
319 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
320 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
323 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
327 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
331 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
333 return m_pageDialogData
;
336 int wxGnomePageSetupDialog::ShowModal()
338 wxGnomePrintNativeData
*native
=
339 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
340 GnomePrintConfig
*config
= native
->GetPrintConfig();
342 // Transfer data from m_pageDialogData to native dialog
344 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
346 if (ret
== GTK_RESPONSE_OK
)
348 // Transfer data back to m_pageDialogData
350 const GnomePrintUnit
*margin_unit
;
351 const GnomePrintUnit
*paper_unit
;
352 const GnomePrintUnit
*mm_unit
= gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
354 double ml
,mr
,mt
,mb
,pw
,ph
;
355 gnome_print_config_get_length (config
,
356 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
357 gnome_print_config_get_length (config
,
358 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
359 gnome_print_config_get_length (config
,
360 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
361 gnome_print_config_get_length (config
,
362 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
363 gnome_print_config_get_length (config
,
364 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
365 gnome_print_config_get_length (config
,
366 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
368 gnome_print_convert_distance( &ml
, margin_unit
, mm_unit
);
369 gnome_print_convert_distance( &mr
, margin_unit
, mm_unit
);
370 gnome_print_convert_distance( &mt
, margin_unit
, mm_unit
);
371 gnome_print_convert_distance( &mb
, margin_unit
, mm_unit
);
372 gnome_print_convert_distance( &pw
, paper_unit
, mm_unit
);
373 gnome_print_convert_distance( &ph
, paper_unit
, mm_unit
);
375 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
*72.0/25.4+0.5), (int)(mt
+0.5)) );
376 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
378 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
380 wxPrintf( wxT("paper %d %d, top margin %d\n"),
381 m_pageDialogData
.GetPaperSize().x
,
382 m_pageDialogData
.GetPaperSize().y
,
383 m_pageDialogData
.GetMarginTopLeft().x
);
393 gtk_widget_destroy( m_widget
);
399 bool wxGnomePageSetupDialog::Validate()
404 bool wxGnomePageSetupDialog::TransferDataToWindow()
409 bool wxGnomePageSetupDialog::TransferDataFromWindow()
414 //----------------------------------------------------------------------------
416 //----------------------------------------------------------------------------
418 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
420 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
421 wxPrinterBase( data
)
424 m_native_preview
= false;
427 wxGnomePrinter::~wxGnomePrinter()
431 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
435 sm_lastError
= wxPRINTER_ERROR
;
439 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
440 wxGnomePrintNativeData
*data
=
441 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
443 // The GnomePrintJob is temporarily stored in the
444 // native print data as the native print dialog
445 // needs to access it.
446 GnomePrintJob
*job
= data
->GetPrintJob();
447 m_gpc
= gnome_print_job_get_context (job
);
449 printout
->SetIsPreview(false);
451 if (m_printDialogData
.GetMinPage() < 1)
452 m_printDialogData
.SetMinPage(1);
453 if (m_printDialogData
.GetMaxPage() < 1)
454 m_printDialogData
.SetMaxPage(9999);
458 dc
= PrintDialog( parent
);
460 dc
= new wxGnomePrintDC( this );
462 if (m_native_preview
)
463 printout
->SetIsPreview(true);
467 gnome_print_job_close( job
);
468 sm_lastError
= wxPRINTER_ERROR
;
472 wxSize ScreenPixels
= wxGetDisplaySize();
473 wxSize ScreenMM
= wxGetDisplaySizeMM();
475 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
476 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
477 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
478 wxGnomePrintDC::GetResolution() );
484 printout
->SetPageSizePixels((int)w
, (int)h
);
485 dc
->GetSizeMM(&w
, &h
);
486 printout
->SetPageSizeMM((int)w
, (int)h
);
488 printout
->OnPreparePrinting();
490 // Get some parameters from the printout, if defined
491 int fromPage
, toPage
;
492 int minPage
, maxPage
;
493 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
497 sm_lastError
= wxPRINTER_ERROR
;
501 printout
->OnBeginPrinting();
503 int minPageNum
= minPage
, maxPageNum
= maxPage
;
505 if ( !m_printDialogData
.GetAllPages() )
507 minPageNum
= m_printDialogData
.GetFromPage();
508 maxPageNum
= m_printDialogData
.GetToPage();
514 copyCount
<= m_printDialogData
.GetNoCopies();
517 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
519 wxLogError(_("Could not start printing."));
520 sm_lastError
= wxPRINTER_ERROR
;
525 for ( pn
= minPageNum
;
526 pn
<= maxPageNum
&& printout
->HasPage(pn
);
530 printout
->OnPrintPage(pn
);
534 printout
->OnEndDocument();
535 printout
->OnEndPrinting();
538 gnome_print_job_close( job
);
539 if (m_native_preview
)
541 wxString
title( _("Print preview") );
542 gtk_widget_show( gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
546 gnome_print_job_print( job
);
551 return (sm_lastError
== wxPRINTER_NO_ERROR
);
554 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
556 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
557 int ret
= dialog
.ShowModal();
558 if (ret
== wxID_CANCEL
)
560 sm_lastError
= wxPRINTER_ERROR
;
564 m_native_preview
= ret
== wxID_PREVIEW
;
566 m_printDialogData
= dialog
.GetPrintDialogData();
567 return new wxGnomePrintDC( this );
570 bool wxGnomePrinter::Setup( wxWindow
*parent
)
575 //-----------------------------------------------------------------------------
577 //-----------------------------------------------------------------------------
579 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
581 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
585 m_gpc
= printer
->GetPrintContext();
587 m_layout
= gnome_print_pango_create_layout( m_gpc
);
588 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
594 m_signX
= 1; // default x-axis left to right
595 m_signY
= -1; // default y-axis bottom up -> top down
598 wxGnomePrintDC::~wxGnomePrintDC()
602 bool wxGnomePrintDC::Ok() const
607 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
612 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
617 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
619 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
623 gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
624 gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
625 gnome_print_stroke ( m_gpc
);
627 CalcBoundingBox( x1
, y1
);
628 CalcBoundingBox( x2
, y2
);
631 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
635 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
639 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
643 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
647 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
651 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
655 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
659 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
661 if (m_brush
.GetStyle () != wxTRANSPARENT
)
665 gnome_print_newpath( m_gpc
);
666 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
667 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
668 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
669 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
670 gnome_print_closepath( m_gpc
);
671 gnome_print_fill( m_gpc
);
673 CalcBoundingBox( x
, y
);
674 CalcBoundingBox( x
+ width
, y
+ height
);
677 if (m_pen
.GetStyle () != wxTRANSPARENT
)
681 gnome_print_newpath( m_gpc
);
682 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
683 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
684 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
685 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
686 gnome_print_closepath( m_gpc
);
687 gnome_print_stroke( m_gpc
);
689 CalcBoundingBox( x
, y
);
690 CalcBoundingBox( x
+ width
, y
+ height
);
694 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
698 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
702 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
706 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
707 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
708 wxCoord xsrcMask
, wxCoord ysrcMask
)
713 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
715 DoDrawBitmap( icon
, x
, y
, true );
718 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
720 if (!bitmap
.Ok()) return;
722 if (bitmap
.HasPixbuf())
724 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
725 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
726 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
727 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
728 int height
= gdk_pixbuf_get_height( pixbuf
);
729 int width
= gdk_pixbuf_get_width( pixbuf
);
731 gnome_print_gsave( m_gpc
);
733 matrix
[0] = XLOG2DEVREL(width
);
736 matrix
[3] = YLOG2DEVREL(height
);
737 matrix
[4] = XLOG2DEV(x
);
738 matrix
[5] = YLOG2DEV(y
+height
);
739 gnome_print_concat( m_gpc
, matrix
);
740 gnome_print_moveto( m_gpc
, 0, 0 );
742 gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
744 gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
745 gnome_print_grestore( m_gpc
);
749 wxImage image
= bitmap
.ConvertToImage();
751 if (!image
.Ok()) return;
753 gnome_print_gsave( m_gpc
);
755 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
758 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
759 matrix
[4] = XLOG2DEV(x
);
760 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
761 gnome_print_concat( m_gpc
, matrix
);
762 gnome_print_moveto( m_gpc
, 0, 0 );
763 gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
764 gnome_print_grestore( m_gpc
);
768 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
770 DoDrawRotatedText( text
, x
, y
, 0.0 );
773 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
778 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
781 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
783 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
786 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
789 size_t datalen
= strlen((const char*)data
);
790 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
794 PangoAttrList
*attrs
= pango_attr_list_new();
795 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
797 a
->end_index
= datalen
;
798 pango_attr_list_insert(attrs
, a
);
799 pango_layout_set_attributes(m_layout
, attrs
);
800 pango_attr_list_unref(attrs
);
803 if (m_textForegroundColour
.Ok())
805 unsigned char red
= m_textForegroundColour
.Red();
806 unsigned char blue
= m_textForegroundColour
.Blue();
807 unsigned char green
= m_textForegroundColour
.Green();
809 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
811 double redPS
= (double)(red
) / 255.0;
812 double bluePS
= (double)(blue
) / 255.0;
813 double greenPS
= (double)(green
) / 255.0;
815 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
818 m_currentBlue
= blue
;
819 m_currentGreen
= green
;
825 if (fabs(m_scaleY
- 1.0) > 0.00001)
827 // If there is a user or actually any scale applied to
828 // the device context, scale the font.
830 // scale font description
831 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
832 double size
= oldSize
;
833 size
= size
* m_scaleY
;
834 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
836 // actually apply scaled font
837 pango_layout_set_font_description( m_layout
, m_fontdesc
);
839 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
841 if ( m_backgroundMode
== wxSOLID
)
843 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
844 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
845 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
849 gnome_print_moveto (m_gpc
, x
, y
);
850 if (fabs(angle
) > 0.00001)
852 gnome_print_gsave( m_gpc
);
853 gnome_print_rotate( m_gpc
, angle
);
854 gnome_print_pango_layout( m_gpc
, m_layout
);
855 gnome_print_grestore( m_gpc
);
859 gnome_print_pango_layout( m_gpc
, m_layout
);
862 // reset unscaled size
863 pango_font_description_set_size( m_fontdesc
, oldSize
);
865 // actually apply unscaled font
866 pango_layout_set_font_description( m_layout
, m_fontdesc
);
870 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
872 if ( m_backgroundMode
== wxSOLID
)
874 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
875 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
876 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
880 gnome_print_moveto (m_gpc
, x
, y
);
881 if (fabs(angle
) > 0.00001)
883 gnome_print_gsave( m_gpc
);
884 gnome_print_rotate( m_gpc
, angle
);
885 gnome_print_pango_layout( m_gpc
, m_layout
);
886 gnome_print_grestore( m_gpc
);
890 gnome_print_pango_layout( m_gpc
, m_layout
);
896 // undo underline attributes setting:
897 pango_layout_set_attributes(m_layout
, NULL
);
900 CalcBoundingBox (x
+ w
, y
+ h
);
903 void wxGnomePrintDC::Clear()
907 void wxGnomePrintDC::SetFont( const wxFont
& font
)
914 pango_font_description_free( m_fontdesc
);
916 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
918 pango_layout_set_font_description( m_layout
, m_fontdesc
);
922 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
924 if (!pen
.Ok()) return;
926 // TODO: support for pen styles other than solid (use gnome_print_setdash)
930 gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
932 unsigned char red
= m_pen
.GetColour().Red();
933 unsigned char blue
= m_pen
.GetColour().Blue();
934 unsigned char green
= m_pen
.GetColour().Green();
936 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
938 double redPS
= (double)(red
) / 255.0;
939 double bluePS
= (double)(blue
) / 255.0;
940 double greenPS
= (double)(green
) / 255.0;
942 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
945 m_currentBlue
= blue
;
946 m_currentGreen
= green
;
950 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
952 if (!brush
.Ok()) return;
957 unsigned char red
= m_brush
.GetColour().Red();
958 unsigned char blue
= m_brush
.GetColour().Blue();
959 unsigned char green
= m_brush
.GetColour().Green();
963 // Anything not white is black
964 if (! (red
== (unsigned char) 255 &&
965 blue
== (unsigned char) 255 &&
966 green
== (unsigned char) 255) )
968 red
= (unsigned char) 0;
969 green
= (unsigned char) 0;
970 blue
= (unsigned char) 0;
975 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
977 double redPS
= (double)(red
) / 255.0;
978 double bluePS
= (double)(blue
) / 255.0;
979 double greenPS
= (double)(green
) / 255.0;
981 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
984 m_currentBlue
= blue
;
985 m_currentGreen
= green
;
989 void wxGnomePrintDC::SetLogicalFunction( int function
)
993 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
997 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1001 void wxGnomePrintDC::DestroyClippingRegion()
1005 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1007 SetDeviceOrigin( 0,0 );
1012 void wxGnomePrintDC::EndDoc()
1016 void wxGnomePrintDC::StartPage()
1018 gnome_print_beginpage( m_gpc
, (const guchar
*) "1" );
1021 void wxGnomePrintDC::EndPage()
1023 gnome_print_showpage( m_gpc
);
1026 wxCoord
wxGnomePrintDC::GetCharHeight() const
1028 pango_layout_set_text( m_layout
, "H", 1 );
1031 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1036 wxCoord
wxGnomePrintDC::GetCharWidth() const
1038 pango_layout_set_text( m_layout
, "H", 1 );
1041 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1046 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1048 wxCoord
*externalLeading
,
1049 wxFont
*theFont
) const
1057 if ( externalLeading
)
1058 *externalLeading
= 0;
1060 if (string
.IsEmpty())
1065 // Set new font description
1067 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1069 // Set layout's text
1071 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1072 const char *dataUTF8
= (const char *)data
;
1074 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1077 if (width
) (*width
) = 0;
1078 if (height
) (*height
) = 0;
1081 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1082 const char *dataUTF8
= (const char *)data
;
1087 // hardly ideal, but what else can we do if conversion failed?
1091 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1094 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1097 *width
= (wxCoord
) w
;
1099 *height
= (wxCoord
) h
;
1102 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1103 int baseline
= pango_layout_iter_get_baseline(iter
);
1104 pango_layout_iter_free(iter
);
1105 *descent
= h
- PANGO_PIXELS(baseline
);
1108 // Reset old font description
1110 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1113 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1115 // No idea if that is efficient
1116 GnomePrintConfig
*config
= gnome_print_config_default();
1119 bool result
= gnome_print_config_get_page_size( config
, &w
, &h
);
1123 // Standard PS resolution DIN A4 size.
1134 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1138 /// Later, for now DIN A4
1148 wxSize
wxGnomePrintDC::GetPPI() const
1150 return wxSize(72,72);
1153 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1155 m_signX
= (xLeftRight
? 1 : -1);
1156 m_signY
= (yBottomUp
? 1 : -1);
1158 ComputeScaleAndOrigin();
1161 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1167 wxDC::SetDeviceOrigin( x
, h
-y
);
1170 void wxGnomePrintDC::SetResolution(int ppi
)
1174 int wxGnomePrintDC::GetResolution()
1180 class wxGnomePrintModule
: public wxModule
1183 wxGnomePrintModule() {}
1184 bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
); return true; }
1188 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1191 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1194 // wxUSE_LIBGNOMEPRINT