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 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
265 if (quality
== GTK_PRINT_QUALITY_HIGH
)
266 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
267 else if (quality
== GTK_PRINT_QUALITY_LOW
)
268 data
.SetQuality(wxPRINT_QUALITY_LOW
);
269 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
270 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
272 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
274 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
276 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
278 switch (gtk_print_settings_get_duplex(m_config
))
280 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
283 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
287 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
291 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
292 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
294 data
.SetOrientation(wxPORTRAIT
);
295 data
.SetOrientationReversed(false);
297 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
299 data
.SetOrientation(wxLANDSCAPE
);
300 data
.SetOrientationReversed(false);
302 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
304 data
.SetOrientation(wxPORTRAIT
);
305 data
.SetOrientationReversed(true);
307 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
309 data
.SetOrientation(wxLANDSCAPE
);
310 data
.SetOrientationReversed(true);
313 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
315 // Paper formats : these are the most common paper formats.
316 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
318 data
.SetPaperId(wxPAPER_NONE
);
319 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
320 data
.SetPaperId(wxPAPER_A3
);
321 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
322 data
.SetPaperId(wxPAPER_A4
);
323 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
324 data
.SetPaperId(wxPAPER_A5
);
325 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
326 data
.SetPaperId(wxPAPER_B5
);
327 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
328 data
.SetPaperId(wxPAPER_LETTER
);
329 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
330 data
.SetPaperId(wxPAPER_LEGAL
);
331 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
332 data
.SetPaperId(wxPAPER_EXECUTIVE
);
333 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
334 data
.SetPaperId(wxPAPER_ENV_10
);
335 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
336 data
.SetPaperId(wxPAPER_ENV_C5
);
337 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
338 data
.SetPaperId(wxPAPER_ENV_C6
);
339 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
340 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
341 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
342 data
.SetPaperId(wxPAPER_ENV_B5
);
343 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
344 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
345 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
346 data
.SetPaperId( wxPAPER_CSHEET
);
347 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
348 data
.SetPaperId( wxPAPER_DSHEET
);
349 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
350 data
.SetPaperId( wxPAPER_ESHEET
);
351 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
352 data
.SetPaperId( wxPAPER_LETTERSMALL
);
353 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
354 data
.SetPaperId( wxPAPER_TABLOID
);
355 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
356 data
.SetPaperId( wxPAPER_LEDGER
);
357 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
358 data
.SetPaperId( wxPAPER_STATEMENT
);
359 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
360 data
.SetPaperId( wxPAPER_A4SMALL
);
361 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
362 data
.SetPaperId( wxPAPER_B4
);
363 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
364 data
.SetPaperId( wxPAPER_FOLIO
);
365 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
366 data
.SetPaperId( wxPAPER_QUARTO
);
367 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
368 data
.SetPaperId( wxPAPER_10X14
);
369 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
370 data
.SetPaperId( wxPAPER_11X17
);
371 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
372 data
.SetPaperId( wxPAPER_NOTE
);
373 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
374 data
.SetPaperId( wxPAPER_ENV_9
);
375 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
376 data
.SetPaperId( wxPAPER_ENV_11
);
377 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
378 data
.SetPaperId( wxPAPER_ENV_12
);
379 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
380 data
.SetPaperId( wxPAPER_ENV_14
);
381 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
382 data
.SetPaperId( wxPAPER_ENV_DL
);
383 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
384 data
.SetPaperId( wxPAPER_ENV_C3
);
385 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
386 data
.SetPaperId( wxPAPER_ENV_C4
);
387 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
388 data
.SetPaperId( wxPAPER_ENV_C65
);
389 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
390 data
.SetPaperId( wxPAPER_ENV_B4
);
391 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
392 data
.SetPaperId( wxPAPER_ENV_B6
);
393 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
394 data
.SetPaperId( wxPAPER_ENV_ITALY
);
395 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
396 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
397 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
398 data
.SetPaperId( wxPAPER_FANFOLD_US
);
399 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
400 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
401 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
402 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
404 data
.SetPaperId(wxPAPER_NONE
);
408 // Put datas given by the wxPrintData into m_config.
409 // Called by wxPrintData::ConvertToNative().
410 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
415 wxPrintQuality quality
= data
.GetQuality();
416 if (quality
== wxPRINT_QUALITY_HIGH
)
417 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
418 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
419 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
420 else if (quality
== wxPRINT_QUALITY_LOW
)
421 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
422 else if (quality
== wxPRINT_QUALITY_DRAFT
)
423 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
424 else if (quality
> 1)
425 gtk_print_settings_set_resolution (m_config
, quality
);
427 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
429 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
431 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
433 switch (data
.GetDuplex())
435 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
438 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
442 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
446 if (!data
.IsOrientationReversed())
448 if (data
.GetOrientation() == wxLANDSCAPE
)
449 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
451 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
454 if (data
.GetOrientation() == wxLANDSCAPE
)
455 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
457 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
460 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
462 // Paper formats: these are the most common paper formats.
463 switch (data
.GetPaperId())
465 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
467 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
469 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
471 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
473 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
475 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
477 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
479 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
481 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
483 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
485 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
487 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
489 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
491 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
493 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
495 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
497 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
499 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
501 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
503 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
505 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
507 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
509 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
511 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
513 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
515 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
517 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
519 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
521 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
523 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
525 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
527 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
529 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
531 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
533 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
535 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
537 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
539 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
541 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
543 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
545 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
547 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
556 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
559 m_config
= gtk_print_settings_copy(config
);
562 // Extract page setup from settings.
563 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
565 GtkPageSetup
* page_setup
= gtk_page_setup_new();
566 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
568 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
569 if (paper_size
!= NULL
)
570 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
575 // Insert page setup into a given GtkPrintSettings.
576 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
578 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
579 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
582 //----------------------------------------------------------------------------
584 //----------------------------------------------------------------------------
586 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
588 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
589 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
590 wxPoint(0, 0), wxSize(600, 600),
591 wxDEFAULT_DIALOG_STYLE
|
595 m_printDialogData
= *data
;
601 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
602 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
603 wxPoint(0, 0), wxSize(600, 600),
604 wxDEFAULT_DIALOG_STYLE
|
608 m_printDialogData
= *data
;
615 wxGtkPrintDialog::~wxGtkPrintDialog()
619 // This is called even if we actually don't want the dialog to appear.
620 int wxGtkPrintDialog::ShowModal()
622 GtkPrintOperationResult response
;
624 // We need to restore the settings given in the constructor.
625 wxPrintData data
= m_printDialogData
.GetPrintData();
626 wxGtkPrintNativeData
*native
=
627 (wxGtkPrintNativeData
*) data
.GetNativeData();
628 data
.ConvertToNative();
630 GtkPrintSettings
* settings
= native
->GetPrintConfig();
632 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
633 int fromPage
= m_printDialogData
.GetFromPage();
634 int toPage
= m_printDialogData
.GetToPage();
635 if (m_printDialogData
.GetSelection())
636 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
637 else if (m_printDialogData
.GetAllPages())
638 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
640 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
642 range
= g_new (GtkPageRange
, 1);
643 range
[0].start
= fromPage
-1;
644 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
645 gtk_print_settings_set_page_ranges (settings
, range
, 1);
648 // If the settings are OK, we restore it.
649 if (settings
!= NULL
)
650 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
651 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
653 // Show the dialog if needed.
654 GError
* gError
= NULL
;
656 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
658 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
660 // Does everything went well?
661 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
665 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
667 g_error_free (gError
);
668 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
669 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
672 // Now get the settings and save it.
673 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
674 native
->SetPrintConfig(newSettings
);
675 data
.ConvertFromNative();
677 // Same problem as a few lines before.
678 switch (gtk_print_settings_get_print_pages(newSettings
))
680 case GTK_PRINT_PAGES_CURRENT
:
681 m_printDialogData
.SetSelection( true );
683 case GTK_PRINT_PAGES_RANGES
:
684 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
685 // 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
686 // will hit "OK" button. However we can only save 1-3 in the print data.
689 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
692 m_printDialogData
.SetFromPage( range
[0].start
);
693 m_printDialogData
.SetToPage( range
[0].end
);
696 m_printDialogData
.SetAllPages( true );
697 m_printDialogData
.SetFromPage( 0 );
698 m_printDialogData
.SetToPage( 9999 );
701 case GTK_PRINT_PAGES_ALL
:
703 m_printDialogData
.SetAllPages( true );
704 m_printDialogData
.SetFromPage( 0 );
705 m_printDialogData
.SetToPage( 9999 );
712 //----------------------------------------------------------------------------
713 // wxGtkPageSetupDialog
714 //----------------------------------------------------------------------------
716 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
718 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
719 wxPageSetupDialogData
* data
)
722 m_pageDialogData
= *data
;
727 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
731 int wxGtkPageSetupDialog::ShowModal()
734 m_pageDialogData
.GetPrintData().ConvertToNative();
735 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
736 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
738 // We only need the pagesetup data which are part of the settings.
739 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
741 // If the user used a custom paper format the last time he printed, we have to restore it too.
742 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
744 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
745 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
747 wxString title
= _("Custom size");
748 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
749 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
750 g_object_unref(customSize
);
754 // Now show the dialog.
755 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
760 if (newPageSetup
!= oldPageSetup
)
762 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
763 m_pageDialogData
.GetPrintData().ConvertFromNative();
765 // Store custom paper format if any.
766 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
768 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
769 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
770 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
771 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
772 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
774 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
775 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
777 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
778 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
780 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
793 //----------------------------------------------------------------------------
795 //----------------------------------------------------------------------------
797 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
799 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
800 wxPrinterBase( data
)
805 m_printDialogData
= *data
;
808 wxGtkPrinter::~wxGtkPrinter()
812 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
816 sm_lastError
= wxPRINTER_ERROR
;
820 // Let's correct the PageInfo just in case the app gives wrong values.
821 int fromPage
, toPage
;
822 int minPage
, maxPage
;
823 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
824 m_printDialogData
.SetAllPages(true);
826 if (minPage
< 1) minPage
= 1;
827 if (maxPage
< 1) maxPage
= 9999;
828 if (maxPage
< minPage
) maxPage
= minPage
;
830 m_printDialogData
.SetMinPage(minPage
);
831 m_printDialogData
.SetMaxPage(maxPage
);
834 if (fromPage
< minPage
) fromPage
= minPage
;
835 else if (fromPage
> maxPage
) fromPage
= maxPage
;
836 m_printDialogData
.SetFromPage(fromPage
);
840 m_printDialogData
.SetToPage(toPage
);
841 if (toPage
> maxPage
) toPage
= maxPage
;
842 else if (toPage
< minPage
) toPage
= minPage
;
845 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
848 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
849 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
851 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
853 native
->SetPrintJob( printOp
);
855 printout
->SetIsPreview(false);
857 wxPrinterToGtkData dataToSend
;
858 dataToSend
.printer
= this;
859 dataToSend
.printout
= printout
;
861 // These Gtk signals are caught here.
862 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
863 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
864 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
865 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
867 // This is used to setup the DC and
868 // show the dialog if desired
869 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
870 dialog
.SetPrintDC(m_dc
);
871 dialog
.SetShowDialog(prompt
);
873 // doesn't necessarily show
874 int ret
= dialog
.ShowModal();
875 if (ret
== wxID_CANCEL
)
877 sm_lastError
= wxPRINTER_CANCELLED
;
881 sm_lastError
= wxPRINTER_ERROR
;
882 wxFAIL_MSG(_("The print dialog returned an error."));
885 g_object_unref (printOp
);
887 return (sm_lastError
== wxPRINTER_NO_ERROR
);
890 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
892 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
893 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
895 SetPrintContext(context
);
896 native
->SetPrintContext( context
);
898 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
903 if (sm_lastError
!= wxPRINTER_CANCELLED
)
905 sm_lastError
= wxPRINTER_ERROR
;
906 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
910 wxSize ScreenPixels
= wxGetDisplaySize();
911 wxSize ScreenMM
= wxGetDisplaySizeMM();
913 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
914 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
915 printout
->SetPPIPrinter( printDC
->GetResolution(),
916 printDC
->GetResolution() );
918 printout
->SetDC(m_dc
);
921 m_dc
->GetSize(&w
, &h
);
922 printout
->SetPageSizePixels((int)w
, (int)h
);
923 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
925 m_dc
->GetSizeMM(&mw
, &mh
);
926 printout
->SetPageSizeMM((int)mw
, (int)mh
);
927 printout
->OnPreparePrinting();
929 // Get some parameters from the printout, if defined.
930 int fromPage
, toPage
;
931 int minPage
, maxPage
;
932 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
936 sm_lastError
= wxPRINTER_ERROR
;
937 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
941 printout
->OnBeginPrinting();
945 // If we're not previewing we need to calculate the number of pages to print.
946 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
947 // have defined in the dialog. So the number of pages is the maximum available.
948 if (!printout
->IsPreview())
950 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
951 switch (gtk_print_settings_get_print_pages(settings
))
953 case GTK_PRINT_PAGES_CURRENT
:
956 case GTK_PRINT_PAGES_RANGES
:
957 {gint num_ranges
= 0;
960 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
961 for (i
=0; i
<num_ranges
; i
++)
963 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
964 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
965 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
966 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
967 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
969 gtk_print_settings_set_page_ranges (settings
, range
, 1);
971 case GTK_PRINT_PAGES_ALL
:
973 numPages
= maxPage
- minPage
+ 1;
977 else numPages
= maxPage
- minPage
+ 1;
979 gtk_print_operation_set_n_pages(operation
, numPages
);
982 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
983 GtkPrintOperation
*operation
,
984 GtkPrintContext
* WXUNUSED(context
),
987 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
988 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
990 int numPageToDraw
= page_nr
+ minPage
;
991 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
992 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
994 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
995 switch (gtk_print_settings_get_print_pages(settings
))
997 case GTK_PRINT_PAGES_CURRENT
:
998 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
999 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1001 case GTK_PRINT_PAGES_RANGES
:
1002 {gint num_ranges
= 0;
1003 GtkPageRange
* range
;
1004 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1005 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1006 if (num_ranges
>= 1)
1008 startPage
= range
[0].start
+ 1;
1009 endPage
= range
[0].end
+ 1;
1012 startPage
= minPage
;
1016 case GTK_PRINT_PAGES_ALL
:
1018 startPage
= minPage
;
1023 if(numPageToDraw
== startPage
)
1025 if (!printout
->OnBeginDocument(startPage
, endPage
))
1027 wxLogError(_("Could not start printing."));
1028 sm_lastError
= wxPRINTER_ERROR
;
1032 // The app can render the page numPageToDraw.
1033 if (printout
->HasPage(numPageToDraw
))
1036 printout
->OnPrintPage(numPageToDraw
);
1041 if(numPageToDraw
== endPage
)
1043 printout
->OnEndDocument();
1047 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1049 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1051 dialog
.SetPrintDC(m_dc
);
1052 dialog
.SetShowDialog(true);
1054 int ret
= dialog
.ShowModal();
1056 if (ret
== wxID_CANCEL
)
1058 sm_lastError
= wxPRINTER_CANCELLED
;
1063 sm_lastError
= wxPRINTER_ERROR
;
1064 wxFAIL_MSG(_("The print dialog returned an error."));
1068 m_printDialogData
= dialog
.GetPrintDialogData();
1070 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1073 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1075 // Obsolete, for backward compatibility.
1079 //-----------------------------------------------------------------------------
1081 //-----------------------------------------------------------------------------
1083 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1084 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1085 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1086 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1089 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1091 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
) :
1096 wxGtkPrintNativeData
*native
=
1097 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1099 m_gpc
= native
->GetPrintContext();
1101 // Match print quality to resolution (high = 1200dpi)
1102 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1103 if (m_resolution
< 0)
1104 m_resolution
= (1 << (m_resolution
+4)) *150;
1106 m_PS2DEV
= (double)m_resolution
/ 72.0;
1107 m_DEV2PS
= 72.0 / (double)m_resolution
;
1109 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1110 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1111 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1113 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1119 m_signX
= 1; // default x-axis left to right.
1120 m_signY
= 1; // default y-axis bottom up -> top down.
1122 // By default the origin of the Cairo context is in the upper left
1123 // corner of the printable area. We need to translate it so that it
1124 // is in the upper left corner of the paper (without margins)
1125 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1127 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1128 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1129 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1132 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1134 g_object_unref(m_context
);
1135 g_object_unref(m_layout
);
1138 bool wxGtkPrinterDCImpl::IsOk() const
1140 return m_gpc
!= NULL
;
1143 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1144 wxCoord
WXUNUSED(y1
),
1145 const wxColour
& WXUNUSED(col
),
1146 int WXUNUSED(style
))
1148 // We can't access the given coord as a Cairo context is scalable, ie a
1149 // coord doesn't mean anything in this context.
1150 wxFAIL_MSG(_("not implemented"));
1154 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1156 wxCoord xC
= circleCenter
.x
;
1157 wxCoord yC
= circleCenter
.y
;
1158 wxCoord xR
= rect
.x
;
1159 wxCoord yR
= rect
.y
;
1160 wxCoord w
= rect
.width
;
1161 wxCoord h
= rect
.height
;
1163 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1165 unsigned char redI
= initialColour
.Red();
1166 unsigned char blueI
= initialColour
.Blue();
1167 unsigned char greenI
= initialColour
.Green();
1168 unsigned char alphaI
= initialColour
.Alpha();
1169 unsigned char redD
= destColour
.Red();
1170 unsigned char blueD
= destColour
.Blue();
1171 unsigned char greenD
= destColour
.Green();
1172 unsigned char alphaD
= destColour
.Alpha();
1174 double redIPS
= (double)(redI
) / 255.0;
1175 double blueIPS
= (double)(blueI
) / 255.0;
1176 double greenIPS
= (double)(greenI
) / 255.0;
1177 double alphaIPS
= (double)(alphaI
) / 255.0;
1178 double redDPS
= (double)(redD
) / 255.0;
1179 double blueDPS
= (double)(blueD
) / 255.0;
1180 double greenDPS
= (double)(greenD
) / 255.0;
1181 double alphaDPS
= (double)(alphaD
) / 255.0;
1183 // Create a pattern with the gradient.
1184 cairo_pattern_t
* gradient
;
1185 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1186 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1187 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1189 // Fill the rectangle with this pattern.
1190 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1191 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1192 gs_cairo
->cairo_fill(m_cairo
);
1194 gs_cairo
->cairo_pattern_destroy(gradient
);
1196 CalcBoundingBox(xR
, yR
);
1197 CalcBoundingBox(xR
+w
, yR
+h
);
1200 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1204 wxCoord w
= rect
.width
;
1205 wxCoord h
= rect
.height
;
1207 unsigned char redI
= initialColour
.Red();
1208 unsigned char blueI
= initialColour
.Blue();
1209 unsigned char greenI
= initialColour
.Green();
1210 unsigned char alphaI
= initialColour
.Alpha();
1211 unsigned char redD
= destColour
.Red();
1212 unsigned char blueD
= destColour
.Blue();
1213 unsigned char greenD
= destColour
.Green();
1214 unsigned char alphaD
= destColour
.Alpha();
1216 double redIPS
= (double)(redI
) / 255.0;
1217 double blueIPS
= (double)(blueI
) / 255.0;
1218 double greenIPS
= (double)(greenI
) / 255.0;
1219 double alphaIPS
= (double)(alphaI
) / 255.0;
1220 double redDPS
= (double)(redD
) / 255.0;
1221 double blueDPS
= (double)(blueD
) / 255.0;
1222 double greenDPS
= (double)(greenD
) / 255.0;
1223 double alphaDPS
= (double)(alphaD
) / 255.0;
1225 // Create a pattern with the gradient.
1226 cairo_pattern_t
* gradient
;
1227 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1229 if (nDirection
== wxWEST
)
1231 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1232 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1235 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1236 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1239 // Fill the rectangle with this pattern.
1240 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1241 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1242 gs_cairo
->cairo_fill(m_cairo
);
1244 gs_cairo
->cairo_pattern_destroy(gradient
);
1246 CalcBoundingBox(x
, y
);
1247 CalcBoundingBox(x
+w
, y
+h
);
1250 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1251 wxCoord
WXUNUSED(y1
),
1252 wxColour
* WXUNUSED(col
)) const
1254 wxFAIL_MSG(_("not implemented"));
1258 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1260 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1263 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1264 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1265 gs_cairo
->cairo_stroke ( m_cairo
);
1267 CalcBoundingBox( x1
, y1
);
1268 CalcBoundingBox( x2
, y2
);
1271 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1278 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1279 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1280 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1281 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1283 gs_cairo
->cairo_stroke (m_cairo
);
1284 CalcBoundingBox( 0, 0 );
1285 CalcBoundingBox( w
, h
);
1288 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1290 double dx
= x1
- xc
;
1291 double dy
= y1
- yc
;
1292 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1294 double alpha1
, alpha2
;
1295 if (x1
== x2
&& y1
== y2
)
1303 alpha1
= alpha2
= 0.0;
1307 alpha1
= (x1
- xc
== 0) ?
1308 (y1
- yc
< 0) ? 90.0 : -90.0 :
1309 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1310 alpha2
= (x2
- xc
== 0) ?
1311 (y2
- yc
< 0) ? 90.0 : -90.0 :
1312 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1314 while (alpha1
<= 0) alpha1
+= 360;
1315 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1316 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1317 while (alpha2
> 360) alpha2
-= 360;
1323 gs_cairo
->cairo_new_path(m_cairo
);
1325 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1326 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1327 gs_cairo
->cairo_close_path (m_cairo
);
1329 SetBrush( m_brush
);
1330 gs_cairo
->cairo_fill_preserve( m_cairo
);
1333 gs_cairo
->cairo_stroke( m_cairo
);
1335 CalcBoundingBox (x1
, y1
);
1336 CalcBoundingBox (xc
, yc
);
1337 CalcBoundingBox (x2
, y2
);
1340 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1342 gs_cairo
->cairo_save( m_cairo
);
1344 gs_cairo
->cairo_new_path(m_cairo
);
1346 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1347 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1348 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1350 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1353 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1355 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1357 SetBrush( m_brush
);
1358 gs_cairo
->cairo_fill( m_cairo
);
1360 gs_cairo
->cairo_restore( m_cairo
);
1362 CalcBoundingBox( x
, y
);
1363 CalcBoundingBox( x
+w
, y
+h
);
1366 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1368 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1372 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1373 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1374 gs_cairo
->cairo_stroke ( m_cairo
);
1376 CalcBoundingBox( x
, y
);
1379 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1381 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1388 for ( i
=0; i
<n
; i
++ )
1389 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1391 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1393 for (i
= 1; i
< n
; i
++)
1394 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1396 gs_cairo
->cairo_stroke ( m_cairo
);
1399 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1403 gs_cairo
->cairo_save(m_cairo
);
1404 if (fillStyle
== wxWINDING_RULE
)
1405 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1407 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1409 int x
= points
[0].x
+ xoffset
;
1410 int y
= points
[0].y
+ yoffset
;
1411 gs_cairo
->cairo_new_path(m_cairo
);
1412 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1414 for (i
= 1; i
< n
; i
++)
1416 int x
= points
[i
].x
+ xoffset
;
1417 int y
= points
[i
].y
+ yoffset
;
1418 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1420 gs_cairo
->cairo_close_path(m_cairo
);
1422 SetBrush( m_brush
);
1423 gs_cairo
->cairo_fill_preserve( m_cairo
);
1426 gs_cairo
->cairo_stroke( m_cairo
);
1428 CalcBoundingBox( x
, y
);
1430 gs_cairo
->cairo_restore(m_cairo
);
1433 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1435 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1438 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1443 gs_cairo
->cairo_new_path(m_cairo
);
1444 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1446 SetBrush( m_brush
);
1447 gs_cairo
->cairo_fill_preserve( m_cairo
);
1450 gs_cairo
->cairo_stroke( m_cairo
);
1452 CalcBoundingBox( x
, y
);
1453 CalcBoundingBox( x
+ width
, y
+ height
);
1456 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1461 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1463 wxCoord dd
= 2 * (wxCoord
) radius
;
1464 if (dd
> width
) dd
= width
;
1465 if (dd
> height
) dd
= height
;
1468 wxCoord rad
= (wxCoord
) radius
;
1470 gs_cairo
->cairo_new_path(m_cairo
);
1471 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1472 gs_cairo
->cairo_curve_to(m_cairo
,
1473 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1474 XLOG2DEV(x
),YLOG2DEV(y
),
1475 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1476 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1477 gs_cairo
->cairo_curve_to(m_cairo
,
1478 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1479 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1480 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1481 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1482 gs_cairo
->cairo_curve_to(m_cairo
,
1483 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1484 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1485 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1486 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1487 gs_cairo
->cairo_curve_to(m_cairo
,
1488 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1489 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1490 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1491 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1492 gs_cairo
->cairo_close_path(m_cairo
);
1495 gs_cairo
->cairo_fill_preserve(m_cairo
);
1498 gs_cairo
->cairo_stroke(m_cairo
);
1500 CalcBoundingBox(x
,y
);
1501 CalcBoundingBox(x
+width
,y
+height
);
1504 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1509 gs_cairo
->cairo_save (m_cairo
);
1511 gs_cairo
->cairo_new_path(m_cairo
);
1513 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1514 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1515 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1517 SetBrush( m_brush
);
1518 gs_cairo
->cairo_fill_preserve( m_cairo
);
1521 gs_cairo
->cairo_stroke( m_cairo
);
1523 CalcBoundingBox( x
, y
);
1524 CalcBoundingBox( x
+ width
, y
+ height
);
1526 gs_cairo
->cairo_restore (m_cairo
);
1530 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1534 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1537 wxPointList::compatibility_iterator node
= points
->GetFirst();
1538 p
= node
->GetData();
1542 node
= node
->GetNext();
1543 p
= node
->GetData();
1547 (double)(x1
+ c
) / 2;
1549 (double)(y1
+ d
) / 2;
1551 gs_cairo
->cairo_new_path( m_cairo
);
1552 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1553 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1555 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1556 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1558 node
= node
->GetNext();
1561 q
= node
->GetData();
1569 x3
= (double)(x2
+ c
) / 2;
1570 y3
= (double)(y2
+ d
) / 2;
1572 gs_cairo
->cairo_curve_to(m_cairo
,
1573 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1574 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1575 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1577 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1578 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1580 node
= node
->GetNext();
1583 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1585 gs_cairo
->cairo_stroke( m_cairo
);
1587 #endif // wxUSE_SPLINES
1589 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1590 wxCoord width
, wxCoord height
,
1591 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1592 int rop
, bool useMask
,
1593 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1594 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1596 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1597 wxT("mask coordinates are not supported") );
1599 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1601 // Blit into a bitmap.
1602 wxBitmap
bitmap( width
, height
);
1604 memDC
.SelectObject(bitmap
);
1605 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1606 memDC
.SelectObject(wxNullBitmap
);
1608 // Draw bitmap. scaling and positioning is done there.
1609 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1614 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1616 DoDrawBitmap( icon
, x
, y
, true );
1619 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1621 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1623 cairo_surface_t
* surface
;
1624 x
= wxCoord(XLOG2DEV(x
));
1625 y
= wxCoord(YLOG2DEV(y
));
1626 int bw
= bitmap
.GetWidth();
1627 int bh
= bitmap
.GetHeight();
1628 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1629 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1630 wxUint32
* data
= (wxUint32
*)buffer
;
1632 wxMask
*mask
= NULL
;
1633 if (useMask
) mask
= bmpSource
.GetMask();
1635 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1636 // then we'll use a different format and iterator than if it doesn't.
1637 if (bmpSource
.HasAlpha() || mask
)
1639 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1640 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1641 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1642 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1644 wxAlphaPixelData::Iterator
p(pixData
);
1646 for (y
=0; y
<bh
; y
++)
1648 wxAlphaPixelData::Iterator rowStart
= p
;
1649 for (x
=0; x
<bw
; x
++)
1651 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1652 // with alpha in the upper 8 bits, then red, then green, then
1653 // blue. The 32-bit quantities are stored native-endian.
1654 // Pre-multiplied alpha is used.
1655 unsigned char alpha
= p
.Alpha();
1657 if (!bmpSource
.HasAlpha() && mask
)
1663 *data
= ( alpha
<< 24
1664 | (p
.Red() * alpha
/255) << 16
1665 | (p
.Green() * alpha
/255) << 8
1666 | (p
.Blue() * alpha
/255) );
1671 p
.OffsetY(pixData
, 1);
1676 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1677 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1678 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1679 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1681 wxNativePixelData::Iterator
p(pixData
);
1683 for (y
=0; y
<bh
; y
++)
1685 wxNativePixelData::Iterator rowStart
= p
;
1686 for (x
=0; x
<bw
; x
++)
1688 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1689 // the upper 8 bits unused. Red, Green, and Blue are stored in
1690 // the remaining 24 bits in that order. The 32-bit quantities
1691 // are stored native-endian.
1692 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1697 p
.OffsetY(pixData
, 1);
1702 gs_cairo
->cairo_save(m_cairo
);
1704 // Prepare to draw the image.
1705 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1708 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1709 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1710 cairo_pattern_set_filter(pattern
,filter
);
1711 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1712 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1713 cairo_scale(m_cairo
, scaleX
, scaleY
);
1715 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1716 // Use the original size here since the context is scaled already.
1717 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1718 // Fill the rectangle using the pattern.
1719 gs_cairo
->cairo_fill(m_cairo
);
1722 gs_cairo
->cairo_pattern_destroy(pattern
);
1723 gs_cairo
->cairo_surface_destroy(surface
);
1726 CalcBoundingBox(0,0);
1727 CalcBoundingBox(bw
,bh
);
1729 gs_cairo
->cairo_restore(m_cairo
);
1732 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1734 DoDrawRotatedText( text
, x
, y
, 0.0 );
1737 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1739 double xx
= XLOG2DEV(x
);
1740 double yy
= YLOG2DEV(y
);
1744 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1746 const wxUTF8Buf data
= text
.utf8_str();
1748 size_t datalen
= strlen(data
);
1749 pango_layout_set_text( m_layout
, data
, datalen
);
1753 PangoAttrList
*attrs
= pango_attr_list_new();
1754 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1756 a
->end_index
= datalen
;
1757 pango_attr_list_insert(attrs
, a
);
1758 pango_layout_set_attributes(m_layout
, attrs
);
1759 pango_attr_list_unref(attrs
);
1762 if (m_textForegroundColour
.Ok())
1764 unsigned char red
= m_textForegroundColour
.Red();
1765 unsigned char blue
= m_textForegroundColour
.Blue();
1766 unsigned char green
= m_textForegroundColour
.Green();
1767 unsigned char alpha
= m_textForegroundColour
.Alpha();
1769 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1771 double redPS
= (double)(red
) / 255.0;
1772 double bluePS
= (double)(blue
) / 255.0;
1773 double greenPS
= (double)(green
) / 255.0;
1774 double alphaPS
= (double)(alpha
) / 255.0;
1776 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1779 m_currentBlue
= blue
;
1780 m_currentGreen
= green
;
1781 m_currentAlpha
= alpha
;
1787 // Scale font description.
1788 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1789 double size
= oldSize
;
1790 size
= size
* m_scaleX
;
1791 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1793 // Actually apply scaled font.
1794 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1796 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1798 if ( m_backgroundMode
== wxSOLID
)
1800 unsigned char red
= m_textBackgroundColour
.Red();
1801 unsigned char blue
= m_textBackgroundColour
.Blue();
1802 unsigned char green
= m_textBackgroundColour
.Green();
1803 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1805 double redPS
= (double)(red
) / 255.0;
1806 double bluePS
= (double)(blue
) / 255.0;
1807 double greenPS
= (double)(green
) / 255.0;
1808 double alphaPS
= (double)(alpha
) / 255.0;
1810 gs_cairo
->cairo_save(m_cairo
);
1811 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1812 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1813 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1814 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1815 gs_cairo
->cairo_fill(m_cairo
);
1816 gs_cairo
->cairo_restore(m_cairo
);
1820 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1822 gs_cairo
->cairo_save( m_cairo
);
1824 if (fabs(angle
) > 0.00001)
1825 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1827 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1828 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1830 gs_cairo
->cairo_restore( m_cairo
);
1834 // Undo underline attributes setting
1835 pango_layout_set_attributes(m_layout
, NULL
);
1838 // Reset unscaled size.
1839 pango_font_description_set_size( m_fontdesc
, oldSize
);
1841 // Actually apply unscaled font.
1842 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1844 // Back to device units:
1845 CalcBoundingBox (x
, y
);
1846 CalcBoundingBox (x
+ w
, y
+ h
);
1849 void wxGtkPrinterDCImpl::Clear()
1851 // Clear does nothing for printing, but keep the code
1854 gs_cairo->cairo_save(m_cairo);
1855 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1856 SetBrush(m_backgroundBrush);
1857 gs_cairo->cairo_paint(m_cairo);
1858 gs_cairo->cairo_restore(m_cairo);
1862 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1869 pango_font_description_free( m_fontdesc
);
1871 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1873 // Scale font description from device units to pango units
1874 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1875 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1876 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1878 // Actually apply scaled font.
1879 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1883 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1885 if (!pen
.Ok()) return;
1891 if (m_pen
.GetWidth() <= 0)
1894 width
= (double) m_pen
.GetWidth();
1896 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1897 static const double dotted
[] = {2.0, 5.0};
1898 static const double short_dashed
[] = {4.0, 4.0};
1899 static const double long_dashed
[] = {4.0, 8.0};
1900 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1902 switch (m_pen
.GetStyle())
1904 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1905 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1906 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1907 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1911 int num
= m_pen
.GetDashes (&wx_dashes
);
1912 gdouble
*g_dashes
= g_new( gdouble
, num
);
1914 for (i
= 0; i
< num
; ++i
)
1915 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1916 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1922 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1925 switch (m_pen
.GetCap())
1927 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1928 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1930 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1933 switch (m_pen
.GetJoin())
1935 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1936 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1938 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1941 unsigned char red
= m_pen
.GetColour().Red();
1942 unsigned char blue
= m_pen
.GetColour().Blue();
1943 unsigned char green
= m_pen
.GetColour().Green();
1944 unsigned char alpha
= m_pen
.GetColour().Alpha();
1946 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1948 double redPS
= (double)(red
) / 255.0;
1949 double bluePS
= (double)(blue
) / 255.0;
1950 double greenPS
= (double)(green
) / 255.0;
1951 double alphaPS
= (double)(alpha
) / 255.0;
1953 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1956 m_currentBlue
= blue
;
1957 m_currentGreen
= green
;
1958 m_currentAlpha
= alpha
;
1962 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1964 if (!brush
.Ok()) return;
1968 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1970 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1979 unsigned char red
= m_brush
.GetColour().Red();
1980 unsigned char blue
= m_brush
.GetColour().Blue();
1981 unsigned char green
= m_brush
.GetColour().Green();
1982 unsigned char alpha
= m_brush
.GetColour().Alpha();
1984 double redPS
= (double)(red
) / 255.0;
1985 double bluePS
= (double)(blue
) / 255.0;
1986 double greenPS
= (double)(green
) / 255.0;
1987 double alphaPS
= (double)(alpha
) / 255.0;
1989 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1991 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1994 m_currentBlue
= blue
;
1995 m_currentGreen
= green
;
1996 m_currentAlpha
= alpha
;
1999 if (m_brush
.IsHatch())
2002 cairo_surface_t
*surface
;
2003 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2004 cr
= gs_cairo
->cairo_create(surface
);
2005 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2006 gs_cairo
->cairo_set_line_width(cr
, 1);
2007 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2009 switch (m_brush
.GetStyle())
2012 gs_cairo
->cairo_move_to(cr
, 5, 0);
2013 gs_cairo
->cairo_line_to(cr
, 5, 10);
2014 gs_cairo
->cairo_move_to(cr
, 0, 5);
2015 gs_cairo
->cairo_line_to(cr
, 10, 5);
2017 case wxBDIAGONAL_HATCH
:
2018 gs_cairo
->cairo_move_to(cr
, 0, 10);
2019 gs_cairo
->cairo_line_to(cr
, 10, 0);
2021 case wxFDIAGONAL_HATCH
:
2022 gs_cairo
->cairo_move_to(cr
, 0, 0);
2023 gs_cairo
->cairo_line_to(cr
, 10, 10);
2025 case wxCROSSDIAG_HATCH
:
2026 gs_cairo
->cairo_move_to(cr
, 0, 0);
2027 gs_cairo
->cairo_line_to(cr
, 10, 10);
2028 gs_cairo
->cairo_move_to(cr
, 10, 0);
2029 gs_cairo
->cairo_line_to(cr
, 0, 10);
2031 case wxHORIZONTAL_HATCH
:
2032 gs_cairo
->cairo_move_to(cr
, 0, 5);
2033 gs_cairo
->cairo_line_to(cr
, 10, 5);
2035 case wxVERTICAL_HATCH
:
2036 gs_cairo
->cairo_move_to(cr
, 5, 0);
2037 gs_cairo
->cairo_line_to(cr
, 5, 10);
2040 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2043 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2044 gs_cairo
->cairo_stroke (cr
);
2046 gs_cairo
->cairo_destroy(cr
);
2047 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2048 gs_cairo
->cairo_surface_destroy(surface
);
2049 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2050 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2051 gs_cairo
->cairo_pattern_destroy(pattern
);
2055 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
2057 if (function
== wxCLEAR
)
2058 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2059 else if (function
== wxOR
)
2060 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2061 else if (function
== wxNO_OP
)
2062 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2063 else if (function
== wxAND
)
2064 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2065 else if (function
== wxSET
)
2066 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2067 else if (function
== wxXOR
)
2068 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2069 else // wxCOPY or anything else.
2070 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2073 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2075 m_backgroundBrush
= brush
;
2076 gs_cairo
->cairo_save(m_cairo
);
2077 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2079 SetBrush(m_backgroundBrush
);
2080 gs_cairo
->cairo_paint(m_cairo
);
2081 gs_cairo
->cairo_restore(m_cairo
);
2084 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2086 if (mode
== wxSOLID
)
2087 m_backgroundMode
= wxSOLID
;
2089 m_backgroundMode
= wxTRANSPARENT
;
2092 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2094 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2095 gs_cairo
->cairo_clip(m_cairo
);
2098 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2100 gs_cairo
->cairo_reset_clip(m_cairo
);
2103 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2108 void wxGtkPrinterDCImpl::EndDoc()
2113 void wxGtkPrinterDCImpl::StartPage()
2118 void wxGtkPrinterDCImpl::EndPage()
2123 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2125 pango_layout_set_text( m_layout
, "H", 1 );
2128 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2130 return wxRound( h
* m_PS2DEV
);
2133 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2135 pango_layout_set_text( m_layout
, "H", 1 );
2138 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2140 return wxRound( w
* m_PS2DEV
);
2143 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2145 wxCoord
*externalLeading
,
2146 const wxFont
*theFont
) const
2154 if ( externalLeading
)
2155 *externalLeading
= 0;
2162 // Set layout's text
2163 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2165 PangoFontDescription
*desc
= m_fontdesc
;
2166 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2168 gint oldSize
= pango_font_description_get_size( desc
);
2169 double size
= oldSize
;
2170 size
= size
* m_scaleY
;
2171 pango_font_description_set_size( desc
, (gint
)size
);
2173 // apply scaled font
2174 pango_layout_set_font_description( m_layout
, desc
);
2176 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2179 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2182 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2184 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2188 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2189 int baseline
= pango_layout_iter_get_baseline(iter
);
2190 pango_layout_iter_free(iter
);
2191 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2194 // Reset unscaled size.
2195 pango_font_description_set_size( desc
, oldSize
);
2197 // Reset unscaled font.
2198 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2201 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2203 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2206 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2208 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2211 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2213 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2216 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2218 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2221 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2223 return wxSize( (int)m_resolution
, (int)m_resolution
);
2226 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2231 // overriden for wxPrinterDC Impl
2233 wxRect
wxGtkPrinterDCImpl::GetPaperRect()
2235 // Does GtkPrint support printer margins?
2238 DoGetSize( &w
, &h
);
2239 return wxRect( 0,0,w
,h
);
2242 int wxGtkPrinterDCImpl::GetResolution()
2244 return m_resolution
;
2247 // ----------------------------------------------------------------------------
2249 // ----------------------------------------------------------------------------
2251 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2253 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2254 wxPrintout
* WXUNUSED(printoutForPrinting
))
2259 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2260 wxPrintout
*printoutForPrinting
,
2261 wxPrintDialogData
*data
)
2262 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2264 Init(printout
, printoutForPrinting
);
2267 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2268 wxPrintout
*printoutForPrinting
,
2270 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2272 Init(printout
, printoutForPrinting
);
2275 wxGtkPrintPreview::~wxGtkPrintPreview()
2279 bool wxGtkPrintPreview::Print(bool interactive
)
2281 if (!m_printPrintout
)
2284 wxPrinter
printer(& m_printDialogData
);
2285 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2288 void wxGtkPrintPreview::DetermineScaling()
2290 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2292 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2294 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2298 wxSize ScreenPixels
= wxGetDisplaySize();
2299 wxSize ScreenMM
= wxGetDisplaySizeMM();
2301 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2302 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2304 // TODO !!!!!!!!!!!!!!!
2305 int resolution
= 600;
2306 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2308 // Get width and height in points (1/72th of an inch)
2309 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2311 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)resolution
/ 72.0);
2312 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)resolution
/ 72.0);
2313 wxSize
sizeTenthsMM(paper
->GetSize());
2314 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2316 // If in landscape mode, we need to swap the width and height.
2317 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2319 m_pageWidth
= sizeDevUnits
.y
;
2320 m_pageHeight
= sizeDevUnits
.x
;
2321 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2325 m_pageWidth
= sizeDevUnits
.x
;
2326 m_pageHeight
= sizeDevUnits
.y
;
2327 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2329 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2330 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2332 // At 100%, the page should look about page-size on the screen.
2333 m_previewScaleX
= 0.8 * 72.0 / (double)resolution
;
2334 m_previewScaleY
= m_previewScaleX
;