1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
25 #include "wx/dcprint.h"
29 #include "wx/module.h"
33 #include "wx/fontutil.h"
34 #include "wx/gtk/private.h"
35 #include "wx/dynlib.h"
40 #if wxUSE_GRAPHICS_CONTEXT
41 #include "wx/graphics.h"
45 wxFORCE_LINK_THIS_MODULE(gtk_print
)
47 #if wxUSE_LIBGNOMEPRINT
48 #include "wx/gtk/gnome/gprint.h"
51 // Usefull to convert angles from/to Rad to/from Deg.
52 static const double RAD2DEG
= 180.0 / M_PI
;
53 static const double DEG2RAD
= M_PI
/ 180.0;
55 //----------------------------------------------------------------------------
57 // Initialized when starting the app : if it successfully load the gtk-print framework,
58 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
59 // to postscript if gnomeprint is not available.
60 //----------------------------------------------------------------------------
62 class wxGtkPrintModule
: public wxModule
67 #if wxUSE_LIBGNOMEPRINT
68 // This module must be initialized AFTER gnomeprint's one
69 AddDependency(CLASSINFO(wxGnomePrintModule
));
76 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
79 bool wxGtkPrintModule
::OnInit()
81 if (gtk_check_version(2,10,0) == NULL
)
82 wxPrintFactory
::SetPrintFactory( new wxGtkPrintFactory
);
86 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
88 //----------------------------------------------------------------------------
90 //----------------------------------------------------------------------------
92 wxPrinterBase
* wxGtkPrintFactory
::CreatePrinter( wxPrintDialogData
*data
)
94 return new wxGtkPrinter( data
);
97 wxPrintPreviewBase
*wxGtkPrintFactory
::CreatePrintPreview( wxPrintout
*preview
,
99 wxPrintDialogData
*data
)
101 return new wxGtkPrintPreview( preview
, printout
, data
);
104 wxPrintPreviewBase
*wxGtkPrintFactory
::CreatePrintPreview( wxPrintout
*preview
,
105 wxPrintout
*printout
,
108 return new wxGtkPrintPreview( preview
, printout
, data
);
111 wxPrintDialogBase
*wxGtkPrintFactory
::CreatePrintDialog( wxWindow
*parent
,
112 wxPrintDialogData
*data
)
114 return new wxGtkPrintDialog( parent
, data
);
117 wxPrintDialogBase
*wxGtkPrintFactory
::CreatePrintDialog( wxWindow
*parent
,
120 return new wxGtkPrintDialog( parent
, data
);
123 wxPageSetupDialogBase
*wxGtkPrintFactory
::CreatePageSetupDialog( wxWindow
*parent
,
124 wxPageSetupDialogData
* data
)
126 return new wxGtkPageSetupDialog( parent
, data
);
129 bool wxGtkPrintFactory
::HasPrintSetupDialog()
135 wxGtkPrintFactory
::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
136 wxPrintData
* WXUNUSED(data
))
141 wxDCImpl
* wxGtkPrintFactory
::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
143 return new wxGtkPrinterDCImpl( owner
, data
);
146 bool wxGtkPrintFactory
::HasOwnPrintToFile()
151 bool wxGtkPrintFactory
::HasPrinterLine()
156 wxString wxGtkPrintFactory
::CreatePrinterLine()
159 return wxEmptyString
;
162 bool wxGtkPrintFactory
::HasStatusLine()
168 wxString wxGtkPrintFactory
::CreateStatusLine()
171 return wxEmptyString
;
174 wxPrintNativeDataBase
*wxGtkPrintFactory
::CreatePrintNativeData()
176 return new wxGtkPrintNativeData
;
179 //----------------------------------------------------------------------------
180 // Callback functions for Gtk Printings.
181 //----------------------------------------------------------------------------
183 // We use it to pass useful objects to GTK printing callback functions.
184 struct wxPrinterToGtkData
186 wxGtkPrinter
* printer
;
187 wxPrintout
* printout
;
192 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
194 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
196 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
199 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
201 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
203 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
206 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
207 GtkPrintContext
* WXUNUSED(context
),
210 wxPrintout
*printout
= (wxPrintout
*) user_data
;
212 printout
->OnEndPrinting();
216 //----------------------------------------------------------------------------
217 // wxGtkPrintNativeData
218 //----------------------------------------------------------------------------
220 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
222 wxGtkPrintNativeData
::wxGtkPrintNativeData()
224 m_config
= gtk_print_settings_new();
225 m_job
= gtk_print_operation_new();
229 wxGtkPrintNativeData
::~wxGtkPrintNativeData()
231 g_object_unref(m_job
);
232 g_object_unref(m_config
);
235 // Convert datas stored in m_config to a wxPrintData.
236 // Called by wxPrintData::ConvertFromNative().
237 bool wxGtkPrintNativeData
::TransferTo( wxPrintData
&data
)
242 int resolution
= gtk_print_settings_get_resolution(m_config
);
243 if ( resolution
> 0 )
245 // if resolution is explicitly set, use it
246 data
.SetQuality(resolution
);
248 else // use more vague "quality"
250 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
251 if (quality
== GTK_PRINT_QUALITY_HIGH
)
252 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
253 else if (quality
== GTK_PRINT_QUALITY_LOW
)
254 data
.SetQuality(wxPRINT_QUALITY_LOW
);
255 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
256 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
258 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
261 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
263 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
265 switch (gtk_print_settings_get_duplex(m_config
))
267 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
270 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
274 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
278 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
279 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
281 data
.SetOrientation(wxPORTRAIT
);
282 data
.SetOrientationReversed(false);
284 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
286 data
.SetOrientation(wxLANDSCAPE
);
287 data
.SetOrientationReversed(false);
289 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
291 data
.SetOrientation(wxPORTRAIT
);
292 data
.SetOrientationReversed(true);
294 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
296 data
.SetOrientation(wxLANDSCAPE
);
297 data
.SetOrientationReversed(true);
300 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
302 // Paper formats : these are the most common paper formats.
303 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
305 data
.SetPaperId(wxPAPER_NONE
);
306 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
307 data
.SetPaperId(wxPAPER_A3
);
308 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
309 data
.SetPaperId(wxPAPER_A4
);
310 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
311 data
.SetPaperId(wxPAPER_A5
);
312 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
313 data
.SetPaperId(wxPAPER_B5
);
314 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
315 data
.SetPaperId(wxPAPER_LETTER
);
316 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
317 data
.SetPaperId(wxPAPER_LEGAL
);
318 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
319 data
.SetPaperId(wxPAPER_EXECUTIVE
);
320 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
321 data
.SetPaperId(wxPAPER_ENV_10
);
322 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
323 data
.SetPaperId(wxPAPER_ENV_C5
);
324 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
325 data
.SetPaperId(wxPAPER_ENV_C6
);
326 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
327 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
329 data
.SetPaperId(wxPAPER_ENV_B5
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
331 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
333 data
.SetPaperId( wxPAPER_CSHEET
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
335 data
.SetPaperId( wxPAPER_DSHEET
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
337 data
.SetPaperId( wxPAPER_ESHEET
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
339 data
.SetPaperId( wxPAPER_LETTERSMALL
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
341 data
.SetPaperId( wxPAPER_TABLOID
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
343 data
.SetPaperId( wxPAPER_LEDGER
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
345 data
.SetPaperId( wxPAPER_STATEMENT
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
347 data
.SetPaperId( wxPAPER_A4SMALL
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
349 data
.SetPaperId( wxPAPER_B4
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
351 data
.SetPaperId( wxPAPER_FOLIO
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
353 data
.SetPaperId( wxPAPER_QUARTO
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
355 data
.SetPaperId( wxPAPER_10X14
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
357 data
.SetPaperId( wxPAPER_11X17
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
359 data
.SetPaperId( wxPAPER_NOTE
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
361 data
.SetPaperId( wxPAPER_ENV_9
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
363 data
.SetPaperId( wxPAPER_ENV_11
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
365 data
.SetPaperId( wxPAPER_ENV_12
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
367 data
.SetPaperId( wxPAPER_ENV_14
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
369 data
.SetPaperId( wxPAPER_ENV_DL
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
371 data
.SetPaperId( wxPAPER_ENV_C3
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
373 data
.SetPaperId( wxPAPER_ENV_C4
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
375 data
.SetPaperId( wxPAPER_ENV_C65
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
377 data
.SetPaperId( wxPAPER_ENV_B4
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
379 data
.SetPaperId( wxPAPER_ENV_B6
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
381 data
.SetPaperId( wxPAPER_ENV_ITALY
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
383 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
385 data
.SetPaperId( wxPAPER_FANFOLD_US
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
387 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
389 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
391 data
.SetPaperId(wxPAPER_NONE
);
395 // Put datas given by the wxPrintData into m_config.
396 // Called by wxPrintData::ConvertToNative().
397 bool wxGtkPrintNativeData
::TransferFrom( const wxPrintData
&data
)
402 wxPrintQuality quality
= data
.GetQuality();
403 if (quality
== wxPRINT_QUALITY_HIGH
)
404 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
405 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
406 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
407 else if (quality
== wxPRINT_QUALITY_LOW
)
408 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
409 else if (quality
== wxPRINT_QUALITY_DRAFT
)
410 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
411 else if (quality
> 1)
412 gtk_print_settings_set_resolution (m_config
, quality
);
414 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
416 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
418 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
420 switch (data
.GetDuplex())
422 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
425 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
429 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
433 if (!data
.IsOrientationReversed())
435 if (data
.GetOrientation() == wxLANDSCAPE
)
436 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
438 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
441 if (data
.GetOrientation() == wxLANDSCAPE
)
442 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
444 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
447 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
449 // Paper formats: these are the most common paper formats.
450 switch (data
.GetPaperId())
452 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
454 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
456 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
458 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
460 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
462 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
464 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
466 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
468 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
470 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
472 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
474 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
476 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
478 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
480 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
482 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
484 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
486 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
488 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
490 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
492 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
494 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
496 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
498 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
500 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
502 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
504 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
506 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
508 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
510 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
512 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
514 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
516 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
518 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
520 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
522 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
524 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
526 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
528 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
530 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
532 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
534 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
543 void wxGtkPrintNativeData
::SetPrintConfig( GtkPrintSettings
* config
)
546 m_config
= gtk_print_settings_copy(config
);
549 // Extract page setup from settings.
550 GtkPageSetup
* wxGtkPrintNativeData
::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
552 GtkPageSetup
* page_setup
= gtk_page_setup_new();
553 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
555 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
556 if (paper_size
!= NULL
)
557 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
562 // Insert page setup into a given GtkPrintSettings.
563 void wxGtkPrintNativeData
::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
565 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
566 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
569 //----------------------------------------------------------------------------
571 //----------------------------------------------------------------------------
573 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
575 wxGtkPrintDialog
::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
576 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
577 wxPoint(0, 0), wxSize(600, 600),
578 wxDEFAULT_DIALOG_STYLE
|
582 m_printDialogData
= *data
;
588 wxGtkPrintDialog
::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
589 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
590 wxPoint(0, 0), wxSize(600, 600),
591 wxDEFAULT_DIALOG_STYLE
|
595 m_printDialogData
= *data
;
602 wxGtkPrintDialog
::~wxGtkPrintDialog()
606 // This is called even if we actually don't want the dialog to appear.
607 int wxGtkPrintDialog
::ShowModal()
609 GtkPrintOperationResult response
;
611 // We need to restore the settings given in the constructor.
612 wxPrintData data
= m_printDialogData
.GetPrintData();
613 wxGtkPrintNativeData
*native
=
614 (wxGtkPrintNativeData
*) data
.GetNativeData();
615 data
.ConvertToNative();
617 GtkPrintSettings
* settings
= native
->GetPrintConfig();
619 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
620 int fromPage
= m_printDialogData
.GetFromPage();
621 int toPage
= m_printDialogData
.GetToPage();
622 if (m_printDialogData
.GetSelection())
623 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
624 else if (m_printDialogData
.GetAllPages())
625 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
627 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
629 range
= g_new (GtkPageRange
, 1);
630 range
[0].start
= fromPage
-1;
631 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
632 gtk_print_settings_set_page_ranges (settings
, range
, 1);
635 GtkPrintOperation
* const printOp
= native
->GetPrintJob();
637 // If the settings are OK, we restore it.
638 if (settings
!= NULL
)
639 gtk_print_operation_set_print_settings (printOp
, settings
);
640 gtk_print_operation_set_default_page_setup (printOp
, native
->GetPageSetupFromSettings(settings
));
642 // Show the dialog if needed.
643 GError
* gError
= NULL
;
645 response
= gtk_print_operation_run (printOp
, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
647 response
= gtk_print_operation_run (printOp
, GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
649 // Does everything went well?
650 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
654 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
656 g_error_free (gError
);
657 wxLogError(_("Error while printing: ") + wxString
::Format(_("%s"), gError
->message
));
658 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
661 // Now get the settings and save it.
662 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings(printOp
);
663 native
->SetPrintConfig(newSettings
);
664 data
.ConvertFromNative();
666 // Same problem as a few lines before.
667 switch (gtk_print_settings_get_print_pages(newSettings
))
669 case GTK_PRINT_PAGES_CURRENT
:
670 m_printDialogData
.SetSelection( true );
672 case GTK_PRINT_PAGES_RANGES
:
673 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
674 // 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
675 // will hit "OK" button. However we can only save 1-3 in the print data.
678 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
681 m_printDialogData
.SetFromPage( range
[0].start
);
682 m_printDialogData
.SetToPage( range
[0].end
);
685 m_printDialogData
.SetAllPages( true );
686 m_printDialogData
.SetFromPage( 0 );
687 m_printDialogData
.SetToPage( 9999 );
690 case GTK_PRINT_PAGES_ALL
:
692 m_printDialogData
.SetAllPages( true );
693 m_printDialogData
.SetFromPage( 0 );
694 m_printDialogData
.SetToPage( 9999 );
701 //----------------------------------------------------------------------------
702 // wxGtkPageSetupDialog
703 //----------------------------------------------------------------------------
705 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
707 wxGtkPageSetupDialog
::wxGtkPageSetupDialog( wxWindow
*parent
,
708 wxPageSetupDialogData
* data
)
711 m_pageDialogData
= *data
;
716 wxGtkPageSetupDialog
::~wxGtkPageSetupDialog()
720 int wxGtkPageSetupDialog
::ShowModal()
723 m_pageDialogData
.GetPrintData().ConvertToNative();
724 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
725 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
727 // We only need the pagesetup data which are part of the settings.
728 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
730 // If the user used a custom paper format the last time he printed, we have to restore it too.
731 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
733 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
734 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
736 wxString title
= _("Custom size");
737 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
738 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
739 g_object_unref(customSize
);
743 // Now show the dialog.
744 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
749 if (newPageSetup
!= oldPageSetup
)
751 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
752 m_pageDialogData
.GetPrintData().ConvertFromNative();
754 // Store custom paper format if any.
755 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
757 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
758 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
759 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
760 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
761 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
763 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
764 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
766 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
767 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
769 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
782 //----------------------------------------------------------------------------
784 //----------------------------------------------------------------------------
786 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
788 wxGtkPrinter
::wxGtkPrinter( wxPrintDialogData
*data
) :
789 wxPrinterBase( data
)
794 m_printDialogData
= *data
;
797 wxGtkPrinter
::~wxGtkPrinter()
801 bool wxGtkPrinter
::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
805 sm_lastError
= wxPRINTER_ERROR
;
809 // Let's correct the PageInfo just in case the app gives wrong values.
810 int fromPage
, toPage
;
811 int minPage
, maxPage
;
812 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
813 m_printDialogData
.SetAllPages(true);
815 if (minPage
< 1) minPage
= 1;
816 if (maxPage
< 1) maxPage
= 9999;
817 if (maxPage
< minPage
) maxPage
= minPage
;
819 m_printDialogData
.SetMinPage(minPage
);
820 m_printDialogData
.SetMaxPage(maxPage
);
823 if (fromPage
< minPage
) fromPage
= minPage
;
824 else if (fromPage
> maxPage
) fromPage
= maxPage
;
825 m_printDialogData
.SetFromPage(fromPage
);
829 m_printDialogData
.SetToPage(toPage
);
830 if (toPage
> maxPage
) toPage
= maxPage
;
831 else if (toPage
< minPage
) toPage
= minPage
;
834 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
837 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
838 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
840 GtkPrintOperation
* const printOp
= native
->GetPrintJob();
842 wxPrinterToGtkData dataToSend
;
843 dataToSend
.printer
= this;
844 dataToSend
.printout
= printout
;
846 // These Gtk signals are caught here.
847 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
848 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
849 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
851 // This is used to setup the DC and
852 // show the dialog if desired
853 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
854 dialog
.SetPrintDC(m_dc
);
855 dialog
.SetShowDialog(prompt
);
857 // doesn't necessarily show
858 int ret
= dialog
.ShowModal();
859 if (ret
== wxID_CANCEL
)
861 sm_lastError
= wxPRINTER_CANCELLED
;
865 sm_lastError
= wxPRINTER_ERROR
;
866 wxFAIL_MSG(_("The print dialog returned an error."));
869 return (sm_lastError
== wxPRINTER_NO_ERROR
);
872 void wxGtkPrinter
::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
874 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
875 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
877 // We need to update printdata with the new data from the dialog and we
878 // have to do this here because this method needs this new data and we
879 // cannot update it earlier
880 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
881 printdata
.ConvertFromNative();
883 SetPrintContext(context
);
884 native
->SetPrintContext( context
);
886 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
891 if (sm_lastError
!= wxPRINTER_CANCELLED
)
893 sm_lastError
= wxPRINTER_ERROR
;
894 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
899 printout
->SetPPIScreen(wxGetDisplayPPI());
900 printout
->SetPPIPrinter( printDC
->GetResolution(),
901 printDC
->GetResolution() );
903 printout
->SetDC(m_dc
);
906 m_dc
->GetSize(&w
, &h
);
907 printout
->SetPageSizePixels((int)w
, (int)h
);
908 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
910 m_dc
->GetSizeMM(&mw
, &mh
);
911 printout
->SetPageSizeMM((int)mw
, (int)mh
);
912 printout
->OnPreparePrinting();
914 // Get some parameters from the printout, if defined.
915 int fromPage
, toPage
;
916 int minPage
, maxPage
;
917 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
921 sm_lastError
= wxPRINTER_ERROR
;
922 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
926 printout
->OnBeginPrinting();
930 // If we're not previewing we need to calculate the number of pages to print.
931 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
932 // have defined in the dialog. So the number of pages is the maximum available.
933 if (!printout
->IsPreview())
935 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
936 switch (gtk_print_settings_get_print_pages(settings
))
938 case GTK_PRINT_PAGES_CURRENT
:
941 case GTK_PRINT_PAGES_RANGES
:
942 {gint num_ranges
= 0;
945 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
946 for (i
=0; i
<num_ranges
; i
++)
948 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
949 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
950 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
951 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
952 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
954 gtk_print_settings_set_page_ranges (settings
, range
, 1);
956 case GTK_PRINT_PAGES_ALL
:
958 numPages
= maxPage
- minPage
+ 1;
962 else numPages
= maxPage
- minPage
+ 1;
964 gtk_print_operation_set_n_pages(operation
, numPages
);
967 void wxGtkPrinter
::DrawPage(wxPrintout
*printout
,
968 GtkPrintOperation
*operation
,
969 GtkPrintContext
* WXUNUSED(context
),
972 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
973 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
975 int numPageToDraw
= page_nr
+ minPage
;
976 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
977 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
979 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
980 switch (gtk_print_settings_get_print_pages(settings
))
982 case GTK_PRINT_PAGES_CURRENT
:
983 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
984 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
986 case GTK_PRINT_PAGES_RANGES
:
987 {gint num_ranges
= 0;
989 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
990 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
993 startPage
= range
[0].start
+ 1;
994 endPage
= range
[0].end
+ 1;
1001 case GTK_PRINT_PAGES_ALL
:
1003 startPage
= minPage
;
1008 if(numPageToDraw
== startPage
)
1010 if (!printout
->OnBeginDocument(startPage
, endPage
))
1012 wxLogError(_("Could not start printing."));
1013 sm_lastError
= wxPRINTER_ERROR
;
1017 // The app can render the page numPageToDraw.
1018 if (printout
->HasPage(numPageToDraw
))
1021 printout
->OnPrintPage(numPageToDraw
);
1026 if(numPageToDraw
== endPage
)
1028 printout
->OnEndDocument();
1032 wxDC
* wxGtkPrinter
::PrintDialog( wxWindow
*parent
)
1034 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1036 dialog
.SetPrintDC(m_dc
);
1037 dialog
.SetShowDialog(true);
1039 int ret
= dialog
.ShowModal();
1041 if (ret
== wxID_CANCEL
)
1043 sm_lastError
= wxPRINTER_CANCELLED
;
1048 sm_lastError
= wxPRINTER_ERROR
;
1049 wxFAIL_MSG(_("The print dialog returned an error."));
1053 m_printDialogData
= dialog
.GetPrintDialogData();
1055 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1058 bool wxGtkPrinter
::Setup( wxWindow
* WXUNUSED(parent
) )
1060 // Obsolete, for backward compatibility.
1064 //-----------------------------------------------------------------------------
1066 //-----------------------------------------------------------------------------
1068 #define wxCAIRO_SCALE 1
1072 #define XLOG2DEV(x) LogicalToDeviceX(x)
1073 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1074 #define YLOG2DEV(x) LogicalToDeviceY(x)
1075 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1079 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1080 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1081 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1082 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1086 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1088 wxGtkPrinterDCImpl
::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1093 wxGtkPrintNativeData
*native
=
1094 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1096 m_gpc
= native
->GetPrintContext();
1098 // Match print quality to resolution (high = 1200dpi)
1099 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1100 if (m_resolution
< 0)
1101 m_resolution
= (1 << (m_resolution
+4)) *150;
1103 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1104 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1105 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1107 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1113 cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1115 m_PS2DEV
= (double)m_resolution
/ 72.0;
1116 m_DEV2PS
= 72.0 / (double)m_resolution
;
1123 m_signX
= 1; // default x-axis left to right.
1124 m_signY
= 1; // default y-axis bottom up -> top down.
1126 // By default the origin of the Cairo context is in the upper left
1127 // corner of the printable area. We need to translate it so that it
1128 // is in the upper left corner of the paper (without margins)
1129 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1131 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1132 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1133 cairo_translate(m_cairo
, -ml
, -mt
);
1136 wxGtkPrinterDCImpl
::~wxGtkPrinterDCImpl()
1138 g_object_unref(m_context
);
1139 g_object_unref(m_layout
);
1142 bool wxGtkPrinterDCImpl
::IsOk() const
1144 return m_gpc
!= NULL
;
1147 void* wxGtkPrinterDCImpl
::GetCairoContext() const
1149 return (void*) cairo_reference( m_cairo
);
1152 bool wxGtkPrinterDCImpl
::DoFloodFill(wxCoord
WXUNUSED(x1
),
1153 wxCoord
WXUNUSED(y1
),
1154 const wxColour
& WXUNUSED(col
),
1155 wxFloodFillStyle
WXUNUSED(style
))
1157 // We can't access the given coord as a Cairo context is scalable, ie a
1158 // coord doesn't mean anything in this context.
1159 wxFAIL_MSG(_("not implemented"));
1163 void wxGtkPrinterDCImpl
::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1165 wxCoord xC
= circleCenter
.x
;
1166 wxCoord yC
= circleCenter
.y
;
1167 wxCoord xR
= rect
.x
;
1168 wxCoord yR
= rect
.y
;
1169 wxCoord w
= rect
.width
;
1170 wxCoord h
= rect
.height
;
1172 const double r2
= (w
/2)*(w
/2)+(h
/2)*(h
/2);
1173 double radius
= sqrt(r2
);
1175 unsigned char redI
= initialColour
.Red();
1176 unsigned char blueI
= initialColour
.Blue();
1177 unsigned char greenI
= initialColour
.Green();
1178 unsigned char alphaI
= initialColour
.Alpha();
1179 unsigned char redD
= destColour
.Red();
1180 unsigned char blueD
= destColour
.Blue();
1181 unsigned char greenD
= destColour
.Green();
1182 unsigned char alphaD
= destColour
.Alpha();
1184 double redIPS
= (double)(redI
) / 255.0;
1185 double blueIPS
= (double)(blueI
) / 255.0;
1186 double greenIPS
= (double)(greenI
) / 255.0;
1187 double alphaIPS
= (double)(alphaI
) / 255.0;
1188 double redDPS
= (double)(redD
) / 255.0;
1189 double blueDPS
= (double)(blueD
) / 255.0;
1190 double greenDPS
= (double)(greenD
) / 255.0;
1191 double alphaDPS
= (double)(alphaD
) / 255.0;
1193 // Create a pattern with the gradient.
1194 cairo_pattern_t
* gradient
;
1195 gradient
= cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1196 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1197 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1199 // Fill the rectangle with this pattern.
1200 cairo_set_source(m_cairo
, gradient
);
1201 cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1202 cairo_fill(m_cairo
);
1204 cairo_pattern_destroy(gradient
);
1206 CalcBoundingBox(xR
, yR
);
1207 CalcBoundingBox(xR
+w
, yR
+h
);
1210 void wxGtkPrinterDCImpl
::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1214 wxCoord w
= rect
.width
;
1215 wxCoord h
= rect
.height
;
1217 unsigned char redI
= initialColour
.Red();
1218 unsigned char blueI
= initialColour
.Blue();
1219 unsigned char greenI
= initialColour
.Green();
1220 unsigned char alphaI
= initialColour
.Alpha();
1221 unsigned char redD
= destColour
.Red();
1222 unsigned char blueD
= destColour
.Blue();
1223 unsigned char greenD
= destColour
.Green();
1224 unsigned char alphaD
= destColour
.Alpha();
1226 double redIPS
= (double)(redI
) / 255.0;
1227 double blueIPS
= (double)(blueI
) / 255.0;
1228 double greenIPS
= (double)(greenI
) / 255.0;
1229 double alphaIPS
= (double)(alphaI
) / 255.0;
1230 double redDPS
= (double)(redD
) / 255.0;
1231 double blueDPS
= (double)(blueD
) / 255.0;
1232 double greenDPS
= (double)(greenD
) / 255.0;
1233 double alphaDPS
= (double)(alphaD
) / 255.0;
1235 // Create a pattern with the gradient.
1236 cairo_pattern_t
* gradient
;
1237 gradient
= cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1239 if (nDirection
== wxWEST
)
1241 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1242 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1245 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1246 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1249 // Fill the rectangle with this pattern.
1250 cairo_set_source(m_cairo
, gradient
);
1251 cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1252 cairo_fill(m_cairo
);
1254 cairo_pattern_destroy(gradient
);
1256 CalcBoundingBox(x
, y
);
1257 CalcBoundingBox(x
+w
, y
+h
);
1260 bool wxGtkPrinterDCImpl
::DoGetPixel(wxCoord
WXUNUSED(x1
),
1261 wxCoord
WXUNUSED(y1
),
1262 wxColour
* WXUNUSED(col
)) const
1264 wxFAIL_MSG(_("not implemented"));
1268 void wxGtkPrinterDCImpl
::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1270 if ( m_pen
.IsTransparent() )
1274 cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1275 cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1276 cairo_stroke ( m_cairo
);
1278 CalcBoundingBox( x1
, y1
);
1279 CalcBoundingBox( x2
, y2
);
1282 void wxGtkPrinterDCImpl
::DoCrossHair(wxCoord x
, wxCoord y
)
1289 cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1290 cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1291 cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1292 cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1294 cairo_stroke (m_cairo
);
1295 CalcBoundingBox( 0, 0 );
1296 CalcBoundingBox( w
, h
);
1299 void wxGtkPrinterDCImpl
::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1301 double dx
= x1
- xc
;
1302 double dy
= y1
- yc
;
1303 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1305 double alpha1
, alpha2
;
1306 if (x1
== x2
&& y1
== y2
)
1314 alpha1
= alpha2
= 0.0;
1318 alpha1
= (x1
- xc
== 0) ?
1319 (y1
- yc
< 0) ?
90.0 : -90.0 :
1320 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1321 alpha2
= (x2
- xc
== 0) ?
1322 (y2
- yc
< 0) ?
90.0 : -90.0 :
1323 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1325 while (alpha1
<= 0) alpha1
+= 360;
1326 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1327 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1328 while (alpha2
> 360) alpha2
-= 360;
1334 cairo_new_path(m_cairo
);
1336 cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1337 cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1338 cairo_close_path (m_cairo
);
1340 SetBrush( m_brush
);
1341 cairo_fill_preserve( m_cairo
);
1344 cairo_stroke( m_cairo
);
1346 CalcBoundingBox (x1
, y1
);
1347 CalcBoundingBox (xc
, yc
);
1348 CalcBoundingBox (x2
, y2
);
1351 void wxGtkPrinterDCImpl
::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1353 cairo_save( m_cairo
);
1355 cairo_new_path(m_cairo
);
1357 cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1358 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1359 cairo_scale( m_cairo
, 1.0, scale
);
1361 cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1364 cairo_stroke_preserve( m_cairo
);
1366 cairo_line_to(m_cairo
, 0,0);
1368 SetBrush( m_brush
);
1369 cairo_fill( m_cairo
);
1371 cairo_restore( m_cairo
);
1373 CalcBoundingBox( x
, y
);
1374 CalcBoundingBox( x
+w
, y
+h
);
1377 void wxGtkPrinterDCImpl
::DoDrawPoint(wxCoord x
, wxCoord y
)
1379 if ( m_pen
.IsTransparent() )
1384 cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1385 cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1386 cairo_stroke ( m_cairo
);
1388 CalcBoundingBox( x
, y
);
1391 void wxGtkPrinterDCImpl
::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1393 if ( m_pen
.IsTransparent() )
1402 for ( i
=0; i
<n
; i
++ )
1403 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1405 cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1407 for (i
= 1; i
< n
; i
++)
1408 cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1410 cairo_stroke ( m_cairo
);
1413 void wxGtkPrinterDCImpl
::DoDrawPolygon(int n
, wxPoint points
[],
1414 wxCoord xoffset
, wxCoord yoffset
,
1415 wxPolygonFillMode fillStyle
)
1419 cairo_save(m_cairo
);
1420 if (fillStyle
== wxWINDING_RULE
)
1421 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1423 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1425 int x
= points
[0].x
+ xoffset
;
1426 int y
= points
[0].y
+ yoffset
;
1427 cairo_new_path(m_cairo
);
1428 cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1430 for (i
= 1; i
< n
; i
++)
1432 int x
= points
[i
].x
+ xoffset
;
1433 int y
= points
[i
].y
+ yoffset
;
1434 cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1436 cairo_close_path(m_cairo
);
1438 SetBrush( m_brush
);
1439 cairo_fill_preserve( m_cairo
);
1442 cairo_stroke( m_cairo
);
1444 CalcBoundingBox( x
, y
);
1446 cairo_restore(m_cairo
);
1449 void wxGtkPrinterDCImpl
::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
1450 wxCoord xoffset
, wxCoord yoffset
,
1451 wxPolygonFillMode fillStyle
)
1453 wxDCImpl
::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1456 void wxGtkPrinterDCImpl
::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1461 cairo_new_path(m_cairo
);
1462 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1464 SetBrush( m_brush
);
1465 cairo_fill_preserve( m_cairo
);
1468 cairo_stroke( m_cairo
);
1470 CalcBoundingBox( x
, y
);
1471 CalcBoundingBox( x
+ width
, y
+ height
);
1474 void wxGtkPrinterDCImpl
::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1479 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1481 wxCoord dd
= 2 * (wxCoord
) radius
;
1482 if (dd
> width
) dd
= width
;
1483 if (dd
> height
) dd
= height
;
1486 wxCoord rad
= (wxCoord
) radius
;
1488 cairo_new_path(m_cairo
);
1489 cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1490 cairo_curve_to(m_cairo
,
1491 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1492 XLOG2DEV(x
),YLOG2DEV(y
),
1493 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1494 cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1495 cairo_curve_to(m_cairo
,
1496 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1497 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1498 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1499 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1500 cairo_curve_to(m_cairo
,
1501 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1502 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1503 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1504 cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1505 cairo_curve_to(m_cairo
,
1506 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1507 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1508 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1509 cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1510 cairo_close_path(m_cairo
);
1513 cairo_fill_preserve(m_cairo
);
1516 cairo_stroke(m_cairo
);
1518 CalcBoundingBox(x
,y
);
1519 CalcBoundingBox(x
+width
,y
+height
);
1522 void wxGtkPrinterDCImpl
::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1527 cairo_save (m_cairo
);
1529 cairo_new_path(m_cairo
);
1531 cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1532 cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1533 cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1535 SetBrush( m_brush
);
1536 cairo_fill_preserve( m_cairo
);
1539 cairo_stroke( m_cairo
);
1541 CalcBoundingBox( x
, y
);
1542 CalcBoundingBox( x
+ width
, y
+ height
);
1544 cairo_restore (m_cairo
);
1548 void wxGtkPrinterDCImpl
::DoDrawSpline(const wxPointList
*points
)
1552 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1555 wxPointList
::compatibility_iterator node
= points
->GetFirst();
1556 p
= node
->GetData();
1560 node
= node
->GetNext();
1561 p
= node
->GetData();
1565 (double)(x1
+ c
) / 2;
1567 (double)(y1
+ d
) / 2;
1569 cairo_new_path( m_cairo
);
1570 cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1571 cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1573 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1574 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1576 node
= node
->GetNext();
1579 q
= node
->GetData();
1587 x3
= (double)(x2
+ c
) / 2;
1588 y3
= (double)(y2
+ d
) / 2;
1590 cairo_curve_to(m_cairo
,
1591 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1592 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1593 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1595 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1596 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1598 node
= node
->GetNext();
1601 cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1603 cairo_stroke( m_cairo
);
1605 #endif // wxUSE_SPLINES
1607 bool wxGtkPrinterDCImpl
::DoBlit(wxCoord xdest
, wxCoord ydest
,
1608 wxCoord width
, wxCoord height
,
1609 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1610 wxRasterOperationMode rop
, bool useMask
,
1611 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1612 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1614 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1615 wxT("mask coordinates are not supported") );
1617 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1619 // Blit into a bitmap.
1620 wxBitmap
bitmap( width
, height
);
1622 memDC
.SelectObject(bitmap
);
1623 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1624 memDC
.SelectObject(wxNullBitmap
);
1626 // Draw bitmap. scaling and positioning is done there.
1627 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1632 void wxGtkPrinterDCImpl
::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1634 DoDrawBitmap( icon
, x
, y
, true );
1637 void wxGtkPrinterDCImpl
::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1639 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1641 x
= wxCoord(XLOG2DEV(x
));
1642 y
= wxCoord(YLOG2DEV(y
));
1643 int bw
= bitmap
.GetWidth();
1644 int bh
= bitmap
.GetHeight();
1645 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1646 if (!useMask
&& !bitmap
.HasPixbuf() && bitmap
.GetMask())
1647 bmpSource
.SetMask(NULL
);
1649 cairo_save(m_cairo
);
1651 // Prepare to draw the image.
1652 cairo_translate(m_cairo
, x
, y
);
1655 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1656 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1657 cairo_scale(m_cairo
, scaleX
, scaleY
);
1659 gdk_cairo_set_source_pixbuf(m_cairo
, bmpSource
.GetPixbuf(), 0, 0);
1660 cairo_pattern_set_filter(cairo_get_source(m_cairo
), CAIRO_FILTER_NEAREST
);
1661 // Use the original size here since the context is scaled already.
1662 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1663 // Fill the rectangle using the pattern.
1664 cairo_fill(m_cairo
);
1666 CalcBoundingBox(0,0);
1667 CalcBoundingBox(bw
,bh
);
1669 cairo_restore(m_cairo
);
1672 void wxGtkPrinterDCImpl
::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1674 DoDrawRotatedText( text
, x
, y
, 0.0 );
1677 void wxGtkPrinterDCImpl
::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1679 double xx
= XLOG2DEV(x
);
1680 double yy
= YLOG2DEV(y
);
1684 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1686 const wxScopedCharBuffer data
= text
.utf8_str();
1688 size_t datalen
= strlen(data
);
1689 pango_layout_set_text( m_layout
, data
, datalen
);
1693 PangoAttrList
*attrs
= pango_attr_list_new();
1694 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1696 a
->end_index
= datalen
;
1697 pango_attr_list_insert(attrs
, a
);
1698 pango_layout_set_attributes(m_layout
, attrs
);
1699 pango_attr_list_unref(attrs
);
1702 if (m_textForegroundColour
.Ok())
1704 unsigned char red
= m_textForegroundColour
.Red();
1705 unsigned char blue
= m_textForegroundColour
.Blue();
1706 unsigned char green
= m_textForegroundColour
.Green();
1707 unsigned char alpha
= m_textForegroundColour
.Alpha();
1709 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1711 double redPS
= (double)(red
) / 255.0;
1712 double bluePS
= (double)(blue
) / 255.0;
1713 double greenPS
= (double)(green
) / 255.0;
1714 double alphaPS
= (double)(alpha
) / 255.0;
1716 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1719 m_currentBlue
= blue
;
1720 m_currentGreen
= green
;
1721 m_currentAlpha
= alpha
;
1726 cairo_move_to (m_cairo
, xx
, yy
);
1728 cairo_save( m_cairo
);
1730 if (fabs(angle
) > 0.00001)
1731 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1733 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1736 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1738 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1740 unsigned char red
= m_textBackgroundColour
.Red();
1741 unsigned char blue
= m_textBackgroundColour
.Blue();
1742 unsigned char green
= m_textBackgroundColour
.Green();
1743 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1745 double redPS
= (double)(red
) / 255.0;
1746 double bluePS
= (double)(blue
) / 255.0;
1747 double greenPS
= (double)(green
) / 255.0;
1748 double alphaPS
= (double)(alpha
) / 255.0;
1750 cairo_save(m_cairo
);
1751 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1752 cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1753 cairo_fill(m_cairo
);
1754 cairo_restore(m_cairo
);
1757 pango_cairo_update_layout (m_cairo
, m_layout
);
1758 pango_cairo_show_layout (m_cairo
, m_layout
);
1760 cairo_restore( m_cairo
);
1764 // Undo underline attributes setting
1765 pango_layout_set_attributes(m_layout
, NULL
);
1768 // Back to device units:
1769 CalcBoundingBox (x
, y
);
1770 CalcBoundingBox (x
+ w
, y
+ h
);
1773 void wxGtkPrinterDCImpl
::Clear()
1775 // Clear does nothing for printing, but keep the code
1778 cairo_save(m_cairo);
1779 cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1780 SetBrush(m_backgroundBrush);
1781 cairo_paint(m_cairo);
1782 cairo_restore(m_cairo);
1786 void wxGtkPrinterDCImpl
::SetFont( const wxFont
& font
)
1793 pango_font_description_free( m_fontdesc
);
1795 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1797 float size
= pango_font_description_get_size( m_fontdesc
);
1798 size
= size
* GetFontPointSizeAdjustment(72.0);
1799 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1801 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1805 void wxGtkPrinterDCImpl
::SetPen( const wxPen
& pen
)
1807 if (!pen
.Ok()) return;
1813 if (m_pen
.GetWidth() <= 0)
1816 width
= (double) m_pen
.GetWidth();
1818 cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1819 static const double dotted
[] = {2.0, 5.0};
1820 static const double short_dashed
[] = {4.0, 4.0};
1821 static const double long_dashed
[] = {4.0, 8.0};
1822 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1824 switch (m_pen
.GetStyle())
1826 case wxPENSTYLE_DOT
: cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1827 case wxPENSTYLE_SHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1828 case wxPENSTYLE_LONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1829 case wxPENSTYLE_DOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1830 case wxPENSTYLE_USER_DASH
:
1833 int num
= m_pen
.GetDashes (&wx_dashes
);
1834 gdouble
*g_dashes
= g_new( gdouble
, num
);
1836 for (i
= 0; i
< num
; ++i
)
1837 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1838 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1842 case wxPENSTYLE_SOLID
:
1843 case wxPENSTYLE_TRANSPARENT
:
1844 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1847 switch (m_pen
.GetCap())
1849 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1850 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1852 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1855 switch (m_pen
.GetJoin())
1857 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1858 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1860 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1863 unsigned char red
= m_pen
.GetColour().Red();
1864 unsigned char blue
= m_pen
.GetColour().Blue();
1865 unsigned char green
= m_pen
.GetColour().Green();
1866 unsigned char alpha
= m_pen
.GetColour().Alpha();
1868 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1870 double redPS
= (double)(red
) / 255.0;
1871 double bluePS
= (double)(blue
) / 255.0;
1872 double greenPS
= (double)(green
) / 255.0;
1873 double alphaPS
= (double)(alpha
) / 255.0;
1875 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1878 m_currentBlue
= blue
;
1879 m_currentGreen
= green
;
1880 m_currentAlpha
= alpha
;
1884 void wxGtkPrinterDCImpl
::SetBrush( const wxBrush
& brush
)
1886 if (!brush
.Ok()) return;
1890 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1892 cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1901 unsigned char red
= m_brush
.GetColour().Red();
1902 unsigned char blue
= m_brush
.GetColour().Blue();
1903 unsigned char green
= m_brush
.GetColour().Green();
1904 unsigned char alpha
= m_brush
.GetColour().Alpha();
1906 double redPS
= (double)(red
) / 255.0;
1907 double bluePS
= (double)(blue
) / 255.0;
1908 double greenPS
= (double)(green
) / 255.0;
1909 double alphaPS
= (double)(alpha
) / 255.0;
1911 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1913 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1916 m_currentBlue
= blue
;
1917 m_currentGreen
= green
;
1918 m_currentAlpha
= alpha
;
1921 if (m_brush
.IsHatch())
1924 cairo_surface_t
*surface
;
1925 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
1926 cr
= cairo_create(surface
);
1927 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
1928 cairo_set_line_width(cr
, 1);
1929 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
1931 switch (m_brush
.GetStyle())
1933 case wxBRUSHSTYLE_CROSS_HATCH
:
1934 cairo_move_to(cr
, 5, 0);
1935 cairo_line_to(cr
, 5, 10);
1936 cairo_move_to(cr
, 0, 5);
1937 cairo_line_to(cr
, 10, 5);
1939 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
1940 cairo_move_to(cr
, 0, 10);
1941 cairo_line_to(cr
, 10, 0);
1943 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
1944 cairo_move_to(cr
, 0, 0);
1945 cairo_line_to(cr
, 10, 10);
1947 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
1948 cairo_move_to(cr
, 0, 0);
1949 cairo_line_to(cr
, 10, 10);
1950 cairo_move_to(cr
, 10, 0);
1951 cairo_line_to(cr
, 0, 10);
1953 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
1954 cairo_move_to(cr
, 0, 5);
1955 cairo_line_to(cr
, 10, 5);
1957 case wxBRUSHSTYLE_VERTICAL_HATCH
:
1958 cairo_move_to(cr
, 5, 0);
1959 cairo_line_to(cr
, 5, 10);
1962 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
1965 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
1969 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
1970 cairo_surface_destroy(surface
);
1971 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
1972 cairo_set_source(m_cairo
, pattern
);
1973 cairo_pattern_destroy(pattern
);
1977 void wxGtkPrinterDCImpl
::SetLogicalFunction( wxRasterOperationMode function
)
1979 if (function
== wxCLEAR
)
1980 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
1981 else if (function
== wxOR
)
1982 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
1983 else if (function
== wxNO_OP
)
1984 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
1985 else if (function
== wxAND
)
1986 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
1987 else if (function
== wxSET
)
1988 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
1989 else if (function
== wxXOR
)
1990 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
1991 else // wxCOPY or anything else.
1992 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
1995 void wxGtkPrinterDCImpl
::SetBackground( const wxBrush
& brush
)
1997 m_backgroundBrush
= brush
;
1998 cairo_save(m_cairo
);
1999 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2001 SetBrush(m_backgroundBrush
);
2002 cairo_paint(m_cairo
);
2003 cairo_restore(m_cairo
);
2006 void wxGtkPrinterDCImpl
::SetBackgroundMode(int mode
)
2008 if (mode
== wxBRUSHSTYLE_SOLID
)
2009 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2011 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2014 void wxGtkPrinterDCImpl
::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2016 cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2017 cairo_clip(m_cairo
);
2020 void wxGtkPrinterDCImpl
::DestroyClippingRegion()
2022 cairo_reset_clip(m_cairo
);
2025 bool wxGtkPrinterDCImpl
::StartDoc(const wxString
& WXUNUSED(message
))
2030 void wxGtkPrinterDCImpl
::EndDoc()
2035 void wxGtkPrinterDCImpl
::StartPage()
2040 void wxGtkPrinterDCImpl
::EndPage()
2045 wxCoord wxGtkPrinterDCImpl
::GetCharHeight() const
2047 pango_layout_set_text( m_layout
, "H", 1 );
2050 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2052 return wxRound( h
* m_PS2DEV
);
2055 wxCoord wxGtkPrinterDCImpl
::GetCharWidth() const
2057 pango_layout_set_text( m_layout
, "H", 1 );
2060 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2062 return wxRound( w
* m_PS2DEV
);
2065 void wxGtkPrinterDCImpl
::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2067 wxCoord
*externalLeading
,
2068 const wxFont
*theFont
) const
2076 if ( externalLeading
)
2077 *externalLeading
= 0;
2084 cairo_save( m_cairo
);
2085 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
2087 // Set layout's text
2088 const wxScopedCharBuffer dataUTF8
= string
.utf8_str();
2093 // scale the font and apply it
2094 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2095 float size
= pango_font_description_get_size(desc
);
2096 size
= size
* GetFontPointSizeAdjustment(72.0);
2097 pango_font_description_set_size(desc
, (gint
)size
);
2099 pango_layout_set_font_description(m_layout
, desc
);
2102 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2105 pango_layout_get_pixel_size( m_layout
, width
, &h
);
2111 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2112 int baseline
= pango_layout_iter_get_baseline(iter
);
2113 pango_layout_iter_free(iter
);
2114 *descent
= h
- PANGO_PIXELS(baseline
);
2119 // restore font and reset font's size back
2120 pango_layout_set_font_description(m_layout
, m_fontdesc
);
2122 PangoFontDescription
*desc
= theFont
->GetNativeFontInfo()->description
;
2123 pango_font_description_set_size(desc
, oldSize
);
2126 cairo_restore( m_cairo
);
2129 void wxGtkPrinterDCImpl
::DoGetSize(int* width
, int* height
) const
2131 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2134 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2136 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2139 void wxGtkPrinterDCImpl
::DoGetSizeMM(int *width
, int *height
) const
2141 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2144 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2146 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2149 wxSize wxGtkPrinterDCImpl
::GetPPI() const
2151 return wxSize( (int)m_resolution
, (int)m_resolution
);
2154 void wxGtkPrinterDCImpl
::SetPrintData(const wxPrintData
& data
)
2159 // overriden for wxPrinterDC Impl
2161 wxRect wxGtkPrinterDCImpl
::GetPaperRect() const
2163 // Does GtkPrint support printer margins?
2166 DoGetSize( &w
, &h
);
2167 return wxRect( 0,0,w
,h
);
2170 int wxGtkPrinterDCImpl
::GetResolution() const
2172 return m_resolution
;
2175 // ----------------------------------------------------------------------------
2177 // ----------------------------------------------------------------------------
2179 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2181 void wxGtkPrintPreview
::Init(wxPrintout
* WXUNUSED(printout
),
2182 wxPrintout
* WXUNUSED(printoutForPrinting
),
2185 // convert wxPrintQuality to resolution (input pointer can be NULL)
2186 wxPrintQuality quality
= data ? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2189 case wxPRINT_QUALITY_HIGH
:
2190 m_resolution
= 1200;
2193 case wxPRINT_QUALITY_LOW
:
2197 case wxPRINT_QUALITY_DRAFT
:
2204 // positive values directly indicate print resolution
2205 m_resolution
= quality
;
2209 wxFAIL_MSG( "unknown print quality" );
2212 case wxPRINT_QUALITY_MEDIUM
:
2221 wxGtkPrintPreview
::wxGtkPrintPreview(wxPrintout
*printout
,
2222 wxPrintout
*printoutForPrinting
,
2223 wxPrintDialogData
*data
)
2224 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2226 Init(printout
, printoutForPrinting
, data ?
&data
->GetPrintData() : NULL
);
2229 wxGtkPrintPreview
::wxGtkPrintPreview(wxPrintout
*printout
,
2230 wxPrintout
*printoutForPrinting
,
2232 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2234 Init(printout
, printoutForPrinting
, data
);
2237 wxGtkPrintPreview
::~wxGtkPrintPreview()
2241 bool wxGtkPrintPreview
::Print(bool interactive
)
2243 if (!m_printPrintout
)
2246 wxPrinter
printer(& m_printDialogData
);
2247 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2250 void wxGtkPrintPreview
::DetermineScaling()
2252 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2254 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2256 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2260 m_previewPrintout
->SetPPIScreen(wxGetDisplayPPI());
2261 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2263 // Get width and height in points (1/72th of an inch)
2264 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2265 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2266 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2268 wxSize
sizeTenthsMM(paper
->GetSize());
2269 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2271 // If in landscape mode, we need to swap the width and height.
2272 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2274 m_pageWidth
= sizeDevUnits
.y
;
2275 m_pageHeight
= sizeDevUnits
.x
;
2276 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2280 m_pageWidth
= sizeDevUnits
.x
;
2281 m_pageHeight
= sizeDevUnits
.y
;
2282 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2284 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2285 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2287 // At 100%, the page should look about page-size on the screen.
2288 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2289 m_previewScaleY
= m_previewScaleX
;