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"
32 #include "wx/fontutil.h"
33 #include "wx/gtk/private.h"
34 #include "wx/dynlib.h"
36 #include "wx/dcprint.h"
37 #include "wx/modalhook.h"
39 #include <libgnomeprint/gnome-print.h>
40 #include <libgnomeprint/gnome-print-pango.h>
41 #include <libgnomeprint/gnome-print-config.h>
42 #include <libgnomeprintui/gnome-print-dialog.h>
43 #include <libgnomeprintui/gnome-print-job-preview.h>
44 #include <libgnomeprintui/gnome-print-paper-selector.h>
47 wxFORCE_LINK_THIS_MODULE(gnome_print
)
49 //----------------------------------------------------------------------------
50 // wxGnomePrintLibrary
51 //----------------------------------------------------------------------------
53 class wxGnomePrintLibrary
56 wxGnomePrintLibrary();
57 ~wxGnomePrintLibrary();
61 bool InitializeMethods();
63 wxDynamicLibrary m_libGnomePrint
;
64 wxDynamicLibrary m_libGnomePrintUI
;
66 // only true if we successfully loaded both libraries
68 // don't rename this field, it's used by wxDL_XXX macros internally
72 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
73 (GnomePrintContext
*pc
), (pc
), 0 )
74 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
75 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
76 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
77 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
79 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
81 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
83 (GnomePrintContext
*pc
), (pc
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
85 (GnomePrintContext
*pc
), (pc
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
87 (GnomePrintContext
*pc
), (pc
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
89 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
91 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
93 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
95 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
96 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
98 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
100 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
101 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
102 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
103 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
105 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
107 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
109 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
110 (GnomePrintContext
*pc
), (pc
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
112 (GnomePrintContext
*pc
), (pc
), 0 )
114 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
115 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
117 (GnomePrintContext
*pc
), (pc
), 0 )
119 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
120 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
121 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
122 (GnomePrintContext
*pc
), (pc
), 0 )
123 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
124 (GnomePrintContext
*pc
), (pc
), 0 )
126 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
127 (GnomePrintContext
*gpc
), (gpc
), NULL
)
128 wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout
,
129 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
) )
131 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
132 (GnomePrintConfig
*config
), (config
), NULL
)
133 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
134 (GnomePrintJob
*job
), (job
), NULL
)
135 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
136 (GnomePrintJob
*job
), (job
), 0 )
137 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
138 (GnomePrintJob
*job
), (job
), 0 )
139 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
140 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
142 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
143 (const guchar
*abbreviation
), (abbreviation
), NULL
)
144 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
145 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
147 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
149 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
150 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
151 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
152 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
153 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
154 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
155 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
156 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
157 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
158 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
160 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
161 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
162 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
163 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
164 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_boolean
,
165 (GnomePrintConfig
*config
, const guchar
*key
, gboolean
*val
), (config
, key
, val
), false )
167 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
168 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
169 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page
,
170 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
171 const guchar
*currentlabel
, const guchar
*rangelabel
),
172 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
) )
173 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies
,
174 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
) )
175 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies
,
176 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
) )
177 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
178 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
179 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
180 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
182 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
183 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
185 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
186 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
188 wxDECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
);
191 wxGnomePrintLibrary::wxGnomePrintLibrary()
195 m_libGnomePrint
.Load("libgnomeprint-2-2.so.0");
196 m_ok
= m_libGnomePrint
.IsLoaded();
200 m_libGnomePrintUI
.Load("libgnomeprintui-2-2.so.0");
201 m_ok
= m_libGnomePrintUI
.IsLoaded();
204 m_libGnomePrint
.Unload();
208 m_ok
= InitializeMethods();
211 wxGnomePrintLibrary::~wxGnomePrintLibrary()
215 bool wxGnomePrintLibrary::IsOk()
220 bool wxGnomePrintLibrary::InitializeMethods()
222 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_newpath
);
223 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_moveto
);
224 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_lineto
);
225 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_curveto
);
226 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_arcto
);
227 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_closepath
);
228 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_stroke
);
229 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_fill
);
230 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setrgbcolor
);
231 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setlinewidth
);
232 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setdash
);
234 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbimage
);
235 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbaimage
);
237 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_concat
);
238 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_scale
);
239 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rotate
);
240 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_translate
);
242 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_gsave
);
243 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_grestore
);
245 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_clip
);
246 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_eoclip
);
248 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_beginpage
);
249 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_showpage
);
250 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_end_doc
);
252 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_create_layout
);
253 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_layout
);
255 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_new
);
256 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_context
);
257 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_close
);
258 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_print
);
259 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_page_size
);
261 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_unit_get_by_abbreviation
);
262 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_convert_distance
);
264 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_default
);
265 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set
);
266 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_boolean
);
267 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_double
);
268 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_int
);
269 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_length
);
271 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get
);
272 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_length
);
273 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_boolean
);
275 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_new
);
276 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_construct_range_page
);
277 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_copies
);
278 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_set_copies
);
279 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range
);
280 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range_page
);
282 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_paper_selector_new_with_flags
);
284 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_job_preview_new
);
289 static wxGnomePrintLibrary
* gs_libGnomePrint
= NULL
;
291 //----------------------------------------------------------------------------
292 // wxGnomePrintNativeData
293 //----------------------------------------------------------------------------
295 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
297 wxGnomePrintNativeData::wxGnomePrintNativeData()
299 m_config
= gs_libGnomePrint
->gnome_print_config_default();
300 m_job
= gs_libGnomePrint
->gnome_print_job_new( m_config
);
303 wxGnomePrintNativeData::~wxGnomePrintNativeData()
305 g_object_unref (m_config
);
308 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
310 guchar
*res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
311 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
);
312 if (g_ascii_strcasecmp((const gchar
*)res
,"R90") == 0)
313 data
.SetOrientation( wxLANDSCAPE
);
315 data
.SetOrientation( wxPORTRAIT
);
318 res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
319 (guchar
*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME
);
322 data
.SetFilename( wxConvFile
.cMB2WX( (const char*) res
) );
323 wxPrintf( "filename %s\n", data
.GetFilename() );
328 data
.SetFilename( wxEmptyString
);
332 if (gs_libGnomePrint
->gnome_print_config_get_boolean( m_config
,
333 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
, &ret
))
335 data
.SetCollate( ret
);
343 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
345 if (data
.GetOrientation() == wxLANDSCAPE
)
347 gs_libGnomePrint
->gnome_print_config_set( m_config
,
348 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
349 (guchar
*)(char*)"R90" );
353 gs_libGnomePrint
->gnome_print_config_set( m_config
,
354 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
355 (guchar
*)(char*)"R0" );
358 if (data
.GetCollate())
360 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
361 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
366 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
367 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
371 switch (data
.GetPaperId())
373 case wxPAPER_A3
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
374 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
375 (guchar
*)(char*)"A3" );
377 case wxPAPER_A5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
378 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
379 (guchar
*)(char*)"A5" );
381 case wxPAPER_B4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
382 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
383 (guchar
*)(char*)"B4" );
385 case wxPAPER_B5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
386 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
387 (guchar
*)(char*)"B5" );
389 case wxPAPER_LETTER
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
390 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
391 (guchar
*)(char*)"USLetter" );
393 case wxPAPER_LEGAL
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
394 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
395 (guchar
*)(char*)"USLegal" );
397 case wxPAPER_EXECUTIVE
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
398 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
399 (guchar
*)(char*)"Executive" );
401 case wxPAPER_ENV_C5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
402 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
403 (guchar
*)(char*)"C5" );
405 case wxPAPER_ENV_C6
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
406 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
407 (guchar
*)(char*)"C6" );
409 case wxPAPER_NONE
: break;
412 case wxPAPER_A4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
413 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
414 (guchar
*)(char*)"A4" );
421 //----------------------------------------------------------------------------
422 // wxGnomePrintFactory
423 //----------------------------------------------------------------------------
425 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
427 return new wxGnomePrinter( data
);
430 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
431 wxPrintout
*printout
,
432 wxPrintDialogData
*data
)
434 return new wxGnomePrintPreview( preview
, printout
, data
);
437 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
438 wxPrintout
*printout
,
441 return new wxGnomePrintPreview( preview
, printout
, data
);
444 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
445 wxPrintDialogData
*data
)
447 return new wxGnomePrintDialog( parent
, data
);
450 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
453 return new wxGnomePrintDialog( parent
, data
);
456 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
457 wxPageSetupDialogData
* data
)
459 // The native page setup dialog is broken. It
460 // miscalculates newly entered values for the
461 // margins if you have not chose "points" but
462 // e.g. centimerters.
463 // This has been fixed in GNOME CVS (maybe
464 // fixed in libgnomeprintui 2.8.1)
466 return new wxGnomePageSetupDialog( parent
, data
);
469 bool wxGnomePrintFactory::HasPrintSetupDialog()
475 wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
476 wxPrintData
* WXUNUSED(data
))
484 wxDCImpl
* wxGnomePrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
486 return new wxGnomePrinterDCImpl( owner
, data
);
491 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
493 return new wxGnomePrinterDC(data
);
498 bool wxGnomePrintFactory::HasOwnPrintToFile()
503 bool wxGnomePrintFactory::HasPrinterLine()
508 wxString
wxGnomePrintFactory::CreatePrinterLine()
511 return wxEmptyString
;
514 bool wxGnomePrintFactory::HasStatusLine()
520 wxString
wxGnomePrintFactory::CreateStatusLine()
523 return wxEmptyString
;
526 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
528 return new wxGnomePrintNativeData
;
531 //----------------------------------------------------------------------------
532 // wxGnomePrintSetupDialog
533 //----------------------------------------------------------------------------
535 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
537 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
538 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
539 wxPoint(0, 0), wxSize(600, 600),
540 wxDEFAULT_DIALOG_STYLE
|
544 m_printDialogData
= *data
;
549 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
550 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
551 wxPoint(0, 0), wxSize(600, 600),
552 wxDEFAULT_DIALOG_STYLE
|
556 m_printDialogData
= *data
;
561 void wxGnomePrintDialog::Init()
563 wxPrintData data
= m_printDialogData
.GetPrintData();
565 data
.ConvertToNative();
567 wxGnomePrintNativeData
*native
=
568 (wxGnomePrintNativeData
*) data
.GetNativeData();
570 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
572 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
575 if (m_printDialogData
.GetEnableSelection())
576 flag
|= GNOME_PRINT_RANGE_SELECTION
;
577 if (m_printDialogData
.GetEnablePageNumbers())
578 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
580 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
582 m_printDialogData
.GetMinPage(),
583 m_printDialogData
.GetMaxPage(),
588 wxGnomePrintDialog::~wxGnomePrintDialog()
593 int wxGnomePrintDialog::ShowModal()
595 WX_HOOK_MODAL_DIALOG();
597 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
599 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
601 gtk_widget_destroy(m_widget
);
607 m_printDialogData
.GetPrintData().ConvertFromNative();
610 gboolean collate
= false;
611 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
612 m_printDialogData
.SetNoCopies( copies
);
613 m_printDialogData
.SetCollate( collate
);
615 // Cast needed to avoid warnings because the gnome_print_dialog_get_range()
616 // is declared as returning a wrong enum type.
617 switch ( static_cast<int>( gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
)))
619 case GNOME_PRINT_RANGE_SELECTION
:
620 m_printDialogData
.SetSelection( true );
622 case GNOME_PRINT_RANGE_ALL
:
623 m_printDialogData
.SetAllPages( true );
624 m_printDialogData
.SetFromPage( 0 );
625 m_printDialogData
.SetToPage( 9999 );
627 case GNOME_PRINT_RANGE_RANGE
:
630 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
631 m_printDialogData
.SetFromPage( start
);
632 m_printDialogData
.SetToPage( end
);
636 gtk_widget_destroy(m_widget
);
639 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
645 wxDC
*wxGnomePrintDialog::GetPrintDC()
651 bool wxGnomePrintDialog::Validate()
656 bool wxGnomePrintDialog::TransferDataToWindow()
661 bool wxGnomePrintDialog::TransferDataFromWindow()
666 //----------------------------------------------------------------------------
667 // wxGnomePageSetupDialog
668 //----------------------------------------------------------------------------
670 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
672 wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow
* WXUNUSED(parent
),
673 wxPageSetupDialogData
*data
)
676 m_pageDialogData
= *data
;
678 m_pageDialogData
.GetPrintData().ConvertToNative();
680 wxGnomePrintNativeData
*native
=
681 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
683 // This *was* required as the page setup dialog
684 // calculates wrong values otherwise.
686 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
687 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
688 (const guchar
*) "Pts" );
691 GnomePrintConfig
*config
= native
->GetPrintConfig();
693 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
695 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
696 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
697 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
698 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
700 gs_libGnomePrint
->gnome_print_config_set_length (config
,
701 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
702 gs_libGnomePrint
->gnome_print_config_set_length (config
,
703 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
704 gs_libGnomePrint
->gnome_print_config_set_length (config
,
705 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
706 gs_libGnomePrint
->gnome_print_config_set_length (config
,
707 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
709 m_widget
= gtk_dialog_new();
711 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
713 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
714 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
715 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
716 gtk_widget_show (main
);
718 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
720 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
722 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
723 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
724 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
727 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
731 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
735 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
737 return m_pageDialogData
;
740 int wxGnomePageSetupDialog::ShowModal()
742 WX_HOOK_MODAL_DIALOG();
744 wxGnomePrintNativeData
*native
=
745 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
747 GnomePrintConfig
*config
= native
->GetPrintConfig();
750 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
752 if (ret
== GTK_RESPONSE_OK
)
754 // Transfer data back to m_pageDialogData
755 m_pageDialogData
.GetPrintData().ConvertFromNative();
757 // I don't know how querying the last parameter works
758 double ml
,mr
,mt
,mb
,pw
,ph
;
759 gs_libGnomePrint
->gnome_print_config_get_length (config
,
760 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
761 gs_libGnomePrint
->gnome_print_config_get_length (config
,
762 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
763 gs_libGnomePrint
->gnome_print_config_get_length (config
,
764 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
765 gs_libGnomePrint
->gnome_print_config_get_length (config
,
766 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
767 gs_libGnomePrint
->gnome_print_config_get_length (config
,
768 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
769 gs_libGnomePrint
->gnome_print_config_get_length (config
,
770 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
772 // This code converts correctly from what the user chose
773 // as the unit although I query Pts here
774 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
775 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
776 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
777 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
778 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
779 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
780 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
781 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
783 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
784 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
786 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
795 gtk_widget_destroy( m_widget
);
801 bool wxGnomePageSetupDialog::Validate()
806 bool wxGnomePageSetupDialog::TransferDataToWindow()
811 bool wxGnomePageSetupDialog::TransferDataFromWindow()
816 //----------------------------------------------------------------------------
818 //----------------------------------------------------------------------------
820 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
822 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
823 wxPrinterBase( data
)
825 m_native_preview
= false;
828 wxGnomePrinter::~wxGnomePrinter()
832 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
836 sm_lastError
= wxPRINTER_ERROR
;
840 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
842 wxGnomePrintNativeData
*native
=
843 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
845 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
847 // The GnomePrintJob is temporarily stored in the
848 // native print data as the native print dialog
849 // needs to access it.
850 native
->SetPrintJob( job
);
853 if (m_printDialogData
.GetMinPage() < 1)
854 m_printDialogData
.SetMinPage(1);
855 if (m_printDialogData
.GetMaxPage() < 1)
856 m_printDialogData
.SetMaxPage(9999);
860 dc
= PrintDialog( parent
);
863 dc
= new wxPrinterDC( printdata
); // TODO: check that this works
865 dc
= new wxGnomePrinterDC( printdata
); // TODO: check that this works
870 gs_libGnomePrint
->gnome_print_job_close( job
);
871 g_object_unref (job
);
872 if (sm_lastError
!= wxPRINTER_CANCELLED
)
873 sm_lastError
= wxPRINTER_ERROR
;
877 printout
->SetPPIScreen(wxGetDisplayPPI());
878 printout
->SetPPIPrinter( dc
->GetResolution(),
879 dc
->GetResolution() );
885 printout
->SetPageSizePixels((int)w
, (int)h
);
886 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
888 dc
->GetSizeMM(&mw
, &mh
);
889 printout
->SetPageSizeMM((int)mw
, (int)mh
);
890 printout
->OnPreparePrinting();
892 // Get some parameters from the printout, if defined
893 int fromPage
, toPage
;
894 int minPage
, maxPage
;
895 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
899 gs_libGnomePrint
->gnome_print_job_close( job
);
900 g_object_unref (job
);
901 sm_lastError
= wxPRINTER_ERROR
;
905 printout
->OnBeginPrinting();
907 int minPageNum
= minPage
, maxPageNum
= maxPage
;
909 if ( !m_printDialogData
.GetAllPages() )
911 minPageNum
= m_printDialogData
.GetFromPage();
912 maxPageNum
= m_printDialogData
.GetToPage();
918 copyCount
<= m_printDialogData
.GetNoCopies();
921 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
923 wxLogError(_("Could not start printing."));
924 sm_lastError
= wxPRINTER_ERROR
;
929 for ( pn
= minPageNum
;
930 pn
<= maxPageNum
&& printout
->HasPage(pn
);
934 printout
->OnPrintPage(pn
);
938 printout
->OnEndDocument();
939 printout
->OnEndPrinting();
942 gs_libGnomePrint
->gnome_print_job_close( job
);
943 if (m_native_preview
)
945 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
946 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
949 (const guchar
*)title
.data()
951 gtk_widget_show(preview
);
955 gs_libGnomePrint
->gnome_print_job_print( job
);
958 g_object_unref (job
);
961 return (sm_lastError
== wxPRINTER_NO_ERROR
);
964 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
966 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
967 int ret
= dialog
.ShowModal();
968 if (ret
== wxID_CANCEL
)
970 sm_lastError
= wxPRINTER_CANCELLED
;
974 m_native_preview
= ret
== wxID_PREVIEW
;
976 m_printDialogData
= dialog
.GetPrintDialogData();
978 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
980 return new wxGnomePrinterDC( m_printDialogData
.GetPrintData() );
984 bool wxGnomePrinter::Setup(wxWindow
* WXUNUSED(parent
))
989 //-----------------------------------------------------------------------------
991 //-----------------------------------------------------------------------------
994 static const double RAD2DEG
= 180.0 / M_PI
;
996 // we don't want to use only 72 dpi from GNOME print
997 static const int DPI
= 600;
998 static const double PS2DEV
= 600.0 / 72.0;
999 static const double DEV2PS
= 72.0 / 600.0;
1001 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
1002 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
1003 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
1004 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
1007 IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDCImpl
, wxDCImpl
)
1009 IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDC
, wxDC
)
1013 wxGnomePrinterDCImpl::wxGnomePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
) :
1016 wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData
& data
)
1021 wxGnomePrintNativeData
*native
=
1022 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1024 m_job
= native
->GetPrintJob();
1025 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
1027 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
1028 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1035 // Query page size. This seems to omit the margins
1037 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1039 m_pageHeight
= ph
* PS2DEV
;
1042 wxGnomePrinterDCImpl::~wxGnomePrinterDCImpl()
1046 bool wxGnomePrinterDCImpl::IsOk() const
1052 wxGnomePrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1053 wxCoord
WXUNUSED(y1
),
1054 const wxColour
& WXUNUSED(col
),
1055 wxFloodFillStyle
WXUNUSED(style
))
1061 wxGnomePrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1062 wxCoord
WXUNUSED(y1
),
1063 wxColour
* WXUNUSED(col
)) const
1068 void wxGnomePrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1070 if ( m_pen
.IsTransparent() )
1075 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1076 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1077 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1079 CalcBoundingBox( x1
, y1
);
1080 CalcBoundingBox( x2
, y2
);
1083 void wxGnomePrinterDCImpl::DoCrossHair(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1087 void wxGnomePrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1089 double dx
= x1
- xc
;
1090 double dy
= y1
- yc
;
1091 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1092 double alpha1
, alpha2
;
1093 if (x1
== x2
&& y1
== y2
)
1098 else if ( wxIsNullDouble(radius
) )
1105 alpha1
= (x1
- xc
== 0) ?
1106 (y1
- yc
< 0) ? 90.0 : -90.0 :
1107 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1108 alpha2
= (x2
- xc
== 0) ?
1109 (y2
- yc
< 0) ? 90.0 : -90.0 :
1110 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1112 while (alpha1
<= 0) alpha1
+= 360;
1113 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1114 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1115 while (alpha2
> 360) alpha2
-= 360;
1118 if ( m_brush
.IsNonTransparent() )
1120 SetBrush( m_brush
);
1121 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1122 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1124 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1127 if ( m_pen
.IsNonTransparent() )
1130 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1131 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1132 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1133 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1135 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1138 CalcBoundingBox (x1
, y1
);
1139 CalcBoundingBox (x2
, y2
);
1140 CalcBoundingBox (xc
, yc
);
1143 void wxGnomePrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1148 double xx
= XLOG2DEV(x
);
1149 double yy
= YLOG2DEV(y
);
1151 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1153 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1154 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1155 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1160 if ( m_brush
.IsNonTransparent() )
1162 SetBrush( m_brush
);
1164 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1165 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1166 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1167 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1169 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1172 if ( m_pen
.IsNonTransparent() )
1176 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1177 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1179 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1182 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1184 CalcBoundingBox( x
, y
);
1185 CalcBoundingBox( x
+w
, y
+h
);
1188 void wxGnomePrinterDCImpl::DoDrawPoint(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1192 void wxGnomePrinterDCImpl::DoDrawLines(int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1196 if ( m_pen
.IsTransparent() )
1202 for ( i
=0; i
<n
; i
++ )
1203 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1205 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1207 for (i
= 1; i
< n
; i
++)
1208 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1210 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1213 void wxGnomePrinterDCImpl::DoDrawPolygon(int n
, const wxPoint points
[],
1214 wxCoord xoffset
, wxCoord yoffset
,
1215 wxPolygonFillMode
WXUNUSED(fillStyle
))
1219 if ( m_brush
.IsNonTransparent() )
1221 SetBrush( m_brush
);
1223 int x
= points
[0].x
+ xoffset
;
1224 int y
= points
[0].y
+ yoffset
;
1225 CalcBoundingBox( x
, y
);
1226 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1227 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1229 for (i
= 1; i
< n
; i
++)
1231 x
= points
[i
].x
+ xoffset
;
1232 y
= points
[i
].y
+ yoffset
;
1233 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1234 CalcBoundingBox( x
, y
);
1236 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1237 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1240 if ( m_pen
.IsNonTransparent() )
1244 int x
= points
[0].x
+ xoffset
;
1245 int y
= points
[0].y
+ yoffset
;
1246 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1247 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1249 for (i
= 1; i
< n
; i
++)
1251 x
= points
[i
].x
+ xoffset
;
1252 y
= points
[i
].y
+ yoffset
;
1253 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1254 CalcBoundingBox( x
, y
);
1256 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1257 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1261 void wxGnomePrinterDCImpl::DoDrawPolyPolygon(int n
, const int count
[], const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, wxPolygonFillMode fillStyle
)
1264 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1266 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1270 void wxGnomePrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1275 if ( m_brush
.IsNonTransparent() )
1277 SetBrush( m_brush
);
1279 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1280 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1281 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1282 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1283 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1284 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1285 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1287 CalcBoundingBox( x
, y
);
1288 CalcBoundingBox( x
+ width
, y
+ height
);
1291 if ( m_pen
.IsNonTransparent() )
1295 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1296 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1297 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1298 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1299 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1300 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1301 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1303 CalcBoundingBox( x
, y
);
1304 CalcBoundingBox( x
+ width
, y
+ height
);
1308 void wxGnomePrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1313 wxCoord rad
= wxRound( radius
);
1315 if ( m_brush
.IsNonTransparent() )
1318 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1319 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1320 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1321 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1322 XLOG2DEV(x
),YLOG2DEV(y
),
1323 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1324 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1325 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1326 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1327 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1328 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1329 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1330 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1331 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1332 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1333 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1334 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1335 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1336 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1337 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1338 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1339 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1340 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1341 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1343 CalcBoundingBox(x
,y
);
1344 CalcBoundingBox(x
+width
,y
+height
);
1347 if ( m_pen
.IsNonTransparent() )
1350 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1351 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1352 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1353 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1354 XLOG2DEV(x
),YLOG2DEV(y
),
1355 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1356 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1357 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1358 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1359 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1360 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1361 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1362 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1363 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1364 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1365 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1366 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1367 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1368 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1369 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1370 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1371 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1372 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1373 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1375 CalcBoundingBox(x
,y
);
1376 CalcBoundingBox(x
+width
,y
+height
);
1380 void wxGnomePrinterDCImpl::makeEllipticalPath(wxCoord x
, wxCoord y
,
1381 wxCoord width
, wxCoord height
)
1383 double r
= 4 * (sqrt(2.) - 1) / 3;
1384 double halfW
= 0.5 * width
,
1385 halfH
= 0.5 * height
,
1388 wxCoord halfWI
= (wxCoord
) halfW
,
1389 halfHI
= (wxCoord
) halfH
;
1391 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1393 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1394 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1395 XLOG2DEV(x
+ width
),
1396 YLOG2DEV(y
+ halfHI
) );
1397 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1398 XLOG2DEV(x
+ width
),
1399 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1400 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1401 YLOG2DEV(y
+ height
),
1402 XLOG2DEV(x
+ halfWI
),
1403 YLOG2DEV(y
+ height
) );
1404 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1405 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1406 YLOG2DEV(y
+ height
),
1408 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1409 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1410 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1412 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1413 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1415 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1416 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1417 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1419 XLOG2DEV(x
+ width
),
1420 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1421 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1423 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1426 void wxGnomePrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1431 if ( m_brush
.IsNonTransparent() )
1433 SetBrush( m_brush
);
1434 makeEllipticalPath( x
, y
, width
, height
);
1435 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1436 CalcBoundingBox( x
, y
);
1437 CalcBoundingBox( x
+ width
, y
+ height
);
1440 if ( m_pen
.IsNonTransparent() )
1443 makeEllipticalPath( x
, y
, width
, height
);
1444 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1445 CalcBoundingBox( x
, y
);
1446 CalcBoundingBox( x
+ width
, y
+ height
);
1451 void wxGnomePrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1455 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1458 wxPointList::compatibility_iterator node
= points
->GetFirst();
1459 p
= node
->GetData();
1463 node
= node
->GetNext();
1464 p
= node
->GetData();
1468 (double)(x1
+ c
) / 2;
1470 (double)(y1
+ d
) / 2;
1472 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1473 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1474 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1476 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1477 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1479 node
= node
->GetNext();
1482 q
= node
->GetData();
1490 x3
= (double)(x2
+ c
) / 2;
1491 y3
= (double)(y2
+ d
) / 2;
1493 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1494 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1495 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1496 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1498 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1499 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1501 node
= node
->GetNext();
1504 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1506 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1508 #endif // wxUSE_SPLINES
1511 wxGnomePrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1512 wxCoord width
, wxCoord height
,
1514 wxCoord xsrc
, wxCoord ysrc
,
1515 wxRasterOperationMode rop
,
1516 bool WXUNUSED(useMask
),
1517 wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
))
1519 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1521 // blit into a bitmap
1522 wxBitmap
bitmap( width
, height
);
1524 memDC
.SelectObject(bitmap
);
1525 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1526 memDC
.SelectObject(wxNullBitmap
);
1528 // draw bitmap. scaling and positioning is done there
1529 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
);
1534 void wxGnomePrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1536 DoDrawBitmap( icon
, x
, y
, true );
1540 wxGnomePrinterDCImpl::DoDrawBitmap(const wxBitmap
& bitmap
,
1541 wxCoord x
, wxCoord y
,
1542 bool WXUNUSED(useMask
))
1544 if (!bitmap
.IsOk()) return;
1546 if (bitmap
.HasPixbuf())
1548 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1549 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1550 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1551 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1552 int height
= gdk_pixbuf_get_height( pixbuf
);
1553 int width
= gdk_pixbuf_get_width( pixbuf
);
1555 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1557 matrix
[0] = XLOG2DEVREL(width
);
1560 matrix
[3] = YLOG2DEVREL(height
);
1561 matrix
[4] = XLOG2DEV(x
);
1562 matrix
[5] = YLOG2DEV(y
+height
);
1563 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1564 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1566 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1568 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1569 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1573 wxImage image
= bitmap
.ConvertToImage();
1575 if (!image
.IsOk()) return;
1577 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1579 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1582 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1583 matrix
[4] = XLOG2DEV(x
);
1584 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1585 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1586 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1587 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1588 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1592 void wxGnomePrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1594 DoDrawRotatedText( text
, x
, y
, 0.0 );
1597 void wxGnomePrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1599 double xx
= XLOG2DEV(x
);
1600 double yy
= YLOG2DEV(y
);
1602 const wxScopedCharBuffer
data(text
.utf8_str());
1604 pango_layout_set_text(m_layout
, data
, data
.length());
1605 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1607 if (m_textForegroundColour
.IsOk())
1609 unsigned char red
= m_textForegroundColour
.Red();
1610 unsigned char blue
= m_textForegroundColour
.Blue();
1611 unsigned char green
= m_textForegroundColour
.Green();
1613 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1615 double redPS
= (double)(red
) / 255.0;
1616 double bluePS
= (double)(blue
) / 255.0;
1617 double greenPS
= (double)(green
) / 255.0;
1619 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1622 m_currentBlue
= blue
;
1623 m_currentGreen
= green
;
1628 if ( m_backgroundMode
== wxSOLID
)
1630 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1631 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1632 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1637 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1639 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1641 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1643 if (fabs(angle
) > 0.00001)
1644 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1646 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1649 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1651 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1655 // undo underline attributes setting:
1656 pango_layout_set_attributes(m_layout
, NULL
);
1659 CalcBoundingBox(x
, y
);
1660 CalcBoundingBox(x
+ w
, y
+ h
);
1663 void wxGnomePrinterDCImpl::Clear()
1667 void wxGnomePrinterDCImpl::SetFont( const wxFont
& font
)
1674 pango_font_description_free( m_fontdesc
);
1676 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1678 float size
= pango_font_description_get_size( m_fontdesc
);
1679 size
= size
* GetFontPointSizeAdjustment(72.0);
1680 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1682 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1686 void wxGnomePrinterDCImpl::SetPen( const wxPen
& pen
)
1688 if (!pen
.IsOk()) return;
1694 if (m_pen
.GetWidth() <= 0)
1697 width
= (double) m_pen
.GetWidth();
1699 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, width
* DEV2PS
* m_scaleX
);
1701 static const double dotted
[] = {2.0, 5.0};
1702 static const double short_dashed
[] = {4.0, 4.0};
1703 static const double wxCoord_dashed
[] = {4.0, 8.0};
1704 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1706 switch (m_pen
.GetStyle())
1708 case wxPENSTYLE_DOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1709 case wxPENSTYLE_SHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1710 case wxPENSTYLE_LONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1711 case wxPENSTYLE_DOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1712 case wxPENSTYLE_USER_DASH
:
1714 // It may be noted that libgnomeprint between at least
1715 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1716 // and then leak the memory since it doesn't set the
1717 // internal flag "privatedash" to 0.
1719 int num
= m_pen
.GetDashes (&wx_dashes
);
1720 gdouble
*g_dashes
= g_new( gdouble
, num
);
1722 for (i
= 0; i
< num
; ++i
)
1723 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1724 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1728 case wxPENSTYLE_SOLID
:
1729 case wxPENSTYLE_TRANSPARENT
:
1730 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1734 unsigned char red
= m_pen
.GetColour().Red();
1735 unsigned char blue
= m_pen
.GetColour().Blue();
1736 unsigned char green
= m_pen
.GetColour().Green();
1738 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1740 double redPS
= (double)(red
) / 255.0;
1741 double bluePS
= (double)(blue
) / 255.0;
1742 double greenPS
= (double)(green
) / 255.0;
1744 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1747 m_currentBlue
= blue
;
1748 m_currentGreen
= green
;
1752 void wxGnomePrinterDCImpl::SetBrush( const wxBrush
& brush
)
1754 if (!brush
.IsOk()) return;
1759 unsigned char red
= m_brush
.GetColour().Red();
1760 unsigned char blue
= m_brush
.GetColour().Blue();
1761 unsigned char green
= m_brush
.GetColour().Green();
1765 // Anything not white is black
1766 if (! (red
== (unsigned char) 255 &&
1767 blue
== (unsigned char) 255 &&
1768 green
== (unsigned char) 255) )
1770 red
= (unsigned char) 0;
1771 green
= (unsigned char) 0;
1772 blue
= (unsigned char) 0;
1777 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1779 double redPS
= (double)(red
) / 255.0;
1780 double bluePS
= (double)(blue
) / 255.0;
1781 double greenPS
= (double)(green
) / 255.0;
1783 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1786 m_currentBlue
= blue
;
1787 m_currentGreen
= green
;
1791 void wxGnomePrinterDCImpl::SetLogicalFunction(wxRasterOperationMode
WXUNUSED(function
))
1795 void wxGnomePrinterDCImpl::SetBackground(const wxBrush
& WXUNUSED(brush
))
1799 void wxGnomePrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1802 m_clipping
= TRUE
; // TODO move somewhere else
1805 m_clipX2
= x
+ width
;
1806 m_clipY2
= y
+ height
;
1808 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1811 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1813 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1814 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1815 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1816 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1817 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1818 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1819 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1822 void wxGnomePrinterDCImpl::DestroyClippingRegion()
1825 wxDCImpl::DestroyClippingRegion();
1827 wxDC::DestroyClippingRegion();
1830 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1833 // not needed, we set the values in each
1834 // drawing method anyways
1836 SetBrush( m_brush
);
1841 bool wxGnomePrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
1846 void wxGnomePrinterDCImpl::EndDoc()
1848 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1851 void wxGnomePrinterDCImpl::StartPage()
1853 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1856 void wxGnomePrinterDCImpl::EndPage()
1858 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1861 wxCoord
wxGnomePrinterDCImpl::GetCharHeight() const
1863 pango_layout_set_text( m_layout
, "H", 1 );
1866 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1871 wxCoord
wxGnomePrinterDCImpl::GetCharWidth() const
1873 pango_layout_set_text( m_layout
, "H", 1 );
1876 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1881 void wxGnomePrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1883 wxCoord
*externalLeading
,
1884 const wxFont
*theFont
) const
1892 if ( externalLeading
)
1893 *externalLeading
= 0;
1900 // Set layout's text
1902 const wxScopedCharBuffer
dataUTF8(string
.utf8_str());
1907 // scale the font and apply it
1908 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
1909 oldSize
= pango_font_description_get_size(desc
);
1910 float size
= oldSize
* GetFontPointSizeAdjustment(72.0);
1911 pango_font_description_set_size(desc
, (gint
)size
);
1913 pango_layout_set_font_description(m_layout
, desc
);
1916 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1919 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1925 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1926 int baseline
= pango_layout_iter_get_baseline(iter
);
1927 pango_layout_iter_free(iter
);
1928 *descent
= h
- PANGO_PIXELS(baseline
);
1933 // restore font and reset font's size back
1934 pango_layout_set_font_description(m_layout
, m_fontdesc
);
1936 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
1937 pango_font_description_set_size(desc
, oldSize
);
1941 void wxGnomePrinterDCImpl::DoGetSize(int* width
, int* height
) const
1943 wxGnomePrintNativeData
*native
=
1944 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1946 // Query page size. This seems to omit the margins
1948 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1951 *width
= wxRound( pw
* PS2DEV
);
1954 *height
= wxRound( ph
* PS2DEV
);
1957 void wxGnomePrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
1959 wxGnomePrintNativeData
*native
=
1960 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1962 // This code assumes values in Pts.
1965 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1969 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1970 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1971 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1972 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1975 *width
= (int) (pw
+ 0.5);
1977 *height
= (int) (ph
+ 0.5);
1980 wxSize
wxGnomePrinterDCImpl::GetPPI() const
1982 return wxSize(DPI
,DPI
);
1985 void wxGnomePrinterDCImpl::SetPrintData(const wxPrintData
& data
)
1990 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1991 GetOwner()->GetSize( NULL
, &height
);
1993 GetOwner()->GetSize( &height
, NULL
);
1994 m_deviceLocalOriginY
= height
;
1997 // overridden for wxPrinterDC Impl
1999 int wxGnomePrinterDCImpl::GetResolution() const
2004 wxRect
wxGnomePrinterDCImpl::GetPaperRect() const
2006 // GNOME print doesn't support printer margins
2009 DoGetSize( &w
, &h
);
2010 return wxRect( 0, 0, w
, h
);
2013 // ----------------------------------------------------------------------------
2014 // wxGnomePrintModule
2015 // ----------------------------------------------------------------------------
2017 bool wxGnomePrintModule::OnInit()
2019 gs_libGnomePrint
= new wxGnomePrintLibrary
;
2020 if (gs_libGnomePrint
->IsOk())
2021 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
2025 void wxGnomePrintModule::OnExit()
2027 wxDELETE(gs_libGnomePrint
);
2030 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
2032 // ----------------------------------------------------------------------------
2034 // ----------------------------------------------------------------------------
2036 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
2038 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2039 wxPrintout
* WXUNUSED(printoutForPrinting
))
2044 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2045 wxPrintout
*printoutForPrinting
,
2046 wxPrintDialogData
*data
)
2047 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2049 Init(printout
, printoutForPrinting
);
2052 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2053 wxPrintout
*printoutForPrinting
,
2055 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2057 Init(printout
, printoutForPrinting
);
2060 wxGnomePrintPreview::~wxGnomePrintPreview()
2064 bool wxGnomePrintPreview::Print(bool interactive
)
2066 if (!m_printPrintout
)
2069 wxPrinter
printer(& m_printDialogData
);
2070 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2073 void wxGnomePrintPreview::DetermineScaling()
2075 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2076 if (paperType
== wxPAPER_NONE
)
2077 paperType
= wxPAPER_NONE
;
2079 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2081 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2085 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2087 int resolution
= DPI
;
2088 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2090 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2092 // TODO: get better resolution information from wxGnomePrinterDCImpl, if possible.
2094 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* resolution
/ 72.0);
2095 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* resolution
/ 72.0);
2096 wxSize
sizeTenthsMM(paper
->GetSize());
2097 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2099 // If in landscape mode, we need to swap the width and height.
2100 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2102 m_pageWidth
= sizeDevUnits
.y
;
2103 m_pageHeight
= sizeDevUnits
.x
;
2104 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2108 m_pageWidth
= sizeDevUnits
.x
;
2109 m_pageHeight
= sizeDevUnits
.y
;
2110 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2112 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2113 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2115 // At 100%, the page should look about page-size on the screen.
2116 m_previewScaleX
= (double)0.8 * 72.0 / (double)resolution
;
2117 m_previewScaleY
= m_previewScaleX
;
2122 // wxUSE_LIBGNOMEPRINT