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 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
217 GtkPrintOperationPreview
* WXUNUSED(preview
),
218 GtkPrintContext
*context
,
222 wxPrintout
*printout
= (wxPrintout
*) user_data
;
224 printout
->SetIsPreview(true);
226 /* We create a Cairo context with 72dpi resolution. This resolution is
227 * only used for positioning. */
228 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
229 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
235 //----------------------------------------------------------------------------
236 // wxGtkPrintNativeData
237 //----------------------------------------------------------------------------
239 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
241 wxGtkPrintNativeData::wxGtkPrintNativeData()
243 m_config
= gtk_print_settings_new();
246 wxGtkPrintNativeData::~wxGtkPrintNativeData()
248 g_object_unref (m_config
);
251 // Convert datas stored in m_config to a wxPrintData.
252 // Called by wxPrintData::ConvertFromNative().
253 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
258 int resolution
= gtk_print_settings_get_resolution(m_config
);
259 if ( resolution
> 0 )
261 // if resolution is explicitly set, use it
262 data
.SetQuality(resolution
);
264 else // use more vague "quality"
266 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
267 if (quality
== GTK_PRINT_QUALITY_HIGH
)
268 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
269 else if (quality
== GTK_PRINT_QUALITY_LOW
)
270 data
.SetQuality(wxPRINT_QUALITY_LOW
);
271 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
272 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
274 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
277 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
279 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
281 switch (gtk_print_settings_get_duplex(m_config
))
283 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
286 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
290 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
294 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
295 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
297 data
.SetOrientation(wxPORTRAIT
);
298 data
.SetOrientationReversed(false);
300 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
302 data
.SetOrientation(wxLANDSCAPE
);
303 data
.SetOrientationReversed(false);
305 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
307 data
.SetOrientation(wxPORTRAIT
);
308 data
.SetOrientationReversed(true);
310 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
312 data
.SetOrientation(wxLANDSCAPE
);
313 data
.SetOrientationReversed(true);
316 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
318 // Paper formats : these are the most common paper formats.
319 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
321 data
.SetPaperId(wxPAPER_NONE
);
322 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
323 data
.SetPaperId(wxPAPER_A3
);
324 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
325 data
.SetPaperId(wxPAPER_A4
);
326 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
327 data
.SetPaperId(wxPAPER_A5
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
329 data
.SetPaperId(wxPAPER_B5
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
331 data
.SetPaperId(wxPAPER_LETTER
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
333 data
.SetPaperId(wxPAPER_LEGAL
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
335 data
.SetPaperId(wxPAPER_EXECUTIVE
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
337 data
.SetPaperId(wxPAPER_ENV_10
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
339 data
.SetPaperId(wxPAPER_ENV_C5
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
341 data
.SetPaperId(wxPAPER_ENV_C6
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
343 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
345 data
.SetPaperId(wxPAPER_ENV_B5
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
347 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
349 data
.SetPaperId( wxPAPER_CSHEET
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
351 data
.SetPaperId( wxPAPER_DSHEET
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
353 data
.SetPaperId( wxPAPER_ESHEET
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
355 data
.SetPaperId( wxPAPER_LETTERSMALL
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
357 data
.SetPaperId( wxPAPER_TABLOID
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
359 data
.SetPaperId( wxPAPER_LEDGER
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
361 data
.SetPaperId( wxPAPER_STATEMENT
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
363 data
.SetPaperId( wxPAPER_A4SMALL
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
365 data
.SetPaperId( wxPAPER_B4
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
367 data
.SetPaperId( wxPAPER_FOLIO
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
369 data
.SetPaperId( wxPAPER_QUARTO
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
371 data
.SetPaperId( wxPAPER_10X14
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
373 data
.SetPaperId( wxPAPER_11X17
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
375 data
.SetPaperId( wxPAPER_NOTE
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
377 data
.SetPaperId( wxPAPER_ENV_9
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
379 data
.SetPaperId( wxPAPER_ENV_11
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
381 data
.SetPaperId( wxPAPER_ENV_12
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
383 data
.SetPaperId( wxPAPER_ENV_14
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
385 data
.SetPaperId( wxPAPER_ENV_DL
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
387 data
.SetPaperId( wxPAPER_ENV_C3
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
389 data
.SetPaperId( wxPAPER_ENV_C4
);
390 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
391 data
.SetPaperId( wxPAPER_ENV_C65
);
392 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
393 data
.SetPaperId( wxPAPER_ENV_B4
);
394 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
395 data
.SetPaperId( wxPAPER_ENV_B6
);
396 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
397 data
.SetPaperId( wxPAPER_ENV_ITALY
);
398 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
399 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
400 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
401 data
.SetPaperId( wxPAPER_FANFOLD_US
);
402 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
403 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
404 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
405 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
407 data
.SetPaperId(wxPAPER_NONE
);
411 // Put datas given by the wxPrintData into m_config.
412 // Called by wxPrintData::ConvertToNative().
413 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
418 wxPrintQuality quality
= data
.GetQuality();
419 if (quality
== wxPRINT_QUALITY_HIGH
)
420 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
421 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
422 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
423 else if (quality
== wxPRINT_QUALITY_LOW
)
424 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
425 else if (quality
== wxPRINT_QUALITY_DRAFT
)
426 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
427 else if (quality
> 1)
428 gtk_print_settings_set_resolution (m_config
, quality
);
430 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
432 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
434 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
436 switch (data
.GetDuplex())
438 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
441 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
445 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
449 if (!data
.IsOrientationReversed())
451 if (data
.GetOrientation() == wxLANDSCAPE
)
452 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
454 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
457 if (data
.GetOrientation() == wxLANDSCAPE
)
458 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
460 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
463 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
465 // Paper formats: these are the most common paper formats.
466 switch (data
.GetPaperId())
468 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
470 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
472 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
474 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
476 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
478 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
480 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
482 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
484 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
486 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
488 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
490 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
492 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
494 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
496 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
498 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
500 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
502 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
504 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
506 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
508 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
510 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
512 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
514 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
516 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
518 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
520 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
522 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
524 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
526 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
528 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
530 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
532 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
534 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
536 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
538 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
540 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
542 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
544 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
546 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
548 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
550 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
559 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
562 m_config
= gtk_print_settings_copy(config
);
565 // Extract page setup from settings.
566 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
568 GtkPageSetup
* page_setup
= gtk_page_setup_new();
569 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
571 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
572 if (paper_size
!= NULL
)
573 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
578 // Insert page setup into a given GtkPrintSettings.
579 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
581 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
582 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
585 //----------------------------------------------------------------------------
587 //----------------------------------------------------------------------------
589 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
591 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
592 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
593 wxPoint(0, 0), wxSize(600, 600),
594 wxDEFAULT_DIALOG_STYLE
|
598 m_printDialogData
= *data
;
604 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
605 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
606 wxPoint(0, 0), wxSize(600, 600),
607 wxDEFAULT_DIALOG_STYLE
|
611 m_printDialogData
= *data
;
618 wxGtkPrintDialog::~wxGtkPrintDialog()
622 // This is called even if we actually don't want the dialog to appear.
623 int wxGtkPrintDialog::ShowModal()
625 GtkPrintOperationResult response
;
627 // We need to restore the settings given in the constructor.
628 wxPrintData data
= m_printDialogData
.GetPrintData();
629 wxGtkPrintNativeData
*native
=
630 (wxGtkPrintNativeData
*) data
.GetNativeData();
631 data
.ConvertToNative();
633 GtkPrintSettings
* settings
= native
->GetPrintConfig();
635 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
636 int fromPage
= m_printDialogData
.GetFromPage();
637 int toPage
= m_printDialogData
.GetToPage();
638 if (m_printDialogData
.GetSelection())
639 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
640 else if (m_printDialogData
.GetAllPages())
641 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
643 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
645 range
= g_new (GtkPageRange
, 1);
646 range
[0].start
= fromPage
-1;
647 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
648 gtk_print_settings_set_page_ranges (settings
, range
, 1);
651 // If the settings are OK, we restore it.
652 if (settings
!= NULL
)
653 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
654 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
656 // Show the dialog if needed.
657 GError
* gError
= NULL
;
659 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
661 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
663 // Does everything went well?
664 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
668 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
670 g_error_free (gError
);
671 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
672 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
675 // Now get the settings and save it.
676 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
677 native
->SetPrintConfig(newSettings
);
678 data
.ConvertFromNative();
680 // Same problem as a few lines before.
681 switch (gtk_print_settings_get_print_pages(newSettings
))
683 case GTK_PRINT_PAGES_CURRENT
:
684 m_printDialogData
.SetSelection( true );
686 case GTK_PRINT_PAGES_RANGES
:
687 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
688 // 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
689 // will hit "OK" button. However we can only save 1-3 in the print data.
692 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
695 m_printDialogData
.SetFromPage( range
[0].start
);
696 m_printDialogData
.SetToPage( range
[0].end
);
699 m_printDialogData
.SetAllPages( true );
700 m_printDialogData
.SetFromPage( 0 );
701 m_printDialogData
.SetToPage( 9999 );
704 case GTK_PRINT_PAGES_ALL
:
706 m_printDialogData
.SetAllPages( true );
707 m_printDialogData
.SetFromPage( 0 );
708 m_printDialogData
.SetToPage( 9999 );
715 //----------------------------------------------------------------------------
716 // wxGtkPageSetupDialog
717 //----------------------------------------------------------------------------
719 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
721 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
722 wxPageSetupDialogData
* data
)
725 m_pageDialogData
= *data
;
730 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
734 int wxGtkPageSetupDialog::ShowModal()
737 m_pageDialogData
.GetPrintData().ConvertToNative();
738 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
739 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
741 // We only need the pagesetup data which are part of the settings.
742 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
744 // If the user used a custom paper format the last time he printed, we have to restore it too.
745 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
747 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
748 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
750 wxString title
= _("Custom size");
751 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
752 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
753 g_object_unref(customSize
);
757 // Now show the dialog.
758 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
763 if (newPageSetup
!= oldPageSetup
)
765 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
766 m_pageDialogData
.GetPrintData().ConvertFromNative();
768 // Store custom paper format if any.
769 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
771 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
772 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
773 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
774 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
775 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
777 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
778 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
780 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
781 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
783 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
796 //----------------------------------------------------------------------------
798 //----------------------------------------------------------------------------
800 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
802 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
803 wxPrinterBase( data
)
808 m_printDialogData
= *data
;
811 wxGtkPrinter::~wxGtkPrinter()
815 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
819 sm_lastError
= wxPRINTER_ERROR
;
823 // Let's correct the PageInfo just in case the app gives wrong values.
824 int fromPage
, toPage
;
825 int minPage
, maxPage
;
826 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
827 m_printDialogData
.SetAllPages(true);
829 if (minPage
< 1) minPage
= 1;
830 if (maxPage
< 1) maxPage
= 9999;
831 if (maxPage
< minPage
) maxPage
= minPage
;
833 m_printDialogData
.SetMinPage(minPage
);
834 m_printDialogData
.SetMaxPage(maxPage
);
837 if (fromPage
< minPage
) fromPage
= minPage
;
838 else if (fromPage
> maxPage
) fromPage
= maxPage
;
839 m_printDialogData
.SetFromPage(fromPage
);
843 m_printDialogData
.SetToPage(toPage
);
844 if (toPage
> maxPage
) toPage
= maxPage
;
845 else if (toPage
< minPage
) toPage
= minPage
;
848 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
851 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
852 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
854 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
856 native
->SetPrintJob( printOp
);
858 printout
->SetIsPreview(false);
860 wxPrinterToGtkData dataToSend
;
861 dataToSend
.printer
= this;
862 dataToSend
.printout
= printout
;
864 // These Gtk signals are caught here.
865 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
866 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
867 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
868 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
870 // This is used to setup the DC and
871 // show the dialog if desired
872 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
873 dialog
.SetPrintDC(m_dc
);
874 dialog
.SetShowDialog(prompt
);
876 // doesn't necessarily show
877 int ret
= dialog
.ShowModal();
878 if (ret
== wxID_CANCEL
)
880 sm_lastError
= wxPRINTER_CANCELLED
;
884 sm_lastError
= wxPRINTER_ERROR
;
885 wxFAIL_MSG(_("The print dialog returned an error."));
888 g_object_unref (printOp
);
890 return (sm_lastError
== wxPRINTER_NO_ERROR
);
893 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
895 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
896 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
898 // We need to update printdata with the new data from the dialog and we
899 // have to do this here because this method needs this new data and we
900 // cannot update it earlier
901 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
902 printdata
.ConvertFromNative();
904 SetPrintContext(context
);
905 native
->SetPrintContext( context
);
907 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
912 if (sm_lastError
!= wxPRINTER_CANCELLED
)
914 sm_lastError
= wxPRINTER_ERROR
;
915 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
920 printout
->SetPPIScreen(wxGetDisplayPPI());
921 printout
->SetPPIPrinter( printDC
->GetResolution(),
922 printDC
->GetResolution() );
924 printout
->SetDC(m_dc
);
927 m_dc
->GetSize(&w
, &h
);
928 printout
->SetPageSizePixels((int)w
, (int)h
);
929 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
931 m_dc
->GetSizeMM(&mw
, &mh
);
932 printout
->SetPageSizeMM((int)mw
, (int)mh
);
933 printout
->OnPreparePrinting();
935 // Get some parameters from the printout, if defined.
936 int fromPage
, toPage
;
937 int minPage
, maxPage
;
938 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
942 sm_lastError
= wxPRINTER_ERROR
;
943 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
947 printout
->OnBeginPrinting();
951 // If we're not previewing we need to calculate the number of pages to print.
952 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
953 // have defined in the dialog. So the number of pages is the maximum available.
954 if (!printout
->IsPreview())
956 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
957 switch (gtk_print_settings_get_print_pages(settings
))
959 case GTK_PRINT_PAGES_CURRENT
:
962 case GTK_PRINT_PAGES_RANGES
:
963 {gint num_ranges
= 0;
966 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
967 for (i
=0; i
<num_ranges
; i
++)
969 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
970 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
971 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
972 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
973 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
975 gtk_print_settings_set_page_ranges (settings
, range
, 1);
977 case GTK_PRINT_PAGES_ALL
:
979 numPages
= maxPage
- minPage
+ 1;
983 else numPages
= maxPage
- minPage
+ 1;
985 gtk_print_operation_set_n_pages(operation
, numPages
);
988 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
989 GtkPrintOperation
*operation
,
990 GtkPrintContext
* WXUNUSED(context
),
993 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
994 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
996 int numPageToDraw
= page_nr
+ minPage
;
997 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
998 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
1000 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
1001 switch (gtk_print_settings_get_print_pages(settings
))
1003 case GTK_PRINT_PAGES_CURRENT
:
1004 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
1005 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1007 case GTK_PRINT_PAGES_RANGES
:
1008 {gint num_ranges
= 0;
1009 GtkPageRange
* range
;
1010 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1011 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1012 if (num_ranges
>= 1)
1014 startPage
= range
[0].start
+ 1;
1015 endPage
= range
[0].end
+ 1;
1018 startPage
= minPage
;
1022 case GTK_PRINT_PAGES_ALL
:
1024 startPage
= minPage
;
1029 if(numPageToDraw
== startPage
)
1031 if (!printout
->OnBeginDocument(startPage
, endPage
))
1033 wxLogError(_("Could not start printing."));
1034 sm_lastError
= wxPRINTER_ERROR
;
1038 // The app can render the page numPageToDraw.
1039 if (printout
->HasPage(numPageToDraw
))
1042 printout
->OnPrintPage(numPageToDraw
);
1047 if(numPageToDraw
== endPage
)
1049 printout
->OnEndDocument();
1053 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1055 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1057 dialog
.SetPrintDC(m_dc
);
1058 dialog
.SetShowDialog(true);
1060 int ret
= dialog
.ShowModal();
1062 if (ret
== wxID_CANCEL
)
1064 sm_lastError
= wxPRINTER_CANCELLED
;
1069 sm_lastError
= wxPRINTER_ERROR
;
1070 wxFAIL_MSG(_("The print dialog returned an error."));
1074 m_printDialogData
= dialog
.GetPrintDialogData();
1076 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1079 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1081 // Obsolete, for backward compatibility.
1085 //-----------------------------------------------------------------------------
1087 //-----------------------------------------------------------------------------
1089 #define wxCAIRO_SCALE 1
1093 #define XLOG2DEV(x) LogicalToDeviceX(x)
1094 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1095 #define YLOG2DEV(x) LogicalToDeviceY(x)
1096 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1100 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1101 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1102 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1103 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1107 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1109 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1114 wxGtkPrintNativeData
*native
=
1115 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1117 m_gpc
= native
->GetPrintContext();
1119 // Match print quality to resolution (high = 1200dpi)
1120 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1121 if (m_resolution
< 0)
1122 m_resolution
= (1 << (m_resolution
+4)) *150;
1124 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1125 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1126 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1128 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1134 cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1136 m_PS2DEV
= (double)m_resolution
/ 72.0;
1137 m_DEV2PS
= 72.0 / (double)m_resolution
;
1144 m_signX
= 1; // default x-axis left to right.
1145 m_signY
= 1; // default y-axis bottom up -> top down.
1147 // By default the origin of the Cairo context is in the upper left
1148 // corner of the printable area. We need to translate it so that it
1149 // is in the upper left corner of the paper (without margins)
1150 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1152 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1153 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1154 cairo_translate(m_cairo
, -ml
, -mt
);
1157 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1159 g_object_unref(m_context
);
1160 g_object_unref(m_layout
);
1163 bool wxGtkPrinterDCImpl::IsOk() const
1165 return m_gpc
!= NULL
;
1168 void* wxGtkPrinterDCImpl::GetCairoContext() const
1170 return (void*) cairo_reference( m_cairo
);
1173 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1174 wxCoord
WXUNUSED(y1
),
1175 const wxColour
& WXUNUSED(col
),
1176 int WXUNUSED(style
))
1178 // We can't access the given coord as a Cairo context is scalable, ie a
1179 // coord doesn't mean anything in this context.
1180 wxFAIL_MSG(_("not implemented"));
1184 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1186 wxCoord xC
= circleCenter
.x
;
1187 wxCoord yC
= circleCenter
.y
;
1188 wxCoord xR
= rect
.x
;
1189 wxCoord yR
= rect
.y
;
1190 wxCoord w
= rect
.width
;
1191 wxCoord h
= rect
.height
;
1193 const double r2
= (w
/2)*(w
/2)+(h
/2)*(h
/2);
1194 double radius
= sqrt(r2
);
1196 unsigned char redI
= initialColour
.Red();
1197 unsigned char blueI
= initialColour
.Blue();
1198 unsigned char greenI
= initialColour
.Green();
1199 unsigned char alphaI
= initialColour
.Alpha();
1200 unsigned char redD
= destColour
.Red();
1201 unsigned char blueD
= destColour
.Blue();
1202 unsigned char greenD
= destColour
.Green();
1203 unsigned char alphaD
= destColour
.Alpha();
1205 double redIPS
= (double)(redI
) / 255.0;
1206 double blueIPS
= (double)(blueI
) / 255.0;
1207 double greenIPS
= (double)(greenI
) / 255.0;
1208 double alphaIPS
= (double)(alphaI
) / 255.0;
1209 double redDPS
= (double)(redD
) / 255.0;
1210 double blueDPS
= (double)(blueD
) / 255.0;
1211 double greenDPS
= (double)(greenD
) / 255.0;
1212 double alphaDPS
= (double)(alphaD
) / 255.0;
1214 // Create a pattern with the gradient.
1215 cairo_pattern_t
* gradient
;
1216 gradient
= cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1217 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1218 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1220 // Fill the rectangle with this pattern.
1221 cairo_set_source(m_cairo
, gradient
);
1222 cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1223 cairo_fill(m_cairo
);
1225 cairo_pattern_destroy(gradient
);
1227 CalcBoundingBox(xR
, yR
);
1228 CalcBoundingBox(xR
+w
, yR
+h
);
1231 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1235 wxCoord w
= rect
.width
;
1236 wxCoord h
= rect
.height
;
1238 unsigned char redI
= initialColour
.Red();
1239 unsigned char blueI
= initialColour
.Blue();
1240 unsigned char greenI
= initialColour
.Green();
1241 unsigned char alphaI
= initialColour
.Alpha();
1242 unsigned char redD
= destColour
.Red();
1243 unsigned char blueD
= destColour
.Blue();
1244 unsigned char greenD
= destColour
.Green();
1245 unsigned char alphaD
= destColour
.Alpha();
1247 double redIPS
= (double)(redI
) / 255.0;
1248 double blueIPS
= (double)(blueI
) / 255.0;
1249 double greenIPS
= (double)(greenI
) / 255.0;
1250 double alphaIPS
= (double)(alphaI
) / 255.0;
1251 double redDPS
= (double)(redD
) / 255.0;
1252 double blueDPS
= (double)(blueD
) / 255.0;
1253 double greenDPS
= (double)(greenD
) / 255.0;
1254 double alphaDPS
= (double)(alphaD
) / 255.0;
1256 // Create a pattern with the gradient.
1257 cairo_pattern_t
* gradient
;
1258 gradient
= cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1260 if (nDirection
== wxWEST
)
1262 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1263 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1266 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1267 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1270 // Fill the rectangle with this pattern.
1271 cairo_set_source(m_cairo
, gradient
);
1272 cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1273 cairo_fill(m_cairo
);
1275 cairo_pattern_destroy(gradient
);
1277 CalcBoundingBox(x
, y
);
1278 CalcBoundingBox(x
+w
, y
+h
);
1281 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1282 wxCoord
WXUNUSED(y1
),
1283 wxColour
* WXUNUSED(col
)) const
1285 wxFAIL_MSG(_("not implemented"));
1289 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1291 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1294 cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1295 cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1296 cairo_stroke ( m_cairo
);
1298 CalcBoundingBox( x1
, y1
);
1299 CalcBoundingBox( x2
, y2
);
1302 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1309 cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1310 cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1311 cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1312 cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1314 cairo_stroke (m_cairo
);
1315 CalcBoundingBox( 0, 0 );
1316 CalcBoundingBox( w
, h
);
1319 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1321 double dx
= x1
- xc
;
1322 double dy
= y1
- yc
;
1323 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1325 double alpha1
, alpha2
;
1326 if (x1
== x2
&& y1
== y2
)
1334 alpha1
= alpha2
= 0.0;
1338 alpha1
= (x1
- xc
== 0) ?
1339 (y1
- yc
< 0) ? 90.0 : -90.0 :
1340 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1341 alpha2
= (x2
- xc
== 0) ?
1342 (y2
- yc
< 0) ? 90.0 : -90.0 :
1343 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1345 while (alpha1
<= 0) alpha1
+= 360;
1346 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1347 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1348 while (alpha2
> 360) alpha2
-= 360;
1354 cairo_new_path(m_cairo
);
1356 cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1357 cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1358 cairo_close_path (m_cairo
);
1360 SetBrush( m_brush
);
1361 cairo_fill_preserve( m_cairo
);
1364 cairo_stroke( m_cairo
);
1366 CalcBoundingBox (x1
, y1
);
1367 CalcBoundingBox (xc
, yc
);
1368 CalcBoundingBox (x2
, y2
);
1371 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1373 cairo_save( m_cairo
);
1375 cairo_new_path(m_cairo
);
1377 cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1378 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1379 cairo_scale( m_cairo
, 1.0, scale
);
1381 cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1384 cairo_stroke_preserve( m_cairo
);
1386 cairo_line_to(m_cairo
, 0,0);
1388 SetBrush( m_brush
);
1389 cairo_fill( m_cairo
);
1391 cairo_restore( m_cairo
);
1393 CalcBoundingBox( x
, y
);
1394 CalcBoundingBox( x
+w
, y
+h
);
1397 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1399 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1403 cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1404 cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1405 cairo_stroke ( m_cairo
);
1407 CalcBoundingBox( x
, y
);
1410 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1412 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1419 for ( i
=0; i
<n
; i
++ )
1420 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1422 cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1424 for (i
= 1; i
< n
; i
++)
1425 cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1427 cairo_stroke ( m_cairo
);
1430 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1434 cairo_save(m_cairo
);
1435 if (fillStyle
== wxWINDING_RULE
)
1436 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1438 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1440 int x
= points
[0].x
+ xoffset
;
1441 int y
= points
[0].y
+ yoffset
;
1442 cairo_new_path(m_cairo
);
1443 cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1445 for (i
= 1; i
< n
; i
++)
1447 int x
= points
[i
].x
+ xoffset
;
1448 int y
= points
[i
].y
+ yoffset
;
1449 cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1451 cairo_close_path(m_cairo
);
1453 SetBrush( m_brush
);
1454 cairo_fill_preserve( m_cairo
);
1457 cairo_stroke( m_cairo
);
1459 CalcBoundingBox( x
, y
);
1461 cairo_restore(m_cairo
);
1464 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1466 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1469 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1474 cairo_new_path(m_cairo
);
1475 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1477 SetBrush( m_brush
);
1478 cairo_fill_preserve( m_cairo
);
1481 cairo_stroke( m_cairo
);
1483 CalcBoundingBox( x
, y
);
1484 CalcBoundingBox( x
+ width
, y
+ height
);
1487 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1492 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1494 wxCoord dd
= 2 * (wxCoord
) radius
;
1495 if (dd
> width
) dd
= width
;
1496 if (dd
> height
) dd
= height
;
1499 wxCoord rad
= (wxCoord
) radius
;
1501 cairo_new_path(m_cairo
);
1502 cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1503 cairo_curve_to(m_cairo
,
1504 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1505 XLOG2DEV(x
),YLOG2DEV(y
),
1506 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1507 cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1508 cairo_curve_to(m_cairo
,
1509 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1510 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1511 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1512 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1513 cairo_curve_to(m_cairo
,
1514 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1515 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1516 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1517 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1518 cairo_curve_to(m_cairo
,
1519 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1520 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1521 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1522 cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1523 cairo_close_path(m_cairo
);
1526 cairo_fill_preserve(m_cairo
);
1529 cairo_stroke(m_cairo
);
1531 CalcBoundingBox(x
,y
);
1532 CalcBoundingBox(x
+width
,y
+height
);
1535 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1540 cairo_save (m_cairo
);
1542 cairo_new_path(m_cairo
);
1544 cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1545 cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1546 cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1548 SetBrush( m_brush
);
1549 cairo_fill_preserve( m_cairo
);
1552 cairo_stroke( m_cairo
);
1554 CalcBoundingBox( x
, y
);
1555 CalcBoundingBox( x
+ width
, y
+ height
);
1557 cairo_restore (m_cairo
);
1561 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1565 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1568 wxPointList::compatibility_iterator node
= points
->GetFirst();
1569 p
= node
->GetData();
1573 node
= node
->GetNext();
1574 p
= node
->GetData();
1578 (double)(x1
+ c
) / 2;
1580 (double)(y1
+ d
) / 2;
1582 cairo_new_path( m_cairo
);
1583 cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1584 cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1586 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1587 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1589 node
= node
->GetNext();
1592 q
= node
->GetData();
1600 x3
= (double)(x2
+ c
) / 2;
1601 y3
= (double)(y2
+ d
) / 2;
1603 cairo_curve_to(m_cairo
,
1604 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1605 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1606 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1608 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1609 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1611 node
= node
->GetNext();
1614 cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1616 cairo_stroke( m_cairo
);
1618 #endif // wxUSE_SPLINES
1620 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1621 wxCoord width
, wxCoord height
,
1622 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1623 int rop
, bool useMask
,
1624 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1625 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1627 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1628 wxT("mask coordinates are not supported") );
1630 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1632 // Blit into a bitmap.
1633 wxBitmap
bitmap( width
, height
);
1635 memDC
.SelectObject(bitmap
);
1636 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1637 memDC
.SelectObject(wxNullBitmap
);
1639 // Draw bitmap. scaling and positioning is done there.
1640 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1645 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1647 DoDrawBitmap( icon
, x
, y
, true );
1650 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1652 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1654 x
= wxCoord(XLOG2DEV(x
));
1655 y
= wxCoord(YLOG2DEV(y
));
1656 int bw
= bitmap
.GetWidth();
1657 int bh
= bitmap
.GetHeight();
1658 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1659 if (!useMask
&& !bitmap
.HasPixbuf() && bitmap
.GetMask())
1660 bmpSource
.SetMask(NULL
);
1662 cairo_save(m_cairo
);
1664 // Prepare to draw the image.
1665 cairo_translate(m_cairo
, x
, y
);
1668 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1669 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1670 cairo_scale(m_cairo
, scaleX
, scaleY
);
1672 gdk_cairo_set_source_pixbuf(m_cairo
, bmpSource
.GetPixbuf(), 0, 0);
1673 cairo_pattern_set_filter(cairo_get_source(m_cairo
), CAIRO_FILTER_NEAREST
);
1674 // Use the original size here since the context is scaled already.
1675 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1676 // Fill the rectangle using the pattern.
1677 cairo_fill(m_cairo
);
1679 CalcBoundingBox(0,0);
1680 CalcBoundingBox(bw
,bh
);
1682 cairo_restore(m_cairo
);
1685 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1687 DoDrawRotatedText( text
, x
, y
, 0.0 );
1690 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1692 double xx
= XLOG2DEV(x
);
1693 double yy
= YLOG2DEV(y
);
1697 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1699 const wxUTF8Buf data
= text
.utf8_str();
1701 size_t datalen
= strlen(data
);
1702 pango_layout_set_text( m_layout
, data
, datalen
);
1706 PangoAttrList
*attrs
= pango_attr_list_new();
1707 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1709 a
->end_index
= datalen
;
1710 pango_attr_list_insert(attrs
, a
);
1711 pango_layout_set_attributes(m_layout
, attrs
);
1712 pango_attr_list_unref(attrs
);
1715 if (m_textForegroundColour
.Ok())
1717 unsigned char red
= m_textForegroundColour
.Red();
1718 unsigned char blue
= m_textForegroundColour
.Blue();
1719 unsigned char green
= m_textForegroundColour
.Green();
1720 unsigned char alpha
= m_textForegroundColour
.Alpha();
1722 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1724 double redPS
= (double)(red
) / 255.0;
1725 double bluePS
= (double)(blue
) / 255.0;
1726 double greenPS
= (double)(green
) / 255.0;
1727 double alphaPS
= (double)(alpha
) / 255.0;
1729 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1732 m_currentBlue
= blue
;
1733 m_currentGreen
= green
;
1734 m_currentAlpha
= alpha
;
1739 cairo_move_to (m_cairo
, xx
, yy
);
1741 cairo_save( m_cairo
);
1743 if (fabs(angle
) > 0.00001)
1744 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1746 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1749 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1751 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1753 unsigned char red
= m_textBackgroundColour
.Red();
1754 unsigned char blue
= m_textBackgroundColour
.Blue();
1755 unsigned char green
= m_textBackgroundColour
.Green();
1756 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1758 double redPS
= (double)(red
) / 255.0;
1759 double bluePS
= (double)(blue
) / 255.0;
1760 double greenPS
= (double)(green
) / 255.0;
1761 double alphaPS
= (double)(alpha
) / 255.0;
1763 cairo_save(m_cairo
);
1764 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1765 cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1766 cairo_fill(m_cairo
);
1767 cairo_restore(m_cairo
);
1770 pango_cairo_update_layout (m_cairo
, m_layout
);
1771 pango_cairo_show_layout (m_cairo
, m_layout
);
1773 cairo_restore( m_cairo
);
1777 // Undo underline attributes setting
1778 pango_layout_set_attributes(m_layout
, NULL
);
1781 // Back to device units:
1782 CalcBoundingBox (x
, y
);
1783 CalcBoundingBox (x
+ w
, y
+ h
);
1786 void wxGtkPrinterDCImpl::Clear()
1788 // Clear does nothing for printing, but keep the code
1791 cairo_save(m_cairo);
1792 cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1793 SetBrush(m_backgroundBrush);
1794 cairo_paint(m_cairo);
1795 cairo_restore(m_cairo);
1799 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1806 pango_font_description_free( m_fontdesc
);
1808 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1810 float size
= pango_font_description_get_size( m_fontdesc
);
1811 size
= size
* GetFontPointSizeAdjustment(72.0);
1812 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1814 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1818 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1820 if (!pen
.Ok()) return;
1826 if (m_pen
.GetWidth() <= 0)
1829 width
= (double) m_pen
.GetWidth();
1831 cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1832 static const double dotted
[] = {2.0, 5.0};
1833 static const double short_dashed
[] = {4.0, 4.0};
1834 static const double long_dashed
[] = {4.0, 8.0};
1835 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1837 switch (m_pen
.GetStyle())
1839 case wxPENSTYLE_DOT
: cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1840 case wxPENSTYLE_SHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1841 case wxPENSTYLE_LONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1842 case wxPENSTYLE_DOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1843 case wxPENSTYLE_USER_DASH
:
1846 int num
= m_pen
.GetDashes (&wx_dashes
);
1847 gdouble
*g_dashes
= g_new( gdouble
, num
);
1849 for (i
= 0; i
< num
; ++i
)
1850 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1851 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1855 case wxPENSTYLE_SOLID
:
1856 case wxPENSTYLE_TRANSPARENT
:
1857 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1860 switch (m_pen
.GetCap())
1862 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1863 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1865 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1868 switch (m_pen
.GetJoin())
1870 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1871 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1873 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1876 unsigned char red
= m_pen
.GetColour().Red();
1877 unsigned char blue
= m_pen
.GetColour().Blue();
1878 unsigned char green
= m_pen
.GetColour().Green();
1879 unsigned char alpha
= m_pen
.GetColour().Alpha();
1881 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1883 double redPS
= (double)(red
) / 255.0;
1884 double bluePS
= (double)(blue
) / 255.0;
1885 double greenPS
= (double)(green
) / 255.0;
1886 double alphaPS
= (double)(alpha
) / 255.0;
1888 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1891 m_currentBlue
= blue
;
1892 m_currentGreen
= green
;
1893 m_currentAlpha
= alpha
;
1897 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1899 if (!brush
.Ok()) return;
1903 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1905 cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1914 unsigned char red
= m_brush
.GetColour().Red();
1915 unsigned char blue
= m_brush
.GetColour().Blue();
1916 unsigned char green
= m_brush
.GetColour().Green();
1917 unsigned char alpha
= m_brush
.GetColour().Alpha();
1919 double redPS
= (double)(red
) / 255.0;
1920 double bluePS
= (double)(blue
) / 255.0;
1921 double greenPS
= (double)(green
) / 255.0;
1922 double alphaPS
= (double)(alpha
) / 255.0;
1924 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1926 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1929 m_currentBlue
= blue
;
1930 m_currentGreen
= green
;
1931 m_currentAlpha
= alpha
;
1934 if (m_brush
.IsHatch())
1937 cairo_surface_t
*surface
;
1938 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
1939 cr
= cairo_create(surface
);
1940 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
1941 cairo_set_line_width(cr
, 1);
1942 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
1944 switch (m_brush
.GetStyle())
1946 case wxBRUSHSTYLE_CROSS_HATCH
:
1947 cairo_move_to(cr
, 5, 0);
1948 cairo_line_to(cr
, 5, 10);
1949 cairo_move_to(cr
, 0, 5);
1950 cairo_line_to(cr
, 10, 5);
1952 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
1953 cairo_move_to(cr
, 0, 10);
1954 cairo_line_to(cr
, 10, 0);
1956 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
1957 cairo_move_to(cr
, 0, 0);
1958 cairo_line_to(cr
, 10, 10);
1960 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
1961 cairo_move_to(cr
, 0, 0);
1962 cairo_line_to(cr
, 10, 10);
1963 cairo_move_to(cr
, 10, 0);
1964 cairo_line_to(cr
, 0, 10);
1966 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
1967 cairo_move_to(cr
, 0, 5);
1968 cairo_line_to(cr
, 10, 5);
1970 case wxBRUSHSTYLE_VERTICAL_HATCH
:
1971 cairo_move_to(cr
, 5, 0);
1972 cairo_line_to(cr
, 5, 10);
1975 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
1978 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
1982 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
1983 cairo_surface_destroy(surface
);
1984 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
1985 cairo_set_source(m_cairo
, pattern
);
1986 cairo_pattern_destroy(pattern
);
1990 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
1992 if (function
== wxCLEAR
)
1993 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
1994 else if (function
== wxOR
)
1995 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
1996 else if (function
== wxNO_OP
)
1997 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
1998 else if (function
== wxAND
)
1999 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2000 else if (function
== wxSET
)
2001 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2002 else if (function
== wxXOR
)
2003 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2004 else // wxCOPY or anything else.
2005 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2008 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2010 m_backgroundBrush
= brush
;
2011 cairo_save(m_cairo
);
2012 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2014 SetBrush(m_backgroundBrush
);
2015 cairo_paint(m_cairo
);
2016 cairo_restore(m_cairo
);
2019 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2021 if (mode
== wxBRUSHSTYLE_SOLID
)
2022 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2024 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2027 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2029 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2030 cairo_clip(m_cairo
);
2033 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2035 cairo_reset_clip(m_cairo
);
2038 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2043 void wxGtkPrinterDCImpl::EndDoc()
2048 void wxGtkPrinterDCImpl::StartPage()
2053 void wxGtkPrinterDCImpl::EndPage()
2058 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2060 pango_layout_set_text( m_layout
, "H", 1 );
2063 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2065 return wxRound( h
* m_PS2DEV
);
2068 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2070 pango_layout_set_text( m_layout
, "H", 1 );
2073 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2075 return wxRound( w
* m_PS2DEV
);
2078 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2080 wxCoord
*externalLeading
,
2081 const wxFont
*theFont
) const
2089 if ( externalLeading
)
2090 *externalLeading
= 0;
2097 cairo_save( m_cairo
);
2098 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
2100 // Set layout's text
2101 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2106 // scale the font and apply it
2107 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2108 float size
= pango_font_description_get_size(desc
);
2109 size
= size
* GetFontPointSizeAdjustment(72.0);
2110 pango_font_description_set_size(desc
, (gint
)size
);
2112 pango_layout_set_font_description(m_layout
, desc
);
2115 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2118 pango_layout_get_pixel_size( m_layout
, width
, &h
);
2124 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2125 int baseline
= pango_layout_iter_get_baseline(iter
);
2126 pango_layout_iter_free(iter
);
2127 *descent
= h
- PANGO_PIXELS(baseline
);
2132 // restore font and reset font's size back
2133 pango_layout_set_font_description(m_layout
, m_fontdesc
);
2135 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2136 pango_font_description_set_size(desc
, oldSize
);
2139 cairo_restore( m_cairo
);
2142 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2144 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2147 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2149 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2152 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2154 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2157 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2159 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2162 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2164 return wxSize( (int)m_resolution
, (int)m_resolution
);
2167 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2172 // overriden for wxPrinterDC Impl
2174 wxRect
wxGtkPrinterDCImpl::GetPaperRect() const
2176 // Does GtkPrint support printer margins?
2179 DoGetSize( &w
, &h
);
2180 return wxRect( 0,0,w
,h
);
2183 int wxGtkPrinterDCImpl::GetResolution() const
2185 return m_resolution
;
2188 // ----------------------------------------------------------------------------
2190 // ----------------------------------------------------------------------------
2192 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2194 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2195 wxPrintout
* WXUNUSED(printoutForPrinting
),
2198 // convert wxPrintQuality to resolution (input pointer can be NULL)
2199 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2202 case wxPRINT_QUALITY_HIGH
:
2203 m_resolution
= 1200;
2206 case wxPRINT_QUALITY_LOW
:
2210 case wxPRINT_QUALITY_DRAFT
:
2217 // positive values directly indicate print resolution
2218 m_resolution
= quality
;
2222 wxFAIL_MSG( "unknown print quality" );
2225 case wxPRINT_QUALITY_MEDIUM
:
2234 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2235 wxPrintout
*printoutForPrinting
,
2236 wxPrintDialogData
*data
)
2237 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2239 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2242 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2243 wxPrintout
*printoutForPrinting
,
2245 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2247 Init(printout
, printoutForPrinting
, data
);
2250 wxGtkPrintPreview::~wxGtkPrintPreview()
2254 bool wxGtkPrintPreview::Print(bool interactive
)
2256 if (!m_printPrintout
)
2259 wxPrinter
printer(& m_printDialogData
);
2260 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2263 void wxGtkPrintPreview::DetermineScaling()
2265 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2267 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2269 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2273 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2274 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2276 // Get width and height in points (1/72th of an inch)
2277 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2278 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2279 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2281 wxSize
sizeTenthsMM(paper
->GetSize());
2282 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2284 // If in landscape mode, we need to swap the width and height.
2285 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2287 m_pageWidth
= sizeDevUnits
.y
;
2288 m_pageHeight
= sizeDevUnits
.x
;
2289 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2293 m_pageWidth
= sizeDevUnits
.x
;
2294 m_pageHeight
= sizeDevUnits
.y
;
2295 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2297 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2298 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2300 // At 100%, the page should look about page-size on the screen.
2301 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2302 m_previewScaleY
= m_previewScaleX
;