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