1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
25 #include "wx/dcprint.h"
29 #include "wx/module.h"
33 #include "wx/fontutil.h"
34 #include "wx/gtk/private.h"
35 #include "wx/dynlib.h"
40 #if wxUSE_GRAPHICS_CONTEXT
41 #include "wx/graphics.h"
45 wxFORCE_LINK_THIS_MODULE(gtk_print
)
47 #if wxUSE_LIBGNOMEPRINT
48 #include "wx/gtk/gnome/gprint.h"
51 // Usefull to convert angles from/to Rad to/from Deg.
52 static const double RAD2DEG
= 180.0 / M_PI
;
53 static const double DEG2RAD
= M_PI
/ 180.0;
55 //----------------------------------------------------------------------------
57 // Initialized when starting the app : if it successfully load the gtk-print framework,
58 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
59 // to postscript if gnomeprint is not available.
60 //----------------------------------------------------------------------------
62 class wxGtkPrintModule
: public wxModule
67 #if wxUSE_LIBGNOMEPRINT
68 // This module must be initialized AFTER gnomeprint's one
69 AddDependency(CLASSINFO(wxGnomePrintModule
));
76 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
79 bool wxGtkPrintModule::OnInit()
81 if (gtk_check_version(2,10,0) == NULL
)
82 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
86 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
88 //----------------------------------------------------------------------------
90 //----------------------------------------------------------------------------
92 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
94 return new wxGtkPrinter( data
);
97 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
99 wxPrintDialogData
*data
)
101 return new wxGtkPrintPreview( preview
, printout
, data
);
104 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
105 wxPrintout
*printout
,
108 return new wxGtkPrintPreview( preview
, printout
, data
);
111 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
112 wxPrintDialogData
*data
)
114 return new wxGtkPrintDialog( parent
, data
);
117 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
120 return new wxGtkPrintDialog( parent
, data
);
123 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
124 wxPageSetupDialogData
* data
)
126 return new wxGtkPageSetupDialog( parent
, data
);
129 bool wxGtkPrintFactory::HasPrintSetupDialog()
135 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
136 wxPrintData
* WXUNUSED(data
))
141 wxDCImpl
* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
143 return new wxGtkPrinterDCImpl( owner
, data
);
146 bool wxGtkPrintFactory::HasOwnPrintToFile()
151 bool wxGtkPrintFactory::HasPrinterLine()
156 wxString
wxGtkPrintFactory::CreatePrinterLine()
159 return wxEmptyString
;
162 bool wxGtkPrintFactory::HasStatusLine()
168 wxString
wxGtkPrintFactory::CreateStatusLine()
171 return wxEmptyString
;
174 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
176 return new wxGtkPrintNativeData
;
179 //----------------------------------------------------------------------------
180 // Callback functions for Gtk Printings.
181 //----------------------------------------------------------------------------
183 // We use it to pass useful objects to GTK printing callback functions.
184 struct wxPrinterToGtkData
186 wxGtkPrinter
* printer
;
187 wxPrintout
* printout
;
192 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
194 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
196 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
199 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
201 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
203 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
206 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
207 GtkPrintContext
* WXUNUSED(context
),
210 wxPrintout
*printout
= (wxPrintout
*) user_data
;
212 printout
->OnEndPrinting();
216 //----------------------------------------------------------------------------
217 // wxGtkPrintNativeData
218 //----------------------------------------------------------------------------
220 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
222 wxGtkPrintNativeData::wxGtkPrintNativeData()
224 m_config
= gtk_print_settings_new();
227 wxGtkPrintNativeData::~wxGtkPrintNativeData()
229 g_object_unref (m_config
);
232 // Convert datas stored in m_config to a wxPrintData.
233 // Called by wxPrintData::ConvertFromNative().
234 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
239 int resolution
= gtk_print_settings_get_resolution(m_config
);
240 if ( resolution
> 0 )
242 // if resolution is explicitly set, use it
243 data
.SetQuality(resolution
);
245 else // use more vague "quality"
247 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
248 if (quality
== GTK_PRINT_QUALITY_HIGH
)
249 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
250 else if (quality
== GTK_PRINT_QUALITY_LOW
)
251 data
.SetQuality(wxPRINT_QUALITY_LOW
);
252 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
253 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
255 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
258 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
260 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
262 switch (gtk_print_settings_get_duplex(m_config
))
264 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
267 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
271 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
275 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
276 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
278 data
.SetOrientation(wxPORTRAIT
);
279 data
.SetOrientationReversed(false);
281 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
283 data
.SetOrientation(wxLANDSCAPE
);
284 data
.SetOrientationReversed(false);
286 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
288 data
.SetOrientation(wxPORTRAIT
);
289 data
.SetOrientationReversed(true);
291 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
293 data
.SetOrientation(wxLANDSCAPE
);
294 data
.SetOrientationReversed(true);
297 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
299 // Paper formats : these are the most common paper formats.
300 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
302 data
.SetPaperId(wxPAPER_NONE
);
303 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
304 data
.SetPaperId(wxPAPER_A3
);
305 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
306 data
.SetPaperId(wxPAPER_A4
);
307 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
308 data
.SetPaperId(wxPAPER_A5
);
309 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
310 data
.SetPaperId(wxPAPER_B5
);
311 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
312 data
.SetPaperId(wxPAPER_LETTER
);
313 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
314 data
.SetPaperId(wxPAPER_LEGAL
);
315 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
316 data
.SetPaperId(wxPAPER_EXECUTIVE
);
317 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
318 data
.SetPaperId(wxPAPER_ENV_10
);
319 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
320 data
.SetPaperId(wxPAPER_ENV_C5
);
321 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
322 data
.SetPaperId(wxPAPER_ENV_C6
);
323 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
324 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
325 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
326 data
.SetPaperId(wxPAPER_ENV_B5
);
327 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
328 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
329 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
330 data
.SetPaperId( wxPAPER_CSHEET
);
331 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
332 data
.SetPaperId( wxPAPER_DSHEET
);
333 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
334 data
.SetPaperId( wxPAPER_ESHEET
);
335 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
336 data
.SetPaperId( wxPAPER_LETTERSMALL
);
337 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
338 data
.SetPaperId( wxPAPER_TABLOID
);
339 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
340 data
.SetPaperId( wxPAPER_LEDGER
);
341 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
342 data
.SetPaperId( wxPAPER_STATEMENT
);
343 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
344 data
.SetPaperId( wxPAPER_A4SMALL
);
345 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
346 data
.SetPaperId( wxPAPER_B4
);
347 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
348 data
.SetPaperId( wxPAPER_FOLIO
);
349 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
350 data
.SetPaperId( wxPAPER_QUARTO
);
351 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
352 data
.SetPaperId( wxPAPER_10X14
);
353 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
354 data
.SetPaperId( wxPAPER_11X17
);
355 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
356 data
.SetPaperId( wxPAPER_NOTE
);
357 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
358 data
.SetPaperId( wxPAPER_ENV_9
);
359 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
360 data
.SetPaperId( wxPAPER_ENV_11
);
361 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
362 data
.SetPaperId( wxPAPER_ENV_12
);
363 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
364 data
.SetPaperId( wxPAPER_ENV_14
);
365 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
366 data
.SetPaperId( wxPAPER_ENV_DL
);
367 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
368 data
.SetPaperId( wxPAPER_ENV_C3
);
369 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
370 data
.SetPaperId( wxPAPER_ENV_C4
);
371 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
372 data
.SetPaperId( wxPAPER_ENV_C65
);
373 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
374 data
.SetPaperId( wxPAPER_ENV_B4
);
375 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
376 data
.SetPaperId( wxPAPER_ENV_B6
);
377 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
378 data
.SetPaperId( wxPAPER_ENV_ITALY
);
379 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
380 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
381 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
382 data
.SetPaperId( wxPAPER_FANFOLD_US
);
383 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
384 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
385 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
386 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
388 data
.SetPaperId(wxPAPER_NONE
);
392 // Put datas given by the wxPrintData into m_config.
393 // Called by wxPrintData::ConvertToNative().
394 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
399 wxPrintQuality quality
= data
.GetQuality();
400 if (quality
== wxPRINT_QUALITY_HIGH
)
401 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
402 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
403 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
404 else if (quality
== wxPRINT_QUALITY_LOW
)
405 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
406 else if (quality
== wxPRINT_QUALITY_DRAFT
)
407 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
408 else if (quality
> 1)
409 gtk_print_settings_set_resolution (m_config
, quality
);
411 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
413 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
415 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
417 switch (data
.GetDuplex())
419 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
422 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
426 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
430 if (!data
.IsOrientationReversed())
432 if (data
.GetOrientation() == wxLANDSCAPE
)
433 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
435 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
438 if (data
.GetOrientation() == wxLANDSCAPE
)
439 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
441 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
444 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
446 // Paper formats: these are the most common paper formats.
447 switch (data
.GetPaperId())
449 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
451 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
453 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
455 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
457 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
459 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
461 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
463 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
465 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
467 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
469 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
471 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
473 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
475 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
477 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
479 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
481 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
483 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
485 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
487 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
489 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
491 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
493 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
495 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
497 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
499 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
501 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
503 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
505 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
507 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
509 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
511 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
513 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
515 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
517 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
519 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
521 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
523 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
525 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
527 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
529 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
531 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
540 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
543 m_config
= gtk_print_settings_copy(config
);
546 // Extract page setup from settings.
547 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
549 GtkPageSetup
* page_setup
= gtk_page_setup_new();
550 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
552 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
553 if (paper_size
!= NULL
)
554 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
559 // Insert page setup into a given GtkPrintSettings.
560 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
562 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
563 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
566 //----------------------------------------------------------------------------
568 //----------------------------------------------------------------------------
570 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
572 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
573 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
574 wxPoint(0, 0), wxSize(600, 600),
575 wxDEFAULT_DIALOG_STYLE
|
579 m_printDialogData
= *data
;
585 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
586 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
587 wxPoint(0, 0), wxSize(600, 600),
588 wxDEFAULT_DIALOG_STYLE
|
592 m_printDialogData
= *data
;
599 wxGtkPrintDialog::~wxGtkPrintDialog()
603 // This is called even if we actually don't want the dialog to appear.
604 int wxGtkPrintDialog::ShowModal()
606 GtkPrintOperationResult response
;
608 // We need to restore the settings given in the constructor.
609 wxPrintData data
= m_printDialogData
.GetPrintData();
610 wxGtkPrintNativeData
*native
=
611 (wxGtkPrintNativeData
*) data
.GetNativeData();
612 data
.ConvertToNative();
614 GtkPrintSettings
* settings
= native
->GetPrintConfig();
616 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
617 int fromPage
= m_printDialogData
.GetFromPage();
618 int toPage
= m_printDialogData
.GetToPage();
619 if (m_printDialogData
.GetSelection())
620 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
621 else if (m_printDialogData
.GetAllPages())
622 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
624 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
626 range
= g_new (GtkPageRange
, 1);
627 range
[0].start
= fromPage
-1;
628 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
629 gtk_print_settings_set_page_ranges (settings
, range
, 1);
632 // If the settings are OK, we restore it.
633 if (settings
!= NULL
)
634 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
635 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
637 // Show the dialog if needed.
638 GError
* gError
= NULL
;
640 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
642 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
644 // Does everything went well?
645 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
649 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
651 g_error_free (gError
);
652 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
653 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
656 // Now get the settings and save it.
657 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
658 native
->SetPrintConfig(newSettings
);
659 data
.ConvertFromNative();
661 // Same problem as a few lines before.
662 switch (gtk_print_settings_get_print_pages(newSettings
))
664 case GTK_PRINT_PAGES_CURRENT
:
665 m_printDialogData
.SetSelection( true );
667 case GTK_PRINT_PAGES_RANGES
:
668 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
669 // For example, the user enters "1-3;5-7" in the dialog: pages 1-3 and 5-7 will be correctly printed when the user
670 // will hit "OK" button. However we can only save 1-3 in the print data.
673 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
676 m_printDialogData
.SetFromPage( range
[0].start
);
677 m_printDialogData
.SetToPage( range
[0].end
);
680 m_printDialogData
.SetAllPages( true );
681 m_printDialogData
.SetFromPage( 0 );
682 m_printDialogData
.SetToPage( 9999 );
685 case GTK_PRINT_PAGES_ALL
:
687 m_printDialogData
.SetAllPages( true );
688 m_printDialogData
.SetFromPage( 0 );
689 m_printDialogData
.SetToPage( 9999 );
696 //----------------------------------------------------------------------------
697 // wxGtkPageSetupDialog
698 //----------------------------------------------------------------------------
700 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
702 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
703 wxPageSetupDialogData
* data
)
706 m_pageDialogData
= *data
;
711 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
715 int wxGtkPageSetupDialog::ShowModal()
718 m_pageDialogData
.GetPrintData().ConvertToNative();
719 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
720 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
722 // We only need the pagesetup data which are part of the settings.
723 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
725 // If the user used a custom paper format the last time he printed, we have to restore it too.
726 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
728 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
729 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
731 wxString title
= _("Custom size");
732 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
733 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
734 g_object_unref(customSize
);
738 // Now show the dialog.
739 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
744 if (newPageSetup
!= oldPageSetup
)
746 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
747 m_pageDialogData
.GetPrintData().ConvertFromNative();
749 // Store custom paper format if any.
750 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
752 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
753 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
754 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
755 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
756 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
758 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
759 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
761 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
762 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
764 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
777 //----------------------------------------------------------------------------
779 //----------------------------------------------------------------------------
781 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
783 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
784 wxPrinterBase( data
)
789 m_printDialogData
= *data
;
792 wxGtkPrinter::~wxGtkPrinter()
796 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
800 sm_lastError
= wxPRINTER_ERROR
;
804 // Let's correct the PageInfo just in case the app gives wrong values.
805 int fromPage
, toPage
;
806 int minPage
, maxPage
;
807 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
808 m_printDialogData
.SetAllPages(true);
810 if (minPage
< 1) minPage
= 1;
811 if (maxPage
< 1) maxPage
= 9999;
812 if (maxPage
< minPage
) maxPage
= minPage
;
814 m_printDialogData
.SetMinPage(minPage
);
815 m_printDialogData
.SetMaxPage(maxPage
);
818 if (fromPage
< minPage
) fromPage
= minPage
;
819 else if (fromPage
> maxPage
) fromPage
= maxPage
;
820 m_printDialogData
.SetFromPage(fromPage
);
824 m_printDialogData
.SetToPage(toPage
);
825 if (toPage
> maxPage
) toPage
= maxPage
;
826 else if (toPage
< minPage
) toPage
= minPage
;
829 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
832 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
833 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
835 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
837 native
->SetPrintJob( printOp
);
839 printout
->SetIsPreview(false);
841 wxPrinterToGtkData dataToSend
;
842 dataToSend
.printer
= this;
843 dataToSend
.printout
= printout
;
845 // These Gtk signals are caught here.
846 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
847 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
848 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
850 // This is used to setup the DC and
851 // show the dialog if desired
852 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
853 dialog
.SetPrintDC(m_dc
);
854 dialog
.SetShowDialog(prompt
);
856 // doesn't necessarily show
857 int ret
= dialog
.ShowModal();
858 if (ret
== wxID_CANCEL
)
860 sm_lastError
= wxPRINTER_CANCELLED
;
864 sm_lastError
= wxPRINTER_ERROR
;
865 wxFAIL_MSG(_("The print dialog returned an error."));
868 g_object_unref (printOp
);
870 return (sm_lastError
== wxPRINTER_NO_ERROR
);
873 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
875 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
876 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
878 // We need to update printdata with the new data from the dialog and we
879 // have to do this here because this method needs this new data and we
880 // cannot update it earlier
881 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
882 printdata
.ConvertFromNative();
884 SetPrintContext(context
);
885 native
->SetPrintContext( context
);
887 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
892 if (sm_lastError
!= wxPRINTER_CANCELLED
)
894 sm_lastError
= wxPRINTER_ERROR
;
895 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
900 printout
->SetPPIScreen(wxGetDisplayPPI());
901 printout
->SetPPIPrinter( printDC
->GetResolution(),
902 printDC
->GetResolution() );
904 printout
->SetDC(m_dc
);
907 m_dc
->GetSize(&w
, &h
);
908 printout
->SetPageSizePixels((int)w
, (int)h
);
909 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
911 m_dc
->GetSizeMM(&mw
, &mh
);
912 printout
->SetPageSizeMM((int)mw
, (int)mh
);
913 printout
->OnPreparePrinting();
915 // Get some parameters from the printout, if defined.
916 int fromPage
, toPage
;
917 int minPage
, maxPage
;
918 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
922 sm_lastError
= wxPRINTER_ERROR
;
923 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
927 printout
->OnBeginPrinting();
931 // If we're not previewing we need to calculate the number of pages to print.
932 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
933 // have defined in the dialog. So the number of pages is the maximum available.
934 if (!printout
->IsPreview())
936 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
937 switch (gtk_print_settings_get_print_pages(settings
))
939 case GTK_PRINT_PAGES_CURRENT
:
942 case GTK_PRINT_PAGES_RANGES
:
943 {gint num_ranges
= 0;
946 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
947 for (i
=0; i
<num_ranges
; i
++)
949 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
950 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
951 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
952 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
953 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
955 gtk_print_settings_set_page_ranges (settings
, range
, 1);
957 case GTK_PRINT_PAGES_ALL
:
959 numPages
= maxPage
- minPage
+ 1;
963 else numPages
= maxPage
- minPage
+ 1;
965 gtk_print_operation_set_n_pages(operation
, numPages
);
968 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
969 GtkPrintOperation
*operation
,
970 GtkPrintContext
* WXUNUSED(context
),
973 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
974 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
976 int numPageToDraw
= page_nr
+ minPage
;
977 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
978 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
980 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
981 switch (gtk_print_settings_get_print_pages(settings
))
983 case GTK_PRINT_PAGES_CURRENT
:
984 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
985 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
987 case GTK_PRINT_PAGES_RANGES
:
988 {gint num_ranges
= 0;
990 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
991 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
994 startPage
= range
[0].start
+ 1;
995 endPage
= range
[0].end
+ 1;
1002 case GTK_PRINT_PAGES_ALL
:
1004 startPage
= minPage
;
1009 if(numPageToDraw
== startPage
)
1011 if (!printout
->OnBeginDocument(startPage
, endPage
))
1013 wxLogError(_("Could not start printing."));
1014 sm_lastError
= wxPRINTER_ERROR
;
1018 // The app can render the page numPageToDraw.
1019 if (printout
->HasPage(numPageToDraw
))
1022 printout
->OnPrintPage(numPageToDraw
);
1027 if(numPageToDraw
== endPage
)
1029 printout
->OnEndDocument();
1033 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1035 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1037 dialog
.SetPrintDC(m_dc
);
1038 dialog
.SetShowDialog(true);
1040 int ret
= dialog
.ShowModal();
1042 if (ret
== wxID_CANCEL
)
1044 sm_lastError
= wxPRINTER_CANCELLED
;
1049 sm_lastError
= wxPRINTER_ERROR
;
1050 wxFAIL_MSG(_("The print dialog returned an error."));
1054 m_printDialogData
= dialog
.GetPrintDialogData();
1056 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1059 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1061 // Obsolete, for backward compatibility.
1065 //-----------------------------------------------------------------------------
1067 //-----------------------------------------------------------------------------
1069 #define wxCAIRO_SCALE 1
1073 #define XLOG2DEV(x) LogicalToDeviceX(x)
1074 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1075 #define YLOG2DEV(x) LogicalToDeviceY(x)
1076 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1080 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1081 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1082 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1083 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1087 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1089 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1094 wxGtkPrintNativeData
*native
=
1095 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1097 m_gpc
= native
->GetPrintContext();
1099 // Match print quality to resolution (high = 1200dpi)
1100 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1101 if (m_resolution
< 0)
1102 m_resolution
= (1 << (m_resolution
+4)) *150;
1104 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1105 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1106 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1108 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1114 cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1116 m_PS2DEV
= (double)m_resolution
/ 72.0;
1117 m_DEV2PS
= 72.0 / (double)m_resolution
;
1124 m_signX
= 1; // default x-axis left to right.
1125 m_signY
= 1; // default y-axis bottom up -> top down.
1127 // By default the origin of the Cairo context is in the upper left
1128 // corner of the printable area. We need to translate it so that it
1129 // is in the upper left corner of the paper (without margins)
1130 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1132 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1133 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1134 cairo_translate(m_cairo
, -ml
, -mt
);
1137 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1139 g_object_unref(m_context
);
1140 g_object_unref(m_layout
);
1143 bool wxGtkPrinterDCImpl::IsOk() const
1145 return m_gpc
!= NULL
;
1148 void* wxGtkPrinterDCImpl::GetCairoContext() const
1150 return (void*) cairo_reference( m_cairo
);
1153 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1154 wxCoord
WXUNUSED(y1
),
1155 const wxColour
& WXUNUSED(col
),
1156 wxFloodFillStyle
WXUNUSED(style
))
1158 // We can't access the given coord as a Cairo context is scalable, ie a
1159 // coord doesn't mean anything in this context.
1160 wxFAIL_MSG(_("not implemented"));
1164 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1166 wxCoord xC
= circleCenter
.x
;
1167 wxCoord yC
= circleCenter
.y
;
1168 wxCoord xR
= rect
.x
;
1169 wxCoord yR
= rect
.y
;
1170 wxCoord w
= rect
.width
;
1171 wxCoord h
= rect
.height
;
1173 const double r2
= (w
/2)*(w
/2)+(h
/2)*(h
/2);
1174 double radius
= sqrt(r2
);
1176 unsigned char redI
= initialColour
.Red();
1177 unsigned char blueI
= initialColour
.Blue();
1178 unsigned char greenI
= initialColour
.Green();
1179 unsigned char alphaI
= initialColour
.Alpha();
1180 unsigned char redD
= destColour
.Red();
1181 unsigned char blueD
= destColour
.Blue();
1182 unsigned char greenD
= destColour
.Green();
1183 unsigned char alphaD
= destColour
.Alpha();
1185 double redIPS
= (double)(redI
) / 255.0;
1186 double blueIPS
= (double)(blueI
) / 255.0;
1187 double greenIPS
= (double)(greenI
) / 255.0;
1188 double alphaIPS
= (double)(alphaI
) / 255.0;
1189 double redDPS
= (double)(redD
) / 255.0;
1190 double blueDPS
= (double)(blueD
) / 255.0;
1191 double greenDPS
= (double)(greenD
) / 255.0;
1192 double alphaDPS
= (double)(alphaD
) / 255.0;
1194 // Create a pattern with the gradient.
1195 cairo_pattern_t
* gradient
;
1196 gradient
= cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1197 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1198 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1200 // Fill the rectangle with this pattern.
1201 cairo_set_source(m_cairo
, gradient
);
1202 cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1203 cairo_fill(m_cairo
);
1205 cairo_pattern_destroy(gradient
);
1207 CalcBoundingBox(xR
, yR
);
1208 CalcBoundingBox(xR
+w
, yR
+h
);
1211 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1215 wxCoord w
= rect
.width
;
1216 wxCoord h
= rect
.height
;
1218 unsigned char redI
= initialColour
.Red();
1219 unsigned char blueI
= initialColour
.Blue();
1220 unsigned char greenI
= initialColour
.Green();
1221 unsigned char alphaI
= initialColour
.Alpha();
1222 unsigned char redD
= destColour
.Red();
1223 unsigned char blueD
= destColour
.Blue();
1224 unsigned char greenD
= destColour
.Green();
1225 unsigned char alphaD
= destColour
.Alpha();
1227 double redIPS
= (double)(redI
) / 255.0;
1228 double blueIPS
= (double)(blueI
) / 255.0;
1229 double greenIPS
= (double)(greenI
) / 255.0;
1230 double alphaIPS
= (double)(alphaI
) / 255.0;
1231 double redDPS
= (double)(redD
) / 255.0;
1232 double blueDPS
= (double)(blueD
) / 255.0;
1233 double greenDPS
= (double)(greenD
) / 255.0;
1234 double alphaDPS
= (double)(alphaD
) / 255.0;
1236 // Create a pattern with the gradient.
1237 cairo_pattern_t
* gradient
;
1238 gradient
= cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1240 if (nDirection
== wxWEST
)
1242 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1243 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1246 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1247 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1250 // Fill the rectangle with this pattern.
1251 cairo_set_source(m_cairo
, gradient
);
1252 cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1253 cairo_fill(m_cairo
);
1255 cairo_pattern_destroy(gradient
);
1257 CalcBoundingBox(x
, y
);
1258 CalcBoundingBox(x
+w
, y
+h
);
1261 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1262 wxCoord
WXUNUSED(y1
),
1263 wxColour
* WXUNUSED(col
)) const
1265 wxFAIL_MSG(_("not implemented"));
1269 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1271 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1274 cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1275 cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1276 cairo_stroke ( m_cairo
);
1278 CalcBoundingBox( x1
, y1
);
1279 CalcBoundingBox( x2
, y2
);
1282 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1289 cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1290 cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1291 cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1292 cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1294 cairo_stroke (m_cairo
);
1295 CalcBoundingBox( 0, 0 );
1296 CalcBoundingBox( w
, h
);
1299 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1301 double dx
= x1
- xc
;
1302 double dy
= y1
- yc
;
1303 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1305 double alpha1
, alpha2
;
1306 if (x1
== x2
&& y1
== y2
)
1314 alpha1
= alpha2
= 0.0;
1318 alpha1
= (x1
- xc
== 0) ?
1319 (y1
- yc
< 0) ? 90.0 : -90.0 :
1320 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1321 alpha2
= (x2
- xc
== 0) ?
1322 (y2
- yc
< 0) ? 90.0 : -90.0 :
1323 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1325 while (alpha1
<= 0) alpha1
+= 360;
1326 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1327 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1328 while (alpha2
> 360) alpha2
-= 360;
1334 cairo_new_path(m_cairo
);
1336 cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1337 cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1338 cairo_close_path (m_cairo
);
1340 SetBrush( m_brush
);
1341 cairo_fill_preserve( m_cairo
);
1344 cairo_stroke( m_cairo
);
1346 CalcBoundingBox (x1
, y1
);
1347 CalcBoundingBox (xc
, yc
);
1348 CalcBoundingBox (x2
, y2
);
1351 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1353 cairo_save( m_cairo
);
1355 cairo_new_path(m_cairo
);
1357 cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1358 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1359 cairo_scale( m_cairo
, 1.0, scale
);
1361 cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1364 cairo_stroke_preserve( m_cairo
);
1366 cairo_line_to(m_cairo
, 0,0);
1368 SetBrush( m_brush
);
1369 cairo_fill( m_cairo
);
1371 cairo_restore( m_cairo
);
1373 CalcBoundingBox( x
, y
);
1374 CalcBoundingBox( x
+w
, y
+h
);
1377 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1379 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1383 cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1384 cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1385 cairo_stroke ( m_cairo
);
1387 CalcBoundingBox( x
, y
);
1390 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1392 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1399 for ( i
=0; i
<n
; i
++ )
1400 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1402 cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1404 for (i
= 1; i
< n
; i
++)
1405 cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1407 cairo_stroke ( m_cairo
);
1410 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[],
1411 wxCoord xoffset
, wxCoord yoffset
,
1412 wxPolygonFillMode fillStyle
)
1416 cairo_save(m_cairo
);
1417 if (fillStyle
== wxWINDING_RULE
)
1418 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1420 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1422 int x
= points
[0].x
+ xoffset
;
1423 int y
= points
[0].y
+ yoffset
;
1424 cairo_new_path(m_cairo
);
1425 cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1427 for (i
= 1; i
< n
; i
++)
1429 int x
= points
[i
].x
+ xoffset
;
1430 int y
= points
[i
].y
+ yoffset
;
1431 cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1433 cairo_close_path(m_cairo
);
1435 SetBrush( m_brush
);
1436 cairo_fill_preserve( m_cairo
);
1439 cairo_stroke( m_cairo
);
1441 CalcBoundingBox( x
, y
);
1443 cairo_restore(m_cairo
);
1446 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
1447 wxCoord xoffset
, wxCoord yoffset
,
1448 wxPolygonFillMode fillStyle
)
1450 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1453 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1458 cairo_new_path(m_cairo
);
1459 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1461 SetBrush( m_brush
);
1462 cairo_fill_preserve( m_cairo
);
1465 cairo_stroke( m_cairo
);
1467 CalcBoundingBox( x
, y
);
1468 CalcBoundingBox( x
+ width
, y
+ height
);
1471 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1476 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1478 wxCoord dd
= 2 * (wxCoord
) radius
;
1479 if (dd
> width
) dd
= width
;
1480 if (dd
> height
) dd
= height
;
1483 wxCoord rad
= (wxCoord
) radius
;
1485 cairo_new_path(m_cairo
);
1486 cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1487 cairo_curve_to(m_cairo
,
1488 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1489 XLOG2DEV(x
),YLOG2DEV(y
),
1490 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1491 cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1492 cairo_curve_to(m_cairo
,
1493 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1494 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1495 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1496 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1497 cairo_curve_to(m_cairo
,
1498 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1499 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1500 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1501 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1502 cairo_curve_to(m_cairo
,
1503 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1504 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1505 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1506 cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1507 cairo_close_path(m_cairo
);
1510 cairo_fill_preserve(m_cairo
);
1513 cairo_stroke(m_cairo
);
1515 CalcBoundingBox(x
,y
);
1516 CalcBoundingBox(x
+width
,y
+height
);
1519 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1524 cairo_save (m_cairo
);
1526 cairo_new_path(m_cairo
);
1528 cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1529 cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1530 cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1532 SetBrush( m_brush
);
1533 cairo_fill_preserve( m_cairo
);
1536 cairo_stroke( m_cairo
);
1538 CalcBoundingBox( x
, y
);
1539 CalcBoundingBox( x
+ width
, y
+ height
);
1541 cairo_restore (m_cairo
);
1545 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1549 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1552 wxPointList::compatibility_iterator node
= points
->GetFirst();
1553 p
= node
->GetData();
1557 node
= node
->GetNext();
1558 p
= node
->GetData();
1562 (double)(x1
+ c
) / 2;
1564 (double)(y1
+ d
) / 2;
1566 cairo_new_path( m_cairo
);
1567 cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1568 cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1570 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1571 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1573 node
= node
->GetNext();
1576 q
= node
->GetData();
1584 x3
= (double)(x2
+ c
) / 2;
1585 y3
= (double)(y2
+ d
) / 2;
1587 cairo_curve_to(m_cairo
,
1588 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1589 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1590 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1592 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1593 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1595 node
= node
->GetNext();
1598 cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1600 cairo_stroke( m_cairo
);
1602 #endif // wxUSE_SPLINES
1604 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1605 wxCoord width
, wxCoord height
,
1606 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1607 wxRasterOperationMode rop
, bool useMask
,
1608 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1609 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1611 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1612 wxT("mask coordinates are not supported") );
1614 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1616 // Blit into a bitmap.
1617 wxBitmap
bitmap( width
, height
);
1619 memDC
.SelectObject(bitmap
);
1620 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1621 memDC
.SelectObject(wxNullBitmap
);
1623 // Draw bitmap. scaling and positioning is done there.
1624 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1629 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1631 DoDrawBitmap( icon
, x
, y
, true );
1634 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1636 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1638 x
= wxCoord(XLOG2DEV(x
));
1639 y
= wxCoord(YLOG2DEV(y
));
1640 int bw
= bitmap
.GetWidth();
1641 int bh
= bitmap
.GetHeight();
1642 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1643 if (!useMask
&& !bitmap
.HasPixbuf() && bitmap
.GetMask())
1644 bmpSource
.SetMask(NULL
);
1646 cairo_save(m_cairo
);
1648 // Prepare to draw the image.
1649 cairo_translate(m_cairo
, x
, y
);
1652 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1653 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1654 cairo_scale(m_cairo
, scaleX
, scaleY
);
1656 gdk_cairo_set_source_pixbuf(m_cairo
, bmpSource
.GetPixbuf(), 0, 0);
1657 cairo_pattern_set_filter(cairo_get_source(m_cairo
), CAIRO_FILTER_NEAREST
);
1658 // Use the original size here since the context is scaled already.
1659 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1660 // Fill the rectangle using the pattern.
1661 cairo_fill(m_cairo
);
1663 CalcBoundingBox(0,0);
1664 CalcBoundingBox(bw
,bh
);
1666 cairo_restore(m_cairo
);
1669 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1671 DoDrawRotatedText( text
, x
, y
, 0.0 );
1674 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1676 double xx
= XLOG2DEV(x
);
1677 double yy
= YLOG2DEV(y
);
1681 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1683 const wxScopedCharBuffer data
= text
.utf8_str();
1685 size_t datalen
= strlen(data
);
1686 pango_layout_set_text( m_layout
, data
, datalen
);
1690 PangoAttrList
*attrs
= pango_attr_list_new();
1691 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1693 a
->end_index
= datalen
;
1694 pango_attr_list_insert(attrs
, a
);
1695 pango_layout_set_attributes(m_layout
, attrs
);
1696 pango_attr_list_unref(attrs
);
1699 if (m_textForegroundColour
.Ok())
1701 unsigned char red
= m_textForegroundColour
.Red();
1702 unsigned char blue
= m_textForegroundColour
.Blue();
1703 unsigned char green
= m_textForegroundColour
.Green();
1704 unsigned char alpha
= m_textForegroundColour
.Alpha();
1706 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1708 double redPS
= (double)(red
) / 255.0;
1709 double bluePS
= (double)(blue
) / 255.0;
1710 double greenPS
= (double)(green
) / 255.0;
1711 double alphaPS
= (double)(alpha
) / 255.0;
1713 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1716 m_currentBlue
= blue
;
1717 m_currentGreen
= green
;
1718 m_currentAlpha
= alpha
;
1723 cairo_move_to (m_cairo
, xx
, yy
);
1725 cairo_save( m_cairo
);
1727 if (fabs(angle
) > 0.00001)
1728 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1730 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1733 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1735 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1737 unsigned char red
= m_textBackgroundColour
.Red();
1738 unsigned char blue
= m_textBackgroundColour
.Blue();
1739 unsigned char green
= m_textBackgroundColour
.Green();
1740 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1742 double redPS
= (double)(red
) / 255.0;
1743 double bluePS
= (double)(blue
) / 255.0;
1744 double greenPS
= (double)(green
) / 255.0;
1745 double alphaPS
= (double)(alpha
) / 255.0;
1747 cairo_save(m_cairo
);
1748 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1749 cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1750 cairo_fill(m_cairo
);
1751 cairo_restore(m_cairo
);
1754 pango_cairo_update_layout (m_cairo
, m_layout
);
1755 pango_cairo_show_layout (m_cairo
, m_layout
);
1757 cairo_restore( m_cairo
);
1761 // Undo underline attributes setting
1762 pango_layout_set_attributes(m_layout
, NULL
);
1765 // Back to device units:
1766 CalcBoundingBox (x
, y
);
1767 CalcBoundingBox (x
+ w
, y
+ h
);
1770 void wxGtkPrinterDCImpl::Clear()
1772 // Clear does nothing for printing, but keep the code
1775 cairo_save(m_cairo);
1776 cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1777 SetBrush(m_backgroundBrush);
1778 cairo_paint(m_cairo);
1779 cairo_restore(m_cairo);
1783 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1790 pango_font_description_free( m_fontdesc
);
1792 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1794 float size
= pango_font_description_get_size( m_fontdesc
);
1795 size
= size
* GetFontPointSizeAdjustment(72.0);
1796 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1798 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1802 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1804 if (!pen
.Ok()) return;
1810 if (m_pen
.GetWidth() <= 0)
1813 width
= (double) m_pen
.GetWidth();
1815 cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1816 static const double dotted
[] = {2.0, 5.0};
1817 static const double short_dashed
[] = {4.0, 4.0};
1818 static const double long_dashed
[] = {4.0, 8.0};
1819 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1821 switch (m_pen
.GetStyle())
1823 case wxPENSTYLE_DOT
: cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1824 case wxPENSTYLE_SHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1825 case wxPENSTYLE_LONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1826 case wxPENSTYLE_DOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1827 case wxPENSTYLE_USER_DASH
:
1830 int num
= m_pen
.GetDashes (&wx_dashes
);
1831 gdouble
*g_dashes
= g_new( gdouble
, num
);
1833 for (i
= 0; i
< num
; ++i
)
1834 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1835 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1839 case wxPENSTYLE_SOLID
:
1840 case wxPENSTYLE_TRANSPARENT
:
1841 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1844 switch (m_pen
.GetCap())
1846 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1847 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1849 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1852 switch (m_pen
.GetJoin())
1854 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1855 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1857 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1860 unsigned char red
= m_pen
.GetColour().Red();
1861 unsigned char blue
= m_pen
.GetColour().Blue();
1862 unsigned char green
= m_pen
.GetColour().Green();
1863 unsigned char alpha
= m_pen
.GetColour().Alpha();
1865 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1867 double redPS
= (double)(red
) / 255.0;
1868 double bluePS
= (double)(blue
) / 255.0;
1869 double greenPS
= (double)(green
) / 255.0;
1870 double alphaPS
= (double)(alpha
) / 255.0;
1872 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1875 m_currentBlue
= blue
;
1876 m_currentGreen
= green
;
1877 m_currentAlpha
= alpha
;
1881 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1883 if (!brush
.Ok()) return;
1887 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1889 cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1898 unsigned char red
= m_brush
.GetColour().Red();
1899 unsigned char blue
= m_brush
.GetColour().Blue();
1900 unsigned char green
= m_brush
.GetColour().Green();
1901 unsigned char alpha
= m_brush
.GetColour().Alpha();
1903 double redPS
= (double)(red
) / 255.0;
1904 double bluePS
= (double)(blue
) / 255.0;
1905 double greenPS
= (double)(green
) / 255.0;
1906 double alphaPS
= (double)(alpha
) / 255.0;
1908 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1910 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1913 m_currentBlue
= blue
;
1914 m_currentGreen
= green
;
1915 m_currentAlpha
= alpha
;
1918 if (m_brush
.IsHatch())
1921 cairo_surface_t
*surface
;
1922 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
1923 cr
= cairo_create(surface
);
1924 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
1925 cairo_set_line_width(cr
, 1);
1926 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
1928 switch (m_brush
.GetStyle())
1930 case wxBRUSHSTYLE_CROSS_HATCH
:
1931 cairo_move_to(cr
, 5, 0);
1932 cairo_line_to(cr
, 5, 10);
1933 cairo_move_to(cr
, 0, 5);
1934 cairo_line_to(cr
, 10, 5);
1936 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
1937 cairo_move_to(cr
, 0, 10);
1938 cairo_line_to(cr
, 10, 0);
1940 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
1941 cairo_move_to(cr
, 0, 0);
1942 cairo_line_to(cr
, 10, 10);
1944 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
1945 cairo_move_to(cr
, 0, 0);
1946 cairo_line_to(cr
, 10, 10);
1947 cairo_move_to(cr
, 10, 0);
1948 cairo_line_to(cr
, 0, 10);
1950 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
1951 cairo_move_to(cr
, 0, 5);
1952 cairo_line_to(cr
, 10, 5);
1954 case wxBRUSHSTYLE_VERTICAL_HATCH
:
1955 cairo_move_to(cr
, 5, 0);
1956 cairo_line_to(cr
, 5, 10);
1959 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
1962 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
1966 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
1967 cairo_surface_destroy(surface
);
1968 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
1969 cairo_set_source(m_cairo
, pattern
);
1970 cairo_pattern_destroy(pattern
);
1974 void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1976 if (function
== wxCLEAR
)
1977 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
1978 else if (function
== wxOR
)
1979 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
1980 else if (function
== wxNO_OP
)
1981 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
1982 else if (function
== wxAND
)
1983 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
1984 else if (function
== wxSET
)
1985 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
1986 else if (function
== wxXOR
)
1987 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
1988 else // wxCOPY or anything else.
1989 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
1992 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
1994 m_backgroundBrush
= brush
;
1995 cairo_save(m_cairo
);
1996 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
1998 SetBrush(m_backgroundBrush
);
1999 cairo_paint(m_cairo
);
2000 cairo_restore(m_cairo
);
2003 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2005 if (mode
== wxBRUSHSTYLE_SOLID
)
2006 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2008 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2011 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2013 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2014 cairo_clip(m_cairo
);
2017 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2019 cairo_reset_clip(m_cairo
);
2022 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2027 void wxGtkPrinterDCImpl::EndDoc()
2032 void wxGtkPrinterDCImpl::StartPage()
2037 void wxGtkPrinterDCImpl::EndPage()
2042 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2044 pango_layout_set_text( m_layout
, "H", 1 );
2047 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2049 return wxRound( h
* m_PS2DEV
);
2052 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2054 pango_layout_set_text( m_layout
, "H", 1 );
2057 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2059 return wxRound( w
* m_PS2DEV
);
2062 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2064 wxCoord
*externalLeading
,
2065 const wxFont
*theFont
) const
2073 if ( externalLeading
)
2074 *externalLeading
= 0;
2081 cairo_save( m_cairo
);
2082 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
2084 // Set layout's text
2085 const wxScopedCharBuffer dataUTF8
= string
.utf8_str();
2090 // scale the font and apply it
2091 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2092 float size
= pango_font_description_get_size(desc
);
2093 size
= size
* GetFontPointSizeAdjustment(72.0);
2094 pango_font_description_set_size(desc
, (gint
)size
);
2096 pango_layout_set_font_description(m_layout
, desc
);
2099 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2102 pango_layout_get_pixel_size( m_layout
, width
, &h
);
2108 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2109 int baseline
= pango_layout_iter_get_baseline(iter
);
2110 pango_layout_iter_free(iter
);
2111 *descent
= h
- PANGO_PIXELS(baseline
);
2116 // restore font and reset font's size back
2117 pango_layout_set_font_description(m_layout
, m_fontdesc
);
2119 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2120 pango_font_description_set_size(desc
, oldSize
);
2123 cairo_restore( m_cairo
);
2126 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2128 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2131 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2133 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2136 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2138 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2141 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2143 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2146 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2148 return wxSize( (int)m_resolution
, (int)m_resolution
);
2151 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2156 // overriden for wxPrinterDC Impl
2158 wxRect
wxGtkPrinterDCImpl::GetPaperRect() const
2160 // Does GtkPrint support printer margins?
2163 DoGetSize( &w
, &h
);
2164 return wxRect( 0,0,w
,h
);
2167 int wxGtkPrinterDCImpl::GetResolution() const
2169 return m_resolution
;
2172 // ----------------------------------------------------------------------------
2174 // ----------------------------------------------------------------------------
2176 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2178 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2179 wxPrintout
* WXUNUSED(printoutForPrinting
),
2182 // convert wxPrintQuality to resolution (input pointer can be NULL)
2183 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2186 case wxPRINT_QUALITY_HIGH
:
2187 m_resolution
= 1200;
2190 case wxPRINT_QUALITY_LOW
:
2194 case wxPRINT_QUALITY_DRAFT
:
2201 // positive values directly indicate print resolution
2202 m_resolution
= quality
;
2206 wxFAIL_MSG( "unknown print quality" );
2209 case wxPRINT_QUALITY_MEDIUM
:
2218 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2219 wxPrintout
*printoutForPrinting
,
2220 wxPrintDialogData
*data
)
2221 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2223 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2226 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2227 wxPrintout
*printoutForPrinting
,
2229 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2231 Init(printout
, printoutForPrinting
, data
);
2234 wxGtkPrintPreview::~wxGtkPrintPreview()
2238 bool wxGtkPrintPreview::Print(bool interactive
)
2240 if (!m_printPrintout
)
2243 wxPrinter
printer(& m_printDialogData
);
2244 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2247 void wxGtkPrintPreview::DetermineScaling()
2249 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2251 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2253 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2257 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2258 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2260 // Get width and height in points (1/72th of an inch)
2261 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2262 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2263 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2265 wxSize
sizeTenthsMM(paper
->GetSize());
2266 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2268 // If in landscape mode, we need to swap the width and height.
2269 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2271 m_pageWidth
= sizeDevUnits
.y
;
2272 m_pageHeight
= sizeDevUnits
.x
;
2273 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2277 m_pageWidth
= sizeDevUnits
.x
;
2278 m_pageHeight
= sizeDevUnits
.y
;
2279 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2281 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2282 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2284 // At 100%, the page should look about page-size on the screen.
2285 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2286 m_previewScaleY
= m_previewScaleX
;