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>
43 static const double RAD2DEG
= 180.0 / M_PI
;
46 wxFORCE_LINK_THIS_MODULE(gnome_print
)
48 //----------------------------------------------------------------------------
49 // wxGnomePrintLibrary
50 //----------------------------------------------------------------------------
52 class wxGnomePrintLibrary
55 wxGnomePrintLibrary();
56 ~wxGnomePrintLibrary();
59 void InitializeMethods();
63 wxDynamicLibrary
*m_gnome_print_lib
;
64 wxDynamicLibrary
*m_gnome_printui_lib
;
67 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
68 (GnomePrintContext
*pc
), (pc
), 0 )
69 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
70 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
71 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
72 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
73 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
74 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
76 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
78 (GnomePrintContext
*pc
), (pc
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
80 (GnomePrintContext
*pc
), (pc
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
82 (GnomePrintContext
*pc
), (pc
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
84 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
86 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
88 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
91 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
93 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
95 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
96 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
98 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
100 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
102 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
105 (GnomePrintContext
*pc
), (pc
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
107 (GnomePrintContext
*pc
), (pc
), 0 )
109 wxDL_METHOD_DEFINE( gint
, gnome_print_clip
,
110 (GnomePrintContext
*pc
), (pc
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_eoclip
,
112 (GnomePrintContext
*pc
), (pc
), 0 )
114 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
115 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
117 (GnomePrintContext
*pc
), (pc
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
119 (GnomePrintContext
*pc
), (pc
), 0 )
121 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
122 (GnomePrintContext
*gpc
), (gpc
), NULL
)
123 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
124 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
126 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
127 (GnomePrintConfig
*config
), (config
), NULL
)
128 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
129 (GnomePrintJob
*job
), (job
), NULL
)
130 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
131 (GnomePrintJob
*job
), (job
), 0 )
132 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
133 (GnomePrintJob
*job
), (job
), 0 )
134 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
135 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
137 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
138 (const guchar
*abbreviation
), (abbreviation
), NULL
)
139 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
140 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
142 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
144 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
145 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
146 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_double
,
147 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
), (config
, key
, value
), false )
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_int
,
149 (GnomePrintConfig
*config
, const guchar
*key
, gint value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_boolean
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gboolean value
), (config
, key
, value
), false )
152 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set_length
,
153 (GnomePrintConfig
*config
, const guchar
*key
, gdouble value
, const GnomePrintUnit
*unit
), (config
, key
, value
, unit
), false )
155 wxDL_METHOD_DEFINE( guchar
*, gnome_print_config_get
,
156 (GnomePrintConfig
*config
, const guchar
*key
), (config
, key
), NULL
)
157 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
158 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
160 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
161 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
162 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
163 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
164 const guchar
*currentlabel
, const guchar
*rangelabel
),
165 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
166 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
167 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
168 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
169 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
170 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
171 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
172 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
173 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
175 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
176 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
178 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
179 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
181 DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
)
184 wxGnomePrintLibrary::wxGnomePrintLibrary()
186 m_gnome_print_lib
= NULL
;
187 m_gnome_printui_lib
= NULL
;
191 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
192 m_ok
= m_gnome_print_lib
->IsLoaded();
195 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
196 m_ok
= m_gnome_printui_lib
->IsLoaded();
202 wxGnomePrintLibrary::~wxGnomePrintLibrary()
204 if (m_gnome_print_lib
)
205 delete m_gnome_print_lib
;
206 if (m_gnome_printui_lib
)
207 delete m_gnome_printui_lib
;
210 bool wxGnomePrintLibrary::IsOk()
215 void wxGnomePrintLibrary::InitializeMethods()
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
225 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
237 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_clip
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_eoclip
, success
)
246 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
247 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
250 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
251 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
253 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
254 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
255 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
256 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
257 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
259 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
260 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
262 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
263 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
264 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set_boolean
, success
)
265 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set_double
, success
)
266 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set_int
, success
)
267 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set_length
, success
)
269 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get
, success
)
270 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
272 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
273 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
274 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
275 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
276 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
277 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
279 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
281 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
286 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
288 //----------------------------------------------------------------------------
289 // wxGnomePrintNativeData
290 //----------------------------------------------------------------------------
292 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
294 wxGnomePrintNativeData::wxGnomePrintNativeData()
296 m_config
= gs_lgp
->gnome_print_config_default();
297 m_job
= gs_lgp
->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_lgp
->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
);
318 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
320 if (data
.GetOrientation() == wxLANDSCAPE
)
322 gs_lgp
->gnome_print_config_set( m_config
,
323 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
324 (guchar
*)(char*)"R90" );
328 gs_lgp
->gnome_print_config_set( m_config
,
329 (guchar
*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION
,
330 (guchar
*)(char*)"R0" );
333 if (data
.GetCollate())
335 gs_lgp
->gnome_print_config_set_boolean( m_config
,
336 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
341 gs_lgp
->gnome_print_config_set_boolean( m_config
,
342 (guchar
*)(char*)GNOME_PRINT_KEY_COLLATE
,
346 switch (data
.GetPaperId())
348 case wxPAPER_A3
: gs_lgp
->gnome_print_config_set( m_config
,
349 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
350 (guchar
*)(char*)"A3" );
352 case wxPAPER_A5
: gs_lgp
->gnome_print_config_set( m_config
,
353 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
354 (guchar
*)(char*)"A5" );
356 case wxPAPER_B4
: gs_lgp
->gnome_print_config_set( m_config
,
357 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
358 (guchar
*)(char*)"B4" );
360 case wxPAPER_B5
: gs_lgp
->gnome_print_config_set( m_config
,
361 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
362 (guchar
*)(char*)"B5" );
364 case wxPAPER_LETTER
: gs_lgp
->gnome_print_config_set( m_config
,
365 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
366 (guchar
*)(char*)"USLetter" );
368 case wxPAPER_LEGAL
: gs_lgp
->gnome_print_config_set( m_config
,
369 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
370 (guchar
*)(char*)"USLegal" );
372 case wxPAPER_EXECUTIVE
: gs_lgp
->gnome_print_config_set( m_config
,
373 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
374 (guchar
*)(char*)"Executive" );
376 case wxPAPER_ENV_C5
: gs_lgp
->gnome_print_config_set( m_config
,
377 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
378 (guchar
*)(char*)"C5" );
380 case wxPAPER_ENV_C6
: gs_lgp
->gnome_print_config_set( m_config
,
381 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
382 (guchar
*)(char*)"C6" );
384 case wxPAPER_NONE
: break;
387 case wxPAPER_A4
: gs_lgp
->gnome_print_config_set( m_config
,
388 (guchar
*)(char*)GNOME_PRINT_KEY_PAPER_SIZE
,
389 (guchar
*)(char*)"A4" );
396 //----------------------------------------------------------------------------
397 // wxGnomePrintFactory
398 //----------------------------------------------------------------------------
400 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
402 return new wxGnomePrinter( data
);
405 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
406 wxPrintout
*printout
,
407 wxPrintDialogData
*data
)
409 return new wxGnomePrintPreview( preview
, printout
, data
);
412 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
413 wxPrintout
*printout
,
416 return new wxGnomePrintPreview( preview
, printout
, data
);
419 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
420 wxPrintDialogData
*data
)
422 return new wxGnomePrintDialog( parent
, data
);
425 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
428 return new wxGnomePrintDialog( parent
, data
);
431 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
432 wxPageSetupDialogData
* data
)
434 // The native page setup dialog is broken. It
435 // miscalculates newly entered values for the
436 // margins if you have not chose "points" but
437 // e.g. centimerters.
438 // This has been fixed in GNOME CVS (maybe
439 // fixed in libgnomeprintui 2.8.1)
441 return new wxGnomePageSetupDialog( parent
, data
);
444 bool wxGnomePrintFactory::HasPrintSetupDialog()
449 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
454 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
456 return new wxGnomePrintDC(data
);
459 bool wxGnomePrintFactory::HasOwnPrintToFile()
464 bool wxGnomePrintFactory::HasPrinterLine()
469 wxString
wxGnomePrintFactory::CreatePrinterLine()
472 return wxEmptyString
;
475 bool wxGnomePrintFactory::HasStatusLine()
481 wxString
wxGnomePrintFactory::CreateStatusLine()
484 return wxEmptyString
;
487 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
489 return new wxGnomePrintNativeData
;
492 //----------------------------------------------------------------------------
493 // wxGnomePrintSetupDialog
494 //----------------------------------------------------------------------------
496 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
498 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
499 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
500 wxPoint(0, 0), wxSize(600, 600),
501 wxDEFAULT_DIALOG_STYLE
|
505 m_printDialogData
= *data
;
510 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
511 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
512 wxPoint(0, 0), wxSize(600, 600),
513 wxDEFAULT_DIALOG_STYLE
|
517 m_printDialogData
= *data
;
522 void wxGnomePrintDialog::Init()
524 wxPrintData data
= m_printDialogData
.GetPrintData();
526 data
.ConvertToNative();
528 wxGnomePrintNativeData
*native
=
529 (wxGnomePrintNativeData
*) data
.GetNativeData();
531 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
533 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
536 if (m_printDialogData
.GetEnableSelection())
537 flag
|= GNOME_PRINT_RANGE_SELECTION
;
538 if (m_printDialogData
.GetEnablePageNumbers())
539 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
541 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
543 m_printDialogData
.GetMinPage(),
544 m_printDialogData
.GetMaxPage(),
549 wxGnomePrintDialog::~wxGnomePrintDialog()
554 int wxGnomePrintDialog::ShowModal()
556 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
558 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
560 gtk_widget_destroy(m_widget
);
566 m_printDialogData
.GetPrintData().ConvertFromNative();
569 gboolean collate
= false;
570 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
571 m_printDialogData
.SetNoCopies( copies
);
572 m_printDialogData
.SetCollate( collate
);
574 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
576 case GNOME_PRINT_RANGE_SELECTION
:
577 m_printDialogData
.SetSelection( true );
579 case GNOME_PRINT_RANGE_ALL
:
580 m_printDialogData
.SetAllPages( true );
581 m_printDialogData
.SetFromPage( 0 );
582 m_printDialogData
.SetToPage( 9999 );
584 case GNOME_PRINT_RANGE_RANGE
:
587 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
588 m_printDialogData
.SetFromPage( start
);
589 m_printDialogData
.SetToPage( end
);
593 gtk_widget_destroy(m_widget
);
596 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
602 wxDC
*wxGnomePrintDialog::GetPrintDC()
608 bool wxGnomePrintDialog::Validate()
613 bool wxGnomePrintDialog::TransferDataToWindow()
618 bool wxGnomePrintDialog::TransferDataFromWindow()
623 //----------------------------------------------------------------------------
624 // wxGnomePageSetupDialog
625 //----------------------------------------------------------------------------
627 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
629 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
630 wxPageSetupDialogData
* data
)
633 m_pageDialogData
= *data
;
635 m_pageDialogData
.GetPrintData().ConvertToNative();
637 wxGnomePrintNativeData
*native
=
638 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
640 // This *was* required as the page setup dialog
641 // calculates wrong values otherwise.
643 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
644 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
645 (const guchar
*) "Pts" );
648 GnomePrintConfig
*config
= native
->GetPrintConfig();
650 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
652 double ml
= (double) m_pageDialogData
.GetMarginTopLeft().x
;
653 double mt
= (double) m_pageDialogData
.GetMarginTopLeft().y
;
654 double mr
= (double) m_pageDialogData
.GetMarginBottomRight().x
;
655 double mb
= (double) m_pageDialogData
.GetMarginBottomRight().y
;
657 gs_lgp
->gnome_print_config_set_length (config
,
658 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, ml
, mm_unit
);
659 gs_lgp
->gnome_print_config_set_length (config
,
660 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, mr
, mm_unit
);
661 gs_lgp
->gnome_print_config_set_length (config
,
662 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, mt
, mm_unit
);
663 gs_lgp
->gnome_print_config_set_length (config
,
664 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, mb
, mm_unit
);
666 m_widget
= gtk_dialog_new();
668 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
670 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
671 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
672 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
673 gtk_widget_show (main
);
675 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
677 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
679 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
680 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
681 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
684 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
688 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
692 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
694 return m_pageDialogData
;
697 int wxGnomePageSetupDialog::ShowModal()
699 wxGnomePrintNativeData
*native
=
700 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
702 GnomePrintConfig
*config
= native
->GetPrintConfig();
705 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
707 if (ret
== GTK_RESPONSE_OK
)
709 // Transfer data back to m_pageDialogData
710 m_pageDialogData
.GetPrintData().ConvertFromNative();
712 // I don't know how querying the last parameter works
713 double ml
,mr
,mt
,mb
,pw
,ph
;
714 gs_lgp
->gnome_print_config_get_length (config
,
715 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
716 gs_lgp
->gnome_print_config_get_length (config
,
717 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
718 gs_lgp
->gnome_print_config_get_length (config
,
719 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
720 gs_lgp
->gnome_print_config_get_length (config
,
721 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
722 gs_lgp
->gnome_print_config_get_length (config
,
723 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
724 gs_lgp
->gnome_print_config_get_length (config
,
725 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
727 // This code converts correctly from what the user chose
728 // as the unit although I query Pts here
729 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
730 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
731 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
732 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
733 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
734 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
735 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
736 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
738 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
739 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
741 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
750 gtk_widget_destroy( m_widget
);
756 bool wxGnomePageSetupDialog::Validate()
761 bool wxGnomePageSetupDialog::TransferDataToWindow()
766 bool wxGnomePageSetupDialog::TransferDataFromWindow()
771 //----------------------------------------------------------------------------
773 //----------------------------------------------------------------------------
775 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
777 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
778 wxPrinterBase( data
)
780 m_native_preview
= false;
783 wxGnomePrinter::~wxGnomePrinter()
787 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
791 sm_lastError
= wxPRINTER_ERROR
;
795 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
797 wxGnomePrintNativeData
*native
=
798 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
800 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
802 // The GnomePrintJob is temporarily stored in the
803 // native print data as the native print dialog
804 // needs to access it.
805 native
->SetPrintJob( job
);
808 printout
->SetIsPreview(false);
810 if (m_printDialogData
.GetMinPage() < 1)
811 m_printDialogData
.SetMinPage(1);
812 if (m_printDialogData
.GetMaxPage() < 1)
813 m_printDialogData
.SetMaxPage(9999);
817 dc
= PrintDialog( parent
);
819 dc
= new wxGnomePrintDC( printdata
);
821 if (m_native_preview
)
822 printout
->SetIsPreview(true);
826 gs_lgp
->gnome_print_job_close( job
);
827 g_object_unref (job
);
828 if (sm_lastError
!= wxPRINTER_CANCELLED
)
829 sm_lastError
= wxPRINTER_ERROR
;
833 wxSize ScreenPixels
= wxGetDisplaySize();
834 wxSize ScreenMM
= wxGetDisplaySizeMM();
836 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
837 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
838 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
839 wxGnomePrintDC::GetResolution() );
845 printout
->SetPageSizePixels((int)w
, (int)h
);
846 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
848 dc
->GetSizeMM(&mw
, &mh
);
849 printout
->SetPageSizeMM((int)mw
, (int)mh
);
850 printout
->OnPreparePrinting();
852 // Get some parameters from the printout, if defined
853 int fromPage
, toPage
;
854 int minPage
, maxPage
;
855 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
859 gs_lgp
->gnome_print_job_close( job
);
860 g_object_unref (job
);
861 sm_lastError
= wxPRINTER_ERROR
;
865 printout
->OnBeginPrinting();
867 int minPageNum
= minPage
, maxPageNum
= maxPage
;
869 if ( !m_printDialogData
.GetAllPages() )
871 minPageNum
= m_printDialogData
.GetFromPage();
872 maxPageNum
= m_printDialogData
.GetToPage();
878 copyCount
<= m_printDialogData
.GetNoCopies();
881 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
883 wxLogError(_("Could not start printing."));
884 sm_lastError
= wxPRINTER_ERROR
;
889 for ( pn
= minPageNum
;
890 pn
<= maxPageNum
&& printout
->HasPage(pn
);
894 printout
->OnPrintPage(pn
);
898 printout
->OnEndDocument();
899 printout
->OnEndPrinting();
902 gs_lgp
->gnome_print_job_close( job
);
903 if (m_native_preview
)
905 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
906 GtkWidget
*preview
= gs_lgp
->gnome_print_job_preview_new
909 (const guchar
*)title
.data()
911 gtk_widget_show(preview
);
915 gs_lgp
->gnome_print_job_print( job
);
918 g_object_unref (job
);
921 return (sm_lastError
== wxPRINTER_NO_ERROR
);
924 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
926 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
927 int ret
= dialog
.ShowModal();
928 if (ret
== wxID_CANCEL
)
930 sm_lastError
= wxPRINTER_CANCELLED
;
934 m_native_preview
= ret
== wxID_PREVIEW
;
936 m_printDialogData
= dialog
.GetPrintDialogData();
937 return new wxGnomePrintDC( m_printDialogData
.GetPrintData() );
940 bool wxGnomePrinter::Setup( wxWindow
*parent
)
945 //-----------------------------------------------------------------------------
947 //-----------------------------------------------------------------------------
949 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
951 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
955 wxGnomePrintNativeData
*native
=
956 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
958 m_job
= native
->GetPrintJob();
959 m_gpc
= gs_lgp
->gnome_print_job_get_context (m_job
);
961 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
962 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
969 m_signX
= 1; // default x-axis left to right
970 m_signY
= -1; // default y-axis bottom up -> top down
972 GetSize( NULL
, &m_deviceOffsetY
);
975 wxGnomePrintDC::~wxGnomePrintDC()
979 bool wxGnomePrintDC::IsOk() const
984 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
989 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
994 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
996 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1000 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1001 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1002 gs_lgp
->gnome_print_stroke ( m_gpc
);
1004 CalcBoundingBox( x1
, y1
);
1005 CalcBoundingBox( x2
, y2
);
1008 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1012 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1014 double dx
= x1
- xc
;
1015 double dy
= y1
- yc
;
1016 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1017 double alpha1
, alpha2
;
1018 if (x1
== x2
&& y1
== y2
)
1026 alpha1
= alpha2
= 0.0;
1030 alpha1
= (x1
- xc
== 0) ?
1031 (y1
- yc
< 0) ? 90.0 : -90.0 :
1032 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1033 alpha2
= (x2
- xc
== 0) ?
1034 (y2
- yc
< 0) ? 90.0 : -90.0 :
1035 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1037 while (alpha1
<= 0) alpha1
+= 360;
1038 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
1039 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
1040 while (alpha2
> 360) alpha2
-= 360;
1043 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1045 SetBrush( m_brush
);
1046 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1047 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1049 gs_lgp
->gnome_print_fill( m_gpc
);
1052 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1055 gs_lgp
->gnome_print_newpath( m_gpc
);
1056 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
1057 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
1058 gs_lgp
->gnome_print_closepath( m_gpc
);
1060 gs_lgp
->gnome_print_stroke( m_gpc
);
1063 CalcBoundingBox (x1
, y1
);
1064 CalcBoundingBox (x2
, y2
);
1065 CalcBoundingBox (xc
, yc
);
1068 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1073 int xx
= XLOG2DEV(x
);
1074 int yy
= YLOG2DEV(y
);
1076 gs_lgp
->gnome_print_gsave( m_gpc
);
1078 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
1079 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1080 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
1085 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1087 SetBrush( m_brush
);
1089 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1090 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1091 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1092 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1094 gs_lgp
->gnome_print_fill( m_gpc
);
1097 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1101 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1102 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1104 gs_lgp
->gnome_print_stroke( m_gpc
);
1107 gs_lgp
->gnome_print_grestore( m_gpc
);
1109 CalcBoundingBox( x
, y
);
1110 CalcBoundingBox( x
+w
, y
+h
);
1113 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1117 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1119 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1126 for ( i
=0; i
<n
; i
++ )
1127 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1129 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1131 for (i
= 1; i
< n
; i
++)
1132 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1134 gs_lgp
->gnome_print_stroke ( m_gpc
);
1137 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1141 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1143 SetBrush( m_brush
);
1145 int x
= points
[0].x
+ xoffset
;
1146 int y
= points
[0].y
+ yoffset
;
1147 CalcBoundingBox( x
, y
);
1148 gs_lgp
->gnome_print_newpath( m_gpc
);
1149 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1151 for (i
= 1; i
< n
; i
++)
1153 int x
= points
[i
].x
+ xoffset
;
1154 int y
= points
[i
].y
+ yoffset
;
1155 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1156 CalcBoundingBox( x
, y
);
1158 gs_lgp
->gnome_print_closepath( m_gpc
);
1159 gs_lgp
->gnome_print_fill( m_gpc
);
1162 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1166 int x
= points
[0].x
+ xoffset
;
1167 int y
= points
[0].y
+ yoffset
;
1168 gs_lgp
->gnome_print_newpath( m_gpc
);
1169 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1171 for (i
= 1; i
< n
; i
++)
1173 int x
= points
[i
].x
+ xoffset
;
1174 int y
= points
[i
].y
+ yoffset
;
1175 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1176 CalcBoundingBox( x
, y
);
1178 gs_lgp
->gnome_print_closepath( m_gpc
);
1179 gs_lgp
->gnome_print_stroke( m_gpc
);
1183 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1185 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1188 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1190 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1192 SetBrush( m_brush
);
1194 gs_lgp
->gnome_print_newpath( m_gpc
);
1195 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1196 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1197 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1198 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1199 gs_lgp
->gnome_print_closepath( m_gpc
);
1200 gs_lgp
->gnome_print_fill( m_gpc
);
1202 CalcBoundingBox( x
, y
);
1203 CalcBoundingBox( x
+ width
, y
+ height
);
1206 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1210 gs_lgp
->gnome_print_newpath( m_gpc
);
1211 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1212 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1213 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1214 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1215 gs_lgp
->gnome_print_closepath( m_gpc
);
1216 gs_lgp
->gnome_print_stroke( m_gpc
);
1218 CalcBoundingBox( x
, y
);
1219 CalcBoundingBox( x
+ width
, y
+ height
);
1223 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1225 wxCoord rad
= (wxCoord
) radius
;
1227 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1230 gs_lgp
->gnome_print_newpath(m_gpc
);
1231 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1232 gs_lgp
->gnome_print_curveto(m_gpc
,
1233 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1234 XLOG2DEV(x
),YLOG2DEV(y
),
1235 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1236 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1237 gs_lgp
->gnome_print_curveto(m_gpc
,
1238 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1239 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1240 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1241 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1242 gs_lgp
->gnome_print_curveto(m_gpc
,
1243 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1244 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1245 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1246 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1247 gs_lgp
->gnome_print_curveto(m_gpc
,
1248 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1249 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1250 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1251 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1252 gs_lgp
->gnome_print_closepath(m_gpc
);
1253 gs_lgp
->gnome_print_fill(m_gpc
);
1255 CalcBoundingBox(x
,y
);
1256 CalcBoundingBox(x
+width
,y
+height
);
1259 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1262 gs_lgp
->gnome_print_newpath(m_gpc
);
1263 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1264 gs_lgp
->gnome_print_curveto(m_gpc
,
1265 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1266 XLOG2DEV(x
),YLOG2DEV(y
),
1267 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1268 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1269 gs_lgp
->gnome_print_curveto(m_gpc
,
1270 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1271 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1272 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1273 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1274 gs_lgp
->gnome_print_curveto(m_gpc
,
1275 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1276 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1277 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1278 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1279 gs_lgp
->gnome_print_curveto(m_gpc
,
1280 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1281 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1282 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1283 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1284 gs_lgp
->gnome_print_closepath(m_gpc
);
1285 gs_lgp
->gnome_print_stroke(m_gpc
);
1287 CalcBoundingBox(x
,y
);
1288 CalcBoundingBox(x
+width
,y
+height
);
1292 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1293 wxCoord width
, wxCoord height
)
1295 double r
= 4 * (sqrt(2.) - 1) / 3;
1296 double halfW
= 0.5 * width
,
1297 halfH
= 0.5 * height
,
1300 wxCoord halfWI
= (wxCoord
) halfW
,
1301 halfHI
= (wxCoord
) halfH
;
1303 gs_lgp
->gnome_print_newpath( m_gpc
);
1305 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1306 gs_lgp
->gnome_print_moveto( m_gpc
,
1307 XLOG2DEV(x
+ width
),
1308 YLOG2DEV(y
+ halfHI
) );
1309 gs_lgp
->gnome_print_curveto( m_gpc
,
1310 XLOG2DEV(x
+ width
),
1311 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1312 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1313 YLOG2DEV(y
+ height
),
1314 XLOG2DEV(x
+ halfWI
),
1315 YLOG2DEV(y
+ height
) );
1316 gs_lgp
->gnome_print_curveto( m_gpc
,
1317 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1318 YLOG2DEV(y
+ height
),
1320 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1321 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1322 gs_lgp
->gnome_print_curveto( m_gpc
,
1324 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1325 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1327 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1328 gs_lgp
->gnome_print_curveto( m_gpc
,
1329 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1331 XLOG2DEV(x
+ width
),
1332 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1333 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1335 gs_lgp
->gnome_print_closepath(m_gpc
);
1338 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1340 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1342 SetBrush( m_brush
);
1343 makeEllipticalPath( x
, y
, width
, height
);
1344 gs_lgp
->gnome_print_fill( m_gpc
);
1345 CalcBoundingBox( x
, y
);
1346 CalcBoundingBox( x
+ width
, y
+ height
);
1349 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1352 makeEllipticalPath( x
, y
, width
, height
);
1353 gs_lgp
->gnome_print_stroke( m_gpc
);
1354 CalcBoundingBox( x
, y
);
1355 CalcBoundingBox( x
+ width
, y
+ height
);
1360 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1364 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1367 wxList::compatibility_iterator node
= points
->GetFirst();
1368 p
= (wxPoint
*)node
->GetData();
1372 node
= node
->GetNext();
1373 p
= (wxPoint
*)node
->GetData();
1377 (double)(x1
+ c
) / 2;
1379 (double)(y1
+ d
) / 2;
1381 gs_lgp
->gnome_print_newpath( m_gpc
);
1382 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1383 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1385 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1386 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1388 node
= node
->GetNext();
1391 q
= (wxPoint
*)node
->GetData();
1399 x3
= (double)(x2
+ c
) / 2;
1400 y3
= (double)(y2
+ d
) / 2;
1402 gs_lgp
->gnome_print_curveto(m_gpc
,
1403 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1404 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1405 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1407 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1408 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1410 node
= node
->GetNext();
1413 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1415 gs_lgp
->gnome_print_stroke( m_gpc
);
1417 #endif // wxUSE_SPLINES
1419 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1420 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1421 wxCoord xsrcMask
, wxCoord ysrcMask
)
1423 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1425 // blit into a bitmap
1426 wxBitmap
bitmap( width
, height
);
1428 memDC
.SelectObject(bitmap
);
1429 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1430 memDC
.SelectObject(wxNullBitmap
);
1432 // draw bitmap. scaling and positioning is done there
1433 DrawBitmap( bitmap
, xdest
, ydest
);
1438 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1440 DoDrawBitmap( icon
, x
, y
, true );
1443 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1445 if (!bitmap
.Ok()) return;
1447 if (bitmap
.HasPixbuf())
1449 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1450 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1451 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1452 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1453 int height
= gdk_pixbuf_get_height( pixbuf
);
1454 int width
= gdk_pixbuf_get_width( pixbuf
);
1456 gs_lgp
->gnome_print_gsave( m_gpc
);
1458 matrix
[0] = XLOG2DEVREL(width
);
1461 matrix
[3] = YLOG2DEVREL(height
);
1462 matrix
[4] = XLOG2DEV(x
);
1463 matrix
[5] = YLOG2DEV(y
+height
);
1464 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1465 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1467 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1469 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1470 gs_lgp
->gnome_print_grestore( m_gpc
);
1474 wxImage image
= bitmap
.ConvertToImage();
1476 if (!image
.Ok()) return;
1478 gs_lgp
->gnome_print_gsave( m_gpc
);
1480 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1483 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1484 matrix
[4] = XLOG2DEV(x
);
1485 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1486 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1487 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1488 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1489 gs_lgp
->gnome_print_grestore( m_gpc
);
1493 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1495 DoDrawRotatedText( text
, x
, y
, 0.0 );
1498 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1503 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1505 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1506 #if wxUSE_UNICODE_UTF8
1507 const char *data
= text
.utf8_str();
1509 const wxCharBuffer data
= text
.utf8_str();
1512 size_t datalen
= strlen(data
);
1513 pango_layout_set_text( m_layout
, data
, datalen
);
1517 PangoAttrList
*attrs
= pango_attr_list_new();
1518 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1520 a
->end_index
= datalen
;
1521 pango_attr_list_insert(attrs
, a
);
1522 pango_layout_set_attributes(m_layout
, attrs
);
1523 pango_attr_list_unref(attrs
);
1526 if (m_textForegroundColour
.Ok())
1528 unsigned char red
= m_textForegroundColour
.Red();
1529 unsigned char blue
= m_textForegroundColour
.Blue();
1530 unsigned char green
= m_textForegroundColour
.Green();
1532 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1534 double redPS
= (double)(red
) / 255.0;
1535 double bluePS
= (double)(blue
) / 255.0;
1536 double greenPS
= (double)(green
) / 255.0;
1538 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1541 m_currentBlue
= blue
;
1542 m_currentGreen
= green
;
1548 if (fabs(m_scaleY
- 1.0) > 0.00001)
1550 // If there is a user or actually any scale applied to
1551 // the device context, scale the font.
1553 // scale font description
1554 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1555 double size
= oldSize
;
1556 size
= size
* m_scaleY
;
1557 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1559 // actually apply scaled font
1560 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1562 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1564 if ( m_backgroundMode
== wxSOLID
)
1566 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1567 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1568 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1572 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1573 if (fabs(angle
) > 0.00001)
1575 gs_lgp
->gnome_print_gsave( m_gpc
);
1576 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1577 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1578 gs_lgp
->gnome_print_grestore( m_gpc
);
1582 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1585 // reset unscaled size
1586 pango_font_description_set_size( m_fontdesc
, oldSize
);
1588 // actually apply unscaled font
1589 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1593 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1595 if ( m_backgroundMode
== wxSOLID
)
1597 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1598 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1599 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1603 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1604 if (fabs(angle
) > 0.00001)
1606 gs_lgp
->gnome_print_gsave( m_gpc
);
1607 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1608 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1609 gs_lgp
->gnome_print_grestore( m_gpc
);
1613 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1619 // undo underline attributes setting:
1620 pango_layout_set_attributes(m_layout
, NULL
);
1623 CalcBoundingBox (x
+ w
, y
+ h
);
1626 void wxGnomePrintDC::Clear()
1630 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1637 pango_font_description_free( m_fontdesc
);
1639 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1641 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1645 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1647 if (!pen
.Ok()) return;
1651 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1653 static const double dotted
[] = {2.0, 5.0};
1654 static const double short_dashed
[] = {4.0, 4.0};
1655 static const double wxCoord_dashed
[] = {4.0, 8.0};
1656 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1658 switch (m_pen
.GetStyle())
1660 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1661 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1662 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1663 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1666 // It may be noted that libgnomeprint between at least
1667 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1668 // and then leak the memory since it doesn't set the
1669 // internal flag "privatedash" to 0.
1671 int num
= m_pen
.GetDashes (&wx_dashes
);
1672 gdouble
*g_dashes
= g_new( gdouble
, num
);
1674 for (i
= 0; i
< num
; ++i
)
1675 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1676 gs_lgp
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1682 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1686 unsigned char red
= m_pen
.GetColour().Red();
1687 unsigned char blue
= m_pen
.GetColour().Blue();
1688 unsigned char green
= m_pen
.GetColour().Green();
1690 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1692 double redPS
= (double)(red
) / 255.0;
1693 double bluePS
= (double)(blue
) / 255.0;
1694 double greenPS
= (double)(green
) / 255.0;
1696 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1699 m_currentBlue
= blue
;
1700 m_currentGreen
= green
;
1704 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1706 if (!brush
.Ok()) return;
1711 unsigned char red
= m_brush
.GetColour().Red();
1712 unsigned char blue
= m_brush
.GetColour().Blue();
1713 unsigned char green
= m_brush
.GetColour().Green();
1717 // Anything not white is black
1718 if (! (red
== (unsigned char) 255 &&
1719 blue
== (unsigned char) 255 &&
1720 green
== (unsigned char) 255) )
1722 red
= (unsigned char) 0;
1723 green
= (unsigned char) 0;
1724 blue
= (unsigned char) 0;
1729 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1731 double redPS
= (double)(red
) / 255.0;
1732 double bluePS
= (double)(blue
) / 255.0;
1733 double greenPS
= (double)(green
) / 255.0;
1735 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1738 m_currentBlue
= blue
;
1739 m_currentGreen
= green
;
1743 void wxGnomePrintDC::SetLogicalFunction( int function
)
1747 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1751 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1753 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
1755 gs_lgp
->gnome_print_gsave( m_gpc
);
1757 gs_lgp
->gnome_print_newpath( m_gpc
);
1758 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1759 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1760 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1761 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1762 gs_lgp
->gnome_print_closepath( m_gpc
);
1763 gs_lgp
->gnome_print_clip( m_gpc
);
1766 void wxGnomePrintDC::DestroyClippingRegion()
1768 wxDC::DestroyClippingRegion();
1770 gs_lgp
->gnome_print_grestore( m_gpc
);
1773 // not needed, we set the values in each
1774 // drawing method anyways
1776 SetBrush( m_brush
);
1781 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1786 void wxGnomePrintDC::EndDoc()
1788 gs_lgp
->gnome_print_end_doc( m_gpc
);
1791 void wxGnomePrintDC::StartPage()
1793 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1796 void wxGnomePrintDC::EndPage()
1798 gs_lgp
->gnome_print_showpage( m_gpc
);
1801 wxCoord
wxGnomePrintDC::GetCharHeight() const
1803 pango_layout_set_text( m_layout
, "H", 1 );
1806 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1811 wxCoord
wxGnomePrintDC::GetCharWidth() const
1813 pango_layout_set_text( m_layout
, "H", 1 );
1816 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1821 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1823 wxCoord
*externalLeading
,
1824 const wxFont
*theFont
) const
1832 if ( externalLeading
)
1833 *externalLeading
= 0;
1840 // Set layout's text
1842 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1843 #if wxUSE_UNICODE_UTF8
1844 const char *dataUTF8
= string
.utf8_str();
1846 const wxCharBuffer dataUTF8
= string
.utf8_str();
1849 PangoFontDescription
*desc
= (theFont
) ? theFont
->GetNativeFontInfo()->description
: m_fontdesc
;
1851 gint oldSize
= pango_font_description_get_size( desc
);
1852 double size
= oldSize
;
1853 size
= size
* m_scaleY
;
1854 pango_font_description_set_size( desc
, (gint
)size
);
1856 // apply scaled font
1857 pango_layout_set_font_description( m_layout
, desc
);
1859 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1862 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1866 *width
= (wxCoord
)(w
/ m_scaleX
);
1868 *height
= (wxCoord
)(h
/ m_scaleY
);
1872 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1873 int baseline
= pango_layout_iter_get_baseline(iter
);
1874 pango_layout_iter_free(iter
);
1875 *descent
= h
- PANGO_PIXELS(baseline
);
1878 // reset unscaled size
1879 pango_font_description_set_size( desc
, oldSize
);
1881 // reset unscaled font
1882 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1885 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1887 wxGnomePrintNativeData
*native
=
1888 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1890 // Query page size. This seems to omit the margins
1892 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1895 *width
= (int) (pw
+ 0.5);
1897 *height
= (int) (ph
+ 0.5);
1900 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1902 wxGnomePrintNativeData
*native
=
1903 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1905 // This code assumes values in Pts.
1908 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1912 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1913 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1914 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1915 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1918 *width
= (int) (pw
+ 0.5);
1920 *height
= (int) (ph
+ 0.5);
1923 wxSize
wxGnomePrintDC::GetPPI() const
1925 return wxSize(72,72);
1928 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1930 m_signX
= (xLeftRight
? 1 : -1);
1931 m_signY
= (yBottomUp
? 1 : -1);
1933 ComputeScaleAndOrigin();
1936 void wxGnomePrintDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1938 wxDC::SetLogicalOrigin( x
, y
);
1941 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1943 wxDC::SetDeviceOrigin( x
, y
);
1946 void wxGnomePrintDC::SetPrintData(const wxPrintData
& data
)
1950 if (m_printData
.GetOrientation() == wxPORTRAIT
)
1951 GetSize( NULL
, &m_deviceOffsetY
);
1953 GetSize( &m_deviceOffsetY
, NULL
);
1956 void wxGnomePrintDC::SetResolution(int ppi
)
1960 int wxGnomePrintDC::GetResolution()
1965 // ----------------------------------------------------------------------------
1966 // wxGnomePrintModule
1967 // ----------------------------------------------------------------------------
1969 bool wxGnomePrintModule::OnInit()
1971 gs_lgp
= new wxGnomePrintLibrary
;
1973 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1977 void wxGnomePrintModule::OnExit()
1982 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1984 // ----------------------------------------------------------------------------
1986 // ----------------------------------------------------------------------------
1988 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1990 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1991 wxPrintout
* WXUNUSED(printoutForPrinting
))
1996 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1997 wxPrintout
*printoutForPrinting
,
1998 wxPrintDialogData
*data
)
1999 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2001 Init(printout
, printoutForPrinting
);
2004 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
2005 wxPrintout
*printoutForPrinting
,
2007 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2009 Init(printout
, printoutForPrinting
);
2012 wxGnomePrintPreview::~wxGnomePrintPreview()
2016 bool wxGnomePrintPreview::Print(bool interactive
)
2018 if (!m_printPrintout
)
2021 wxPrinter
printer(& m_printDialogData
);
2022 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2025 void wxGnomePrintPreview::DetermineScaling()
2027 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2028 if (paperType
== wxPAPER_NONE
)
2029 paperType
= wxPAPER_NONE
;
2031 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2033 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2037 wxSize ScreenPixels
= wxGetDisplaySize();
2038 wxSize ScreenMM
= wxGetDisplaySizeMM();
2040 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2041 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2042 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
2044 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2046 // TODO: get better resolution information from wxGnomePrintDC, if possible.
2048 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
2049 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
2050 wxSize
sizeTenthsMM(paper
->GetSize());
2051 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2053 // If in landscape mode, we need to swap the width and height.
2054 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2056 m_pageWidth
= sizeDevUnits
.y
;
2057 m_pageHeight
= sizeDevUnits
.x
;
2058 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2062 m_pageWidth
= sizeDevUnits
.x
;
2063 m_pageHeight
= sizeDevUnits
.y
;
2064 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2066 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2067 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2069 // At 100%, the page should look about page-size on the screen.
2070 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
2071 m_previewScaleY
= m_previewScaleX
;
2076 // wxUSE_LIBGNOMEPRINT