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