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