1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_LIBGNOMEPRINT
20 #include "wx/gtk/gnome/gprint.h"
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
36 #include <libgnomeprint/gnome-print.h>
37 #include <libgnomeprint/gnome-print-pango.h>
38 #include <libgnomeprint/gnome-print-config.h>
39 #include <libgnomeprintui/gnome-print-dialog.h>
40 #include <libgnomeprintui/gnome-print-job-preview.h>
41 #include <libgnomeprintui/gnome-print-paper-selector.h>
44 wxFORCE_LINK_THIS_MODULE(gnome_print
)
46 //----------------------------------------------------------------------------
47 // wxGnomePrintLibrary
48 //----------------------------------------------------------------------------
50 class wxGnomePrintLibrary
53 wxGnomePrintLibrary();
54 ~wxGnomePrintLibrary();
58 bool InitializeMethods();
60 wxDynamicLibrary m_libGnomePrint
;
61 wxDynamicLibrary m_libGnomePrintUI
;
63 // only true if we successfully loaded both libraries
65 // don't rename this field, it's used by wxDL_XXX macros internally
69 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
70 (GnomePrintContext
*pc
), (pc
), 0 )
71 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
72 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
73 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
74 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
76 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
78 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
80 (GnomePrintContext
*pc
), (pc
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
82 (GnomePrintContext
*pc
), (pc
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
84 (GnomePrintContext
*pc
), (pc
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
86 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
88 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
90 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
93 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
95 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
98 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
100 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
102 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
104 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
107 (GnomePrintContext
*pc
), (pc
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
109 (GnomePrintContext
*pc
), (pc
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
112 (GnomePrintContext
*pc
), (pc
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
117 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
119 (GnomePrintContext
*pc
), (pc
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
123 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
124 (GnomePrintContext
*gpc
), (gpc
), NULL
)
125 wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout
,
126 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
) )
128 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
129 (GnomePrintConfig
*config
), (config
), NULL
)
130 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
131 (GnomePrintJob
*job
), (job
), NULL
)
132 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
133 (GnomePrintJob
*job
), (job
), 0 )
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
137 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
139 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
140 (const guchar
*abbreviation
), (abbreviation
), NULL
)
141 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
142 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
144 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
146 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
147 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
149 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
152 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
153 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
154 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
155 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
157 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
158 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
159 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
160 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
162 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
163 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
164 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page
,
165 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
166 const guchar
*currentlabel
, const guchar
*rangelabel
),
167 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
) )
168 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies
,
169 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
) )
170 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies
,
171 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
) )
172 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
173 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
174 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
175 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
177 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
178 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
180 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
181 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
183 DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
)
186 wxGnomePrintLibrary::wxGnomePrintLibrary()
190 m_libGnomePrint
.Load("libgnomeprint-2-2.so.0");
191 m_ok
= m_libGnomePrint
.IsLoaded();
195 m_libGnomePrintUI
.Load("libgnomeprintui-2-2.so.0");
196 m_ok
= m_libGnomePrintUI
.IsLoaded();
199 m_libGnomePrint
.Unload();
203 m_ok
= InitializeMethods();
206 wxGnomePrintLibrary::~wxGnomePrintLibrary()
210 bool wxGnomePrintLibrary::IsOk()
215 bool wxGnomePrintLibrary::InitializeMethods()
217 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_newpath
);
218 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_moveto
);
219 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_lineto
);
220 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_curveto
);
221 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_arcto
);
222 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_closepath
);
223 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_stroke
);
224 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_fill
);
225 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setrgbcolor
);
226 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setlinewidth
);
227 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setdash
);
229 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbimage
);
230 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbaimage
);
232 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_concat
);
233 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_scale
);
234 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rotate
);
235 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_translate
);
237 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_gsave
);
238 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_grestore
);
240 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_clip
);
241 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_eoclip
);
243 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_beginpage
);
244 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_showpage
);
245 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_end_doc
);
247 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_create_layout
);
248 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_layout
);
250 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_new
);
251 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_context
);
252 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_close
);
253 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_print
);
254 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_page_size
);
256 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_unit_get_by_abbreviation
);
257 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_convert_distance
);
259 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_default
);
260 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set
);
261 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_boolean
);
262 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_double
);
263 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_int
);
264 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_length
);
266 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get
);
267 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_length
);
269 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_new
);
270 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_construct_range_page
);
271 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_copies
);
272 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_set_copies
);
273 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range
);
274 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range_page
);
276 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_paper_selector_new_with_flags
);
278 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_job_preview_new
);
283 static wxGnomePrintLibrary
* gs_libGnomePrint
= NULL
;
285 //----------------------------------------------------------------------------
286 // wxGnomePrintNativeData
287 //----------------------------------------------------------------------------
289 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
291 wxGnomePrintNativeData::wxGnomePrintNativeData()
293 m_config
= gs_libGnomePrint
->gnome_print_config_default();
294 m_job
= gs_libGnomePrint
->gnome_print_job_new( m_config
);
297 wxGnomePrintNativeData::~wxGnomePrintNativeData()
299 g_object_unref (m_config
);
302 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
304 guchar
*res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
305 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
);
306 if (g_ascii_strcasecmp((const gchar
*)res
,"R90") == 0)
307 data
.SetOrientation( wxLANDSCAPE
);
309 data
.SetOrientation( wxPORTRAIT
);
315 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
317 if (data
.GetOrientation() == wxLANDSCAPE
)
319 gs_libGnomePrint
->gnome_print_config_set( m_config
,
320 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
321 (guchar
*)(char*)"R90" );
325 gs_libGnomePrint
->gnome_print_config_set( m_config
,
326 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
327 (guchar
*)(char*)"R0" );
330 if (data
.GetCollate())
332 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
333 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
338 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
339 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
343 switch (data
.GetPaperId())
345 case wxPAPER_A3
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
346 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
347 (guchar
*)(char*)"A3" );
349 case wxPAPER_A5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
350 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
351 (guchar
*)(char*)"A5" );
353 case wxPAPER_B4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
354 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
355 (guchar
*)(char*)"B4" );
357 case wxPAPER_B5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
358 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
359 (guchar
*)(char*)"B5" );
361 case wxPAPER_LETTER
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
362 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
363 (guchar
*)(char*)"USLetter" );
365 case wxPAPER_LEGAL
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
366 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
367 (guchar
*)(char*)"USLegal" );
369 case wxPAPER_EXECUTIVE
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
370 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
371 (guchar
*)(char*)"Executive" );
373 case wxPAPER_ENV_C5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
374 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
375 (guchar
*)(char*)"C5" );
377 case wxPAPER_ENV_C6
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
378 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
379 (guchar
*)(char*)"C6" );
381 case wxPAPER_NONE
: break;
384 case wxPAPER_A4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
385 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
386 (guchar
*)(char*)"A4" );
393 //----------------------------------------------------------------------------
394 // wxGnomePrintFactory
395 //----------------------------------------------------------------------------
397 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
399 return new wxGnomePrinter( data
);
402 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
403 wxPrintout
*printout
,
404 wxPrintDialogData
*data
)
406 return new wxGnomePrintPreview( preview
, printout
, data
);
409 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
410 wxPrintout
*printout
,
413 return new wxGnomePrintPreview( preview
, printout
, data
);
416 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
417 wxPrintDialogData
*data
)
419 return new wxGnomePrintDialog( parent
, data
);
422 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
425 return new wxGnomePrintDialog( parent
, data
);
428 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
429 wxPageSetupDialogData
* data
)
431 // The native page setup dialog is broken. It
432 // miscalculates newly entered values for the
433 // margins if you have not chose "points" but
434 // e.g. centimerters.
435 // This has been fixed in GNOME CVS (maybe
436 // fixed in libgnomeprintui 2.8.1)
438 return new wxGnomePageSetupDialog( parent
, data
);
441 bool wxGnomePrintFactory::HasPrintSetupDialog()
446 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
451 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
453 return new wxGnomePrintDC(data
);
456 bool wxGnomePrintFactory::HasOwnPrintToFile()
461 bool wxGnomePrintFactory::HasPrinterLine()
466 wxString
wxGnomePrintFactory::CreatePrinterLine()
469 return wxEmptyString
;
472 bool wxGnomePrintFactory::HasStatusLine()
478 wxString
wxGnomePrintFactory::CreateStatusLine()
481 return wxEmptyString
;
484 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
486 return new wxGnomePrintNativeData
;
489 //----------------------------------------------------------------------------
490 // wxGnomePrintSetupDialog
491 //----------------------------------------------------------------------------
493 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
495 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
496 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
497 wxPoint(0, 0), wxSize(600, 600),
498 wxDEFAULT_DIALOG_STYLE
|
502 m_printDialogData
= *data
;
507 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
508 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
509 wxPoint(0, 0), wxSize(600, 600),
510 wxDEFAULT_DIALOG_STYLE
|
514 m_printDialogData
= *data
;
519 void wxGnomePrintDialog::Init()
521 wxPrintData data
= m_printDialogData
.GetPrintData();
523 data
.ConvertToNative();
525 wxGnomePrintNativeData
*native
=
526 (wxGnomePrintNativeData
*) data
.GetNativeData();
528 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
530 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
533 if (m_printDialogData
.GetEnableSelection())
534 flag
|= GNOME_PRINT_RANGE_SELECTION
;
535 if (m_printDialogData
.GetEnablePageNumbers())
536 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
538 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
540 m_printDialogData
.GetMinPage(),
541 m_printDialogData
.GetMaxPage(),
546 wxGnomePrintDialog::~wxGnomePrintDialog()
551 int wxGnomePrintDialog::ShowModal()
553 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
555 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
557 gtk_widget_destroy(m_widget
);
563 m_printDialogData
.GetPrintData().ConvertFromNative();
566 gboolean collate
= false;
567 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
568 m_printDialogData
.SetNoCopies( copies
);
569 m_printDialogData
.SetCollate( collate
);
571 switch (gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
573 case GNOME_PRINT_RANGE_SELECTION
:
574 m_printDialogData
.SetSelection( true );
576 case GNOME_PRINT_RANGE_ALL
:
577 m_printDialogData
.SetAllPages( true );
578 m_printDialogData
.SetFromPage( 0 );
579 m_printDialogData
.SetToPage( 9999 );
581 case GNOME_PRINT_RANGE_RANGE
:
584 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
585 m_printDialogData
.SetFromPage( start
);
586 m_printDialogData
.SetToPage( end
);
590 gtk_widget_destroy(m_widget
);
593 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
599 wxDC
*wxGnomePrintDialog::GetPrintDC()
605 bool wxGnomePrintDialog::Validate()
610 bool wxGnomePrintDialog::TransferDataToWindow()
615 bool wxGnomePrintDialog::TransferDataFromWindow()
620 //----------------------------------------------------------------------------
621 // wxGnomePageSetupDialog
622 //----------------------------------------------------------------------------
624 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
626 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
627 wxPageSetupDialogData
* data
)
630 m_pageDialogData
= *data
;
632 m_pageDialogData
.GetPrintData().ConvertToNative();
634 wxGnomePrintNativeData
*native
=
635 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
637 // This *was* required as the page setup dialog
638 // calculates wrong values otherwise.
640 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
641 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
642 (const guchar
*) "Pts" );
645 GnomePrintConfig
*config
= native
->GetPrintConfig();
647 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
649 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
650 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
651 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
652 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
654 gs_libGnomePrint
->gnome_print_config_set_length (config
,
655 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
656 gs_libGnomePrint
->gnome_print_config_set_length (config
,
657 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
658 gs_libGnomePrint
->gnome_print_config_set_length (config
,
659 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
660 gs_libGnomePrint
->gnome_print_config_set_length (config
,
661 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
663 m_widget
= gtk_dialog_new();
665 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
667 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
668 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
669 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
670 gtk_widget_show (main
);
672 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
674 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
676 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
677 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
678 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
681 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
685 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
689 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
691 return m_pageDialogData
;
694 int wxGnomePageSetupDialog::ShowModal()
696 wxGnomePrintNativeData
*native
=
697 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
699 GnomePrintConfig
*config
= native
->GetPrintConfig();
702 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
704 if (ret
== GTK_RESPONSE_OK
)
706 // Transfer data back to m_pageDialogData
707 m_pageDialogData
.GetPrintData().ConvertFromNative();
709 // I don't know how querying the last parameter works
710 double ml
,mr
,mt
,mb
,pw
,ph
;
711 gs_libGnomePrint
->gnome_print_config_get_length (config
,
712 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
713 gs_libGnomePrint
->gnome_print_config_get_length (config
,
714 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
715 gs_libGnomePrint
->gnome_print_config_get_length (config
,
716 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
717 gs_libGnomePrint
->gnome_print_config_get_length (config
,
718 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
719 gs_libGnomePrint
->gnome_print_config_get_length (config
,
720 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
721 gs_libGnomePrint
->gnome_print_config_get_length (config
,
722 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
724 // This code converts correctly from what the user chose
725 // as the unit although I query Pts here
726 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
727 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
728 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
729 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
730 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
731 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
732 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
733 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
735 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
736 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
738 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
747 gtk_widget_destroy( m_widget
);
753 bool wxGnomePageSetupDialog::Validate()
758 bool wxGnomePageSetupDialog::TransferDataToWindow()
763 bool wxGnomePageSetupDialog::TransferDataFromWindow()
768 //----------------------------------------------------------------------------
770 //----------------------------------------------------------------------------
772 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
774 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
775 wxPrinterBase( data
)
777 m_native_preview
= false;
780 wxGnomePrinter::~wxGnomePrinter()
784 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
788 sm_lastError
= wxPRINTER_ERROR
;
792 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
794 wxGnomePrintNativeData
*native
=
795 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
797 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
799 // The GnomePrintJob is temporarily stored in the
800 // native print data as the native print dialog
801 // needs to access it.
802 native
->SetPrintJob( job
);
805 printout
->SetIsPreview(false);
807 if (m_printDialogData
.GetMinPage() < 1)
808 m_printDialogData
.SetMinPage(1);
809 if (m_printDialogData
.GetMaxPage() < 1)
810 m_printDialogData
.SetMaxPage(9999);
814 dc
= PrintDialog( parent
);
816 dc
= new wxGnomePrintDC( printdata
);
818 if (m_native_preview
)
819 printout
->SetIsPreview(true);
823 gs_libGnomePrint
->gnome_print_job_close( job
);
824 g_object_unref (job
);
825 if (sm_lastError
!= wxPRINTER_CANCELLED
)
826 sm_lastError
= wxPRINTER_ERROR
;
830 wxSize ScreenPixels
= wxGetDisplaySize();
831 wxSize ScreenMM
= wxGetDisplaySizeMM();
833 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
834 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
835 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
836 wxGnomePrintDC::GetResolution() );
842 printout
->SetPageSizePixels((int)w
, (int)h
);
843 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
845 dc
->GetSizeMM(&mw
, &mh
);
846 printout
->SetPageSizeMM((int)mw
, (int)mh
);
847 printout
->OnPreparePrinting();
849 // Get some parameters from the printout, if defined
850 int fromPage
, toPage
;
851 int minPage
, maxPage
;
852 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
856 gs_libGnomePrint
->gnome_print_job_close( job
);
857 g_object_unref (job
);
858 sm_lastError
= wxPRINTER_ERROR
;
862 printout
->OnBeginPrinting();
864 int minPageNum
= minPage
, maxPageNum
= maxPage
;
866 if ( !m_printDialogData
.GetAllPages() )
868 minPageNum
= m_printDialogData
.GetFromPage();
869 maxPageNum
= m_printDialogData
.GetToPage();
875 copyCount
<= m_printDialogData
.GetNoCopies();
878 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
880 wxLogError(_("Could not start printing."));
881 sm_lastError
= wxPRINTER_ERROR
;
886 for ( pn
= minPageNum
;
887 pn
<= maxPageNum
&& printout
->HasPage(pn
);
891 printout
->OnPrintPage(pn
);
895 printout
->OnEndDocument();
896 printout
->OnEndPrinting();
899 gs_libGnomePrint
->gnome_print_job_close( job
);
900 if (m_native_preview
)
902 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
903 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
906 (const guchar
*)title
.data()
908 gtk_widget_show(preview
);
912 gs_libGnomePrint
->gnome_print_job_print( job
);
915 g_object_unref (job
);
918 return (sm_lastError
== wxPRINTER_NO_ERROR
);
921 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
923 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
924 int ret
= dialog
.ShowModal();
925 if (ret
== wxID_CANCEL
)
927 sm_lastError
= wxPRINTER_CANCELLED
;
931 m_native_preview
= ret
== wxID_PREVIEW
;
933 m_printDialogData
= dialog
.GetPrintDialogData();
934 return new wxGnomePrintDC( m_printDialogData
.GetPrintData() );
937 bool wxGnomePrinter::Setup( wxWindow
*parent
)
942 //-----------------------------------------------------------------------------
944 //-----------------------------------------------------------------------------
947 static const double RAD2DEG
= 180.0 / M_PI
;
949 // we don't want to use only 72 dpi from GNOME print
950 static const int DPI
= 600;
951 static const double PS2DEV
= 600.0 / 72.0;
952 static const double DEV2PS
= 72.0 / 600.0;
954 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
955 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
956 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
957 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
959 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
961 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
965 wxGnomePrintNativeData
*native
=
966 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
968 m_job
= native
->GetPrintJob();
969 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
971 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
972 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
979 // Query page size. This seems to omit the margins
981 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
983 m_pageHeight
= ph
* PS2DEV
;
986 wxGnomePrintDC::~wxGnomePrintDC()
990 bool wxGnomePrintDC::IsOk() const
995 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
1000 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
1005 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1007 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1011 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1012 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1013 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1015 CalcBoundingBox( x1
, y1
);
1016 CalcBoundingBox( x2
, y2
);
1019 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1023 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1025 double dx
= x1
- xc
;
1026 double dy
= y1
- yc
;
1027 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1028 double alpha1
, alpha2
;
1029 if (x1
== x2
&& y1
== y2
)
1037 alpha1
= alpha2
= 0.0;
1041 alpha1
= (x1
- xc
== 0) ?
1042 (y1
- yc
< 0) ? 90.0 : -90.0 :
1043 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1044 alpha2
= (x2
- xc
== 0) ?
1045 (y2
- yc
< 0) ? 90.0 : -90.0 :
1046 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1048 while (alpha1
<= 0) alpha1
+= 360;
1049 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1050 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1051 while (alpha2
> 360) alpha2
-= 360;
1054 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1056 SetBrush( m_brush
);
1057 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1058 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1060 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1063 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1066 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1067 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1068 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1069 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1071 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1074 CalcBoundingBox (x1
, y1
);
1075 CalcBoundingBox (x2
, y2
);
1076 CalcBoundingBox (xc
, yc
);
1079 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1084 double xx
= XLOG2DEV(x
);
1085 double yy
= YLOG2DEV(y
);
1087 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1089 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1090 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1091 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1096 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1098 SetBrush( m_brush
);
1100 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1101 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1102 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1103 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1105 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1108 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1112 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1113 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1115 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1118 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1120 CalcBoundingBox( x
, y
);
1121 CalcBoundingBox( x
+w
, y
+h
);
1124 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1128 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1130 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1137 for ( i
=0; i
<n
; i
++ )
1138 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1140 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1142 for (i
= 1; i
< n
; i
++)
1143 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1145 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1148 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1152 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1154 SetBrush( m_brush
);
1156 int x
= points
[0].x
+ xoffset
;
1157 int y
= points
[0].y
+ yoffset
;
1158 CalcBoundingBox( x
, y
);
1159 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1160 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1162 for (i
= 1; i
< n
; i
++)
1164 int x
= points
[i
].x
+ xoffset
;
1165 int y
= points
[i
].y
+ yoffset
;
1166 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1167 CalcBoundingBox( x
, y
);
1169 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1170 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1173 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1177 int x
= points
[0].x
+ xoffset
;
1178 int y
= points
[0].y
+ yoffset
;
1179 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1180 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1182 for (i
= 1; i
< n
; i
++)
1184 int x
= points
[i
].x
+ xoffset
;
1185 int y
= points
[i
].y
+ yoffset
;
1186 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1187 CalcBoundingBox( x
, y
);
1189 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1190 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1194 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1196 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1199 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1201 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1203 SetBrush( m_brush
);
1205 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1206 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1207 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1208 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1209 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1210 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1211 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1213 CalcBoundingBox( x
, y
);
1214 CalcBoundingBox( x
+ width
, y
+ height
);
1217 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1221 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1222 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1223 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1224 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1225 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1226 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1227 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1229 CalcBoundingBox( x
, y
);
1230 CalcBoundingBox( x
+ width
, y
+ height
);
1234 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1236 wxCoord rad
= (wxCoord
) radius
;
1238 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1241 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1242 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1243 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1244 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1245 XLOG2DEV(x
),YLOG2DEV(y
),
1246 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1247 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1248 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1249 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1250 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1251 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1252 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1253 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1254 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1255 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1256 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1257 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1258 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1259 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1260 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1261 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1262 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1263 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1264 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1266 CalcBoundingBox(x
,y
);
1267 CalcBoundingBox(x
+width
,y
+height
);
1270 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1273 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1274 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1275 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1276 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1277 XLOG2DEV(x
),YLOG2DEV(y
),
1278 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1279 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1280 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1281 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1282 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1283 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1284 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1285 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1286 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1287 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1288 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1289 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1290 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1291 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1292 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1293 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1294 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1295 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1296 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1298 CalcBoundingBox(x
,y
);
1299 CalcBoundingBox(x
+width
,y
+height
);
1303 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1304 wxCoord width
, wxCoord height
)
1306 double r
= 4 * (sqrt(2.) - 1) / 3;
1307 double halfW
= 0.5 * width
,
1308 halfH
= 0.5 * height
,
1311 wxCoord halfWI
= (wxCoord
) halfW
,
1312 halfHI
= (wxCoord
) halfH
;
1314 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1316 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1317 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1318 XLOG2DEV(x
+ width
),
1319 YLOG2DEV(y
+ halfHI
) );
1320 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1321 XLOG2DEV(x
+ width
),
1322 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1323 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1324 YLOG2DEV(y
+ height
),
1325 XLOG2DEV(x
+ halfWI
),
1326 YLOG2DEV(y
+ height
) );
1327 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1328 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1329 YLOG2DEV(y
+ height
),
1331 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1332 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1333 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1335 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1336 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1338 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1339 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1340 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1342 XLOG2DEV(x
+ width
),
1343 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1344 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1346 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1349 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1351 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1353 SetBrush( m_brush
);
1354 makeEllipticalPath( x
, y
, width
, height
);
1355 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1356 CalcBoundingBox( x
, y
);
1357 CalcBoundingBox( x
+ width
, y
+ height
);
1360 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1363 makeEllipticalPath( x
, y
, width
, height
);
1364 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1365 CalcBoundingBox( x
, y
);
1366 CalcBoundingBox( x
+ width
, y
+ height
);
1371 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1375 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1378 wxList::compatibility_iterator node
= points
->GetFirst();
1379 p
= (wxPoint
*)node
->GetData();
1383 node
= node
->GetNext();
1384 p
= (wxPoint
*)node
->GetData();
1388 (double)(x1
+ c
) / 2;
1390 (double)(y1
+ d
) / 2;
1392 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1393 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1394 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1396 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1397 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1399 node
= node
->GetNext();
1402 q
= (wxPoint
*)node
->GetData();
1410 x3
= (double)(x2
+ c
) / 2;
1411 y3
= (double)(y2
+ d
) / 2;
1413 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1414 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1415 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1416 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1418 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1419 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1421 node
= node
->GetNext();
1424 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1426 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1428 #endif // wxUSE_SPLINES
1430 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1431 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1432 wxCoord xsrcMask
, wxCoord ysrcMask
)
1434 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1436 // blit into a bitmap
1437 wxBitmap
bitmap( width
, height
);
1439 memDC
.SelectObject(bitmap
);
1440 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1441 memDC
.SelectObject(wxNullBitmap
);
1443 // draw bitmap. scaling and positioning is done there
1444 DrawBitmap( bitmap
, xdest
, ydest
);
1449 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1451 DoDrawBitmap( icon
, x
, y
, true );
1454 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1456 if (!bitmap
.Ok()) return;
1458 if (bitmap
.HasPixbuf())
1460 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1461 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1462 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1463 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1464 int height
= gdk_pixbuf_get_height( pixbuf
);
1465 int width
= gdk_pixbuf_get_width( pixbuf
);
1467 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1469 matrix
[0] = XLOG2DEVREL(width
);
1472 matrix
[3] = YLOG2DEVREL(height
);
1473 matrix
[4] = XLOG2DEV(x
);
1474 matrix
[5] = YLOG2DEV(y
+height
);
1475 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1476 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1478 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1480 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1481 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1485 wxImage image
= bitmap
.ConvertToImage();
1487 if (!image
.Ok()) return;
1489 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1491 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1494 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1495 matrix
[4] = XLOG2DEV(x
);
1496 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1497 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1498 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1499 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1500 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1504 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1506 DoDrawRotatedText( text
, x
, y
, 0.0 );
1509 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1511 double xx
= XLOG2DEV(x
);
1512 double yy
= YLOG2DEV(y
);
1514 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1516 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1517 #if wxUSE_UNICODE_UTF8
1518 const char *data
= text
.utf8_str();
1520 const wxCharBuffer data
= text
.utf8_str();
1523 size_t datalen
= strlen(data
);
1524 pango_layout_set_text( m_layout
, data
, datalen
);
1528 PangoAttrList
*attrs
= pango_attr_list_new();
1529 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1531 a
->end_index
= datalen
;
1532 pango_attr_list_insert(attrs
, a
);
1533 pango_layout_set_attributes(m_layout
, attrs
);
1534 pango_attr_list_unref(attrs
);
1537 if (m_textForegroundColour
.Ok())
1539 unsigned char red
= m_textForegroundColour
.Red();
1540 unsigned char blue
= m_textForegroundColour
.Blue();
1541 unsigned char green
= m_textForegroundColour
.Green();
1543 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1545 double redPS
= (double)(red
) / 255.0;
1546 double bluePS
= (double)(blue
) / 255.0;
1547 double greenPS
= (double)(green
) / 255.0;
1549 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1552 m_currentBlue
= blue
;
1553 m_currentGreen
= green
;
1558 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1560 if ( m_backgroundMode
== wxSOLID
)
1562 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1563 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1564 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1569 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1571 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1573 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1575 if (fabs(angle
) > 0.00001)
1576 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1578 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1580 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1584 // undo underline attributes setting:
1585 pango_layout_set_attributes(m_layout
, NULL
);
1588 CalcBoundingBox (x
+ w
, y
+ h
);
1591 void wxGnomePrintDC::Clear()
1595 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1602 pango_font_description_free( m_fontdesc
);
1604 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1606 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1610 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1612 if (!pen
.Ok()) return;
1616 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1618 static const double dotted
[] = {2.0, 5.0};
1619 static const double short_dashed
[] = {4.0, 4.0};
1620 static const double wxCoord_dashed
[] = {4.0, 8.0};
1621 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1623 switch (m_pen
.GetStyle())
1625 case wxDOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1626 case wxSHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1627 case wxLONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1628 case wxDOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1631 // It may be noted that libgnomeprint between at least
1632 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1633 // and then leak the memory since it doesn't set the
1634 // internal flag "privatedash" to 0.
1636 int num
= m_pen
.GetDashes (&wx_dashes
);
1637 gdouble
*g_dashes
= g_new( gdouble
, num
);
1639 for (i
= 0; i
< num
; ++i
)
1640 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1641 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1647 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1651 unsigned char red
= m_pen
.GetColour().Red();
1652 unsigned char blue
= m_pen
.GetColour().Blue();
1653 unsigned char green
= m_pen
.GetColour().Green();
1655 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1657 double redPS
= (double)(red
) / 255.0;
1658 double bluePS
= (double)(blue
) / 255.0;
1659 double greenPS
= (double)(green
) / 255.0;
1661 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1664 m_currentBlue
= blue
;
1665 m_currentGreen
= green
;
1669 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1671 if (!brush
.Ok()) return;
1676 unsigned char red
= m_brush
.GetColour().Red();
1677 unsigned char blue
= m_brush
.GetColour().Blue();
1678 unsigned char green
= m_brush
.GetColour().Green();
1682 // Anything not white is black
1683 if (! (red
== (unsigned char) 255 &&
1684 blue
== (unsigned char) 255 &&
1685 green
== (unsigned char) 255) )
1687 red
= (unsigned char) 0;
1688 green
= (unsigned char) 0;
1689 blue
= (unsigned char) 0;
1694 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1696 double redPS
= (double)(red
) / 255.0;
1697 double bluePS
= (double)(blue
) / 255.0;
1698 double greenPS
= (double)(green
) / 255.0;
1700 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1703 m_currentBlue
= blue
;
1704 m_currentGreen
= green
;
1708 void wxGnomePrintDC::SetLogicalFunction( int function
)
1712 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1716 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1718 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1720 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1722 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1723 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1724 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1725 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1726 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1727 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1728 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1731 void wxGnomePrintDC::DestroyClippingRegion()
1733 wxDC::DestroyClippingRegion();
1735 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1738 // not needed, we set the values in each
1739 // drawing method anyways
1741 SetBrush( m_brush
);
1746 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1751 void wxGnomePrintDC::EndDoc()
1753 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1756 void wxGnomePrintDC::StartPage()
1758 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1761 void wxGnomePrintDC::EndPage()
1763 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1766 wxCoord
wxGnomePrintDC::GetCharHeight() const
1768 pango_layout_set_text( m_layout
, "H", 1 );
1771 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1776 wxCoord
wxGnomePrintDC::GetCharWidth() const
1778 pango_layout_set_text( m_layout
, "H", 1 );
1781 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1786 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1788 wxCoord
*externalLeading
,
1789 const wxFont
*theFont
) const
1797 if ( externalLeading
)
1798 *externalLeading
= 0;
1805 // Set layout's text
1807 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1808 #if wxUSE_UNICODE_UTF8
1809 const char *dataUTF8
= string
.utf8_str();
1811 const wxCharBuffer dataUTF8
= string
.utf8_str();
1814 PangoFontDescription
*desc
= (theFont
) ? theFont
->GetNativeFontInfo()->description
: m_fontdesc
;
1816 gint oldSize
= pango_font_description_get_size( desc
);
1817 double size
= oldSize
;
1818 size
= size
* m_scaleY
;
1819 pango_font_description_set_size( desc
, (gint
)size
);
1821 // apply scaled font
1822 pango_layout_set_font_description( m_layout
, desc
);
1824 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1827 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1831 *width
= (wxCoord
)(w
/ m_scaleX
);
1833 *height
= (wxCoord
)(h
/ m_scaleY
);
1837 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1838 int baseline
= pango_layout_iter_get_baseline(iter
);
1839 pango_layout_iter_free(iter
);
1840 *descent
= h
- PANGO_PIXELS(baseline
);
1843 // reset unscaled size
1844 pango_font_description_set_size( desc
, oldSize
);
1846 // reset unscaled font
1847 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1850 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1852 wxGnomePrintNativeData
*native
=
1853 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1855 // Query page size. This seems to omit the margins
1857 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1860 *width
= wxRound( pw
* PS2DEV
);
1862 *height
= wxRound( ph
* PS2DEV
);
1865 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1867 wxGnomePrintNativeData
*native
=
1868 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1870 // This code assumes values in Pts.
1873 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1877 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1878 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1879 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1880 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1883 *width
= (int) (pw
+ 0.5);
1885 *height
= (int) (ph
+ 0.5);
1888 wxSize
wxGnomePrintDC::GetPPI() const
1890 return wxSize(DPI
,DPI
);
1893 void wxGnomePrintDC::SetPrintData(const wxPrintData
& data
)
1898 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1899 GetSize( NULL
, &height
);
1901 GetSize( &height
, NULL
);
1902 m_deviceLocalOriginY
= height
;
1905 void wxGnomePrintDC::SetResolution(int ppi
)
1909 int wxGnomePrintDC::GetResolution()
1914 // ----------------------------------------------------------------------------
1915 // wxGnomePrintModule
1916 // ----------------------------------------------------------------------------
1918 bool wxGnomePrintModule::OnInit()
1920 gs_libGnomePrint
= new wxGnomePrintLibrary
;
1921 if (gs_libGnomePrint
->IsOk())
1922 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1926 void wxGnomePrintModule::OnExit()
1928 delete gs_libGnomePrint
;
1929 gs_libGnomePrint
= NULL
;
1932 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1934 // ----------------------------------------------------------------------------
1936 // ----------------------------------------------------------------------------
1938 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1940 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1941 wxPrintout
* WXUNUSED(printoutForPrinting
))
1946 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1947 wxPrintout
*printoutForPrinting
,
1948 wxPrintDialogData
*data
)
1949 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1951 Init(printout
, printoutForPrinting
);
1954 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1955 wxPrintout
*printoutForPrinting
,
1957 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1959 Init(printout
, printoutForPrinting
);
1962 wxGnomePrintPreview::~wxGnomePrintPreview()
1966 bool wxGnomePrintPreview::Print(bool interactive
)
1968 if (!m_printPrintout
)
1971 wxPrinter
printer(& m_printDialogData
);
1972 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
1975 void wxGnomePrintPreview::DetermineScaling()
1977 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
1978 if (paperType
== wxPAPER_NONE
)
1979 paperType
= wxPAPER_NONE
;
1981 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1983 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1987 wxSize ScreenPixels
= wxGetDisplaySize();
1988 wxSize ScreenMM
= wxGetDisplaySizeMM();
1990 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
1991 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
1992 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
1994 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
1996 // TODO: get better resolution information from wxGnomePrintDC, if possible.
1998 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
1999 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
2000 wxSize
sizeTenthsMM(paper
->GetSize());
2001 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2003 // If in landscape mode, we need to swap the width and height.
2004 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2006 m_pageWidth
= sizeDevUnits
.y
;
2007 m_pageHeight
= sizeDevUnits
.x
;
2008 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2012 m_pageWidth
= sizeDevUnits
.x
;
2013 m_pageHeight
= sizeDevUnits
.y
;
2014 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2016 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2017 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2019 // At 100%, the page should look about page-size on the screen.
2020 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
2021 m_previewScaleY
= m_previewScaleX
;
2026 // wxUSE_LIBGNOMEPRINT