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"
37 #include "wx/rawbmp.h"
40 #include <gtk/gtkpagesetupunixdialog.h>
43 wxFORCE_LINK_THIS_MODULE(gtk_print
)
45 #if wxUSE_LIBGNOMEPRINT
46 #include "wx/gtk/gnome/gprint.h"
49 // Usefull to convert angles from/to Rad to/from Deg.
50 static const double RAD2DEG
= 180.0 / M_PI
;
51 static const double DEG2RAD
= M_PI
/ 180.0;
53 static wxCairoLibrary
* gs_cairo
= NULL
;
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 gs_cairo
= wxCairoLibrary::Get();
82 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
83 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
87 void wxGtkPrintModule::OnExit()
92 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
94 //----------------------------------------------------------------------------
96 //----------------------------------------------------------------------------
98 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
100 return new wxGtkPrinter( data
);
103 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
104 wxPrintout
*printout
,
105 wxPrintDialogData
*data
)
107 return new wxGtkPrintPreview( preview
, printout
, data
);
110 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
111 wxPrintout
*printout
,
114 return new wxGtkPrintPreview( preview
, printout
, data
);
117 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
118 wxPrintDialogData
*data
)
120 return new wxGtkPrintDialog( parent
, data
);
123 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
126 return new wxGtkPrintDialog( parent
, data
);
129 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
130 wxPageSetupDialogData
* data
)
132 return new wxGtkPageSetupDialog( parent
, data
);
135 bool wxGtkPrintFactory::HasPrintSetupDialog()
141 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
142 wxPrintData
* WXUNUSED(data
))
147 wxDCImpl
* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
149 return new wxGtkPrinterDCImpl( owner
, data
);
152 bool wxGtkPrintFactory::HasOwnPrintToFile()
157 bool wxGtkPrintFactory::HasPrinterLine()
162 wxString
wxGtkPrintFactory::CreatePrinterLine()
165 return wxEmptyString
;
168 bool wxGtkPrintFactory::HasStatusLine()
174 wxString
wxGtkPrintFactory::CreateStatusLine()
177 return wxEmptyString
;
180 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
182 return new wxGtkPrintNativeData
;
185 //----------------------------------------------------------------------------
186 // Callback functions for Gtk Printings.
187 //----------------------------------------------------------------------------
189 // We use it to pass useful objects to GTK printing callback functions.
190 struct wxPrinterToGtkData
192 wxGtkPrinter
* printer
;
193 wxPrintout
* printout
;
198 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
200 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
202 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
205 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
207 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
209 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
212 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
213 GtkPrintContext
* WXUNUSED(context
),
216 wxPrintout
*printout
= (wxPrintout
*) user_data
;
218 printout
->OnEndPrinting();
222 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
223 GtkPrintOperationPreview
* WXUNUSED(preview
),
224 GtkPrintContext
*context
,
228 wxPrintout
*printout
= (wxPrintout
*) user_data
;
230 printout
->SetIsPreview(true);
232 /* We create a Cairo context with 72dpi resolution. This resolution is
233 * only used for positioning. */
234 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
235 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
241 //----------------------------------------------------------------------------
242 // wxGtkPrintNativeData
243 //----------------------------------------------------------------------------
245 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
247 wxGtkPrintNativeData::wxGtkPrintNativeData()
249 m_config
= gtk_print_settings_new();
252 wxGtkPrintNativeData::~wxGtkPrintNativeData()
254 g_object_unref (m_config
);
257 // Convert datas stored in m_config to a wxPrintData.
258 // Called by wxPrintData::ConvertFromNative().
259 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
264 int resolution
= gtk_print_settings_get_resolution(m_config
);
265 if ( resolution
> 0 )
267 // if resolution is explicitly set, use it
268 data
.SetQuality(resolution
);
270 else // use more vague "quality"
272 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
273 if (quality
== GTK_PRINT_QUALITY_HIGH
)
274 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
275 else if (quality
== GTK_PRINT_QUALITY_LOW
)
276 data
.SetQuality(wxPRINT_QUALITY_LOW
);
277 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
278 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
280 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
283 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
285 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
287 switch (gtk_print_settings_get_duplex(m_config
))
289 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
292 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
296 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
300 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
301 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
303 data
.SetOrientation(wxPORTRAIT
);
304 data
.SetOrientationReversed(false);
306 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
308 data
.SetOrientation(wxLANDSCAPE
);
309 data
.SetOrientationReversed(false);
311 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
313 data
.SetOrientation(wxPORTRAIT
);
314 data
.SetOrientationReversed(true);
316 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
318 data
.SetOrientation(wxLANDSCAPE
);
319 data
.SetOrientationReversed(true);
322 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
324 // Paper formats : these are the most common paper formats.
325 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
327 data
.SetPaperId(wxPAPER_NONE
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
329 data
.SetPaperId(wxPAPER_A3
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
331 data
.SetPaperId(wxPAPER_A4
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
333 data
.SetPaperId(wxPAPER_A5
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
335 data
.SetPaperId(wxPAPER_B5
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
337 data
.SetPaperId(wxPAPER_LETTER
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
339 data
.SetPaperId(wxPAPER_LEGAL
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
341 data
.SetPaperId(wxPAPER_EXECUTIVE
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
343 data
.SetPaperId(wxPAPER_ENV_10
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
345 data
.SetPaperId(wxPAPER_ENV_C5
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
347 data
.SetPaperId(wxPAPER_ENV_C6
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
349 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
351 data
.SetPaperId(wxPAPER_ENV_B5
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
353 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
355 data
.SetPaperId( wxPAPER_CSHEET
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
357 data
.SetPaperId( wxPAPER_DSHEET
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
359 data
.SetPaperId( wxPAPER_ESHEET
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
361 data
.SetPaperId( wxPAPER_LETTERSMALL
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
363 data
.SetPaperId( wxPAPER_TABLOID
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
365 data
.SetPaperId( wxPAPER_LEDGER
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
367 data
.SetPaperId( wxPAPER_STATEMENT
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
369 data
.SetPaperId( wxPAPER_A4SMALL
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
371 data
.SetPaperId( wxPAPER_B4
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
373 data
.SetPaperId( wxPAPER_FOLIO
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
375 data
.SetPaperId( wxPAPER_QUARTO
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
377 data
.SetPaperId( wxPAPER_10X14
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
379 data
.SetPaperId( wxPAPER_11X17
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
381 data
.SetPaperId( wxPAPER_NOTE
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
383 data
.SetPaperId( wxPAPER_ENV_9
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
385 data
.SetPaperId( wxPAPER_ENV_11
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
387 data
.SetPaperId( wxPAPER_ENV_12
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
389 data
.SetPaperId( wxPAPER_ENV_14
);
390 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
391 data
.SetPaperId( wxPAPER_ENV_DL
);
392 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
393 data
.SetPaperId( wxPAPER_ENV_C3
);
394 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
395 data
.SetPaperId( wxPAPER_ENV_C4
);
396 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
397 data
.SetPaperId( wxPAPER_ENV_C65
);
398 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
399 data
.SetPaperId( wxPAPER_ENV_B4
);
400 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
401 data
.SetPaperId( wxPAPER_ENV_B6
);
402 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
403 data
.SetPaperId( wxPAPER_ENV_ITALY
);
404 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
405 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
406 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
407 data
.SetPaperId( wxPAPER_FANFOLD_US
);
408 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
409 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
410 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
411 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
413 data
.SetPaperId(wxPAPER_NONE
);
417 // Put datas given by the wxPrintData into m_config.
418 // Called by wxPrintData::ConvertToNative().
419 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
424 wxPrintQuality quality
= data
.GetQuality();
425 if (quality
== wxPRINT_QUALITY_HIGH
)
426 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
427 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
428 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
429 else if (quality
== wxPRINT_QUALITY_LOW
)
430 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
431 else if (quality
== wxPRINT_QUALITY_DRAFT
)
432 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
433 else if (quality
> 1)
434 gtk_print_settings_set_resolution (m_config
, quality
);
436 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
438 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
440 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
442 switch (data
.GetDuplex())
444 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
447 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
451 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
455 if (!data
.IsOrientationReversed())
457 if (data
.GetOrientation() == wxLANDSCAPE
)
458 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
460 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
463 if (data
.GetOrientation() == wxLANDSCAPE
)
464 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
466 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
469 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
471 // Paper formats: these are the most common paper formats.
472 switch (data
.GetPaperId())
474 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
476 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
478 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
480 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
482 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
484 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
486 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
488 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
490 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
492 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
494 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
496 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
498 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
500 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
502 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
504 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
506 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
508 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
510 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
512 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
514 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
516 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
518 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
520 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
522 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
524 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
526 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
528 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
530 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
532 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
534 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
536 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
538 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
540 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
542 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
544 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
546 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
548 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
550 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
552 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
554 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
556 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
565 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
568 m_config
= gtk_print_settings_copy(config
);
571 // Extract page setup from settings.
572 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
574 GtkPageSetup
* page_setup
= gtk_page_setup_new();
575 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
577 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
578 if (paper_size
!= NULL
)
579 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
584 // Insert page setup into a given GtkPrintSettings.
585 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
587 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
588 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
591 //----------------------------------------------------------------------------
593 //----------------------------------------------------------------------------
595 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
597 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
598 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
599 wxPoint(0, 0), wxSize(600, 600),
600 wxDEFAULT_DIALOG_STYLE
|
604 m_printDialogData
= *data
;
610 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
611 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
612 wxPoint(0, 0), wxSize(600, 600),
613 wxDEFAULT_DIALOG_STYLE
|
617 m_printDialogData
= *data
;
624 wxGtkPrintDialog::~wxGtkPrintDialog()
628 // This is called even if we actually don't want the dialog to appear.
629 int wxGtkPrintDialog::ShowModal()
631 GtkPrintOperationResult response
;
633 // We need to restore the settings given in the constructor.
634 wxPrintData data
= m_printDialogData
.GetPrintData();
635 wxGtkPrintNativeData
*native
=
636 (wxGtkPrintNativeData
*) data
.GetNativeData();
637 data
.ConvertToNative();
639 GtkPrintSettings
* settings
= native
->GetPrintConfig();
641 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
642 int fromPage
= m_printDialogData
.GetFromPage();
643 int toPage
= m_printDialogData
.GetToPage();
644 if (m_printDialogData
.GetSelection())
645 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
646 else if (m_printDialogData
.GetAllPages())
647 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
649 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
651 range
= g_new (GtkPageRange
, 1);
652 range
[0].start
= fromPage
-1;
653 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
654 gtk_print_settings_set_page_ranges (settings
, range
, 1);
657 // If the settings are OK, we restore it.
658 if (settings
!= NULL
)
659 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
660 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
662 // Show the dialog if needed.
663 GError
* gError
= NULL
;
665 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
667 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
669 // Does everything went well?
670 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
674 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
676 g_error_free (gError
);
677 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
678 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
681 // Now get the settings and save it.
682 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
683 native
->SetPrintConfig(newSettings
);
684 data
.ConvertFromNative();
686 // Same problem as a few lines before.
687 switch (gtk_print_settings_get_print_pages(newSettings
))
689 case GTK_PRINT_PAGES_CURRENT
:
690 m_printDialogData
.SetSelection( true );
692 case GTK_PRINT_PAGES_RANGES
:
693 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
694 // 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
695 // will hit "OK" button. However we can only save 1-3 in the print data.
698 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
701 m_printDialogData
.SetFromPage( range
[0].start
);
702 m_printDialogData
.SetToPage( range
[0].end
);
705 m_printDialogData
.SetAllPages( true );
706 m_printDialogData
.SetFromPage( 0 );
707 m_printDialogData
.SetToPage( 9999 );
710 case GTK_PRINT_PAGES_ALL
:
712 m_printDialogData
.SetAllPages( true );
713 m_printDialogData
.SetFromPage( 0 );
714 m_printDialogData
.SetToPage( 9999 );
721 //----------------------------------------------------------------------------
722 // wxGtkPageSetupDialog
723 //----------------------------------------------------------------------------
725 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
727 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
728 wxPageSetupDialogData
* data
)
731 m_pageDialogData
= *data
;
736 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
740 int wxGtkPageSetupDialog::ShowModal()
743 m_pageDialogData
.GetPrintData().ConvertToNative();
744 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
745 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
747 // We only need the pagesetup data which are part of the settings.
748 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
750 // If the user used a custom paper format the last time he printed, we have to restore it too.
751 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
753 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
754 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
756 wxString title
= _("Custom size");
757 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
758 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
759 g_object_unref(customSize
);
763 // Now show the dialog.
764 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
769 if (newPageSetup
!= oldPageSetup
)
771 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
772 m_pageDialogData
.GetPrintData().ConvertFromNative();
774 // Store custom paper format if any.
775 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
777 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
778 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
779 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
780 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
781 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
783 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
784 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
786 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
787 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
789 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
802 //----------------------------------------------------------------------------
804 //----------------------------------------------------------------------------
806 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
808 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
809 wxPrinterBase( data
)
814 m_printDialogData
= *data
;
817 wxGtkPrinter::~wxGtkPrinter()
821 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
825 sm_lastError
= wxPRINTER_ERROR
;
829 // Let's correct the PageInfo just in case the app gives wrong values.
830 int fromPage
, toPage
;
831 int minPage
, maxPage
;
832 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
833 m_printDialogData
.SetAllPages(true);
835 if (minPage
< 1) minPage
= 1;
836 if (maxPage
< 1) maxPage
= 9999;
837 if (maxPage
< minPage
) maxPage
= minPage
;
839 m_printDialogData
.SetMinPage(minPage
);
840 m_printDialogData
.SetMaxPage(maxPage
);
843 if (fromPage
< minPage
) fromPage
= minPage
;
844 else if (fromPage
> maxPage
) fromPage
= maxPage
;
845 m_printDialogData
.SetFromPage(fromPage
);
849 m_printDialogData
.SetToPage(toPage
);
850 if (toPage
> maxPage
) toPage
= maxPage
;
851 else if (toPage
< minPage
) toPage
= minPage
;
854 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
857 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
858 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
860 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
862 native
->SetPrintJob( printOp
);
864 printout
->SetIsPreview(false);
866 wxPrinterToGtkData dataToSend
;
867 dataToSend
.printer
= this;
868 dataToSend
.printout
= printout
;
870 // These Gtk signals are caught here.
871 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
872 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
873 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
874 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
876 // This is used to setup the DC and
877 // show the dialog if desired
878 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
879 dialog
.SetPrintDC(m_dc
);
880 dialog
.SetShowDialog(prompt
);
882 // doesn't necessarily show
883 int ret
= dialog
.ShowModal();
884 if (ret
== wxID_CANCEL
)
886 sm_lastError
= wxPRINTER_CANCELLED
;
890 sm_lastError
= wxPRINTER_ERROR
;
891 wxFAIL_MSG(_("The print dialog returned an error."));
894 g_object_unref (printOp
);
896 return (sm_lastError
== wxPRINTER_NO_ERROR
);
899 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
901 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
902 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
904 // We need to update printdata with the new data from the dialog and we
905 // have to do this here because this method needs this new data and we
906 // cannot update it earlier
907 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
908 printdata
.ConvertFromNative();
910 SetPrintContext(context
);
911 native
->SetPrintContext( context
);
913 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
918 if (sm_lastError
!= wxPRINTER_CANCELLED
)
920 sm_lastError
= wxPRINTER_ERROR
;
921 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
925 wxSize ScreenPixels
= wxGetDisplaySize();
926 wxSize ScreenMM
= wxGetDisplaySizeMM();
928 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
929 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
930 printout
->SetPPIPrinter( printDC
->GetResolution(),
931 printDC
->GetResolution() );
933 printout
->SetDC(m_dc
);
936 m_dc
->GetSize(&w
, &h
);
937 printout
->SetPageSizePixels((int)w
, (int)h
);
938 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
940 m_dc
->GetSizeMM(&mw
, &mh
);
941 printout
->SetPageSizeMM((int)mw
, (int)mh
);
942 printout
->OnPreparePrinting();
944 // Get some parameters from the printout, if defined.
945 int fromPage
, toPage
;
946 int minPage
, maxPage
;
947 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
951 sm_lastError
= wxPRINTER_ERROR
;
952 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
956 printout
->OnBeginPrinting();
960 // If we're not previewing we need to calculate the number of pages to print.
961 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
962 // have defined in the dialog. So the number of pages is the maximum available.
963 if (!printout
->IsPreview())
965 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
966 switch (gtk_print_settings_get_print_pages(settings
))
968 case GTK_PRINT_PAGES_CURRENT
:
971 case GTK_PRINT_PAGES_RANGES
:
972 {gint num_ranges
= 0;
975 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
976 for (i
=0; i
<num_ranges
; i
++)
978 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
979 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
980 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
981 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
982 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
984 gtk_print_settings_set_page_ranges (settings
, range
, 1);
986 case GTK_PRINT_PAGES_ALL
:
988 numPages
= maxPage
- minPage
+ 1;
992 else numPages
= maxPage
- minPage
+ 1;
994 gtk_print_operation_set_n_pages(operation
, numPages
);
997 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
998 GtkPrintOperation
*operation
,
999 GtkPrintContext
* WXUNUSED(context
),
1002 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
1003 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
1005 int numPageToDraw
= page_nr
+ minPage
;
1006 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
1007 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
1009 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
1010 switch (gtk_print_settings_get_print_pages(settings
))
1012 case GTK_PRINT_PAGES_CURRENT
:
1013 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
1014 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1016 case GTK_PRINT_PAGES_RANGES
:
1017 {gint num_ranges
= 0;
1018 GtkPageRange
* range
;
1019 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1020 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1021 if (num_ranges
>= 1)
1023 startPage
= range
[0].start
+ 1;
1024 endPage
= range
[0].end
+ 1;
1027 startPage
= minPage
;
1031 case GTK_PRINT_PAGES_ALL
:
1033 startPage
= minPage
;
1038 if(numPageToDraw
== startPage
)
1040 if (!printout
->OnBeginDocument(startPage
, endPage
))
1042 wxLogError(_("Could not start printing."));
1043 sm_lastError
= wxPRINTER_ERROR
;
1047 // The app can render the page numPageToDraw.
1048 if (printout
->HasPage(numPageToDraw
))
1051 printout
->OnPrintPage(numPageToDraw
);
1056 if(numPageToDraw
== endPage
)
1058 printout
->OnEndDocument();
1062 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1064 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1066 dialog
.SetPrintDC(m_dc
);
1067 dialog
.SetShowDialog(true);
1069 int ret
= dialog
.ShowModal();
1071 if (ret
== wxID_CANCEL
)
1073 sm_lastError
= wxPRINTER_CANCELLED
;
1078 sm_lastError
= wxPRINTER_ERROR
;
1079 wxFAIL_MSG(_("The print dialog returned an error."));
1083 m_printDialogData
= dialog
.GetPrintDialogData();
1085 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1088 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1090 // Obsolete, for backward compatibility.
1094 //-----------------------------------------------------------------------------
1096 //-----------------------------------------------------------------------------
1098 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1099 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1100 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1101 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1104 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1106 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1111 wxGtkPrintNativeData
*native
=
1112 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1114 m_gpc
= native
->GetPrintContext();
1116 // Match print quality to resolution (high = 1200dpi)
1117 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1118 if (m_resolution
< 0)
1119 m_resolution
= (1 << (m_resolution
+4)) *150;
1121 m_PS2DEV
= (double)m_resolution
/ 72.0;
1122 m_DEV2PS
= 72.0 / (double)m_resolution
;
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 m_signX
= 1; // default x-axis left to right.
1135 m_signY
= 1; // default y-axis bottom up -> top down.
1137 // By default the origin of the Cairo context is in the upper left
1138 // corner of the printable area. We need to translate it so that it
1139 // is in the upper left corner of the paper (without margins)
1140 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1142 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1143 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1144 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1147 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1149 g_object_unref(m_context
);
1150 g_object_unref(m_layout
);
1153 bool wxGtkPrinterDCImpl::IsOk() const
1155 return m_gpc
!= NULL
;
1158 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1159 wxCoord
WXUNUSED(y1
),
1160 const wxColour
& WXUNUSED(col
),
1161 int WXUNUSED(style
))
1163 // We can't access the given coord as a Cairo context is scalable, ie a
1164 // coord doesn't mean anything in this context.
1165 wxFAIL_MSG(_("not implemented"));
1169 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1171 wxCoord xC
= circleCenter
.x
;
1172 wxCoord yC
= circleCenter
.y
;
1173 wxCoord xR
= rect
.x
;
1174 wxCoord yR
= rect
.y
;
1175 wxCoord w
= rect
.width
;
1176 wxCoord h
= rect
.height
;
1178 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1180 unsigned char redI
= initialColour
.Red();
1181 unsigned char blueI
= initialColour
.Blue();
1182 unsigned char greenI
= initialColour
.Green();
1183 unsigned char alphaI
= initialColour
.Alpha();
1184 unsigned char redD
= destColour
.Red();
1185 unsigned char blueD
= destColour
.Blue();
1186 unsigned char greenD
= destColour
.Green();
1187 unsigned char alphaD
= destColour
.Alpha();
1189 double redIPS
= (double)(redI
) / 255.0;
1190 double blueIPS
= (double)(blueI
) / 255.0;
1191 double greenIPS
= (double)(greenI
) / 255.0;
1192 double alphaIPS
= (double)(alphaI
) / 255.0;
1193 double redDPS
= (double)(redD
) / 255.0;
1194 double blueDPS
= (double)(blueD
) / 255.0;
1195 double greenDPS
= (double)(greenD
) / 255.0;
1196 double alphaDPS
= (double)(alphaD
) / 255.0;
1198 // Create a pattern with the gradient.
1199 cairo_pattern_t
* gradient
;
1200 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1201 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1202 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1204 // Fill the rectangle with this pattern.
1205 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1206 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1207 gs_cairo
->cairo_fill(m_cairo
);
1209 gs_cairo
->cairo_pattern_destroy(gradient
);
1211 CalcBoundingBox(xR
, yR
);
1212 CalcBoundingBox(xR
+w
, yR
+h
);
1215 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1219 wxCoord w
= rect
.width
;
1220 wxCoord h
= rect
.height
;
1222 unsigned char redI
= initialColour
.Red();
1223 unsigned char blueI
= initialColour
.Blue();
1224 unsigned char greenI
= initialColour
.Green();
1225 unsigned char alphaI
= initialColour
.Alpha();
1226 unsigned char redD
= destColour
.Red();
1227 unsigned char blueD
= destColour
.Blue();
1228 unsigned char greenD
= destColour
.Green();
1229 unsigned char alphaD
= destColour
.Alpha();
1231 double redIPS
= (double)(redI
) / 255.0;
1232 double blueIPS
= (double)(blueI
) / 255.0;
1233 double greenIPS
= (double)(greenI
) / 255.0;
1234 double alphaIPS
= (double)(alphaI
) / 255.0;
1235 double redDPS
= (double)(redD
) / 255.0;
1236 double blueDPS
= (double)(blueD
) / 255.0;
1237 double greenDPS
= (double)(greenD
) / 255.0;
1238 double alphaDPS
= (double)(alphaD
) / 255.0;
1240 // Create a pattern with the gradient.
1241 cairo_pattern_t
* gradient
;
1242 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1244 if (nDirection
== wxWEST
)
1246 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1247 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1250 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1251 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1254 // Fill the rectangle with this pattern.
1255 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1256 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1257 gs_cairo
->cairo_fill(m_cairo
);
1259 gs_cairo
->cairo_pattern_destroy(gradient
);
1261 CalcBoundingBox(x
, y
);
1262 CalcBoundingBox(x
+w
, y
+h
);
1265 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1266 wxCoord
WXUNUSED(y1
),
1267 wxColour
* WXUNUSED(col
)) const
1269 wxFAIL_MSG(_("not implemented"));
1273 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1275 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1278 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1279 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1280 gs_cairo
->cairo_stroke ( m_cairo
);
1282 CalcBoundingBox( x1
, y1
);
1283 CalcBoundingBox( x2
, y2
);
1286 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1293 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1294 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1295 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1296 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1298 gs_cairo
->cairo_stroke (m_cairo
);
1299 CalcBoundingBox( 0, 0 );
1300 CalcBoundingBox( w
, h
);
1303 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1305 double dx
= x1
- xc
;
1306 double dy
= y1
- yc
;
1307 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1309 double alpha1
, alpha2
;
1310 if (x1
== x2
&& y1
== y2
)
1318 alpha1
= alpha2
= 0.0;
1322 alpha1
= (x1
- xc
== 0) ?
1323 (y1
- yc
< 0) ? 90.0 : -90.0 :
1324 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1325 alpha2
= (x2
- xc
== 0) ?
1326 (y2
- yc
< 0) ? 90.0 : -90.0 :
1327 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1329 while (alpha1
<= 0) alpha1
+= 360;
1330 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1331 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1332 while (alpha2
> 360) alpha2
-= 360;
1338 gs_cairo
->cairo_new_path(m_cairo
);
1340 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1341 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1342 gs_cairo
->cairo_close_path (m_cairo
);
1344 SetBrush( m_brush
);
1345 gs_cairo
->cairo_fill_preserve( m_cairo
);
1348 gs_cairo
->cairo_stroke( m_cairo
);
1350 CalcBoundingBox (x1
, y1
);
1351 CalcBoundingBox (xc
, yc
);
1352 CalcBoundingBox (x2
, y2
);
1355 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1357 gs_cairo
->cairo_save( m_cairo
);
1359 gs_cairo
->cairo_new_path(m_cairo
);
1361 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1362 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1363 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1365 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1368 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1370 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1372 SetBrush( m_brush
);
1373 gs_cairo
->cairo_fill( m_cairo
);
1375 gs_cairo
->cairo_restore( m_cairo
);
1377 CalcBoundingBox( x
, y
);
1378 CalcBoundingBox( x
+w
, y
+h
);
1381 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1383 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1387 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1388 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1389 gs_cairo
->cairo_stroke ( m_cairo
);
1391 CalcBoundingBox( x
, y
);
1394 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1396 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1403 for ( i
=0; i
<n
; i
++ )
1404 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1406 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1408 for (i
= 1; i
< n
; i
++)
1409 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1411 gs_cairo
->cairo_stroke ( m_cairo
);
1414 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1418 gs_cairo
->cairo_save(m_cairo
);
1419 if (fillStyle
== wxWINDING_RULE
)
1420 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1422 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1424 int x
= points
[0].x
+ xoffset
;
1425 int y
= points
[0].y
+ yoffset
;
1426 gs_cairo
->cairo_new_path(m_cairo
);
1427 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1429 for (i
= 1; i
< n
; i
++)
1431 int x
= points
[i
].x
+ xoffset
;
1432 int y
= points
[i
].y
+ yoffset
;
1433 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1435 gs_cairo
->cairo_close_path(m_cairo
);
1437 SetBrush( m_brush
);
1438 gs_cairo
->cairo_fill_preserve( m_cairo
);
1441 gs_cairo
->cairo_stroke( m_cairo
);
1443 CalcBoundingBox( x
, y
);
1445 gs_cairo
->cairo_restore(m_cairo
);
1448 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1450 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1453 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1458 gs_cairo
->cairo_new_path(m_cairo
);
1459 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1461 SetBrush( m_brush
);
1462 gs_cairo
->cairo_fill_preserve( m_cairo
);
1465 gs_cairo
->cairo_stroke( m_cairo
);
1467 CalcBoundingBox( x
, y
);
1468 CalcBoundingBox( x
+ width
, y
+ height
);
1471 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1476 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1478 wxCoord dd
= 2 * (wxCoord
) radius
;
1479 if (dd
> width
) dd
= width
;
1480 if (dd
> height
) dd
= height
;
1483 wxCoord rad
= (wxCoord
) radius
;
1485 gs_cairo
->cairo_new_path(m_cairo
);
1486 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1487 gs_cairo
->cairo_curve_to(m_cairo
,
1488 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1489 XLOG2DEV(x
),YLOG2DEV(y
),
1490 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1491 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1492 gs_cairo
->cairo_curve_to(m_cairo
,
1493 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1494 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1495 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1496 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1497 gs_cairo
->cairo_curve_to(m_cairo
,
1498 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1499 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1500 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1501 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1502 gs_cairo
->cairo_curve_to(m_cairo
,
1503 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1504 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1505 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1506 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1507 gs_cairo
->cairo_close_path(m_cairo
);
1510 gs_cairo
->cairo_fill_preserve(m_cairo
);
1513 gs_cairo
->cairo_stroke(m_cairo
);
1515 CalcBoundingBox(x
,y
);
1516 CalcBoundingBox(x
+width
,y
+height
);
1519 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1524 gs_cairo
->cairo_save (m_cairo
);
1526 gs_cairo
->cairo_new_path(m_cairo
);
1528 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1529 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1530 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1532 SetBrush( m_brush
);
1533 gs_cairo
->cairo_fill_preserve( m_cairo
);
1536 gs_cairo
->cairo_stroke( m_cairo
);
1538 CalcBoundingBox( x
, y
);
1539 CalcBoundingBox( x
+ width
, y
+ height
);
1541 gs_cairo
->cairo_restore (m_cairo
);
1545 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1549 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1552 wxPointList::compatibility_iterator node
= points
->GetFirst();
1553 p
= node
->GetData();
1557 node
= node
->GetNext();
1558 p
= node
->GetData();
1562 (double)(x1
+ c
) / 2;
1564 (double)(y1
+ d
) / 2;
1566 gs_cairo
->cairo_new_path( m_cairo
);
1567 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1568 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1570 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1571 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1573 node
= node
->GetNext();
1576 q
= node
->GetData();
1584 x3
= (double)(x2
+ c
) / 2;
1585 y3
= (double)(y2
+ d
) / 2;
1587 gs_cairo
->cairo_curve_to(m_cairo
,
1588 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1589 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1590 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1592 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1593 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1595 node
= node
->GetNext();
1598 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1600 gs_cairo
->cairo_stroke( m_cairo
);
1602 #endif // wxUSE_SPLINES
1604 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1605 wxCoord width
, wxCoord height
,
1606 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1607 int rop
, bool useMask
,
1608 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1609 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1611 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1612 wxT("mask coordinates are not supported") );
1614 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1616 // Blit into a bitmap.
1617 wxBitmap
bitmap( width
, height
);
1619 memDC
.SelectObject(bitmap
);
1620 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1621 memDC
.SelectObject(wxNullBitmap
);
1623 // Draw bitmap. scaling and positioning is done there.
1624 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1629 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1631 DoDrawBitmap( icon
, x
, y
, true );
1634 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1636 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1638 cairo_surface_t
* surface
;
1639 x
= wxCoord(XLOG2DEV(x
));
1640 y
= wxCoord(YLOG2DEV(y
));
1641 int bw
= bitmap
.GetWidth();
1642 int bh
= bitmap
.GetHeight();
1643 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1644 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1645 wxUint32
* data
= (wxUint32
*)buffer
;
1647 wxMask
*mask
= NULL
;
1648 if (useMask
) mask
= bmpSource
.GetMask();
1650 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1651 // then we'll use a different format and iterator than if it doesn't.
1652 if (bmpSource
.HasAlpha() || mask
)
1654 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1655 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1656 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1657 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1659 wxAlphaPixelData::Iterator
p(pixData
);
1661 for (y
=0; y
<bh
; y
++)
1663 wxAlphaPixelData::Iterator rowStart
= p
;
1664 for (x
=0; x
<bw
; x
++)
1666 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1667 // with alpha in the upper 8 bits, then red, then green, then
1668 // blue. The 32-bit quantities are stored native-endian.
1669 // Pre-multiplied alpha is used.
1670 unsigned char alpha
= p
.Alpha();
1672 if (!bmpSource
.HasAlpha() && mask
)
1678 *data
= ( alpha
<< 24
1679 | (p
.Red() * alpha
/255) << 16
1680 | (p
.Green() * alpha
/255) << 8
1681 | (p
.Blue() * alpha
/255) );
1686 p
.OffsetY(pixData
, 1);
1691 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1692 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1693 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1694 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1696 wxNativePixelData::Iterator
p(pixData
);
1698 for (y
=0; y
<bh
; y
++)
1700 wxNativePixelData::Iterator rowStart
= p
;
1701 for (x
=0; x
<bw
; x
++)
1703 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1704 // the upper 8 bits unused. Red, Green, and Blue are stored in
1705 // the remaining 24 bits in that order. The 32-bit quantities
1706 // are stored native-endian.
1707 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1712 p
.OffsetY(pixData
, 1);
1717 gs_cairo
->cairo_save(m_cairo
);
1719 // Prepare to draw the image.
1720 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1723 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1724 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1725 cairo_pattern_set_filter(pattern
,filter
);
1726 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1727 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1728 cairo_scale(m_cairo
, scaleX
, scaleY
);
1730 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1731 // Use the original size here since the context is scaled already.
1732 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1733 // Fill the rectangle using the pattern.
1734 gs_cairo
->cairo_fill(m_cairo
);
1737 gs_cairo
->cairo_pattern_destroy(pattern
);
1738 gs_cairo
->cairo_surface_destroy(surface
);
1741 CalcBoundingBox(0,0);
1742 CalcBoundingBox(bw
,bh
);
1744 gs_cairo
->cairo_restore(m_cairo
);
1747 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1749 DoDrawRotatedText( text
, x
, y
, 0.0 );
1752 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1754 double xx
= XLOG2DEV(x
);
1755 double yy
= YLOG2DEV(y
);
1759 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1761 const wxUTF8Buf data
= text
.utf8_str();
1763 size_t datalen
= strlen(data
);
1764 pango_layout_set_text( m_layout
, data
, datalen
);
1768 PangoAttrList
*attrs
= pango_attr_list_new();
1769 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1771 a
->end_index
= datalen
;
1772 pango_attr_list_insert(attrs
, a
);
1773 pango_layout_set_attributes(m_layout
, attrs
);
1774 pango_attr_list_unref(attrs
);
1777 if (m_textForegroundColour
.Ok())
1779 unsigned char red
= m_textForegroundColour
.Red();
1780 unsigned char blue
= m_textForegroundColour
.Blue();
1781 unsigned char green
= m_textForegroundColour
.Green();
1782 unsigned char alpha
= m_textForegroundColour
.Alpha();
1784 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1786 double redPS
= (double)(red
) / 255.0;
1787 double bluePS
= (double)(blue
) / 255.0;
1788 double greenPS
= (double)(green
) / 255.0;
1789 double alphaPS
= (double)(alpha
) / 255.0;
1791 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1794 m_currentBlue
= blue
;
1795 m_currentGreen
= green
;
1796 m_currentAlpha
= alpha
;
1802 // Scale font description.
1803 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1804 double size
= oldSize
;
1805 size
= size
* m_scaleX
;
1806 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1808 // Actually apply scaled font.
1809 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1811 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1813 if ( m_backgroundMode
== wxSOLID
)
1815 unsigned char red
= m_textBackgroundColour
.Red();
1816 unsigned char blue
= m_textBackgroundColour
.Blue();
1817 unsigned char green
= m_textBackgroundColour
.Green();
1818 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1820 double redPS
= (double)(red
) / 255.0;
1821 double bluePS
= (double)(blue
) / 255.0;
1822 double greenPS
= (double)(green
) / 255.0;
1823 double alphaPS
= (double)(alpha
) / 255.0;
1825 gs_cairo
->cairo_save(m_cairo
);
1826 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1827 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1828 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1829 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1830 gs_cairo
->cairo_fill(m_cairo
);
1831 gs_cairo
->cairo_restore(m_cairo
);
1835 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1837 gs_cairo
->cairo_save( m_cairo
);
1839 if (fabs(angle
) > 0.00001)
1840 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1842 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1843 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1845 gs_cairo
->cairo_restore( m_cairo
);
1849 // Undo underline attributes setting
1850 pango_layout_set_attributes(m_layout
, NULL
);
1853 // Reset unscaled size.
1854 pango_font_description_set_size( m_fontdesc
, oldSize
);
1856 // Actually apply unscaled font.
1857 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1859 // Back to device units:
1860 CalcBoundingBox (x
, y
);
1861 CalcBoundingBox (x
+ w
, y
+ h
);
1864 void wxGtkPrinterDCImpl::Clear()
1866 // Clear does nothing for printing, but keep the code
1869 gs_cairo->cairo_save(m_cairo);
1870 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1871 SetBrush(m_backgroundBrush);
1872 gs_cairo->cairo_paint(m_cairo);
1873 gs_cairo->cairo_restore(m_cairo);
1877 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1884 pango_font_description_free( m_fontdesc
);
1886 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1888 // Scale font description from device units to pango units
1889 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1890 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1891 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1893 // Actually apply scaled font.
1894 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1898 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1900 if (!pen
.Ok()) return;
1906 if (m_pen
.GetWidth() <= 0)
1909 width
= (double) m_pen
.GetWidth();
1911 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1912 static const double dotted
[] = {2.0, 5.0};
1913 static const double short_dashed
[] = {4.0, 4.0};
1914 static const double long_dashed
[] = {4.0, 8.0};
1915 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1917 switch (m_pen
.GetStyle())
1919 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1920 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1921 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1922 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1926 int num
= m_pen
.GetDashes (&wx_dashes
);
1927 gdouble
*g_dashes
= g_new( gdouble
, num
);
1929 for (i
= 0; i
< num
; ++i
)
1930 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1931 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1937 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1940 switch (m_pen
.GetCap())
1942 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1943 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1945 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1948 switch (m_pen
.GetJoin())
1950 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1951 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1953 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1956 unsigned char red
= m_pen
.GetColour().Red();
1957 unsigned char blue
= m_pen
.GetColour().Blue();
1958 unsigned char green
= m_pen
.GetColour().Green();
1959 unsigned char alpha
= m_pen
.GetColour().Alpha();
1961 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1963 double redPS
= (double)(red
) / 255.0;
1964 double bluePS
= (double)(blue
) / 255.0;
1965 double greenPS
= (double)(green
) / 255.0;
1966 double alphaPS
= (double)(alpha
) / 255.0;
1968 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1971 m_currentBlue
= blue
;
1972 m_currentGreen
= green
;
1973 m_currentAlpha
= alpha
;
1977 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1979 if (!brush
.Ok()) return;
1983 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1985 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1994 unsigned char red
= m_brush
.GetColour().Red();
1995 unsigned char blue
= m_brush
.GetColour().Blue();
1996 unsigned char green
= m_brush
.GetColour().Green();
1997 unsigned char alpha
= m_brush
.GetColour().Alpha();
1999 double redPS
= (double)(red
) / 255.0;
2000 double bluePS
= (double)(blue
) / 255.0;
2001 double greenPS
= (double)(green
) / 255.0;
2002 double alphaPS
= (double)(alpha
) / 255.0;
2004 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2006 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2009 m_currentBlue
= blue
;
2010 m_currentGreen
= green
;
2011 m_currentAlpha
= alpha
;
2014 if (m_brush
.IsHatch())
2017 cairo_surface_t
*surface
;
2018 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2019 cr
= gs_cairo
->cairo_create(surface
);
2020 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2021 gs_cairo
->cairo_set_line_width(cr
, 1);
2022 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2024 switch (m_brush
.GetStyle())
2027 gs_cairo
->cairo_move_to(cr
, 5, 0);
2028 gs_cairo
->cairo_line_to(cr
, 5, 10);
2029 gs_cairo
->cairo_move_to(cr
, 0, 5);
2030 gs_cairo
->cairo_line_to(cr
, 10, 5);
2032 case wxBDIAGONAL_HATCH
:
2033 gs_cairo
->cairo_move_to(cr
, 0, 10);
2034 gs_cairo
->cairo_line_to(cr
, 10, 0);
2036 case wxFDIAGONAL_HATCH
:
2037 gs_cairo
->cairo_move_to(cr
, 0, 0);
2038 gs_cairo
->cairo_line_to(cr
, 10, 10);
2040 case wxCROSSDIAG_HATCH
:
2041 gs_cairo
->cairo_move_to(cr
, 0, 0);
2042 gs_cairo
->cairo_line_to(cr
, 10, 10);
2043 gs_cairo
->cairo_move_to(cr
, 10, 0);
2044 gs_cairo
->cairo_line_to(cr
, 0, 10);
2046 case wxHORIZONTAL_HATCH
:
2047 gs_cairo
->cairo_move_to(cr
, 0, 5);
2048 gs_cairo
->cairo_line_to(cr
, 10, 5);
2050 case wxVERTICAL_HATCH
:
2051 gs_cairo
->cairo_move_to(cr
, 5, 0);
2052 gs_cairo
->cairo_line_to(cr
, 5, 10);
2055 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2058 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2059 gs_cairo
->cairo_stroke (cr
);
2061 gs_cairo
->cairo_destroy(cr
);
2062 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2063 gs_cairo
->cairo_surface_destroy(surface
);
2064 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2065 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2066 gs_cairo
->cairo_pattern_destroy(pattern
);
2070 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
2072 if (function
== wxCLEAR
)
2073 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2074 else if (function
== wxOR
)
2075 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2076 else if (function
== wxNO_OP
)
2077 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2078 else if (function
== wxAND
)
2079 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2080 else if (function
== wxSET
)
2081 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2082 else if (function
== wxXOR
)
2083 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2084 else // wxCOPY or anything else.
2085 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2088 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2090 m_backgroundBrush
= brush
;
2091 gs_cairo
->cairo_save(m_cairo
);
2092 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2094 SetBrush(m_backgroundBrush
);
2095 gs_cairo
->cairo_paint(m_cairo
);
2096 gs_cairo
->cairo_restore(m_cairo
);
2099 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2101 if (mode
== wxSOLID
)
2102 m_backgroundMode
= wxSOLID
;
2104 m_backgroundMode
= wxTRANSPARENT
;
2107 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2109 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2110 gs_cairo
->cairo_clip(m_cairo
);
2113 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2115 gs_cairo
->cairo_reset_clip(m_cairo
);
2118 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2123 void wxGtkPrinterDCImpl::EndDoc()
2128 void wxGtkPrinterDCImpl::StartPage()
2133 void wxGtkPrinterDCImpl::EndPage()
2138 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2140 pango_layout_set_text( m_layout
, "H", 1 );
2143 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2145 return wxRound( h
* m_PS2DEV
);
2148 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2150 pango_layout_set_text( m_layout
, "H", 1 );
2153 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2155 return wxRound( w
* m_PS2DEV
);
2158 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2160 wxCoord
*externalLeading
,
2161 const wxFont
*theFont
) const
2169 if ( externalLeading
)
2170 *externalLeading
= 0;
2177 // Set layout's text
2178 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2180 PangoFontDescription
*desc
= m_fontdesc
;
2181 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2183 gint oldSize
= pango_font_description_get_size( desc
);
2184 double size
= oldSize
;
2185 size
= size
* m_scaleY
;
2186 pango_font_description_set_size( desc
, (gint
)size
);
2188 // apply scaled font
2189 pango_layout_set_font_description( m_layout
, desc
);
2191 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2194 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2197 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2199 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2203 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2204 int baseline
= pango_layout_iter_get_baseline(iter
);
2205 pango_layout_iter_free(iter
);
2206 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2209 // Reset unscaled size.
2210 pango_font_description_set_size( desc
, oldSize
);
2212 // Reset unscaled font.
2213 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2216 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2218 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2221 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2223 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2226 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2228 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2231 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2233 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2236 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2238 return wxSize( (int)m_resolution
, (int)m_resolution
);
2241 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2246 // overriden for wxPrinterDC Impl
2248 wxRect
wxGtkPrinterDCImpl::GetPaperRect()
2250 // Does GtkPrint support printer margins?
2253 DoGetSize( &w
, &h
);
2254 return wxRect( 0,0,w
,h
);
2257 int wxGtkPrinterDCImpl::GetResolution()
2259 return m_resolution
;
2262 // ----------------------------------------------------------------------------
2264 // ----------------------------------------------------------------------------
2266 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2268 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2269 wxPrintout
* WXUNUSED(printoutForPrinting
),
2272 // convert wxPrintQuality to resolution (input pointer can be NULL)
2273 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2276 case wxPRINT_QUALITY_HIGH
:
2277 m_resolution
= 1200;
2280 case wxPRINT_QUALITY_LOW
:
2284 case wxPRINT_QUALITY_DRAFT
:
2291 // positive values directly indicate print resolution
2292 m_resolution
= quality
;
2296 wxFAIL_MSG( "unknown print quality" );
2299 case wxPRINT_QUALITY_MEDIUM
:
2308 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2309 wxPrintout
*printoutForPrinting
,
2310 wxPrintDialogData
*data
)
2311 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2313 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2316 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2317 wxPrintout
*printoutForPrinting
,
2319 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2321 Init(printout
, printoutForPrinting
, data
);
2324 wxGtkPrintPreview::~wxGtkPrintPreview()
2328 bool wxGtkPrintPreview::Print(bool interactive
)
2330 if (!m_printPrintout
)
2333 wxPrinter
printer(& m_printDialogData
);
2334 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2337 void wxGtkPrintPreview::DetermineScaling()
2339 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2341 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2343 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2347 wxSize ScreenPixels
= wxGetDisplaySize();
2348 wxSize ScreenMM
= wxGetDisplaySizeMM();
2350 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2351 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2353 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2355 // Get width and height in points (1/72th of an inch)
2356 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2358 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2359 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2360 wxSize
sizeTenthsMM(paper
->GetSize());
2361 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2363 // If in landscape mode, we need to swap the width and height.
2364 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2366 m_pageWidth
= sizeDevUnits
.y
;
2367 m_pageHeight
= sizeDevUnits
.x
;
2368 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2372 m_pageWidth
= sizeDevUnits
.x
;
2373 m_pageHeight
= sizeDevUnits
.y
;
2374 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2376 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2377 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2379 // At 100%, the page should look about page-size on the screen.
2380 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2381 m_previewScaleY
= m_previewScaleX
;