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"
32 #include "wx/dynlib.h"
34 #include <libgnomeprint/gnome-print.h>
35 #include <libgnomeprint/gnome-print-pango.h>
36 #include <libgnomeprint/gnome-print-config.h>
37 #include <libgnomeprintui/gnome-print-dialog.h>
38 #include <libgnomeprintui/gnome-print-job-preview.h>
39 #include <libgnomeprintui/gnome-print-paper-selector.h>
42 #include "wx/html/forcelnk.h"
43 FORCE_LINK_ME(gnome_print
)
45 //----------------------------------------------------------------------------
46 // wxGnomePrintLibrary
47 //----------------------------------------------------------------------------
49 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
50 typedef rettype (* name ## Type) args ; \
51 name ## Type pfn_ ## name; \
53 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
55 #define wxDL_METHOD_LOAD( lib, name, success ) \
56 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
59 class wxGnomePrintLibrary
62 wxGnomePrintLibrary();
63 ~wxGnomePrintLibrary();
66 void InitializeMethods();
70 wxDynamicLibrary
*m_gnome_print_lib
;
71 wxDynamicLibrary
*m_gnome_printui_lib
;
74 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
75 (GnomePrintContext
*pc
), (pc
), 0 )
76 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
77 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
79 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
81 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
83 (GnomePrintContext
*pc
), (pc
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
85 (GnomePrintContext
*pc
), (pc
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
87 (GnomePrintContext
*pc
), (pc
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
89 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
91 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
93 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
95 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
96 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
98 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
100 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
101 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
102 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
103 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
105 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
107 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
108 (GnomePrintContext
*pc
), (pc
), 0 )
109 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
110 (GnomePrintContext
*pc
), (pc
), 0 )
112 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
113 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
114 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
115 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
117 (GnomePrintContext
*pc
), (pc
), 0 )
119 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
120 (GnomePrintContext
*gpc
), (gpc
), NULL
)
121 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
122 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
124 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
125 (GnomePrintConfig
*config
), (config
), NULL
)
126 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
127 (GnomePrintJob
*job
), (job
), NULL
)
128 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
129 (GnomePrintJob
*job
), (job
), 0 )
130 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
131 (GnomePrintJob
*job
), (job
), 0 )
132 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
133 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
135 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
136 (const guchar
*abbreviation
), (abbreviation
), NULL
)
137 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
138 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
140 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
142 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
143 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
144 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
145 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
147 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
148 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
149 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
150 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
151 const guchar
*currentlabel
, const guchar
*rangelabel
),
152 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
153 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
154 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
155 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
156 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
157 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
158 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
159 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
160 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
162 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
163 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
165 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
166 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
169 wxGnomePrintLibrary::wxGnomePrintLibrary()
171 m_gnome_print_lib
= NULL
;
172 m_gnome_printui_lib
= NULL
;
176 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so") );
177 m_ok
= m_gnome_print_lib
->IsLoaded();
180 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so") );
181 m_ok
= m_gnome_printui_lib
->IsLoaded();
187 wxGnomePrintLibrary::~wxGnomePrintLibrary()
189 if (m_gnome_print_lib
)
190 delete m_gnome_print_lib
;
191 if (m_gnome_printui_lib
)
192 delete m_gnome_printui_lib
;
195 bool wxGnomePrintLibrary::IsOk()
200 void wxGnomePrintLibrary::InitializeMethods()
205 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
206 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
207 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
208 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
209 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
210 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
237 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
246 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
247 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
248 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
249 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
250 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
251 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
253 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
260 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
262 //----------------------------------------------------------------------------
263 // wxGnomePrintNativeData
264 //----------------------------------------------------------------------------
266 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
268 wxGnomePrintNativeData::wxGnomePrintNativeData()
270 m_config
= gs_lgp
->gnome_print_config_default();
271 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
274 wxGnomePrintNativeData::~wxGnomePrintNativeData()
276 g_object_unref (G_OBJECT (m_config
));
279 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
285 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
291 //----------------------------------------------------------------------------
292 // wxGnomePrintFactory
293 //----------------------------------------------------------------------------
295 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
297 return new wxGnomePrinter( data
);
300 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
301 wxPrintout
*printout
,
302 wxPrintDialogData
*data
)
304 return new wxPostScriptPrintPreview( preview
, printout
, data
);
307 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
308 wxPrintout
*printout
,
311 return new wxPostScriptPrintPreview( preview
, printout
, data
);
314 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
315 wxPrintDialogData
*data
)
317 return new wxGnomePrintDialog( parent
, data
);
320 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
323 return new wxGnomePrintDialog( parent
, data
);
326 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
327 wxPageSetupDialogData
* data
)
329 // The native page setup dialog is broken. It
330 // miscalculates newly entered values for the
331 // margins if you have not chose "points" but
332 // e.g. centimerters.
333 // This has been fixed in GNOME CVS (maybe
334 // fixed in libgnomeprintui 2.8.1)
336 return new wxGnomePageSetupDialog( parent
, data
);
339 bool wxGnomePrintFactory::HasPrintSetupDialog()
344 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
349 bool wxGnomePrintFactory::HasOwnPrintToFile()
354 bool wxGnomePrintFactory::HasPrinterLine()
359 wxString
wxGnomePrintFactory::CreatePrinterLine()
362 return wxEmptyString
;
365 bool wxGnomePrintFactory::HasStatusLine()
371 wxString
wxGnomePrintFactory::CreateStatusLine()
374 return wxEmptyString
;
377 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
379 return new wxGnomePrintNativeData
;
382 //----------------------------------------------------------------------------
383 // wxGnomePrintSetupDialog
384 //----------------------------------------------------------------------------
386 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
388 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
389 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
390 wxPoint(0, 0), wxSize(600, 600),
391 wxDEFAULT_DIALOG_STYLE
|
395 m_printDialogData
= *data
;
400 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
401 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
402 wxPoint(0, 0), wxSize(600, 600),
403 wxDEFAULT_DIALOG_STYLE
|
407 m_printDialogData
= *data
;
412 void wxGnomePrintDialog::Init()
414 wxPrintData data
= m_printDialogData
.GetPrintData();
416 wxGnomePrintNativeData
*native
=
417 (wxGnomePrintNativeData
*) data
.GetNativeData();
419 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
421 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
424 if (m_printDialogData
.GetEnableSelection())
425 flag
|= GNOME_PRINT_RANGE_SELECTION
;
426 if (m_printDialogData
.GetEnablePageNumbers())
427 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
429 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
431 m_printDialogData
.GetMinPage(),
432 m_printDialogData
.GetMaxPage(),
437 wxGnomePrintDialog::~wxGnomePrintDialog()
442 int wxGnomePrintDialog::ShowModal()
444 // Transfer data from m_printDalogData to dialog here
446 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
448 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
450 gtk_widget_destroy(m_widget
);
457 gboolean collate
= false;
458 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
459 m_printDialogData
.SetNoCopies( copies
);
460 m_printDialogData
.SetCollate( collate
);
462 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
464 case GNOME_PRINT_RANGE_SELECTION
:
465 m_printDialogData
.SetSelection( true );
467 case GNOME_PRINT_RANGE_ALL
:
468 m_printDialogData
.SetAllPages( true );
469 m_printDialogData
.SetFromPage( 0 );
470 m_printDialogData
.SetToPage( 9999 );
472 case GNOME_PRINT_RANGE_RANGE
:
475 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
476 m_printDialogData
.SetFromPage( start
);
477 m_printDialogData
.SetToPage( end
);
481 gtk_widget_destroy(m_widget
);
484 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
490 wxDC
*wxGnomePrintDialog::GetPrintDC()
496 bool wxGnomePrintDialog::Validate()
501 bool wxGnomePrintDialog::TransferDataToWindow()
506 bool wxGnomePrintDialog::TransferDataFromWindow()
511 //----------------------------------------------------------------------------
512 // wxGnomePageSetupDialog
513 //----------------------------------------------------------------------------
515 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
517 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
518 wxPageSetupDialogData
* data
)
521 m_pageDialogData
= *data
;
523 wxGnomePrintNativeData
*native
=
524 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
526 // This is required as the page setup dialog
527 // calculates wrong values otherwise.
528 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
529 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
530 (const guchar
*) "Pts" );
532 m_widget
= gtk_dialog_new();
534 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
536 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
537 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
538 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
539 gtk_widget_show (main
);
541 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
543 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
545 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
546 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
547 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
550 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
554 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
558 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
560 return m_pageDialogData
;
563 int wxGnomePageSetupDialog::ShowModal()
565 wxGnomePrintNativeData
*native
=
566 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
567 GnomePrintConfig
*config
= native
->GetPrintConfig();
569 // Transfer data from m_pageDialogData to native dialog
571 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
573 if (ret
== GTK_RESPONSE_OK
)
575 // Transfer data back to m_pageDialogData
577 // I don't know how querying the last parameter works
578 // I cannot test it as the dialog is currently broken
579 // anyways (it only works for points).
580 double ml
,mr
,mt
,mb
,pw
,ph
;
581 gs_lgp
->gnome_print_config_get_length (config
,
582 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
583 gs_lgp
->gnome_print_config_get_length (config
,
584 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
585 gs_lgp
->gnome_print_config_get_length (config
,
586 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
587 gs_lgp
->gnome_print_config_get_length (config
,
588 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
589 gs_lgp
->gnome_print_config_get_length (config
,
590 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
591 gs_lgp
->gnome_print_config_get_length (config
,
592 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
594 // This probably assumes that the user entered the
595 // values in Pts. Since that is the only the dialog
596 // works right now, we need to fix this later.
597 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
598 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
599 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
600 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
601 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
602 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
603 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
604 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
606 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
607 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
609 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
612 wxPrintf( wxT("paper %d %d, top margin %d\n"),
613 m_pageDialogData
.GetPaperSize().x
,
614 m_pageDialogData
.GetPaperSize().y
,
615 m_pageDialogData
.GetMarginTopLeft().x
);
625 gtk_widget_destroy( m_widget
);
631 bool wxGnomePageSetupDialog::Validate()
636 bool wxGnomePageSetupDialog::TransferDataToWindow()
641 bool wxGnomePageSetupDialog::TransferDataFromWindow()
646 //----------------------------------------------------------------------------
648 //----------------------------------------------------------------------------
650 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
652 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
653 wxPrinterBase( data
)
656 m_native_preview
= false;
659 wxGnomePrinter::~wxGnomePrinter()
663 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
667 sm_lastError
= wxPRINTER_ERROR
;
671 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
672 wxGnomePrintNativeData
*native
=
673 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
675 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
676 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
678 // The GnomePrintJob is temporarily stored in the
679 // native print data as the native print dialog
680 // needs to access it.
681 native
->SetPrintJob( job
);
684 printout
->SetIsPreview(false);
686 if (m_printDialogData
.GetMinPage() < 1)
687 m_printDialogData
.SetMinPage(1);
688 if (m_printDialogData
.GetMaxPage() < 1)
689 m_printDialogData
.SetMaxPage(9999);
693 dc
= PrintDialog( parent
);
695 dc
= new wxGnomePrintDC( this );
697 if (m_native_preview
)
698 printout
->SetIsPreview(true);
702 gs_lgp
->gnome_print_job_close( job
);
703 g_object_unref (G_OBJECT (job
));
704 sm_lastError
= wxPRINTER_ERROR
;
708 wxSize ScreenPixels
= wxGetDisplaySize();
709 wxSize ScreenMM
= wxGetDisplaySizeMM();
711 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
712 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
713 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
714 wxGnomePrintDC::GetResolution() );
720 printout
->SetPageSizePixels((int)w
, (int)h
);
721 dc
->GetSizeMM(&w
, &h
);
722 printout
->SetPageSizeMM((int)w
, (int)h
);
724 printout
->OnPreparePrinting();
726 // Get some parameters from the printout, if defined
727 int fromPage
, toPage
;
728 int minPage
, maxPage
;
729 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
733 gs_lgp
->gnome_print_job_close( job
);
734 g_object_unref (G_OBJECT (job
));
735 sm_lastError
= wxPRINTER_ERROR
;
739 printout
->OnBeginPrinting();
741 int minPageNum
= minPage
, maxPageNum
= maxPage
;
743 if ( !m_printDialogData
.GetAllPages() )
745 minPageNum
= m_printDialogData
.GetFromPage();
746 maxPageNum
= m_printDialogData
.GetToPage();
752 copyCount
<= m_printDialogData
.GetNoCopies();
755 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
757 wxLogError(_("Could not start printing."));
758 sm_lastError
= wxPRINTER_ERROR
;
763 for ( pn
= minPageNum
;
764 pn
<= maxPageNum
&& printout
->HasPage(pn
);
768 printout
->OnPrintPage(pn
);
772 printout
->OnEndDocument();
773 printout
->OnEndPrinting();
776 gs_lgp
->gnome_print_job_close( job
);
777 if (m_native_preview
)
779 wxString
title( _("Print preview") );
780 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
784 gs_lgp
->gnome_print_job_print( job
);
787 g_object_unref (G_OBJECT (job
));
790 return (sm_lastError
== wxPRINTER_NO_ERROR
);
793 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
795 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
796 int ret
= dialog
.ShowModal();
797 if (ret
== wxID_CANCEL
)
799 sm_lastError
= wxPRINTER_ERROR
;
803 m_native_preview
= ret
== wxID_PREVIEW
;
805 m_printDialogData
= dialog
.GetPrintDialogData();
806 return new wxGnomePrintDC( this );
809 bool wxGnomePrinter::Setup( wxWindow
*parent
)
814 //-----------------------------------------------------------------------------
816 //-----------------------------------------------------------------------------
818 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
820 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
824 m_gpc
= printer
->GetPrintContext();
826 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
827 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
833 m_signX
= 1; // default x-axis left to right
834 m_signY
= -1; // default y-axis bottom up -> top down
837 wxGnomePrintDC::~wxGnomePrintDC()
841 bool wxGnomePrintDC::Ok() const
846 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
851 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
856 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
858 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
862 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
863 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
864 gs_lgp
->gnome_print_stroke ( m_gpc
);
866 CalcBoundingBox( x1
, y1
);
867 CalcBoundingBox( x2
, y2
);
870 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
874 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
878 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
882 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
886 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
888 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
895 for ( i
=0; i
<n
; i
++ )
896 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
898 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
900 for (i
= 1; i
< n
; i
++)
901 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
903 gs_lgp
->gnome_print_stroke ( m_gpc
);
906 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
910 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
914 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
916 if (m_brush
.GetStyle () != wxTRANSPARENT
)
920 gs_lgp
->gnome_print_newpath( m_gpc
);
921 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
922 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
923 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
924 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
925 gs_lgp
->gnome_print_closepath( m_gpc
);
926 gs_lgp
->gnome_print_fill( m_gpc
);
928 CalcBoundingBox( x
, y
);
929 CalcBoundingBox( x
+ width
, y
+ height
);
932 if (m_pen
.GetStyle () != wxTRANSPARENT
)
936 gs_lgp
->gnome_print_newpath( m_gpc
);
937 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
938 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
939 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
940 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
941 gs_lgp
->gnome_print_closepath( m_gpc
);
942 gs_lgp
->gnome_print_stroke( m_gpc
);
944 CalcBoundingBox( x
, y
);
945 CalcBoundingBox( x
+ width
, y
+ height
);
949 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
953 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
955 if (m_brush
.GetStyle () != wxTRANSPARENT
)
959 gs_lgp
->gnome_print_newpath( m_gpc
);
960 gs_lgp
->gnome_print_moveto( m_gpc
,
961 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
963 // start with top half
964 gs_lgp
->gnome_print_curveto( m_gpc
,
965 XLOG2DEV(x
), YLOG2DEV(y
),
966 XLOG2DEV(x
+width
), YLOG2DEV(y
),
967 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
969 gs_lgp
->gnome_print_curveto( m_gpc
,
970 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
971 XLOG2DEV(x
), YLOG2DEV(y
+height
),
972 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
974 gs_lgp
->gnome_print_closepath( m_gpc
);
975 gs_lgp
->gnome_print_fill( m_gpc
);
977 CalcBoundingBox( x
, y
);
978 CalcBoundingBox( x
+ width
, y
+ height
);
981 if (m_pen
.GetStyle () != wxTRANSPARENT
)
985 gs_lgp
->gnome_print_newpath( m_gpc
);
986 gs_lgp
->gnome_print_moveto( m_gpc
,
987 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
989 // start with top half
990 gs_lgp
->gnome_print_curveto( m_gpc
,
991 XLOG2DEV(x
), YLOG2DEV(y
),
992 XLOG2DEV(x
+width
), YLOG2DEV(y
),
993 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
995 gs_lgp
->gnome_print_curveto( m_gpc
,
996 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
997 XLOG2DEV(x
), YLOG2DEV(y
+height
),
998 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1000 gs_lgp
->gnome_print_closepath( m_gpc
);
1001 gs_lgp
->gnome_print_stroke( m_gpc
);
1003 CalcBoundingBox( x
, y
);
1004 CalcBoundingBox( x
+ width
, y
+ height
);
1008 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1012 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1013 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1014 wxCoord xsrcMask
, wxCoord ysrcMask
)
1019 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1021 DoDrawBitmap( icon
, x
, y
, true );
1024 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1026 if (!bitmap
.Ok()) return;
1028 if (bitmap
.HasPixbuf())
1030 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1031 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1032 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1033 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1034 int height
= gdk_pixbuf_get_height( pixbuf
);
1035 int width
= gdk_pixbuf_get_width( pixbuf
);
1037 gs_lgp
->gnome_print_gsave( m_gpc
);
1039 matrix
[0] = XLOG2DEVREL(width
);
1042 matrix
[3] = YLOG2DEVREL(height
);
1043 matrix
[4] = XLOG2DEV(x
);
1044 matrix
[5] = YLOG2DEV(y
+height
);
1045 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1046 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1048 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1050 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1051 gs_lgp
->gnome_print_grestore( m_gpc
);
1055 wxImage image
= bitmap
.ConvertToImage();
1057 if (!image
.Ok()) return;
1059 gs_lgp
->gnome_print_gsave( m_gpc
);
1061 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1064 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1065 matrix
[4] = XLOG2DEV(x
);
1066 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1067 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1068 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1069 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1070 gs_lgp
->gnome_print_grestore( m_gpc
);
1074 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1076 DoDrawRotatedText( text
, x
, y
, 0.0 );
1079 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1084 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1087 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1089 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1092 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1095 size_t datalen
= strlen((const char*)data
);
1096 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1100 PangoAttrList
*attrs
= pango_attr_list_new();
1101 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1103 a
->end_index
= datalen
;
1104 pango_attr_list_insert(attrs
, a
);
1105 pango_layout_set_attributes(m_layout
, attrs
);
1106 pango_attr_list_unref(attrs
);
1109 if (m_textForegroundColour
.Ok())
1111 unsigned char red
= m_textForegroundColour
.Red();
1112 unsigned char blue
= m_textForegroundColour
.Blue();
1113 unsigned char green
= m_textForegroundColour
.Green();
1115 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1117 double redPS
= (double)(red
) / 255.0;
1118 double bluePS
= (double)(blue
) / 255.0;
1119 double greenPS
= (double)(green
) / 255.0;
1121 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1124 m_currentBlue
= blue
;
1125 m_currentGreen
= green
;
1131 if (fabs(m_scaleY
- 1.0) > 0.00001)
1133 // If there is a user or actually any scale applied to
1134 // the device context, scale the font.
1136 // scale font description
1137 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1138 double size
= oldSize
;
1139 size
= size
* m_scaleY
;
1140 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1142 // actually apply scaled font
1143 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1145 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1147 if ( m_backgroundMode
== wxSOLID
)
1149 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1150 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1151 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1155 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1156 if (fabs(angle
) > 0.00001)
1158 gs_lgp
->gnome_print_gsave( m_gpc
);
1159 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1160 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1161 gs_lgp
->gnome_print_grestore( m_gpc
);
1165 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1168 // reset unscaled size
1169 pango_font_description_set_size( m_fontdesc
, oldSize
);
1171 // actually apply unscaled font
1172 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1176 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1178 if ( m_backgroundMode
== wxSOLID
)
1180 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1181 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1182 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1186 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1187 if (fabs(angle
) > 0.00001)
1189 gs_lgp
->gnome_print_gsave( m_gpc
);
1190 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1191 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1192 gs_lgp
->gnome_print_grestore( m_gpc
);
1196 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1202 // undo underline attributes setting:
1203 pango_layout_set_attributes(m_layout
, NULL
);
1206 CalcBoundingBox (x
+ w
, y
+ h
);
1209 void wxGnomePrintDC::Clear()
1213 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1220 pango_font_description_free( m_fontdesc
);
1222 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1224 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1228 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1230 if (!pen
.Ok()) return;
1234 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1236 static const double dotted
[] = {2.0, 5.0};
1237 static const double short_dashed
[] = {4.0, 4.0};
1238 static const double wxCoord_dashed
[] = {4.0, 8.0};
1239 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1241 switch (m_pen
.GetStyle())
1243 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1244 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1245 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1246 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1249 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1253 unsigned char red
= m_pen
.GetColour().Red();
1254 unsigned char blue
= m_pen
.GetColour().Blue();
1255 unsigned char green
= m_pen
.GetColour().Green();
1257 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1259 double redPS
= (double)(red
) / 255.0;
1260 double bluePS
= (double)(blue
) / 255.0;
1261 double greenPS
= (double)(green
) / 255.0;
1263 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1266 m_currentBlue
= blue
;
1267 m_currentGreen
= green
;
1271 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1273 if (!brush
.Ok()) return;
1278 unsigned char red
= m_brush
.GetColour().Red();
1279 unsigned char blue
= m_brush
.GetColour().Blue();
1280 unsigned char green
= m_brush
.GetColour().Green();
1284 // Anything not white is black
1285 if (! (red
== (unsigned char) 255 &&
1286 blue
== (unsigned char) 255 &&
1287 green
== (unsigned char) 255) )
1289 red
= (unsigned char) 0;
1290 green
= (unsigned char) 0;
1291 blue
= (unsigned char) 0;
1296 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1298 double redPS
= (double)(red
) / 255.0;
1299 double bluePS
= (double)(blue
) / 255.0;
1300 double greenPS
= (double)(green
) / 255.0;
1302 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1305 m_currentBlue
= blue
;
1306 m_currentGreen
= green
;
1310 void wxGnomePrintDC::SetLogicalFunction( int function
)
1314 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1318 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1322 void wxGnomePrintDC::DestroyClippingRegion()
1326 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1328 SetDeviceOrigin( 0,0 );
1333 void wxGnomePrintDC::EndDoc()
1335 gs_lgp
->gnome_print_end_doc( m_gpc
);
1338 void wxGnomePrintDC::StartPage()
1340 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1343 void wxGnomePrintDC::EndPage()
1345 gs_lgp
->gnome_print_showpage( m_gpc
);
1348 wxCoord
wxGnomePrintDC::GetCharHeight() const
1350 pango_layout_set_text( m_layout
, "H", 1 );
1353 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1358 wxCoord
wxGnomePrintDC::GetCharWidth() const
1360 pango_layout_set_text( m_layout
, "H", 1 );
1363 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1368 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1370 wxCoord
*externalLeading
,
1371 wxFont
*theFont
) const
1379 if ( externalLeading
)
1380 *externalLeading
= 0;
1382 if (string
.IsEmpty())
1387 // Set new font description
1389 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1391 // Set layout's text
1393 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1394 const char *dataUTF8
= (const char *)data
;
1396 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1399 if (width
) (*width
) = 0;
1400 if (height
) (*height
) = 0;
1403 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1404 const char *dataUTF8
= (const char *)data
;
1409 // hardly ideal, but what else can we do if conversion failed?
1413 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1416 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1419 *width
= (wxCoord
)(w
/ m_scaleX
);
1421 *height
= (wxCoord
)(h
/ m_scaleY
);
1424 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1425 int baseline
= pango_layout_iter_get_baseline(iter
);
1426 pango_layout_iter_free(iter
);
1427 *descent
= h
- PANGO_PIXELS(baseline
);
1430 // Reset old font description
1432 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1435 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1437 wxGnomePrintNativeData
*native
=
1438 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1440 // Query page size. This seems to omit the margins
1441 // right now, although it shouldn't
1443 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1446 *width
= (int) (pw
+ 0.5);
1448 *height
= (int) (ph
+ 0.5);
1451 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1453 wxGnomePrintNativeData
*native
=
1454 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1456 // This code assumes values in Pts.
1459 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1463 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1464 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1465 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1466 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1469 *width
= (int) (pw
+ 0.5);
1471 *height
= (int) (ph
+ 0.5);
1474 wxSize
wxGnomePrintDC::GetPPI() const
1476 return wxSize(72,72);
1479 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1481 m_signX
= (xLeftRight
? 1 : -1);
1482 m_signY
= (yBottomUp
? 1 : -1);
1484 ComputeScaleAndOrigin();
1487 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1493 wxDC::SetDeviceOrigin( x
, h
-y
);
1496 void wxGnomePrintDC::SetResolution(int ppi
)
1500 int wxGnomePrintDC::GetResolution()
1506 class wxGnomePrintModule
: public wxModule
1509 wxGnomePrintModule() {}
1514 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1517 bool wxGnomePrintModule::OnInit()
1519 gs_lgp
= new wxGnomePrintLibrary
;
1521 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1525 void wxGnomePrintModule::OnExit()
1530 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1533 // wxUSE_LIBGNOMEPRINT