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