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"
37 #include <libgnomeprint/gnome-print.h>
38 #include <libgnomeprint/gnome-print-pango.h>
39 #include <libgnomeprint/gnome-print-config.h>
40 #include <libgnomeprintui/gnome-print-dialog.h>
41 #include <libgnomeprintui/gnome-print-job-preview.h>
42 #include <libgnomeprintui/gnome-print-paper-selector.h>
45 wxFORCE_LINK_THIS_MODULE(gnome_print
)
47 //----------------------------------------------------------------------------
48 // wxGnomePrintLibrary
49 //----------------------------------------------------------------------------
51 class wxGnomePrintLibrary
54 wxGnomePrintLibrary();
55 ~wxGnomePrintLibrary();
59 bool InitializeMethods();
61 wxDynamicLibrary m_libGnomePrint
;
62 wxDynamicLibrary m_libGnomePrintUI
;
64 // only true if we successfully loaded both libraries
66 // don't rename this field, it's used by wxDL_XXX macros internally
70 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
71 (GnomePrintContext
*pc
), (pc
), 0 )
72 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
73 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
74 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
75 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
76 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
77 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
79 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
81 (GnomePrintContext
*pc
), (pc
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
83 (GnomePrintContext
*pc
), (pc
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
85 (GnomePrintContext
*pc
), (pc
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
87 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
89 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
91 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
93 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
94 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
95 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
96 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
98 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
99 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
100 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
101 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
102 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
103 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
105 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
107 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
108 (GnomePrintContext
*pc
), (pc
), 0 )
109 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
110 (GnomePrintContext
*pc
), (pc
), 0 )
112 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
113 (GnomePrintContext
*pc
), (pc
), 0 )
114 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
115 (GnomePrintContext
*pc
), (pc
), 0 )
117 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
118 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
119 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
120 (GnomePrintContext
*pc
), (pc
), 0 )
121 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
122 (GnomePrintContext
*pc
), (pc
), 0 )
124 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
125 (GnomePrintContext
*gpc
), (gpc
), NULL
)
126 wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout
,
127 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
) )
129 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
130 (GnomePrintConfig
*config
), (config
), NULL
)
131 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
132 (GnomePrintJob
*job
), (job
), NULL
)
133 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
134 (GnomePrintJob
*job
), (job
), 0 )
135 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
136 (GnomePrintJob
*job
), (job
), 0 )
137 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
138 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
140 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
141 (const guchar
*abbreviation
), (abbreviation
), NULL
)
142 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
143 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
145 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
147 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
148 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
149 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
150 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
151 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
152 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
153 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
154 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
155 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
156 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
158 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
159 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
160 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
161 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
162 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_boolean
,
163 (GnomePrintConfig
*config
, const guchar
*key
, gboolean
*val
), (config
, key
, val
), false )
165 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
166 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
167 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page
,
168 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
169 const guchar
*currentlabel
, const guchar
*rangelabel
),
170 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
) )
171 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies
,
172 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
) )
173 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies
,
174 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
) )
175 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
176 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
177 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
178 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
180 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
181 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
183 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
184 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
186 DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
)
189 wxGnomePrintLibrary::wxGnomePrintLibrary()
193 m_libGnomePrint
.Load("libgnomeprint-2-2.so.0");
194 m_ok
= m_libGnomePrint
.IsLoaded();
198 m_libGnomePrintUI
.Load("libgnomeprintui-2-2.so.0");
199 m_ok
= m_libGnomePrintUI
.IsLoaded();
202 m_libGnomePrint
.Unload();
206 m_ok
= InitializeMethods();
209 wxGnomePrintLibrary::~wxGnomePrintLibrary()
213 bool wxGnomePrintLibrary::IsOk()
218 bool wxGnomePrintLibrary::InitializeMethods()
220 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_newpath
);
221 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_moveto
);
222 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_lineto
);
223 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_curveto
);
224 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_arcto
);
225 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_closepath
);
226 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_stroke
);
227 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_fill
);
228 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setrgbcolor
);
229 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setlinewidth
);
230 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setdash
);
232 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbimage
);
233 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbaimage
);
235 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_concat
);
236 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_scale
);
237 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rotate
);
238 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_translate
);
240 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_gsave
);
241 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_grestore
);
243 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_clip
);
244 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_eoclip
);
246 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_beginpage
);
247 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_showpage
);
248 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_end_doc
);
250 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_create_layout
);
251 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_layout
);
253 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_new
);
254 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_context
);
255 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_close
);
256 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_print
);
257 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_page_size
);
259 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_unit_get_by_abbreviation
);
260 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_convert_distance
);
262 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_default
);
263 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set
);
264 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_boolean
);
265 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_double
);
266 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_int
);
267 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_length
);
269 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get
);
270 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_length
);
271 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_boolean
);
273 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_new
);
274 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_construct_range_page
);
275 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_copies
);
276 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_set_copies
);
277 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range
);
278 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range_page
);
280 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_paper_selector_new_with_flags
);
282 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_job_preview_new
);
287 static wxGnomePrintLibrary
* gs_libGnomePrint
= NULL
;
289 //----------------------------------------------------------------------------
290 // wxGnomePrintNativeData
291 //----------------------------------------------------------------------------
293 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
295 wxGnomePrintNativeData::wxGnomePrintNativeData()
297 m_config
= gs_libGnomePrint
->gnome_print_config_default();
298 m_job
= gs_libGnomePrint
->gnome_print_job_new( m_config
);
301 wxGnomePrintNativeData::~wxGnomePrintNativeData()
303 g_object_unref (m_config
);
306 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
308 guchar
*res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
309 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
);
310 if (g_ascii_strcasecmp((const gchar
*)res
,"R90") == 0)
311 data
.SetOrientation( wxLANDSCAPE
);
313 data
.SetOrientation( wxPORTRAIT
);
316 res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
317 (guchar
*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME
);
320 data
.SetFilename( wxConvFile
.cMB2WX( (const char*) res
) );
321 wxPrintf( "filename %s\n", data
.GetFilename() );
326 data
.SetFilename( wxEmptyString
);
330 if (gs_libGnomePrint
->gnome_print_config_get_boolean( m_config
,
331 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
, &ret
))
333 data
.SetCollate( ret
);
341 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
343 if (data
.GetOrientation() == wxLANDSCAPE
)
345 gs_libGnomePrint
->gnome_print_config_set( m_config
,
346 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
347 (guchar
*)(char*)"R90" );
351 gs_libGnomePrint
->gnome_print_config_set( m_config
,
352 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
353 (guchar
*)(char*)"R0" );
356 if (data
.GetCollate())
358 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
359 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
364 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
365 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
369 switch (data
.GetPaperId())
371 case wxPAPER_A3
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
372 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
373 (guchar
*)(char*)"A3" );
375 case wxPAPER_A5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
376 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
377 (guchar
*)(char*)"A5" );
379 case wxPAPER_B4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
380 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
381 (guchar
*)(char*)"B4" );
383 case wxPAPER_B5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
384 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
385 (guchar
*)(char*)"B5" );
387 case wxPAPER_LETTER
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
388 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
389 (guchar
*)(char*)"USLetter" );
391 case wxPAPER_LEGAL
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
392 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
393 (guchar
*)(char*)"USLegal" );
395 case wxPAPER_EXECUTIVE
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
396 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
397 (guchar
*)(char*)"Executive" );
399 case wxPAPER_ENV_C5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
400 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
401 (guchar
*)(char*)"C5" );
403 case wxPAPER_ENV_C6
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
404 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
405 (guchar
*)(char*)"C6" );
407 case wxPAPER_NONE
: break;
410 case wxPAPER_A4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
411 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
412 (guchar
*)(char*)"A4" );
419 //----------------------------------------------------------------------------
420 // wxGnomePrintFactory
421 //----------------------------------------------------------------------------
423 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
425 return new wxGnomePrinter( data
);
428 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
429 wxPrintout
*printout
,
430 wxPrintDialogData
*data
)
432 return new wxGnomePrintPreview( preview
, printout
, data
);
435 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
436 wxPrintout
*printout
,
439 return new wxGnomePrintPreview( preview
, printout
, data
);
442 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
443 wxPrintDialogData
*data
)
445 return new wxGnomePrintDialog( parent
, data
);
448 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
451 return new wxGnomePrintDialog( parent
, data
);
454 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
455 wxPageSetupDialogData
* data
)
457 // The native page setup dialog is broken. It
458 // miscalculates newly entered values for the
459 // margins if you have not chose "points" but
460 // e.g. centimerters.
461 // This has been fixed in GNOME CVS (maybe
462 // fixed in libgnomeprintui 2.8.1)
464 return new wxGnomePageSetupDialog( parent
, data
);
467 bool wxGnomePrintFactory::HasPrintSetupDialog()
473 wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
474 wxPrintData
* WXUNUSED(data
))
479 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
481 return new wxGnomePrinterDC(data
);
484 bool wxGnomePrintFactory::HasOwnPrintToFile()
489 bool wxGnomePrintFactory::HasPrinterLine()
494 wxString
wxGnomePrintFactory::CreatePrinterLine()
497 return wxEmptyString
;
500 bool wxGnomePrintFactory::HasStatusLine()
506 wxString
wxGnomePrintFactory::CreateStatusLine()
509 return wxEmptyString
;
512 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
514 return new wxGnomePrintNativeData
;
517 //----------------------------------------------------------------------------
518 // wxGnomePrintSetupDialog
519 //----------------------------------------------------------------------------
521 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
523 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
524 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
525 wxPoint(0, 0), wxSize(600, 600),
526 wxDEFAULT_DIALOG_STYLE
|
530 m_printDialogData
= *data
;
535 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
536 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
537 wxPoint(0, 0), wxSize(600, 600),
538 wxDEFAULT_DIALOG_STYLE
|
542 m_printDialogData
= *data
;
547 void wxGnomePrintDialog::Init()
549 wxPrintData data
= m_printDialogData
.GetPrintData();
551 data
.ConvertToNative();
553 wxGnomePrintNativeData
*native
=
554 (wxGnomePrintNativeData
*) data
.GetNativeData();
556 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
558 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
561 if (m_printDialogData
.GetEnableSelection())
562 flag
|= GNOME_PRINT_RANGE_SELECTION
;
563 if (m_printDialogData
.GetEnablePageNumbers())
564 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
566 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
568 m_printDialogData
.GetMinPage(),
569 m_printDialogData
.GetMaxPage(),
574 wxGnomePrintDialog::~wxGnomePrintDialog()
579 int wxGnomePrintDialog::ShowModal()
581 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
583 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
585 gtk_widget_destroy(m_widget
);
591 m_printDialogData
.GetPrintData().ConvertFromNative();
594 gboolean collate
= false;
595 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
596 m_printDialogData
.SetNoCopies( copies
);
597 m_printDialogData
.SetCollate( collate
);
599 switch (gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
601 case GNOME_PRINT_RANGE_SELECTION
:
602 m_printDialogData
.SetSelection( true );
604 case GNOME_PRINT_RANGE_ALL
:
605 m_printDialogData
.SetAllPages( true );
606 m_printDialogData
.SetFromPage( 0 );
607 m_printDialogData
.SetToPage( 9999 );
609 case GNOME_PRINT_RANGE_RANGE
:
612 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
613 m_printDialogData
.SetFromPage( start
);
614 m_printDialogData
.SetToPage( end
);
618 gtk_widget_destroy(m_widget
);
621 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
627 wxDC
*wxGnomePrintDialog::GetPrintDC()
633 bool wxGnomePrintDialog::Validate()
638 bool wxGnomePrintDialog::TransferDataToWindow()
643 bool wxGnomePrintDialog::TransferDataFromWindow()
648 //----------------------------------------------------------------------------
649 // wxGnomePageSetupDialog
650 //----------------------------------------------------------------------------
652 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
654 wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow
* WXUNUSED(parent
),
655 wxPageSetupDialogData
*data
)
658 m_pageDialogData
= *data
;
660 m_pageDialogData
.GetPrintData().ConvertToNative();
662 wxGnomePrintNativeData
*native
=
663 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
665 // This *was* required as the page setup dialog
666 // calculates wrong values otherwise.
668 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
669 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
670 (const guchar
*) "Pts" );
673 GnomePrintConfig
*config
= native
->GetPrintConfig();
675 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
677 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
678 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
679 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
680 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
682 gs_libGnomePrint
->gnome_print_config_set_length (config
,
683 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
684 gs_libGnomePrint
->gnome_print_config_set_length (config
,
685 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
686 gs_libGnomePrint
->gnome_print_config_set_length (config
,
687 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
688 gs_libGnomePrint
->gnome_print_config_set_length (config
,
689 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
691 m_widget
= gtk_dialog_new();
693 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
695 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
696 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
697 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
698 gtk_widget_show (main
);
700 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
702 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
704 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
705 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
706 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
709 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
713 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
717 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
719 return m_pageDialogData
;
722 int wxGnomePageSetupDialog::ShowModal()
724 wxGnomePrintNativeData
*native
=
725 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
727 GnomePrintConfig
*config
= native
->GetPrintConfig();
730 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
732 if (ret
== GTK_RESPONSE_OK
)
734 // Transfer data back to m_pageDialogData
735 m_pageDialogData
.GetPrintData().ConvertFromNative();
737 // I don't know how querying the last parameter works
738 double ml
,mr
,mt
,mb
,pw
,ph
;
739 gs_libGnomePrint
->gnome_print_config_get_length (config
,
740 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
741 gs_libGnomePrint
->gnome_print_config_get_length (config
,
742 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
743 gs_libGnomePrint
->gnome_print_config_get_length (config
,
744 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
745 gs_libGnomePrint
->gnome_print_config_get_length (config
,
746 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
747 gs_libGnomePrint
->gnome_print_config_get_length (config
,
748 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
749 gs_libGnomePrint
->gnome_print_config_get_length (config
,
750 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
752 // This code converts correctly from what the user chose
753 // as the unit although I query Pts here
754 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
755 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
756 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
757 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
758 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
759 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
760 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
761 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
763 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
764 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
766 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
775 gtk_widget_destroy( m_widget
);
781 bool wxGnomePageSetupDialog::Validate()
786 bool wxGnomePageSetupDialog::TransferDataToWindow()
791 bool wxGnomePageSetupDialog::TransferDataFromWindow()
796 //----------------------------------------------------------------------------
798 //----------------------------------------------------------------------------
800 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
802 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
803 wxPrinterBase( data
)
805 m_native_preview
= false;
808 wxGnomePrinter::~wxGnomePrinter()
812 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
816 sm_lastError
= wxPRINTER_ERROR
;
820 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
822 wxGnomePrintNativeData
*native
=
823 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
825 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
827 // The GnomePrintJob is temporarily stored in the
828 // native print data as the native print dialog
829 // needs to access it.
830 native
->SetPrintJob( job
);
833 printout
->SetIsPreview(false);
835 if (m_printDialogData
.GetMinPage() < 1)
836 m_printDialogData
.SetMinPage(1);
837 if (m_printDialogData
.GetMaxPage() < 1)
838 m_printDialogData
.SetMaxPage(9999);
842 dc
= PrintDialog( parent
);
844 dc
= new wxGnomePrinterDC( printdata
);
846 if (m_native_preview
)
847 printout
->SetIsPreview(true);
851 gs_libGnomePrint
->gnome_print_job_close( job
);
852 g_object_unref (job
);
853 if (sm_lastError
!= wxPRINTER_CANCELLED
)
854 sm_lastError
= wxPRINTER_ERROR
;
858 wxSize ScreenPixels
= wxGetDisplaySize();
859 wxSize ScreenMM
= wxGetDisplaySizeMM();
861 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
862 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
863 printout
->SetPPIPrinter( wxGnomePrinterDC::GetResolution(),
864 wxGnomePrinterDC::GetResolution() );
870 printout
->SetPageSizePixels((int)w
, (int)h
);
871 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
873 dc
->GetSizeMM(&mw
, &mh
);
874 printout
->SetPageSizeMM((int)mw
, (int)mh
);
875 printout
->OnPreparePrinting();
877 // Get some parameters from the printout, if defined
878 int fromPage
, toPage
;
879 int minPage
, maxPage
;
880 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
884 gs_libGnomePrint
->gnome_print_job_close( job
);
885 g_object_unref (job
);
886 sm_lastError
= wxPRINTER_ERROR
;
890 printout
->OnBeginPrinting();
892 int minPageNum
= minPage
, maxPageNum
= maxPage
;
894 if ( !m_printDialogData
.GetAllPages() )
896 minPageNum
= m_printDialogData
.GetFromPage();
897 maxPageNum
= m_printDialogData
.GetToPage();
903 copyCount
<= m_printDialogData
.GetNoCopies();
906 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
908 wxLogError(_("Could not start printing."));
909 sm_lastError
= wxPRINTER_ERROR
;
914 for ( pn
= minPageNum
;
915 pn
<= maxPageNum
&& printout
->HasPage(pn
);
919 printout
->OnPrintPage(pn
);
923 printout
->OnEndDocument();
924 printout
->OnEndPrinting();
927 gs_libGnomePrint
->gnome_print_job_close( job
);
928 if (m_native_preview
)
930 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
931 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
934 (const guchar
*)title
.data()
936 gtk_widget_show(preview
);
940 gs_libGnomePrint
->gnome_print_job_print( job
);
943 g_object_unref (job
);
946 return (sm_lastError
== wxPRINTER_NO_ERROR
);
949 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
951 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
952 int ret
= dialog
.ShowModal();
953 if (ret
== wxID_CANCEL
)
955 sm_lastError
= wxPRINTER_CANCELLED
;
959 m_native_preview
= ret
== wxID_PREVIEW
;
961 m_printDialogData
= dialog
.GetPrintDialogData();
962 return new wxGnomePrinterDC( m_printDialogData
.GetPrintData() );
965 bool wxGnomePrinter::Setup(wxWindow
* WXUNUSED(parent
))
970 //-----------------------------------------------------------------------------
972 //-----------------------------------------------------------------------------
975 static const double RAD2DEG
= 180.0 / M_PI
;
977 // we don't want to use only 72 dpi from GNOME print
978 static const int DPI
= 600;
979 static const double PS2DEV
= 600.0 / 72.0;
980 static const double DEV2PS
= 72.0 / 600.0;
982 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
983 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
984 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
985 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
987 IMPLEMENT_CLASS(wxGnomePrinterDC
, wxDC
)
989 wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData
& data
)
993 wxGnomePrintNativeData
*native
=
994 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
996 m_job
= native
->GetPrintJob();
997 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
999 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
1000 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1007 // Query page size. This seems to omit the margins
1009 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1011 m_pageHeight
= ph
* PS2DEV
;
1014 wxGnomePrinterDC::~wxGnomePrinterDC()
1018 bool wxGnomePrinterDC::IsOk() const
1024 wxGnomePrinterDC::DoFloodFill(wxCoord
WXUNUSED(x1
),
1025 wxCoord
WXUNUSED(y1
),
1026 const wxColour
& WXUNUSED(col
),
1027 int WXUNUSED(style
))
1033 wxGnomePrinterDC::DoGetPixel(wxCoord
WXUNUSED(x1
),
1034 wxCoord
WXUNUSED(y1
),
1035 wxColour
* WXUNUSED(col
)) const
1040 void wxGnomePrinterDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1042 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1046 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1047 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1048 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1050 CalcBoundingBox( x1
, y1
);
1051 CalcBoundingBox( x2
, y2
);
1054 void wxGnomePrinterDC::DoCrossHair(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1058 void wxGnomePrinterDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1060 double dx
= x1
- xc
;
1061 double dy
= y1
- yc
;
1062 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1063 double alpha1
, alpha2
;
1064 if (x1
== x2
&& y1
== y2
)
1069 else if ( wxIsNullDouble(radius
) )
1076 alpha1
= (x1
- xc
== 0) ?
1077 (y1
- yc
< 0) ? 90.0 : -90.0 :
1078 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1079 alpha2
= (x2
- xc
== 0) ?
1080 (y2
- yc
< 0) ? 90.0 : -90.0 :
1081 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1083 while (alpha1
<= 0) alpha1
+= 360;
1084 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1085 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1086 while (alpha2
> 360) alpha2
-= 360;
1089 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1091 SetBrush( m_brush
);
1092 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1093 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1095 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1098 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1101 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1102 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1103 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1104 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1106 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1109 CalcBoundingBox (x1
, y1
);
1110 CalcBoundingBox (x2
, y2
);
1111 CalcBoundingBox (xc
, yc
);
1114 void wxGnomePrinterDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1119 double xx
= XLOG2DEV(x
);
1120 double yy
= YLOG2DEV(y
);
1122 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1124 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1125 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1126 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1131 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1133 SetBrush( m_brush
);
1135 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1136 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1137 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1138 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1140 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1143 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1147 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1148 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1150 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1153 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1155 CalcBoundingBox( x
, y
);
1156 CalcBoundingBox( x
+w
, y
+h
);
1159 void wxGnomePrinterDC::DoDrawPoint(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1163 void wxGnomePrinterDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1165 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1172 for ( i
=0; i
<n
; i
++ )
1173 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1175 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1177 for (i
= 1; i
< n
; i
++)
1178 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1180 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1183 void wxGnomePrinterDC::DoDrawPolygon(int n
, wxPoint points
[],
1184 wxCoord xoffset
, wxCoord yoffset
,
1185 int WXUNUSED(fillStyle
))
1189 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1191 SetBrush( m_brush
);
1193 int x
= points
[0].x
+ xoffset
;
1194 int y
= points
[0].y
+ yoffset
;
1195 CalcBoundingBox( x
, y
);
1196 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1197 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1199 for (i
= 1; i
< n
; i
++)
1201 x
= points
[i
].x
+ xoffset
;
1202 y
= points
[i
].y
+ yoffset
;
1203 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1204 CalcBoundingBox( x
, y
);
1206 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1207 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1210 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1214 int x
= points
[0].x
+ xoffset
;
1215 int y
= points
[0].y
+ yoffset
;
1216 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1217 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1219 for (i
= 1; i
< n
; i
++)
1221 x
= points
[i
].x
+ xoffset
;
1222 y
= points
[i
].y
+ yoffset
;
1223 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1224 CalcBoundingBox( x
, y
);
1226 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1227 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1231 void wxGnomePrinterDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1233 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1236 void wxGnomePrinterDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1241 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1243 SetBrush( m_brush
);
1245 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1246 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1247 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1248 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1249 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1250 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1251 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1253 CalcBoundingBox( x
, y
);
1254 CalcBoundingBox( x
+ width
, y
+ height
);
1257 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1261 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1262 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1263 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1264 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1265 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1266 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1267 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1269 CalcBoundingBox( x
, y
);
1270 CalcBoundingBox( x
+ width
, y
+ height
);
1274 void wxGnomePrinterDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1279 wxCoord rad
= wxRound( radius
);
1281 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1284 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1285 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1286 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1287 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1288 XLOG2DEV(x
),YLOG2DEV(y
),
1289 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1290 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1291 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1292 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1293 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1294 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1295 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1296 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1297 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1298 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1299 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1300 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1301 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1302 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1303 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1304 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1305 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1306 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1307 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1309 CalcBoundingBox(x
,y
);
1310 CalcBoundingBox(x
+width
,y
+height
);
1313 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1316 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1317 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1318 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1319 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1320 XLOG2DEV(x
),YLOG2DEV(y
),
1321 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1322 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1323 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1324 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1325 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1326 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1327 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1328 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1329 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1330 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1331 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1332 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1333 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1334 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1335 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1336 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1337 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1338 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1339 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1341 CalcBoundingBox(x
,y
);
1342 CalcBoundingBox(x
+width
,y
+height
);
1346 void wxGnomePrinterDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1347 wxCoord width
, wxCoord height
)
1349 double r
= 4 * (sqrt(2.) - 1) / 3;
1350 double halfW
= 0.5 * width
,
1351 halfH
= 0.5 * height
,
1354 wxCoord halfWI
= (wxCoord
) halfW
,
1355 halfHI
= (wxCoord
) halfH
;
1357 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1359 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1360 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1361 XLOG2DEV(x
+ width
),
1362 YLOG2DEV(y
+ halfHI
) );
1363 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1364 XLOG2DEV(x
+ width
),
1365 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1366 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1367 YLOG2DEV(y
+ height
),
1368 XLOG2DEV(x
+ halfWI
),
1369 YLOG2DEV(y
+ height
) );
1370 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1371 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1372 YLOG2DEV(y
+ height
),
1374 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1375 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1376 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1378 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1379 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1381 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1382 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1383 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1385 XLOG2DEV(x
+ width
),
1386 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1387 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1389 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1392 void wxGnomePrinterDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1397 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1399 SetBrush( m_brush
);
1400 makeEllipticalPath( x
, y
, width
, height
);
1401 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1402 CalcBoundingBox( x
, y
);
1403 CalcBoundingBox( x
+ width
, y
+ height
);
1406 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1409 makeEllipticalPath( x
, y
, width
, height
);
1410 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1411 CalcBoundingBox( x
, y
);
1412 CalcBoundingBox( x
+ width
, y
+ height
);
1417 void wxGnomePrinterDC::DoDrawSpline(const wxPointList
*points
)
1421 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1424 wxPointList::compatibility_iterator node
= points
->GetFirst();
1425 p
= node
->GetData();
1429 node
= node
->GetNext();
1430 p
= node
->GetData();
1434 (double)(x1
+ c
) / 2;
1436 (double)(y1
+ d
) / 2;
1438 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1439 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1440 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1442 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1443 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1445 node
= node
->GetNext();
1448 q
= node
->GetData();
1456 x3
= (double)(x2
+ c
) / 2;
1457 y3
= (double)(y2
+ d
) / 2;
1459 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1460 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1461 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1462 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1464 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1465 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1467 node
= node
->GetNext();
1470 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1472 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1474 #endif // wxUSE_SPLINES
1477 wxGnomePrinterDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1478 wxCoord width
, wxCoord height
,
1480 wxCoord xsrc
, wxCoord ysrc
,
1482 bool WXUNUSED(useMask
),
1483 wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
))
1485 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1487 // blit into a bitmap
1488 wxBitmap
bitmap( width
, height
);
1490 memDC
.SelectObject(bitmap
);
1491 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1492 memDC
.SelectObject(wxNullBitmap
);
1494 // draw bitmap. scaling and positioning is done there
1495 DrawBitmap( bitmap
, xdest
, ydest
);
1500 void wxGnomePrinterDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1502 DoDrawBitmap( icon
, x
, y
, true );
1506 wxGnomePrinterDC::DoDrawBitmap(const wxBitmap
& bitmap
,
1507 wxCoord x
, wxCoord y
,
1508 bool WXUNUSED(useMask
))
1510 if (!bitmap
.Ok()) return;
1512 if (bitmap
.HasPixbuf())
1514 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1515 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1516 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1517 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1518 int height
= gdk_pixbuf_get_height( pixbuf
);
1519 int width
= gdk_pixbuf_get_width( pixbuf
);
1521 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1523 matrix
[0] = XLOG2DEVREL(width
);
1526 matrix
[3] = YLOG2DEVREL(height
);
1527 matrix
[4] = XLOG2DEV(x
);
1528 matrix
[5] = YLOG2DEV(y
+height
);
1529 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1530 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1532 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1534 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1535 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1539 wxImage image
= bitmap
.ConvertToImage();
1541 if (!image
.Ok()) return;
1543 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1545 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1548 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1549 matrix
[4] = XLOG2DEV(x
);
1550 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1551 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1552 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1553 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1554 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1558 void wxGnomePrinterDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1560 DoDrawRotatedText( text
, x
, y
, 0.0 );
1563 void wxGnomePrinterDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1565 double xx
= XLOG2DEV(x
);
1566 double yy
= YLOG2DEV(y
);
1568 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1570 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1571 #if wxUSE_UNICODE_UTF8
1572 const char *data
= text
.utf8_str();
1574 const wxCharBuffer data
= text
.utf8_str();
1577 size_t datalen
= strlen(data
);
1578 pango_layout_set_text( m_layout
, data
, datalen
);
1582 PangoAttrList
*attrs
= pango_attr_list_new();
1583 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1585 a
->end_index
= datalen
;
1586 pango_attr_list_insert(attrs
, a
);
1587 pango_layout_set_attributes(m_layout
, attrs
);
1588 pango_attr_list_unref(attrs
);
1591 if (m_textForegroundColour
.Ok())
1593 unsigned char red
= m_textForegroundColour
.Red();
1594 unsigned char blue
= m_textForegroundColour
.Blue();
1595 unsigned char green
= m_textForegroundColour
.Green();
1597 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1599 double redPS
= (double)(red
) / 255.0;
1600 double bluePS
= (double)(blue
) / 255.0;
1601 double greenPS
= (double)(green
) / 255.0;
1603 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1606 m_currentBlue
= blue
;
1607 m_currentGreen
= green
;
1612 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1614 if ( m_backgroundMode
== wxSOLID
)
1616 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1617 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1618 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1623 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1625 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1627 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1629 if (fabs(angle
) > 0.00001)
1630 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1632 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1634 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1638 // undo underline attributes setting:
1639 pango_layout_set_attributes(m_layout
, NULL
);
1642 CalcBoundingBox (x
+ w
, y
+ h
);
1645 void wxGnomePrinterDC::Clear()
1649 void wxGnomePrinterDC::SetFont( const wxFont
& font
)
1656 pango_font_description_free( m_fontdesc
);
1658 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1660 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1664 void wxGnomePrinterDC::SetPen( const wxPen
& pen
)
1666 if (!pen
.Ok()) return;
1672 if (m_pen
.GetWidth() <= 0)
1675 width
= (double) m_pen
.GetWidth();
1677 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, width
* DEV2PS
* m_scaleX
);
1679 static const double dotted
[] = {2.0, 5.0};
1680 static const double short_dashed
[] = {4.0, 4.0};
1681 static const double wxCoord_dashed
[] = {4.0, 8.0};
1682 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1684 switch (m_pen
.GetStyle())
1686 case wxDOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1687 case wxSHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1688 case wxLONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1689 case wxDOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1692 // It may be noted that libgnomeprint between at least
1693 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1694 // and then leak the memory since it doesn't set the
1695 // internal flag "privatedash" to 0.
1697 int num
= m_pen
.GetDashes (&wx_dashes
);
1698 gdouble
*g_dashes
= g_new( gdouble
, num
);
1700 for (i
= 0; i
< num
; ++i
)
1701 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1702 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1708 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1712 unsigned char red
= m_pen
.GetColour().Red();
1713 unsigned char blue
= m_pen
.GetColour().Blue();
1714 unsigned char green
= m_pen
.GetColour().Green();
1716 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1718 double redPS
= (double)(red
) / 255.0;
1719 double bluePS
= (double)(blue
) / 255.0;
1720 double greenPS
= (double)(green
) / 255.0;
1722 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1725 m_currentBlue
= blue
;
1726 m_currentGreen
= green
;
1730 void wxGnomePrinterDC::SetBrush( const wxBrush
& brush
)
1732 if (!brush
.Ok()) return;
1737 unsigned char red
= m_brush
.GetColour().Red();
1738 unsigned char blue
= m_brush
.GetColour().Blue();
1739 unsigned char green
= m_brush
.GetColour().Green();
1743 // Anything not white is black
1744 if (! (red
== (unsigned char) 255 &&
1745 blue
== (unsigned char) 255 &&
1746 green
== (unsigned char) 255) )
1748 red
= (unsigned char) 0;
1749 green
= (unsigned char) 0;
1750 blue
= (unsigned char) 0;
1755 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1757 double redPS
= (double)(red
) / 255.0;
1758 double bluePS
= (double)(blue
) / 255.0;
1759 double greenPS
= (double)(green
) / 255.0;
1761 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1764 m_currentBlue
= blue
;
1765 m_currentGreen
= green
;
1769 void wxGnomePrinterDC::SetLogicalFunction(int WXUNUSED(function
))
1773 void wxGnomePrinterDC::SetBackground(const wxBrush
& WXUNUSED(brush
))
1777 void wxGnomePrinterDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1779 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1781 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1783 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1784 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1785 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1786 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1787 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1788 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1789 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1792 void wxGnomePrinterDC::DestroyClippingRegion()
1794 wxDC::DestroyClippingRegion();
1796 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1799 // not needed, we set the values in each
1800 // drawing method anyways
1802 SetBrush( m_brush
);
1807 bool wxGnomePrinterDC::StartDoc(const wxString
& WXUNUSED(message
))
1812 void wxGnomePrinterDC::EndDoc()
1814 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1817 void wxGnomePrinterDC::StartPage()
1819 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1822 void wxGnomePrinterDC::EndPage()
1824 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1827 wxCoord
wxGnomePrinterDC::GetCharHeight() const
1829 pango_layout_set_text( m_layout
, "H", 1 );
1832 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1837 wxCoord
wxGnomePrinterDC::GetCharWidth() const
1839 pango_layout_set_text( m_layout
, "H", 1 );
1842 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1847 void wxGnomePrinterDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1849 wxCoord
*externalLeading
,
1850 const wxFont
*theFont
) const
1858 if ( externalLeading
)
1859 *externalLeading
= 0;
1866 // Set layout's text
1868 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1869 #if wxUSE_UNICODE_UTF8
1870 const char *dataUTF8
= string
.utf8_str();
1872 const wxCharBuffer dataUTF8
= string
.utf8_str();
1875 PangoFontDescription
*desc
= (theFont
) ? theFont
->GetNativeFontInfo()->description
: m_fontdesc
;
1877 gint oldSize
= pango_font_description_get_size( desc
);
1878 double size
= oldSize
;
1879 size
= size
* m_scaleY
;
1880 pango_font_description_set_size( desc
, (gint
)size
);
1882 // apply scaled font
1883 pango_layout_set_font_description( m_layout
, desc
);
1885 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1888 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1892 *width
= (wxCoord
)(w
/ m_scaleX
);
1894 *height
= (wxCoord
)(h
/ m_scaleY
);
1898 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1899 int baseline
= pango_layout_iter_get_baseline(iter
);
1900 pango_layout_iter_free(iter
);
1901 *descent
= h
- PANGO_PIXELS(baseline
);
1904 // reset unscaled size
1905 pango_font_description_set_size( desc
, oldSize
);
1907 // reset unscaled font
1908 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1911 void wxGnomePrinterDC::DoGetSize(int* width
, int* height
) const
1913 wxGnomePrintNativeData
*native
=
1914 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1916 // Query page size. This seems to omit the margins
1918 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1921 *width
= wxRound( pw
* PS2DEV
);
1924 *height
= wxRound( ph
* PS2DEV
);
1927 void wxGnomePrinterDC::DoGetSizeMM(int *width
, int *height
) const
1929 wxGnomePrintNativeData
*native
=
1930 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1932 // This code assumes values in Pts.
1935 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1939 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1940 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1941 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1942 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1945 *width
= (int) (pw
+ 0.5);
1947 *height
= (int) (ph
+ 0.5);
1950 wxSize
wxGnomePrinterDC::GetPPI() const
1952 return wxSize(DPI
,DPI
);
1955 void wxGnomePrinterDC::SetPrintData(const wxPrintData
& data
)
1960 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1961 GetSize( NULL
, &height
);
1963 GetSize( &height
, NULL
);
1964 m_deviceLocalOriginY
= height
;
1967 void wxGnomePrinterDC::SetResolution(int WXUNUSED(ppi
))
1971 int wxGnomePrinterDC::GetResolution()
1976 // ----------------------------------------------------------------------------
1977 // wxGnomePrintModule
1978 // ----------------------------------------------------------------------------
1980 bool wxGnomePrintModule::OnInit()
1982 gs_libGnomePrint
= new wxGnomePrintLibrary
;
1983 if (gs_libGnomePrint
->IsOk())
1984 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1988 void wxGnomePrintModule::OnExit()
1990 delete gs_libGnomePrint
;
1991 gs_libGnomePrint
= NULL
;
1994 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1996 // ----------------------------------------------------------------------------
1998 // ----------------------------------------------------------------------------
2000 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
2002 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2003 wxPrintout
* WXUNUSED(printoutForPrinting
))
2008 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2009 wxPrintout
*printoutForPrinting
,
2010 wxPrintDialogData
*data
)
2011 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2013 Init(printout
, printoutForPrinting
);
2016 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2017 wxPrintout
*printoutForPrinting
,
2019 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2021 Init(printout
, printoutForPrinting
);
2024 wxGnomePrintPreview::~wxGnomePrintPreview()
2028 bool wxGnomePrintPreview::Print(bool interactive
)
2030 if (!m_printPrintout
)
2033 wxPrinter
printer(& m_printDialogData
);
2034 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2037 void wxGnomePrintPreview::DetermineScaling()
2039 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2040 if (paperType
== wxPAPER_NONE
)
2041 paperType
= wxPAPER_NONE
;
2043 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2045 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2049 wxSize ScreenPixels
= wxGetDisplaySize();
2050 wxSize ScreenMM
= wxGetDisplaySizeMM();
2052 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2053 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2054 m_previewPrintout
->SetPPIPrinter(wxGnomePrinterDC::GetResolution(), wxGnomePrinterDC::GetResolution());
2056 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2058 // TODO: get better resolution information from wxGnomePrinterDC, if possible.
2060 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrinterDC::GetResolution() / 72.0);
2061 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrinterDC::GetResolution() / 72.0);
2062 wxSize
sizeTenthsMM(paper
->GetSize());
2063 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2065 // If in landscape mode, we need to swap the width and height.
2066 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2068 m_pageWidth
= sizeDevUnits
.y
;
2069 m_pageHeight
= sizeDevUnits
.x
;
2070 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2074 m_pageWidth
= sizeDevUnits
.x
;
2075 m_pageHeight
= sizeDevUnits
.y
;
2076 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2078 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2079 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2081 // At 100%, the page should look about page-size on the screen.
2082 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrinterDC::GetResolution();
2083 m_previewScaleY
= m_previewScaleX
;
2088 // wxUSE_LIBGNOMEPRINT