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
26 #include "wx/fontutil.h"
27 #include "wx/printdlg.h"
28 #include "wx/gtk/private.h"
29 #include "wx/module.h"
30 #include "wx/generic/prntdlgg.h"
31 #include "wx/dynlib.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>
41 #include "wx/html/forcelnk.h"
42 FORCE_LINK_ME(gnome_print
)
44 //----------------------------------------------------------------------------
45 // wxGnomePrintLibrary
46 //----------------------------------------------------------------------------
48 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
49 typedef rettype (* name ## Type) args ; \
50 name ## Type pfn_ ## name; \
52 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
54 #define wxDL_METHOD_LOAD( lib, name, success ) \
55 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
58 class wxGnomePrintLibrary
61 wxGnomePrintLibrary();
62 ~wxGnomePrintLibrary();
65 void InitializeMethods();
69 wxDynamicLibrary
*m_gnome_print_lib
;
70 wxDynamicLibrary
*m_gnome_printui_lib
;
73 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
74 (GnomePrintContext
*pc
), (pc
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
76 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
78 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
80 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
82 (GnomePrintContext
*pc
), (pc
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
84 (GnomePrintContext
*pc
), (pc
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
86 (GnomePrintContext
*pc
), (pc
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
88 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
90 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
91 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
92 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
95 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
97 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
100 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
102 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
104 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
107 (GnomePrintContext
*pc
), (pc
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
109 (GnomePrintContext
*pc
), (pc
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
112 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
116 (GnomePrintContext
*pc
), (pc
), 0 )
118 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
119 (GnomePrintContext
*gpc
), (gpc
), NULL
)
120 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
121 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
123 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
124 (GnomePrintConfig
*config
), (config
), NULL
)
125 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
126 (GnomePrintJob
*job
), (job
), NULL
)
127 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
128 (GnomePrintJob
*job
), (job
), 0 )
129 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
130 (GnomePrintJob
*job
), (job
), 0 )
131 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
132 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
134 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
135 (const guchar
*abbreviation
), (abbreviation
), NULL
)
136 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
137 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
139 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
141 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
142 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
143 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
144 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
146 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
147 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
148 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
149 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
150 const guchar
*currentlabel
, const guchar
*rangelabel
),
151 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
152 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
153 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
154 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
155 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
156 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
157 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
158 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
159 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
161 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
162 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
164 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
165 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
168 wxGnomePrintLibrary::wxGnomePrintLibrary()
170 m_gnome_print_lib
= NULL
;
171 m_gnome_printui_lib
= NULL
;
175 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so") );
176 m_ok
= m_gnome_print_lib
->IsLoaded();
179 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so") );
180 m_ok
= m_gnome_printui_lib
->IsLoaded();
186 wxGnomePrintLibrary::~wxGnomePrintLibrary()
188 if (m_gnome_print_lib
)
189 delete m_gnome_print_lib
;
190 if (m_gnome_printui_lib
)
191 delete m_gnome_printui_lib
;
194 bool wxGnomePrintLibrary::IsOk()
199 void wxGnomePrintLibrary::InitializeMethods()
204 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
205 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
206 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
207 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
208 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
209 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
210 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
225 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
245 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
246 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
247 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
248 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
249 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
250 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
252 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
254 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
259 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
261 //----------------------------------------------------------------------------
262 // wxGnomePrintNativeData
263 //----------------------------------------------------------------------------
265 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
267 wxGnomePrintNativeData::wxGnomePrintNativeData()
269 m_config
= gs_lgp
->gnome_print_config_default();
270 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
273 wxGnomePrintNativeData::~wxGnomePrintNativeData()
275 g_object_unref (G_OBJECT (m_config
));
278 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
284 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
290 //----------------------------------------------------------------------------
291 // wxGnomePrintFactory
292 //----------------------------------------------------------------------------
294 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
296 return new wxGnomePrinter( data
);
299 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
300 wxPrintout
*printout
,
301 wxPrintDialogData
*data
)
303 return new wxPostScriptPrintPreview( preview
, printout
, data
);
306 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
307 wxPrintout
*printout
,
310 return new wxPostScriptPrintPreview( preview
, printout
, data
);
313 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
314 wxPrintDialogData
*data
)
316 return new wxGnomePrintDialog( parent
, data
);
319 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
322 return new wxGnomePrintDialog( parent
, data
);
325 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
326 wxPageSetupDialogData
* data
)
328 // The native page setup dialog is broken. It
329 // miscalculates newly entered values for the
330 // margins if you have not chose "points" but
331 // e.g. centimerters.
332 // This has been fixed in GNOME CVS (maybe
333 // fixed in libgnomeprintui 2.8.1)
335 return new wxGnomePageSetupDialog( parent
, data
);
338 bool wxGnomePrintFactory::HasPrintSetupDialog()
343 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
348 bool wxGnomePrintFactory::HasOwnPrintToFile()
353 bool wxGnomePrintFactory::HasPrinterLine()
358 wxString
wxGnomePrintFactory::CreatePrinterLine()
361 return wxEmptyString
;
364 bool wxGnomePrintFactory::HasStatusLine()
370 wxString
wxGnomePrintFactory::CreateStatusLine()
373 return wxEmptyString
;
376 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
378 return new wxGnomePrintNativeData
;
381 //----------------------------------------------------------------------------
382 // wxGnomePrintSetupDialog
383 //----------------------------------------------------------------------------
385 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
387 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
388 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
389 wxPoint(0, 0), wxSize(600, 600),
390 wxDEFAULT_DIALOG_STYLE
|
394 m_printDialogData
= *data
;
399 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
400 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
401 wxPoint(0, 0), wxSize(600, 600),
402 wxDEFAULT_DIALOG_STYLE
|
406 m_printDialogData
= *data
;
411 void wxGnomePrintDialog::Init()
413 wxPrintData data
= m_printDialogData
.GetPrintData();
415 wxGnomePrintNativeData
*native
=
416 (wxGnomePrintNativeData
*) data
.GetNativeData();
418 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
420 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
423 if (m_printDialogData
.GetEnableSelection())
424 flag
|= GNOME_PRINT_RANGE_SELECTION
;
425 if (m_printDialogData
.GetEnablePageNumbers())
426 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
428 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
430 m_printDialogData
.GetMinPage(),
431 m_printDialogData
.GetMaxPage(),
436 wxGnomePrintDialog::~wxGnomePrintDialog()
441 int wxGnomePrintDialog::ShowModal()
443 // Transfer data from m_printDalogData to dialog here
445 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
447 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
449 gtk_widget_destroy(m_widget
);
456 gboolean collate
= false;
457 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
458 m_printDialogData
.SetNoCopies( copies
);
459 m_printDialogData
.SetCollate( collate
);
461 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
463 case GNOME_PRINT_RANGE_SELECTION
:
464 m_printDialogData
.SetSelection( true );
466 case GNOME_PRINT_RANGE_ALL
:
467 m_printDialogData
.SetAllPages( true );
468 m_printDialogData
.SetFromPage( 0 );
469 m_printDialogData
.SetToPage( 9999 );
471 case GNOME_PRINT_RANGE_RANGE
:
474 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
475 m_printDialogData
.SetFromPage( start
);
476 m_printDialogData
.SetToPage( end
);
480 gtk_widget_destroy(m_widget
);
483 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
489 wxDC
*wxGnomePrintDialog::GetPrintDC()
495 bool wxGnomePrintDialog::Validate()
500 bool wxGnomePrintDialog::TransferDataToWindow()
505 bool wxGnomePrintDialog::TransferDataFromWindow()
510 //----------------------------------------------------------------------------
511 // wxGnomePageSetupDialog
512 //----------------------------------------------------------------------------
514 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
516 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
517 wxPageSetupDialogData
* data
)
520 m_pageDialogData
= *data
;
522 wxGnomePrintNativeData
*native
=
523 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
525 // This is required as the page setup dialog
526 // calculates wrong values otherwise.
527 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
528 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
529 (const guchar
*) "Pts" );
531 m_widget
= gtk_dialog_new();
533 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
535 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
536 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
537 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
538 gtk_widget_show (main
);
540 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
542 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
544 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
545 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
546 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
549 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
553 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
557 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
559 return m_pageDialogData
;
562 int wxGnomePageSetupDialog::ShowModal()
564 wxGnomePrintNativeData
*native
=
565 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
566 GnomePrintConfig
*config
= native
->GetPrintConfig();
568 // Transfer data from m_pageDialogData to native dialog
570 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
572 if (ret
== GTK_RESPONSE_OK
)
574 // Transfer data back to m_pageDialogData
576 // I don't know how querying the last parameter works
577 // I cannot test it as the dialog is currently broken
578 // anyways (it only works for points).
579 double ml
,mr
,mt
,mb
,pw
,ph
;
580 gs_lgp
->gnome_print_config_get_length (config
,
581 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
582 gs_lgp
->gnome_print_config_get_length (config
,
583 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
584 gs_lgp
->gnome_print_config_get_length (config
,
585 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
586 gs_lgp
->gnome_print_config_get_length (config
,
587 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
588 gs_lgp
->gnome_print_config_get_length (config
,
589 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
590 gs_lgp
->gnome_print_config_get_length (config
,
591 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
593 // This probably assumes that the user entered the
594 // values in Pts. Since that is the only the dialog
595 // works right now, we need to fix this later.
596 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
597 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
598 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
599 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
600 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
601 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
602 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
603 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
605 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
606 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
608 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
611 wxPrintf( wxT("paper %d %d, top margin %d\n"),
612 m_pageDialogData
.GetPaperSize().x
,
613 m_pageDialogData
.GetPaperSize().y
,
614 m_pageDialogData
.GetMarginTopLeft().x
);
624 gtk_widget_destroy( m_widget
);
630 bool wxGnomePageSetupDialog::Validate()
635 bool wxGnomePageSetupDialog::TransferDataToWindow()
640 bool wxGnomePageSetupDialog::TransferDataFromWindow()
645 //----------------------------------------------------------------------------
647 //----------------------------------------------------------------------------
649 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
651 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
652 wxPrinterBase( data
)
655 m_native_preview
= false;
658 wxGnomePrinter::~wxGnomePrinter()
662 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
666 sm_lastError
= wxPRINTER_ERROR
;
670 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
671 wxGnomePrintNativeData
*native
=
672 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
674 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
675 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
677 // The GnomePrintJob is temporarily stored in the
678 // native print data as the native print dialog
679 // needs to access it.
680 native
->SetPrintJob( job
);
683 printout
->SetIsPreview(false);
685 if (m_printDialogData
.GetMinPage() < 1)
686 m_printDialogData
.SetMinPage(1);
687 if (m_printDialogData
.GetMaxPage() < 1)
688 m_printDialogData
.SetMaxPage(9999);
692 dc
= PrintDialog( parent
);
694 dc
= new wxGnomePrintDC( this );
696 if (m_native_preview
)
697 printout
->SetIsPreview(true);
701 gs_lgp
->gnome_print_job_close( job
);
702 g_object_unref (G_OBJECT (job
));
703 sm_lastError
= wxPRINTER_ERROR
;
707 wxSize ScreenPixels
= wxGetDisplaySize();
708 wxSize ScreenMM
= wxGetDisplaySizeMM();
710 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
711 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
712 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
713 wxGnomePrintDC::GetResolution() );
719 printout
->SetPageSizePixels((int)w
, (int)h
);
720 dc
->GetSizeMM(&w
, &h
);
721 printout
->SetPageSizeMM((int)w
, (int)h
);
723 printout
->OnPreparePrinting();
725 // Get some parameters from the printout, if defined
726 int fromPage
, toPage
;
727 int minPage
, maxPage
;
728 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
732 gs_lgp
->gnome_print_job_close( job
);
733 g_object_unref (G_OBJECT (job
));
734 sm_lastError
= wxPRINTER_ERROR
;
738 printout
->OnBeginPrinting();
740 int minPageNum
= minPage
, maxPageNum
= maxPage
;
742 if ( !m_printDialogData
.GetAllPages() )
744 minPageNum
= m_printDialogData
.GetFromPage();
745 maxPageNum
= m_printDialogData
.GetToPage();
751 copyCount
<= m_printDialogData
.GetNoCopies();
754 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
756 wxLogError(_("Could not start printing."));
757 sm_lastError
= wxPRINTER_ERROR
;
762 for ( pn
= minPageNum
;
763 pn
<= maxPageNum
&& printout
->HasPage(pn
);
767 printout
->OnPrintPage(pn
);
771 printout
->OnEndDocument();
772 printout
->OnEndPrinting();
775 gs_lgp
->gnome_print_job_close( job
);
776 if (m_native_preview
)
778 wxString
title( _("Print preview") );
779 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
783 gs_lgp
->gnome_print_job_print( job
);
786 g_object_unref (G_OBJECT (job
));
789 return (sm_lastError
== wxPRINTER_NO_ERROR
);
792 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
794 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
795 int ret
= dialog
.ShowModal();
796 if (ret
== wxID_CANCEL
)
798 sm_lastError
= wxPRINTER_CANCELLED
;
802 m_native_preview
= ret
== wxID_PREVIEW
;
804 m_printDialogData
= dialog
.GetPrintDialogData();
805 return new wxGnomePrintDC( this );
808 bool wxGnomePrinter::Setup( wxWindow
*parent
)
813 //-----------------------------------------------------------------------------
815 //-----------------------------------------------------------------------------
817 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
819 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
823 m_gpc
= printer
->GetPrintContext();
825 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
826 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
832 m_signX
= 1; // default x-axis left to right
833 m_signY
= -1; // default y-axis bottom up -> top down
836 wxGnomePrintDC::~wxGnomePrintDC()
840 bool wxGnomePrintDC::Ok() const
845 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
850 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
855 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
857 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
861 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
862 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
863 gs_lgp
->gnome_print_stroke ( m_gpc
);
865 CalcBoundingBox( x1
, y1
);
866 CalcBoundingBox( x2
, y2
);
869 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
873 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
877 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
881 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
885 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
887 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
894 for ( i
=0; i
<n
; i
++ )
895 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
897 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
899 for (i
= 1; i
< n
; i
++)
900 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
902 gs_lgp
->gnome_print_stroke ( m_gpc
);
905 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
909 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
913 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
915 if (m_brush
.GetStyle () != wxTRANSPARENT
)
919 gs_lgp
->gnome_print_newpath( m_gpc
);
920 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
921 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
922 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
923 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
924 gs_lgp
->gnome_print_closepath( m_gpc
);
925 gs_lgp
->gnome_print_fill( m_gpc
);
927 CalcBoundingBox( x
, y
);
928 CalcBoundingBox( x
+ width
, y
+ height
);
931 if (m_pen
.GetStyle () != wxTRANSPARENT
)
935 gs_lgp
->gnome_print_newpath( m_gpc
);
936 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
937 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
938 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
939 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
940 gs_lgp
->gnome_print_closepath( m_gpc
);
941 gs_lgp
->gnome_print_stroke( m_gpc
);
943 CalcBoundingBox( x
, y
);
944 CalcBoundingBox( x
+ width
, y
+ height
);
948 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
952 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
954 if (m_brush
.GetStyle () != wxTRANSPARENT
)
958 gs_lgp
->gnome_print_newpath( m_gpc
);
959 gs_lgp
->gnome_print_moveto( m_gpc
,
960 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
962 // start with top half
963 gs_lgp
->gnome_print_curveto( m_gpc
,
964 XLOG2DEV(x
), YLOG2DEV(y
),
965 XLOG2DEV(x
+width
), YLOG2DEV(y
),
966 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
968 gs_lgp
->gnome_print_curveto( m_gpc
,
969 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
970 XLOG2DEV(x
), YLOG2DEV(y
+height
),
971 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
973 gs_lgp
->gnome_print_closepath( m_gpc
);
974 gs_lgp
->gnome_print_fill( m_gpc
);
976 CalcBoundingBox( x
, y
);
977 CalcBoundingBox( x
+ width
, y
+ height
);
980 if (m_pen
.GetStyle () != wxTRANSPARENT
)
984 gs_lgp
->gnome_print_newpath( m_gpc
);
985 gs_lgp
->gnome_print_moveto( m_gpc
,
986 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
988 // start with top half
989 gs_lgp
->gnome_print_curveto( m_gpc
,
990 XLOG2DEV(x
), YLOG2DEV(y
),
991 XLOG2DEV(x
+width
), YLOG2DEV(y
),
992 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
994 gs_lgp
->gnome_print_curveto( m_gpc
,
995 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
996 XLOG2DEV(x
), YLOG2DEV(y
+height
),
997 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
999 gs_lgp
->gnome_print_closepath( m_gpc
);
1000 gs_lgp
->gnome_print_stroke( m_gpc
);
1002 CalcBoundingBox( x
, y
);
1003 CalcBoundingBox( x
+ width
, y
+ height
);
1007 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1011 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1012 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1013 wxCoord xsrcMask
, wxCoord ysrcMask
)
1018 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1020 DoDrawBitmap( icon
, x
, y
, true );
1023 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1025 if (!bitmap
.Ok()) return;
1027 if (bitmap
.HasPixbuf())
1029 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1030 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1031 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1032 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1033 int height
= gdk_pixbuf_get_height( pixbuf
);
1034 int width
= gdk_pixbuf_get_width( pixbuf
);
1036 gs_lgp
->gnome_print_gsave( m_gpc
);
1038 matrix
[0] = XLOG2DEVREL(width
);
1041 matrix
[3] = YLOG2DEVREL(height
);
1042 matrix
[4] = XLOG2DEV(x
);
1043 matrix
[5] = YLOG2DEV(y
+height
);
1044 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1045 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1047 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1049 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1050 gs_lgp
->gnome_print_grestore( m_gpc
);
1054 wxImage image
= bitmap
.ConvertToImage();
1056 if (!image
.Ok()) return;
1058 gs_lgp
->gnome_print_gsave( m_gpc
);
1060 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1063 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1064 matrix
[4] = XLOG2DEV(x
);
1065 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1066 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1067 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1068 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1069 gs_lgp
->gnome_print_grestore( m_gpc
);
1073 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1075 DoDrawRotatedText( text
, x
, y
, 0.0 );
1078 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1083 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1086 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1088 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1091 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1094 size_t datalen
= strlen((const char*)data
);
1095 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1099 PangoAttrList
*attrs
= pango_attr_list_new();
1100 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1102 a
->end_index
= datalen
;
1103 pango_attr_list_insert(attrs
, a
);
1104 pango_layout_set_attributes(m_layout
, attrs
);
1105 pango_attr_list_unref(attrs
);
1108 if (m_textForegroundColour
.Ok())
1110 unsigned char red
= m_textForegroundColour
.Red();
1111 unsigned char blue
= m_textForegroundColour
.Blue();
1112 unsigned char green
= m_textForegroundColour
.Green();
1114 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1116 double redPS
= (double)(red
) / 255.0;
1117 double bluePS
= (double)(blue
) / 255.0;
1118 double greenPS
= (double)(green
) / 255.0;
1120 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1123 m_currentBlue
= blue
;
1124 m_currentGreen
= green
;
1130 if (fabs(m_scaleY
- 1.0) > 0.00001)
1132 // If there is a user or actually any scale applied to
1133 // the device context, scale the font.
1135 // scale font description
1136 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1137 double size
= oldSize
;
1138 size
= size
* m_scaleY
;
1139 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1141 // actually apply scaled font
1142 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1144 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1146 if ( m_backgroundMode
== wxSOLID
)
1148 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1149 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1150 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1154 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1155 if (fabs(angle
) > 0.00001)
1157 gs_lgp
->gnome_print_gsave( m_gpc
);
1158 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1159 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1160 gs_lgp
->gnome_print_grestore( m_gpc
);
1164 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1167 // reset unscaled size
1168 pango_font_description_set_size( m_fontdesc
, oldSize
);
1170 // actually apply unscaled font
1171 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1175 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1177 if ( m_backgroundMode
== wxSOLID
)
1179 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1180 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1181 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1185 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1186 if (fabs(angle
) > 0.00001)
1188 gs_lgp
->gnome_print_gsave( m_gpc
);
1189 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1190 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1191 gs_lgp
->gnome_print_grestore( m_gpc
);
1195 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1201 // undo underline attributes setting:
1202 pango_layout_set_attributes(m_layout
, NULL
);
1205 CalcBoundingBox (x
+ w
, y
+ h
);
1208 void wxGnomePrintDC::Clear()
1212 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1219 pango_font_description_free( m_fontdesc
);
1221 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1223 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1227 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1229 if (!pen
.Ok()) return;
1233 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1235 static const double dotted
[] = {2.0, 5.0};
1236 static const double short_dashed
[] = {4.0, 4.0};
1237 static const double wxCoord_dashed
[] = {4.0, 8.0};
1238 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1240 switch (m_pen
.GetStyle())
1242 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1243 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1244 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1245 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1248 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1252 unsigned char red
= m_pen
.GetColour().Red();
1253 unsigned char blue
= m_pen
.GetColour().Blue();
1254 unsigned char green
= m_pen
.GetColour().Green();
1256 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1258 double redPS
= (double)(red
) / 255.0;
1259 double bluePS
= (double)(blue
) / 255.0;
1260 double greenPS
= (double)(green
) / 255.0;
1262 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1265 m_currentBlue
= blue
;
1266 m_currentGreen
= green
;
1270 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1272 if (!brush
.Ok()) return;
1277 unsigned char red
= m_brush
.GetColour().Red();
1278 unsigned char blue
= m_brush
.GetColour().Blue();
1279 unsigned char green
= m_brush
.GetColour().Green();
1283 // Anything not white is black
1284 if (! (red
== (unsigned char) 255 &&
1285 blue
== (unsigned char) 255 &&
1286 green
== (unsigned char) 255) )
1288 red
= (unsigned char) 0;
1289 green
= (unsigned char) 0;
1290 blue
= (unsigned char) 0;
1295 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1297 double redPS
= (double)(red
) / 255.0;
1298 double bluePS
= (double)(blue
) / 255.0;
1299 double greenPS
= (double)(green
) / 255.0;
1301 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1304 m_currentBlue
= blue
;
1305 m_currentGreen
= green
;
1309 void wxGnomePrintDC::SetLogicalFunction( int function
)
1313 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1317 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1321 void wxGnomePrintDC::DestroyClippingRegion()
1325 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1327 SetDeviceOrigin( 0,0 );
1332 void wxGnomePrintDC::EndDoc()
1334 gs_lgp
->gnome_print_end_doc( m_gpc
);
1337 void wxGnomePrintDC::StartPage()
1339 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1342 void wxGnomePrintDC::EndPage()
1344 gs_lgp
->gnome_print_showpage( m_gpc
);
1347 wxCoord
wxGnomePrintDC::GetCharHeight() const
1349 pango_layout_set_text( m_layout
, "H", 1 );
1352 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1357 wxCoord
wxGnomePrintDC::GetCharWidth() const
1359 pango_layout_set_text( m_layout
, "H", 1 );
1362 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1367 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1369 wxCoord
*externalLeading
,
1370 wxFont
*theFont
) const
1378 if ( externalLeading
)
1379 *externalLeading
= 0;
1381 if (string
.IsEmpty())
1386 // Set new font description
1388 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1390 // Set layout's text
1392 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1393 const char *dataUTF8
= (const char *)data
;
1395 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1398 if (width
) (*width
) = 0;
1399 if (height
) (*height
) = 0;
1402 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1403 const char *dataUTF8
= (const char *)data
;
1408 // hardly ideal, but what else can we do if conversion failed?
1412 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1415 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1418 *width
= (wxCoord
)(w
/ m_scaleX
);
1420 *height
= (wxCoord
)(h
/ m_scaleY
);
1423 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1424 int baseline
= pango_layout_iter_get_baseline(iter
);
1425 pango_layout_iter_free(iter
);
1426 *descent
= h
- PANGO_PIXELS(baseline
);
1429 // Reset old font description
1431 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1434 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1436 wxGnomePrintNativeData
*native
=
1437 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1439 // Query page size. This seems to omit the margins
1440 // right now, although it shouldn't
1442 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1445 *width
= (int) (pw
+ 0.5);
1447 *height
= (int) (ph
+ 0.5);
1450 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1452 wxGnomePrintNativeData
*native
=
1453 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1455 // This code assumes values in Pts.
1458 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1462 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1463 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1464 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1465 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1468 *width
= (int) (pw
+ 0.5);
1470 *height
= (int) (ph
+ 0.5);
1473 wxSize
wxGnomePrintDC::GetPPI() const
1475 return wxSize(72,72);
1478 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1480 m_signX
= (xLeftRight
? 1 : -1);
1481 m_signY
= (yBottomUp
? 1 : -1);
1483 ComputeScaleAndOrigin();
1486 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1492 wxDC::SetDeviceOrigin( x
, h
-y
);
1495 void wxGnomePrintDC::SetResolution(int ppi
)
1499 int wxGnomePrintDC::GetResolution()
1505 class wxGnomePrintModule
: public wxModule
1508 wxGnomePrintModule() {}
1513 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1516 bool wxGnomePrintModule::OnInit()
1518 gs_lgp
= new wxGnomePrintLibrary
;
1520 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1524 void wxGnomePrintModule::OnExit()
1529 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1532 // wxUSE_LIBGNOMEPRINT