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 wxPrinterToGtkData dataToSend
;
840 dataToSend
.printer
= this;
841 dataToSend
.printout
= printout
;
843 // These Gtk signals are caught here.
844 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
845 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
846 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
848 // This is used to setup the DC and
849 // show the dialog if desired
850 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
851 dialog
.SetPrintDC(m_dc
);
852 dialog
.SetShowDialog(prompt
);
854 // doesn't necessarily show
855 int ret
= dialog
.ShowModal();
856 if (ret
== wxID_CANCEL
)
858 sm_lastError
= wxPRINTER_CANCELLED
;
862 sm_lastError
= wxPRINTER_ERROR
;
863 wxFAIL_MSG(_("The print dialog returned an error."));
866 g_object_unref (printOp
);
868 return (sm_lastError
== wxPRINTER_NO_ERROR
);
871 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
873 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
874 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
876 // We need to update printdata with the new data from the dialog and we
877 // have to do this here because this method needs this new data and we
878 // cannot update it earlier
879 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
880 printdata
.ConvertFromNative();
882 SetPrintContext(context
);
883 native
->SetPrintContext( context
);
885 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
890 if (sm_lastError
!= wxPRINTER_CANCELLED
)
892 sm_lastError
= wxPRINTER_ERROR
;
893 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
898 printout
->SetPPIScreen(wxGetDisplayPPI());
899 printout
->SetPPIPrinter( printDC
->GetResolution(),
900 printDC
->GetResolution() );
902 printout
->SetDC(m_dc
);
905 m_dc
->GetSize(&w
, &h
);
906 printout
->SetPageSizePixels((int)w
, (int)h
);
907 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
909 m_dc
->GetSizeMM(&mw
, &mh
);
910 printout
->SetPageSizeMM((int)mw
, (int)mh
);
911 printout
->OnPreparePrinting();
913 // Get some parameters from the printout, if defined.
914 int fromPage
, toPage
;
915 int minPage
, maxPage
;
916 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
920 sm_lastError
= wxPRINTER_ERROR
;
921 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
925 printout
->OnBeginPrinting();
929 // If we're not previewing we need to calculate the number of pages to print.
930 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
931 // have defined in the dialog. So the number of pages is the maximum available.
932 if (!printout
->IsPreview())
934 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
935 switch (gtk_print_settings_get_print_pages(settings
))
937 case GTK_PRINT_PAGES_CURRENT
:
940 case GTK_PRINT_PAGES_RANGES
:
941 {gint num_ranges
= 0;
944 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
945 for (i
=0; i
<num_ranges
; i
++)
947 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
948 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
949 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
950 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
951 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
953 gtk_print_settings_set_page_ranges (settings
, range
, 1);
955 case GTK_PRINT_PAGES_ALL
:
957 numPages
= maxPage
- minPage
+ 1;
961 else numPages
= maxPage
- minPage
+ 1;
963 gtk_print_operation_set_n_pages(operation
, numPages
);
966 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
967 GtkPrintOperation
*operation
,
968 GtkPrintContext
* WXUNUSED(context
),
971 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
972 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
974 int numPageToDraw
= page_nr
+ minPage
;
975 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
976 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
978 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
979 switch (gtk_print_settings_get_print_pages(settings
))
981 case GTK_PRINT_PAGES_CURRENT
:
982 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
983 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
985 case GTK_PRINT_PAGES_RANGES
:
986 {gint num_ranges
= 0;
988 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
989 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
992 startPage
= range
[0].start
+ 1;
993 endPage
= range
[0].end
+ 1;
1000 case GTK_PRINT_PAGES_ALL
:
1002 startPage
= minPage
;
1007 if(numPageToDraw
== startPage
)
1009 if (!printout
->OnBeginDocument(startPage
, endPage
))
1011 wxLogError(_("Could not start printing."));
1012 sm_lastError
= wxPRINTER_ERROR
;
1016 // The app can render the page numPageToDraw.
1017 if (printout
->HasPage(numPageToDraw
))
1020 printout
->OnPrintPage(numPageToDraw
);
1025 if(numPageToDraw
== endPage
)
1027 printout
->OnEndDocument();
1031 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1033 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1035 dialog
.SetPrintDC(m_dc
);
1036 dialog
.SetShowDialog(true);
1038 int ret
= dialog
.ShowModal();
1040 if (ret
== wxID_CANCEL
)
1042 sm_lastError
= wxPRINTER_CANCELLED
;
1047 sm_lastError
= wxPRINTER_ERROR
;
1048 wxFAIL_MSG(_("The print dialog returned an error."));
1052 m_printDialogData
= dialog
.GetPrintDialogData();
1054 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1057 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1059 // Obsolete, for backward compatibility.
1063 //-----------------------------------------------------------------------------
1065 //-----------------------------------------------------------------------------
1067 #define wxCAIRO_SCALE 1
1071 #define XLOG2DEV(x) LogicalToDeviceX(x)
1072 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1073 #define YLOG2DEV(x) LogicalToDeviceY(x)
1074 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1078 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1079 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1080 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1081 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1085 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1087 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1092 wxGtkPrintNativeData
*native
=
1093 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1095 m_gpc
= native
->GetPrintContext();
1097 // Match print quality to resolution (high = 1200dpi)
1098 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1099 if (m_resolution
< 0)
1100 m_resolution
= (1 << (m_resolution
+4)) *150;
1102 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1103 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1104 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1106 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1112 cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1114 m_PS2DEV
= (double)m_resolution
/ 72.0;
1115 m_DEV2PS
= 72.0 / (double)m_resolution
;
1122 m_signX
= 1; // default x-axis left to right.
1123 m_signY
= 1; // default y-axis bottom up -> top down.
1125 // By default the origin of the Cairo context is in the upper left
1126 // corner of the printable area. We need to translate it so that it
1127 // is in the upper left corner of the paper (without margins)
1128 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1130 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1131 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1132 cairo_translate(m_cairo
, -ml
, -mt
);
1135 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1137 g_object_unref(m_context
);
1138 g_object_unref(m_layout
);
1141 bool wxGtkPrinterDCImpl::IsOk() const
1143 return m_gpc
!= NULL
;
1146 void* wxGtkPrinterDCImpl::GetCairoContext() const
1148 return (void*) cairo_reference( m_cairo
);
1151 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1152 wxCoord
WXUNUSED(y1
),
1153 const wxColour
& WXUNUSED(col
),
1154 wxFloodFillStyle
WXUNUSED(style
))
1156 // We can't access the given coord as a Cairo context is scalable, ie a
1157 // coord doesn't mean anything in this context.
1158 wxFAIL_MSG(_("not implemented"));
1162 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1164 wxCoord xC
= circleCenter
.x
;
1165 wxCoord yC
= circleCenter
.y
;
1166 wxCoord xR
= rect
.x
;
1167 wxCoord yR
= rect
.y
;
1168 wxCoord w
= rect
.width
;
1169 wxCoord h
= rect
.height
;
1171 const double r2
= (w
/2)*(w
/2)+(h
/2)*(h
/2);
1172 double radius
= sqrt(r2
);
1174 unsigned char redI
= initialColour
.Red();
1175 unsigned char blueI
= initialColour
.Blue();
1176 unsigned char greenI
= initialColour
.Green();
1177 unsigned char alphaI
= initialColour
.Alpha();
1178 unsigned char redD
= destColour
.Red();
1179 unsigned char blueD
= destColour
.Blue();
1180 unsigned char greenD
= destColour
.Green();
1181 unsigned char alphaD
= destColour
.Alpha();
1183 double redIPS
= (double)(redI
) / 255.0;
1184 double blueIPS
= (double)(blueI
) / 255.0;
1185 double greenIPS
= (double)(greenI
) / 255.0;
1186 double alphaIPS
= (double)(alphaI
) / 255.0;
1187 double redDPS
= (double)(redD
) / 255.0;
1188 double blueDPS
= (double)(blueD
) / 255.0;
1189 double greenDPS
= (double)(greenD
) / 255.0;
1190 double alphaDPS
= (double)(alphaD
) / 255.0;
1192 // Create a pattern with the gradient.
1193 cairo_pattern_t
* gradient
;
1194 gradient
= cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1195 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1196 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1198 // Fill the rectangle with this pattern.
1199 cairo_set_source(m_cairo
, gradient
);
1200 cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1201 cairo_fill(m_cairo
);
1203 cairo_pattern_destroy(gradient
);
1205 CalcBoundingBox(xR
, yR
);
1206 CalcBoundingBox(xR
+w
, yR
+h
);
1209 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1213 wxCoord w
= rect
.width
;
1214 wxCoord h
= rect
.height
;
1216 unsigned char redI
= initialColour
.Red();
1217 unsigned char blueI
= initialColour
.Blue();
1218 unsigned char greenI
= initialColour
.Green();
1219 unsigned char alphaI
= initialColour
.Alpha();
1220 unsigned char redD
= destColour
.Red();
1221 unsigned char blueD
= destColour
.Blue();
1222 unsigned char greenD
= destColour
.Green();
1223 unsigned char alphaD
= destColour
.Alpha();
1225 double redIPS
= (double)(redI
) / 255.0;
1226 double blueIPS
= (double)(blueI
) / 255.0;
1227 double greenIPS
= (double)(greenI
) / 255.0;
1228 double alphaIPS
= (double)(alphaI
) / 255.0;
1229 double redDPS
= (double)(redD
) / 255.0;
1230 double blueDPS
= (double)(blueD
) / 255.0;
1231 double greenDPS
= (double)(greenD
) / 255.0;
1232 double alphaDPS
= (double)(alphaD
) / 255.0;
1234 // Create a pattern with the gradient.
1235 cairo_pattern_t
* gradient
;
1236 gradient
= cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1238 if (nDirection
== wxWEST
)
1240 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1241 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1244 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1245 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1248 // Fill the rectangle with this pattern.
1249 cairo_set_source(m_cairo
, gradient
);
1250 cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1251 cairo_fill(m_cairo
);
1253 cairo_pattern_destroy(gradient
);
1255 CalcBoundingBox(x
, y
);
1256 CalcBoundingBox(x
+w
, y
+h
);
1259 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1260 wxCoord
WXUNUSED(y1
),
1261 wxColour
* WXUNUSED(col
)) const
1263 wxFAIL_MSG(_("not implemented"));
1267 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1269 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1272 cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1273 cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1274 cairo_stroke ( m_cairo
);
1276 CalcBoundingBox( x1
, y1
);
1277 CalcBoundingBox( x2
, y2
);
1280 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1287 cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1288 cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1289 cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1290 cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1292 cairo_stroke (m_cairo
);
1293 CalcBoundingBox( 0, 0 );
1294 CalcBoundingBox( w
, h
);
1297 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1299 double dx
= x1
- xc
;
1300 double dy
= y1
- yc
;
1301 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1303 double alpha1
, alpha2
;
1304 if (x1
== x2
&& y1
== y2
)
1312 alpha1
= alpha2
= 0.0;
1316 alpha1
= (x1
- xc
== 0) ?
1317 (y1
- yc
< 0) ? 90.0 : -90.0 :
1318 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1319 alpha2
= (x2
- xc
== 0) ?
1320 (y2
- yc
< 0) ? 90.0 : -90.0 :
1321 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1323 while (alpha1
<= 0) alpha1
+= 360;
1324 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1325 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1326 while (alpha2
> 360) alpha2
-= 360;
1332 cairo_new_path(m_cairo
);
1334 cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1335 cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1336 cairo_close_path (m_cairo
);
1338 SetBrush( m_brush
);
1339 cairo_fill_preserve( m_cairo
);
1342 cairo_stroke( m_cairo
);
1344 CalcBoundingBox (x1
, y1
);
1345 CalcBoundingBox (xc
, yc
);
1346 CalcBoundingBox (x2
, y2
);
1349 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1351 cairo_save( m_cairo
);
1353 cairo_new_path(m_cairo
);
1355 cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1356 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1357 cairo_scale( m_cairo
, 1.0, scale
);
1359 cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1362 cairo_stroke_preserve( m_cairo
);
1364 cairo_line_to(m_cairo
, 0,0);
1366 SetBrush( m_brush
);
1367 cairo_fill( m_cairo
);
1369 cairo_restore( m_cairo
);
1371 CalcBoundingBox( x
, y
);
1372 CalcBoundingBox( x
+w
, y
+h
);
1375 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1377 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1381 cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1382 cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1383 cairo_stroke ( m_cairo
);
1385 CalcBoundingBox( x
, y
);
1388 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1390 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1397 for ( i
=0; i
<n
; i
++ )
1398 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1400 cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1402 for (i
= 1; i
< n
; i
++)
1403 cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1405 cairo_stroke ( m_cairo
);
1408 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[],
1409 wxCoord xoffset
, wxCoord yoffset
,
1410 wxPolygonFillMode fillStyle
)
1414 cairo_save(m_cairo
);
1415 if (fillStyle
== wxWINDING_RULE
)
1416 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1418 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1420 int x
= points
[0].x
+ xoffset
;
1421 int y
= points
[0].y
+ yoffset
;
1422 cairo_new_path(m_cairo
);
1423 cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1425 for (i
= 1; i
< n
; i
++)
1427 int x
= points
[i
].x
+ xoffset
;
1428 int y
= points
[i
].y
+ yoffset
;
1429 cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1431 cairo_close_path(m_cairo
);
1433 SetBrush( m_brush
);
1434 cairo_fill_preserve( m_cairo
);
1437 cairo_stroke( m_cairo
);
1439 CalcBoundingBox( x
, y
);
1441 cairo_restore(m_cairo
);
1444 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
1445 wxCoord xoffset
, wxCoord yoffset
,
1446 wxPolygonFillMode fillStyle
)
1448 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1451 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1456 cairo_new_path(m_cairo
);
1457 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1459 SetBrush( m_brush
);
1460 cairo_fill_preserve( m_cairo
);
1463 cairo_stroke( m_cairo
);
1465 CalcBoundingBox( x
, y
);
1466 CalcBoundingBox( x
+ width
, y
+ height
);
1469 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1474 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1476 wxCoord dd
= 2 * (wxCoord
) radius
;
1477 if (dd
> width
) dd
= width
;
1478 if (dd
> height
) dd
= height
;
1481 wxCoord rad
= (wxCoord
) radius
;
1483 cairo_new_path(m_cairo
);
1484 cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1485 cairo_curve_to(m_cairo
,
1486 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1487 XLOG2DEV(x
),YLOG2DEV(y
),
1488 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1489 cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1490 cairo_curve_to(m_cairo
,
1491 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1492 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1493 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1494 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1495 cairo_curve_to(m_cairo
,
1496 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1497 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1498 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1499 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1500 cairo_curve_to(m_cairo
,
1501 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1502 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1503 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1504 cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1505 cairo_close_path(m_cairo
);
1508 cairo_fill_preserve(m_cairo
);
1511 cairo_stroke(m_cairo
);
1513 CalcBoundingBox(x
,y
);
1514 CalcBoundingBox(x
+width
,y
+height
);
1517 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1522 cairo_save (m_cairo
);
1524 cairo_new_path(m_cairo
);
1526 cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1527 cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1528 cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1530 SetBrush( m_brush
);
1531 cairo_fill_preserve( m_cairo
);
1534 cairo_stroke( m_cairo
);
1536 CalcBoundingBox( x
, y
);
1537 CalcBoundingBox( x
+ width
, y
+ height
);
1539 cairo_restore (m_cairo
);
1543 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1547 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1550 wxPointList::compatibility_iterator node
= points
->GetFirst();
1551 p
= node
->GetData();
1555 node
= node
->GetNext();
1556 p
= node
->GetData();
1560 (double)(x1
+ c
) / 2;
1562 (double)(y1
+ d
) / 2;
1564 cairo_new_path( m_cairo
);
1565 cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1566 cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1568 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1569 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1571 node
= node
->GetNext();
1574 q
= node
->GetData();
1582 x3
= (double)(x2
+ c
) / 2;
1583 y3
= (double)(y2
+ d
) / 2;
1585 cairo_curve_to(m_cairo
,
1586 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1587 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1588 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1590 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1591 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1593 node
= node
->GetNext();
1596 cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1598 cairo_stroke( m_cairo
);
1600 #endif // wxUSE_SPLINES
1602 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1603 wxCoord width
, wxCoord height
,
1604 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1605 wxRasterOperationMode rop
, bool useMask
,
1606 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1607 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1609 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1610 wxT("mask coordinates are not supported") );
1612 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1614 // Blit into a bitmap.
1615 wxBitmap
bitmap( width
, height
);
1617 memDC
.SelectObject(bitmap
);
1618 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1619 memDC
.SelectObject(wxNullBitmap
);
1621 // Draw bitmap. scaling and positioning is done there.
1622 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1627 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1629 DoDrawBitmap( icon
, x
, y
, true );
1632 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1634 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1636 x
= wxCoord(XLOG2DEV(x
));
1637 y
= wxCoord(YLOG2DEV(y
));
1638 int bw
= bitmap
.GetWidth();
1639 int bh
= bitmap
.GetHeight();
1640 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1641 if (!useMask
&& !bitmap
.HasPixbuf() && bitmap
.GetMask())
1642 bmpSource
.SetMask(NULL
);
1644 cairo_save(m_cairo
);
1646 // Prepare to draw the image.
1647 cairo_translate(m_cairo
, x
, y
);
1650 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1651 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1652 cairo_scale(m_cairo
, scaleX
, scaleY
);
1654 gdk_cairo_set_source_pixbuf(m_cairo
, bmpSource
.GetPixbuf(), 0, 0);
1655 cairo_pattern_set_filter(cairo_get_source(m_cairo
), CAIRO_FILTER_NEAREST
);
1656 // Use the original size here since the context is scaled already.
1657 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1658 // Fill the rectangle using the pattern.
1659 cairo_fill(m_cairo
);
1661 CalcBoundingBox(0,0);
1662 CalcBoundingBox(bw
,bh
);
1664 cairo_restore(m_cairo
);
1667 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1669 DoDrawRotatedText( text
, x
, y
, 0.0 );
1672 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1674 double xx
= XLOG2DEV(x
);
1675 double yy
= YLOG2DEV(y
);
1679 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1681 const wxScopedCharBuffer data
= text
.utf8_str();
1683 size_t datalen
= strlen(data
);
1684 pango_layout_set_text( m_layout
, data
, datalen
);
1688 PangoAttrList
*attrs
= pango_attr_list_new();
1689 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1691 a
->end_index
= datalen
;
1692 pango_attr_list_insert(attrs
, a
);
1693 pango_layout_set_attributes(m_layout
, attrs
);
1694 pango_attr_list_unref(attrs
);
1697 if (m_textForegroundColour
.Ok())
1699 unsigned char red
= m_textForegroundColour
.Red();
1700 unsigned char blue
= m_textForegroundColour
.Blue();
1701 unsigned char green
= m_textForegroundColour
.Green();
1702 unsigned char alpha
= m_textForegroundColour
.Alpha();
1704 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1706 double redPS
= (double)(red
) / 255.0;
1707 double bluePS
= (double)(blue
) / 255.0;
1708 double greenPS
= (double)(green
) / 255.0;
1709 double alphaPS
= (double)(alpha
) / 255.0;
1711 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1714 m_currentBlue
= blue
;
1715 m_currentGreen
= green
;
1716 m_currentAlpha
= alpha
;
1721 cairo_move_to (m_cairo
, xx
, yy
);
1723 cairo_save( m_cairo
);
1725 if (fabs(angle
) > 0.00001)
1726 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1728 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1731 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1733 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1735 unsigned char red
= m_textBackgroundColour
.Red();
1736 unsigned char blue
= m_textBackgroundColour
.Blue();
1737 unsigned char green
= m_textBackgroundColour
.Green();
1738 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1740 double redPS
= (double)(red
) / 255.0;
1741 double bluePS
= (double)(blue
) / 255.0;
1742 double greenPS
= (double)(green
) / 255.0;
1743 double alphaPS
= (double)(alpha
) / 255.0;
1745 cairo_save(m_cairo
);
1746 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1747 cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1748 cairo_fill(m_cairo
);
1749 cairo_restore(m_cairo
);
1752 pango_cairo_update_layout (m_cairo
, m_layout
);
1753 pango_cairo_show_layout (m_cairo
, m_layout
);
1755 cairo_restore( m_cairo
);
1759 // Undo underline attributes setting
1760 pango_layout_set_attributes(m_layout
, NULL
);
1763 // Back to device units:
1764 CalcBoundingBox (x
, y
);
1765 CalcBoundingBox (x
+ w
, y
+ h
);
1768 void wxGtkPrinterDCImpl::Clear()
1770 // Clear does nothing for printing, but keep the code
1773 cairo_save(m_cairo);
1774 cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1775 SetBrush(m_backgroundBrush);
1776 cairo_paint(m_cairo);
1777 cairo_restore(m_cairo);
1781 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1788 pango_font_description_free( m_fontdesc
);
1790 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1792 float size
= pango_font_description_get_size( m_fontdesc
);
1793 size
= size
* GetFontPointSizeAdjustment(72.0);
1794 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1796 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1800 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1802 if (!pen
.Ok()) return;
1808 if (m_pen
.GetWidth() <= 0)
1811 width
= (double) m_pen
.GetWidth();
1813 cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1814 static const double dotted
[] = {2.0, 5.0};
1815 static const double short_dashed
[] = {4.0, 4.0};
1816 static const double long_dashed
[] = {4.0, 8.0};
1817 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1819 switch (m_pen
.GetStyle())
1821 case wxPENSTYLE_DOT
: cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1822 case wxPENSTYLE_SHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1823 case wxPENSTYLE_LONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1824 case wxPENSTYLE_DOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1825 case wxPENSTYLE_USER_DASH
:
1828 int num
= m_pen
.GetDashes (&wx_dashes
);
1829 gdouble
*g_dashes
= g_new( gdouble
, num
);
1831 for (i
= 0; i
< num
; ++i
)
1832 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1833 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1837 case wxPENSTYLE_SOLID
:
1838 case wxPENSTYLE_TRANSPARENT
:
1839 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1842 switch (m_pen
.GetCap())
1844 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1845 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1847 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1850 switch (m_pen
.GetJoin())
1852 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1853 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1855 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1858 unsigned char red
= m_pen
.GetColour().Red();
1859 unsigned char blue
= m_pen
.GetColour().Blue();
1860 unsigned char green
= m_pen
.GetColour().Green();
1861 unsigned char alpha
= m_pen
.GetColour().Alpha();
1863 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1865 double redPS
= (double)(red
) / 255.0;
1866 double bluePS
= (double)(blue
) / 255.0;
1867 double greenPS
= (double)(green
) / 255.0;
1868 double alphaPS
= (double)(alpha
) / 255.0;
1870 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1873 m_currentBlue
= blue
;
1874 m_currentGreen
= green
;
1875 m_currentAlpha
= alpha
;
1879 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1881 if (!brush
.Ok()) return;
1885 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1887 cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1896 unsigned char red
= m_brush
.GetColour().Red();
1897 unsigned char blue
= m_brush
.GetColour().Blue();
1898 unsigned char green
= m_brush
.GetColour().Green();
1899 unsigned char alpha
= m_brush
.GetColour().Alpha();
1901 double redPS
= (double)(red
) / 255.0;
1902 double bluePS
= (double)(blue
) / 255.0;
1903 double greenPS
= (double)(green
) / 255.0;
1904 double alphaPS
= (double)(alpha
) / 255.0;
1906 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1908 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1911 m_currentBlue
= blue
;
1912 m_currentGreen
= green
;
1913 m_currentAlpha
= alpha
;
1916 if (m_brush
.IsHatch())
1919 cairo_surface_t
*surface
;
1920 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
1921 cr
= cairo_create(surface
);
1922 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
1923 cairo_set_line_width(cr
, 1);
1924 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
1926 switch (m_brush
.GetStyle())
1928 case wxBRUSHSTYLE_CROSS_HATCH
:
1929 cairo_move_to(cr
, 5, 0);
1930 cairo_line_to(cr
, 5, 10);
1931 cairo_move_to(cr
, 0, 5);
1932 cairo_line_to(cr
, 10, 5);
1934 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
1935 cairo_move_to(cr
, 0, 10);
1936 cairo_line_to(cr
, 10, 0);
1938 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
1939 cairo_move_to(cr
, 0, 0);
1940 cairo_line_to(cr
, 10, 10);
1942 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
1943 cairo_move_to(cr
, 0, 0);
1944 cairo_line_to(cr
, 10, 10);
1945 cairo_move_to(cr
, 10, 0);
1946 cairo_line_to(cr
, 0, 10);
1948 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
1949 cairo_move_to(cr
, 0, 5);
1950 cairo_line_to(cr
, 10, 5);
1952 case wxBRUSHSTYLE_VERTICAL_HATCH
:
1953 cairo_move_to(cr
, 5, 0);
1954 cairo_line_to(cr
, 5, 10);
1957 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
1960 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
1964 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
1965 cairo_surface_destroy(surface
);
1966 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
1967 cairo_set_source(m_cairo
, pattern
);
1968 cairo_pattern_destroy(pattern
);
1972 void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1974 if (function
== wxCLEAR
)
1975 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
1976 else if (function
== wxOR
)
1977 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
1978 else if (function
== wxNO_OP
)
1979 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
1980 else if (function
== wxAND
)
1981 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
1982 else if (function
== wxSET
)
1983 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
1984 else if (function
== wxXOR
)
1985 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
1986 else // wxCOPY or anything else.
1987 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
1990 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
1992 m_backgroundBrush
= brush
;
1993 cairo_save(m_cairo
);
1994 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
1996 SetBrush(m_backgroundBrush
);
1997 cairo_paint(m_cairo
);
1998 cairo_restore(m_cairo
);
2001 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2003 if (mode
== wxBRUSHSTYLE_SOLID
)
2004 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2006 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2009 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2011 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2012 cairo_clip(m_cairo
);
2015 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2017 cairo_reset_clip(m_cairo
);
2020 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2025 void wxGtkPrinterDCImpl::EndDoc()
2030 void wxGtkPrinterDCImpl::StartPage()
2035 void wxGtkPrinterDCImpl::EndPage()
2040 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2042 pango_layout_set_text( m_layout
, "H", 1 );
2045 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2047 return wxRound( h
* m_PS2DEV
);
2050 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2052 pango_layout_set_text( m_layout
, "H", 1 );
2055 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2057 return wxRound( w
* m_PS2DEV
);
2060 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2062 wxCoord
*externalLeading
,
2063 const wxFont
*theFont
) const
2071 if ( externalLeading
)
2072 *externalLeading
= 0;
2079 cairo_save( m_cairo
);
2080 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
2082 // Set layout's text
2083 const wxScopedCharBuffer dataUTF8
= string
.utf8_str();
2088 // scale the font and apply it
2089 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2090 float size
= pango_font_description_get_size(desc
);
2091 size
= size
* GetFontPointSizeAdjustment(72.0);
2092 pango_font_description_set_size(desc
, (gint
)size
);
2094 pango_layout_set_font_description(m_layout
, desc
);
2097 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2100 pango_layout_get_pixel_size( m_layout
, width
, &h
);
2106 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2107 int baseline
= pango_layout_iter_get_baseline(iter
);
2108 pango_layout_iter_free(iter
);
2109 *descent
= h
- PANGO_PIXELS(baseline
);
2114 // restore font and reset font's size back
2115 pango_layout_set_font_description(m_layout
, m_fontdesc
);
2117 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2118 pango_font_description_set_size(desc
, oldSize
);
2121 cairo_restore( m_cairo
);
2124 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2126 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2129 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2131 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2134 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2136 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2139 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2141 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2144 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2146 return wxSize( (int)m_resolution
, (int)m_resolution
);
2149 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2154 // overriden for wxPrinterDC Impl
2156 wxRect
wxGtkPrinterDCImpl::GetPaperRect() const
2158 // Does GtkPrint support printer margins?
2161 DoGetSize( &w
, &h
);
2162 return wxRect( 0,0,w
,h
);
2165 int wxGtkPrinterDCImpl::GetResolution() const
2167 return m_resolution
;
2170 // ----------------------------------------------------------------------------
2172 // ----------------------------------------------------------------------------
2174 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2176 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2177 wxPrintout
* WXUNUSED(printoutForPrinting
),
2180 // convert wxPrintQuality to resolution (input pointer can be NULL)
2181 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2184 case wxPRINT_QUALITY_HIGH
:
2185 m_resolution
= 1200;
2188 case wxPRINT_QUALITY_LOW
:
2192 case wxPRINT_QUALITY_DRAFT
:
2199 // positive values directly indicate print resolution
2200 m_resolution
= quality
;
2204 wxFAIL_MSG( "unknown print quality" );
2207 case wxPRINT_QUALITY_MEDIUM
:
2216 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2217 wxPrintout
*printoutForPrinting
,
2218 wxPrintDialogData
*data
)
2219 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2221 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2224 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2225 wxPrintout
*printoutForPrinting
,
2227 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2229 Init(printout
, printoutForPrinting
, data
);
2232 wxGtkPrintPreview::~wxGtkPrintPreview()
2236 bool wxGtkPrintPreview::Print(bool interactive
)
2238 if (!m_printPrintout
)
2241 wxPrinter
printer(& m_printDialogData
);
2242 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2245 void wxGtkPrintPreview::DetermineScaling()
2247 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2249 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2251 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2255 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2256 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2258 // Get width and height in points (1/72th of an inch)
2259 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2260 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2261 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2263 wxSize
sizeTenthsMM(paper
->GetSize());
2264 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2266 // If in landscape mode, we need to swap the width and height.
2267 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2269 m_pageWidth
= sizeDevUnits
.y
;
2270 m_pageHeight
= sizeDevUnits
.x
;
2271 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2275 m_pageWidth
= sizeDevUnits
.x
;
2276 m_pageHeight
= sizeDevUnits
.y
;
2277 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2279 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2280 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2282 // At 100%, the page should look about page-size on the screen.
2283 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2284 m_previewScaleY
= m_previewScaleX
;