]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gnome/gprint.cpp
Reduce width and height of drawing ops by one in all vector printing backends
[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 if ( wxIsNullDouble(radius) )
1035 {
1036 alpha1 =
1037 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 x = points[i].x + xoffset;
1165 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 x = points[i].x + xoffset;
1185 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 width--;
1202 height--;
1203
1204 if (m_brush.GetStyle () != wxTRANSPARENT)
1205 {
1206 SetBrush( m_brush );
1207
1208 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1209 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1210 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1211 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1212 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1213 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1214 gs_libGnomePrint->gnome_print_fill( m_gpc );
1215
1216 CalcBoundingBox( x, y );
1217 CalcBoundingBox( x + width, y + height );
1218 }
1219
1220 if (m_pen.GetStyle () != wxTRANSPARENT)
1221 {
1222 SetPen (m_pen);
1223
1224 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1225 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1226 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1227 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1228 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1229 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1230 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1231
1232 CalcBoundingBox( x, y );
1233 CalcBoundingBox( x + width, y + height );
1234 }
1235 }
1236
1237 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
1238 {
1239 width--;
1240 height--;
1241
1242 wxCoord rad = wxRound( radius );
1243
1244 if (m_brush.GetStyle() != wxTRANSPARENT)
1245 {
1246 SetBrush(m_brush);
1247 gs_libGnomePrint->gnome_print_newpath(m_gpc);
1248 gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1249 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1250 XLOG2DEV(x + rad),YLOG2DEV(y),
1251 XLOG2DEV(x),YLOG2DEV(y),
1252 XLOG2DEV(x),YLOG2DEV(y + rad));
1253 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1254 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1255 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1256 XLOG2DEV(x),YLOG2DEV(y + height),
1257 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1258 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1259 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1260 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1261 XLOG2DEV(x + width),YLOG2DEV(y + height),
1262 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1263 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1264 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1265 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1266 XLOG2DEV(x + width),YLOG2DEV(y),
1267 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1268 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1269 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1270 gs_libGnomePrint->gnome_print_fill(m_gpc);
1271
1272 CalcBoundingBox(x,y);
1273 CalcBoundingBox(x+width,y+height);
1274 }
1275
1276 if (m_pen.GetStyle() != wxTRANSPARENT)
1277 {
1278 SetPen(m_pen);
1279 gs_libGnomePrint->gnome_print_newpath(m_gpc);
1280 gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1281 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1282 XLOG2DEV(x + rad),YLOG2DEV(y),
1283 XLOG2DEV(x),YLOG2DEV(y),
1284 XLOG2DEV(x),YLOG2DEV(y + rad));
1285 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1286 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1287 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1288 XLOG2DEV(x),YLOG2DEV(y + height),
1289 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1290 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1291 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1292 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1293 XLOG2DEV(x + width),YLOG2DEV(y + height),
1294 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1295 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1296 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1297 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1298 XLOG2DEV(x + width),YLOG2DEV(y),
1299 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1300 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1301 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1302 gs_libGnomePrint->gnome_print_stroke(m_gpc);
1303
1304 CalcBoundingBox(x,y);
1305 CalcBoundingBox(x+width,y+height);
1306 }
1307 }
1308
1309 void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y,
1310 wxCoord width, wxCoord height)
1311 {
1312 double r = 4 * (sqrt(2.) - 1) / 3;
1313 double halfW = 0.5 * width,
1314 halfH = 0.5 * height,
1315 halfWR = r * halfW,
1316 halfHR = r * halfH;
1317 wxCoord halfWI = (wxCoord) halfW,
1318 halfHI = (wxCoord) halfH;
1319
1320 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1321
1322 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1323 gs_libGnomePrint->gnome_print_moveto( m_gpc,
1324 XLOG2DEV(x + width),
1325 YLOG2DEV(y + halfHI) );
1326 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1327 XLOG2DEV(x + width),
1328 YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
1329 XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
1330 YLOG2DEV(y + height),
1331 XLOG2DEV(x + halfWI),
1332 YLOG2DEV(y + height) );
1333 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1334 XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)),
1335 YLOG2DEV(y + height),
1336 XLOG2DEV(x),
1337 YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
1338 XLOG2DEV(x), YLOG2DEV(y+halfHI) );
1339 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1340 XLOG2DEV(x),
1341 YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)),
1342 XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)),
1343 YLOG2DEV(y),
1344 XLOG2DEV(x+halfWI), YLOG2DEV(y) );
1345 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1346 XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
1347 YLOG2DEV(y),
1348 XLOG2DEV(x + width),
1349 YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)),
1350 XLOG2DEV(x + width), YLOG2DEV(y + halfHI) );
1351
1352 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1353 }
1354
1355 void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1356 {
1357 width--;
1358 height--;
1359
1360 if (m_brush.GetStyle () != wxTRANSPARENT)
1361 {
1362 SetBrush( m_brush );
1363 makeEllipticalPath( x, y, width, height );
1364 gs_libGnomePrint->gnome_print_fill( m_gpc );
1365 CalcBoundingBox( x, y );
1366 CalcBoundingBox( x + width, y + height );
1367 }
1368
1369 if (m_pen.GetStyle () != wxTRANSPARENT)
1370 {
1371 SetPen (m_pen);
1372 makeEllipticalPath( x, y, width, height );
1373 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1374 CalcBoundingBox( x, y );
1375 CalcBoundingBox( x + width, y + height );
1376 }
1377 }
1378
1379 #if wxUSE_SPLINES
1380 void wxGnomePrintDC::DoDrawSpline(wxList *points)
1381 {
1382 SetPen (m_pen);
1383
1384 double c, d, x1, y1, x2, y2, x3, y3;
1385 wxPoint *p, *q;
1386
1387 wxList::compatibility_iterator node = points->GetFirst();
1388 p = (wxPoint *)node->GetData();
1389 x1 = p->x;
1390 y1 = p->y;
1391
1392 node = node->GetNext();
1393 p = (wxPoint *)node->GetData();
1394 c = p->x;
1395 d = p->y;
1396 x3 =
1397 (double)(x1 + c) / 2;
1398 y3 =
1399 (double)(y1 + d) / 2;
1400
1401 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1402 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
1403 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1404
1405 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1406 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1407
1408 node = node->GetNext();
1409 while (node)
1410 {
1411 q = (wxPoint *)node->GetData();
1412
1413 x1 = x3;
1414 y1 = y3;
1415 x2 = c;
1416 y2 = d;
1417 c = q->x;
1418 d = q->y;
1419 x3 = (double)(x2 + c) / 2;
1420 y3 = (double)(y2 + d) / 2;
1421
1422 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1423 XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
1424 XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
1425 XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1426
1427 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1428 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1429
1430 node = node->GetNext();
1431 }
1432
1433 gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
1434
1435 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1436 }
1437 #endif // wxUSE_SPLINES
1438
1439 bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1440 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask,
1441 wxCoord xsrcMask, wxCoord ysrcMask)
1442 {
1443 wxCHECK_MSG( source, false, wxT("invalid source dc") );
1444
1445 // blit into a bitmap
1446 wxBitmap bitmap( width, height );
1447 wxMemoryDC memDC;
1448 memDC.SelectObject(bitmap);
1449 memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
1450 memDC.SelectObject(wxNullBitmap);
1451
1452 // draw bitmap. scaling and positioning is done there
1453 DrawBitmap( bitmap, xdest, ydest );
1454
1455 return true;
1456 }
1457
1458 void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
1459 {
1460 DoDrawBitmap( icon, x, y, true );
1461 }
1462
1463 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
1464 {
1465 if (!bitmap.Ok()) return;
1466
1467 if (bitmap.HasPixbuf())
1468 {
1469 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
1470 guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf );
1471 bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf );
1472 int rowstride = gdk_pixbuf_get_rowstride( pixbuf );
1473 int height = gdk_pixbuf_get_height( pixbuf );
1474 int width = gdk_pixbuf_get_width( pixbuf );
1475
1476 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1477 double matrix[6];
1478 matrix[0] = XLOG2DEVREL(width);
1479 matrix[1] = 0;
1480 matrix[2] = 0;
1481 matrix[3] = YLOG2DEVREL(height);
1482 matrix[4] = XLOG2DEV(x);
1483 matrix[5] = YLOG2DEV(y+height);
1484 gs_libGnomePrint->gnome_print_concat( m_gpc, matrix );
1485 gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 );
1486 if (has_alpha)
1487 gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1488 else
1489 gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1490 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1491 }
1492 else
1493 {
1494 wxImage image = bitmap.ConvertToImage();
1495
1496 if (!image.Ok()) return;
1497
1498 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1499 double matrix[6];
1500 matrix[0] = XLOG2DEVREL(image.GetWidth());
1501 matrix[1] = 0;
1502 matrix[2] = 0;
1503 matrix[3] = YLOG2DEVREL(image.GetHeight());
1504 matrix[4] = XLOG2DEV(x);
1505 matrix[5] = YLOG2DEV(y+image.GetHeight());
1506 gs_libGnomePrint->gnome_print_concat( m_gpc, matrix );
1507 gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 );
1508 gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 );
1509 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1510 }
1511 }
1512
1513 void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
1514 {
1515 DoDrawRotatedText( text, x, y, 0.0 );
1516 }
1517
1518 void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1519 {
1520 double xx = XLOG2DEV(x);
1521 double yy = YLOG2DEV(y);
1522
1523 bool underlined = m_font.Ok() && m_font.GetUnderlined();
1524
1525 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1526 #if wxUSE_UNICODE_UTF8
1527 const char *data = text.utf8_str();
1528 #else
1529 const wxCharBuffer data = text.utf8_str();
1530 #endif
1531
1532 size_t datalen = strlen(data);
1533 pango_layout_set_text( m_layout, data, datalen);
1534
1535 if (underlined)
1536 {
1537 PangoAttrList *attrs = pango_attr_list_new();
1538 PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1539 a->start_index = 0;
1540 a->end_index = datalen;
1541 pango_attr_list_insert(attrs, a);
1542 pango_layout_set_attributes(m_layout, attrs);
1543 pango_attr_list_unref(attrs);
1544 }
1545
1546 if (m_textForegroundColour.Ok())
1547 {
1548 unsigned char red = m_textForegroundColour.Red();
1549 unsigned char blue = m_textForegroundColour.Blue();
1550 unsigned char green = m_textForegroundColour.Green();
1551
1552 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1553 {
1554 double redPS = (double)(red) / 255.0;
1555 double bluePS = (double)(blue) / 255.0;
1556 double greenPS = (double)(green) / 255.0;
1557
1558 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1559
1560 m_currentRed = red;
1561 m_currentBlue = blue;
1562 m_currentGreen = green;
1563 }
1564 }
1565
1566 int w,h;
1567 pango_layout_get_pixel_size( m_layout, &w, &h );
1568 #if 0
1569 if ( m_backgroundMode == wxSOLID )
1570 {
1571 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1572 gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h);
1573 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1574 }
1575 #endif
1576
1577 // Draw layout.
1578 gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy);
1579
1580 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1581
1582 gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS );
1583
1584 if (fabs(angle) > 0.00001)
1585 gs_libGnomePrint->gnome_print_rotate( m_gpc, angle );
1586
1587 gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout );
1588
1589 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1590
1591 if (underlined)
1592 {
1593 // undo underline attributes setting:
1594 pango_layout_set_attributes(m_layout, NULL);
1595 }
1596
1597 CalcBoundingBox (x + w, y + h);
1598 }
1599
1600 void wxGnomePrintDC::Clear()
1601 {
1602 }
1603
1604 void wxGnomePrintDC::SetFont( const wxFont& font )
1605 {
1606 m_font = font;
1607
1608 if (m_font.Ok())
1609 {
1610 if (m_fontdesc)
1611 pango_font_description_free( m_fontdesc );
1612
1613 m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
1614
1615 pango_layout_set_font_description( m_layout, m_fontdesc );
1616 }
1617 }
1618
1619 void wxGnomePrintDC::SetPen( const wxPen& pen )
1620 {
1621 if (!pen.Ok()) return;
1622
1623 m_pen = pen;
1624
1625 double width;
1626
1627 if (m_pen.GetWidth() <= 0)
1628 width = 0.1;
1629 else
1630 width = (double) m_pen.GetWidth();
1631
1632 gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX );
1633
1634 static const double dotted[] = {2.0, 5.0};
1635 static const double short_dashed[] = {4.0, 4.0};
1636 static const double wxCoord_dashed[] = {4.0, 8.0};
1637 static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
1638
1639 switch (m_pen.GetStyle())
1640 {
1641 case wxDOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
1642 case wxSHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
1643 case wxLONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
1644 case wxDOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break;
1645 case wxUSER_DASH:
1646 {
1647 // It may be noted that libgnomeprint between at least
1648 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1649 // and then leak the memory since it doesn't set the
1650 // internal flag "privatedash" to 0.
1651 wxDash *wx_dashes;
1652 int num = m_pen.GetDashes (&wx_dashes);
1653 gdouble *g_dashes = g_new( gdouble, num );
1654 int i;
1655 for (i = 0; i < num; ++i)
1656 g_dashes[i] = (gdouble) wx_dashes[i];
1657 gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0);
1658 g_free( g_dashes );
1659 }
1660 break;
1661 case wxSOLID:
1662 case wxTRANSPARENT:
1663 default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break;
1664 }
1665
1666
1667 unsigned char red = m_pen.GetColour().Red();
1668 unsigned char blue = m_pen.GetColour().Blue();
1669 unsigned char green = m_pen.GetColour().Green();
1670
1671 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1672 {
1673 double redPS = (double)(red) / 255.0;
1674 double bluePS = (double)(blue) / 255.0;
1675 double greenPS = (double)(green) / 255.0;
1676
1677 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1678
1679 m_currentRed = red;
1680 m_currentBlue = blue;
1681 m_currentGreen = green;
1682 }
1683 }
1684
1685 void wxGnomePrintDC::SetBrush( const wxBrush& brush )
1686 {
1687 if (!brush.Ok()) return;
1688
1689 m_brush = brush;
1690
1691 // Brush colour
1692 unsigned char red = m_brush.GetColour().Red();
1693 unsigned char blue = m_brush.GetColour().Blue();
1694 unsigned char green = m_brush.GetColour().Green();
1695
1696 if (!m_colour)
1697 {
1698 // Anything not white is black
1699 if (! (red == (unsigned char) 255 &&
1700 blue == (unsigned char) 255 &&
1701 green == (unsigned char) 255) )
1702 {
1703 red = (unsigned char) 0;
1704 green = (unsigned char) 0;
1705 blue = (unsigned char) 0;
1706 }
1707 // setgray here ?
1708 }
1709
1710 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1711 {
1712 double redPS = (double)(red) / 255.0;
1713 double bluePS = (double)(blue) / 255.0;
1714 double greenPS = (double)(green) / 255.0;
1715
1716 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1717
1718 m_currentRed = red;
1719 m_currentBlue = blue;
1720 m_currentGreen = green;
1721 }
1722 }
1723
1724 void wxGnomePrintDC::SetLogicalFunction( int function )
1725 {
1726 }
1727
1728 void wxGnomePrintDC::SetBackground( const wxBrush& brush )
1729 {
1730 }
1731
1732 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1733 {
1734 wxDC::DoSetClippingRegion( x, y, width, height );
1735
1736 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1737
1738 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1739 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1740 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1741 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1742 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1743 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1744 gs_libGnomePrint->gnome_print_clip( m_gpc );
1745 }
1746
1747 void wxGnomePrintDC::DestroyClippingRegion()
1748 {
1749 wxDC::DestroyClippingRegion();
1750
1751 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1752
1753 #if 0
1754 // not needed, we set the values in each
1755 // drawing method anyways
1756 SetPen( m_pen );
1757 SetBrush( m_brush );
1758 SetFont( m_font );
1759 #endif
1760 }
1761
1762 bool wxGnomePrintDC::StartDoc(const wxString& message)
1763 {
1764 return true;
1765 }
1766
1767 void wxGnomePrintDC::EndDoc()
1768 {
1769 gs_libGnomePrint->gnome_print_end_doc( m_gpc );
1770 }
1771
1772 void wxGnomePrintDC::StartPage()
1773 {
1774 gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" );
1775 }
1776
1777 void wxGnomePrintDC::EndPage()
1778 {
1779 gs_libGnomePrint->gnome_print_showpage( m_gpc );
1780 }
1781
1782 wxCoord wxGnomePrintDC::GetCharHeight() const
1783 {
1784 pango_layout_set_text( m_layout, "H", 1 );
1785
1786 int w,h;
1787 pango_layout_get_pixel_size( m_layout, &w, &h );
1788
1789 return h;
1790 }
1791
1792 wxCoord wxGnomePrintDC::GetCharWidth() const
1793 {
1794 pango_layout_set_text( m_layout, "H", 1 );
1795
1796 int w,h;
1797 pango_layout_get_pixel_size( m_layout, &w, &h );
1798
1799 return w;
1800 }
1801
1802 void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
1803 wxCoord *descent,
1804 wxCoord *externalLeading,
1805 const wxFont *theFont ) const
1806 {
1807 if ( width )
1808 *width = 0;
1809 if ( height )
1810 *height = 0;
1811 if ( descent )
1812 *descent = 0;
1813 if ( externalLeading )
1814 *externalLeading = 0;
1815
1816 if (string.empty())
1817 {
1818 return;
1819 }
1820
1821 // Set layout's text
1822
1823 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1824 #if wxUSE_UNICODE_UTF8
1825 const char *dataUTF8 = string.utf8_str();
1826 #else
1827 const wxCharBuffer dataUTF8 = string.utf8_str();
1828 #endif
1829
1830 PangoFontDescription *desc = (theFont) ? theFont->GetNativeFontInfo()->description : m_fontdesc;
1831
1832 gint oldSize = pango_font_description_get_size( desc );
1833 double size = oldSize;
1834 size = size * m_scaleY;
1835 pango_font_description_set_size( desc, (gint)size );
1836
1837 // apply scaled font
1838 pango_layout_set_font_description( m_layout, desc );
1839
1840 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
1841
1842 int w, h;
1843 pango_layout_get_pixel_size( m_layout, &w, &h );
1844
1845
1846 if (width)
1847 *width = (wxCoord)(w / m_scaleX);
1848 if (height)
1849 *height = (wxCoord)(h / m_scaleY);
1850
1851 if (descent)
1852 {
1853 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1854 int baseline = pango_layout_iter_get_baseline(iter);
1855 pango_layout_iter_free(iter);
1856 *descent = h - PANGO_PIXELS(baseline);
1857 }
1858
1859 // reset unscaled size
1860 pango_font_description_set_size( desc, oldSize );
1861
1862 // reset unscaled font
1863 pango_layout_set_font_description( m_layout, m_fontdesc );
1864 }
1865
1866 void wxGnomePrintDC::DoGetSize(int* width, int* height) const
1867 {
1868 wxGnomePrintNativeData *native =
1869 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1870
1871 // Query page size. This seems to omit the margins
1872 double pw,ph;
1873 gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1874
1875 if (width)
1876 *width = wxRound( pw * PS2DEV );
1877
1878 if (height)
1879 *height = wxRound( ph * PS2DEV );
1880 }
1881
1882 void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
1883 {
1884 wxGnomePrintNativeData *native =
1885 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1886
1887 // This code assumes values in Pts.
1888
1889 double pw,ph;
1890 gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1891
1892 // Convert to mm.
1893
1894 const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" );
1895 const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" );
1896 gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit );
1897 gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit );
1898
1899 if (width)
1900 *width = (int) (pw + 0.5);
1901 if (height)
1902 *height = (int) (ph + 0.5);
1903 }
1904
1905 wxSize wxGnomePrintDC::GetPPI() const
1906 {
1907 return wxSize(DPI,DPI);
1908 }
1909
1910 void wxGnomePrintDC::SetPrintData(const wxPrintData& data)
1911 {
1912 m_printData = data;
1913
1914 int height;
1915 if (m_printData.GetOrientation() == wxPORTRAIT)
1916 GetSize( NULL, &height );
1917 else
1918 GetSize( &height, NULL );
1919 m_deviceLocalOriginY = height;
1920 }
1921
1922 void wxGnomePrintDC::SetResolution(int ppi)
1923 {
1924 }
1925
1926 int wxGnomePrintDC::GetResolution()
1927 {
1928 return DPI;
1929 }
1930
1931 // ----------------------------------------------------------------------------
1932 // wxGnomePrintModule
1933 // ----------------------------------------------------------------------------
1934
1935 bool wxGnomePrintModule::OnInit()
1936 {
1937 gs_libGnomePrint = new wxGnomePrintLibrary;
1938 if (gs_libGnomePrint->IsOk())
1939 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory );
1940 return true;
1941 }
1942
1943 void wxGnomePrintModule::OnExit()
1944 {
1945 delete gs_libGnomePrint;
1946 gs_libGnomePrint = NULL;
1947 }
1948
1949 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
1950
1951 // ----------------------------------------------------------------------------
1952 // Print preview
1953 // ----------------------------------------------------------------------------
1954
1955 IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase)
1956
1957 void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout),
1958 wxPrintout * WXUNUSED(printoutForPrinting))
1959 {
1960 DetermineScaling();
1961 }
1962
1963 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
1964 wxPrintout *printoutForPrinting,
1965 wxPrintDialogData *data)
1966 : wxPrintPreviewBase(printout, printoutForPrinting, data)
1967 {
1968 Init(printout, printoutForPrinting);
1969 }
1970
1971 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
1972 wxPrintout *printoutForPrinting,
1973 wxPrintData *data)
1974 : wxPrintPreviewBase(printout, printoutForPrinting, data)
1975 {
1976 Init(printout, printoutForPrinting);
1977 }
1978
1979 wxGnomePrintPreview::~wxGnomePrintPreview()
1980 {
1981 }
1982
1983 bool wxGnomePrintPreview::Print(bool interactive)
1984 {
1985 if (!m_printPrintout)
1986 return false;
1987
1988 wxPrinter printer(& m_printDialogData);
1989 return printer.Print(m_previewFrame, m_printPrintout, interactive);
1990 }
1991
1992 void wxGnomePrintPreview::DetermineScaling()
1993 {
1994 wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId();
1995 if (paperType == wxPAPER_NONE)
1996 paperType = wxPAPER_NONE;
1997
1998 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
1999 if (!paper)
2000 paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
2001
2002 if (paper)
2003 {
2004 wxSize ScreenPixels = wxGetDisplaySize();
2005 wxSize ScreenMM = wxGetDisplaySizeMM();
2006
2007 m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
2008 (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
2009 m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
2010
2011 wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
2012
2013 // TODO: get better resolution information from wxGnomePrintDC, if possible.
2014
2015 sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0);
2016 sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0);
2017 wxSize sizeTenthsMM(paper->GetSize());
2018 wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
2019
2020 // If in landscape mode, we need to swap the width and height.
2021 if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE )
2022 {
2023 m_pageWidth = sizeDevUnits.y;
2024 m_pageHeight = sizeDevUnits.x;
2025 m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x);
2026 }
2027 else
2028 {
2029 m_pageWidth = sizeDevUnits.x;
2030 m_pageHeight = sizeDevUnits.y;
2031 m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y);
2032 }
2033 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
2034 m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight));
2035
2036 // At 100%, the page should look about page-size on the screen.
2037 m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
2038 m_previewScaleY = m_previewScaleX;
2039 }
2040 }
2041
2042 #endif
2043 // wxUSE_LIBGNOMEPRINT