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>
41 //----------------------------------------------------------------------------
42 // wxGnomePrintLibrary
43 //----------------------------------------------------------------------------
45 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
46 typedef rettype (* name ## Type) args ; \
47 name ## Type pfn_ ## name; \
49 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
51 #define wxDL_METHOD_LOAD( lib, name, success ) \
52 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
55 class wxGnomePrintLibrary
58 wxGnomePrintLibrary();
59 ~wxGnomePrintLibrary();
62 void InitializeMethods();
66 wxDynamicLibrary
*m_gnome_print_lib
;
67 wxDynamicLibrary
*m_gnome_printui_lib
;
70 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
71 (GnomePrintContext
*pc
), (pc
), 0 )
72 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
73 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
74 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
75 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
76 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
77 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
79 (GnomePrintContext
*pc
), (pc
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
81 (GnomePrintContext
*pc
), (pc
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
83 (GnomePrintContext
*pc
), (pc
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
85 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
87 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
89 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
91 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
92 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
93 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
94 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
97 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
98 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
99 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
100 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
101 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
104 (GnomePrintContext
*pc
), (pc
), 0 )
105 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
106 (GnomePrintContext
*pc
), (pc
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
109 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
110 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
111 (GnomePrintContext
*pc
), (pc
), 0 )
112 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
113 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
116 (GnomePrintContext
*gpc
), (gpc
), NULL
)
117 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
118 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
120 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
121 (GnomePrintConfig
*config
), (config
), NULL
)
122 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
123 (GnomePrintJob
*job
), (job
), NULL
)
124 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
125 (GnomePrintJob
*job
), (job
), 0 )
126 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
127 (GnomePrintJob
*job
), (job
), 0 )
128 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
129 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
131 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
132 (const guchar
*abbreviation
), (abbreviation
), NULL
)
133 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
134 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
136 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
138 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
139 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
140 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
141 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
143 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
144 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
145 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
146 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
147 const guchar
*currentlabel
, const guchar
*rangelabel
),
148 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
149 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
150 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
151 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
152 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
153 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
154 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
155 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
156 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
158 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
159 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
161 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
162 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
165 wxGnomePrintLibrary::wxGnomePrintLibrary()
167 m_gnome_print_lib
= NULL
;
168 m_gnome_printui_lib
= NULL
;
172 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so") );
173 m_ok
= m_gnome_print_lib
->IsLoaded();
176 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so") );
177 m_ok
= m_gnome_printui_lib
->IsLoaded();
183 wxGnomePrintLibrary::~wxGnomePrintLibrary()
185 if (m_gnome_print_lib
)
186 delete m_gnome_print_lib
;
187 if (m_gnome_printui_lib
)
188 delete m_gnome_printui_lib
;
191 bool wxGnomePrintLibrary::IsOk()
196 void wxGnomePrintLibrary::InitializeMethods()
201 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
202 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
203 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
204 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
205 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
206 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
207 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
208 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
209 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
210 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
242 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
243 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
244 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
245 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
246 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
247 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
249 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
251 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
256 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
258 //----------------------------------------------------------------------------
259 // wxGnomePrintNativeData
260 //----------------------------------------------------------------------------
262 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
264 wxGnomePrintNativeData::wxGnomePrintNativeData()
266 m_config
= gs_lgp
->gnome_print_config_default();
267 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
270 wxGnomePrintNativeData::~wxGnomePrintNativeData()
272 g_object_unref (G_OBJECT (m_config
));
275 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
281 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
287 //----------------------------------------------------------------------------
288 // wxGnomePrintFactory
289 //----------------------------------------------------------------------------
291 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
293 return new wxGnomePrinter( data
);
296 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
297 wxPrintout
*printout
,
298 wxPrintDialogData
*data
)
300 return new wxPostScriptPrintPreview( preview
, printout
, data
);
303 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
304 wxPrintout
*printout
,
307 return new wxPostScriptPrintPreview( preview
, printout
, data
);
310 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
311 wxPrintDialogData
*data
)
313 return new wxGnomePrintDialog( parent
, data
);
316 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
319 return new wxGnomePrintDialog( parent
, data
);
322 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
323 wxPageSetupDialogData
* data
)
325 // The native page setup dialog is broken. It
326 // miscalculates newly entered values for the
327 // margins if you have not chose "points" but
328 // e.g. centimerters.
329 // This has been fixed in GNOME CVS (maybe
330 // fixed in libgnomeprintui 2.8.1)
332 return new wxGnomePageSetupDialog( parent
, data
);
335 bool wxGnomePrintFactory::HasPrintSetupDialog()
340 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
345 bool wxGnomePrintFactory::HasOwnPrintToFile()
350 bool wxGnomePrintFactory::HasPrinterLine()
355 wxString
wxGnomePrintFactory::CreatePrinterLine()
358 return wxEmptyString
;
361 bool wxGnomePrintFactory::HasStatusLine()
367 wxString
wxGnomePrintFactory::CreateStatusLine()
370 return wxEmptyString
;
373 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
375 return new wxGnomePrintNativeData
;
378 //----------------------------------------------------------------------------
379 // wxGnomePrintSetupDialog
380 //----------------------------------------------------------------------------
382 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
384 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
385 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
386 wxPoint(0, 0), wxSize(600, 600),
387 wxDEFAULT_DIALOG_STYLE
|
391 m_printDialogData
= *data
;
396 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
397 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
398 wxPoint(0, 0), wxSize(600, 600),
399 wxDEFAULT_DIALOG_STYLE
|
403 m_printDialogData
= *data
;
408 void wxGnomePrintDialog::Init()
410 wxPrintData data
= m_printDialogData
.GetPrintData();
412 wxGnomePrintNativeData
*native
=
413 (wxGnomePrintNativeData
*) data
.GetNativeData();
415 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
417 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
420 if (m_printDialogData
.GetEnableSelection())
421 flag
|= GNOME_PRINT_RANGE_SELECTION
;
422 if (m_printDialogData
.GetEnablePageNumbers())
423 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
425 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
427 m_printDialogData
.GetMinPage(),
428 m_printDialogData
.GetMaxPage(),
433 wxGnomePrintDialog::~wxGnomePrintDialog()
438 int wxGnomePrintDialog::ShowModal()
440 // Transfer data from m_printDalogData to dialog here
442 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
444 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
446 gtk_widget_destroy(m_widget
);
453 gboolean collate
= false;
454 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
455 m_printDialogData
.SetNoCopies( copies
);
456 m_printDialogData
.SetCollate( collate
);
458 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
460 case GNOME_PRINT_RANGE_SELECTION
:
461 m_printDialogData
.SetSelection( true );
463 case GNOME_PRINT_RANGE_ALL
:
464 m_printDialogData
.SetAllPages( true );
465 m_printDialogData
.SetFromPage( 0 );
466 m_printDialogData
.SetToPage( 9999 );
468 case GNOME_PRINT_RANGE_RANGE
:
471 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
472 m_printDialogData
.SetFromPage( start
);
473 m_printDialogData
.SetToPage( end
);
477 gtk_widget_destroy(m_widget
);
480 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
486 wxDC
*wxGnomePrintDialog::GetPrintDC()
492 bool wxGnomePrintDialog::Validate()
497 bool wxGnomePrintDialog::TransferDataToWindow()
502 bool wxGnomePrintDialog::TransferDataFromWindow()
507 //----------------------------------------------------------------------------
508 // wxGnomePageSetupDialog
509 //----------------------------------------------------------------------------
511 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
513 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
514 wxPageSetupDialogData
* data
)
517 m_pageDialogData
= *data
;
519 wxGnomePrintNativeData
*native
=
520 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
522 // This is required as the page setup dialog
523 // calculates wrong values otherwise.
524 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
525 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
526 (const guchar
*) "Pts" );
528 m_widget
= gtk_dialog_new();
530 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
532 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
533 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
534 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
535 gtk_widget_show (main
);
537 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
539 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
541 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
542 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
543 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
546 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
550 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
554 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
556 return m_pageDialogData
;
559 int wxGnomePageSetupDialog::ShowModal()
561 wxGnomePrintNativeData
*native
=
562 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
563 GnomePrintConfig
*config
= native
->GetPrintConfig();
565 // Transfer data from m_pageDialogData to native dialog
567 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
569 if (ret
== GTK_RESPONSE_OK
)
571 // Transfer data back to m_pageDialogData
573 // I don't know how querying the last parameter works
574 // I cannot test it as the dialog is currently broken
575 // anyways (it only works for points).
576 double ml
,mr
,mt
,mb
,pw
,ph
;
577 gs_lgp
->gnome_print_config_get_length (config
,
578 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
579 gs_lgp
->gnome_print_config_get_length (config
,
580 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
581 gs_lgp
->gnome_print_config_get_length (config
,
582 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
583 gs_lgp
->gnome_print_config_get_length (config
,
584 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
585 gs_lgp
->gnome_print_config_get_length (config
,
586 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
587 gs_lgp
->gnome_print_config_get_length (config
,
588 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
590 // This probably assumes that the user entered the
591 // values in Pts. Since that is the only the dialog
592 // works right now, we need to fix this later.
593 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
594 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
595 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
596 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
597 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
598 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
599 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
600 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
602 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
603 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
605 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
608 wxPrintf( wxT("paper %d %d, top margin %d\n"),
609 m_pageDialogData
.GetPaperSize().x
,
610 m_pageDialogData
.GetPaperSize().y
,
611 m_pageDialogData
.GetMarginTopLeft().x
);
621 gtk_widget_destroy( m_widget
);
627 bool wxGnomePageSetupDialog::Validate()
632 bool wxGnomePageSetupDialog::TransferDataToWindow()
637 bool wxGnomePageSetupDialog::TransferDataFromWindow()
642 //----------------------------------------------------------------------------
644 //----------------------------------------------------------------------------
646 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
648 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
649 wxPrinterBase( data
)
652 m_native_preview
= false;
655 wxGnomePrinter::~wxGnomePrinter()
659 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
663 sm_lastError
= wxPRINTER_ERROR
;
667 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
668 wxGnomePrintNativeData
*native
=
669 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
671 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
672 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
674 // The GnomePrintJob is temporarily stored in the
675 // native print data as the native print dialog
676 // needs to access it.
677 native
->SetPrintJob( job
);
680 printout
->SetIsPreview(false);
682 if (m_printDialogData
.GetMinPage() < 1)
683 m_printDialogData
.SetMinPage(1);
684 if (m_printDialogData
.GetMaxPage() < 1)
685 m_printDialogData
.SetMaxPage(9999);
689 dc
= PrintDialog( parent
);
691 dc
= new wxGnomePrintDC( this );
693 if (m_native_preview
)
694 printout
->SetIsPreview(true);
698 gs_lgp
->gnome_print_job_close( job
);
699 g_object_unref (G_OBJECT (job
));
700 sm_lastError
= wxPRINTER_ERROR
;
704 wxSize ScreenPixels
= wxGetDisplaySize();
705 wxSize ScreenMM
= wxGetDisplaySizeMM();
707 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
708 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
709 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
710 wxGnomePrintDC::GetResolution() );
716 printout
->SetPageSizePixels((int)w
, (int)h
);
717 dc
->GetSizeMM(&w
, &h
);
718 printout
->SetPageSizeMM((int)w
, (int)h
);
720 printout
->OnPreparePrinting();
722 // Get some parameters from the printout, if defined
723 int fromPage
, toPage
;
724 int minPage
, maxPage
;
725 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
729 gs_lgp
->gnome_print_job_close( job
);
730 g_object_unref (G_OBJECT (job
));
731 sm_lastError
= wxPRINTER_ERROR
;
735 printout
->OnBeginPrinting();
737 int minPageNum
= minPage
, maxPageNum
= maxPage
;
739 if ( !m_printDialogData
.GetAllPages() )
741 minPageNum
= m_printDialogData
.GetFromPage();
742 maxPageNum
= m_printDialogData
.GetToPage();
748 copyCount
<= m_printDialogData
.GetNoCopies();
751 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
753 wxLogError(_("Could not start printing."));
754 sm_lastError
= wxPRINTER_ERROR
;
759 for ( pn
= minPageNum
;
760 pn
<= maxPageNum
&& printout
->HasPage(pn
);
764 printout
->OnPrintPage(pn
);
768 printout
->OnEndDocument();
769 printout
->OnEndPrinting();
772 gs_lgp
->gnome_print_job_close( job
);
773 if (m_native_preview
)
775 wxString
title( _("Print preview") );
776 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
780 gs_lgp
->gnome_print_job_print( job
);
783 g_object_unref (G_OBJECT (job
));
786 return (sm_lastError
== wxPRINTER_NO_ERROR
);
789 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
791 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
792 int ret
= dialog
.ShowModal();
793 if (ret
== wxID_CANCEL
)
795 sm_lastError
= wxPRINTER_ERROR
;
799 m_native_preview
= ret
== wxID_PREVIEW
;
801 m_printDialogData
= dialog
.GetPrintDialogData();
802 return new wxGnomePrintDC( this );
805 bool wxGnomePrinter::Setup( wxWindow
*parent
)
810 //-----------------------------------------------------------------------------
812 //-----------------------------------------------------------------------------
814 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDCBase
)
816 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
820 m_gpc
= printer
->GetPrintContext();
822 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
823 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
829 m_signX
= 1; // default x-axis left to right
830 m_signY
= -1; // default y-axis bottom up -> top down
833 wxGnomePrintDC::~wxGnomePrintDC()
837 bool wxGnomePrintDC::Ok() const
842 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
847 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
852 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
854 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
858 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
859 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
860 gs_lgp
->gnome_print_stroke ( m_gpc
);
862 CalcBoundingBox( x1
, y1
);
863 CalcBoundingBox( x2
, y2
);
866 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
870 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
874 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
878 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
882 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
884 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
891 for ( i
=0; i
<n
; i
++ )
892 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
894 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
896 for (i
= 1; i
< n
; i
++)
897 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
899 gs_lgp
->gnome_print_stroke ( m_gpc
);
902 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
906 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
910 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
912 if (m_brush
.GetStyle () != wxTRANSPARENT
)
916 gs_lgp
->gnome_print_newpath( m_gpc
);
917 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
918 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
919 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
920 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
921 gs_lgp
->gnome_print_closepath( m_gpc
);
922 gs_lgp
->gnome_print_fill( m_gpc
);
924 CalcBoundingBox( x
, y
);
925 CalcBoundingBox( x
+ width
, y
+ height
);
928 if (m_pen
.GetStyle () != wxTRANSPARENT
)
932 gs_lgp
->gnome_print_newpath( m_gpc
);
933 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
934 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
935 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
936 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
937 gs_lgp
->gnome_print_closepath( m_gpc
);
938 gs_lgp
->gnome_print_stroke( m_gpc
);
940 CalcBoundingBox( x
, y
);
941 CalcBoundingBox( x
+ width
, y
+ height
);
945 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
949 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
951 if (m_brush
.GetStyle () != wxTRANSPARENT
)
955 gs_lgp
->gnome_print_newpath( m_gpc
);
956 gs_lgp
->gnome_print_moveto( m_gpc
,
957 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
959 // start with top half
960 gs_lgp
->gnome_print_curveto( m_gpc
,
961 XLOG2DEV(x
), YLOG2DEV(y
),
962 XLOG2DEV(x
+width
), YLOG2DEV(y
),
963 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
965 gs_lgp
->gnome_print_curveto( m_gpc
,
966 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
967 XLOG2DEV(x
), YLOG2DEV(y
+height
),
968 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
970 gs_lgp
->gnome_print_closepath( m_gpc
);
971 gs_lgp
->gnome_print_fill( m_gpc
);
973 CalcBoundingBox( x
, y
);
974 CalcBoundingBox( x
+ width
, y
+ height
);
977 if (m_pen
.GetStyle () != wxTRANSPARENT
)
981 gs_lgp
->gnome_print_newpath( m_gpc
);
982 gs_lgp
->gnome_print_moveto( m_gpc
,
983 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
985 // start with top half
986 gs_lgp
->gnome_print_curveto( m_gpc
,
987 XLOG2DEV(x
), YLOG2DEV(y
),
988 XLOG2DEV(x
+width
), YLOG2DEV(y
),
989 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
991 gs_lgp
->gnome_print_curveto( m_gpc
,
992 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
993 XLOG2DEV(x
), YLOG2DEV(y
+height
),
994 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
996 gs_lgp
->gnome_print_closepath( m_gpc
);
997 gs_lgp
->gnome_print_stroke( m_gpc
);
999 CalcBoundingBox( x
, y
);
1000 CalcBoundingBox( x
+ width
, y
+ height
);
1004 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1008 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1009 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1010 wxCoord xsrcMask
, wxCoord ysrcMask
)
1015 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1017 DoDrawBitmap( icon
, x
, y
, true );
1020 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1022 if (!bitmap
.Ok()) return;
1024 if (bitmap
.HasPixbuf())
1026 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1027 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1028 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1029 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1030 int height
= gdk_pixbuf_get_height( pixbuf
);
1031 int width
= gdk_pixbuf_get_width( pixbuf
);
1033 gs_lgp
->gnome_print_gsave( m_gpc
);
1035 matrix
[0] = XLOG2DEVREL(width
);
1038 matrix
[3] = YLOG2DEVREL(height
);
1039 matrix
[4] = XLOG2DEV(x
);
1040 matrix
[5] = YLOG2DEV(y
+height
);
1041 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1042 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1044 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1046 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1047 gs_lgp
->gnome_print_grestore( m_gpc
);
1051 wxImage image
= bitmap
.ConvertToImage();
1053 if (!image
.Ok()) return;
1055 gs_lgp
->gnome_print_gsave( m_gpc
);
1057 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1060 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1061 matrix
[4] = XLOG2DEV(x
);
1062 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1063 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1064 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1065 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1066 gs_lgp
->gnome_print_grestore( m_gpc
);
1070 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1072 DoDrawRotatedText( text
, x
, y
, 0.0 );
1075 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1080 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1083 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1085 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1088 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1091 size_t datalen
= strlen((const char*)data
);
1092 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1096 PangoAttrList
*attrs
= pango_attr_list_new();
1097 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1099 a
->end_index
= datalen
;
1100 pango_attr_list_insert(attrs
, a
);
1101 pango_layout_set_attributes(m_layout
, attrs
);
1102 pango_attr_list_unref(attrs
);
1105 if (m_textForegroundColour
.Ok())
1107 unsigned char red
= m_textForegroundColour
.Red();
1108 unsigned char blue
= m_textForegroundColour
.Blue();
1109 unsigned char green
= m_textForegroundColour
.Green();
1111 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1113 double redPS
= (double)(red
) / 255.0;
1114 double bluePS
= (double)(blue
) / 255.0;
1115 double greenPS
= (double)(green
) / 255.0;
1117 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1120 m_currentBlue
= blue
;
1121 m_currentGreen
= green
;
1127 if (fabs(m_scaleY
- 1.0) > 0.00001)
1129 // If there is a user or actually any scale applied to
1130 // the device context, scale the font.
1132 // scale font description
1133 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1134 double size
= oldSize
;
1135 size
= size
* m_scaleY
;
1136 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1138 // actually apply scaled font
1139 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1141 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1143 if ( m_backgroundMode
== wxSOLID
)
1145 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1146 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1147 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1151 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1152 if (fabs(angle
) > 0.00001)
1154 gs_lgp
->gnome_print_gsave( m_gpc
);
1155 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1156 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1157 gs_lgp
->gnome_print_grestore( m_gpc
);
1161 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1164 // reset unscaled size
1165 pango_font_description_set_size( m_fontdesc
, oldSize
);
1167 // actually apply unscaled font
1168 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1172 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1174 if ( m_backgroundMode
== wxSOLID
)
1176 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1177 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1178 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1182 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1183 if (fabs(angle
) > 0.00001)
1185 gs_lgp
->gnome_print_gsave( m_gpc
);
1186 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1187 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1188 gs_lgp
->gnome_print_grestore( m_gpc
);
1192 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1198 // undo underline attributes setting:
1199 pango_layout_set_attributes(m_layout
, NULL
);
1202 CalcBoundingBox (x
+ w
, y
+ h
);
1205 void wxGnomePrintDC::Clear()
1209 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1216 pango_font_description_free( m_fontdesc
);
1218 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1220 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1224 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1226 if (!pen
.Ok()) return;
1230 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1232 static const double dotted
[] = {2.0, 5.0};
1233 static const double short_dashed
[] = {4.0, 4.0};
1234 static const double wxCoord_dashed
[] = {4.0, 8.0};
1235 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1237 switch (m_pen
.GetStyle())
1239 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1240 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1241 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1242 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1245 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1249 unsigned char red
= m_pen
.GetColour().Red();
1250 unsigned char blue
= m_pen
.GetColour().Blue();
1251 unsigned char green
= m_pen
.GetColour().Green();
1253 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1255 double redPS
= (double)(red
) / 255.0;
1256 double bluePS
= (double)(blue
) / 255.0;
1257 double greenPS
= (double)(green
) / 255.0;
1259 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1262 m_currentBlue
= blue
;
1263 m_currentGreen
= green
;
1267 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1269 if (!brush
.Ok()) return;
1274 unsigned char red
= m_brush
.GetColour().Red();
1275 unsigned char blue
= m_brush
.GetColour().Blue();
1276 unsigned char green
= m_brush
.GetColour().Green();
1280 // Anything not white is black
1281 if (! (red
== (unsigned char) 255 &&
1282 blue
== (unsigned char) 255 &&
1283 green
== (unsigned char) 255) )
1285 red
= (unsigned char) 0;
1286 green
= (unsigned char) 0;
1287 blue
= (unsigned char) 0;
1292 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1294 double redPS
= (double)(red
) / 255.0;
1295 double bluePS
= (double)(blue
) / 255.0;
1296 double greenPS
= (double)(green
) / 255.0;
1298 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1301 m_currentBlue
= blue
;
1302 m_currentGreen
= green
;
1306 void wxGnomePrintDC::SetLogicalFunction( int function
)
1310 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1314 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1318 void wxGnomePrintDC::DestroyClippingRegion()
1322 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1324 SetDeviceOrigin( 0,0 );
1329 void wxGnomePrintDC::EndDoc()
1331 gs_lgp
->gnome_print_end_doc( m_gpc
);
1334 void wxGnomePrintDC::StartPage()
1336 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1339 void wxGnomePrintDC::EndPage()
1341 gs_lgp
->gnome_print_showpage( m_gpc
);
1344 wxCoord
wxGnomePrintDC::GetCharHeight() const
1346 pango_layout_set_text( m_layout
, "H", 1 );
1349 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1354 wxCoord
wxGnomePrintDC::GetCharWidth() const
1356 pango_layout_set_text( m_layout
, "H", 1 );
1359 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1364 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1366 wxCoord
*externalLeading
,
1367 wxFont
*theFont
) const
1375 if ( externalLeading
)
1376 *externalLeading
= 0;
1378 if (string
.IsEmpty())
1383 // Set new font description
1385 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1387 // Set layout's text
1389 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1390 const char *dataUTF8
= (const char *)data
;
1392 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1395 if (width
) (*width
) = 0;
1396 if (height
) (*height
) = 0;
1399 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1400 const char *dataUTF8
= (const char *)data
;
1405 // hardly ideal, but what else can we do if conversion failed?
1409 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1412 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1415 *width
= (wxCoord
) w
;
1417 *height
= (wxCoord
) h
;
1420 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1421 int baseline
= pango_layout_iter_get_baseline(iter
);
1422 pango_layout_iter_free(iter
);
1423 *descent
= h
- PANGO_PIXELS(baseline
);
1426 // Reset old font description
1428 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1431 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1433 wxGnomePrintNativeData
*native
=
1434 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1436 // Query page size. This seems to omit the margins
1437 // right now, although it shouldn't
1439 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1442 *width
= (int) (pw
+ 0.5);
1444 *height
= (int) (ph
+ 0.5);
1447 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1449 wxGnomePrintNativeData
*native
=
1450 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1452 // This code assumes values in Pts.
1455 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1459 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1460 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1461 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1462 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1465 *width
= (int) (pw
+ 0.5);
1467 *height
= (int) (ph
+ 0.5);
1470 wxSize
wxGnomePrintDC::GetPPI() const
1472 return wxSize(72,72);
1475 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1477 m_signX
= (xLeftRight
? 1 : -1);
1478 m_signY
= (yBottomUp
? 1 : -1);
1480 ComputeScaleAndOrigin();
1483 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1489 wxDC::SetDeviceOrigin( x
, h
-y
);
1492 void wxGnomePrintDC::SetResolution(int ppi
)
1496 int wxGnomePrintDC::GetResolution()
1502 class wxGnomePrintModule
: public wxModule
1505 wxGnomePrintModule() {}
1510 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1513 bool wxGnomePrintModule::OnInit()
1515 gs_lgp
= new wxGnomePrintLibrary
;
1517 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1521 void wxGnomePrintModule::OnExit()
1526 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1529 // wxUSE_LIBGNOMEPRINT