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