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>
35 //----------------------------------------------------------------------------
36 // wxGnomePrintNativeData
37 //----------------------------------------------------------------------------
39 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
41 wxGnomePrintNativeData::wxGnomePrintNativeData()
43 m_config
= gnome_print_config_default();
44 m_job
= gnome_print_job_new( m_config
);
47 wxGnomePrintNativeData::~wxGnomePrintNativeData()
49 g_object_unref (G_OBJECT (m_config
));
50 g_object_unref (G_OBJECT (m_job
));
53 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
59 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
65 //----------------------------------------------------------------------------
66 // wxGnomePrintFactory
67 //----------------------------------------------------------------------------
69 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
71 return new wxGnomePrinter( data
);
74 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
76 wxPrintDialogData
*data
)
78 return new wxPostScriptPrintPreview( preview
, printout
, data
);
81 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
85 return new wxPostScriptPrintPreview( preview
, printout
, data
);
88 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
89 wxPrintDialogData
*data
)
91 return new wxGnomePrintDialog( parent
, data
);
94 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
97 return new wxGnomePrintDialog( parent
, data
);
100 bool wxGnomePrintFactory::HasPrintSetupDialog()
105 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
110 bool wxGnomePrintFactory::HasOwnPrintToFile()
115 bool wxGnomePrintFactory::HasPrinterLine()
120 wxString
wxGnomePrintFactory::CreatePrinterLine()
123 return wxEmptyString
;
126 bool wxGnomePrintFactory::HasStatusLine()
132 wxString
wxGnomePrintFactory::CreateStatusLine()
135 return wxEmptyString
;
138 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
140 return new wxGnomePrintNativeData
;
143 //----------------------------------------------------------------------------
144 // wxGnomePrintSetupDialog
145 //----------------------------------------------------------------------------
147 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
149 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
150 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
151 wxPoint(0, 0), wxSize(600, 600),
152 wxDEFAULT_DIALOG_STYLE
|
156 m_printDialogData
= *data
;
161 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
162 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
163 wxPoint(0, 0), wxSize(600, 600),
164 wxDEFAULT_DIALOG_STYLE
|
168 m_printDialogData
= *data
;
173 void wxGnomePrintDialog::Init()
175 wxPrintData data
= m_printDialogData
.GetPrintData();
177 wxGnomePrintNativeData
*native
=
178 (wxGnomePrintNativeData
*) data
.GetNativeData();
180 m_widget
= gnome_print_dialog_new( native
->GetPrintJob(),
182 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
185 if (m_printDialogData
.GetEnableSelection())
186 flag
|= GNOME_PRINT_RANGE_SELECTION
;
187 if (m_printDialogData
.GetEnablePageNumbers())
188 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
190 gnome_print_dialog_construct_range_page( GNOME_PRINT_DIALOG( m_widget
),
192 m_printDialogData
.GetMinPage(),
193 m_printDialogData
.GetMaxPage(),
198 wxGnomePrintDialog::~wxGnomePrintDialog()
203 int wxGnomePrintDialog::ShowModal()
205 // Transfer data from m_printDalogData to dialog here
207 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
209 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
211 gtk_widget_destroy(m_widget
);
218 gboolean collate
= false;
219 gnome_print_dialog_get_copies( GNOME_PRINT_DIALOG(m_widget
), &copies
, &collate
);
220 m_printDialogData
.SetNoCopies( copies
);
221 m_printDialogData
.SetCollate( collate
);
223 switch (gnome_print_dialog_get_range( GNOME_PRINT_DIALOG(m_widget
) ))
225 case GNOME_PRINT_RANGE_SELECTION
:
226 m_printDialogData
.SetSelection( true );
228 case GNOME_PRINT_RANGE_ALL
:
229 m_printDialogData
.SetAllPages( true );
230 m_printDialogData
.SetFromPage( 0 );
231 m_printDialogData
.SetToPage( 9999 );
233 case GNOME_PRINT_RANGE_RANGE
:
236 gnome_print_dialog_get_range_page( GNOME_PRINT_DIALOG(m_widget
), &start
, &end
);
237 m_printDialogData
.SetFromPage( start
);
238 m_printDialogData
.SetToPage( end
);
242 gtk_widget_destroy(m_widget
);
248 wxDC
*wxGnomePrintDialog::GetPrintDC()
254 bool wxGnomePrintDialog::Validate()
259 bool wxGnomePrintDialog::TransferDataToWindow()
264 bool wxGnomePrintDialog::TransferDataFromWindow()
269 //----------------------------------------------------------------------------
271 //----------------------------------------------------------------------------
273 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
275 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
276 wxPrinterBase( data
)
281 wxGnomePrinter::~wxGnomePrinter()
285 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
289 sm_lastError
= wxPRINTER_ERROR
;
293 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
294 wxGnomePrintNativeData
*data
=
295 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
297 // The GnomePrintJob is temporarily stored in the
298 // native print data as the native print dialog
299 // needs to access it.
300 GnomePrintJob
*job
= data
->GetPrintJob();
301 m_gpc
= gnome_print_job_get_context (job
);
303 printout
->SetIsPreview(false);
305 if (m_printDialogData
.GetMinPage() < 1)
306 m_printDialogData
.SetMinPage(1);
307 if (m_printDialogData
.GetMaxPage() < 1)
308 m_printDialogData
.SetMaxPage(9999);
312 dc
= PrintDialog( parent
);
314 dc
= new wxGnomePrintDC( this );
318 gnome_print_job_close( job
);
319 sm_lastError
= wxPRINTER_ERROR
;
323 wxSize ScreenPixels
= wxGetDisplaySize();
324 wxSize ScreenMM
= wxGetDisplaySizeMM();
326 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
327 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
328 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
329 wxGnomePrintDC::GetResolution() );
335 printout
->SetPageSizePixels((int)w
, (int)h
);
336 dc
->GetSizeMM(&w
, &h
);
337 printout
->SetPageSizeMM((int)w
, (int)h
);
339 printout
->OnPreparePrinting();
341 // Get some parameters from the printout, if defined
342 int fromPage
, toPage
;
343 int minPage
, maxPage
;
344 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
348 sm_lastError
= wxPRINTER_ERROR
;
352 printout
->OnBeginPrinting();
354 int minPageNum
= minPage
, maxPageNum
= maxPage
;
356 if ( !m_printDialogData
.GetAllPages() )
358 minPageNum
= m_printDialogData
.GetFromPage();
359 maxPageNum
= m_printDialogData
.GetToPage();
365 copyCount
<= m_printDialogData
.GetNoCopies();
368 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
370 wxLogError(_("Could not start printing."));
371 sm_lastError
= wxPRINTER_ERROR
;
376 for ( pn
= minPageNum
;
377 pn
<= maxPageNum
&& printout
->HasPage(pn
);
381 printout
->OnPrintPage(pn
);
385 printout
->OnEndDocument();
386 printout
->OnEndPrinting();
389 gnome_print_job_close( job
);
390 gnome_print_job_print( job
);
394 return (sm_lastError
== wxPRINTER_NO_ERROR
);
397 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
399 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
400 if (dialog
.ShowModal() == wxID_CANCEL
)
402 sm_lastError
= wxPRINTER_ERROR
;
406 m_printDialogData
= dialog
.GetPrintDialogData();
407 return new wxGnomePrintDC( this );
410 bool wxGnomePrinter::Setup( wxWindow
*parent
)
415 //-----------------------------------------------------------------------------
417 //-----------------------------------------------------------------------------
419 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
421 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
425 m_gpc
= printer
->GetPrintContext();
427 m_layout
= gnome_print_pango_create_layout( m_gpc
);
428 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
434 m_signX
= 1; // default x-axis left to right
435 m_signY
= -1; // default y-axis bottom up -> top down
438 wxGnomePrintDC::~wxGnomePrintDC()
442 bool wxGnomePrintDC::Ok() const
447 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
452 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
457 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
459 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
463 gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
464 gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
465 gnome_print_stroke ( m_gpc
);
467 CalcBoundingBox( x1
, y1
);
468 CalcBoundingBox( x2
, y2
);
471 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
475 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
479 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
483 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
487 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
491 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
495 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
499 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
501 if (m_brush
.GetStyle () != wxTRANSPARENT
)
505 gnome_print_newpath( m_gpc
);
506 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
507 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
508 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
509 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
510 gnome_print_closepath( m_gpc
);
511 gnome_print_fill( m_gpc
);
513 CalcBoundingBox( x
, y
);
514 CalcBoundingBox( x
+ width
, y
+ height
);
517 if (m_pen
.GetStyle () != wxTRANSPARENT
)
521 gnome_print_newpath( m_gpc
);
522 gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
523 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
524 gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
525 gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
526 gnome_print_closepath( m_gpc
);
527 gnome_print_stroke( m_gpc
);
529 CalcBoundingBox( x
, y
);
530 CalcBoundingBox( x
+ width
, y
+ height
);
534 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
538 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
542 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
546 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
547 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
548 wxCoord xsrcMask
, wxCoord ysrcMask
)
553 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
555 DoDrawBitmap( icon
, x
, y
, true );
558 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
560 if (!bitmap
.Ok()) return;
562 if (bitmap
.HasPixbuf())
564 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
565 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
566 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
567 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
568 int height
= gdk_pixbuf_get_height( pixbuf
);
569 int width
= gdk_pixbuf_get_width( pixbuf
);
571 gnome_print_gsave( m_gpc
);
573 matrix
[0] = XLOG2DEVREL(width
);
576 matrix
[3] = YLOG2DEVREL(height
);
577 matrix
[4] = XLOG2DEV(x
);
578 matrix
[5] = YLOG2DEV(y
+height
);
579 gnome_print_concat( m_gpc
, matrix
);
580 gnome_print_moveto( m_gpc
, 0, 0 );
582 gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
584 gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
585 gnome_print_grestore( m_gpc
);
589 wxImage image
= bitmap
.ConvertToImage();
591 if (!image
.Ok()) return;
593 gnome_print_gsave( m_gpc
);
595 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
598 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
599 matrix
[4] = XLOG2DEV(x
);
600 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
601 gnome_print_concat( m_gpc
, matrix
);
602 gnome_print_moveto( m_gpc
, 0, 0 );
603 gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
604 gnome_print_grestore( m_gpc
);
608 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
610 DoDrawRotatedText( text
, x
, y
, 0.0 );
613 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
618 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
621 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
623 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
626 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
629 size_t datalen
= strlen((const char*)data
);
630 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
634 PangoAttrList
*attrs
= pango_attr_list_new();
635 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
637 a
->end_index
= datalen
;
638 pango_attr_list_insert(attrs
, a
);
639 pango_layout_set_attributes(m_layout
, attrs
);
640 pango_attr_list_unref(attrs
);
643 if (m_textForegroundColour
.Ok())
645 unsigned char red
= m_textForegroundColour
.Red();
646 unsigned char blue
= m_textForegroundColour
.Blue();
647 unsigned char green
= m_textForegroundColour
.Green();
649 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
651 double redPS
= (double)(red
) / 255.0;
652 double bluePS
= (double)(blue
) / 255.0;
653 double greenPS
= (double)(green
) / 255.0;
655 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
658 m_currentBlue
= blue
;
659 m_currentGreen
= green
;
665 if (fabs(m_scaleY
- 1.0) > 0.00001)
667 // If there is a user or actually any scale applied to
668 // the device context, scale the font.
670 // scale font description
671 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
672 double size
= oldSize
;
673 size
= size
* m_scaleY
;
674 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
676 // actually apply scaled font
677 pango_layout_set_font_description( m_layout
, m_fontdesc
);
679 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
681 if ( m_backgroundMode
== wxSOLID
)
683 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
684 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
685 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
689 gnome_print_moveto (m_gpc
, x
, y
);
690 if (fabs(angle
) > 0.00001)
692 gnome_print_gsave( m_gpc
);
693 gnome_print_rotate( m_gpc
, angle
);
694 gnome_print_pango_layout( m_gpc
, m_layout
);
695 gnome_print_grestore( m_gpc
);
699 gnome_print_pango_layout( m_gpc
, m_layout
);
702 // reset unscaled size
703 pango_font_description_set_size( m_fontdesc
, oldSize
);
705 // actually apply unscaled font
706 pango_layout_set_font_description( m_layout
, m_fontdesc
);
710 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
712 if ( m_backgroundMode
== wxSOLID
)
714 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
715 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
716 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
720 gnome_print_moveto (m_gpc
, x
, y
);
721 if (fabs(angle
) > 0.00001)
723 gnome_print_gsave( m_gpc
);
724 gnome_print_rotate( m_gpc
, angle
);
725 gnome_print_pango_layout( m_gpc
, m_layout
);
726 gnome_print_grestore( m_gpc
);
730 gnome_print_pango_layout( m_gpc
, m_layout
);
736 // undo underline attributes setting:
737 pango_layout_set_attributes(m_layout
, NULL
);
740 CalcBoundingBox (x
+ w
, y
+ h
);
743 void wxGnomePrintDC::Clear()
747 void wxGnomePrintDC::SetFont( const wxFont
& font
)
754 pango_font_description_free( m_fontdesc
);
756 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
758 pango_layout_set_font_description( m_layout
, m_fontdesc
);
762 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
764 if (!pen
.Ok()) return;
766 // TODO: support for pen styles other than solid (use gnome_print_setdash)
770 gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
772 unsigned char red
= m_pen
.GetColour().Red();
773 unsigned char blue
= m_pen
.GetColour().Blue();
774 unsigned char green
= m_pen
.GetColour().Green();
776 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
778 double redPS
= (double)(red
) / 255.0;
779 double bluePS
= (double)(blue
) / 255.0;
780 double greenPS
= (double)(green
) / 255.0;
782 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
785 m_currentBlue
= blue
;
786 m_currentGreen
= green
;
790 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
792 if (!brush
.Ok()) return;
797 unsigned char red
= m_brush
.GetColour().Red();
798 unsigned char blue
= m_brush
.GetColour().Blue();
799 unsigned char green
= m_brush
.GetColour().Green();
803 // Anything not white is black
804 if (! (red
== (unsigned char) 255 &&
805 blue
== (unsigned char) 255 &&
806 green
== (unsigned char) 255) )
808 red
= (unsigned char) 0;
809 green
= (unsigned char) 0;
810 blue
= (unsigned char) 0;
815 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
817 double redPS
= (double)(red
) / 255.0;
818 double bluePS
= (double)(blue
) / 255.0;
819 double greenPS
= (double)(green
) / 255.0;
821 gnome_print_setrgbcolor( m_gpc
, redPS
, bluePS
, greenPS
);
824 m_currentBlue
= blue
;
825 m_currentGreen
= green
;
829 void wxGnomePrintDC::SetLogicalFunction( int function
)
833 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
837 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
841 void wxGnomePrintDC::DestroyClippingRegion()
845 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
847 SetDeviceOrigin( 0,0 );
852 void wxGnomePrintDC::EndDoc()
856 void wxGnomePrintDC::StartPage()
858 gnome_print_beginpage( m_gpc
, (const guchar
*) "1" );
861 void wxGnomePrintDC::EndPage()
863 gnome_print_showpage( m_gpc
);
866 wxCoord
wxGnomePrintDC::GetCharHeight() const
868 pango_layout_set_text( m_layout
, "H", 1 );
871 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
876 wxCoord
wxGnomePrintDC::GetCharWidth() const
878 pango_layout_set_text( m_layout
, "H", 1 );
881 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
886 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
888 wxCoord
*externalLeading
,
889 wxFont
*theFont
) const
897 if ( externalLeading
)
898 *externalLeading
= 0;
900 if (string
.IsEmpty())
905 // Set new font description
907 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
911 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
912 const char *dataUTF8
= (const char *)data
;
914 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
917 if (width
) (*width
) = 0;
918 if (height
) (*height
) = 0;
921 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
922 const char *dataUTF8
= (const char *)data
;
927 // hardly ideal, but what else can we do if conversion failed?
931 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
934 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
937 *width
= (wxCoord
) w
;
939 *height
= (wxCoord
) h
;
942 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
943 int baseline
= pango_layout_iter_get_baseline(iter
);
944 pango_layout_iter_free(iter
);
945 *descent
= h
- PANGO_PIXELS(baseline
);
948 // Reset old font description
950 pango_layout_set_font_description( m_layout
, m_fontdesc
);
953 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
955 // No idea if that is efficient
956 GnomePrintConfig
*config
= gnome_print_config_default();
959 bool result
= gnome_print_config_get_page_size( config
, &w
, &h
);
963 // Standard PS resolution DIN A4 size.
974 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
978 /// Later, for now DIN A4
988 wxSize
wxGnomePrintDC::GetPPI() const
990 return wxSize(72,72);
993 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
995 m_signX
= (xLeftRight
? 1 : -1);
996 m_signY
= (yBottomUp
? 1 : -1);
998 ComputeScaleAndOrigin();
1001 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1007 wxDC::SetDeviceOrigin( x
, h
-y
);
1010 void wxGnomePrintDC::SetResolution(int ppi
)
1014 int wxGnomePrintDC::GetResolution()
1020 class wxGnomePrintModule
: public wxModule
1023 wxGnomePrintModule() {}
1024 bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
); return true; }
1028 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1031 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1034 // wxUSE_LIBGNOMEPRINT