1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_LIBGNOMEPRINT
20 #include "wx/gtk/gnome/gprint.h"
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
36 #include <libgnomeprint/gnome-print.h>
37 #include <libgnomeprint/gnome-print-pango.h>
38 #include <libgnomeprint/gnome-print-config.h>
39 #include <libgnomeprintui/gnome-print-dialog.h>
40 #include <libgnomeprintui/gnome-print-job-preview.h>
41 #include <libgnomeprintui/gnome-print-paper-selector.h>
44 wxFORCE_LINK_THIS_MODULE(gnome_print
)
46 //----------------------------------------------------------------------------
47 // wxGnomePrintLibrary
48 //----------------------------------------------------------------------------
50 class wxGnomePrintLibrary
53 wxGnomePrintLibrary();
54 ~wxGnomePrintLibrary();
58 bool InitializeMethods();
60 wxDynamicLibrary m_libGnomePrint
;
61 wxDynamicLibrary m_libGnomePrintUI
;
63 // only true if we successfully loaded both libraries
65 // don't rename this field, it's used by wxDL_XXX macros internally
69 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
70 (GnomePrintContext
*pc
), (pc
), 0 )
71 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
72 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
73 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
74 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
76 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
78 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
80 (GnomePrintContext
*pc
), (pc
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
82 (GnomePrintContext
*pc
), (pc
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
84 (GnomePrintContext
*pc
), (pc
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
86 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
88 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
90 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
93 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
95 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
98 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
100 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
102 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
104 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
107 (GnomePrintContext
*pc
), (pc
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
109 (GnomePrintContext
*pc
), (pc
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
112 (GnomePrintContext
*pc
), (pc
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
117 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
119 (GnomePrintContext
*pc
), (pc
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
123 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
124 (GnomePrintContext
*gpc
), (gpc
), NULL
)
125 wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout
,
126 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
) )
128 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
129 (GnomePrintConfig
*config
), (config
), NULL
)
130 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
131 (GnomePrintJob
*job
), (job
), NULL
)
132 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
133 (GnomePrintJob
*job
), (job
), 0 )
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
137 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
139 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
140 (const guchar
*abbreviation
), (abbreviation
), NULL
)
141 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
142 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
144 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
146 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
147 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
149 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
152 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
153 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
154 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
155 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
157 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
158 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
159 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
160 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
161 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_boolean
,
162 (GnomePrintConfig
*config
, const guchar
*key
, gboolean
*val
), (config
, key
, val
), false )
164 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
165 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
166 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page
,
167 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
168 const guchar
*currentlabel
, const guchar
*rangelabel
),
169 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
) )
170 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies
,
171 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
) )
172 wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies
,
173 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
) )
174 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
175 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
176 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
177 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
179 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
180 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
182 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
183 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
185 DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
)
188 wxGnomePrintLibrary::wxGnomePrintLibrary()
192 m_libGnomePrint
.Load("libgnomeprint-2-2.so.0");
193 m_ok
= m_libGnomePrint
.IsLoaded();
197 m_libGnomePrintUI
.Load("libgnomeprintui-2-2.so.0");
198 m_ok
= m_libGnomePrintUI
.IsLoaded();
201 m_libGnomePrint
.Unload();
205 m_ok
= InitializeMethods();
208 wxGnomePrintLibrary::~wxGnomePrintLibrary()
212 bool wxGnomePrintLibrary::IsOk()
217 bool wxGnomePrintLibrary::InitializeMethods()
219 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_newpath
);
220 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_moveto
);
221 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_lineto
);
222 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_curveto
);
223 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_arcto
);
224 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_closepath
);
225 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_stroke
);
226 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_fill
);
227 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setrgbcolor
);
228 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setlinewidth
);
229 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_setdash
);
231 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbimage
);
232 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rgbaimage
);
234 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_concat
);
235 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_scale
);
236 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_rotate
);
237 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_translate
);
239 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_gsave
);
240 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_grestore
);
242 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_clip
);
243 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_eoclip
);
245 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_beginpage
);
246 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_showpage
);
247 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_end_doc
);
249 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_create_layout
);
250 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_pango_layout
);
252 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_new
);
253 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_context
);
254 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_close
);
255 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_print
);
256 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_job_get_page_size
);
258 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_unit_get_by_abbreviation
);
259 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_convert_distance
);
261 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_default
);
262 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set
);
263 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_boolean
);
264 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_double
);
265 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_int
);
266 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_set_length
);
268 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get
);
269 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_length
);
270 wxDL_METHOD_LOAD( m_libGnomePrint
, gnome_print_config_get_boolean
);
272 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_new
);
273 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_construct_range_page
);
274 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_copies
);
275 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_set_copies
);
276 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range
);
277 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_dialog_get_range_page
);
279 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_paper_selector_new_with_flags
);
281 wxDL_METHOD_LOAD( m_libGnomePrintUI
, gnome_print_job_preview_new
);
286 static wxGnomePrintLibrary
* gs_libGnomePrint
= NULL
;
288 //----------------------------------------------------------------------------
289 // wxGnomePrintNativeData
290 //----------------------------------------------------------------------------
292 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
294 wxGnomePrintNativeData::wxGnomePrintNativeData()
296 m_config
= gs_libGnomePrint
->gnome_print_config_default();
297 m_job
= gs_libGnomePrint
->gnome_print_job_new( m_config
);
300 wxGnomePrintNativeData::~wxGnomePrintNativeData()
302 g_object_unref (m_config
);
305 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
307 guchar
*res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
308 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
);
309 if (g_ascii_strcasecmp((const gchar
*)res
,"R90") == 0)
310 data
.SetOrientation( wxLANDSCAPE
);
312 data
.SetOrientation( wxPORTRAIT
);
315 res
= gs_libGnomePrint
->gnome_print_config_get( m_config
,
316 (guchar
*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME
);
319 data
.SetFilename( wxConvFile
.cMB2WX( (const char*) res
) );
320 wxPrintf( "filename %s\n", data
.GetFilename() );
325 data
.SetFilename( wxEmptyString
);
329 if (gs_libGnomePrint
->gnome_print_config_get_boolean( m_config
,
330 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
, &ret
))
332 data
.SetCollate( ret
);
340 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
342 if (data
.GetOrientation() == wxLANDSCAPE
)
344 gs_libGnomePrint
->gnome_print_config_set( m_config
,
345 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
346 (guchar
*)(char*)"R90" );
350 gs_libGnomePrint
->gnome_print_config_set( m_config
,
351 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
352 (guchar
*)(char*)"R0" );
355 if (data
.GetCollate())
357 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
358 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
363 gs_libGnomePrint
->gnome_print_config_set_boolean( m_config
,
364 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
368 switch (data
.GetPaperId())
370 case wxPAPER_A3
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
371 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
372 (guchar
*)(char*)"A3" );
374 case wxPAPER_A5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
375 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
376 (guchar
*)(char*)"A5" );
378 case wxPAPER_B4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
379 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
380 (guchar
*)(char*)"B4" );
382 case wxPAPER_B5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
383 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
384 (guchar
*)(char*)"B5" );
386 case wxPAPER_LETTER
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
387 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
388 (guchar
*)(char*)"USLetter" );
390 case wxPAPER_LEGAL
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
391 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
392 (guchar
*)(char*)"USLegal" );
394 case wxPAPER_EXECUTIVE
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
395 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
396 (guchar
*)(char*)"Executive" );
398 case wxPAPER_ENV_C5
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
399 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
400 (guchar
*)(char*)"C5" );
402 case wxPAPER_ENV_C6
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
403 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
404 (guchar
*)(char*)"C6" );
406 case wxPAPER_NONE
: break;
409 case wxPAPER_A4
: gs_libGnomePrint
->gnome_print_config_set( m_config
,
410 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
411 (guchar
*)(char*)"A4" );
418 //----------------------------------------------------------------------------
419 // wxGnomePrintFactory
420 //----------------------------------------------------------------------------
422 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
424 return new wxGnomePrinter( data
);
427 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
428 wxPrintout
*printout
,
429 wxPrintDialogData
*data
)
431 return new wxGnomePrintPreview( preview
, printout
, data
);
434 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
435 wxPrintout
*printout
,
438 return new wxGnomePrintPreview( preview
, printout
, data
);
441 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
442 wxPrintDialogData
*data
)
444 return new wxGnomePrintDialog( parent
, data
);
447 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
450 return new wxGnomePrintDialog( parent
, data
);
453 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
454 wxPageSetupDialogData
* data
)
456 // The native page setup dialog is broken. It
457 // miscalculates newly entered values for the
458 // margins if you have not chose "points" but
459 // e.g. centimerters.
460 // This has been fixed in GNOME CVS (maybe
461 // fixed in libgnomeprintui 2.8.1)
463 return new wxGnomePageSetupDialog( parent
, data
);
466 bool wxGnomePrintFactory::HasPrintSetupDialog()
472 wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
473 wxPrintData
* WXUNUSED(data
))
478 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
480 return new wxGnomePrintDC(data
);
483 bool wxGnomePrintFactory::HasOwnPrintToFile()
488 bool wxGnomePrintFactory::HasPrinterLine()
493 wxString
wxGnomePrintFactory::CreatePrinterLine()
496 return wxEmptyString
;
499 bool wxGnomePrintFactory::HasStatusLine()
505 wxString
wxGnomePrintFactory::CreateStatusLine()
508 return wxEmptyString
;
511 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
513 return new wxGnomePrintNativeData
;
516 //----------------------------------------------------------------------------
517 // wxGnomePrintSetupDialog
518 //----------------------------------------------------------------------------
520 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
522 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
523 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
524 wxPoint(0, 0), wxSize(600, 600),
525 wxDEFAULT_DIALOG_STYLE
|
529 m_printDialogData
= *data
;
534 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
535 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
536 wxPoint(0, 0), wxSize(600, 600),
537 wxDEFAULT_DIALOG_STYLE
|
541 m_printDialogData
= *data
;
546 void wxGnomePrintDialog::Init()
548 wxPrintData data
= m_printDialogData
.GetPrintData();
550 data
.ConvertToNative();
552 wxGnomePrintNativeData
*native
=
553 (wxGnomePrintNativeData
*) data
.GetNativeData();
555 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
557 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
560 if (m_printDialogData
.GetEnableSelection())
561 flag
|= GNOME_PRINT_RANGE_SELECTION
;
562 if (m_printDialogData
.GetEnablePageNumbers())
563 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
565 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
567 m_printDialogData
.GetMinPage(),
568 m_printDialogData
.GetMaxPage(),
573 wxGnomePrintDialog::~wxGnomePrintDialog()
578 int wxGnomePrintDialog::ShowModal()
580 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
582 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
584 gtk_widget_destroy(m_widget
);
590 m_printDialogData
.GetPrintData().ConvertFromNative();
593 gboolean collate
= false;
594 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
595 m_printDialogData
.SetNoCopies( copies
);
596 m_printDialogData
.SetCollate( collate
);
598 switch (gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
600 case GNOME_PRINT_RANGE_SELECTION
:
601 m_printDialogData
.SetSelection( true );
603 case GNOME_PRINT_RANGE_ALL
:
604 m_printDialogData
.SetAllPages( true );
605 m_printDialogData
.SetFromPage( 0 );
606 m_printDialogData
.SetToPage( 9999 );
608 case GNOME_PRINT_RANGE_RANGE
:
611 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
612 m_printDialogData
.SetFromPage( start
);
613 m_printDialogData
.SetToPage( end
);
617 gtk_widget_destroy(m_widget
);
620 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
626 wxDC
*wxGnomePrintDialog::GetPrintDC()
632 bool wxGnomePrintDialog::Validate()
637 bool wxGnomePrintDialog::TransferDataToWindow()
642 bool wxGnomePrintDialog::TransferDataFromWindow()
647 //----------------------------------------------------------------------------
648 // wxGnomePageSetupDialog
649 //----------------------------------------------------------------------------
651 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
653 wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow
* WXUNUSED(parent
),
654 wxPageSetupDialogData
*data
)
657 m_pageDialogData
= *data
;
659 m_pageDialogData
.GetPrintData().ConvertToNative();
661 wxGnomePrintNativeData
*native
=
662 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
664 // This *was* required as the page setup dialog
665 // calculates wrong values otherwise.
667 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
668 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
669 (const guchar
*) "Pts" );
672 GnomePrintConfig
*config
= native
->GetPrintConfig();
674 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
676 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
677 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
678 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
679 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
681 gs_libGnomePrint
->gnome_print_config_set_length (config
,
682 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
683 gs_libGnomePrint
->gnome_print_config_set_length (config
,
684 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
685 gs_libGnomePrint
->gnome_print_config_set_length (config
,
686 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
687 gs_libGnomePrint
->gnome_print_config_set_length (config
,
688 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
690 m_widget
= gtk_dialog_new();
692 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
694 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
695 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
696 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
697 gtk_widget_show (main
);
699 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
701 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
703 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
704 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
705 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
708 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
712 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
716 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
718 return m_pageDialogData
;
721 int wxGnomePageSetupDialog::ShowModal()
723 wxGnomePrintNativeData
*native
=
724 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
726 GnomePrintConfig
*config
= native
->GetPrintConfig();
729 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
731 if (ret
== GTK_RESPONSE_OK
)
733 // Transfer data back to m_pageDialogData
734 m_pageDialogData
.GetPrintData().ConvertFromNative();
736 // I don't know how querying the last parameter works
737 double ml
,mr
,mt
,mb
,pw
,ph
;
738 gs_libGnomePrint
->gnome_print_config_get_length (config
,
739 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
740 gs_libGnomePrint
->gnome_print_config_get_length (config
,
741 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
742 gs_libGnomePrint
->gnome_print_config_get_length (config
,
743 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
744 gs_libGnomePrint
->gnome_print_config_get_length (config
,
745 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
746 gs_libGnomePrint
->gnome_print_config_get_length (config
,
747 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
748 gs_libGnomePrint
->gnome_print_config_get_length (config
,
749 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
751 // This code converts correctly from what the user chose
752 // as the unit although I query Pts here
753 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
754 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
755 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
756 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
757 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
758 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
759 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
760 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
762 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
763 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
765 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
774 gtk_widget_destroy( m_widget
);
780 bool wxGnomePageSetupDialog::Validate()
785 bool wxGnomePageSetupDialog::TransferDataToWindow()
790 bool wxGnomePageSetupDialog::TransferDataFromWindow()
795 //----------------------------------------------------------------------------
797 //----------------------------------------------------------------------------
799 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
801 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
802 wxPrinterBase( data
)
804 m_native_preview
= false;
807 wxGnomePrinter::~wxGnomePrinter()
811 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
815 sm_lastError
= wxPRINTER_ERROR
;
819 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
821 wxGnomePrintNativeData
*native
=
822 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
824 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
826 // The GnomePrintJob is temporarily stored in the
827 // native print data as the native print dialog
828 // needs to access it.
829 native
->SetPrintJob( job
);
832 printout
->SetIsPreview(false);
834 if (m_printDialogData
.GetMinPage() < 1)
835 m_printDialogData
.SetMinPage(1);
836 if (m_printDialogData
.GetMaxPage() < 1)
837 m_printDialogData
.SetMaxPage(9999);
841 dc
= PrintDialog( parent
);
843 dc
= new wxGnomePrintDC( printdata
);
845 if (m_native_preview
)
846 printout
->SetIsPreview(true);
850 gs_libGnomePrint
->gnome_print_job_close( job
);
851 g_object_unref (job
);
852 if (sm_lastError
!= wxPRINTER_CANCELLED
)
853 sm_lastError
= wxPRINTER_ERROR
;
857 wxSize ScreenPixels
= wxGetDisplaySize();
858 wxSize ScreenMM
= wxGetDisplaySizeMM();
860 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
861 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
862 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
863 wxGnomePrintDC::GetResolution() );
869 printout
->SetPageSizePixels((int)w
, (int)h
);
870 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
872 dc
->GetSizeMM(&mw
, &mh
);
873 printout
->SetPageSizeMM((int)mw
, (int)mh
);
874 printout
->OnPreparePrinting();
876 // Get some parameters from the printout, if defined
877 int fromPage
, toPage
;
878 int minPage
, maxPage
;
879 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
883 gs_libGnomePrint
->gnome_print_job_close( job
);
884 g_object_unref (job
);
885 sm_lastError
= wxPRINTER_ERROR
;
889 printout
->OnBeginPrinting();
891 int minPageNum
= minPage
, maxPageNum
= maxPage
;
893 if ( !m_printDialogData
.GetAllPages() )
895 minPageNum
= m_printDialogData
.GetFromPage();
896 maxPageNum
= m_printDialogData
.GetToPage();
902 copyCount
<= m_printDialogData
.GetNoCopies();
905 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
907 wxLogError(_("Could not start printing."));
908 sm_lastError
= wxPRINTER_ERROR
;
913 for ( pn
= minPageNum
;
914 pn
<= maxPageNum
&& printout
->HasPage(pn
);
918 printout
->OnPrintPage(pn
);
922 printout
->OnEndDocument();
923 printout
->OnEndPrinting();
926 gs_libGnomePrint
->gnome_print_job_close( job
);
927 if (m_native_preview
)
929 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
930 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
933 (const guchar
*)title
.data()
935 gtk_widget_show(preview
);
939 gs_libGnomePrint
->gnome_print_job_print( job
);
942 g_object_unref (job
);
945 return (sm_lastError
== wxPRINTER_NO_ERROR
);
948 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
950 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
951 int ret
= dialog
.ShowModal();
952 if (ret
== wxID_CANCEL
)
954 sm_lastError
= wxPRINTER_CANCELLED
;
958 m_native_preview
= ret
== wxID_PREVIEW
;
960 m_printDialogData
= dialog
.GetPrintDialogData();
961 return new wxGnomePrintDC( m_printDialogData
.GetPrintData() );
964 bool wxGnomePrinter::Setup(wxWindow
* WXUNUSED(parent
))
969 //-----------------------------------------------------------------------------
971 //-----------------------------------------------------------------------------
974 static const double RAD2DEG
= 180.0 / M_PI
;
976 // we don't want to use only 72 dpi from GNOME print
977 static const int DPI
= 600;
978 static const double PS2DEV
= 600.0 / 72.0;
979 static const double DEV2PS
= 72.0 / 600.0;
981 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
982 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
983 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
984 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
986 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
988 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
992 wxGnomePrintNativeData
*native
=
993 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
995 m_job
= native
->GetPrintJob();
996 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
998 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
999 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1006 // Query page size. This seems to omit the margins
1008 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1010 m_pageHeight
= ph
* PS2DEV
;
1013 wxGnomePrintDC::~wxGnomePrintDC()
1017 bool wxGnomePrintDC::IsOk() const
1023 wxGnomePrintDC::DoFloodFill(wxCoord
WXUNUSED(x1
),
1024 wxCoord
WXUNUSED(y1
),
1025 const wxColour
& WXUNUSED(col
),
1026 int WXUNUSED(style
))
1032 wxGnomePrintDC::DoGetPixel(wxCoord
WXUNUSED(x1
),
1033 wxCoord
WXUNUSED(y1
),
1034 wxColour
* WXUNUSED(col
)) const
1039 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1041 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1045 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1046 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1047 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1049 CalcBoundingBox( x1
, y1
);
1050 CalcBoundingBox( x2
, y2
);
1053 void wxGnomePrintDC::DoCrossHair(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1057 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1059 double dx
= x1
- xc
;
1060 double dy
= y1
- yc
;
1061 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1062 double alpha1
, alpha2
;
1063 if (x1
== x2
&& y1
== y2
)
1068 else if ( wxIsNullDouble(radius
) )
1075 alpha1
= (x1
- xc
== 0) ?
1076 (y1
- yc
< 0) ? 90.0 : -90.0 :
1077 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1078 alpha2
= (x2
- xc
== 0) ?
1079 (y2
- yc
< 0) ? 90.0 : -90.0 :
1080 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1082 while (alpha1
<= 0) alpha1
+= 360;
1083 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1084 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1085 while (alpha2
> 360) alpha2
-= 360;
1088 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1090 SetBrush( m_brush
);
1091 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1092 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1094 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1097 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1100 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1101 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1102 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1103 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1105 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1108 CalcBoundingBox (x1
, y1
);
1109 CalcBoundingBox (x2
, y2
);
1110 CalcBoundingBox (xc
, yc
);
1113 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1118 double xx
= XLOG2DEV(x
);
1119 double yy
= YLOG2DEV(y
);
1121 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1123 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1124 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1125 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1130 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1132 SetBrush( m_brush
);
1134 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1135 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1136 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1137 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1139 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1142 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1146 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1147 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1149 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1152 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1154 CalcBoundingBox( x
, y
);
1155 CalcBoundingBox( x
+w
, y
+h
);
1158 void wxGnomePrintDC::DoDrawPoint(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
1162 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1164 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1171 for ( i
=0; i
<n
; i
++ )
1172 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1174 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1176 for (i
= 1; i
< n
; i
++)
1177 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1179 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1182 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[],
1183 wxCoord xoffset
, wxCoord yoffset
,
1184 int WXUNUSED(fillStyle
))
1188 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1190 SetBrush( m_brush
);
1192 int x
= points
[0].x
+ xoffset
;
1193 int y
= points
[0].y
+ yoffset
;
1194 CalcBoundingBox( x
, y
);
1195 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1196 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1198 for (i
= 1; i
< n
; i
++)
1200 x
= points
[i
].x
+ xoffset
;
1201 y
= points
[i
].y
+ yoffset
;
1202 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1203 CalcBoundingBox( x
, y
);
1205 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1206 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1209 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1213 int x
= points
[0].x
+ xoffset
;
1214 int y
= points
[0].y
+ yoffset
;
1215 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1216 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1218 for (i
= 1; i
< n
; i
++)
1220 x
= points
[i
].x
+ xoffset
;
1221 y
= points
[i
].y
+ yoffset
;
1222 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1223 CalcBoundingBox( x
, y
);
1225 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1226 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1230 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1232 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1235 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1240 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1242 SetBrush( m_brush
);
1244 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1245 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1246 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1247 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1248 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1249 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1250 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1252 CalcBoundingBox( x
, y
);
1253 CalcBoundingBox( x
+ width
, y
+ height
);
1256 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1260 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1261 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1262 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1263 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1264 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1265 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1266 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1268 CalcBoundingBox( x
, y
);
1269 CalcBoundingBox( x
+ width
, y
+ height
);
1273 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1278 wxCoord rad
= wxRound( radius
);
1280 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1283 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1284 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1285 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1286 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1287 XLOG2DEV(x
),YLOG2DEV(y
),
1288 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1289 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1290 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1291 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1292 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1293 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1294 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1295 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1296 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1297 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1298 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1299 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1300 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1301 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1302 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1303 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1304 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1305 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1306 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1308 CalcBoundingBox(x
,y
);
1309 CalcBoundingBox(x
+width
,y
+height
);
1312 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1315 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1316 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1317 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1318 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1319 XLOG2DEV(x
),YLOG2DEV(y
),
1320 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1321 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1322 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1323 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1324 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1325 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1326 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1327 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1328 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1329 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1330 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1331 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1332 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1333 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1334 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1335 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1336 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1337 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1338 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1340 CalcBoundingBox(x
,y
);
1341 CalcBoundingBox(x
+width
,y
+height
);
1345 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1346 wxCoord width
, wxCoord height
)
1348 double r
= 4 * (sqrt(2.) - 1) / 3;
1349 double halfW
= 0.5 * width
,
1350 halfH
= 0.5 * height
,
1353 wxCoord halfWI
= (wxCoord
) halfW
,
1354 halfHI
= (wxCoord
) halfH
;
1356 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1358 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1359 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1360 XLOG2DEV(x
+ width
),
1361 YLOG2DEV(y
+ halfHI
) );
1362 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1363 XLOG2DEV(x
+ width
),
1364 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1365 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1366 YLOG2DEV(y
+ height
),
1367 XLOG2DEV(x
+ halfWI
),
1368 YLOG2DEV(y
+ height
) );
1369 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1370 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1371 YLOG2DEV(y
+ height
),
1373 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1374 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1375 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1377 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1378 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1380 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1381 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1382 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1384 XLOG2DEV(x
+ width
),
1385 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1386 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1388 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1391 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1396 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1398 SetBrush( m_brush
);
1399 makeEllipticalPath( x
, y
, width
, height
);
1400 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1401 CalcBoundingBox( x
, y
);
1402 CalcBoundingBox( x
+ width
, y
+ height
);
1405 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1408 makeEllipticalPath( x
, y
, width
, height
);
1409 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1410 CalcBoundingBox( x
, y
);
1411 CalcBoundingBox( x
+ width
, y
+ height
);
1416 void wxGnomePrintDC::DoDrawSpline(const wxPointList
*points
)
1420 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1423 wxPointList::compatibility_iterator node
= points
->GetFirst();
1424 p
= node
->GetData();
1428 node
= node
->GetNext();
1429 p
= node
->GetData();
1433 (double)(x1
+ c
) / 2;
1435 (double)(y1
+ d
) / 2;
1437 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1438 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1439 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1441 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1442 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1444 node
= node
->GetNext();
1447 q
= node
->GetData();
1455 x3
= (double)(x2
+ c
) / 2;
1456 y3
= (double)(y2
+ d
) / 2;
1458 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1459 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1460 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1461 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1463 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1464 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1466 node
= node
->GetNext();
1469 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1471 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1473 #endif // wxUSE_SPLINES
1476 wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1477 wxCoord width
, wxCoord height
,
1479 wxCoord xsrc
, wxCoord ysrc
,
1481 bool WXUNUSED(useMask
),
1482 wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
))
1484 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1486 // blit into a bitmap
1487 wxBitmap
bitmap( width
, height
);
1489 memDC
.SelectObject(bitmap
);
1490 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1491 memDC
.SelectObject(wxNullBitmap
);
1493 // draw bitmap. scaling and positioning is done there
1494 DrawBitmap( bitmap
, xdest
, ydest
);
1499 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1501 DoDrawBitmap( icon
, x
, y
, true );
1505 wxGnomePrintDC::DoDrawBitmap(const wxBitmap
& bitmap
,
1506 wxCoord x
, wxCoord y
,
1507 bool WXUNUSED(useMask
))
1509 if (!bitmap
.Ok()) return;
1511 if (bitmap
.HasPixbuf())
1513 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1514 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1515 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1516 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1517 int height
= gdk_pixbuf_get_height( pixbuf
);
1518 int width
= gdk_pixbuf_get_width( pixbuf
);
1520 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1522 matrix
[0] = XLOG2DEVREL(width
);
1525 matrix
[3] = YLOG2DEVREL(height
);
1526 matrix
[4] = XLOG2DEV(x
);
1527 matrix
[5] = YLOG2DEV(y
+height
);
1528 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1529 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1531 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1533 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1534 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1538 wxImage image
= bitmap
.ConvertToImage();
1540 if (!image
.Ok()) return;
1542 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1544 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1547 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1548 matrix
[4] = XLOG2DEV(x
);
1549 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1550 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1551 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1552 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1553 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1557 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1559 DoDrawRotatedText( text
, x
, y
, 0.0 );
1562 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1564 double xx
= XLOG2DEV(x
);
1565 double yy
= YLOG2DEV(y
);
1567 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1569 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1570 #if wxUSE_UNICODE_UTF8
1571 const char *data
= text
.utf8_str();
1573 const wxCharBuffer data
= text
.utf8_str();
1576 size_t datalen
= strlen(data
);
1577 pango_layout_set_text( m_layout
, data
, datalen
);
1581 PangoAttrList
*attrs
= pango_attr_list_new();
1582 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1584 a
->end_index
= datalen
;
1585 pango_attr_list_insert(attrs
, a
);
1586 pango_layout_set_attributes(m_layout
, attrs
);
1587 pango_attr_list_unref(attrs
);
1590 if (m_textForegroundColour
.Ok())
1592 unsigned char red
= m_textForegroundColour
.Red();
1593 unsigned char blue
= m_textForegroundColour
.Blue();
1594 unsigned char green
= m_textForegroundColour
.Green();
1596 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1598 double redPS
= (double)(red
) / 255.0;
1599 double bluePS
= (double)(blue
) / 255.0;
1600 double greenPS
= (double)(green
) / 255.0;
1602 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1605 m_currentBlue
= blue
;
1606 m_currentGreen
= green
;
1611 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1613 if ( m_backgroundMode
== wxSOLID
)
1615 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1616 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1617 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1622 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1624 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1626 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1628 if (fabs(angle
) > 0.00001)
1629 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1631 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1633 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1637 // undo underline attributes setting:
1638 pango_layout_set_attributes(m_layout
, NULL
);
1641 CalcBoundingBox (x
+ w
, y
+ h
);
1644 void wxGnomePrintDC::Clear()
1648 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1655 pango_font_description_free( m_fontdesc
);
1657 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1659 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1663 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1665 if (!pen
.Ok()) return;
1671 if (m_pen
.GetWidth() <= 0)
1674 width
= (double) m_pen
.GetWidth();
1676 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, width
* DEV2PS
* m_scaleX
);
1678 static const double dotted
[] = {2.0, 5.0};
1679 static const double short_dashed
[] = {4.0, 4.0};
1680 static const double wxCoord_dashed
[] = {4.0, 8.0};
1681 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1683 switch (m_pen
.GetStyle())
1685 case wxDOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1686 case wxSHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1687 case wxLONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1688 case wxDOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1691 // It may be noted that libgnomeprint between at least
1692 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1693 // and then leak the memory since it doesn't set the
1694 // internal flag "privatedash" to 0.
1696 int num
= m_pen
.GetDashes (&wx_dashes
);
1697 gdouble
*g_dashes
= g_new( gdouble
, num
);
1699 for (i
= 0; i
< num
; ++i
)
1700 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1701 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1707 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1711 unsigned char red
= m_pen
.GetColour().Red();
1712 unsigned char blue
= m_pen
.GetColour().Blue();
1713 unsigned char green
= m_pen
.GetColour().Green();
1715 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1717 double redPS
= (double)(red
) / 255.0;
1718 double bluePS
= (double)(blue
) / 255.0;
1719 double greenPS
= (double)(green
) / 255.0;
1721 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1724 m_currentBlue
= blue
;
1725 m_currentGreen
= green
;
1729 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1731 if (!brush
.Ok()) return;
1736 unsigned char red
= m_brush
.GetColour().Red();
1737 unsigned char blue
= m_brush
.GetColour().Blue();
1738 unsigned char green
= m_brush
.GetColour().Green();
1742 // Anything not white is black
1743 if (! (red
== (unsigned char) 255 &&
1744 blue
== (unsigned char) 255 &&
1745 green
== (unsigned char) 255) )
1747 red
= (unsigned char) 0;
1748 green
= (unsigned char) 0;
1749 blue
= (unsigned char) 0;
1754 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1756 double redPS
= (double)(red
) / 255.0;
1757 double bluePS
= (double)(blue
) / 255.0;
1758 double greenPS
= (double)(green
) / 255.0;
1760 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1763 m_currentBlue
= blue
;
1764 m_currentGreen
= green
;
1768 void wxGnomePrintDC::SetLogicalFunction(int WXUNUSED(function
))
1772 void wxGnomePrintDC::SetBackground(const wxBrush
& WXUNUSED(brush
))
1776 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1778 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1780 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1782 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1783 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1784 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1785 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1786 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1787 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1788 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1791 void wxGnomePrintDC::DestroyClippingRegion()
1793 wxDC::DestroyClippingRegion();
1795 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1798 // not needed, we set the values in each
1799 // drawing method anyways
1801 SetBrush( m_brush
);
1806 bool wxGnomePrintDC::StartDoc(const wxString
& WXUNUSED(message
))
1811 void wxGnomePrintDC::EndDoc()
1813 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1816 void wxGnomePrintDC::StartPage()
1818 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1821 void wxGnomePrintDC::EndPage()
1823 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1826 wxCoord
wxGnomePrintDC::GetCharHeight() const
1828 pango_layout_set_text( m_layout
, "H", 1 );
1831 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1836 wxCoord
wxGnomePrintDC::GetCharWidth() const
1838 pango_layout_set_text( m_layout
, "H", 1 );
1841 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1846 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1848 wxCoord
*externalLeading
,
1849 const wxFont
*theFont
) const
1857 if ( externalLeading
)
1858 *externalLeading
= 0;
1865 // Set layout's text
1867 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1868 #if wxUSE_UNICODE_UTF8
1869 const char *dataUTF8
= string
.utf8_str();
1871 const wxCharBuffer dataUTF8
= string
.utf8_str();
1874 PangoFontDescription
*desc
= (theFont
) ? theFont
->GetNativeFontInfo()->description
: m_fontdesc
;
1876 gint oldSize
= pango_font_description_get_size( desc
);
1877 double size
= oldSize
;
1878 size
= size
* m_scaleY
;
1879 pango_font_description_set_size( desc
, (gint
)size
);
1881 // apply scaled font
1882 pango_layout_set_font_description( m_layout
, desc
);
1884 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1887 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1891 *width
= (wxCoord
)(w
/ m_scaleX
);
1893 *height
= (wxCoord
)(h
/ m_scaleY
);
1897 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1898 int baseline
= pango_layout_iter_get_baseline(iter
);
1899 pango_layout_iter_free(iter
);
1900 *descent
= h
- PANGO_PIXELS(baseline
);
1903 // reset unscaled size
1904 pango_font_description_set_size( desc
, oldSize
);
1906 // reset unscaled font
1907 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1910 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1912 wxGnomePrintNativeData
*native
=
1913 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1915 // Query page size. This seems to omit the margins
1917 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1920 *width
= wxRound( pw
* PS2DEV
);
1923 *height
= wxRound( ph
* PS2DEV
);
1926 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1928 wxGnomePrintNativeData
*native
=
1929 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1931 // This code assumes values in Pts.
1934 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1938 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1939 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1940 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1941 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1944 *width
= (int) (pw
+ 0.5);
1946 *height
= (int) (ph
+ 0.5);
1949 wxSize
wxGnomePrintDC::GetPPI() const
1951 return wxSize(DPI
,DPI
);
1954 void wxGnomePrintDC::SetPrintData(const wxPrintData
& data
)
1959 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1960 GetSize( NULL
, &height
);
1962 GetSize( &height
, NULL
);
1963 m_deviceLocalOriginY
= height
;
1966 void wxGnomePrintDC::SetResolution(int WXUNUSED(ppi
))
1970 int wxGnomePrintDC::GetResolution()
1975 // ----------------------------------------------------------------------------
1976 // wxGnomePrintModule
1977 // ----------------------------------------------------------------------------
1979 bool wxGnomePrintModule::OnInit()
1981 gs_libGnomePrint
= new wxGnomePrintLibrary
;
1982 if (gs_libGnomePrint
->IsOk())
1983 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1987 void wxGnomePrintModule::OnExit()
1989 delete gs_libGnomePrint
;
1990 gs_libGnomePrint
= NULL
;
1993 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1995 // ----------------------------------------------------------------------------
1997 // ----------------------------------------------------------------------------
1999 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
2001 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2002 wxPrintout
* WXUNUSED(printoutForPrinting
))
2007 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2008 wxPrintout
*printoutForPrinting
,
2009 wxPrintDialogData
*data
)
2010 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2012 Init(printout
, printoutForPrinting
);
2015 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2016 wxPrintout
*printoutForPrinting
,
2018 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2020 Init(printout
, printoutForPrinting
);
2023 wxGnomePrintPreview::~wxGnomePrintPreview()
2027 bool wxGnomePrintPreview::Print(bool interactive
)
2029 if (!m_printPrintout
)
2032 wxPrinter
printer(& m_printDialogData
);
2033 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2036 void wxGnomePrintPreview::DetermineScaling()
2038 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2039 if (paperType
== wxPAPER_NONE
)
2040 paperType
= wxPAPER_NONE
;
2042 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2044 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2048 wxSize ScreenPixels
= wxGetDisplaySize();
2049 wxSize ScreenMM
= wxGetDisplaySizeMM();
2051 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2052 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2053 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
2055 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2057 // TODO: get better resolution information from wxGnomePrintDC, if possible.
2059 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
2060 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
2061 wxSize
sizeTenthsMM(paper
->GetSize());
2062 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2064 // If in landscape mode, we need to swap the width and height.
2065 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2067 m_pageWidth
= sizeDevUnits
.y
;
2068 m_pageHeight
= sizeDevUnits
.x
;
2069 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2073 m_pageWidth
= sizeDevUnits
.x
;
2074 m_pageHeight
= sizeDevUnits
.y
;
2075 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2077 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2078 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2080 // At 100%, the page should look about page-size on the screen.
2081 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
2082 m_previewScaleY
= m_previewScaleX
;
2087 // wxUSE_LIBGNOMEPRINT