1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
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();
225 m_job
= gtk_print_operation_new();
229 wxGtkPrintNativeData::~wxGtkPrintNativeData()
231 g_object_unref(m_job
);
232 g_object_unref(m_config
);
235 // Convert datas stored in m_config to a wxPrintData.
236 // Called by wxPrintData::ConvertFromNative().
237 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
242 int resolution
= gtk_print_settings_get_resolution(m_config
);
243 if ( resolution
> 0 )
245 // if resolution is explicitly set, use it
246 data
.SetQuality(resolution
);
248 else // use more vague "quality"
250 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
251 if (quality
== GTK_PRINT_QUALITY_HIGH
)
252 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
253 else if (quality
== GTK_PRINT_QUALITY_LOW
)
254 data
.SetQuality(wxPRINT_QUALITY_LOW
);
255 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
256 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
258 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
261 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
263 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
265 switch (gtk_print_settings_get_duplex(m_config
))
267 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
270 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
274 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
278 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
279 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
281 data
.SetOrientation(wxPORTRAIT
);
282 data
.SetOrientationReversed(false);
284 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
286 data
.SetOrientation(wxLANDSCAPE
);
287 data
.SetOrientationReversed(false);
289 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
291 data
.SetOrientation(wxPORTRAIT
);
292 data
.SetOrientationReversed(true);
294 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
296 data
.SetOrientation(wxLANDSCAPE
);
297 data
.SetOrientationReversed(true);
300 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
302 // Paper formats : these are the most common paper formats.
303 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
305 data
.SetPaperId(wxPAPER_NONE
);
306 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
307 data
.SetPaperId(wxPAPER_A3
);
308 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
309 data
.SetPaperId(wxPAPER_A4
);
310 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
311 data
.SetPaperId(wxPAPER_A5
);
312 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
313 data
.SetPaperId(wxPAPER_B5
);
314 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
315 data
.SetPaperId(wxPAPER_LETTER
);
316 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
317 data
.SetPaperId(wxPAPER_LEGAL
);
318 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
319 data
.SetPaperId(wxPAPER_EXECUTIVE
);
320 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
321 data
.SetPaperId(wxPAPER_ENV_10
);
322 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
323 data
.SetPaperId(wxPAPER_ENV_C5
);
324 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
325 data
.SetPaperId(wxPAPER_ENV_C6
);
326 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
327 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
329 data
.SetPaperId(wxPAPER_ENV_B5
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
331 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
333 data
.SetPaperId( wxPAPER_CSHEET
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
335 data
.SetPaperId( wxPAPER_DSHEET
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
337 data
.SetPaperId( wxPAPER_ESHEET
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
339 data
.SetPaperId( wxPAPER_LETTERSMALL
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
341 data
.SetPaperId( wxPAPER_TABLOID
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
343 data
.SetPaperId( wxPAPER_LEDGER
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
345 data
.SetPaperId( wxPAPER_STATEMENT
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
347 data
.SetPaperId( wxPAPER_A4SMALL
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
349 data
.SetPaperId( wxPAPER_B4
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
351 data
.SetPaperId( wxPAPER_FOLIO
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
353 data
.SetPaperId( wxPAPER_QUARTO
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
355 data
.SetPaperId( wxPAPER_10X14
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
357 data
.SetPaperId( wxPAPER_11X17
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
359 data
.SetPaperId( wxPAPER_NOTE
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
361 data
.SetPaperId( wxPAPER_ENV_9
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
363 data
.SetPaperId( wxPAPER_ENV_11
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
365 data
.SetPaperId( wxPAPER_ENV_12
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
367 data
.SetPaperId( wxPAPER_ENV_14
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
369 data
.SetPaperId( wxPAPER_ENV_DL
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
371 data
.SetPaperId( wxPAPER_ENV_C3
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
373 data
.SetPaperId( wxPAPER_ENV_C4
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
375 data
.SetPaperId( wxPAPER_ENV_C65
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
377 data
.SetPaperId( wxPAPER_ENV_B4
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
379 data
.SetPaperId( wxPAPER_ENV_B6
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
381 data
.SetPaperId( wxPAPER_ENV_ITALY
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
383 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
385 data
.SetPaperId( wxPAPER_FANFOLD_US
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
387 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
389 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
391 data
.SetPaperId(wxPAPER_NONE
);
393 data
.SetPrinterName(gtk_print_settings_get_printer(m_config
));
398 // Put datas given by the wxPrintData into m_config.
399 // Called by wxPrintData::ConvertToNative().
400 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
405 wxPrintQuality quality
= data
.GetQuality();
406 if (quality
== wxPRINT_QUALITY_HIGH
)
407 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
408 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
409 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
410 else if (quality
== wxPRINT_QUALITY_LOW
)
411 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
412 else if (quality
== wxPRINT_QUALITY_DRAFT
)
413 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
414 else if (quality
> 1)
415 gtk_print_settings_set_resolution (m_config
, quality
);
417 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
419 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
421 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
423 switch (data
.GetDuplex())
425 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
428 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
432 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
436 if (!data
.IsOrientationReversed())
438 if (data
.GetOrientation() == wxLANDSCAPE
)
439 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
441 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
444 if (data
.GetOrientation() == wxLANDSCAPE
)
445 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
447 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
450 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
452 // Paper formats: these are the most common paper formats.
453 switch (data
.GetPaperId())
455 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
457 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
459 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
461 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
463 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
465 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
467 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
469 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
471 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
473 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
475 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
477 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
479 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
481 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
483 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
485 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
487 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
489 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
491 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
493 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
495 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
497 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
499 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
501 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
503 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
505 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
507 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
509 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
511 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
513 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
515 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
517 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
519 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
521 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
523 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
525 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
527 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
529 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
531 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
533 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
535 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
537 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
543 gtk_print_settings_set_printer(m_config
, data
.GetPrinterName());
548 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
551 m_config
= gtk_print_settings_copy(config
);
554 // Extract page setup from settings.
555 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
557 GtkPageSetup
* page_setup
= gtk_page_setup_new();
558 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
560 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
561 if (paper_size
!= NULL
)
562 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
567 // Insert page setup into a given GtkPrintSettings.
568 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
570 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
571 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
574 //----------------------------------------------------------------------------
576 //----------------------------------------------------------------------------
578 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
580 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
581 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
582 wxPoint(0, 0), wxSize(600, 600),
583 wxDEFAULT_DIALOG_STYLE
|
587 m_printDialogData
= *data
;
593 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
594 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
595 wxPoint(0, 0), wxSize(600, 600),
596 wxDEFAULT_DIALOG_STYLE
|
600 m_printDialogData
= *data
;
607 wxGtkPrintDialog::~wxGtkPrintDialog()
611 // This is called even if we actually don't want the dialog to appear.
612 int wxGtkPrintDialog::ShowModal()
614 GtkPrintOperationResult response
;
616 // We need to restore the settings given in the constructor.
617 wxPrintData data
= m_printDialogData
.GetPrintData();
618 wxGtkPrintNativeData
*native
=
619 (wxGtkPrintNativeData
*) data
.GetNativeData();
620 data
.ConvertToNative();
622 GtkPrintSettings
* settings
= native
->GetPrintConfig();
624 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
625 int fromPage
= m_printDialogData
.GetFromPage();
626 int toPage
= m_printDialogData
.GetToPage();
627 if (m_printDialogData
.GetSelection())
628 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
629 else if (m_printDialogData
.GetAllPages())
630 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
632 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
634 range
= g_new (GtkPageRange
, 1);
635 range
[0].start
= fromPage
-1;
636 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
637 gtk_print_settings_set_page_ranges (settings
, range
, 1);
640 GtkPrintOperation
* const printOp
= native
->GetPrintJob();
642 // If the settings are OK, we restore it.
643 if (settings
!= NULL
)
644 gtk_print_operation_set_print_settings (printOp
, settings
);
645 gtk_print_operation_set_default_page_setup (printOp
, native
->GetPageSetupFromSettings(settings
));
647 // Show the dialog if needed.
648 GError
* gError
= NULL
;
650 response
= gtk_print_operation_run (printOp
, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
652 response
= gtk_print_operation_run (printOp
, GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
654 // Does everything went well?
655 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
659 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
661 g_error_free (gError
);
662 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
663 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
666 // Now get the settings and save it.
667 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings(printOp
);
668 native
->SetPrintConfig(newSettings
);
669 data
.ConvertFromNative();
671 // Same problem as a few lines before.
672 switch (gtk_print_settings_get_print_pages(newSettings
))
674 case GTK_PRINT_PAGES_CURRENT
:
675 m_printDialogData
.SetSelection( true );
677 case GTK_PRINT_PAGES_RANGES
:
678 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
679 // 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
680 // will hit "OK" button. However we can only save 1-3 in the print data.
683 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
686 m_printDialogData
.SetFromPage( range
[0].start
);
687 m_printDialogData
.SetToPage( range
[0].end
);
690 m_printDialogData
.SetAllPages( true );
691 m_printDialogData
.SetFromPage( 0 );
692 m_printDialogData
.SetToPage( 9999 );
695 case GTK_PRINT_PAGES_ALL
:
697 m_printDialogData
.SetAllPages( true );
698 m_printDialogData
.SetFromPage( 0 );
699 m_printDialogData
.SetToPage( 9999 );
706 //----------------------------------------------------------------------------
707 // wxGtkPageSetupDialog
708 //----------------------------------------------------------------------------
710 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
712 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
713 wxPageSetupDialogData
* data
)
716 m_pageDialogData
= *data
;
721 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
725 int wxGtkPageSetupDialog::ShowModal()
728 m_pageDialogData
.GetPrintData().ConvertToNative();
729 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
730 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
732 // We only need the pagesetup data which are part of the settings.
733 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
735 // If the user used a custom paper format the last time he printed, we have to restore it too.
736 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
738 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
739 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
741 wxString title
= _("Custom size");
742 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
743 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
744 g_object_unref(customSize
);
748 // Now show the dialog.
749 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
754 if (newPageSetup
!= oldPageSetup
)
756 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
757 m_pageDialogData
.GetPrintData().ConvertFromNative();
759 // Store custom paper format if any.
760 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
762 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
763 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
764 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
765 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
766 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
768 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
769 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
771 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
772 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
774 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
787 //----------------------------------------------------------------------------
789 //----------------------------------------------------------------------------
791 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
793 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
794 wxPrinterBase( data
)
799 m_printDialogData
= *data
;
802 wxGtkPrinter::~wxGtkPrinter()
806 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
810 sm_lastError
= wxPRINTER_ERROR
;
814 // Let's correct the PageInfo just in case the app gives wrong values.
815 int fromPage
, toPage
;
816 int minPage
, maxPage
;
817 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
818 m_printDialogData
.SetAllPages(true);
820 if (minPage
< 1) minPage
= 1;
821 if (maxPage
< 1) maxPage
= 9999;
822 if (maxPage
< minPage
) maxPage
= minPage
;
824 m_printDialogData
.SetMinPage(minPage
);
825 m_printDialogData
.SetMaxPage(maxPage
);
828 if (fromPage
< minPage
) fromPage
= minPage
;
829 else if (fromPage
> maxPage
) fromPage
= maxPage
;
830 m_printDialogData
.SetFromPage(fromPage
);
834 m_printDialogData
.SetToPage(toPage
);
835 if (toPage
> maxPage
) toPage
= maxPage
;
836 else if (toPage
< minPage
) toPage
= minPage
;
839 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
842 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
843 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
845 GtkPrintOperation
* const printOp
= native
->GetPrintJob();
847 wxPrinterToGtkData dataToSend
;
848 dataToSend
.printer
= this;
849 dataToSend
.printout
= printout
;
851 // These Gtk signals are caught here.
852 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
853 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
854 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
856 // This is used to setup the DC and
857 // show the dialog if desired
858 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
859 dialog
.SetPrintDC(m_dc
);
860 dialog
.SetShowDialog(prompt
);
862 // doesn't necessarily show
863 int ret
= dialog
.ShowModal();
864 if (ret
== wxID_CANCEL
)
866 sm_lastError
= wxPRINTER_CANCELLED
;
870 sm_lastError
= wxPRINTER_ERROR
;
871 wxFAIL_MSG(_("The print dialog returned an error."));
874 return (sm_lastError
== wxPRINTER_NO_ERROR
);
877 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
879 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
880 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
882 // We need to update printdata with the new data from the dialog and we
883 // have to do this here because this method needs this new data and we
884 // cannot update it earlier
885 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
886 printdata
.ConvertFromNative();
888 SetPrintContext(context
);
889 native
->SetPrintContext( context
);
891 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
896 if (sm_lastError
!= wxPRINTER_CANCELLED
)
898 sm_lastError
= wxPRINTER_ERROR
;
899 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
904 printout
->SetPPIScreen(wxGetDisplayPPI());
905 printout
->SetPPIPrinter( printDC
->GetResolution(),
906 printDC
->GetResolution() );
908 printout
->SetDC(m_dc
);
911 m_dc
->GetSize(&w
, &h
);
912 printout
->SetPageSizePixels((int)w
, (int)h
);
913 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
915 m_dc
->GetSizeMM(&mw
, &mh
);
916 printout
->SetPageSizeMM((int)mw
, (int)mh
);
917 printout
->OnPreparePrinting();
919 // Get some parameters from the printout, if defined.
920 int fromPage
, toPage
;
921 int minPage
, maxPage
;
922 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
926 sm_lastError
= wxPRINTER_ERROR
;
927 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
931 printout
->OnBeginPrinting();
935 // If we're not previewing we need to calculate the number of pages to print.
936 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
937 // have defined in the dialog. So the number of pages is the maximum available.
938 if (!printout
->IsPreview())
940 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
941 switch (gtk_print_settings_get_print_pages(settings
))
943 case GTK_PRINT_PAGES_CURRENT
:
946 case GTK_PRINT_PAGES_RANGES
:
947 {gint num_ranges
= 0;
950 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
951 for (i
=0; i
<num_ranges
; i
++)
953 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
954 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
955 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
956 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
957 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
959 gtk_print_settings_set_page_ranges (settings
, range
, 1);
961 case GTK_PRINT_PAGES_ALL
:
963 numPages
= maxPage
- minPage
+ 1;
967 else numPages
= maxPage
- minPage
+ 1;
969 gtk_print_operation_set_n_pages(operation
, numPages
);
972 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
973 GtkPrintOperation
*operation
,
974 GtkPrintContext
* WXUNUSED(context
),
977 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
978 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
980 int numPageToDraw
= page_nr
+ minPage
;
981 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
982 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
984 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
985 switch (gtk_print_settings_get_print_pages(settings
))
987 case GTK_PRINT_PAGES_CURRENT
:
988 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
989 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
991 case GTK_PRINT_PAGES_RANGES
:
992 {gint num_ranges
= 0;
994 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
995 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
998 startPage
= range
[0].start
+ 1;
999 endPage
= range
[0].end
+ 1;
1002 startPage
= minPage
;
1006 case GTK_PRINT_PAGES_ALL
:
1008 startPage
= minPage
;
1013 if(numPageToDraw
== startPage
)
1015 if (!printout
->OnBeginDocument(startPage
, endPage
))
1017 wxLogError(_("Could not start printing."));
1018 sm_lastError
= wxPRINTER_ERROR
;
1022 // The app can render the page numPageToDraw.
1023 if (printout
->HasPage(numPageToDraw
))
1026 printout
->OnPrintPage(numPageToDraw
);
1031 if(numPageToDraw
== endPage
)
1033 printout
->OnEndDocument();
1037 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1039 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1041 dialog
.SetPrintDC(m_dc
);
1042 dialog
.SetShowDialog(true);
1044 int ret
= dialog
.ShowModal();
1046 if (ret
== wxID_CANCEL
)
1048 sm_lastError
= wxPRINTER_CANCELLED
;
1053 sm_lastError
= wxPRINTER_ERROR
;
1054 wxFAIL_MSG(_("The print dialog returned an error."));
1058 m_printDialogData
= dialog
.GetPrintDialogData();
1060 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1063 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1065 // Obsolete, for backward compatibility.
1069 //-----------------------------------------------------------------------------
1071 //-----------------------------------------------------------------------------
1073 #define wxCAIRO_SCALE 1
1077 #define XLOG2DEV(x) LogicalToDeviceX(x)
1078 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1079 #define YLOG2DEV(x) LogicalToDeviceY(x)
1080 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1084 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1085 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1086 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1087 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1091 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1093 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1098 wxGtkPrintNativeData
*native
=
1099 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1101 m_gpc
= native
->GetPrintContext();
1103 // Match print quality to resolution (high = 1200dpi)
1104 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1105 if (m_resolution
< 0)
1106 m_resolution
= (1 << (m_resolution
+4)) *150;
1108 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1109 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1110 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1112 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1118 cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1120 m_PS2DEV
= (double)m_resolution
/ 72.0;
1121 m_DEV2PS
= 72.0 / (double)m_resolution
;
1128 m_signX
= 1; // default x-axis left to right.
1129 m_signY
= 1; // default y-axis bottom up -> top down.
1131 // By default the origin of the Cairo context is in the upper left
1132 // corner of the printable area. We need to translate it so that it
1133 // is in the upper left corner of the paper (without margins)
1134 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1136 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1137 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1138 cairo_translate(m_cairo
, -ml
, -mt
);
1141 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1143 g_object_unref(m_context
);
1144 g_object_unref(m_layout
);
1147 bool wxGtkPrinterDCImpl::IsOk() const
1149 return m_gpc
!= NULL
;
1152 void* wxGtkPrinterDCImpl::GetCairoContext() const
1154 return (void*) cairo_reference( m_cairo
);
1157 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1158 wxCoord
WXUNUSED(y1
),
1159 const wxColour
& WXUNUSED(col
),
1160 wxFloodFillStyle
WXUNUSED(style
))
1162 // We can't access the given coord as a Cairo context is scalable, ie a
1163 // coord doesn't mean anything in this context.
1164 wxFAIL_MSG(_("not implemented"));
1168 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1170 wxCoord xC
= circleCenter
.x
;
1171 wxCoord yC
= circleCenter
.y
;
1172 wxCoord xR
= rect
.x
;
1173 wxCoord yR
= rect
.y
;
1174 wxCoord w
= rect
.width
;
1175 wxCoord h
= rect
.height
;
1177 const double r2
= (w
/2)*(w
/2)+(h
/2)*(h
/2);
1178 double radius
= sqrt(r2
);
1180 unsigned char redI
= initialColour
.Red();
1181 unsigned char blueI
= initialColour
.Blue();
1182 unsigned char greenI
= initialColour
.Green();
1183 unsigned char alphaI
= initialColour
.Alpha();
1184 unsigned char redD
= destColour
.Red();
1185 unsigned char blueD
= destColour
.Blue();
1186 unsigned char greenD
= destColour
.Green();
1187 unsigned char alphaD
= destColour
.Alpha();
1189 double redIPS
= (double)(redI
) / 255.0;
1190 double blueIPS
= (double)(blueI
) / 255.0;
1191 double greenIPS
= (double)(greenI
) / 255.0;
1192 double alphaIPS
= (double)(alphaI
) / 255.0;
1193 double redDPS
= (double)(redD
) / 255.0;
1194 double blueDPS
= (double)(blueD
) / 255.0;
1195 double greenDPS
= (double)(greenD
) / 255.0;
1196 double alphaDPS
= (double)(alphaD
) / 255.0;
1198 // Create a pattern with the gradient.
1199 cairo_pattern_t
* gradient
;
1200 gradient
= cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1201 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1202 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1204 // Fill the rectangle with this pattern.
1205 cairo_set_source(m_cairo
, gradient
);
1206 cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1207 cairo_fill(m_cairo
);
1209 cairo_pattern_destroy(gradient
);
1211 CalcBoundingBox(xR
, yR
);
1212 CalcBoundingBox(xR
+w
, yR
+h
);
1215 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1219 wxCoord w
= rect
.width
;
1220 wxCoord h
= rect
.height
;
1222 unsigned char redI
= initialColour
.Red();
1223 unsigned char blueI
= initialColour
.Blue();
1224 unsigned char greenI
= initialColour
.Green();
1225 unsigned char alphaI
= initialColour
.Alpha();
1226 unsigned char redD
= destColour
.Red();
1227 unsigned char blueD
= destColour
.Blue();
1228 unsigned char greenD
= destColour
.Green();
1229 unsigned char alphaD
= destColour
.Alpha();
1231 double redIPS
= (double)(redI
) / 255.0;
1232 double blueIPS
= (double)(blueI
) / 255.0;
1233 double greenIPS
= (double)(greenI
) / 255.0;
1234 double alphaIPS
= (double)(alphaI
) / 255.0;
1235 double redDPS
= (double)(redD
) / 255.0;
1236 double blueDPS
= (double)(blueD
) / 255.0;
1237 double greenDPS
= (double)(greenD
) / 255.0;
1238 double alphaDPS
= (double)(alphaD
) / 255.0;
1240 // Create a pattern with the gradient.
1241 cairo_pattern_t
* gradient
;
1242 gradient
= cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1244 if (nDirection
== wxWEST
)
1246 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1247 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1250 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1251 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1254 // Fill the rectangle with this pattern.
1255 cairo_set_source(m_cairo
, gradient
);
1256 cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1257 cairo_fill(m_cairo
);
1259 cairo_pattern_destroy(gradient
);
1261 CalcBoundingBox(x
, y
);
1262 CalcBoundingBox(x
+w
, y
+h
);
1265 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1266 wxCoord
WXUNUSED(y1
),
1267 wxColour
* WXUNUSED(col
)) const
1269 wxFAIL_MSG(_("not implemented"));
1273 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1275 if ( m_pen
.IsTransparent() )
1279 cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1280 cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1281 cairo_stroke ( m_cairo
);
1283 CalcBoundingBox( x1
, y1
);
1284 CalcBoundingBox( x2
, y2
);
1287 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1294 cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1295 cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1296 cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1297 cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1299 cairo_stroke (m_cairo
);
1300 CalcBoundingBox( 0, 0 );
1301 CalcBoundingBox( w
, h
);
1304 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1306 double dx
= x1
- xc
;
1307 double dy
= y1
- yc
;
1308 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1310 double alpha1
, alpha2
;
1311 if (x1
== x2
&& y1
== y2
)
1319 alpha1
= alpha2
= 0.0;
1323 alpha1
= (x1
- xc
== 0) ?
1324 (y1
- yc
< 0) ? 90.0 : -90.0 :
1325 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1326 alpha2
= (x2
- xc
== 0) ?
1327 (y2
- yc
< 0) ? 90.0 : -90.0 :
1328 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1330 while (alpha1
<= 0) alpha1
+= 360;
1331 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1332 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1333 while (alpha2
> 360) alpha2
-= 360;
1339 cairo_new_path(m_cairo
);
1341 cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1342 cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1343 cairo_close_path (m_cairo
);
1345 SetBrush( m_brush
);
1346 cairo_fill_preserve( m_cairo
);
1349 cairo_stroke( m_cairo
);
1351 CalcBoundingBox (x1
, y1
);
1352 CalcBoundingBox (xc
, yc
);
1353 CalcBoundingBox (x2
, y2
);
1356 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1358 cairo_save( m_cairo
);
1360 cairo_new_path(m_cairo
);
1362 cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1363 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1364 cairo_scale( m_cairo
, 1.0, scale
);
1366 cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1369 cairo_stroke_preserve( m_cairo
);
1371 cairo_line_to(m_cairo
, 0,0);
1373 SetBrush( m_brush
);
1374 cairo_fill( m_cairo
);
1376 cairo_restore( m_cairo
);
1378 CalcBoundingBox( x
, y
);
1379 CalcBoundingBox( x
+w
, y
+h
);
1382 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1384 if ( m_pen
.IsTransparent() )
1389 cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1390 cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1391 cairo_stroke ( m_cairo
);
1393 CalcBoundingBox( x
, y
);
1396 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1398 if ( m_pen
.IsTransparent() )
1407 for ( i
=0; i
<n
; i
++ )
1408 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1410 cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1412 for (i
= 1; i
< n
; i
++)
1413 cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1415 cairo_stroke ( m_cairo
);
1418 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[],
1419 wxCoord xoffset
, wxCoord yoffset
,
1420 wxPolygonFillMode fillStyle
)
1424 cairo_save(m_cairo
);
1425 if (fillStyle
== wxWINDING_RULE
)
1426 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1428 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1430 int x
= points
[0].x
+ xoffset
;
1431 int y
= points
[0].y
+ yoffset
;
1432 cairo_new_path(m_cairo
);
1433 cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1435 for (i
= 1; i
< n
; i
++)
1437 int x
= points
[i
].x
+ xoffset
;
1438 int y
= points
[i
].y
+ yoffset
;
1439 cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1441 cairo_close_path(m_cairo
);
1443 SetBrush( m_brush
);
1444 cairo_fill_preserve( m_cairo
);
1447 cairo_stroke( m_cairo
);
1449 CalcBoundingBox( x
, y
);
1451 cairo_restore(m_cairo
);
1454 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
1455 wxCoord xoffset
, wxCoord yoffset
,
1456 wxPolygonFillMode fillStyle
)
1458 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1461 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1466 cairo_new_path(m_cairo
);
1467 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1469 SetBrush( m_brush
);
1470 cairo_fill_preserve( m_cairo
);
1473 cairo_stroke( m_cairo
);
1475 CalcBoundingBox( x
, y
);
1476 CalcBoundingBox( x
+ width
, y
+ height
);
1479 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1484 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1486 wxCoord dd
= 2 * (wxCoord
) radius
;
1487 if (dd
> width
) dd
= width
;
1488 if (dd
> height
) dd
= height
;
1491 wxCoord rad
= (wxCoord
) radius
;
1493 cairo_new_path(m_cairo
);
1494 cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1495 cairo_curve_to(m_cairo
,
1496 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1497 XLOG2DEV(x
),YLOG2DEV(y
),
1498 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1499 cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1500 cairo_curve_to(m_cairo
,
1501 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1502 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1503 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1504 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1505 cairo_curve_to(m_cairo
,
1506 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1507 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1508 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1509 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1510 cairo_curve_to(m_cairo
,
1511 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1512 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1513 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1514 cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1515 cairo_close_path(m_cairo
);
1518 cairo_fill_preserve(m_cairo
);
1521 cairo_stroke(m_cairo
);
1523 CalcBoundingBox(x
,y
);
1524 CalcBoundingBox(x
+width
,y
+height
);
1527 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1532 cairo_save (m_cairo
);
1534 cairo_new_path(m_cairo
);
1536 cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1537 cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1538 cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1540 SetBrush( m_brush
);
1541 cairo_fill_preserve( m_cairo
);
1544 cairo_stroke( m_cairo
);
1546 CalcBoundingBox( x
, y
);
1547 CalcBoundingBox( x
+ width
, y
+ height
);
1549 cairo_restore (m_cairo
);
1553 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1557 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1560 wxPointList::compatibility_iterator node
= points
->GetFirst();
1561 p
= node
->GetData();
1565 node
= node
->GetNext();
1566 p
= node
->GetData();
1570 (double)(x1
+ c
) / 2;
1572 (double)(y1
+ d
) / 2;
1574 cairo_new_path( m_cairo
);
1575 cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1576 cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1578 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1579 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1581 node
= node
->GetNext();
1584 q
= node
->GetData();
1592 x3
= (double)(x2
+ c
) / 2;
1593 y3
= (double)(y2
+ d
) / 2;
1595 cairo_curve_to(m_cairo
,
1596 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1597 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1598 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1600 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1601 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1603 node
= node
->GetNext();
1606 cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1608 cairo_stroke( m_cairo
);
1610 #endif // wxUSE_SPLINES
1612 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1613 wxCoord width
, wxCoord height
,
1614 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1615 wxRasterOperationMode rop
, bool useMask
,
1616 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1617 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1619 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1620 wxT("mask coordinates are not supported") );
1622 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1624 // Blit into a bitmap.
1625 wxBitmap
bitmap( width
, height
);
1627 memDC
.SelectObject(bitmap
);
1628 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1629 memDC
.SelectObject(wxNullBitmap
);
1631 // Draw bitmap. scaling and positioning is done there.
1632 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1637 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1639 DoDrawBitmap( icon
, x
, y
, true );
1642 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1644 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1646 x
= wxCoord(XLOG2DEV(x
));
1647 y
= wxCoord(YLOG2DEV(y
));
1648 int bw
= bitmap
.GetWidth();
1649 int bh
= bitmap
.GetHeight();
1650 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1651 if (!useMask
&& !bitmap
.HasPixbuf() && bitmap
.GetMask())
1652 bmpSource
.SetMask(NULL
);
1654 cairo_save(m_cairo
);
1656 // Prepare to draw the image.
1657 cairo_translate(m_cairo
, x
, y
);
1660 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1661 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1662 cairo_scale(m_cairo
, scaleX
, scaleY
);
1664 gdk_cairo_set_source_pixbuf(m_cairo
, bmpSource
.GetPixbuf(), 0, 0);
1665 cairo_pattern_set_filter(cairo_get_source(m_cairo
), CAIRO_FILTER_NEAREST
);
1666 // Use the original size here since the context is scaled already.
1667 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1668 // Fill the rectangle using the pattern.
1669 cairo_fill(m_cairo
);
1671 CalcBoundingBox(0,0);
1672 CalcBoundingBox(bw
,bh
);
1674 cairo_restore(m_cairo
);
1677 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1679 DoDrawRotatedText( text
, x
, y
, 0.0 );
1682 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1684 double xx
= XLOG2DEV(x
);
1685 double yy
= YLOG2DEV(y
);
1689 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1691 const wxScopedCharBuffer data
= text
.utf8_str();
1693 size_t datalen
= strlen(data
);
1694 pango_layout_set_text( m_layout
, data
, datalen
);
1698 PangoAttrList
*attrs
= pango_attr_list_new();
1699 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1701 a
->end_index
= datalen
;
1702 pango_attr_list_insert(attrs
, a
);
1703 pango_layout_set_attributes(m_layout
, attrs
);
1704 pango_attr_list_unref(attrs
);
1707 if (m_textForegroundColour
.Ok())
1709 unsigned char red
= m_textForegroundColour
.Red();
1710 unsigned char blue
= m_textForegroundColour
.Blue();
1711 unsigned char green
= m_textForegroundColour
.Green();
1712 unsigned char alpha
= m_textForegroundColour
.Alpha();
1714 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1716 double redPS
= (double)(red
) / 255.0;
1717 double bluePS
= (double)(blue
) / 255.0;
1718 double greenPS
= (double)(green
) / 255.0;
1719 double alphaPS
= (double)(alpha
) / 255.0;
1721 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1724 m_currentBlue
= blue
;
1725 m_currentGreen
= green
;
1726 m_currentAlpha
= alpha
;
1731 cairo_move_to (m_cairo
, xx
, yy
);
1733 cairo_save( m_cairo
);
1735 if (fabs(angle
) > 0.00001)
1736 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1738 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1741 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1743 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1745 unsigned char red
= m_textBackgroundColour
.Red();
1746 unsigned char blue
= m_textBackgroundColour
.Blue();
1747 unsigned char green
= m_textBackgroundColour
.Green();
1748 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1750 double redPS
= (double)(red
) / 255.0;
1751 double bluePS
= (double)(blue
) / 255.0;
1752 double greenPS
= (double)(green
) / 255.0;
1753 double alphaPS
= (double)(alpha
) / 255.0;
1755 cairo_save(m_cairo
);
1756 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1757 cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1758 cairo_fill(m_cairo
);
1759 cairo_restore(m_cairo
);
1762 pango_cairo_update_layout (m_cairo
, m_layout
);
1763 pango_cairo_show_layout (m_cairo
, m_layout
);
1765 cairo_restore( m_cairo
);
1769 // Undo underline attributes setting
1770 pango_layout_set_attributes(m_layout
, NULL
);
1773 // Back to device units:
1774 CalcBoundingBox (x
, y
);
1775 CalcBoundingBox (x
+ w
, y
+ h
);
1778 void wxGtkPrinterDCImpl::Clear()
1780 // Clear does nothing for printing, but keep the code
1783 cairo_save(m_cairo);
1784 cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1785 SetBrush(m_backgroundBrush);
1786 cairo_paint(m_cairo);
1787 cairo_restore(m_cairo);
1791 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1798 pango_font_description_free( m_fontdesc
);
1800 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1802 float size
= pango_font_description_get_size( m_fontdesc
);
1803 size
= size
* GetFontPointSizeAdjustment(72.0);
1804 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1806 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1810 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1812 if (!pen
.Ok()) return;
1818 if (m_pen
.GetWidth() <= 0)
1821 width
= (double) m_pen
.GetWidth();
1823 cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1824 static const double dotted
[] = {2.0, 5.0};
1825 static const double short_dashed
[] = {4.0, 4.0};
1826 static const double long_dashed
[] = {4.0, 8.0};
1827 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1829 switch (m_pen
.GetStyle())
1831 case wxPENSTYLE_DOT
: cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1832 case wxPENSTYLE_SHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1833 case wxPENSTYLE_LONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1834 case wxPENSTYLE_DOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1835 case wxPENSTYLE_USER_DASH
:
1838 int num
= m_pen
.GetDashes (&wx_dashes
);
1839 gdouble
*g_dashes
= g_new( gdouble
, num
);
1841 for (i
= 0; i
< num
; ++i
)
1842 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1843 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1847 case wxPENSTYLE_SOLID
:
1848 case wxPENSTYLE_TRANSPARENT
:
1849 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1852 switch (m_pen
.GetCap())
1854 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1855 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1857 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1860 switch (m_pen
.GetJoin())
1862 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1863 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1865 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1868 unsigned char red
= m_pen
.GetColour().Red();
1869 unsigned char blue
= m_pen
.GetColour().Blue();
1870 unsigned char green
= m_pen
.GetColour().Green();
1871 unsigned char alpha
= m_pen
.GetColour().Alpha();
1873 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1875 double redPS
= (double)(red
) / 255.0;
1876 double bluePS
= (double)(blue
) / 255.0;
1877 double greenPS
= (double)(green
) / 255.0;
1878 double alphaPS
= (double)(alpha
) / 255.0;
1880 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1883 m_currentBlue
= blue
;
1884 m_currentGreen
= green
;
1885 m_currentAlpha
= alpha
;
1889 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1891 if (!brush
.Ok()) return;
1895 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1897 cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1906 unsigned char red
= m_brush
.GetColour().Red();
1907 unsigned char blue
= m_brush
.GetColour().Blue();
1908 unsigned char green
= m_brush
.GetColour().Green();
1909 unsigned char alpha
= m_brush
.GetColour().Alpha();
1911 double redPS
= (double)(red
) / 255.0;
1912 double bluePS
= (double)(blue
) / 255.0;
1913 double greenPS
= (double)(green
) / 255.0;
1914 double alphaPS
= (double)(alpha
) / 255.0;
1916 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1918 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1921 m_currentBlue
= blue
;
1922 m_currentGreen
= green
;
1923 m_currentAlpha
= alpha
;
1926 if (m_brush
.IsHatch())
1929 cairo_surface_t
*surface
;
1930 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
1931 cr
= cairo_create(surface
);
1932 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
1933 cairo_set_line_width(cr
, 1);
1934 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
1936 switch (m_brush
.GetStyle())
1938 case wxBRUSHSTYLE_CROSS_HATCH
:
1939 cairo_move_to(cr
, 5, 0);
1940 cairo_line_to(cr
, 5, 10);
1941 cairo_move_to(cr
, 0, 5);
1942 cairo_line_to(cr
, 10, 5);
1944 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
1945 cairo_move_to(cr
, 0, 10);
1946 cairo_line_to(cr
, 10, 0);
1948 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
1949 cairo_move_to(cr
, 0, 0);
1950 cairo_line_to(cr
, 10, 10);
1952 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
1953 cairo_move_to(cr
, 0, 0);
1954 cairo_line_to(cr
, 10, 10);
1955 cairo_move_to(cr
, 10, 0);
1956 cairo_line_to(cr
, 0, 10);
1958 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
1959 cairo_move_to(cr
, 0, 5);
1960 cairo_line_to(cr
, 10, 5);
1962 case wxBRUSHSTYLE_VERTICAL_HATCH
:
1963 cairo_move_to(cr
, 5, 0);
1964 cairo_line_to(cr
, 5, 10);
1967 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
1970 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
1974 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
1975 cairo_surface_destroy(surface
);
1976 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
1977 cairo_set_source(m_cairo
, pattern
);
1978 cairo_pattern_destroy(pattern
);
1982 void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1984 if (function
== wxCLEAR
)
1985 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
1986 else if (function
== wxOR
)
1987 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
1988 else if (function
== wxNO_OP
)
1989 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
1990 else if (function
== wxAND
)
1991 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
1992 else if (function
== wxSET
)
1993 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
1994 else if (function
== wxXOR
)
1995 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
1996 else // wxCOPY or anything else.
1997 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2000 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2002 m_backgroundBrush
= brush
;
2003 cairo_save(m_cairo
);
2004 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2006 SetBrush(m_backgroundBrush
);
2007 cairo_paint(m_cairo
);
2008 cairo_restore(m_cairo
);
2011 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2013 if (mode
== wxBRUSHSTYLE_SOLID
)
2014 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2016 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2019 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2021 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2022 cairo_clip(m_cairo
);
2025 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2027 cairo_reset_clip(m_cairo
);
2030 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2035 void wxGtkPrinterDCImpl::EndDoc()
2040 void wxGtkPrinterDCImpl::StartPage()
2045 void wxGtkPrinterDCImpl::EndPage()
2050 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2052 pango_layout_set_text( m_layout
, "H", 1 );
2055 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2057 return wxRound( h
* m_PS2DEV
);
2060 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2062 pango_layout_set_text( m_layout
, "H", 1 );
2065 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2067 return wxRound( w
* m_PS2DEV
);
2070 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2072 wxCoord
*externalLeading
,
2073 const wxFont
*theFont
) const
2081 if ( externalLeading
)
2082 *externalLeading
= 0;
2089 cairo_save( m_cairo
);
2090 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
2092 // Set layout's text
2093 const wxScopedCharBuffer dataUTF8
= string
.utf8_str();
2098 // scale the font and apply it
2099 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2100 float size
= pango_font_description_get_size(desc
);
2101 size
= size
* GetFontPointSizeAdjustment(72.0);
2102 pango_font_description_set_size(desc
, (gint
)size
);
2104 pango_layout_set_font_description(m_layout
, desc
);
2107 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2110 pango_layout_get_pixel_size( m_layout
, width
, &h
);
2116 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2117 int baseline
= pango_layout_iter_get_baseline(iter
);
2118 pango_layout_iter_free(iter
);
2119 *descent
= h
- PANGO_PIXELS(baseline
);
2124 // restore font and reset font's size back
2125 pango_layout_set_font_description(m_layout
, m_fontdesc
);
2127 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2128 pango_font_description_set_size(desc
, oldSize
);
2131 cairo_restore( m_cairo
);
2134 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2136 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2139 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2141 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2144 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2146 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2149 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2151 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2154 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2156 return wxSize( (int)m_resolution
, (int)m_resolution
);
2159 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2164 // overriden for wxPrinterDC Impl
2166 wxRect
wxGtkPrinterDCImpl::GetPaperRect() const
2168 // Does GtkPrint support printer margins?
2171 DoGetSize( &w
, &h
);
2172 return wxRect( 0,0,w
,h
);
2175 int wxGtkPrinterDCImpl::GetResolution() const
2177 return m_resolution
;
2180 // ----------------------------------------------------------------------------
2182 // ----------------------------------------------------------------------------
2184 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2186 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2187 wxPrintout
* WXUNUSED(printoutForPrinting
),
2190 // convert wxPrintQuality to resolution (input pointer can be NULL)
2191 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2194 case wxPRINT_QUALITY_HIGH
:
2195 m_resolution
= 1200;
2198 case wxPRINT_QUALITY_LOW
:
2202 case wxPRINT_QUALITY_DRAFT
:
2209 // positive values directly indicate print resolution
2210 m_resolution
= quality
;
2214 wxFAIL_MSG( "unknown print quality" );
2217 case wxPRINT_QUALITY_MEDIUM
:
2226 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2227 wxPrintout
*printoutForPrinting
,
2228 wxPrintDialogData
*data
)
2229 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2231 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2234 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2235 wxPrintout
*printoutForPrinting
,
2237 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2239 Init(printout
, printoutForPrinting
, data
);
2242 wxGtkPrintPreview::~wxGtkPrintPreview()
2246 bool wxGtkPrintPreview::Print(bool interactive
)
2248 if (!m_printPrintout
)
2251 wxPrinter
printer(& m_printDialogData
);
2252 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2255 void wxGtkPrintPreview::DetermineScaling()
2257 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2259 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2261 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2265 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2266 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2268 // Get width and height in points (1/72th of an inch)
2269 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2270 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2271 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2273 wxSize
sizeTenthsMM(paper
->GetSize());
2274 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2276 // If in landscape mode, we need to swap the width and height.
2277 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2279 m_pageWidth
= sizeDevUnits
.y
;
2280 m_pageHeight
= sizeDevUnits
.x
;
2281 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2285 m_pageWidth
= sizeDevUnits
.x
;
2286 m_pageHeight
= sizeDevUnits
.y
;
2287 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2289 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2290 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2292 // At 100%, the page should look about page-size on the screen.
2293 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2294 m_previewScaleY
= m_previewScaleX
;