]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/gnome/gprint.cpp
make sure theme font info is reset if anything is changed
[wxWidgets.git] / src / gtk / gnome / gprint.cpp
... / ...
CommitLineData
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"
46wxFORCE_LINK_THIS_MODULE(gnome_print)
47
48//----------------------------------------------------------------------------
49// wxGnomePrintLibrary
50//----------------------------------------------------------------------------
51
52class wxGnomePrintLibrary
53{
54public:
55 wxGnomePrintLibrary();
56 ~wxGnomePrintLibrary();
57
58 bool IsOk();
59private:
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
70public:
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 wxDECLARE_NO_COPY_CLASS(wxGnomePrintLibrary);
188};
189
190wxGnomePrintLibrary::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
210wxGnomePrintLibrary::~wxGnomePrintLibrary()
211{
212}
213
214bool wxGnomePrintLibrary::IsOk()
215{
216 return m_ok;
217}
218
219bool 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
288static wxGnomePrintLibrary* gs_libGnomePrint = NULL;
289
290//----------------------------------------------------------------------------
291// wxGnomePrintNativeData
292//----------------------------------------------------------------------------
293
294IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase)
295
296wxGnomePrintNativeData::wxGnomePrintNativeData()
297{
298 m_config = gs_libGnomePrint->gnome_print_config_default();
299 m_job = gs_libGnomePrint->gnome_print_job_new( m_config );
300}
301
302wxGnomePrintNativeData::~wxGnomePrintNativeData()
303{
304 g_object_unref (m_config);
305}
306
307bool 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
342bool 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
424wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data )
425{
426 return new wxGnomePrinter( data );
427}
428
429wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
430 wxPrintout *printout,
431 wxPrintDialogData *data )
432{
433 return new wxGnomePrintPreview( preview, printout, data );
434}
435
436wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
437 wxPrintout *printout,
438 wxPrintData *data )
439{
440 return new wxGnomePrintPreview( preview, printout, data );
441}
442
443wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
444 wxPrintDialogData *data )
445{
446 return new wxGnomePrintDialog( parent, data );
447}
448
449wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
450 wxPrintData *data )
451{
452 return new wxGnomePrintDialog( parent, data );
453}
454
455wxPageSetupDialogBase *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
468bool wxGnomePrintFactory::HasPrintSetupDialog()
469{
470 return false;
471}
472
473wxDialog *
474wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent),
475 wxPrintData * WXUNUSED(data))
476{
477 return NULL;
478}
479
480
481#if wxUSE_NEW_DC
482
483wxDCImpl* wxGnomePrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data )
484{
485 return new wxGnomePrinterDCImpl( owner, data );
486}
487
488#else
489
490wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data )
491{
492 return new wxGnomePrinterDC(data);
493}
494
495#endif
496
497bool wxGnomePrintFactory::HasOwnPrintToFile()
498{
499 return true;
500}
501
502bool wxGnomePrintFactory::HasPrinterLine()
503{
504 return true;
505}
506
507wxString wxGnomePrintFactory::CreatePrinterLine()
508{
509 // redundant now
510 return wxEmptyString;
511}
512
513bool wxGnomePrintFactory::HasStatusLine()
514{
515 // redundant now
516 return true;
517}
518
519wxString wxGnomePrintFactory::CreateStatusLine()
520{
521 // redundant now
522 return wxEmptyString;
523}
524
525wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData()
526{
527 return new wxGnomePrintNativeData;
528}
529
530//----------------------------------------------------------------------------
531// wxGnomePrintSetupDialog
532//----------------------------------------------------------------------------
533
534IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase)
535
536wxGnomePrintDialog::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
548wxGnomePrintDialog::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
560void 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
587wxGnomePrintDialog::~wxGnomePrintDialog()
588{
589 m_widget = NULL;
590}
591
592int 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
640wxDC *wxGnomePrintDialog::GetPrintDC()
641{
642 // Later
643 return NULL;
644}
645
646bool wxGnomePrintDialog::Validate()
647{
648 return true;
649}
650
651bool wxGnomePrintDialog::TransferDataToWindow()
652{
653 return true;
654}
655
656bool wxGnomePrintDialog::TransferDataFromWindow()
657{
658 return true;
659}
660
661//----------------------------------------------------------------------------
662// wxGnomePageSetupDialog
663//----------------------------------------------------------------------------
664
665IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase)
666
667wxGnomePageSetupDialog::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
726wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
727{
728}
729
730wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData()
731{
732 return m_pageDialogData;
733}
734
735int 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
794bool wxGnomePageSetupDialog::Validate()
795{
796 return true;
797}
798
799bool wxGnomePageSetupDialog::TransferDataToWindow()
800{
801 return true;
802}
803
804bool wxGnomePageSetupDialog::TransferDataFromWindow()
805{
806 return true;
807}
808
809//----------------------------------------------------------------------------
810// wxGnomePrinter
811//----------------------------------------------------------------------------
812
813IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase)
814
815wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) :
816 wxPrinterBase( data )
817{
818 m_native_preview = false;
819}
820
821wxGnomePrinter::~wxGnomePrinter()
822{
823}
824
825bool 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 printout->SetPPIScreen(wxGetDisplayPPI());
876 printout->SetPPIPrinter( dc->GetResolution(),
877 dc->GetResolution() );
878
879 printout->SetDC(dc);
880
881 int w, h;
882 dc->GetSize(&w, &h);
883 printout->SetPageSizePixels((int)w, (int)h);
884 printout->SetPaperRectPixels(wxRect(0, 0, w, h));
885 int mw, mh;
886 dc->GetSizeMM(&mw, &mh);
887 printout->SetPageSizeMM((int)mw, (int)mh);
888 printout->OnPreparePrinting();
889
890 // Get some parameters from the printout, if defined
891 int fromPage, toPage;
892 int minPage, maxPage;
893 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
894
895 if (maxPage == 0)
896 {
897 gs_libGnomePrint->gnome_print_job_close( job );
898 g_object_unref (job);
899 sm_lastError = wxPRINTER_ERROR;
900 return false;
901 }
902
903 printout->OnBeginPrinting();
904
905 int minPageNum = minPage, maxPageNum = maxPage;
906
907 if ( !m_printDialogData.GetAllPages() )
908 {
909 minPageNum = m_printDialogData.GetFromPage();
910 maxPageNum = m_printDialogData.GetToPage();
911 }
912
913
914 int copyCount;
915 for ( copyCount = 1;
916 copyCount <= m_printDialogData.GetNoCopies();
917 copyCount++ )
918 {
919 if (!printout->OnBeginDocument(minPageNum, maxPageNum))
920 {
921 wxLogError(_("Could not start printing."));
922 sm_lastError = wxPRINTER_ERROR;
923 break;
924 }
925
926 int pn;
927 for ( pn = minPageNum;
928 pn <= maxPageNum && printout->HasPage(pn);
929 pn++ )
930 {
931 dc->StartPage();
932 printout->OnPrintPage(pn);
933 dc->EndPage();
934 }
935
936 printout->OnEndDocument();
937 printout->OnEndPrinting();
938 }
939
940 gs_libGnomePrint->gnome_print_job_close( job );
941 if (m_native_preview)
942 {
943 const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview")));
944 GtkWidget *preview = gs_libGnomePrint->gnome_print_job_preview_new
945 (
946 job,
947 (const guchar *)title.data()
948 );
949 gtk_widget_show(preview);
950 }
951 else
952 {
953 gs_libGnomePrint->gnome_print_job_print( job );
954 }
955
956 g_object_unref (job);
957 delete dc;
958
959 return (sm_lastError == wxPRINTER_NO_ERROR);
960}
961
962wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent )
963{
964 wxGnomePrintDialog dialog( parent, &m_printDialogData );
965 int ret = dialog.ShowModal();
966 if (ret == wxID_CANCEL)
967 {
968 sm_lastError = wxPRINTER_CANCELLED;
969 return NULL;
970 }
971
972 m_native_preview = ret == wxID_PREVIEW;
973
974 m_printDialogData = dialog.GetPrintDialogData();
975#if wxUSE_NEW_DC
976 return new wxPrinterDC( m_printDialogData.GetPrintData() );
977#else
978 return new wxGnomePrinterDC( m_printDialogData.GetPrintData() );
979#endif
980}
981
982bool wxGnomePrinter::Setup(wxWindow * WXUNUSED(parent))
983{
984 return false;
985}
986
987//-----------------------------------------------------------------------------
988// wxGnomePrinterDC
989//-----------------------------------------------------------------------------
990
991// conversion
992static const double RAD2DEG = 180.0 / M_PI;
993
994// we don't want to use only 72 dpi from GNOME print
995static const int DPI = 600;
996static const double PS2DEV = 600.0 / 72.0;
997static const double DEV2PS = 72.0 / 600.0;
998
999#define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
1000#define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
1001#define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
1002#define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
1003
1004#if wxUSE_NEW_DC
1005IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDCImpl, wxDCImpl)
1006#else
1007IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDC, wxDC)
1008#endif
1009
1010#if wxUSE_NEW_DC
1011wxGnomePrinterDCImpl::wxGnomePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) :
1012 wxDCImpl( owner )
1013#else
1014wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData& data )
1015#endif
1016{
1017 m_printData = data;
1018
1019 wxGnomePrintNativeData *native =
1020 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1021
1022 m_job = native->GetPrintJob();
1023 m_gpc = gs_libGnomePrint->gnome_print_job_get_context (m_job);
1024
1025 m_layout = gs_libGnomePrint->gnome_print_pango_create_layout( m_gpc );
1026 m_fontdesc = pango_font_description_from_string( "Sans 12" );
1027 m_context = NULL;
1028
1029 m_currentRed = 0;
1030 m_currentBlue = 0;
1031 m_currentGreen = 0;
1032
1033 // Query page size. This seems to omit the margins
1034 double pw,ph;
1035 gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1036
1037 m_pageHeight = ph * PS2DEV;
1038}
1039
1040wxGnomePrinterDCImpl::~wxGnomePrinterDCImpl()
1041{
1042}
1043
1044bool wxGnomePrinterDCImpl::IsOk() const
1045{
1046 return true;
1047}
1048
1049bool
1050wxGnomePrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
1051 wxCoord WXUNUSED(y1),
1052 const wxColour& WXUNUSED(col),
1053 wxFloodFillStyle WXUNUSED(style))
1054{
1055 return false;
1056}
1057
1058bool
1059wxGnomePrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1),
1060 wxCoord WXUNUSED(y1),
1061 wxColour * WXUNUSED(col)) const
1062{
1063 return false;
1064}
1065
1066void wxGnomePrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
1067{
1068 if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
1069
1070 SetPen( m_pen );
1071
1072 gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
1073 gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
1074 gs_libGnomePrint->gnome_print_stroke ( m_gpc);
1075
1076 CalcBoundingBox( x1, y1 );
1077 CalcBoundingBox( x2, y2 );
1078}
1079
1080void wxGnomePrinterDCImpl::DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
1081{
1082}
1083
1084void wxGnomePrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
1085{
1086 double dx = x1 - xc;
1087 double dy = y1 - yc;
1088 double radius = sqrt((double)(dx*dx+dy*dy));
1089 double alpha1, alpha2;
1090 if (x1 == x2 && y1 == y2)
1091 {
1092 alpha1 = 0.0;
1093 alpha2 = 360.0;
1094 }
1095 else if ( wxIsNullDouble(radius) )
1096 {
1097 alpha1 =
1098 alpha2 = 0.0;
1099 }
1100 else
1101 {
1102 alpha1 = (x1 - xc == 0) ?
1103 (y1 - yc < 0) ? 90.0 : -90.0 :
1104 -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
1105 alpha2 = (x2 - xc == 0) ?
1106 (y2 - yc < 0) ? 90.0 : -90.0 :
1107 -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
1108
1109 while (alpha1 <= 0) alpha1 += 360;
1110 while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
1111 while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
1112 while (alpha2 > 360) alpha2 -= 360;
1113 }
1114
1115 if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT)
1116 {
1117 SetBrush( m_brush );
1118 gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
1119 gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
1120
1121 gs_libGnomePrint->gnome_print_fill( m_gpc );
1122 }
1123
1124 if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT)
1125 {
1126 SetPen (m_pen);
1127 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1128 gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
1129 gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
1130 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1131
1132 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1133 }
1134
1135 CalcBoundingBox (x1, y1);
1136 CalcBoundingBox (x2, y2);
1137 CalcBoundingBox (xc, yc);
1138}
1139
1140void wxGnomePrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
1141{
1142 x += w/2;
1143 y += h/2;
1144
1145 double xx = XLOG2DEV(x);
1146 double yy = YLOG2DEV(y);
1147
1148 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1149
1150 gs_libGnomePrint->gnome_print_translate( m_gpc, xx, yy );
1151 double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w);
1152 gs_libGnomePrint->gnome_print_scale( m_gpc, 1.0, scale );
1153
1154 xx = 0.0;
1155 yy = 0.0;
1156
1157 if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT)
1158 {
1159 SetBrush( m_brush );
1160
1161 gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy );
1162 gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy,
1163 XLOG2DEVREL(w)/2, sa, ea, 0 );
1164 gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy );
1165
1166 gs_libGnomePrint->gnome_print_fill( m_gpc );
1167 }
1168
1169 if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT)
1170 {
1171 SetPen (m_pen);
1172
1173 gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy,
1174 XLOG2DEVREL(w)/2, sa, ea, 0 );
1175
1176 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1177 }
1178
1179 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1180
1181 CalcBoundingBox( x, y );
1182 CalcBoundingBox( x+w, y+h );
1183}
1184
1185void wxGnomePrinterDCImpl::DoDrawPoint(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
1186{
1187}
1188
1189void wxGnomePrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
1190{
1191 if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
1192
1193 if (n <= 0) return;
1194
1195 SetPen (m_pen);
1196
1197 int i;
1198 for ( i =0; i<n ; i++ )
1199 CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset);
1200
1201 gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
1202
1203 for (i = 1; i < n; i++)
1204 gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
1205
1206 gs_libGnomePrint->gnome_print_stroke ( m_gpc);
1207}
1208
1209void wxGnomePrinterDCImpl::DoDrawPolygon(int n, wxPoint points[],
1210 wxCoord xoffset, wxCoord yoffset,
1211 wxPolygonFillMode WXUNUSED(fillStyle))
1212{
1213 if (n==0) return;
1214
1215 if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT)
1216 {
1217 SetBrush( m_brush );
1218
1219 int x = points[0].x + xoffset;
1220 int y = points[0].y + yoffset;
1221 CalcBoundingBox( x, y );
1222 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1223 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1224 int i;
1225 for (i = 1; i < n; i++)
1226 {
1227 x = points[i].x + xoffset;
1228 y = points[i].y + yoffset;
1229 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1230 CalcBoundingBox( x, y );
1231 }
1232 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1233 gs_libGnomePrint->gnome_print_fill( m_gpc );
1234 }
1235
1236 if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT)
1237 {
1238 SetPen (m_pen);
1239
1240 int x = points[0].x + xoffset;
1241 int y = points[0].y + yoffset;
1242 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1243 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1244 int i;
1245 for (i = 1; i < n; i++)
1246 {
1247 x = points[i].x + xoffset;
1248 y = points[i].y + yoffset;
1249 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1250 CalcBoundingBox( x, y );
1251 }
1252 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1253 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1254 }
1255}
1256
1257void wxGnomePrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle)
1258{
1259#if wxUSE_NEW_DC
1260 wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
1261#else
1262 wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
1263#endif
1264}
1265
1266void wxGnomePrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1267{
1268 width--;
1269 height--;
1270
1271 if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT)
1272 {
1273 SetBrush( m_brush );
1274
1275 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1276 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1277 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1278 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1279 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1280 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1281 gs_libGnomePrint->gnome_print_fill( m_gpc );
1282
1283 CalcBoundingBox( x, y );
1284 CalcBoundingBox( x + width, y + height );
1285 }
1286
1287 if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT)
1288 {
1289 SetPen (m_pen);
1290
1291 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1292 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1293 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1294 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1295 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1296 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1297 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1298
1299 CalcBoundingBox( x, y );
1300 CalcBoundingBox( x + width, y + height );
1301 }
1302}
1303
1304void wxGnomePrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
1305{
1306 width--;
1307 height--;
1308
1309 wxCoord rad = wxRound( radius );
1310
1311 if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT)
1312 {
1313 SetBrush(m_brush);
1314 gs_libGnomePrint->gnome_print_newpath(m_gpc);
1315 gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1316 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1317 XLOG2DEV(x + rad),YLOG2DEV(y),
1318 XLOG2DEV(x),YLOG2DEV(y),
1319 XLOG2DEV(x),YLOG2DEV(y + rad));
1320 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1321 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1322 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1323 XLOG2DEV(x),YLOG2DEV(y + height),
1324 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1325 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1326 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1327 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1328 XLOG2DEV(x + width),YLOG2DEV(y + height),
1329 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1330 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1331 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1332 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1333 XLOG2DEV(x + width),YLOG2DEV(y),
1334 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1335 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1336 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1337 gs_libGnomePrint->gnome_print_fill(m_gpc);
1338
1339 CalcBoundingBox(x,y);
1340 CalcBoundingBox(x+width,y+height);
1341 }
1342
1343 if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT)
1344 {
1345 SetPen(m_pen);
1346 gs_libGnomePrint->gnome_print_newpath(m_gpc);
1347 gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1348 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1349 XLOG2DEV(x + rad),YLOG2DEV(y),
1350 XLOG2DEV(x),YLOG2DEV(y),
1351 XLOG2DEV(x),YLOG2DEV(y + rad));
1352 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
1353 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1354 XLOG2DEV(x),YLOG2DEV(y + height - rad),
1355 XLOG2DEV(x),YLOG2DEV(y + height),
1356 XLOG2DEV(x + rad),YLOG2DEV(y + height));
1357 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
1358 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1359 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
1360 XLOG2DEV(x + width),YLOG2DEV(y + height),
1361 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
1362 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
1363 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1364 XLOG2DEV(x + width),YLOG2DEV(y + rad),
1365 XLOG2DEV(x + width),YLOG2DEV(y),
1366 XLOG2DEV(x + width - rad),YLOG2DEV(y));
1367 gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
1368 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1369 gs_libGnomePrint->gnome_print_stroke(m_gpc);
1370
1371 CalcBoundingBox(x,y);
1372 CalcBoundingBox(x+width,y+height);
1373 }
1374}
1375
1376void wxGnomePrinterDCImpl::makeEllipticalPath(wxCoord x, wxCoord y,
1377 wxCoord width, wxCoord height)
1378{
1379 double r = 4 * (sqrt(2.) - 1) / 3;
1380 double halfW = 0.5 * width,
1381 halfH = 0.5 * height,
1382 halfWR = r * halfW,
1383 halfHR = r * halfH;
1384 wxCoord halfWI = (wxCoord) halfW,
1385 halfHI = (wxCoord) halfH;
1386
1387 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1388
1389 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1390 gs_libGnomePrint->gnome_print_moveto( m_gpc,
1391 XLOG2DEV(x + width),
1392 YLOG2DEV(y + halfHI) );
1393 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1394 XLOG2DEV(x + width),
1395 YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
1396 XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
1397 YLOG2DEV(y + height),
1398 XLOG2DEV(x + halfWI),
1399 YLOG2DEV(y + height) );
1400 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1401 XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)),
1402 YLOG2DEV(y + height),
1403 XLOG2DEV(x),
1404 YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
1405 XLOG2DEV(x), YLOG2DEV(y+halfHI) );
1406 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1407 XLOG2DEV(x),
1408 YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)),
1409 XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)),
1410 YLOG2DEV(y),
1411 XLOG2DEV(x+halfWI), YLOG2DEV(y) );
1412 gs_libGnomePrint->gnome_print_curveto( m_gpc,
1413 XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
1414 YLOG2DEV(y),
1415 XLOG2DEV(x + width),
1416 YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)),
1417 XLOG2DEV(x + width), YLOG2DEV(y + halfHI) );
1418
1419 gs_libGnomePrint->gnome_print_closepath(m_gpc);
1420}
1421
1422void wxGnomePrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1423{
1424 width--;
1425 height--;
1426
1427 if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT)
1428 {
1429 SetBrush( m_brush );
1430 makeEllipticalPath( x, y, width, height );
1431 gs_libGnomePrint->gnome_print_fill( m_gpc );
1432 CalcBoundingBox( x, y );
1433 CalcBoundingBox( x + width, y + height );
1434 }
1435
1436 if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT)
1437 {
1438 SetPen (m_pen);
1439 makeEllipticalPath( x, y, width, height );
1440 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1441 CalcBoundingBox( x, y );
1442 CalcBoundingBox( x + width, y + height );
1443 }
1444}
1445
1446#if wxUSE_SPLINES
1447void wxGnomePrinterDCImpl::DoDrawSpline(const wxPointList *points)
1448{
1449 SetPen (m_pen);
1450
1451 double c, d, x1, y1, x2, y2, x3, y3;
1452 wxPoint *p, *q;
1453
1454 wxPointList::compatibility_iterator node = points->GetFirst();
1455 p = node->GetData();
1456 x1 = p->x;
1457 y1 = p->y;
1458
1459 node = node->GetNext();
1460 p = node->GetData();
1461 c = p->x;
1462 d = p->y;
1463 x3 =
1464 (double)(x1 + c) / 2;
1465 y3 =
1466 (double)(y1 + d) / 2;
1467
1468 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1469 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
1470 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1471
1472 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1473 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1474
1475 node = node->GetNext();
1476 while (node)
1477 {
1478 q = node->GetData();
1479
1480 x1 = x3;
1481 y1 = y3;
1482 x2 = c;
1483 y2 = d;
1484 c = q->x;
1485 d = q->y;
1486 x3 = (double)(x2 + c) / 2;
1487 y3 = (double)(y2 + d) / 2;
1488
1489 gs_libGnomePrint->gnome_print_curveto(m_gpc,
1490 XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
1491 XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
1492 XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1493
1494 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1495 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1496
1497 node = node->GetNext();
1498 }
1499
1500 gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
1501
1502 gs_libGnomePrint->gnome_print_stroke( m_gpc );
1503}
1504#endif // wxUSE_SPLINES
1505
1506bool
1507wxGnomePrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
1508 wxCoord width, wxCoord height,
1509 wxDC *source,
1510 wxCoord xsrc, wxCoord ysrc,
1511 wxRasterOperationMode rop,
1512 bool WXUNUSED(useMask),
1513 wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask))
1514{
1515 wxCHECK_MSG( source, false, wxT("invalid source dc") );
1516
1517 // blit into a bitmap
1518 wxBitmap bitmap( width, height );
1519 wxMemoryDC memDC;
1520 memDC.SelectObject(bitmap);
1521 memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
1522 memDC.SelectObject(wxNullBitmap);
1523
1524 // draw bitmap. scaling and positioning is done there
1525 GetOwner()->DrawBitmap( bitmap, xdest, ydest );
1526
1527 return true;
1528}
1529
1530void wxGnomePrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
1531{
1532 DoDrawBitmap( icon, x, y, true );
1533}
1534
1535void
1536wxGnomePrinterDCImpl::DoDrawBitmap(const wxBitmap& bitmap,
1537 wxCoord x, wxCoord y,
1538 bool WXUNUSED(useMask))
1539{
1540 if (!bitmap.Ok()) return;
1541
1542 if (bitmap.HasPixbuf())
1543 {
1544 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
1545 guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf );
1546 bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf );
1547 int rowstride = gdk_pixbuf_get_rowstride( pixbuf );
1548 int height = gdk_pixbuf_get_height( pixbuf );
1549 int width = gdk_pixbuf_get_width( pixbuf );
1550
1551 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1552 double matrix[6];
1553 matrix[0] = XLOG2DEVREL(width);
1554 matrix[1] = 0;
1555 matrix[2] = 0;
1556 matrix[3] = YLOG2DEVREL(height);
1557 matrix[4] = XLOG2DEV(x);
1558 matrix[5] = YLOG2DEV(y+height);
1559 gs_libGnomePrint->gnome_print_concat( m_gpc, matrix );
1560 gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 );
1561 if (has_alpha)
1562 gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1563 else
1564 gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
1565 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1566 }
1567 else
1568 {
1569 wxImage image = bitmap.ConvertToImage();
1570
1571 if (!image.Ok()) return;
1572
1573 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1574 double matrix[6];
1575 matrix[0] = XLOG2DEVREL(image.GetWidth());
1576 matrix[1] = 0;
1577 matrix[2] = 0;
1578 matrix[3] = YLOG2DEVREL(image.GetHeight());
1579 matrix[4] = XLOG2DEV(x);
1580 matrix[5] = YLOG2DEV(y+image.GetHeight());
1581 gs_libGnomePrint->gnome_print_concat( m_gpc, matrix );
1582 gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 );
1583 gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 );
1584 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1585 }
1586}
1587
1588void wxGnomePrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
1589{
1590 DoDrawRotatedText( text, x, y, 0.0 );
1591}
1592
1593void wxGnomePrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1594{
1595 double xx = XLOG2DEV(x);
1596 double yy = YLOG2DEV(y);
1597
1598 bool underlined = m_font.Ok() && m_font.GetUnderlined();
1599
1600 const wxScopedCharBuffer data(text.utf8_str());
1601
1602 size_t datalen = strlen(data);
1603 pango_layout_set_text( m_layout, data, datalen);
1604
1605 if (underlined)
1606 {
1607 PangoAttrList *attrs = pango_attr_list_new();
1608 PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1609 a->start_index = 0;
1610 a->end_index = datalen;
1611 pango_attr_list_insert(attrs, a);
1612 pango_layout_set_attributes(m_layout, attrs);
1613 pango_attr_list_unref(attrs);
1614 }
1615
1616 if (m_textForegroundColour.Ok())
1617 {
1618 unsigned char red = m_textForegroundColour.Red();
1619 unsigned char blue = m_textForegroundColour.Blue();
1620 unsigned char green = m_textForegroundColour.Green();
1621
1622 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1623 {
1624 double redPS = (double)(red) / 255.0;
1625 double bluePS = (double)(blue) / 255.0;
1626 double greenPS = (double)(green) / 255.0;
1627
1628 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1629
1630 m_currentRed = red;
1631 m_currentBlue = blue;
1632 m_currentGreen = green;
1633 }
1634 }
1635
1636#if 0
1637 if ( m_backgroundMode == wxSOLID )
1638 {
1639 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1640 gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h);
1641 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1642 }
1643#endif
1644
1645 // Draw layout.
1646 gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy);
1647
1648 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1649
1650 gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS );
1651
1652 if (fabs(angle) > 0.00001)
1653 gs_libGnomePrint->gnome_print_rotate( m_gpc, angle );
1654
1655 gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout );
1656
1657 int w,h;
1658 pango_layout_get_pixel_size( m_layout, &w, &h );
1659
1660 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1661
1662 if (underlined)
1663 {
1664 // undo underline attributes setting:
1665 pango_layout_set_attributes(m_layout, NULL);
1666 }
1667
1668 CalcBoundingBox(x, y);
1669 CalcBoundingBox(x + w, y + h);
1670}
1671
1672void wxGnomePrinterDCImpl::Clear()
1673{
1674}
1675
1676void wxGnomePrinterDCImpl::SetFont( const wxFont& font )
1677{
1678 m_font = font;
1679
1680 if (m_font.Ok())
1681 {
1682 if (m_fontdesc)
1683 pango_font_description_free( m_fontdesc );
1684
1685 m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
1686
1687 float size = pango_font_description_get_size( m_fontdesc );
1688 size = size * GetFontPointSizeAdjustment(72.0);
1689 pango_font_description_set_size( m_fontdesc, (gint)size );
1690
1691 pango_layout_set_font_description( m_layout, m_fontdesc );
1692 }
1693}
1694
1695void wxGnomePrinterDCImpl::SetPen( const wxPen& pen )
1696{
1697 if (!pen.Ok()) return;
1698
1699 m_pen = pen;
1700
1701 double width;
1702
1703 if (m_pen.GetWidth() <= 0)
1704 width = 0.1;
1705 else
1706 width = (double) m_pen.GetWidth();
1707
1708 gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX );
1709
1710 static const double dotted[] = {2.0, 5.0};
1711 static const double short_dashed[] = {4.0, 4.0};
1712 static const double wxCoord_dashed[] = {4.0, 8.0};
1713 static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
1714
1715 switch (m_pen.GetStyle())
1716 {
1717 case wxPENSTYLE_DOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
1718 case wxPENSTYLE_SHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
1719 case wxPENSTYLE_LONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
1720 case wxPENSTYLE_DOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break;
1721 case wxPENSTYLE_USER_DASH:
1722 {
1723 // It may be noted that libgnomeprint between at least
1724 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1725 // and then leak the memory since it doesn't set the
1726 // internal flag "privatedash" to 0.
1727 wxDash *wx_dashes;
1728 int num = m_pen.GetDashes (&wx_dashes);
1729 gdouble *g_dashes = g_new( gdouble, num );
1730 int i;
1731 for (i = 0; i < num; ++i)
1732 g_dashes[i] = (gdouble) wx_dashes[i];
1733 gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0);
1734 g_free( g_dashes );
1735 }
1736 break;
1737 case wxPENSTYLE_SOLID:
1738 case wxPENSTYLE_TRANSPARENT:
1739 default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break;
1740 }
1741
1742
1743 unsigned char red = m_pen.GetColour().Red();
1744 unsigned char blue = m_pen.GetColour().Blue();
1745 unsigned char green = m_pen.GetColour().Green();
1746
1747 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1748 {
1749 double redPS = (double)(red) / 255.0;
1750 double bluePS = (double)(blue) / 255.0;
1751 double greenPS = (double)(green) / 255.0;
1752
1753 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1754
1755 m_currentRed = red;
1756 m_currentBlue = blue;
1757 m_currentGreen = green;
1758 }
1759}
1760
1761void wxGnomePrinterDCImpl::SetBrush( const wxBrush& brush )
1762{
1763 if (!brush.Ok()) return;
1764
1765 m_brush = brush;
1766
1767 // Brush colour
1768 unsigned char red = m_brush.GetColour().Red();
1769 unsigned char blue = m_brush.GetColour().Blue();
1770 unsigned char green = m_brush.GetColour().Green();
1771
1772 if (!m_colour)
1773 {
1774 // Anything not white is black
1775 if (! (red == (unsigned char) 255 &&
1776 blue == (unsigned char) 255 &&
1777 green == (unsigned char) 255) )
1778 {
1779 red = (unsigned char) 0;
1780 green = (unsigned char) 0;
1781 blue = (unsigned char) 0;
1782 }
1783 // setgray here ?
1784 }
1785
1786 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1787 {
1788 double redPS = (double)(red) / 255.0;
1789 double bluePS = (double)(blue) / 255.0;
1790 double greenPS = (double)(green) / 255.0;
1791
1792 gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );
1793
1794 m_currentRed = red;
1795 m_currentBlue = blue;
1796 m_currentGreen = green;
1797 }
1798}
1799
1800void wxGnomePrinterDCImpl::SetLogicalFunction(wxRasterOperationMode WXUNUSED(function))
1801{
1802}
1803
1804void wxGnomePrinterDCImpl::SetBackground(const wxBrush& WXUNUSED(brush))
1805{
1806}
1807
1808void wxGnomePrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1809{
1810#if wxUSE_NEW_DC
1811 m_clipping = TRUE; // TODO move somewhere else
1812 m_clipX1 = x;
1813 m_clipY1 = y;
1814 m_clipX2 = x + width;
1815 m_clipY2 = y + height;
1816#else
1817 wxDC::DoSetClippingRegion( x, y, width, height );
1818#endif
1819
1820 gs_libGnomePrint->gnome_print_gsave( m_gpc );
1821
1822 gs_libGnomePrint->gnome_print_newpath( m_gpc );
1823 gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
1824 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
1825 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
1826 gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
1827 gs_libGnomePrint->gnome_print_closepath( m_gpc );
1828 gs_libGnomePrint->gnome_print_clip( m_gpc );
1829}
1830
1831void wxGnomePrinterDCImpl::DestroyClippingRegion()
1832{
1833#if wxUSE_NEW_DC
1834 wxDCImpl::DestroyClippingRegion();
1835#else
1836 wxDC::DestroyClippingRegion();
1837#endif
1838
1839 gs_libGnomePrint->gnome_print_grestore( m_gpc );
1840
1841#if 0
1842 // not needed, we set the values in each
1843 // drawing method anyways
1844 SetPen( m_pen );
1845 SetBrush( m_brush );
1846 SetFont( m_font );
1847#endif
1848}
1849
1850bool wxGnomePrinterDCImpl::StartDoc(const wxString& WXUNUSED(message))
1851{
1852 return true;
1853}
1854
1855void wxGnomePrinterDCImpl::EndDoc()
1856{
1857 gs_libGnomePrint->gnome_print_end_doc( m_gpc );
1858}
1859
1860void wxGnomePrinterDCImpl::StartPage()
1861{
1862 gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" );
1863}
1864
1865void wxGnomePrinterDCImpl::EndPage()
1866{
1867 gs_libGnomePrint->gnome_print_showpage( m_gpc );
1868}
1869
1870wxCoord wxGnomePrinterDCImpl::GetCharHeight() const
1871{
1872 pango_layout_set_text( m_layout, "H", 1 );
1873
1874 int w,h;
1875 pango_layout_get_pixel_size( m_layout, &w, &h );
1876
1877 return h;
1878}
1879
1880wxCoord wxGnomePrinterDCImpl::GetCharWidth() const
1881{
1882 pango_layout_set_text( m_layout, "H", 1 );
1883
1884 int w,h;
1885 pango_layout_get_pixel_size( m_layout, &w, &h );
1886
1887 return w;
1888}
1889
1890void wxGnomePrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
1891 wxCoord *descent,
1892 wxCoord *externalLeading,
1893 const wxFont *theFont ) const
1894{
1895 if ( width )
1896 *width = 0;
1897 if ( height )
1898 *height = 0;
1899 if ( descent )
1900 *descent = 0;
1901 if ( externalLeading )
1902 *externalLeading = 0;
1903
1904 if (string.empty())
1905 {
1906 return;
1907 }
1908
1909 // Set layout's text
1910
1911 const wxScopedCharBuffer dataUTF8(string.utf8_str());
1912
1913 gint oldSize = 0;
1914 if ( theFont )
1915 {
1916 // scale the font and apply it
1917 PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
1918 oldSize = pango_font_description_get_size(desc);
1919 float size = oldSize * GetFontPointSizeAdjustment(72.0);
1920 pango_font_description_set_size(desc, (gint)size);
1921
1922 pango_layout_set_font_description(m_layout, desc);
1923 }
1924
1925 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
1926
1927 int h;
1928 pango_layout_get_pixel_size( m_layout, width, &h );
1929 if ( height )
1930 *height = h;
1931
1932 if (descent)
1933 {
1934 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1935 int baseline = pango_layout_iter_get_baseline(iter);
1936 pango_layout_iter_free(iter);
1937 *descent = h - PANGO_PIXELS(baseline);
1938 }
1939
1940 if ( theFont )
1941 {
1942 // restore font and reset font's size back
1943 pango_layout_set_font_description(m_layout, m_fontdesc);
1944
1945 PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
1946 pango_font_description_set_size(desc, oldSize);
1947 }
1948}
1949
1950void wxGnomePrinterDCImpl::DoGetSize(int* width, int* height) const
1951{
1952 wxGnomePrintNativeData *native =
1953 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1954
1955 // Query page size. This seems to omit the margins
1956 double pw,ph;
1957 gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1958
1959 if (width)
1960 *width = wxRound( pw * PS2DEV );
1961
1962 if (height)
1963 *height = wxRound( ph * PS2DEV );
1964}
1965
1966void wxGnomePrinterDCImpl::DoGetSizeMM(int *width, int *height) const
1967{
1968 wxGnomePrintNativeData *native =
1969 (wxGnomePrintNativeData*) m_printData.GetNativeData();
1970
1971 // This code assumes values in Pts.
1972
1973 double pw,ph;
1974 gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
1975
1976 // Convert to mm.
1977
1978 const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" );
1979 const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" );
1980 gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit );
1981 gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit );
1982
1983 if (width)
1984 *width = (int) (pw + 0.5);
1985 if (height)
1986 *height = (int) (ph + 0.5);
1987}
1988
1989wxSize wxGnomePrinterDCImpl::GetPPI() const
1990{
1991 return wxSize(DPI,DPI);
1992}
1993
1994void wxGnomePrinterDCImpl::SetPrintData(const wxPrintData& data)
1995{
1996 m_printData = data;
1997
1998 int height;
1999 if (m_printData.GetOrientation() == wxPORTRAIT)
2000 GetOwner()->GetSize( NULL, &height );
2001 else
2002 GetOwner()->GetSize( &height, NULL );
2003 m_deviceLocalOriginY = height;
2004}
2005
2006// overridden for wxPrinterDC Impl
2007
2008int wxGnomePrinterDCImpl::GetResolution() const
2009{
2010 return DPI;
2011}
2012
2013wxRect wxGnomePrinterDCImpl::GetPaperRect() const
2014{
2015 // GNOME print doesn't support printer margins
2016 int w = 0;
2017 int h = 0;
2018 DoGetSize( &w, &h );
2019 return wxRect( 0, 0, w, h );
2020}
2021
2022// ----------------------------------------------------------------------------
2023// wxGnomePrintModule
2024// ----------------------------------------------------------------------------
2025
2026bool wxGnomePrintModule::OnInit()
2027{
2028 gs_libGnomePrint = new wxGnomePrintLibrary;
2029 if (gs_libGnomePrint->IsOk())
2030 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory );
2031 return true;
2032}
2033
2034void wxGnomePrintModule::OnExit()
2035{
2036 delete gs_libGnomePrint;
2037 gs_libGnomePrint = NULL;
2038}
2039
2040IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
2041
2042// ----------------------------------------------------------------------------
2043// Print preview
2044// ----------------------------------------------------------------------------
2045
2046IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase)
2047
2048void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout),
2049 wxPrintout * WXUNUSED(printoutForPrinting))
2050{
2051 DetermineScaling();
2052}
2053
2054wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
2055 wxPrintout *printoutForPrinting,
2056 wxPrintDialogData *data)
2057 : wxPrintPreviewBase(printout, printoutForPrinting, data)
2058{
2059 Init(printout, printoutForPrinting);
2060}
2061
2062wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
2063 wxPrintout *printoutForPrinting,
2064 wxPrintData *data)
2065 : wxPrintPreviewBase(printout, printoutForPrinting, data)
2066{
2067 Init(printout, printoutForPrinting);
2068}
2069
2070wxGnomePrintPreview::~wxGnomePrintPreview()
2071{
2072}
2073
2074bool wxGnomePrintPreview::Print(bool interactive)
2075{
2076 if (!m_printPrintout)
2077 return false;
2078
2079 wxPrinter printer(& m_printDialogData);
2080 return printer.Print(m_previewFrame, m_printPrintout, interactive);
2081}
2082
2083void wxGnomePrintPreview::DetermineScaling()
2084{
2085 wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId();
2086 if (paperType == wxPAPER_NONE)
2087 paperType = wxPAPER_NONE;
2088
2089 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
2090 if (!paper)
2091 paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
2092
2093 if (paper)
2094 {
2095 m_previewPrintout->SetPPIScreen(wxGetDisplayPPI());
2096
2097 int resolution = DPI;
2098 m_previewPrintout->SetPPIPrinter( resolution, resolution );
2099
2100 wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
2101
2102 // TODO: get better resolution information from wxGnomePrinterDCImpl, if possible.
2103
2104 sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * resolution / 72.0);
2105 sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * resolution / 72.0);
2106 wxSize sizeTenthsMM(paper->GetSize());
2107 wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
2108
2109 // If in landscape mode, we need to swap the width and height.
2110 if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE )
2111 {
2112 m_pageWidth = sizeDevUnits.y;
2113 m_pageHeight = sizeDevUnits.x;
2114 m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x);
2115 }
2116 else
2117 {
2118 m_pageWidth = sizeDevUnits.x;
2119 m_pageHeight = sizeDevUnits.y;
2120 m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y);
2121 }
2122 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
2123 m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight));
2124
2125 // At 100%, the page should look about page-size on the screen.
2126 m_previewScaleX = (double)0.8 * 72.0 / (double)resolution;
2127 m_previewScaleY = m_previewScaleX;
2128 }
2129}
2130
2131#endif
2132 // wxUSE_LIBGNOMEPRINT