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()
471 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
476 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
478 return new wxGnomePrintDC(data
);
481 bool wxGnomePrintFactory::HasOwnPrintToFile()
486 bool wxGnomePrintFactory::HasPrinterLine()
491 wxString
wxGnomePrintFactory::CreatePrinterLine()
494 return wxEmptyString
;
497 bool wxGnomePrintFactory::HasStatusLine()
503 wxString
wxGnomePrintFactory::CreateStatusLine()
506 return wxEmptyString
;
509 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
511 return new wxGnomePrintNativeData
;
514 //----------------------------------------------------------------------------
515 // wxGnomePrintSetupDialog
516 //----------------------------------------------------------------------------
518 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
520 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
521 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
522 wxPoint(0, 0), wxSize(600, 600),
523 wxDEFAULT_DIALOG_STYLE
|
527 m_printDialogData
= *data
;
532 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
533 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
534 wxPoint(0, 0), wxSize(600, 600),
535 wxDEFAULT_DIALOG_STYLE
|
539 m_printDialogData
= *data
;
544 void wxGnomePrintDialog::Init()
546 wxPrintData data
= m_printDialogData
.GetPrintData();
548 data
.ConvertToNative();
550 wxGnomePrintNativeData
*native
=
551 (wxGnomePrintNativeData
*) data
.GetNativeData();
553 m_widget
= gs_libGnomePrint
->gnome_print_dialog_new( native
->GetPrintJob(),
555 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
558 if (m_printDialogData
.GetEnableSelection())
559 flag
|= GNOME_PRINT_RANGE_SELECTION
;
560 if (m_printDialogData
.GetEnablePageNumbers())
561 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
563 gs_libGnomePrint
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
565 m_printDialogData
.GetMinPage(),
566 m_printDialogData
.GetMaxPage(),
571 wxGnomePrintDialog::~wxGnomePrintDialog()
576 int wxGnomePrintDialog::ShowModal()
578 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
580 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
582 gtk_widget_destroy(m_widget
);
588 m_printDialogData
.GetPrintData().ConvertFromNative();
591 gboolean collate
= false;
592 gs_libGnomePrint
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
593 m_printDialogData
.SetNoCopies( copies
);
594 m_printDialogData
.SetCollate( collate
);
596 switch (gs_libGnomePrint
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
598 case GNOME_PRINT_RANGE_SELECTION
:
599 m_printDialogData
.SetSelection( true );
601 case GNOME_PRINT_RANGE_ALL
:
602 m_printDialogData
.SetAllPages( true );
603 m_printDialogData
.SetFromPage( 0 );
604 m_printDialogData
.SetToPage( 9999 );
606 case GNOME_PRINT_RANGE_RANGE
:
609 gs_libGnomePrint
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
610 m_printDialogData
.SetFromPage( start
);
611 m_printDialogData
.SetToPage( end
);
615 gtk_widget_destroy(m_widget
);
618 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
624 wxDC
*wxGnomePrintDialog::GetPrintDC()
630 bool wxGnomePrintDialog::Validate()
635 bool wxGnomePrintDialog::TransferDataToWindow()
640 bool wxGnomePrintDialog::TransferDataFromWindow()
645 //----------------------------------------------------------------------------
646 // wxGnomePageSetupDialog
647 //----------------------------------------------------------------------------
649 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
651 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
652 wxPageSetupDialogData
* data
)
655 m_pageDialogData
= *data
;
657 m_pageDialogData
.GetPrintData().ConvertToNative();
659 wxGnomePrintNativeData
*native
=
660 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
662 // This *was* required as the page setup dialog
663 // calculates wrong values otherwise.
665 gs_libGnomePrint
->gnome_print_config_set( native
->GetPrintConfig(),
666 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
667 (const guchar
*) "Pts" );
670 GnomePrintConfig
*config
= native
->GetPrintConfig();
672 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
674 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
675 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
676 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
677 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
679 gs_libGnomePrint
->gnome_print_config_set_length (config
,
680 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
681 gs_libGnomePrint
->gnome_print_config_set_length (config
,
682 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
683 gs_libGnomePrint
->gnome_print_config_set_length (config
,
684 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
685 gs_libGnomePrint
->gnome_print_config_set_length (config
,
686 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
688 m_widget
= gtk_dialog_new();
690 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
692 GtkWidget
*main
= gs_libGnomePrint
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
693 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
694 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
695 gtk_widget_show (main
);
697 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
699 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
701 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
702 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
703 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
706 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
710 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
714 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
716 return m_pageDialogData
;
719 int wxGnomePageSetupDialog::ShowModal()
721 wxGnomePrintNativeData
*native
=
722 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
724 GnomePrintConfig
*config
= native
->GetPrintConfig();
727 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
729 if (ret
== GTK_RESPONSE_OK
)
731 // Transfer data back to m_pageDialogData
732 m_pageDialogData
.GetPrintData().ConvertFromNative();
734 // I don't know how querying the last parameter works
735 double ml
,mr
,mt
,mb
,pw
,ph
;
736 gs_libGnomePrint
->gnome_print_config_get_length (config
,
737 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
738 gs_libGnomePrint
->gnome_print_config_get_length (config
,
739 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
740 gs_libGnomePrint
->gnome_print_config_get_length (config
,
741 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
742 gs_libGnomePrint
->gnome_print_config_get_length (config
,
743 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
744 gs_libGnomePrint
->gnome_print_config_get_length (config
,
745 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
746 gs_libGnomePrint
->gnome_print_config_get_length (config
,
747 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
749 // This code converts correctly from what the user chose
750 // as the unit although I query Pts here
751 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
752 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
753 gs_libGnomePrint
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
754 gs_libGnomePrint
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
755 gs_libGnomePrint
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
756 gs_libGnomePrint
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
757 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
758 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
760 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
761 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
763 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
772 gtk_widget_destroy( m_widget
);
778 bool wxGnomePageSetupDialog::Validate()
783 bool wxGnomePageSetupDialog::TransferDataToWindow()
788 bool wxGnomePageSetupDialog::TransferDataFromWindow()
793 //----------------------------------------------------------------------------
795 //----------------------------------------------------------------------------
797 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
799 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
800 wxPrinterBase( data
)
802 m_native_preview
= false;
805 wxGnomePrinter::~wxGnomePrinter()
809 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
813 sm_lastError
= wxPRINTER_ERROR
;
817 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
819 wxGnomePrintNativeData
*native
=
820 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
822 GnomePrintJob
*job
= gs_libGnomePrint
->gnome_print_job_new( native
->GetPrintConfig() );
824 // The GnomePrintJob is temporarily stored in the
825 // native print data as the native print dialog
826 // needs to access it.
827 native
->SetPrintJob( job
);
830 printout
->SetIsPreview(false);
832 if (m_printDialogData
.GetMinPage() < 1)
833 m_printDialogData
.SetMinPage(1);
834 if (m_printDialogData
.GetMaxPage() < 1)
835 m_printDialogData
.SetMaxPage(9999);
839 dc
= PrintDialog( parent
);
841 dc
= new wxGnomePrintDC( printdata
);
843 if (m_native_preview
)
844 printout
->SetIsPreview(true);
848 gs_libGnomePrint
->gnome_print_job_close( job
);
849 g_object_unref (job
);
850 if (sm_lastError
!= wxPRINTER_CANCELLED
)
851 sm_lastError
= wxPRINTER_ERROR
;
855 wxSize ScreenPixels
= wxGetDisplaySize();
856 wxSize ScreenMM
= wxGetDisplaySizeMM();
858 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
859 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
860 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
861 wxGnomePrintDC::GetResolution() );
867 printout
->SetPageSizePixels((int)w
, (int)h
);
868 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
870 dc
->GetSizeMM(&mw
, &mh
);
871 printout
->SetPageSizeMM((int)mw
, (int)mh
);
872 printout
->OnPreparePrinting();
874 // Get some parameters from the printout, if defined
875 int fromPage
, toPage
;
876 int minPage
, maxPage
;
877 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
881 gs_libGnomePrint
->gnome_print_job_close( job
);
882 g_object_unref (job
);
883 sm_lastError
= wxPRINTER_ERROR
;
887 printout
->OnBeginPrinting();
889 int minPageNum
= minPage
, maxPageNum
= maxPage
;
891 if ( !m_printDialogData
.GetAllPages() )
893 minPageNum
= m_printDialogData
.GetFromPage();
894 maxPageNum
= m_printDialogData
.GetToPage();
900 copyCount
<= m_printDialogData
.GetNoCopies();
903 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
905 wxLogError(_("Could not start printing."));
906 sm_lastError
= wxPRINTER_ERROR
;
911 for ( pn
= minPageNum
;
912 pn
<= maxPageNum
&& printout
->HasPage(pn
);
916 printout
->OnPrintPage(pn
);
920 printout
->OnEndDocument();
921 printout
->OnEndPrinting();
924 gs_libGnomePrint
->gnome_print_job_close( job
);
925 if (m_native_preview
)
927 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
928 GtkWidget
*preview
= gs_libGnomePrint
->gnome_print_job_preview_new
931 (const guchar
*)title
.data()
933 gtk_widget_show(preview
);
937 gs_libGnomePrint
->gnome_print_job_print( job
);
940 g_object_unref (job
);
943 return (sm_lastError
== wxPRINTER_NO_ERROR
);
946 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
948 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
949 int ret
= dialog
.ShowModal();
950 if (ret
== wxID_CANCEL
)
952 sm_lastError
= wxPRINTER_CANCELLED
;
956 m_native_preview
= ret
== wxID_PREVIEW
;
958 m_printDialogData
= dialog
.GetPrintDialogData();
959 return new wxGnomePrintDC( m_printDialogData
.GetPrintData() );
962 bool wxGnomePrinter::Setup( wxWindow
*parent
)
967 //-----------------------------------------------------------------------------
969 //-----------------------------------------------------------------------------
972 static const double RAD2DEG
= 180.0 / M_PI
;
974 // we don't want to use only 72 dpi from GNOME print
975 static const int DPI
= 600;
976 static const double PS2DEV
= 600.0 / 72.0;
977 static const double DEV2PS
= 72.0 / 600.0;
979 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
980 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
981 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
982 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
984 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
986 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
990 wxGnomePrintNativeData
*native
=
991 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
993 m_job
= native
->GetPrintJob();
994 m_gpc
= gs_libGnomePrint
->gnome_print_job_get_context (m_job
);
996 m_layout
= gs_libGnomePrint
->gnome_print_pango_create_layout( m_gpc
);
997 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1004 // Query page size. This seems to omit the margins
1006 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1008 m_pageHeight
= ph
* PS2DEV
;
1011 wxGnomePrintDC::~wxGnomePrintDC()
1015 bool wxGnomePrintDC::IsOk() const
1020 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
1025 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
1030 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1032 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1036 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1037 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1038 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1040 CalcBoundingBox( x1
, y1
);
1041 CalcBoundingBox( x2
, y2
);
1044 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1048 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1050 double dx
= x1
- xc
;
1051 double dy
= y1
- yc
;
1052 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1053 double alpha1
, alpha2
;
1054 if (x1
== x2
&& y1
== y2
)
1059 else if ( wxIsNullDouble(radius
) )
1066 alpha1
= (x1
- xc
== 0) ?
1067 (y1
- yc
< 0) ? 90.0 : -90.0 :
1068 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1069 alpha2
= (x2
- xc
== 0) ?
1070 (y2
- yc
< 0) ? 90.0 : -90.0 :
1071 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1073 while (alpha1
<= 0) alpha1
+= 360;
1074 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1075 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1076 while (alpha2
> 360) alpha2
-= 360;
1079 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1081 SetBrush( m_brush
);
1082 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1083 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1085 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1088 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1091 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
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 );
1094 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1096 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1099 CalcBoundingBox (x1
, y1
);
1100 CalcBoundingBox (x2
, y2
);
1101 CalcBoundingBox (xc
, yc
);
1104 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1109 double xx
= XLOG2DEV(x
);
1110 double yy
= YLOG2DEV(y
);
1112 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1114 gs_libGnomePrint
->gnome_print_translate( m_gpc
, xx
, yy
);
1115 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1116 gs_libGnomePrint
->gnome_print_scale( m_gpc
, 1.0, scale
);
1121 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1123 SetBrush( m_brush
);
1125 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1126 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1127 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1128 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1130 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1133 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1137 gs_libGnomePrint
->gnome_print_arcto( m_gpc
, xx
, yy
,
1138 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1140 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1143 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1145 CalcBoundingBox( x
, y
);
1146 CalcBoundingBox( x
+w
, y
+h
);
1149 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1153 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1155 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1162 for ( i
=0; i
<n
; i
++ )
1163 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1165 gs_libGnomePrint
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1167 for (i
= 1; i
< n
; i
++)
1168 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1170 gs_libGnomePrint
->gnome_print_stroke ( m_gpc
);
1173 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1177 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1179 SetBrush( m_brush
);
1181 int x
= points
[0].x
+ xoffset
;
1182 int y
= points
[0].y
+ yoffset
;
1183 CalcBoundingBox( x
, y
);
1184 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1185 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1187 for (i
= 1; i
< n
; i
++)
1189 x
= points
[i
].x
+ xoffset
;
1190 y
= points
[i
].y
+ yoffset
;
1191 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1192 CalcBoundingBox( x
, y
);
1194 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1195 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1198 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1202 int x
= points
[0].x
+ xoffset
;
1203 int y
= points
[0].y
+ yoffset
;
1204 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1205 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1207 for (i
= 1; i
< n
; i
++)
1209 x
= points
[i
].x
+ xoffset
;
1210 y
= points
[i
].y
+ yoffset
;
1211 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1212 CalcBoundingBox( x
, y
);
1214 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1215 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1219 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1221 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1224 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1229 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1231 SetBrush( m_brush
);
1233 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1234 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1235 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1236 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1237 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1238 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1239 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1241 CalcBoundingBox( x
, y
);
1242 CalcBoundingBox( x
+ width
, y
+ height
);
1245 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1249 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1250 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1251 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1252 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1253 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1254 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1255 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1257 CalcBoundingBox( x
, y
);
1258 CalcBoundingBox( x
+ width
, y
+ height
);
1262 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1267 wxCoord rad
= wxRound( radius
);
1269 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1272 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1273 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1274 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1275 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1276 XLOG2DEV(x
),YLOG2DEV(y
),
1277 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1278 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1279 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1280 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1281 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1282 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1283 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1284 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1285 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1286 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1287 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1288 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1289 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1290 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1291 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1292 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1293 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1294 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1295 gs_libGnomePrint
->gnome_print_fill(m_gpc
);
1297 CalcBoundingBox(x
,y
);
1298 CalcBoundingBox(x
+width
,y
+height
);
1301 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1304 gs_libGnomePrint
->gnome_print_newpath(m_gpc
);
1305 gs_libGnomePrint
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1306 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1307 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1308 XLOG2DEV(x
),YLOG2DEV(y
),
1309 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1310 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1311 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1312 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1313 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1314 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1315 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1316 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1317 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1318 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1319 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1320 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1321 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1322 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1323 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1324 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1325 gs_libGnomePrint
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1326 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1327 gs_libGnomePrint
->gnome_print_stroke(m_gpc
);
1329 CalcBoundingBox(x
,y
);
1330 CalcBoundingBox(x
+width
,y
+height
);
1334 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1335 wxCoord width
, wxCoord height
)
1337 double r
= 4 * (sqrt(2.) - 1) / 3;
1338 double halfW
= 0.5 * width
,
1339 halfH
= 0.5 * height
,
1342 wxCoord halfWI
= (wxCoord
) halfW
,
1343 halfHI
= (wxCoord
) halfH
;
1345 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1347 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1348 gs_libGnomePrint
->gnome_print_moveto( m_gpc
,
1349 XLOG2DEV(x
+ width
),
1350 YLOG2DEV(y
+ halfHI
) );
1351 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1352 XLOG2DEV(x
+ width
),
1353 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1354 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1355 YLOG2DEV(y
+ height
),
1356 XLOG2DEV(x
+ halfWI
),
1357 YLOG2DEV(y
+ height
) );
1358 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1359 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1360 YLOG2DEV(y
+ height
),
1362 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1363 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1364 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1366 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1367 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1369 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1370 gs_libGnomePrint
->gnome_print_curveto( m_gpc
,
1371 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1373 XLOG2DEV(x
+ width
),
1374 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1375 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1377 gs_libGnomePrint
->gnome_print_closepath(m_gpc
);
1380 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1385 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1387 SetBrush( m_brush
);
1388 makeEllipticalPath( x
, y
, width
, height
);
1389 gs_libGnomePrint
->gnome_print_fill( m_gpc
);
1390 CalcBoundingBox( x
, y
);
1391 CalcBoundingBox( x
+ width
, y
+ height
);
1394 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1397 makeEllipticalPath( x
, y
, width
, height
);
1398 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1399 CalcBoundingBox( x
, y
);
1400 CalcBoundingBox( x
+ width
, y
+ height
);
1405 void wxGnomePrintDC::DoDrawSpline(const wxPointList
*points
)
1409 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1412 wxPointList::compatibility_iterator node
= points
->GetFirst();
1413 p
= node
->GetData();
1417 node
= node
->GetNext();
1418 p
= node
->GetData();
1422 (double)(x1
+ c
) / 2;
1424 (double)(y1
+ d
) / 2;
1426 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1427 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1428 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1430 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1431 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1433 node
= node
->GetNext();
1436 q
= node
->GetData();
1444 x3
= (double)(x2
+ c
) / 2;
1445 y3
= (double)(y2
+ d
) / 2;
1447 gs_libGnomePrint
->gnome_print_curveto(m_gpc
,
1448 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1449 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1450 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1452 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1453 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1455 node
= node
->GetNext();
1458 gs_libGnomePrint
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1460 gs_libGnomePrint
->gnome_print_stroke( m_gpc
);
1462 #endif // wxUSE_SPLINES
1464 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1465 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1466 wxCoord xsrcMask
, wxCoord ysrcMask
)
1468 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1470 // blit into a bitmap
1471 wxBitmap
bitmap( width
, height
);
1473 memDC
.SelectObject(bitmap
);
1474 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1475 memDC
.SelectObject(wxNullBitmap
);
1477 // draw bitmap. scaling and positioning is done there
1478 DrawBitmap( bitmap
, xdest
, ydest
);
1483 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1485 DoDrawBitmap( icon
, x
, y
, true );
1488 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1490 if (!bitmap
.Ok()) return;
1492 if (bitmap
.HasPixbuf())
1494 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1495 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1496 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1497 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1498 int height
= gdk_pixbuf_get_height( pixbuf
);
1499 int width
= gdk_pixbuf_get_width( pixbuf
);
1501 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1503 matrix
[0] = XLOG2DEVREL(width
);
1506 matrix
[3] = YLOG2DEVREL(height
);
1507 matrix
[4] = XLOG2DEV(x
);
1508 matrix
[5] = YLOG2DEV(y
+height
);
1509 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1510 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1512 gs_libGnomePrint
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1514 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1515 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1519 wxImage image
= bitmap
.ConvertToImage();
1521 if (!image
.Ok()) return;
1523 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1525 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1528 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1529 matrix
[4] = XLOG2DEV(x
);
1530 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1531 gs_libGnomePrint
->gnome_print_concat( m_gpc
, matrix
);
1532 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, 0, 0 );
1533 gs_libGnomePrint
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1534 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1538 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1540 DoDrawRotatedText( text
, x
, y
, 0.0 );
1543 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1545 double xx
= XLOG2DEV(x
);
1546 double yy
= YLOG2DEV(y
);
1548 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1550 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1551 #if wxUSE_UNICODE_UTF8
1552 const char *data
= text
.utf8_str();
1554 const wxCharBuffer data
= text
.utf8_str();
1557 size_t datalen
= strlen(data
);
1558 pango_layout_set_text( m_layout
, data
, datalen
);
1562 PangoAttrList
*attrs
= pango_attr_list_new();
1563 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1565 a
->end_index
= datalen
;
1566 pango_attr_list_insert(attrs
, a
);
1567 pango_layout_set_attributes(m_layout
, attrs
);
1568 pango_attr_list_unref(attrs
);
1571 if (m_textForegroundColour
.Ok())
1573 unsigned char red
= m_textForegroundColour
.Red();
1574 unsigned char blue
= m_textForegroundColour
.Blue();
1575 unsigned char green
= m_textForegroundColour
.Green();
1577 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1579 double redPS
= (double)(red
) / 255.0;
1580 double bluePS
= (double)(blue
) / 255.0;
1581 double greenPS
= (double)(green
) / 255.0;
1583 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1586 m_currentBlue
= blue
;
1587 m_currentGreen
= green
;
1592 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1594 if ( m_backgroundMode
== wxSOLID
)
1596 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1597 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, xx
, yy
, w
, h
);
1598 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1603 gs_libGnomePrint
->gnome_print_moveto (m_gpc
, xx
, yy
);
1605 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1607 gs_libGnomePrint
->gnome_print_scale( m_gpc
, m_scaleX
* DEV2PS
, m_scaleY
* DEV2PS
);
1609 if (fabs(angle
) > 0.00001)
1610 gs_libGnomePrint
->gnome_print_rotate( m_gpc
, angle
);
1612 gs_libGnomePrint
->gnome_print_pango_layout( m_gpc
, m_layout
);
1614 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1618 // undo underline attributes setting:
1619 pango_layout_set_attributes(m_layout
, NULL
);
1622 CalcBoundingBox (x
+ w
, y
+ h
);
1625 void wxGnomePrintDC::Clear()
1629 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1636 pango_font_description_free( m_fontdesc
);
1638 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1640 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1644 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1646 if (!pen
.Ok()) return;
1652 if (m_pen
.GetWidth() <= 0)
1655 width
= (double) m_pen
.GetWidth();
1657 gs_libGnomePrint
->gnome_print_setlinewidth( m_gpc
, width
* DEV2PS
* m_scaleX
);
1659 static const double dotted
[] = {2.0, 5.0};
1660 static const double short_dashed
[] = {4.0, 4.0};
1661 static const double wxCoord_dashed
[] = {4.0, 8.0};
1662 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1664 switch (m_pen
.GetStyle())
1666 case wxDOT
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1667 case wxSHORT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1668 case wxLONG_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1669 case wxDOT_DASH
: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1672 // It may be noted that libgnomeprint between at least
1673 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1674 // and then leak the memory since it doesn't set the
1675 // internal flag "privatedash" to 0.
1677 int num
= m_pen
.GetDashes (&wx_dashes
);
1678 gdouble
*g_dashes
= g_new( gdouble
, num
);
1680 for (i
= 0; i
< num
; ++i
)
1681 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1682 gs_libGnomePrint
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1688 default: gs_libGnomePrint
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1692 unsigned char red
= m_pen
.GetColour().Red();
1693 unsigned char blue
= m_pen
.GetColour().Blue();
1694 unsigned char green
= m_pen
.GetColour().Green();
1696 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1698 double redPS
= (double)(red
) / 255.0;
1699 double bluePS
= (double)(blue
) / 255.0;
1700 double greenPS
= (double)(green
) / 255.0;
1702 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1705 m_currentBlue
= blue
;
1706 m_currentGreen
= green
;
1710 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1712 if (!brush
.Ok()) return;
1717 unsigned char red
= m_brush
.GetColour().Red();
1718 unsigned char blue
= m_brush
.GetColour().Blue();
1719 unsigned char green
= m_brush
.GetColour().Green();
1723 // Anything not white is black
1724 if (! (red
== (unsigned char) 255 &&
1725 blue
== (unsigned char) 255 &&
1726 green
== (unsigned char) 255) )
1728 red
= (unsigned char) 0;
1729 green
= (unsigned char) 0;
1730 blue
= (unsigned char) 0;
1735 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1737 double redPS
= (double)(red
) / 255.0;
1738 double bluePS
= (double)(blue
) / 255.0;
1739 double greenPS
= (double)(green
) / 255.0;
1741 gs_libGnomePrint
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1744 m_currentBlue
= blue
;
1745 m_currentGreen
= green
;
1749 void wxGnomePrintDC::SetLogicalFunction( int function
)
1753 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1757 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1759 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1761 gs_libGnomePrint
->gnome_print_gsave( m_gpc
);
1763 gs_libGnomePrint
->gnome_print_newpath( m_gpc
);
1764 gs_libGnomePrint
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1765 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1766 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1767 gs_libGnomePrint
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1768 gs_libGnomePrint
->gnome_print_closepath( m_gpc
);
1769 gs_libGnomePrint
->gnome_print_clip( m_gpc
);
1772 void wxGnomePrintDC::DestroyClippingRegion()
1774 wxDC::DestroyClippingRegion();
1776 gs_libGnomePrint
->gnome_print_grestore( m_gpc
);
1779 // not needed, we set the values in each
1780 // drawing method anyways
1782 SetBrush( m_brush
);
1787 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1792 void wxGnomePrintDC::EndDoc()
1794 gs_libGnomePrint
->gnome_print_end_doc( m_gpc
);
1797 void wxGnomePrintDC::StartPage()
1799 gs_libGnomePrint
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1802 void wxGnomePrintDC::EndPage()
1804 gs_libGnomePrint
->gnome_print_showpage( m_gpc
);
1807 wxCoord
wxGnomePrintDC::GetCharHeight() const
1809 pango_layout_set_text( m_layout
, "H", 1 );
1812 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1817 wxCoord
wxGnomePrintDC::GetCharWidth() const
1819 pango_layout_set_text( m_layout
, "H", 1 );
1822 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1827 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1829 wxCoord
*externalLeading
,
1830 const wxFont
*theFont
) const
1838 if ( externalLeading
)
1839 *externalLeading
= 0;
1846 // Set layout's text
1848 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1849 #if wxUSE_UNICODE_UTF8
1850 const char *dataUTF8
= string
.utf8_str();
1852 const wxCharBuffer dataUTF8
= string
.utf8_str();
1855 PangoFontDescription
*desc
= (theFont
) ? theFont
->GetNativeFontInfo()->description
: m_fontdesc
;
1857 gint oldSize
= pango_font_description_get_size( desc
);
1858 double size
= oldSize
;
1859 size
= size
* m_scaleY
;
1860 pango_font_description_set_size( desc
, (gint
)size
);
1862 // apply scaled font
1863 pango_layout_set_font_description( m_layout
, desc
);
1865 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1868 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1872 *width
= (wxCoord
)(w
/ m_scaleX
);
1874 *height
= (wxCoord
)(h
/ m_scaleY
);
1878 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1879 int baseline
= pango_layout_iter_get_baseline(iter
);
1880 pango_layout_iter_free(iter
);
1881 *descent
= h
- PANGO_PIXELS(baseline
);
1884 // reset unscaled size
1885 pango_font_description_set_size( desc
, oldSize
);
1887 // reset unscaled font
1888 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1891 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1893 wxGnomePrintNativeData
*native
=
1894 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1896 // Query page size. This seems to omit the margins
1898 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1901 *width
= wxRound( pw
* PS2DEV
);
1904 *height
= wxRound( ph
* PS2DEV
);
1907 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1909 wxGnomePrintNativeData
*native
=
1910 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1912 // This code assumes values in Pts.
1915 gs_libGnomePrint
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1919 const GnomePrintUnit
*mm_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1920 const GnomePrintUnit
*pts_unit
= gs_libGnomePrint
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1921 gs_libGnomePrint
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1922 gs_libGnomePrint
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1925 *width
= (int) (pw
+ 0.5);
1927 *height
= (int) (ph
+ 0.5);
1930 wxSize
wxGnomePrintDC::GetPPI() const
1932 return wxSize(DPI
,DPI
);
1935 void wxGnomePrintDC::SetPrintData(const wxPrintData
& data
)
1940 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1941 GetSize( NULL
, &height
);
1943 GetSize( &height
, NULL
);
1944 m_deviceLocalOriginY
= height
;
1947 void wxGnomePrintDC::SetResolution(int ppi
)
1951 int wxGnomePrintDC::GetResolution()
1956 // ----------------------------------------------------------------------------
1957 // wxGnomePrintModule
1958 // ----------------------------------------------------------------------------
1960 bool wxGnomePrintModule::OnInit()
1962 gs_libGnomePrint
= new wxGnomePrintLibrary
;
1963 if (gs_libGnomePrint
->IsOk())
1964 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1968 void wxGnomePrintModule::OnExit()
1970 delete gs_libGnomePrint
;
1971 gs_libGnomePrint
= NULL
;
1974 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1976 // ----------------------------------------------------------------------------
1978 // ----------------------------------------------------------------------------
1980 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1982 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1983 wxPrintout
* WXUNUSED(printoutForPrinting
))
1988 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1989 wxPrintout
*printoutForPrinting
,
1990 wxPrintDialogData
*data
)
1991 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1993 Init(printout
, printoutForPrinting
);
1996 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1997 wxPrintout
*printoutForPrinting
,
1999 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2001 Init(printout
, printoutForPrinting
);
2004 wxGnomePrintPreview::~wxGnomePrintPreview()
2008 bool wxGnomePrintPreview::Print(bool interactive
)
2010 if (!m_printPrintout
)
2013 wxPrinter
printer(& m_printDialogData
);
2014 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2017 void wxGnomePrintPreview::DetermineScaling()
2019 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2020 if (paperType
== wxPAPER_NONE
)
2021 paperType
= wxPAPER_NONE
;
2023 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2025 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2029 wxSize ScreenPixels
= wxGetDisplaySize();
2030 wxSize ScreenMM
= wxGetDisplaySizeMM();
2032 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2033 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2034 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
2036 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2038 // TODO: get better resolution information from wxGnomePrintDC, if possible.
2040 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
2041 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
2042 wxSize
sizeTenthsMM(paper
->GetSize());
2043 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2045 // If in landscape mode, we need to swap the width and height.
2046 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2048 m_pageWidth
= sizeDevUnits
.y
;
2049 m_pageHeight
= sizeDevUnits
.x
;
2050 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2054 m_pageWidth
= sizeDevUnits
.x
;
2055 m_pageHeight
= sizeDevUnits
.y
;
2056 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2058 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2059 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2061 // At 100%, the page should look about page-size on the screen.
2062 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
2063 m_previewScaleY
= m_previewScaleX
;
2068 // wxUSE_LIBGNOMEPRINT