]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gnome/gprint.cpp
[wxGTK2] Move wxFontRefData::SetPointSize to wxNativeFontInfo. Implement SetFaceName()
[wxWidgets.git] / src / gtk / gnome / gprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
5 // Created: 09/20/04
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "gprint.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "wx/gtk/gnome/gprint.h"
22
23 #if wxUSE_LIBGNOMEPRINT
24
25 #include "wx/math.h"
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"
32
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>
39
40 static const double RAD2DEG = 180.0 / M_PI;
41
42 #include "wx/html/forcelnk.h"
43 FORCE_LINK_ME(gnome_print)
44
45 //----------------------------------------------------------------------------
46 // wxGnomePrintLibrary
47 //----------------------------------------------------------------------------
48
49 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
50 typedef rettype (* name ## Type) args ; \
51 name ## Type pfn_ ## name; \
52 rettype name args \
53 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
54
55 #define wxDL_METHOD_LOAD( lib, name, success ) \
56 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
57 if (!success) return;
58
59 class wxGnomePrintLibrary
60 {
61 public:
62 wxGnomePrintLibrary();
63 ~wxGnomePrintLibrary();
64
65 bool IsOk();
66 void InitializeMethods();
67
68 private:
69 bool m_ok;
70 wxDynamicLibrary *m_gnome_print_lib;
71 wxDynamicLibrary *m_gnome_printui_lib;
72
73 public:
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_arcto,
81 (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 )
82 wxDL_METHOD_DEFINE( gint, gnome_print_curveto,
83 (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 )
84 wxDL_METHOD_DEFINE( gint, gnome_print_closepath,
85 (GnomePrintContext *pc), (pc), 0 )
86 wxDL_METHOD_DEFINE( gint, gnome_print_stroke,
87 (GnomePrintContext *pc), (pc), 0 )
88 wxDL_METHOD_DEFINE( gint, gnome_print_fill,
89 (GnomePrintContext *pc), (pc), 0 )
90 wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor,
91 (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 )
92 wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth,
93 (GnomePrintContext *pc, gdouble width), (pc, width), 0 )
94 wxDL_METHOD_DEFINE( gint, gnome_print_setdash,
95 (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 )
96
97 wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage,
98 (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 )
99 wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage,
100 (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 )
101
102 wxDL_METHOD_DEFINE( gint, gnome_print_concat,
103 (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 )
104 wxDL_METHOD_DEFINE( gint, gnome_print_scale,
105 (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 )
106 wxDL_METHOD_DEFINE( gint, gnome_print_rotate,
107 (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 )
108 wxDL_METHOD_DEFINE( gint, gnome_print_translate,
109 (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 )
110
111 wxDL_METHOD_DEFINE( gint, gnome_print_gsave,
112 (GnomePrintContext *pc), (pc), 0 )
113 wxDL_METHOD_DEFINE( gint, gnome_print_grestore,
114 (GnomePrintContext *pc), (pc), 0 )
115
116 wxDL_METHOD_DEFINE( gint, gnome_print_beginpage,
117 (GnomePrintContext *pc, const guchar* name), (pc, name), 0 )
118 wxDL_METHOD_DEFINE( gint, gnome_print_showpage,
119 (GnomePrintContext *pc), (pc), 0 )
120 wxDL_METHOD_DEFINE( gint, gnome_print_end_doc,
121 (GnomePrintContext *pc), (pc), 0 )
122
123 wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout,
124 (GnomePrintContext *gpc), (gpc), NULL )
125 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout,
126 (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout), /**/ )
127
128 wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new,
129 (GnomePrintConfig *config), (config), NULL )
130 wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context,
131 (GnomePrintJob *job), (job), NULL )
132 wxDL_METHOD_DEFINE( gint, gnome_print_job_close,
133 (GnomePrintJob *job), (job), 0 )
134 wxDL_METHOD_DEFINE( gint, gnome_print_job_print,
135 (GnomePrintJob *job), (job), 0 )
136 wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size,
137 (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 )
138
139 wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation,
140 (const guchar *abbreviation), (abbreviation), NULL )
141 wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance,
142 (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false )
143
144 wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default,
145 (void), (), NULL )
146 wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set,
147 (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false )
148 wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length,
149 (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false )
150
151 wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new,
152 (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL )
153 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page,
154 (GnomePrintDialog *gpd, gint flags, gint start, gint end,
155 const guchar *currentlabel, const guchar *rangelabel),
156 (gpd, flags, start, end, currentlabel, rangelabel), /**/ )
157 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies,
158 (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate), /**/ )
159 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies,
160 (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate), /**/ )
161 wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range,
162 (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE )
163 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page,
164 (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 )
165
166 wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags,
167 (GnomePrintConfig *config, gint flags), (config, flags), NULL )
168
169 wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new,
170 (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL )
171 };
172
173 wxGnomePrintLibrary::wxGnomePrintLibrary()
174 {
175 m_gnome_print_lib = NULL;
176 m_gnome_printui_lib = NULL;
177
178 wxLogNull log;
179
180 m_gnome_print_lib = new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
181 m_ok = m_gnome_print_lib->IsLoaded();
182 if (!m_ok) return;
183
184 m_gnome_printui_lib = new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
185 m_ok = m_gnome_printui_lib->IsLoaded();
186 if (!m_ok) return;
187
188 InitializeMethods();
189 }
190
191 wxGnomePrintLibrary::~wxGnomePrintLibrary()
192 {
193 if (m_gnome_print_lib)
194 delete m_gnome_print_lib;
195 if (m_gnome_printui_lib)
196 delete m_gnome_printui_lib;
197 }
198
199 bool wxGnomePrintLibrary::IsOk()
200 {
201 return m_ok;
202 }
203
204 void wxGnomePrintLibrary::InitializeMethods()
205 {
206 m_ok = false;
207 bool success;
208
209 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_newpath, success )
210 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_moveto, success )
211 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_lineto, success )
212 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_curveto, success )
213 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_arcto, success )
214 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_closepath, success )
215 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_stroke, success )
216 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_fill, success )
217 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setrgbcolor, success )
218 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setlinewidth, success )
219 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setdash, success )
220
221 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbimage, success )
222 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbaimage, success )
223
224 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_concat, success )
225 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_scale, success )
226 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rotate, success )
227 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_translate, success )
228
229 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_gsave, success )
230 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_grestore, success )
231
232 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_beginpage, success )
233 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_showpage, success )
234 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_end_doc, success )
235
236 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_create_layout, success )
237 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_layout, success )
238
239 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_new, success )
240 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_context, success )
241 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_close, success )
242 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_print, success )
243 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_page_size, success )
244
245 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_unit_get_by_abbreviation, success )
246 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_convert_distance, success )
247
248 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_default, success )
249 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_set, success )
250 wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_get_length, success )
251
252 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_new, success )
253 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_construct_range_page, success )
254 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_copies, success )
255 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_set_copies, success )
256 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range, success )
257 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range_page, success )
258
259 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_paper_selector_new_with_flags, success )
260
261 wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_job_preview_new, success )
262
263 m_ok = true;
264 }
265
266 static wxGnomePrintLibrary* gs_lgp = NULL;
267
268 //----------------------------------------------------------------------------
269 // wxGnomePrintNativeData
270 //----------------------------------------------------------------------------
271
272 IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase)
273
274 wxGnomePrintNativeData::wxGnomePrintNativeData()
275 {
276 m_config = gs_lgp->gnome_print_config_default();
277 m_job = gs_lgp->gnome_print_job_new( m_config );
278 }
279
280 wxGnomePrintNativeData::~wxGnomePrintNativeData()
281 {
282 g_object_unref (G_OBJECT (m_config));
283 }
284
285 bool wxGnomePrintNativeData::TransferTo( wxPrintData &data )
286 {
287 // TODO
288 return true;
289 }
290
291 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data )
292 {
293 // TODO
294 return true;
295 }
296
297 //----------------------------------------------------------------------------
298 // wxGnomePrintFactory
299 //----------------------------------------------------------------------------
300
301 wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data )
302 {
303 return new wxGnomePrinter( data );
304 }
305
306 wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
307 wxPrintout *printout,
308 wxPrintDialogData *data )
309 {
310 return new wxPostScriptPrintPreview( preview, printout, data );
311 }
312
313 wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
314 wxPrintout *printout,
315 wxPrintData *data )
316 {
317 return new wxPostScriptPrintPreview( preview, printout, data );
318 }
319
320 wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
321 wxPrintDialogData *data )
322 {
323 return new wxGnomePrintDialog( parent, data );
324 }
325
326 wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
327 wxPrintData *data )
328 {
329 return new wxGnomePrintDialog( parent, data );
330 }
331
332 wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent,
333 wxPageSetupDialogData * data )
334 {
335 // The native page setup dialog is broken. It
336 // miscalculates newly entered values for the
337 // margins if you have not chose "points" but
338 // e.g. centimerters.
339 // This has been fixed in GNOME CVS (maybe
340 // fixed in libgnomeprintui 2.8.1)
341
342 return new wxGnomePageSetupDialog( parent, data );
343 }
344
345 bool wxGnomePrintFactory::HasPrintSetupDialog()
346 {
347 return false;
348 }
349
350 wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data )
351 {
352 return NULL;
353 }
354
355 bool wxGnomePrintFactory::HasOwnPrintToFile()
356 {
357 return true;
358 }
359
360 bool wxGnomePrintFactory::HasPrinterLine()
361 {
362 return true;
363 }
364
365 wxString wxGnomePrintFactory::CreatePrinterLine()
366 {
367 // redundant now
368 return wxEmptyString;
369 }
370
371 bool wxGnomePrintFactory::HasStatusLine()
372 {
373 // redundant now
374 return true;
375 }
376
377 wxString wxGnomePrintFactory::CreateStatusLine()
378 {
379 // redundant now
380 return wxEmptyString;
381 }
382
383 wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData()
384 {
385 return new wxGnomePrintNativeData;
386 }
387
388 //----------------------------------------------------------------------------
389 // wxGnomePrintSetupDialog
390 //----------------------------------------------------------------------------
391
392 IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase)
393
394 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data )
395 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
396 wxPoint(0, 0), wxSize(600, 600),
397 wxDEFAULT_DIALOG_STYLE |
398 wxTAB_TRAVERSAL)
399 {
400 if (data)
401 m_printDialogData = *data;
402
403 Init();
404 }
405
406 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data )
407 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
408 wxPoint(0, 0), wxSize(600, 600),
409 wxDEFAULT_DIALOG_STYLE |
410 wxTAB_TRAVERSAL)
411 {
412 if (data)
413 m_printDialogData = *data;
414
415 Init();
416 }
417
418 void wxGnomePrintDialog::Init()
419 {
420 wxPrintData data = m_printDialogData.GetPrintData();
421
422 wxGnomePrintNativeData *native =
423 (wxGnomePrintNativeData*) data.GetNativeData();
424
425 m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(),
426 (guchar*)"Print",
427 GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES );
428
429 int flag = 0;
430 if (m_printDialogData.GetEnableSelection())
431 flag |= GNOME_PRINT_RANGE_SELECTION;
432 if (m_printDialogData.GetEnablePageNumbers())
433 flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE;
434
435 gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget,
436 flag,
437 m_printDialogData.GetMinPage(),
438 m_printDialogData.GetMaxPage(),
439 NULL,
440 NULL );
441 }
442
443 wxGnomePrintDialog::~wxGnomePrintDialog()
444 {
445 m_widget = NULL;
446 }
447
448 int wxGnomePrintDialog::ShowModal()
449 {
450 // Transfer data from m_printDalogData to dialog here
451
452 int response = gtk_dialog_run (GTK_DIALOG (m_widget));
453
454 if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL)
455 {
456 gtk_widget_destroy(m_widget);
457 m_widget = NULL;
458
459 return wxID_CANCEL;
460 }
461
462 gint copies = 1;
463 gboolean collate = false;
464 gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate );
465 m_printDialogData.SetNoCopies( copies );
466 m_printDialogData.SetCollate( collate );
467
468 switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget ))
469 {
470 case GNOME_PRINT_RANGE_SELECTION:
471 m_printDialogData.SetSelection( true );
472 break;
473 case GNOME_PRINT_RANGE_ALL:
474 m_printDialogData.SetAllPages( true );
475 m_printDialogData.SetFromPage( 0 );
476 m_printDialogData.SetToPage( 9999 );
477 break;
478 case GNOME_PRINT_RANGE_RANGE:
479 default:
480 gint start,end;
481 gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end );
482 m_printDialogData.SetFromPage( start );
483 m_printDialogData.SetToPage( end );
484 break;
485 }
486
487 gtk_widget_destroy(m_widget);
488 m_widget = NULL;
489
490 if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW)
491 return wxID_PREVIEW;
492
493 return wxID_OK;
494 }
495
496 wxDC *wxGnomePrintDialog::GetPrintDC()
497 {
498 // Later
499 return NULL;
500 }
501
502 bool wxGnomePrintDialog::Validate()
503 {
504 return true;
505 }
506
507 bool wxGnomePrintDialog::TransferDataToWindow()
508 {
509 return true;
510 }
511
512 bool wxGnomePrintDialog::TransferDataFromWindow()
513 {
514 return true;
515 }
516
517 //----------------------------------------------------------------------------
518 // wxGnomePageSetupDialog
519 //----------------------------------------------------------------------------
520
521 IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase)
522
523 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent,
524 wxPageSetupDialogData* data )
525 {
526 if (data)
527 m_pageDialogData = *data;
528
529 wxGnomePrintNativeData *native =
530 (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();
531
532 // This is required as the page setup dialog
533 // calculates wrong values otherwise.
534 gs_lgp->gnome_print_config_set( native->GetPrintConfig(),
535 (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT,
536 (const guchar*) "Pts" );
537
538 m_widget = gtk_dialog_new();
539
540 gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) );
541
542 GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(),
543 GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION );
544 gtk_container_set_border_width (GTK_CONTAINER (main), 8);
545 gtk_widget_show (main);
546
547 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main );
548
549 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE);
550
551 gtk_dialog_add_buttons (GTK_DIALOG (m_widget),
552 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
553 GTK_STOCK_OK, GTK_RESPONSE_OK,
554 NULL);
555
556 gtk_dialog_set_default_response (GTK_DIALOG (m_widget),
557 GTK_RESPONSE_OK);
558 }
559
560 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
561 {
562 }
563
564 wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData()
565 {
566 return m_pageDialogData;
567 }
568
569 int wxGnomePageSetupDialog::ShowModal()
570 {
571 wxGnomePrintNativeData *native =
572 (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();
573 GnomePrintConfig *config = native->GetPrintConfig();
574
575 // Transfer data from m_pageDialogData to native dialog
576
577 int ret = gtk_dialog_run( GTK_DIALOG(m_widget) );
578
579 if (ret == GTK_RESPONSE_OK)
580 {
581 // Transfer data back to m_pageDialogData
582
583 // I don't know how querying the last parameter works
584 // I cannot test it as the dialog is currently broken
585 // anyways (it only works for points).
586 double ml,mr,mt,mb,pw,ph;
587 gs_lgp->gnome_print_config_get_length (config,
588 (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL);
589 gs_lgp->gnome_print_config_get_length (config,
590 (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL);
591 gs_lgp->gnome_print_config_get_length (config,
592 (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL);
593 gs_lgp->gnome_print_config_get_length (config,
594 (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL);
595 gs_lgp->gnome_print_config_get_length (config,
596 (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL);
597 gs_lgp->gnome_print_config_get_length (config,
598 (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL);
599
600 // This probably assumes that the user entered the
601 // values in Pts. Since that is the only the dialog
602 // works right now, we need to fix this later.
603 const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" );
604 const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" );
605 gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit );
606 gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit );
607 gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit );
608 gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit );
609 gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit );
610 gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit );
611
612 m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) );
613 m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) );
614
615 m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );
616
617 #if 0
618 wxPrintf( wxT("paper %d %d, top margin %d\n"),
619 m_pageDialogData.GetPaperSize().x,
620 m_pageDialogData.GetPaperSize().y,
621 m_pageDialogData.GetMarginTopLeft().x );
622 #endif
623
624 ret = wxID_OK;
625 }
626 else
627 {
628 ret = wxID_CANCEL;
629 }
630
631 gtk_widget_destroy( m_widget );
632 m_widget = NULL;
633
634 return ret;
635 }
636
637 bool wxGnomePageSetupDialog::Validate()
638 {
639 return true;
640 }
641
642 bool wxGnomePageSetupDialog::TransferDataToWindow()
643 {
644 return true;
645 }
646
647 bool wxGnomePageSetupDialog::TransferDataFromWindow()
648 {
649 return true;
650 }
651
652 //----------------------------------------------------------------------------
653 // wxGnomePrinter
654 //----------------------------------------------------------------------------
655
656 IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase)
657
658 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) :
659 wxPrinterBase( data )
660 {
661 m_gpc = NULL;
662 m_native_preview = false;
663 }
664
665 wxGnomePrinter::~wxGnomePrinter()
666 {
667 }
668
669 bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
670 {
671 if (!printout)
672 {
673 sm_lastError = wxPRINTER_ERROR;
674 return false;
675 }
676
677 wxPrintData printdata = GetPrintDialogData().GetPrintData();
678 wxGnomePrintNativeData *native =
679 (wxGnomePrintNativeData*) printdata.GetNativeData();
680
681 GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() );
682 m_gpc = gs_lgp->gnome_print_job_get_context (job);
683
684 // The GnomePrintJob is temporarily stored in the
685 // native print data as the native print dialog
686 // needs to access it.
687 native->SetPrintJob( job );
688
689
690 printout->SetIsPreview(false);
691
692 if (m_printDialogData.GetMinPage() < 1)
693 m_printDialogData.SetMinPage(1);
694 if (m_printDialogData.GetMaxPage() < 1)
695 m_printDialogData.SetMaxPage(9999);
696
697 wxDC *dc;
698 if (prompt)
699 dc = PrintDialog( parent );
700 else
701 dc = new wxGnomePrintDC( this );
702
703 if (m_native_preview)
704 printout->SetIsPreview(true);
705
706 if (!dc)
707 {
708 gs_lgp->gnome_print_job_close( job );
709 g_object_unref (G_OBJECT (job));
710 sm_lastError = wxPRINTER_ERROR;
711 return false;
712 }
713
714 wxSize ScreenPixels = wxGetDisplaySize();
715 wxSize ScreenMM = wxGetDisplaySizeMM();
716
717 printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
718 (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
719 printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
720 wxGnomePrintDC::GetResolution() );
721
722 printout->SetDC(dc);
723
724 int w, h;
725 dc->GetSize(&w, &h);
726 printout->SetPageSizePixels((int)w, (int)h);
727 dc->GetSizeMM(&w, &h);
728 printout->SetPageSizeMM((int)w, (int)h);
729
730 printout->OnPreparePrinting();
731
732 // Get some parameters from the printout, if defined
733 int fromPage, toPage;
734 int minPage, maxPage;
735 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
736
737 if (maxPage == 0)
738 {
739 gs_lgp->gnome_print_job_close( job );
740 g_object_unref (G_OBJECT (job));
741 sm_lastError = wxPRINTER_ERROR;
742 return false;
743 }
744
745 printout->OnBeginPrinting();
746
747 int minPageNum = minPage, maxPageNum = maxPage;
748
749 if ( !m_printDialogData.GetAllPages() )
750 {
751 minPageNum = m_printDialogData.GetFromPage();
752 maxPageNum = m_printDialogData.GetToPage();
753 }
754
755
756 int copyCount;
757 for ( copyCount = 1;
758 copyCount <= m_printDialogData.GetNoCopies();
759 copyCount++ )
760 {
761 if (!printout->OnBeginDocument(minPageNum, maxPageNum))
762 {
763 wxLogError(_("Could not start printing."));
764 sm_lastError = wxPRINTER_ERROR;
765 break;
766 }
767
768 int pn;
769 for ( pn = minPageNum;
770 pn <= maxPageNum && printout->HasPage(pn);
771 pn++ )
772 {
773 dc->StartPage();
774 printout->OnPrintPage(pn);
775 dc->EndPage();
776 }
777
778 printout->OnEndDocument();
779 printout->OnEndPrinting();
780 }
781
782 gs_lgp->gnome_print_job_close( job );
783 if (m_native_preview)
784 {
785 wxString title( _("Print preview") );
786 gtk_widget_show( gs_lgp->gnome_print_job_preview_new( job, (const guchar*)(const char*)wxGTK_CONV(title) ));
787 }
788 else
789 {
790 gs_lgp->gnome_print_job_print( job );
791 }
792
793 g_object_unref (G_OBJECT (job));
794 delete dc;
795
796 return (sm_lastError == wxPRINTER_NO_ERROR);
797 }
798
799 wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent )
800 {
801 wxGnomePrintDialog dialog( parent, &m_printDialogData );
802 int ret = dialog.ShowModal();
803 if (ret == wxID_CANCEL)
804 {
805 sm_lastError = wxPRINTER_CANCELLED;
806 return NULL;
807 }
808
809 m_native_preview = ret == wxID_PREVIEW;
810
811 m_printDialogData = dialog.GetPrintDialogData();
812 return new wxGnomePrintDC( this );
813 }
814
815 bool wxGnomePrinter::Setup( wxWindow *parent )
816 {
817 return false;
818 }
819
820 //-----------------------------------------------------------------------------
821 // wxGnomePrintDC
822 //-----------------------------------------------------------------------------
823
824 IMPLEMENT_CLASS(wxGnomePrintDC, wxDC)
825
826 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer )
827 {
828 m_printer = printer;
829
830 m_gpc = printer->GetPrintContext();
831
832 m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
833 m_fontdesc = pango_font_description_from_string( "Sans 12" );
834
835 m_currentRed = 0;
836 m_currentBlue = 0;
837 m_currentGreen = 0;
838
839 m_signX = 1; // default x-axis left to right
840 m_signY = -1; // default y-axis bottom up -> top down
841 }
842
843 wxGnomePrintDC::~wxGnomePrintDC()
844 {
845 }
846
847 bool wxGnomePrintDC::Ok() const
848 {
849 return true;
850 }
851
852 bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style )
853 {
854 return false;
855 }
856
857 bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const
858 {
859 return false;
860 }
861
862 void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
863 {
864 if (m_pen.GetStyle() == wxTRANSPARENT) return;
865
866 SetPen( m_pen );
867
868 gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
869 gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
870 gs_lgp->gnome_print_stroke ( m_gpc);
871
872 CalcBoundingBox( x1, y1 );
873 CalcBoundingBox( x2, y2 );
874 }
875
876 void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y)
877 {
878 }
879
880 void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
881 {
882 double dx = x1 - xc;
883 double dy = y1 - yc;
884 double radius = sqrt((double)(dx*dx+dy*dy));
885 double alpha1, alpha2;
886 if (x1 == x2 && y1 == y2)
887 {
888 alpha1 = 0.0;
889 alpha2 = 360.0;
890 }
891 else
892 if (radius == 0.0)
893 {
894 alpha1 = alpha2 = 0.0;
895 }
896 else
897 {
898 alpha1 = (x1 - xc == 0) ?
899 (y1 - yc < 0) ? 90.0 : -90.0 :
900 -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
901 alpha2 = (x2 - xc == 0) ?
902 (y2 - yc < 0) ? 90.0 : -90.0 :
903 -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
904
905 while (alpha1 <= 0) alpha1 += 360;
906 while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
907 while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
908 while (alpha2 > 360) alpha2 -= 360;
909 }
910
911 if (m_brush.GetStyle() != wxTRANSPARENT)
912 {
913 SetBrush( m_brush );
914 gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
915 gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
916
917 gs_lgp->gnome_print_fill( m_gpc );
918 }
919
920 if (m_pen.GetStyle() != wxTRANSPARENT)
921 {
922 SetPen (m_pen);
923 gs_lgp->gnome_print_newpath( m_gpc );
924 gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
925 gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
926 gs_lgp->gnome_print_closepath( m_gpc );
927
928 gs_lgp->gnome_print_stroke( m_gpc );
929 }
930
931 CalcBoundingBox (x1, y1);
932 CalcBoundingBox (x2, y2);
933 CalcBoundingBox (xc, yc);
934 }
935
936 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
937 {
938 x += w/2;
939 y += h/2;
940
941 int xx = XLOG2DEV(x);
942 int yy = YLOG2DEV(y);
943
944 gs_lgp->gnome_print_gsave( m_gpc );
945
946 gs_lgp->gnome_print_translate( m_gpc, xx, yy );
947 double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w);
948 gs_lgp->gnome_print_scale( m_gpc, 1.0, scale );
949
950 xx = 0;
951 yy = 0;
952
953 if (m_brush.GetStyle () != wxTRANSPARENT)
954 {
955 SetBrush( m_brush );
956
957 gs_lgp->gnome_print_moveto ( m_gpc, xx, yy );
958 gs_lgp->gnome_print_arcto( m_gpc, xx, yy,
959 XLOG2DEVREL(w)/2, sa, ea, 0 );
960 gs_lgp->gnome_print_moveto ( m_gpc, xx, yy );
961
962 gs_lgp->gnome_print_fill( m_gpc );
963 }
964
965 if (m_pen.GetStyle () != wxTRANSPARENT)
966 {
967 SetPen (m_pen);
968
969 gs_lgp->gnome_print_arcto( m_gpc, xx, yy,
970 XLOG2DEVREL(w)/2, sa, ea, 0 );
971
972 gs_lgp->gnome_print_stroke( m_gpc );
973 }
974
975 gs_lgp->gnome_print_grestore( m_gpc );
976
977 CalcBoundingBox( x, y );
978 CalcBoundingBox( x+w, y+h );
979 }
980
981 void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y)
982 {
983 }
984
985 void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
986 {
987 if (m_pen.GetStyle() == wxTRANSPARENT) return;
988
989 if (n <= 0) return;
990
991 SetPen (m_pen);
992
993 int i;
994 for ( i =0; i<n ; i++ )
995 CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset);
996
997 gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
998
999 for (i = 1; i < n; i++)
1000 gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
1001
1002 gs_lgp->gnome_print_stroke ( m_gpc);
1003 }
1004
1005 void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
1006 {
1007 if (n==0) return;
1008
1009 if (m_brush.GetStyle () != wxTRANSPARENT)
1010 {
1011 SetBrush( m_brush );
1012
1013 int x = points[0].x + xoffset;
1014 int y = points[0].y + yoffset;
1015 CalcBoundingBox( x, y );
1016 gs_lgp->gnome_print_newpath( m_gpc );
1017 gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1018 int i;
1019 for (i = 1; i < n; i++)
1020 {
1021 int x = points[i].x + xoffset;
1022 int y = points[i].y + yoffset;
1023 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1024 CalcBoundingBox( x, y );
1025 }
1026 gs_lgp->gnome_print_closepath( m_gpc );
1027 gs_lgp->gnome_print_fill( m_gpc );
1028 }
1029
1030 if (m_pen.GetStyle () != wxTRANSPARENT)
1031 {
1032 SetPen (m_pen);
1033
1034 int x = points[0].x + xoffset;
1035 int y = points[0].y + yoffset;
1036 gs_lgp->gnome_print_newpath( m_gpc );
1037 gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1038 int i;
1039 for (i = 1; i < n; i++)
1040 {
1041 int x = points[i].x + xoffset;
1042 int y = points[i].y + yoffset;
1043 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1044 CalcBoundingBox( x, y );
1045 }
1046 gs_lgp->gnome_print_closepath( m_gpc );
1047 gs_lgp->gnome_print_stroke( m_gpc );
1048 }
1049 }
1050
1051 void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
1052 {
1053 wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
1054 }
1055
1056 void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1057 {
1058 if (m_brush.GetStyle () != wxTRANSPARENT)
1059 {
1060 SetBrush( m_brush );
1061
1062 gs_lgp->gnome_print_newpath( m_gpc );
1063 gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1064 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1065 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1066 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1067 gs_lgp->gnome_print_closepath( m_gpc );
1068 gs_lgp->gnome_print_fill( m_gpc );
1069
1070 CalcBoundingBox( x, y );
1071 CalcBoundingBox( x + width, y + height );
1072 }
1073
1074 if (m_pen.GetStyle () != wxTRANSPARENT)
1075 {
1076 SetPen (m_pen);
1077
1078 gs_lgp->gnome_print_newpath( m_gpc );
1079 gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1080 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1081 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1082 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1083 gs_lgp->gnome_print_closepath( m_gpc );
1084 gs_lgp->gnome_print_stroke( m_gpc );
1085
1086 CalcBoundingBox( x, y );
1087 CalcBoundingBox( x + width, y + height );
1088 }
1089 }
1090
1091 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
1092 {
1093 wxCoord rad = (wxCoord) radius;
1094
1095 if (m_brush.GetStyle() != wxTRANSPARENT)
1096 {
1097 SetBrush(m_brush);
1098 gs_lgp->gnome_print_newpath(m_gpc);
1099 gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1100 gs_lgp->gnome_print_curveto(m_gpc,
1101 XLOG2DEV(x + rad),YLOG2DEV(y),
1102 XLOG2DEV(x),YLOG2DEV(y),
1103 XLOG2DEV(x),YLOG2DEV(y + rad));
1104 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1105 gs_lgp->gnome_print_curveto(m_gpc,
1106 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1107 XLOG2DEV(x),YLOG2DEV(y + height),
1108 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1109 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1110 gs_lgp->gnome_print_curveto(m_gpc,
1111 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1112 XLOG2DEV(x + width),YLOG2DEV(y + height),
1113 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1114 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1115 gs_lgp->gnome_print_curveto(m_gpc,
1116 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1117 XLOG2DEV(x + width),YLOG2DEV(y),
1118 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1119 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1120 gs_lgp->gnome_print_closepath(m_gpc);
1121 gs_lgp->gnome_print_fill(m_gpc);
1122
1123 CalcBoundingBox(x,y);
1124 CalcBoundingBox(x+width,y+height);
1125 }
1126
1127 if (m_pen.GetStyle() != wxTRANSPARENT)
1128 {
1129 SetPen(m_pen);
1130 gs_lgp->gnome_print_newpath(m_gpc);
1131 gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1132 gs_lgp->gnome_print_curveto(m_gpc,
1133 XLOG2DEV(x + rad),YLOG2DEV(y),
1134 XLOG2DEV(x),YLOG2DEV(y),
1135 XLOG2DEV(x),YLOG2DEV(y + rad));
1136 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1137 gs_lgp->gnome_print_curveto(m_gpc,
1138 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1139 XLOG2DEV(x),YLOG2DEV(y + height),
1140 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1141 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1142 gs_lgp->gnome_print_curveto(m_gpc,
1143 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1144 XLOG2DEV(x + width),YLOG2DEV(y + height),
1145 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1146 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1147 gs_lgp->gnome_print_curveto(m_gpc,
1148 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1149 XLOG2DEV(x + width),YLOG2DEV(y),
1150 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1151 gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1152 gs_lgp->gnome_print_closepath(m_gpc);
1153 gs_lgp->gnome_print_stroke(m_gpc);
1154
1155 CalcBoundingBox(x,y);
1156 CalcBoundingBox(x+width,y+height);
1157 }
1158 }
1159
1160 void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1161 {
1162 if (m_brush.GetStyle () != wxTRANSPARENT)
1163 {
1164 SetBrush( m_brush );
1165
1166 gs_lgp->gnome_print_newpath( m_gpc );
1167 gs_lgp->gnome_print_moveto( m_gpc,
1168 XLOG2DEV(x), YLOG2DEV(y+height/2) );
1169
1170 // start with top half
1171 gs_lgp->gnome_print_curveto( m_gpc,
1172 XLOG2DEV(x), YLOG2DEV(y),
1173 XLOG2DEV(x+width), YLOG2DEV(y),
1174 XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
1175 // lower half
1176 gs_lgp->gnome_print_curveto( m_gpc,
1177 XLOG2DEV(x+width), YLOG2DEV(y+height),
1178 XLOG2DEV(x), YLOG2DEV(y+height),
1179 XLOG2DEV(x), YLOG2DEV(y+height/2) );
1180
1181 gs_lgp->gnome_print_closepath( m_gpc );
1182 gs_lgp->gnome_print_fill( m_gpc );
1183
1184 CalcBoundingBox( x, y );
1185 CalcBoundingBox( x + width, y + height );
1186 }
1187
1188 if (m_pen.GetStyle () != wxTRANSPARENT)
1189 {
1190 SetPen (m_pen);
1191
1192 gs_lgp->gnome_print_newpath( m_gpc );
1193 gs_lgp->gnome_print_moveto( m_gpc,
1194 XLOG2DEV(x), YLOG2DEV(y+height/2) );
1195
1196 // start with top half
1197 gs_lgp->gnome_print_curveto( m_gpc,
1198 XLOG2DEV(x), YLOG2DEV(y),
1199 XLOG2DEV(x+width), YLOG2DEV(y),
1200 XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
1201 // lower half
1202 gs_lgp->gnome_print_curveto( m_gpc,
1203 XLOG2DEV(x+width), YLOG2DEV(y+height),
1204 XLOG2DEV(x), YLOG2DEV(y+height),
1205 XLOG2DEV(x), YLOG2DEV(y+height/2) );
1206
1207 gs_lgp->gnome_print_closepath( m_gpc );
1208 gs_lgp->gnome_print_stroke( m_gpc );
1209
1210 CalcBoundingBox( x, y );
1211 CalcBoundingBox( x + width, y + height );
1212 }
1213 }
1214
1215 void wxGnomePrintDC::DoDrawSpline(wxList *points)
1216 {
1217 SetPen (m_pen);
1218
1219 double c, d, x1, y1, x2, y2, x3, y3;
1220 wxPoint *p, *q;
1221
1222 wxList::compatibility_iterator node = points->GetFirst();
1223 p = (wxPoint *)node->GetData();
1224 x1 = p->x;
1225 y1 = p->y;
1226
1227 node = node->GetNext();
1228 p = (wxPoint *)node->GetData();
1229 c = p->x;
1230 d = p->y;
1231 x3 =
1232 (double)(x1 + c) / 2;
1233 y3 =
1234 (double)(y1 + d) / 2;
1235
1236 gs_lgp->gnome_print_newpath( m_gpc );
1237 gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
1238 gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1239
1240 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1241 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1242
1243 node = node->GetNext();
1244 while (node)
1245 {
1246 q = (wxPoint *)node->GetData();
1247
1248 x1 = x3;
1249 y1 = y3;
1250 x2 = c;
1251 y2 = d;
1252 c = q->x;
1253 d = q->y;
1254 x3 = (double)(x2 + c) / 2;
1255 y3 = (double)(y2 + d) / 2;
1256
1257 gs_lgp->gnome_print_curveto(m_gpc,
1258 XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
1259 XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
1260 XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1261
1262 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1263 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1264
1265 node = node->GetNext();
1266 }
1267
1268 gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
1269
1270 gs_lgp->gnome_print_stroke( m_gpc );
1271 }
1272
1273 bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1274 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask,
1275 wxCoord xsrcMask, wxCoord ysrcMask)
1276 {
1277 wxCHECK_MSG( source, false, wxT("invalid source dc") );
1278
1279 // blit into a bitmap
1280 wxBitmap bitmap( width, height );
1281 wxMemoryDC memDC;
1282 memDC.SelectObject(bitmap);
1283 memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
1284 memDC.SelectObject(wxNullBitmap);
1285
1286 // draw bitmap. scaling and positioning is done there
1287 DrawBitmap( bitmap, xdest, ydest );
1288
1289 return true;
1290 }
1291
1292 void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
1293 {
1294 DoDrawBitmap( icon, x, y, true );
1295 }
1296
1297 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
1298 {
1299 if (!bitmap.Ok()) return;
1300
1301 if (bitmap.HasPixbuf())
1302 {
1303 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
1304 guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf );
1305 bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf );
1306 int rowstride = gdk_pixbuf_get_rowstride( pixbuf );
1307 int height = gdk_pixbuf_get_height( pixbuf );
1308 int width = gdk_pixbuf_get_width( pixbuf );
1309
1310 gs_lgp->gnome_print_gsave( m_gpc );
1311 double matrix[6];
1312 matrix[0] = XLOG2DEVREL(width);
1313 matrix[1] = 0;
1314 matrix[2] = 0;
1315 matrix[3] = YLOG2DEVREL(height);
1316 matrix[4] = XLOG2DEV(x);
1317 matrix[5] = YLOG2DEV(y+height);
1318 gs_lgp->gnome_print_concat( m_gpc, matrix );
1319 gs_lgp->gnome_print_moveto( m_gpc, 0, 0 );
1320 if (has_alpha)
1321 gs_lgp->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1322 else
1323 gs_lgp->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1324 gs_lgp->gnome_print_grestore( m_gpc );
1325 }
1326 else
1327 {
1328 wxImage image = bitmap.ConvertToImage();
1329
1330 if (!image.Ok()) return;
1331
1332 gs_lgp->gnome_print_gsave( m_gpc );
1333 double matrix[6];
1334 matrix[0] = XLOG2DEVREL(image.GetWidth());
1335 matrix[1] = 0;
1336 matrix[2] = 0;
1337 matrix[3] = YLOG2DEVREL(image.GetHeight());
1338 matrix[4] = XLOG2DEV(x);
1339 matrix[5] = YLOG2DEV(y+image.GetHeight());
1340 gs_lgp->gnome_print_concat( m_gpc, matrix );
1341 gs_lgp->gnome_print_moveto( m_gpc, 0, 0 );
1342 gs_lgp->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 );
1343 gs_lgp->gnome_print_grestore( m_gpc );
1344 }
1345 }
1346
1347 void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
1348 {
1349 DoDrawRotatedText( text, x, y, 0.0 );
1350 }
1351
1352 void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1353 {
1354 x = XLOG2DEV(x);
1355 y = YLOG2DEV(y);
1356
1357 bool underlined = m_font.Ok() && m_font.GetUnderlined();
1358
1359 #if wxUSE_UNICODE
1360 const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
1361 #else
1362 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
1363 if ( !wdata )
1364 return;
1365 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
1366 #endif
1367
1368 size_t datalen = strlen((const char*)data);
1369 pango_layout_set_text( m_layout, (const char*) data, datalen);
1370
1371 if (underlined)
1372 {
1373 PangoAttrList *attrs = pango_attr_list_new();
1374 PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1375 a->start_index = 0;
1376 a->end_index = datalen;
1377 pango_attr_list_insert(attrs, a);
1378 pango_layout_set_attributes(m_layout, attrs);
1379 pango_attr_list_unref(attrs);
1380 }
1381
1382 if (m_textForegroundColour.Ok())
1383 {
1384 unsigned char red = m_textForegroundColour.Red();
1385 unsigned char blue = m_textForegroundColour.Blue();
1386 unsigned char green = m_textForegroundColour.Green();
1387
1388 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1389 {
1390 double redPS = (double)(red) / 255.0;
1391 double bluePS = (double)(blue) / 255.0;
1392 double greenPS = (double)(green) / 255.0;
1393
1394 gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1395
1396 m_currentRed = red;
1397 m_currentBlue = blue;
1398 m_currentGreen = green;
1399 }
1400 }
1401
1402 int w,h;
1403
1404 if (fabs(m_scaleY - 1.0) > 0.00001)
1405 {
1406 // If there is a user or actually any scale applied to
1407 // the device context, scale the font.
1408
1409 // scale font description
1410 gint oldSize = pango_font_description_get_size( m_fontdesc );
1411 double size = oldSize;
1412 size = size * m_scaleY;
1413 pango_font_description_set_size( m_fontdesc, (gint)size );
1414
1415 // actually apply scaled font
1416 pango_layout_set_font_description( m_layout, m_fontdesc );
1417
1418 pango_layout_get_pixel_size( m_layout, &w, &h );
1419 #if 0
1420 if ( m_backgroundMode == wxSOLID )
1421 {
1422 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1423 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1424 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1425 }
1426 #endif
1427 // Draw layout.
1428 gs_lgp->gnome_print_moveto (m_gpc, x, y);
1429 if (fabs(angle) > 0.00001)
1430 {
1431 gs_lgp->gnome_print_gsave( m_gpc );
1432 gs_lgp->gnome_print_rotate( m_gpc, angle );
1433 gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
1434 gs_lgp->gnome_print_grestore( m_gpc );
1435 }
1436 else
1437 {
1438 gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
1439 }
1440
1441 // reset unscaled size
1442 pango_font_description_set_size( m_fontdesc, oldSize );
1443
1444 // actually apply unscaled font
1445 pango_layout_set_font_description( m_layout, m_fontdesc );
1446 }
1447 else
1448 {
1449 pango_layout_get_pixel_size( m_layout, &w, &h );
1450 #if 0
1451 if ( m_backgroundMode == wxSOLID )
1452 {
1453 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1454 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1455 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1456 }
1457 #endif
1458 // Draw layout.
1459 gs_lgp->gnome_print_moveto (m_gpc, x, y);
1460 if (fabs(angle) > 0.00001)
1461 {
1462 gs_lgp->gnome_print_gsave( m_gpc );
1463 gs_lgp->gnome_print_rotate( m_gpc, angle );
1464 gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
1465 gs_lgp->gnome_print_grestore( m_gpc );
1466 }
1467 else
1468 {
1469 gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
1470 }
1471 }
1472
1473 if (underlined)
1474 {
1475 // undo underline attributes setting:
1476 pango_layout_set_attributes(m_layout, NULL);
1477 }
1478
1479 CalcBoundingBox (x + w, y + h);
1480 }
1481
1482 void wxGnomePrintDC::Clear()
1483 {
1484 }
1485
1486 void wxGnomePrintDC::SetFont( const wxFont& font )
1487 {
1488 m_font = font;
1489
1490 if (m_font.Ok())
1491 {
1492 if (m_fontdesc)
1493 pango_font_description_free( m_fontdesc );
1494
1495 m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
1496
1497 pango_layout_set_font_description( m_layout, m_fontdesc );
1498 }
1499 }
1500
1501 void wxGnomePrintDC::SetPen( const wxPen& pen )
1502 {
1503 if (!pen.Ok()) return;
1504
1505 m_pen = pen;
1506
1507 gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f );
1508
1509 static const double dotted[] = {2.0, 5.0};
1510 static const double short_dashed[] = {4.0, 4.0};
1511 static const double wxCoord_dashed[] = {4.0, 8.0};
1512 static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
1513
1514 switch (m_pen.GetStyle())
1515 {
1516 case wxDOT: gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
1517 case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
1518 case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
1519 case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break;
1520 case wxSOLID:
1521 case wxTRANSPARENT:
1522 default: gs_lgp->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break;
1523 }
1524
1525
1526 unsigned char red = m_pen.GetColour().Red();
1527 unsigned char blue = m_pen.GetColour().Blue();
1528 unsigned char green = m_pen.GetColour().Green();
1529
1530 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1531 {
1532 double redPS = (double)(red) / 255.0;
1533 double bluePS = (double)(blue) / 255.0;
1534 double greenPS = (double)(green) / 255.0;
1535
1536 gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1537
1538 m_currentRed = red;
1539 m_currentBlue = blue;
1540 m_currentGreen = green;
1541 }
1542 }
1543
1544 void wxGnomePrintDC::SetBrush( const wxBrush& brush )
1545 {
1546 if (!brush.Ok()) return;
1547
1548 m_brush = brush;
1549
1550 // Brush colour
1551 unsigned char red = m_brush.GetColour().Red();
1552 unsigned char blue = m_brush.GetColour().Blue();
1553 unsigned char green = m_brush.GetColour().Green();
1554
1555 if (!m_colour)
1556 {
1557 // Anything not white is black
1558 if (! (red == (unsigned char) 255 &&
1559 blue == (unsigned char) 255 &&
1560 green == (unsigned char) 255) )
1561 {
1562 red = (unsigned char) 0;
1563 green = (unsigned char) 0;
1564 blue = (unsigned char) 0;
1565 }
1566 // setgray here ?
1567 }
1568
1569 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1570 {
1571 double redPS = (double)(red) / 255.0;
1572 double bluePS = (double)(blue) / 255.0;
1573 double greenPS = (double)(green) / 255.0;
1574
1575 gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1576
1577 m_currentRed = red;
1578 m_currentBlue = blue;
1579 m_currentGreen = green;
1580 }
1581 }
1582
1583 void wxGnomePrintDC::SetLogicalFunction( int function )
1584 {
1585 }
1586
1587 void wxGnomePrintDC::SetBackground( const wxBrush& brush )
1588 {
1589 }
1590
1591 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1592 {
1593 }
1594
1595 void wxGnomePrintDC::DestroyClippingRegion()
1596 {
1597 }
1598
1599 bool wxGnomePrintDC::StartDoc(const wxString& message)
1600 {
1601 SetDeviceOrigin( 0,0 );
1602
1603 return true;
1604 }
1605
1606 void wxGnomePrintDC::EndDoc()
1607 {
1608 gs_lgp->gnome_print_end_doc( m_gpc );
1609 }
1610
1611 void wxGnomePrintDC::StartPage()
1612 {
1613 gs_lgp->gnome_print_beginpage( m_gpc, (const guchar*) "page" );
1614 }
1615
1616 void wxGnomePrintDC::EndPage()
1617 {
1618 gs_lgp->gnome_print_showpage( m_gpc );
1619 }
1620
1621 wxCoord wxGnomePrintDC::GetCharHeight() const
1622 {
1623 pango_layout_set_text( m_layout, "H", 1 );
1624
1625 int w,h;
1626 pango_layout_get_pixel_size( m_layout, &w, &h );
1627
1628 return h;
1629 }
1630
1631 wxCoord wxGnomePrintDC::GetCharWidth() const
1632 {
1633 pango_layout_set_text( m_layout, "H", 1 );
1634
1635 int w,h;
1636 pango_layout_get_pixel_size( m_layout, &w, &h );
1637
1638 return w;
1639 }
1640
1641 void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
1642 wxCoord *descent,
1643 wxCoord *externalLeading,
1644 wxFont *theFont ) const
1645 {
1646 if ( width )
1647 *width = 0;
1648 if ( height )
1649 *height = 0;
1650 if ( descent )
1651 *descent = 0;
1652 if ( externalLeading )
1653 *externalLeading = 0;
1654
1655 if (string.IsEmpty())
1656 {
1657 return;
1658 }
1659
1660 // Set new font description
1661 if (theFont)
1662 pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description );
1663
1664 // Set layout's text
1665 #if wxUSE_UNICODE
1666 const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
1667 const char *dataUTF8 = (const char *)data;
1668 #else
1669 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
1670 if ( !wdata )
1671 {
1672 if (width) (*width) = 0;
1673 if (height) (*height) = 0;
1674 return;
1675 }
1676 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
1677 const char *dataUTF8 = (const char *)data;
1678 #endif
1679
1680 if ( !dataUTF8 )
1681 {
1682 // hardly ideal, but what else can we do if conversion failed?
1683 return;
1684 }
1685
1686 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
1687
1688 int w,h;
1689 pango_layout_get_pixel_size( m_layout, &w, &h );
1690
1691 if (width)
1692 *width = (wxCoord)(w / m_scaleX);
1693 if (height)
1694 *height = (wxCoord)(h / m_scaleY);
1695 if (descent)
1696 {
1697 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1698 int baseline = pango_layout_iter_get_baseline(iter);
1699 pango_layout_iter_free(iter);
1700 *descent = h - PANGO_PIXELS(baseline);
1701 }
1702
1703 // Reset old font description
1704 if (theFont)
1705 pango_layout_set_font_description( m_layout, m_fontdesc );
1706 }
1707
1708 void wxGnomePrintDC::DoGetSize(int* width, int* height) const
1709 {
1710 wxGnomePrintNativeData *native =
1711 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1712
1713 // Query page size. This seems to omit the margins
1714 // right now, although it shouldn't
1715 double pw,ph;
1716 gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1717
1718 if (width)
1719 *width = (int) (pw + 0.5);
1720 if (height)
1721 *height = (int) (ph + 0.5);
1722 }
1723
1724 void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
1725 {
1726 wxGnomePrintNativeData *native =
1727 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1728
1729 // This code assumes values in Pts.
1730
1731 double pw,ph;
1732 gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1733
1734 // Convert to mm.
1735
1736 const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" );
1737 const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" );
1738 gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit );
1739 gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit );
1740
1741 if (width)
1742 *width = (int) (pw + 0.5);
1743 if (height)
1744 *height = (int) (ph + 0.5);
1745 }
1746
1747 wxSize wxGnomePrintDC::GetPPI() const
1748 {
1749 return wxSize(72,72);
1750 }
1751
1752 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
1753 {
1754 m_signX = (xLeftRight ? 1 : -1);
1755 m_signY = (yBottomUp ? 1 : -1);
1756
1757 ComputeScaleAndOrigin();
1758 }
1759
1760 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y )
1761 {
1762 int h = 0;
1763 int w = 0;
1764 GetSize( &w, &h );
1765
1766 wxDC::SetDeviceOrigin( x, h-y );
1767 }
1768
1769 void wxGnomePrintDC::SetResolution(int ppi)
1770 {
1771 }
1772
1773 int wxGnomePrintDC::GetResolution()
1774 {
1775 return 72;
1776 }
1777
1778
1779 class wxGnomePrintModule: public wxModule
1780 {
1781 public:
1782 wxGnomePrintModule() {}
1783 bool OnInit();
1784 void OnExit();
1785
1786 private:
1787 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule)
1788 };
1789
1790 bool wxGnomePrintModule::OnInit()
1791 {
1792 gs_lgp = new wxGnomePrintLibrary;
1793 if (gs_lgp->IsOk())
1794 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory );
1795 return true;
1796 }
1797
1798 void wxGnomePrintModule::OnExit()
1799 {
1800 delete gs_lgp;
1801 }
1802
1803 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
1804
1805 #endif
1806 // wxUSE_LIBGNOMEPRINT