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