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"
38 #include <libgnomeprint/gnome-print.h>
39 #include <libgnomeprint/gnome-print-pango.h>
40 #include <libgnomeprint/gnome-print-config.h>
41 #include <libgnomeprintui/gnome-print-dialog.h>
42 #include <libgnomeprintui/gnome-print-job-preview.h>
43 #include <libgnomeprintui/gnome-print-paper-selector.h>
46 wxFORCE_LINK_THIS_MODULE(gnome_print
)
48 //----------------------------------------------------------------------------
49 // wxGnomePrintLibrary
50 //----------------------------------------------------------------------------
52 class wxGnomePrintLibrary
55 wxGnomePrintLibrary();
56 ~wxGnomePrintLibrary();
60 bool InitializeMethods();
62 wxDynamicLibrary m_libGnomePrint
;
63 wxDynamicLibrary m_libGnomePrintUI
;
65 // only true if we successfully loaded both libraries
67 // don't rename this field, it's used by wxDL_XXX macros internally
71 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
72 (GnomePrintContext
*pc
), (pc
), 0 )
73 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
74 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
76 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
78 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
80 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
82 (GnomePrintContext
*pc
), (pc
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
84 (GnomePrintContext
*pc
), (pc
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
86 (GnomePrintContext
*pc
), (pc
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
88 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
90 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
91 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
92 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
95 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
97 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
100 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
102 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
104 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
105 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
106 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
109 (GnomePrintContext
*pc
), (pc
), 0 )
110 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
111 (GnomePrintContext
*pc
), (pc
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
116 (GnomePrintContext
*pc
), (pc
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
119 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
122 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
123 (GnomePrintContext
*pc
), (pc
), 0 )
125 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
126 (GnomePrintContext
*gpc
), (gpc
), NULL
)
127 wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout
,
128 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
) )
130 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
131 (GnomePrintConfig
*config
), (config
), NULL
)
132 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
133 (GnomePrintJob
*job
), (job
), NULL
)
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
137 (GnomePrintJob
*job
), (job
), 0 )
138 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
139 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
141 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
142 (const guchar
*abbreviation
), (abbreviation
), NULL
)
143 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
144 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
146 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
149 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
152 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
153 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
154 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
155 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
156 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
157 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
159 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
160 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
161 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
162 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
163 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_boolean
,
164 (GnomePrintConfig
*config
, const guchar
*key
, gboolean
*val
), (config
, key
, val
), false )
166 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
167 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
168 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page
,
169 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
170 const guchar
*currentlabel
, const guchar
*rangelabel
),
171 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
) )
172 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies
,
173 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
) )
174 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies
,
175 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
) )
176 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
177 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
178 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
179 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
181 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
182 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
184 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
185 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
187 wxDECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
);
190 wxGnomePrintLibrary::wxGnomePrintLibrary()
194 m_libGnomePrint
.Load("libgnomeprint-2-2.so.0");
195 m_ok
= m_libGnomePrint
.IsLoaded();
199 m_libGnomePrintUI
.Load("libgnomeprintui-2-2.so.0");
200 m_ok
= m_libGnomePrintUI
.IsLoaded();
203 m_libGnomePrint
.Unload();
207 m_ok
= InitializeMethods();
210 wxGnomePrintLibrary::~wxGnomePrintLibrary()
214 bool wxGnomePrintLibrary::IsOk()
219 bool wxGnomePrintLibrary::InitializeMethods()
221 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_newpath
);
222 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_moveto
);
223 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_lineto
);
224 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_curveto
);
225 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_arcto
);
226 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_closepath
);
227 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_stroke
);
228 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_fill
);
229 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setrgbcolor
);
230 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setlinewidth
);
231 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setdash
);
233 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbimage
);
234 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbaimage
);
236 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_concat
);
237 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_scale
);
238 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rotate
);
239 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_translate
);
241 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_gsave
);
242 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_grestore
);
244 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_clip
);
245 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_eoclip
);
247 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_beginpage
);
248 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_showpage
);
249 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_end_doc
);
251 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_create_layout
);
252 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_layout
);
254 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_new
);
255 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_context
);
256 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_close
);
257 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_print
);
258 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_page_size
);
260 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_unit_get_by_abbreviation
);
261 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_convert_distance
);
263 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_default
);
264 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set
);
265 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_boolean
);
266 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_double
);
267 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_int
);
268 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_length
);
270 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get
);
271 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_length
);
272 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_boolean
);
274 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_new
);
275 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_construct_range_page
);
276 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_copies
);
277 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_set_copies
);
278 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range
);
279 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range_page
);
281 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_paper_selector_new_with_flags
);
283 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_job_preview_new
);
288 static wxGnomePrintLibrary
* gs_libGnomePrint
= NULL
;
290 //----------------------------------------------------------------------------
291 // wxGnomePrintNativeData
292 //----------------------------------------------------------------------------
294 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
296 wxGnomePrintNativeData::wxGnomePrintNativeData()
298 m_config
= gs_libGnomePrint
->gnome_print_config_default();
299 m_job
= gs_libGnomePrint
->gnome_print_job_new( m_config
);
302 wxGnomePrintNativeData::~wxGnomePrintNativeData()
304 g_object_unref (m_config
);
307 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
309 guchar
*res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
310 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
);
311 if (g_ascii_strcasecmp((const gchar
*)res
,"R90") == 0)
312 data
.SetOrientation( wxLANDSCAPE
);
314 data
.SetOrientation( wxPORTRAIT
);
317 res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
318 (guchar
*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME
);
321 data
.SetFilename( wxConvFile
.cMB2WX( (const char*) res
) );
322 wxPrintf( "filename %s\n", data
.GetFilename() );
327 data
.SetFilename( wxEmptyString
);
331 if (gs_libGnomePrint
->gnome_print_config_get_boolean( m_config
,
332 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
, &ret
))
334 data
.SetCollate( ret
);
342 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
344 if (data
.GetOrientation() == wxLANDSCAPE
)
346 gs_libGnomePrint
->gnome_print_config_set( m_config
,
347 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
348 (guchar
*)(char*)"R90" );
352 gs_libGnomePrint
->gnome_print_config_set( m_config
,
353 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
354 (guchar
*)(char*)"R0" );
357 if (data
.GetCollate())
359 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
360 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
365 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
366 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
370 switch (data
.GetPaperId())
372 case wxPAPER_A3
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
373 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
374 (guchar
*)(char*)"A3" );
376 case wxPAPER_A5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
377 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
378 (guchar
*)(char*)"A5" );
380 case wxPAPER_B4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
381 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
382 (guchar
*)(char*)"B4" );
384 case wxPAPER_B5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
385 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
386 (guchar
*)(char*)"B5" );
388 case wxPAPER_LETTER
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
389 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
390 (guchar
*)(char*)"USLetter" );
392 case wxPAPER_LEGAL
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
393 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
394 (guchar
*)(char*)"USLegal" );
396 case wxPAPER_EXECUTIVE
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
397 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
398 (guchar
*)(char*)"Executive" );
400 case wxPAPER_ENV_C5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
401 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
402 (guchar
*)(char*)"C5" );
404 case wxPAPER_ENV_C6
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
405 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
406 (guchar
*)(char*)"C6" );
408 case wxPAPER_NONE
: break;
411 case wxPAPER_A4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
412 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
413 (guchar
*)(char*)"A4" );
420 //----------------------------------------------------------------------------
421 // wxGnomePrintFactory
422 //----------------------------------------------------------------------------
424 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
426 return new wxGnomePrinter( data
);
429 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
430 wxPrintout
*printout
,
431 wxPrintDialogData
*data
)
433 return new wxGnomePrintPreview( preview
, printout
, data
);
436 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
437 wxPrintout
*printout
,
440 return new wxGnomePrintPreview( preview
, printout
, data
);
443 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
444 wxPrintDialogData
*data
)
446 return new wxGnomePrintDialog( parent
, data
);
449 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
452 return new wxGnomePrintDialog( parent
, data
);
455 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
456 wxPageSetupDialogData
* data
)
458 // The native page setup dialog is broken. It
459 // miscalculates newly entered values for the
460 // margins if you have not chose "points" but
461 // e.g. centimerters.
462 // This has been fixed in GNOME CVS (maybe
463 // fixed in libgnomeprintui 2.8.1)
465 return new wxGnomePageSetupDialog( parent
, data
);
468 bool wxGnomePrintFactory::HasPrintSetupDialog()
474 wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
475 wxPrintData
* WXUNUSED(data
))
483 wxDCImpl
* wxGnomePrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
485 return new wxGnomePrinterDCImpl( owner
, data
);
490 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
492 return new wxGnomePrinterDC(data
);
497 bool wxGnomePrintFactory::HasOwnPrintToFile()
502 bool wxGnomePrintFactory::HasPrinterLine()
507 wxString
wxGnomePrintFactory::CreatePrinterLine()
510 return wxEmptyString
;
513 bool wxGnomePrintFactory::HasStatusLine()
519 wxString
wxGnomePrintFactory::CreateStatusLine()
522 return wxEmptyString
;
525 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
527 return new wxGnomePrintNativeData
;
530 //----------------------------------------------------------------------------
531 // wxGnomePrintSetupDialog
532 //----------------------------------------------------------------------------
534 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
536 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
537 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
538 wxPoint(0, 0), wxSize(600, 600),
539 wxDEFAULT_DIALOG_STYLE
|
543 m_printDialogData
= *data
;
548 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
549 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
550 wxPoint(0, 0), wxSize(600, 600),
551 wxDEFAULT_DIALOG_STYLE
|
555 m_printDialogData
= *data
;
560 void wxGnomePrintDialog::Init()
562 wxPrintData data
= m_printDialogData
.GetPrintData();
564 data
.ConvertToNative();
566 wxGnomePrintNativeData
*native
=
567 (wxGnomePrintNativeData
*) data
.GetNativeData();
569 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
571 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
574 if (m_printDialogData
.GetEnableSelection())
575 flag
|= GNOME_PRINT_RANGE_SELECTION
;
576 if (m_printDialogData
.GetEnablePageNumbers())
577 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
579 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
581 m_printDialogData
.GetMinPage(),
582 m_printDialogData
.GetMaxPage(),
587 wxGnomePrintDialog::~wxGnomePrintDialog()
592 int wxGnomePrintDialog::ShowModal()
594 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
596 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
598 gtk_widget_destroy(m_widget
);
604 m_printDialogData
.GetPrintData().ConvertFromNative();
607 gboolean collate
= false;
608 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
609 m_printDialogData
.SetNoCopies( copies
);
610 m_printDialogData
.SetCollate( collate
);
612 switch (gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
614 case GNOME_PRINT_RANGE_SELECTION
:
615 m_printDialogData
.SetSelection( true );
617 case GNOME_PRINT_RANGE_ALL
:
618 m_printDialogData
.SetAllPages( true );
619 m_printDialogData
.SetFromPage( 0 );
620 m_printDialogData
.SetToPage( 9999 );
622 case GNOME_PRINT_RANGE_RANGE
:
625 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
626 m_printDialogData
.SetFromPage( start
);
627 m_printDialogData
.SetToPage( end
);
631 gtk_widget_destroy(m_widget
);
634 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
640 wxDC
*wxGnomePrintDialog::GetPrintDC()
646 bool wxGnomePrintDialog::Validate()
651 bool wxGnomePrintDialog::TransferDataToWindow()
656 bool wxGnomePrintDialog::TransferDataFromWindow()
661 //----------------------------------------------------------------------------
662 // wxGnomePageSetupDialog
663 //----------------------------------------------------------------------------
665 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
667 wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow
* WXUNUSED(parent
),
668 wxPageSetupDialogData
*data
)
671 m_pageDialogData
= *data
;
673 m_pageDialogData
.GetPrintData().ConvertToNative();
675 wxGnomePrintNativeData
*native
=
676 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
678 // This *was* required as the page setup dialog
679 // calculates wrong values otherwise.
681 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
682 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
683 (const guchar
*) "Pts" );
686 GnomePrintConfig
*config
= native
->GetPrintConfig();
688 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
690 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
691 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
692 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
693 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
695 gs_libGnomePrint
->gnome_print_config_set_length (config
,
696 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
697 gs_libGnomePrint
->gnome_print_config_set_length (config
,
698 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
699 gs_libGnomePrint
->gnome_print_config_set_length (config
,
700 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
701 gs_libGnomePrint
->gnome_print_config_set_length (config
,
702 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
704 m_widget
= gtk_dialog_new();
706 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
708 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
709 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
710 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
711 gtk_widget_show (main
);
713 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
715 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
717 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
718 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
719 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
722 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
726 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
730 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
732 return m_pageDialogData
;
735 int wxGnomePageSetupDialog::ShowModal()
737 wxGnomePrintNativeData
*native
=
738 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
740 GnomePrintConfig
*config
= native
->GetPrintConfig();
743 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
745 if (ret
== GTK_RESPONSE_OK
)
747 // Transfer data back to m_pageDialogData
748 m_pageDialogData
.GetPrintData().ConvertFromNative();
750 // I don't know how querying the last parameter works
751 double ml
,mr
,mt
,mb
,pw
,ph
;
752 gs_libGnomePrint
->gnome_print_config_get_length (config
,
753 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
754 gs_libGnomePrint
->gnome_print_config_get_length (config
,
755 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
756 gs_libGnomePrint
->gnome_print_config_get_length (config
,
757 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
758 gs_libGnomePrint
->gnome_print_config_get_length (config
,
759 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
760 gs_libGnomePrint
->gnome_print_config_get_length (config
,
761 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
762 gs_libGnomePrint
->gnome_print_config_get_length (config
,
763 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
765 // This code converts correctly from what the user chose
766 // as the unit although I query Pts here
767 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
768 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
769 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
770 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
771 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
772 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
773 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
774 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
776 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
777 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
779 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
788 gtk_widget_destroy( m_widget
);
794 bool wxGnomePageSetupDialog::Validate()
799 bool wxGnomePageSetupDialog::TransferDataToWindow()
804 bool wxGnomePageSetupDialog::TransferDataFromWindow()
809 //----------------------------------------------------------------------------
811 //----------------------------------------------------------------------------
813 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
815 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
816 wxPrinterBase( data
)
818 m_native_preview
= false;
821 wxGnomePrinter::~wxGnomePrinter()
825 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
829 sm_lastError
= wxPRINTER_ERROR
;
833 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
835 wxGnomePrintNativeData
*native
=
836 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
838 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
840 // The GnomePrintJob is temporarily stored in the
841 // native print data as the native print dialog
842 // needs to access it.
843 native
->SetPrintJob( job
);
846 if (m_printDialogData
.GetMinPage() < 1)
847 m_printDialogData
.SetMinPage(1);
848 if (m_printDialogData
.GetMaxPage() < 1)
849 m_printDialogData
.SetMaxPage(9999);
853 dc
= PrintDialog( parent
);
856 dc
= new wxPrinterDC( printdata
); // TODO: check that this works
858 dc
= new wxGnomePrinterDC( printdata
); // TODO: check that this works
863 gs_libGnomePrint
->gnome_print_job_close( job
);
864 g_object_unref (job
);
865 if (sm_lastError
!= wxPRINTER_CANCELLED
)
866 sm_lastError
= wxPRINTER_ERROR
;
870 printout
->SetPPIScreen(wxGetDisplayPPI());
871 printout
->SetPPIPrinter( dc
->GetResolution(),
872 dc
->GetResolution() );
878 printout
->SetPageSizePixels((int)w
, (int)h
);
879 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
881 dc
->GetSizeMM(&mw
, &mh
);
882 printout
->SetPageSizeMM((int)mw
, (int)mh
);
883 printout
->OnPreparePrinting();
885 // Get some parameters from the printout, if defined
886 int fromPage
, toPage
;
887 int minPage
, maxPage
;
888 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
892 gs_libGnomePrint
->gnome_print_job_close( job
);
893 g_object_unref (job
);
894 sm_lastError
= wxPRINTER_ERROR
;
898 printout
->OnBeginPrinting();
900 int minPageNum
= minPage
, maxPageNum
= maxPage
;
902 if ( !m_printDialogData
.GetAllPages() )
904 minPageNum
= m_printDialogData
.GetFromPage();
905 maxPageNum
= m_printDialogData
.GetToPage();
911 copyCount
<= m_printDialogData
.GetNoCopies();
914 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
916 wxLogError(_("Could not start printing."));
917 sm_lastError
= wxPRINTER_ERROR
;
922 for ( pn
= minPageNum
;
923 pn
<= maxPageNum
&& printout
->HasPage(pn
);
927 printout
->OnPrintPage(pn
);
931 printout
->OnEndDocument();
932 printout
->OnEndPrinting();
935 gs_libGnomePrint
->gnome_print_job_close( job
);
936 if (m_native_preview
)
938 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
939 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
942 (const guchar
*)title
.data()
944 gtk_widget_show(preview
);
948 gs_libGnomePrint
->gnome_print_job_print( job
);
951 g_object_unref (job
);
954 return (sm_lastError
== wxPRINTER_NO_ERROR
);
957 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
959 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
960 int ret
= dialog
.ShowModal();
961 if (ret
== wxID_CANCEL
)
963 sm_lastError
= wxPRINTER_CANCELLED
;
967 m_native_preview
= ret
== wxID_PREVIEW
;
969 m_printDialogData
= dialog
.GetPrintDialogData();
971 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
973 return new wxGnomePrinterDC( m_printDialogData
.GetPrintData() );
977 bool wxGnomePrinter::Setup(wxWindow
* WXUNUSED(parent
))
982 //-----------------------------------------------------------------------------
984 //-----------------------------------------------------------------------------
987 static const double RAD2DEG
= 180.0 / M_PI
;
989 // we don't want to use only 72 dpi from GNOME print
990 static const int DPI
= 600;
991 static const double PS2DEV
= 600.0 / 72.0;
992 static const double DEV2PS
= 72.0 / 600.0;
994 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
995 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
996 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
997 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
1000 IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDCImpl
, wxDCImpl
)
1002 IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDC
, wxDC
)
1006 wxGnomePrinterDCImpl::wxGnomePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
) :
1009 wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData
& data
)
1014 wxGnomePrintNativeData
*native
=
1015 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1017 m_job
= native
->GetPrintJob();
1018 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
1020 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
1021 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1028 // Query page size. This seems to omit the margins
1030 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1032 m_pageHeight
= ph
* PS2DEV
;
1035 wxGnomePrinterDCImpl::~wxGnomePrinterDCImpl()
1039 bool wxGnomePrinterDCImpl::IsOk() const
1045 wxGnomePrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1046 wxCoord
WXUNUSED(y1
),
1047 const wxColour
& WXUNUSED(col
),
1048 wxFloodFillStyle
WXUNUSED(style
))
1054 wxGnomePrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1055 wxCoord
WXUNUSED(y1
),
1056 wxColour
* WXUNUSED(col
)) const
1061 void wxGnomePrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1063 if ( m_pen
.IsTransparent() )
1068 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1069 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1070 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1072 CalcBoundingBox( x1
, y1
);
1073 CalcBoundingBox( x2
, y2
);
1076 void wxGnomePrinterDCImpl::DoCrossHair(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1080 void wxGnomePrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1082 double dx
= x1
- xc
;
1083 double dy
= y1
- yc
;
1084 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1085 double alpha1
, alpha2
;
1086 if (x1
== x2
&& y1
== y2
)
1091 else if ( wxIsNullDouble(radius
) )
1098 alpha1
= (x1
- xc
== 0) ?
1099 (y1
- yc
< 0) ? 90.0 : -90.0 :
1100 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1101 alpha2
= (x2
- xc
== 0) ?
1102 (y2
- yc
< 0) ? 90.0 : -90.0 :
1103 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1105 while (alpha1
<= 0) alpha1
+= 360;
1106 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1107 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1108 while (alpha2
> 360) alpha2
-= 360;
1111 if ( m_brush
.IsNonTransparent() )
1113 SetBrush( m_brush
);
1114 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1115 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1117 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1120 if ( m_pen
.IsNonTransparent() )
1123 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1124 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1125 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1126 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1128 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1131 CalcBoundingBox (x1
, y1
);
1132 CalcBoundingBox (x2
, y2
);
1133 CalcBoundingBox (xc
, yc
);
1136 void wxGnomePrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1141 double xx
= XLOG2DEV(x
);
1142 double yy
= YLOG2DEV(y
);
1144 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1146 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1147 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1148 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1153 if ( m_brush
.IsNonTransparent() )
1155 SetBrush( m_brush
);
1157 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1158 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1159 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1160 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1162 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1165 if ( m_pen
.IsNonTransparent() )
1169 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1170 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1172 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1175 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1177 CalcBoundingBox( x
, y
);
1178 CalcBoundingBox( x
+w
, y
+h
);
1181 void wxGnomePrinterDCImpl::DoDrawPoint(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1185 void wxGnomePrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1189 if ( m_pen
.IsTransparent() )
1195 for ( i
=0; i
<n
; i
++ )
1196 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1198 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1200 for (i
= 1; i
< n
; i
++)
1201 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1203 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1206 void wxGnomePrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[],
1207 wxCoord xoffset
, wxCoord yoffset
,
1208 wxPolygonFillMode
WXUNUSED(fillStyle
))
1212 if ( m_brush
.IsNonTransparent() )
1214 SetBrush( m_brush
);
1216 int x
= points
[0].x
+ xoffset
;
1217 int y
= points
[0].y
+ yoffset
;
1218 CalcBoundingBox( x
, y
);
1219 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1220 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1222 for (i
= 1; i
< n
; i
++)
1224 x
= points
[i
].x
+ xoffset
;
1225 y
= points
[i
].y
+ yoffset
;
1226 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1227 CalcBoundingBox( x
, y
);
1229 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1230 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1233 if ( m_pen
.IsNonTransparent() )
1237 int x
= points
[0].x
+ xoffset
;
1238 int y
= points
[0].y
+ yoffset
;
1239 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1240 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1242 for (i
= 1; i
< n
; i
++)
1244 x
= points
[i
].x
+ xoffset
;
1245 y
= points
[i
].y
+ yoffset
;
1246 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1247 CalcBoundingBox( x
, y
);
1249 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1250 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1254 void wxGnomePrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, wxPolygonFillMode fillStyle
)
1257 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1259 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1263 void wxGnomePrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1268 if ( m_brush
.IsNonTransparent() )
1270 SetBrush( m_brush
);
1272 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1273 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1274 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1275 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1276 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1277 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1278 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1280 CalcBoundingBox( x
, y
);
1281 CalcBoundingBox( x
+ width
, y
+ height
);
1284 if ( m_pen
.IsNonTransparent() )
1288 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1289 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1290 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1291 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1292 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1293 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1294 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1296 CalcBoundingBox( x
, y
);
1297 CalcBoundingBox( x
+ width
, y
+ height
);
1301 void wxGnomePrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1306 wxCoord rad
= wxRound( radius
);
1308 if ( m_brush
.IsNonTransparent() )
1311 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1312 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1313 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1314 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1315 XLOG2DEV(x
),YLOG2DEV(y
),
1316 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1317 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1318 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1319 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1320 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1321 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1322 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1323 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1324 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1325 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1326 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1327 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1328 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1329 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1330 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1331 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1332 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1333 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1334 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1336 CalcBoundingBox(x
,y
);
1337 CalcBoundingBox(x
+width
,y
+height
);
1340 if ( m_pen
.IsNonTransparent() )
1343 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1344 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1345 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1346 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1347 XLOG2DEV(x
),YLOG2DEV(y
),
1348 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1349 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1350 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1351 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1352 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1353 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1354 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1355 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1356 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1357 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1358 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1359 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1360 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1361 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1362 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1363 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1364 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1365 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1366 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1368 CalcBoundingBox(x
,y
);
1369 CalcBoundingBox(x
+width
,y
+height
);
1373 void wxGnomePrinterDCImpl::makeEllipticalPath(wxCoord x
, wxCoord y
,
1374 wxCoord width
, wxCoord height
)
1376 double r
= 4 * (sqrt(2.) - 1) / 3;
1377 double halfW
= 0.5 * width
,
1378 halfH
= 0.5 * height
,
1381 wxCoord halfWI
= (wxCoord
) halfW
,
1382 halfHI
= (wxCoord
) halfH
;
1384 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1386 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1387 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1388 XLOG2DEV(x
+ width
),
1389 YLOG2DEV(y
+ halfHI
) );
1390 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1391 XLOG2DEV(x
+ width
),
1392 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1393 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1394 YLOG2DEV(y
+ height
),
1395 XLOG2DEV(x
+ halfWI
),
1396 YLOG2DEV(y
+ height
) );
1397 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1398 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1399 YLOG2DEV(y
+ height
),
1401 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1402 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1403 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1405 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1406 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1408 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1409 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1410 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1412 XLOG2DEV(x
+ width
),
1413 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1414 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1416 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1419 void wxGnomePrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1424 if ( m_brush
.IsNonTransparent() )
1426 SetBrush( m_brush
);
1427 makeEllipticalPath( x
, y
, width
, height
);
1428 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1429 CalcBoundingBox( x
, y
);
1430 CalcBoundingBox( x
+ width
, y
+ height
);
1433 if ( m_pen
.IsNonTransparent() )
1436 makeEllipticalPath( x
, y
, width
, height
);
1437 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1438 CalcBoundingBox( x
, y
);
1439 CalcBoundingBox( x
+ width
, y
+ height
);
1444 void wxGnomePrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1448 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1451 wxPointList::compatibility_iterator node
= points
->GetFirst();
1452 p
= node
->GetData();
1456 node
= node
->GetNext();
1457 p
= node
->GetData();
1461 (double)(x1
+ c
) / 2;
1463 (double)(y1
+ d
) / 2;
1465 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1466 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1467 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1469 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1470 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1472 node
= node
->GetNext();
1475 q
= node
->GetData();
1483 x3
= (double)(x2
+ c
) / 2;
1484 y3
= (double)(y2
+ d
) / 2;
1486 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1487 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1488 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1489 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1491 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1492 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1494 node
= node
->GetNext();
1497 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1499 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1501 #endif // wxUSE_SPLINES
1504 wxGnomePrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1505 wxCoord width
, wxCoord height
,
1507 wxCoord xsrc
, wxCoord ysrc
,
1508 wxRasterOperationMode rop
,
1509 bool WXUNUSED(useMask
),
1510 wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
))
1512 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1514 // blit into a bitmap
1515 wxBitmap
bitmap( width
, height
);
1517 memDC
.SelectObject(bitmap
);
1518 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1519 memDC
.SelectObject(wxNullBitmap
);
1521 // draw bitmap. scaling and positioning is done there
1522 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
);
1527 void wxGnomePrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1529 DoDrawBitmap( icon
, x
, y
, true );
1533 wxGnomePrinterDCImpl::DoDrawBitmap(const wxBitmap
& bitmap
,
1534 wxCoord x
, wxCoord y
,
1535 bool WXUNUSED(useMask
))
1537 if (!bitmap
.IsOk()) return;
1539 if (bitmap
.HasPixbuf())
1541 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1542 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1543 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1544 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1545 int height
= gdk_pixbuf_get_height( pixbuf
);
1546 int width
= gdk_pixbuf_get_width( pixbuf
);
1548 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1550 matrix
[0] = XLOG2DEVREL(width
);
1553 matrix
[3] = YLOG2DEVREL(height
);
1554 matrix
[4] = XLOG2DEV(x
);
1555 matrix
[5] = YLOG2DEV(y
+height
);
1556 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1557 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1559 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1561 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1562 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1566 wxImage image
= bitmap
.ConvertToImage();
1568 if (!image
.IsOk()) return;
1570 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1572 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1575 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1576 matrix
[4] = XLOG2DEV(x
);
1577 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1578 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1579 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1580 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1581 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1585 void wxGnomePrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1587 DoDrawRotatedText( text
, x
, y
, 0.0 );
1590 void wxGnomePrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1592 double xx
= XLOG2DEV(x
);
1593 double yy
= YLOG2DEV(y
);
1595 bool underlined
= m_font
.IsOk() && m_font
.GetUnderlined();
1597 const wxScopedCharBuffer
data(text
.utf8_str());
1599 size_t datalen
= strlen(data
);
1600 pango_layout_set_text( m_layout
, data
, datalen
);
1604 PangoAttrList
*attrs
= pango_attr_list_new();
1605 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1607 a
->end_index
= datalen
;
1608 pango_attr_list_insert(attrs
, a
);
1609 pango_layout_set_attributes(m_layout
, attrs
);
1610 pango_attr_list_unref(attrs
);
1613 if (m_textForegroundColour
.IsOk())
1615 unsigned char red
= m_textForegroundColour
.Red();
1616 unsigned char blue
= m_textForegroundColour
.Blue();
1617 unsigned char green
= m_textForegroundColour
.Green();
1619 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1621 double redPS
= (double)(red
) / 255.0;
1622 double bluePS
= (double)(blue
) / 255.0;
1623 double greenPS
= (double)(green
) / 255.0;
1625 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1628 m_currentBlue
= blue
;
1629 m_currentGreen
= green
;
1634 if ( m_backgroundMode
== wxSOLID
)
1636 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1637 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1638 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1643 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1645 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1647 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1649 if (fabs(angle
) > 0.00001)
1650 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1652 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1655 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1657 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1661 // undo underline attributes setting:
1662 pango_layout_set_attributes(m_layout
, NULL
);
1665 CalcBoundingBox(x
, y
);
1666 CalcBoundingBox(x
+ w
, y
+ h
);
1669 void wxGnomePrinterDCImpl::Clear()
1673 void wxGnomePrinterDCImpl::SetFont( const wxFont
& font
)
1680 pango_font_description_free( m_fontdesc
);
1682 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1684 float size
= pango_font_description_get_size( m_fontdesc
);
1685 size
= size
* GetFontPointSizeAdjustment(72.0);
1686 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1688 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1692 void wxGnomePrinterDCImpl::SetPen( const wxPen
& pen
)
1694 if (!pen
.IsOk()) return;
1700 if (m_pen
.GetWidth() <= 0)
1703 width
= (double) m_pen
.GetWidth();
1705 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, width
* DEV2PS
* m_scaleX
);
1707 static const double dotted
[] = {2.0, 5.0};
1708 static const double short_dashed
[] = {4.0, 4.0};
1709 static const double wxCoord_dashed
[] = {4.0, 8.0};
1710 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1712 switch (m_pen
.GetStyle())
1714 case wxPENSTYLE_DOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1715 case wxPENSTYLE_SHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1716 case wxPENSTYLE_LONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1717 case wxPENSTYLE_DOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1718 case wxPENSTYLE_USER_DASH
:
1720 // It may be noted that libgnomeprint between at least
1721 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1722 // and then leak the memory since it doesn't set the
1723 // internal flag "privatedash" to 0.
1725 int num
= m_pen
.GetDashes (&wx_dashes
);
1726 gdouble
*g_dashes
= g_new( gdouble
, num
);
1728 for (i
= 0; i
< num
; ++i
)
1729 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1730 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1734 case wxPENSTYLE_SOLID
:
1735 case wxPENSTYLE_TRANSPARENT
:
1736 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1740 unsigned char red
= m_pen
.GetColour().Red();
1741 unsigned char blue
= m_pen
.GetColour().Blue();
1742 unsigned char green
= m_pen
.GetColour().Green();
1744 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1746 double redPS
= (double)(red
) / 255.0;
1747 double bluePS
= (double)(blue
) / 255.0;
1748 double greenPS
= (double)(green
) / 255.0;
1750 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1753 m_currentBlue
= blue
;
1754 m_currentGreen
= green
;
1758 void wxGnomePrinterDCImpl::SetBrush( const wxBrush
& brush
)
1760 if (!brush
.IsOk()) return;
1765 unsigned char red
= m_brush
.GetColour().Red();
1766 unsigned char blue
= m_brush
.GetColour().Blue();
1767 unsigned char green
= m_brush
.GetColour().Green();
1771 // Anything not white is black
1772 if (! (red
== (unsigned char) 255 &&
1773 blue
== (unsigned char) 255 &&
1774 green
== (unsigned char) 255) )
1776 red
= (unsigned char) 0;
1777 green
= (unsigned char) 0;
1778 blue
= (unsigned char) 0;
1783 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1785 double redPS
= (double)(red
) / 255.0;
1786 double bluePS
= (double)(blue
) / 255.0;
1787 double greenPS
= (double)(green
) / 255.0;
1789 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1792 m_currentBlue
= blue
;
1793 m_currentGreen
= green
;
1797 void wxGnomePrinterDCImpl::SetLogicalFunction(wxRasterOperationMode
WXUNUSED(function
))
1801 void wxGnomePrinterDCImpl::SetBackground(const wxBrush
& WXUNUSED(brush
))
1805 void wxGnomePrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1808 m_clipping
= TRUE
; // TODO move somewhere else
1811 m_clipX2
= x
+ width
;
1812 m_clipY2
= y
+ height
;
1814 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1817 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1819 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1820 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1821 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1822 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1823 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1824 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1825 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1828 void wxGnomePrinterDCImpl::DestroyClippingRegion()
1831 wxDCImpl::DestroyClippingRegion();
1833 wxDC::DestroyClippingRegion();
1836 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1839 // not needed, we set the values in each
1840 // drawing method anyways
1842 SetBrush( m_brush
);
1847 bool wxGnomePrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
1852 void wxGnomePrinterDCImpl::EndDoc()
1854 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1857 void wxGnomePrinterDCImpl::StartPage()
1859 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1862 void wxGnomePrinterDCImpl::EndPage()
1864 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1867 wxCoord
wxGnomePrinterDCImpl::GetCharHeight() const
1869 pango_layout_set_text( m_layout
, "H", 1 );
1872 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1877 wxCoord
wxGnomePrinterDCImpl::GetCharWidth() const
1879 pango_layout_set_text( m_layout
, "H", 1 );
1882 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1887 void wxGnomePrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1889 wxCoord
*externalLeading
,
1890 const wxFont
*theFont
) const
1898 if ( externalLeading
)
1899 *externalLeading
= 0;
1906 // Set layout's text
1908 const wxScopedCharBuffer
dataUTF8(string
.utf8_str());
1913 // scale the font and apply it
1914 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
1915 oldSize
= pango_font_description_get_size(desc
);
1916 float size
= oldSize
* GetFontPointSizeAdjustment(72.0);
1917 pango_font_description_set_size(desc
, (gint
)size
);
1919 pango_layout_set_font_description(m_layout
, desc
);
1922 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1925 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1931 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1932 int baseline
= pango_layout_iter_get_baseline(iter
);
1933 pango_layout_iter_free(iter
);
1934 *descent
= h
- PANGO_PIXELS(baseline
);
1939 // restore font and reset font's size back
1940 pango_layout_set_font_description(m_layout
, m_fontdesc
);
1942 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
1943 pango_font_description_set_size(desc
, oldSize
);
1947 void wxGnomePrinterDCImpl::DoGetSize(int* width
, int* height
) const
1949 wxGnomePrintNativeData
*native
=
1950 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1952 // Query page size. This seems to omit the margins
1954 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1957 *width
= wxRound( pw
* PS2DEV
);
1960 *height
= wxRound( ph
* PS2DEV
);
1963 void wxGnomePrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
1965 wxGnomePrintNativeData
*native
=
1966 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1968 // This code assumes values in Pts.
1971 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1975 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1976 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1977 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1978 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1981 *width
= (int) (pw
+ 0.5);
1983 *height
= (int) (ph
+ 0.5);
1986 wxSize
wxGnomePrinterDCImpl::GetPPI() const
1988 return wxSize(DPI
,DPI
);
1991 void wxGnomePrinterDCImpl::SetPrintData(const wxPrintData
& data
)
1996 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1997 GetOwner()->GetSize( NULL
, &height
);
1999 GetOwner()->GetSize( &height
, NULL
);
2000 m_deviceLocalOriginY
= height
;
2003 // overridden for wxPrinterDC Impl
2005 int wxGnomePrinterDCImpl::GetResolution() const
2010 wxRect
wxGnomePrinterDCImpl::GetPaperRect() const
2012 // GNOME print doesn't support printer margins
2015 DoGetSize( &w
, &h
);
2016 return wxRect( 0, 0, w
, h
);
2019 // ----------------------------------------------------------------------------
2020 // wxGnomePrintModule
2021 // ----------------------------------------------------------------------------
2023 bool wxGnomePrintModule::OnInit()
2025 gs_libGnomePrint
= new wxGnomePrintLibrary
;
2026 if (gs_libGnomePrint
->IsOk())
2027 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
2031 void wxGnomePrintModule::OnExit()
2033 wxDELETE(gs_libGnomePrint
);
2036 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
2038 // ----------------------------------------------------------------------------
2040 // ----------------------------------------------------------------------------
2042 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
2044 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2045 wxPrintout
* WXUNUSED(printoutForPrinting
))
2050 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2051 wxPrintout
*printoutForPrinting
,
2052 wxPrintDialogData
*data
)
2053 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2055 Init(printout
, printoutForPrinting
);
2058 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2059 wxPrintout
*printoutForPrinting
,
2061 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2063 Init(printout
, printoutForPrinting
);
2066 wxGnomePrintPreview::~wxGnomePrintPreview()
2070 bool wxGnomePrintPreview::Print(bool interactive
)
2072 if (!m_printPrintout
)
2075 wxPrinter
printer(& m_printDialogData
);
2076 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2079 void wxGnomePrintPreview::DetermineScaling()
2081 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2082 if (paperType
== wxPAPER_NONE
)
2083 paperType
= wxPAPER_NONE
;
2085 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2087 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2091 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2093 int resolution
= DPI
;
2094 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2096 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2098 // TODO: get better resolution information from wxGnomePrinterDCImpl, if possible.
2100 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* resolution
/ 72.0);
2101 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* resolution
/ 72.0);
2102 wxSize
sizeTenthsMM(paper
->GetSize());
2103 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2105 // If in landscape mode, we need to swap the width and height.
2106 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2108 m_pageWidth
= sizeDevUnits
.y
;
2109 m_pageHeight
= sizeDevUnits
.x
;
2110 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2114 m_pageWidth
= sizeDevUnits
.x
;
2115 m_pageHeight
= sizeDevUnits
.y
;
2116 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2118 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2119 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2121 // At 100%, the page should look about page-size on the screen.
2122 m_previewScaleX
= (double)0.8 * 72.0 / (double)resolution
;
2123 m_previewScaleY
= m_previewScaleX
;
2128 // wxUSE_LIBGNOMEPRINT