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"
31 #include <libgnomeprint/gnome-print.h>
32 #include <libgnomeprint/gnome-print-pango.h>
33 #include <libgnomeprintui/gnome-print-dialog.h>
34 #include <libgnomeprintui/gnome-print-job-preview.h>
36 //----------------------------------------------------------------------------
37 // wxGnomePrintNativeData
38 //----------------------------------------------------------------------------
40 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
42 wxGnomePrintNativeData::wxGnomePrintNativeData()
44 m_config
= gnome_print_config_default();
45 m_job
= gnome_print_job_new( m_config
);
48 wxGnomePrintNativeData::~wxGnomePrintNativeData()
50 g_object_unref (G_OBJECT (m_config
));
51 g_object_unref (G_OBJECT (m_job
));
54 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
60 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
66 //----------------------------------------------------------------------------
67 // wxGnomePrintFactory
68 //----------------------------------------------------------------------------
70 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
72 return new wxGnomePrinter( data
);
75 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
77 wxPrintDialogData
*data
)
79 return new wxPostScriptPrintPreview( preview
, printout
, data
);
82 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
86 return new wxPostScriptPrintPreview( preview
, printout
, data
);
89 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
90 wxPrintDialogData
*data
)
92 return new wxGnomePrintDialog( parent
, data
);
95 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
98 return new wxGnomePrintDialog( parent
, data
);
101 bool wxGnomePrintFactory::HasPrintSetupDialog()
106 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
111 bool wxGnomePrintFactory::HasOwnPrintToFile()
116 bool wxGnomePrintFactory::HasPrinterLine()
121 wxString
wxGnomePrintFactory::CreatePrinterLine()
124 return wxEmptyString
;
127 bool wxGnomePrintFactory::HasStatusLine()
133 wxString
wxGnomePrintFactory::CreateStatusLine()
136 return wxEmptyString
;
139 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
141 return new wxGnomePrintNativeData
;
144 //----------------------------------------------------------------------------
145 // wxGnomePrintSetupDialog
146 //----------------------------------------------------------------------------
148 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
150 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
151 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
152 wxPoint(0, 0), wxSize(600, 600),
153 wxDEFAULT_DIALOG_STYLE
|
157 m_printDialogData
= *data
;
162 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
163 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
164 wxPoint(0, 0), wxSize(600, 600),
165 wxDEFAULT_DIALOG_STYLE
|
169 m_printDialogData
= *data
;
174 void wxGnomePrintDialog::Init()
176 wxPrintData data
= m_printDialogData
.GetPrintData();
178 wxGnomePrintNativeData
*native
=
179 (wxGnomePrintNativeData
*) data
.GetNativeData();
181 m_widget
= gnome_print_dialog_new( native
->GetPrintJob(),
183 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
186 if (m_printDialogData
.GetEnableSelection())
187 flag
|= GNOME_PRINT_RANGE_SELECTION
;
188 if (m_printDialogData
.GetEnablePageNumbers())
189 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
191 gnome_print_dialog_construct_range_page( GNOME_PRINT_DIALOG( m_widget
),
193 m_printDialogData
.GetMinPage(),
194 m_printDialogData
.GetMaxPage(),
199 wxGnomePrintDialog::~wxGnomePrintDialog()
204 int wxGnomePrintDialog::ShowModal()
206 // Transfer data from m_printDalogData to dialog here
208 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
210 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
212 gtk_widget_destroy(m_widget
);
219 gboolean collate
= false;
220 gnome_print_dialog_get_copies( GNOME_PRINT_DIALOG(m_widget
), &copies
, &collate
);
221 m_printDialogData
.SetNoCopies( copies
);
222 m_printDialogData
.SetCollate( collate
);
224 switch (gnome_print_dialog_get_range( GNOME_PRINT_DIALOG(m_widget
) ))
226 case GNOME_PRINT_RANGE_SELECTION
:
227 m_printDialogData
.SetSelection( true );
229 case GNOME_PRINT_RANGE_ALL
:
230 m_printDialogData
.SetAllPages( true );
231 m_printDialogData
.SetFromPage( 0 );
232 m_printDialogData
.SetToPage( 9999 );
234 case GNOME_PRINT_RANGE_RANGE
:
237 gnome_print_dialog_get_range_page( GNOME_PRINT_DIALOG(m_widget
), &start
, &end
);
238 m_printDialogData
.SetFromPage( start
);
239 m_printDialogData
.SetToPage( end
);
243 gtk_widget_destroy(m_widget
);
246 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
252 wxDC
*wxGnomePrintDialog::GetPrintDC()
258 bool wxGnomePrintDialog::Validate()
263 bool wxGnomePrintDialog::TransferDataToWindow()
268 bool wxGnomePrintDialog::TransferDataFromWindow()
273 //----------------------------------------------------------------------------
275 //----------------------------------------------------------------------------
277 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
279 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
280 wxPrinterBase( data
)
283 m_native_preview
= false;
286 wxGnomePrinter::~wxGnomePrinter()
290 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
294 sm_lastError
= wxPRINTER_ERROR
;
298 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
299 wxGnomePrintNativeData
*data
=
300 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
302 // The GnomePrintJob is temporarily stored in the
303 // native print data as the native print dialog
304 // needs to access it.
305 GnomePrintJob
*job
= data
->GetPrintJob();
306 m_gpc
= gnome_print_job_get_context (job
);
308 printout
->SetIsPreview(false);
310 if (m_printDialogData
.GetMinPage() < 1)
311 m_printDialogData
.SetMinPage(1);
312 if (m_printDialogData
.GetMaxPage() < 1)
313 m_printDialogData
.SetMaxPage(9999);
317 dc
= PrintDialog( parent
);
319 dc
= new wxGnomePrintDC( this );
321 if (m_native_preview
)
322 printout
->SetIsPreview(true);
326 gnome_print_job_close( job
);
327 sm_lastError
= wxPRINTER_ERROR
;
331 wxSize ScreenPixels
= wxGetDisplaySize();
332 wxSize ScreenMM
= wxGetDisplaySizeMM();
334 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
335 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
336 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
337 wxGnomePrintDC::GetResolution() );
343 printout
->SetPageSizePixels((int)w
, (int)h
);
344 dc
->GetSizeMM(&w
, &h
);
345 printout
->SetPageSizeMM((int)w
, (int)h
);
347 printout
->OnPreparePrinting();
349 // Get some parameters from the printout, if defined
350 int fromPage
, toPage
;
351 int minPage
, maxPage
;
352 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
356 sm_lastError
= wxPRINTER_ERROR
;
360 printout
->OnBeginPrinting();
362 int minPageNum
= minPage
, maxPageNum
= maxPage
;
364 if ( !m_printDialogData
.GetAllPages() )
366 minPageNum
= m_printDialogData
.GetFromPage();
367 maxPageNum
= m_printDialogData
.GetToPage();
373 copyCount
<= m_printDialogData
.GetNoCopies();
376 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
378 wxLogError(_("Could not start printing."));
379 sm_lastError
= wxPRINTER_ERROR
;
384 for ( pn
= minPageNum
;
385 pn
<= maxPageNum
&& printout
->HasPage(pn
);
389 printout
->OnPrintPage(pn
);
393 printout
->OnEndDocument();
394 printout
->OnEndPrinting();
397 gnome_print_job_close( job
);
398 if (m_native_preview
)
400 wxString
title( _("Print preview") );
401 gtk_widget_show( gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
405 gnome_print_job_print( job
);
410 return (sm_lastError
== wxPRINTER_NO_ERROR
);
413 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
415 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
416 int ret
= dialog
.ShowModal();
417 if (ret
== wxID_CANCEL
)
419 sm_lastError
= wxPRINTER_ERROR
;
423 m_native_preview
= ret
== wxID_PREVIEW
;
425 m_printDialogData
= dialog
.GetPrintDialogData();
426 return new wxGnomePrintDC( this );
429 bool wxGnomePrinter::Setup( wxWindow
*parent
)
434 //-----------------------------------------------------------------------------
436 //-----------------------------------------------------------------------------
438 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
440 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
444 m_gpc
= printer
->GetPrintContext();
446 m_layout
= gnome_print_pango_create_layout( m_gpc
);
447 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
453 m_signX
= 1; // default x-axis left to right
454 m_signY
= -1; // default y-axis bottom up -> top down
457 wxGnomePrintDC::~wxGnomePrintDC()
461 bool wxGnomePrintDC::Ok() const
466 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
471 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
476 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
478 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
482 gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
483 gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
484 gnome_print_stroke ( m_gpc
);
486 CalcBoundingBox( x1
, y1
);
487 CalcBoundingBox( x2
, y2
);
490 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
494 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
498 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
502 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
506 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
510 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
514 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
518 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
520 if (m_brush
.GetStyle () != wxTRANSPARENT
)
524 gnome_print_newpath( m_gpc
);
525 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
526 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
527 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
528 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
529 gnome_print_closepath( m_gpc
);
530 gnome_print_fill( m_gpc
);
532 CalcBoundingBox( x
, y
);
533 CalcBoundingBox( x
+ width
, y
+ height
);
536 if (m_pen
.GetStyle () != wxTRANSPARENT
)
540 gnome_print_newpath( m_gpc
);
541 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
542 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
543 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
544 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
545 gnome_print_closepath( m_gpc
);
546 gnome_print_stroke( m_gpc
);
548 CalcBoundingBox( x
, y
);
549 CalcBoundingBox( x
+ width
, y
+ height
);
553 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
557 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
561 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
565 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
566 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
567 wxCoord xsrcMask
, wxCoord ysrcMask
)
572 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
574 DoDrawBitmap( icon
, x
, y
, true );
577 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
579 if (!bitmap
.Ok()) return;
581 if (bitmap
.HasPixbuf())
583 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
584 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
585 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
586 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
587 int height
= gdk_pixbuf_get_height( pixbuf
);
588 int width
= gdk_pixbuf_get_width( pixbuf
);
590 gnome_print_gsave( m_gpc
);
592 matrix
[0] = XLOG2DEVREL(width
);
595 matrix
[3] = YLOG2DEVREL(height
);
596 matrix
[4] = XLOG2DEV(x
);
597 matrix
[5] = YLOG2DEV(y
+height
);
598 gnome_print_concat( m_gpc
, matrix
);
599 gnome_print_moveto( m_gpc
, 0, 0 );
601 gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
603 gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
604 gnome_print_grestore( m_gpc
);
608 wxImage image
= bitmap
.ConvertToImage();
610 if (!image
.Ok()) return;
612 gnome_print_gsave( m_gpc
);
614 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
617 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
618 matrix
[4] = XLOG2DEV(x
);
619 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
620 gnome_print_concat( m_gpc
, matrix
);
621 gnome_print_moveto( m_gpc
, 0, 0 );
622 gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
623 gnome_print_grestore( m_gpc
);
627 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
629 DoDrawRotatedText( text
, x
, y
, 0.0 );
632 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
637 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
640 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
642 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
645 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
648 size_t datalen
= strlen((const char*)data
);
649 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
653 PangoAttrList
*attrs
= pango_attr_list_new();
654 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
656 a
->end_index
= datalen
;
657 pango_attr_list_insert(attrs
, a
);
658 pango_layout_set_attributes(m_layout
, attrs
);
659 pango_attr_list_unref(attrs
);
662 if (m_textForegroundColour
.Ok())
664 unsigned char red
= m_textForegroundColour
.Red();
665 unsigned char blue
= m_textForegroundColour
.Blue();
666 unsigned char green
= m_textForegroundColour
.Green();
668 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
670 double redPS
= (double)(red
) / 255.0;
671 double bluePS
= (double)(blue
) / 255.0;
672 double greenPS
= (double)(green
) / 255.0;
674 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
677 m_currentBlue
= blue
;
678 m_currentGreen
= green
;
684 if (fabs(m_scaleY
- 1.0) > 0.00001)
686 // If there is a user or actually any scale applied to
687 // the device context, scale the font.
689 // scale font description
690 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
691 double size
= oldSize
;
692 size
= size
* m_scaleY
;
693 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
695 // actually apply scaled font
696 pango_layout_set_font_description( m_layout
, m_fontdesc
);
698 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
700 if ( m_backgroundMode
== wxSOLID
)
702 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
703 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
704 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
708 gnome_print_moveto (m_gpc
, x
, y
);
709 if (fabs(angle
) > 0.00001)
711 gnome_print_gsave( m_gpc
);
712 gnome_print_rotate( m_gpc
, angle
);
713 gnome_print_pango_layout( m_gpc
, m_layout
);
714 gnome_print_grestore( m_gpc
);
718 gnome_print_pango_layout( m_gpc
, m_layout
);
721 // reset unscaled size
722 pango_font_description_set_size( m_fontdesc
, oldSize
);
724 // actually apply unscaled font
725 pango_layout_set_font_description( m_layout
, m_fontdesc
);
729 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
731 if ( m_backgroundMode
== wxSOLID
)
733 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
734 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
735 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
739 gnome_print_moveto (m_gpc
, x
, y
);
740 if (fabs(angle
) > 0.00001)
742 gnome_print_gsave( m_gpc
);
743 gnome_print_rotate( m_gpc
, angle
);
744 gnome_print_pango_layout( m_gpc
, m_layout
);
745 gnome_print_grestore( m_gpc
);
749 gnome_print_pango_layout( m_gpc
, m_layout
);
755 // undo underline attributes setting:
756 pango_layout_set_attributes(m_layout
, NULL
);
759 CalcBoundingBox (x
+ w
, y
+ h
);
762 void wxGnomePrintDC::Clear()
766 void wxGnomePrintDC::SetFont( const wxFont
& font
)
773 pango_font_description_free( m_fontdesc
);
775 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
777 pango_layout_set_font_description( m_layout
, m_fontdesc
);
781 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
783 if (!pen
.Ok()) return;
785 // TODO: support for pen styles other than solid (use gnome_print_setdash)
789 gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
791 unsigned char red
= m_pen
.GetColour().Red();
792 unsigned char blue
= m_pen
.GetColour().Blue();
793 unsigned char green
= m_pen
.GetColour().Green();
795 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
797 double redPS
= (double)(red
) / 255.0;
798 double bluePS
= (double)(blue
) / 255.0;
799 double greenPS
= (double)(green
) / 255.0;
801 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
804 m_currentBlue
= blue
;
805 m_currentGreen
= green
;
809 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
811 if (!brush
.Ok()) return;
816 unsigned char red
= m_brush
.GetColour().Red();
817 unsigned char blue
= m_brush
.GetColour().Blue();
818 unsigned char green
= m_brush
.GetColour().Green();
822 // Anything not white is black
823 if (! (red
== (unsigned char) 255 &&
824 blue
== (unsigned char) 255 &&
825 green
== (unsigned char) 255) )
827 red
= (unsigned char) 0;
828 green
= (unsigned char) 0;
829 blue
= (unsigned char) 0;
834 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
836 double redPS
= (double)(red
) / 255.0;
837 double bluePS
= (double)(blue
) / 255.0;
838 double greenPS
= (double)(green
) / 255.0;
840 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
843 m_currentBlue
= blue
;
844 m_currentGreen
= green
;
848 void wxGnomePrintDC::SetLogicalFunction( int function
)
852 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
856 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
860 void wxGnomePrintDC::DestroyClippingRegion()
864 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
866 SetDeviceOrigin( 0,0 );
871 void wxGnomePrintDC::EndDoc()
875 void wxGnomePrintDC::StartPage()
877 gnome_print_beginpage( m_gpc
, (const guchar
*) "1" );
880 void wxGnomePrintDC::EndPage()
882 gnome_print_showpage( m_gpc
);
885 wxCoord
wxGnomePrintDC::GetCharHeight() const
887 pango_layout_set_text( m_layout
, "H", 1 );
890 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
895 wxCoord
wxGnomePrintDC::GetCharWidth() const
897 pango_layout_set_text( m_layout
, "H", 1 );
900 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
905 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
907 wxCoord
*externalLeading
,
908 wxFont
*theFont
) const
916 if ( externalLeading
)
917 *externalLeading
= 0;
919 if (string
.IsEmpty())
924 // Set new font description
926 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
930 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
931 const char *dataUTF8
= (const char *)data
;
933 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
936 if (width
) (*width
) = 0;
937 if (height
) (*height
) = 0;
940 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
941 const char *dataUTF8
= (const char *)data
;
946 // hardly ideal, but what else can we do if conversion failed?
950 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
953 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
956 *width
= (wxCoord
) w
;
958 *height
= (wxCoord
) h
;
961 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
962 int baseline
= pango_layout_iter_get_baseline(iter
);
963 pango_layout_iter_free(iter
);
964 *descent
= h
- PANGO_PIXELS(baseline
);
967 // Reset old font description
969 pango_layout_set_font_description( m_layout
, m_fontdesc
);
972 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
974 // No idea if that is efficient
975 GnomePrintConfig
*config
= gnome_print_config_default();
978 bool result
= gnome_print_config_get_page_size( config
, &w
, &h
);
982 // Standard PS resolution DIN A4 size.
993 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
997 /// Later, for now DIN A4
1007 wxSize
wxGnomePrintDC::GetPPI() const
1009 return wxSize(72,72);
1012 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1014 m_signX
= (xLeftRight
? 1 : -1);
1015 m_signY
= (yBottomUp
? 1 : -1);
1017 ComputeScaleAndOrigin();
1020 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1026 wxDC::SetDeviceOrigin( x
, h
-y
);
1029 void wxGnomePrintDC::SetResolution(int ppi
)
1033 int wxGnomePrintDC::GetResolution()
1039 class wxGnomePrintModule
: public wxModule
1042 wxGnomePrintModule() {}
1043 bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
); return true; }
1047 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1050 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1053 // wxUSE_LIBGNOMEPRINT