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