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"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
35 #include "wx/rawbmp.h"
38 #include <gtk/gtkpagesetupunixdialog.h>
41 wxFORCE_LINK_THIS_MODULE(gtk_print
)
43 #if wxUSE_LIBGNOMEPRINT
44 #include "wx/gtk/gnome/gprint.h"
47 // Usefull to convert angles from/to Rad to/from Deg.
48 static const double RAD2DEG
= 180.0 / M_PI
;
49 static const double DEG2RAD
= M_PI
/ 180.0;
51 static wxCairoLibrary
* gs_cairo
= NULL
;
53 //----------------------------------------------------------------------------
55 // Initialized when starting the app : if it successfully load the gtk-print framework,
56 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
57 // to postscript if gnomeprint is not available.
58 //----------------------------------------------------------------------------
60 class wxGtkPrintModule
: public wxModule
65 #if wxUSE_LIBGNOMEPRINT
66 // This module must be initialized AFTER gnomeprint's one
67 AddDependency(CLASSINFO(wxGnomePrintModule
));
74 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
77 bool wxGtkPrintModule::OnInit()
79 gs_cairo
= wxCairoLibrary::Get();
80 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
81 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
86 void wxGtkPrintModule::OnExit()
91 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
93 //----------------------------------------------------------------------------
95 //----------------------------------------------------------------------------
97 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
99 return new wxGtkPrinter( data
);
102 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
103 wxPrintout
*printout
,
104 wxPrintDialogData
*data
)
106 return new wxGtkPrintPreview( preview
, printout
, data
);
109 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
110 wxPrintout
*printout
,
113 return new wxGtkPrintPreview( preview
, printout
, data
);
116 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
117 wxPrintDialogData
*data
)
119 return new wxGtkPrintDialog( parent
, data
);
122 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
125 return new wxGtkPrintDialog( parent
, data
);
128 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
129 wxPageSetupDialogData
* data
)
131 return new wxGtkPageSetupDialog( parent
, data
);
134 bool wxGtkPrintFactory::HasPrintSetupDialog()
139 wxDialog
*wxGtkPrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
144 wxDC
* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData
& data
)
146 return new wxGtkPrintDC(data
);
149 bool wxGtkPrintFactory::HasOwnPrintToFile()
154 bool wxGtkPrintFactory::HasPrinterLine()
159 wxString
wxGtkPrintFactory::CreatePrinterLine()
162 return wxEmptyString
;
165 bool wxGtkPrintFactory::HasStatusLine()
171 wxString
wxGtkPrintFactory::CreateStatusLine()
174 return wxEmptyString
;
177 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
179 return new wxGtkPrintNativeData
;
182 //----------------------------------------------------------------------------
183 // Callback functions for Gtk Printings.
184 //----------------------------------------------------------------------------
186 // We use it to pass useful objets to gtk printing callback functions.
189 wxGtkPrinter
* printer
;
190 wxPrintout
* printout
;
196 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
198 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
200 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
203 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
205 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
207 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
210 static void gtk_end_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
212 wxPrintout
*printout
= (wxPrintout
*) user_data
;
214 printout
->OnEndPrinting();
217 static gboolean
gtk_preview_print_callback (GtkPrintOperation
*operation
, GtkPrintOperationPreview
*preview
, GtkPrintContext
*context
, GtkWindow
*parent
, gpointer user_data
)
219 wxPrintout
*printout
= (wxPrintout
*) user_data
;
221 printout
->SetIsPreview(true);
223 /* We create a cairo context with 72dpi resolution. This resolution is only used for positionning. */
224 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
225 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
231 //----------------------------------------------------------------------------
232 // wxGtkPrintNativeData
233 //----------------------------------------------------------------------------
235 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
237 wxGtkPrintNativeData::wxGtkPrintNativeData()
239 m_config
= gtk_print_settings_new();
242 wxGtkPrintNativeData::~wxGtkPrintNativeData()
244 g_object_unref (m_config
);
247 // Convert datas stored in m_config to a wxPrintData.
248 // Called by wxPrintData::ConvertFromNative().
249 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
254 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
255 if (quality
== GTK_PRINT_QUALITY_HIGH
)
256 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
257 else if (quality
== GTK_PRINT_QUALITY_LOW
)
258 data
.SetQuality(wxPRINT_QUALITY_LOW
);
259 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
260 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
262 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
264 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
266 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
268 switch (gtk_print_settings_get_duplex(m_config
))
270 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
273 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
277 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
281 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
282 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
284 data
.SetOrientation(wxPORTRAIT
);
285 data
.SetOrientationReversed(false);
287 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
289 data
.SetOrientation(wxLANDSCAPE
);
290 data
.SetOrientationReversed(false);
292 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
294 data
.SetOrientation(wxPORTRAIT
);
295 data
.SetOrientationReversed(true);
297 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
299 data
.SetOrientation(wxLANDSCAPE
);
300 data
.SetOrientationReversed(true);
303 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
305 // Paper formats : these are the most common paper formats.
306 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
308 data
.SetPaperId(wxPAPER_NONE
);
309 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
310 data
.SetPaperId(wxPAPER_A3
);
311 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
312 data
.SetPaperId(wxPAPER_A4
);
313 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
314 data
.SetPaperId(wxPAPER_A5
);
315 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
316 data
.SetPaperId(wxPAPER_B5
);
317 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
318 data
.SetPaperId(wxPAPER_LETTER
);
319 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
320 data
.SetPaperId(wxPAPER_LEGAL
);
321 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
322 data
.SetPaperId(wxPAPER_EXECUTIVE
);
323 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
324 data
.SetPaperId(wxPAPER_ENV_10
);
325 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
326 data
.SetPaperId(wxPAPER_ENV_C5
);
327 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
328 data
.SetPaperId(wxPAPER_ENV_C6
);
329 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
330 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
331 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
332 data
.SetPaperId(wxPAPER_ENV_B5
);
333 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
334 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
335 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
336 data
.SetPaperId( wxPAPER_CSHEET
);
337 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
338 data
.SetPaperId( wxPAPER_DSHEET
);
339 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
340 data
.SetPaperId( wxPAPER_ESHEET
);
341 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
342 data
.SetPaperId( wxPAPER_LETTERSMALL
);
343 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
344 data
.SetPaperId( wxPAPER_TABLOID
);
345 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
346 data
.SetPaperId( wxPAPER_LEDGER
);
347 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
348 data
.SetPaperId( wxPAPER_STATEMENT
);
349 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
350 data
.SetPaperId( wxPAPER_A4SMALL
);
351 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
352 data
.SetPaperId( wxPAPER_B4
);
353 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
354 data
.SetPaperId( wxPAPER_FOLIO
);
355 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
356 data
.SetPaperId( wxPAPER_QUARTO
);
357 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
358 data
.SetPaperId( wxPAPER_10X14
);
359 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
360 data
.SetPaperId( wxPAPER_11X17
);
361 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
362 data
.SetPaperId( wxPAPER_NOTE
);
363 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
364 data
.SetPaperId( wxPAPER_ENV_9
);
365 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
366 data
.SetPaperId( wxPAPER_ENV_11
);
367 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
368 data
.SetPaperId( wxPAPER_ENV_12
);
369 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
370 data
.SetPaperId( wxPAPER_ENV_14
);
371 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
372 data
.SetPaperId( wxPAPER_ENV_DL
);
373 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
374 data
.SetPaperId( wxPAPER_ENV_C3
);
375 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
376 data
.SetPaperId( wxPAPER_ENV_C4
);
377 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
378 data
.SetPaperId( wxPAPER_ENV_C65
);
379 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
380 data
.SetPaperId( wxPAPER_ENV_B4
);
381 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
382 data
.SetPaperId( wxPAPER_ENV_B6
);
383 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
384 data
.SetPaperId( wxPAPER_ENV_ITALY
);
385 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
386 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
387 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
388 data
.SetPaperId( wxPAPER_FANFOLD_US
);
389 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
390 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
391 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
392 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
394 data
.SetPaperId(wxPAPER_NONE
);
398 // Put datas given by the wxPrintData into m_config.
399 // Called by wxPrintData::ConvertToNative().
400 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
405 wxPrintQuality quality
= data
.GetQuality();
406 if (quality
== wxPRINT_QUALITY_HIGH
)
407 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
408 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
409 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
410 else if (quality
== wxPRINT_QUALITY_LOW
)
411 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
412 else if (quality
== wxPRINT_QUALITY_DRAFT
)
413 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
414 else if (quality
> 1)
415 gtk_print_settings_set_resolution (m_config
, quality
);
417 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
419 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
421 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
423 switch (data
.GetDuplex())
425 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
428 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
432 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
436 if (!data
.IsOrientationReversed())
438 if (data
.GetOrientation() == wxLANDSCAPE
)
439 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
441 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
444 if (data
.GetOrientation() == wxLANDSCAPE
)
445 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
447 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
450 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
452 // Paper formats: these are the most common paper formats.
453 switch (data
.GetPaperId())
455 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
457 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
459 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
461 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
463 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
465 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
467 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
469 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
471 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
473 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
475 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
477 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
479 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
481 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
483 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
485 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
487 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
489 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
491 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
493 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
495 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
497 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
499 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
501 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
503 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
505 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
507 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
509 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
511 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
513 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
515 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
517 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
519 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
521 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
523 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
525 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
527 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
529 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
531 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
533 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
535 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
537 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
546 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
549 m_config
= gtk_print_settings_copy(config
);
552 // Extract page setup from settings.
553 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
555 GtkPageSetup
* page_setup
= gtk_page_setup_new();
556 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
558 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
559 if (paper_size
!= NULL
)
560 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
565 // Insert page setup into a given GtkPrintSettings.
566 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
568 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
569 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
572 //----------------------------------------------------------------------------
574 //----------------------------------------------------------------------------
576 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
578 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
579 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
580 wxPoint(0, 0), wxSize(600, 600),
581 wxDEFAULT_DIALOG_STYLE
|
585 m_printDialogData
= *data
;
591 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
592 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
593 wxPoint(0, 0), wxSize(600, 600),
594 wxDEFAULT_DIALOG_STYLE
|
598 m_printDialogData
= *data
;
605 wxGtkPrintDialog::~wxGtkPrintDialog()
609 // This is called even if we actually don't want the dialog to appear.
610 int wxGtkPrintDialog::ShowModal()
612 GtkPrintOperationResult response
;
614 // We need to restore the settings given in the constructor.
615 wxPrintData data
= m_printDialogData
.GetPrintData();
616 wxGtkPrintNativeData
*native
=
617 (wxGtkPrintNativeData
*) data
.GetNativeData();
618 data
.ConvertToNative();
620 GtkPrintSettings
* settings
= native
->GetPrintConfig();
622 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
623 int fromPage
= m_printDialogData
.GetFromPage();
624 int toPage
= m_printDialogData
.GetToPage();
625 if (m_printDialogData
.GetSelection())
626 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
627 else if (m_printDialogData
.GetAllPages())
628 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
630 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
632 range
= g_new (GtkPageRange
, 1);
633 range
[0].start
= fromPage
-1;
634 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
635 gtk_print_settings_set_page_ranges (settings
, range
, 1);
638 // If the settings are OK, we restore it.
639 if (settings
!= NULL
)
640 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
641 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
643 // Show the dialog if needed.
644 GError
* gError
= NULL
;
646 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
648 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, (GtkWindow
*) m_parent
, &gError
);
650 // Does everything went well?
651 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
655 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
657 g_error_free (gError
);
658 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
659 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
662 // Now get the settings and save it.
663 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
664 native
->SetPrintConfig(newSettings
);
665 data
.ConvertFromNative();
667 // Same problem as a few lines before.
668 switch (gtk_print_settings_get_print_pages(newSettings
))
670 case GTK_PRINT_PAGES_CURRENT
:
671 m_printDialogData
.SetSelection( true );
673 case GTK_PRINT_PAGES_ALL
:
674 m_printDialogData
.SetAllPages( true );
675 m_printDialogData
.SetFromPage( 0 );
676 m_printDialogData
.SetToPage( 9999 );
678 case GTK_PRINT_PAGES_RANGES
:
680 // wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
681 // 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
682 // will hit "OK" button. However we can only save 1-3 in the print data.
685 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
686 m_printDialogData
.SetFromPage( range
[0].start
);
687 m_printDialogData
.SetToPage( range
[0].end
);
694 //----------------------------------------------------------------------------
695 // wxGtkPageSetupDialog
696 //----------------------------------------------------------------------------
698 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
700 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
701 wxPageSetupDialogData
* data
)
704 m_pageDialogData
= *data
;
709 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
713 int wxGtkPageSetupDialog::ShowModal()
716 m_pageDialogData
.GetPrintData().ConvertToNative();
717 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
718 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
720 // We only need the pagesetup data which are part of the settings.
721 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
723 // If the user used a custom paper format the last time he printed, we have to restore it too.
724 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
726 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
727 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
729 wxString title
= _("Custom size");
730 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
731 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
732 g_object_unref(customSize
);
736 // Now show the dialog.
737 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
742 if (newPageSetup
!= oldPageSetup
)
744 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
745 m_pageDialogData
.GetPrintData().ConvertFromNative();
747 // Store custom paper format if any.
748 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
750 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
751 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
752 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
753 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
754 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
756 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
757 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
759 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
760 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
762 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
775 //----------------------------------------------------------------------------
777 //----------------------------------------------------------------------------
779 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
781 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
782 wxPrinterBase( data
)
787 m_printDialogData
= *data
;
790 wxGtkPrinter::~wxGtkPrinter()
794 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
798 sm_lastError
= wxPRINTER_ERROR
;
802 // Let's correct the PageInfo just in case the app gives wrong values.
803 int fromPage
, toPage
;
804 int minPage
, maxPage
;
805 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
806 m_printDialogData
.SetAllPages(true);
808 if (minPage
< 1) minPage
= 1;
809 if (maxPage
< 1) maxPage
= 9999;
810 if (maxPage
< minPage
) maxPage
= minPage
;
812 m_printDialogData
.SetMinPage(minPage
);
813 m_printDialogData
.SetMaxPage(maxPage
);
816 if (fromPage
< minPage
) fromPage
= minPage
;
817 else if (fromPage
> maxPage
) fromPage
= maxPage
;
818 m_printDialogData
.SetFromPage(fromPage
);
822 m_printDialogData
.SetToPage(toPage
);
823 if (toPage
> maxPage
) toPage
= maxPage
;
824 else if (toPage
< minPage
) toPage
= minPage
;
827 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
830 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
831 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
833 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
835 native
->SetPrintJob( printOp
);
837 printout
->SetIsPreview(false);
839 wxPrinterToGtkData dataToSend
;
840 dataToSend
.printer
= this;
841 dataToSend
.printout
= printout
;
843 // These Gtk signals are catched here.
844 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
845 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
846 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
847 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
851 m_showDialog
= false;
853 // PrintDialog returns a wxDC but we created it before so we don't need it anymore: we just delete it.
854 wxDC
* uselessdc
= PrintDialog( parent
);
857 g_object_unref (printOp
);
859 return (sm_lastError
== wxPRINTER_NO_ERROR
);
862 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
864 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
865 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
867 SetPrintContext(context
);
868 native
->SetPrintContext( context
);
870 m_dc
= new wxGtkPrintDC( printdata
);
874 if (sm_lastError
!= wxPRINTER_CANCELLED
)
876 sm_lastError
= wxPRINTER_ERROR
;
877 wxFAIL_MSG(_("The wxGtkPrintDC cannot be used."));
881 wxSize ScreenPixels
= wxGetDisplaySize();
882 wxSize ScreenMM
= wxGetDisplaySizeMM();
884 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
885 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
886 printout
->SetPPIPrinter( wxGtkPrintDC::GetResolution(),
887 wxGtkPrintDC::GetResolution() );
889 printout
->SetDC(m_dc
);
892 m_dc
->GetSize(&w
, &h
);
893 printout
->SetPageSizePixels((int)w
, (int)h
);
894 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
896 m_dc
->GetSizeMM(&mw
, &mh
);
897 printout
->SetPageSizeMM((int)mw
, (int)mh
);
898 printout
->OnPreparePrinting();
900 // Get some parameters from the printout, if defined.
901 int fromPage
, toPage
;
902 int minPage
, maxPage
;
903 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
907 sm_lastError
= wxPRINTER_ERROR
;
908 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
912 printout
->OnBeginPrinting();
916 // If we're not previewing we need to calculate the number of pages to print.
917 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
918 // have defined in the dialog. So the number of pages is the maximum available.
919 if (!printout
->IsPreview())
921 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
922 switch (gtk_print_settings_get_print_pages(settings
))
924 case GTK_PRINT_PAGES_CURRENT
:
927 case GTK_PRINT_PAGES_RANGES
:
928 {gint num_ranges
= 0;
931 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
932 for (i
=0; i
<num_ranges
; i
++)
934 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
935 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
936 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
937 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
938 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
940 gtk_print_settings_set_page_ranges (settings
, range
, 1);
942 case GTK_PRINT_PAGES_ALL
:
944 numPages
= maxPage
- minPage
+ 1;
948 else numPages
= maxPage
- minPage
+ 1;
950 gtk_print_operation_set_n_pages(operation
, numPages
);
953 void wxGtkPrinter::DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
)
955 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
956 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
958 int numPageToDraw
= page_nr
+ minPage
;
959 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
960 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
962 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
963 switch (gtk_print_settings_get_print_pages(settings
))
965 case GTK_PRINT_PAGES_CURRENT
:
966 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
967 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
969 case GTK_PRINT_PAGES_RANGES
:
970 {gint num_ranges
= 0;
972 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
973 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
974 startPage
= range
[0].start
+ 1;
975 endPage
= range
[0].end
+ 1;
977 case GTK_PRINT_PAGES_ALL
:
984 if(numPageToDraw
== startPage
)
986 if (!printout
->OnBeginDocument(startPage
, endPage
))
988 wxLogError(_("Could not start printing."));
989 sm_lastError
= wxPRINTER_ERROR
;
993 // The app can render the page numPageToDraw.
994 if (printout
->HasPage(numPageToDraw
))
997 printout
->OnPrintPage(numPageToDraw
);
1002 if(numPageToDraw
== endPage
)
1004 printout
->OnEndDocument();
1008 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1010 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1013 dialog
.SetPrintDC(m_dc
);
1015 dialog
.SetShowDialog(m_showDialog
);
1017 ret
= dialog
.ShowModal();
1019 if (ret
== wxID_CANCEL
)
1021 sm_lastError
= wxPRINTER_CANCELLED
;
1026 sm_lastError
= wxPRINTER_ERROR
;
1027 wxFAIL_MSG(_("The print dialog returned an error."));
1031 m_printDialogData
= dialog
.GetPrintDialogData();
1032 return new wxGtkPrintDC( m_printDialogData
.GetPrintData() );
1035 bool wxGtkPrinter::Setup( wxWindow
*parent
)
1037 // Obsolete, for backward compatibility.
1041 //-----------------------------------------------------------------------------
1043 //-----------------------------------------------------------------------------
1045 IMPLEMENT_CLASS(wxGtkPrintDC
, wxDC
)
1047 // Define the default resolution for this DC. This resolution is just used for positioning as the cairo context is scalable.
1048 int wxGtkPrintDC::ms_resolution
= 72;
1050 wxGtkPrintDC::wxGtkPrintDC( const wxPrintData
& data
)
1054 wxGtkPrintNativeData
*native
=
1055 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1057 m_gpc
= native
->GetPrintContext();
1059 ms_resolution
= m_printData
.GetQuality();// (int) gtk_print_context_get_dpi_x( m_gpc );
1060 if (ms_resolution
< 0)
1062 ms_resolution
= (1 << (ms_resolution
+4)) *150;
1064 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1065 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1066 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1068 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1074 m_signX
= 1; // default x-axis left to right.
1075 m_signY
= 1; // default y-axis bottom up -> top down.
1077 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
1080 wxGtkPrintDC::~wxGtkPrintDC()
1082 g_object_unref(m_context
);
1083 g_object_unref(m_layout
);
1086 bool wxGtkPrintDC::IsOk() const
1091 void wxGtkPrintDC::ComputeScaleAndOrigin()
1093 // Called when the scale and/or origin of the context has to be changed.
1094 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1095 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1097 gs_cairo
->cairo_translate(m_cairo
, MapToCairo(m_deviceOriginX
), MapToCairo(m_deviceOriginY
) );
1098 gs_cairo
->cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1101 bool wxGtkPrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
1103 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1104 wxFAIL_MSG(_("not implemented"));
1108 void wxGtkPrintDC::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1110 wxCoord xC
= circleCenter
.x
;
1111 wxCoord yC
= circleCenter
.y
;
1112 wxCoord xR
= rect
.x
;
1113 wxCoord yR
= rect
.y
;
1114 wxCoord w
= rect
.width
;
1115 wxCoord h
= rect
.height
;
1117 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1119 unsigned char redI
= initialColour
.Red();
1120 unsigned char blueI
= initialColour
.Blue();
1121 unsigned char greenI
= initialColour
.Green();
1122 unsigned char alphaI
= initialColour
.Alpha();
1123 unsigned char redD
= destColour
.Red();
1124 unsigned char blueD
= destColour
.Blue();
1125 unsigned char greenD
= destColour
.Green();
1126 unsigned char alphaD
= destColour
.Alpha();
1128 double redIPS
= (double)(redI
) / 255.0;
1129 double blueIPS
= (double)(blueI
) / 255.0;
1130 double greenIPS
= (double)(greenI
) / 255.0;
1131 double alphaIPS
= (double)(alphaI
) / 255.0;
1132 double redDPS
= (double)(redD
) / 255.0;
1133 double blueDPS
= (double)(blueD
) / 255.0;
1134 double greenDPS
= (double)(greenD
) / 255.0;
1135 double alphaDPS
= (double)(alphaD
) / 255.0;
1137 // Create a pattern with the gradient.
1138 cairo_pattern_t
* gradient
;
1139 gradient
= gs_cairo
->cairo_pattern_create_radial (LogicalToCairoX(xC
+xR
), LogicalToCairoY(yC
+yR
), 0, LogicalToCairoX(xC
+xR
), LogicalToCairoY(yC
+yR
), MapToCairo(radius
));
1140 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1141 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1143 // Fill the rectangle with this pattern.
1144 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1145 gs_cairo
->cairo_rectangle (m_cairo
, LogicalToCairoX(xR
), LogicalToCairoY(yR
), LogicalToCairoXRel(w
), LogicalToCairoYRel(h
) );
1146 gs_cairo
->cairo_fill(m_cairo
);
1148 gs_cairo
->cairo_pattern_destroy(gradient
);
1150 CalcBoundingBox(xR
, yR
);
1151 CalcBoundingBox(xR
+w
, yR
+h
);
1154 void wxGtkPrintDC::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1158 wxCoord w
= rect
.width
;
1159 wxCoord h
= rect
.height
;
1161 unsigned char redI
= initialColour
.Red();
1162 unsigned char blueI
= initialColour
.Blue();
1163 unsigned char greenI
= initialColour
.Green();
1164 unsigned char alphaI
= initialColour
.Alpha();
1165 unsigned char redD
= destColour
.Red();
1166 unsigned char blueD
= destColour
.Blue();
1167 unsigned char greenD
= destColour
.Green();
1168 unsigned char alphaD
= destColour
.Alpha();
1170 double redIPS
= (double)(redI
) / 255.0;
1171 double blueIPS
= (double)(blueI
) / 255.0;
1172 double greenIPS
= (double)(greenI
) / 255.0;
1173 double alphaIPS
= (double)(alphaI
) / 255.0;
1174 double redDPS
= (double)(redD
) / 255.0;
1175 double blueDPS
= (double)(blueD
) / 255.0;
1176 double greenDPS
= (double)(greenD
) / 255.0;
1177 double alphaDPS
= (double)(alphaD
) / 255.0;
1179 // Create a pattern with the gradient.
1180 cairo_pattern_t
* gradient
;
1181 gradient
= gs_cairo
->cairo_pattern_create_linear (LogicalToCairoX(x
), LogicalToCairoY(y
), LogicalToCairoX(x
+w
), LogicalToCairoY(y
));
1183 if (nDirection
== wxWEST
)
1185 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1186 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1189 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1190 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1193 // Fill the rectangle with this pattern.
1194 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1195 gs_cairo
->cairo_rectangle (m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
), LogicalToCairoXRel(w
), LogicalToCairoYRel(h
) );
1196 gs_cairo
->cairo_fill(m_cairo
);
1198 gs_cairo
->cairo_pattern_destroy(gradient
);
1200 CalcBoundingBox(x
, y
);
1201 CalcBoundingBox(x
+w
, y
+h
);
1204 bool wxGtkPrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
1206 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1207 wxFAIL_MSG(_("not implemented"));
1211 void wxGtkPrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1213 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1216 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToCairoX(x1
), LogicalToCairoY(y1
) );
1217 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToCairoX(x2
), LogicalToCairoY(y2
) );
1218 gs_cairo
->cairo_stroke ( m_cairo
);
1220 CalcBoundingBox( x1
, y1
);
1221 CalcBoundingBox( x2
, y2
);
1224 void wxGtkPrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1233 gs_cairo
->cairo_move_to (m_cairo
, LogicalToCairoX(x
), 0);
1234 gs_cairo
->cairo_line_to (m_cairo
, LogicalToCairoX(x
), MapToCairo(*h
));
1235 gs_cairo
->cairo_move_to (m_cairo
, 0, LogicalToCairoY(y
));
1236 gs_cairo
->cairo_line_to (m_cairo
, MapToCairo(*w
), LogicalToCairoY(y
));
1238 gs_cairo
->cairo_stroke (m_cairo
);
1239 CalcBoundingBox( 0, 0 );
1240 CalcBoundingBox( *w
, *h
);
1246 void wxGtkPrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1248 double dx
= x1
- xc
;
1249 double dy
= y1
- yc
;
1250 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1252 double alpha1
, alpha2
;
1253 if (x1
== x2
&& y1
== y2
)
1261 alpha1
= alpha2
= 0.0;
1265 alpha1
= (x1
- xc
== 0) ?
1266 (y1
- yc
< 0) ? 90.0 : -90.0 :
1267 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1268 alpha2
= (x2
- xc
== 0) ?
1269 (y2
- yc
< 0) ? 90.0 : -90.0 :
1270 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1272 while (alpha1
<= 0) alpha1
+= 360;
1273 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1274 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1275 while (alpha2
> 360) alpha2
-= 360;
1281 gs_cairo
->cairo_arc_negative ( m_cairo
, LogicalToCairoX(xc
), LogicalToCairoY(yc
), LogicalToCairoXRel((int)radius
), alpha1
, alpha2
);
1282 gs_cairo
->cairo_line_to(m_cairo
, LogicalToCairoX(xc
), LogicalToCairoY(yc
));
1283 gs_cairo
->cairo_close_path (m_cairo
);
1285 SetBrush( m_brush
);
1286 gs_cairo
->cairo_fill_preserve( m_cairo
);
1289 gs_cairo
->cairo_stroke( m_cairo
);
1291 CalcBoundingBox (x1
, y1
);
1292 CalcBoundingBox (xc
, yc
);
1293 CalcBoundingBox (x2
, y2
);
1296 void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1298 gs_cairo
->cairo_save( m_cairo
);
1300 gs_cairo
->cairo_translate( m_cairo
, LogicalToCairoX((wxCoord
) (x
+ w
/ 2.)), LogicalToCairoX((wxCoord
) (y
+ h
/ 2.)) );
1301 double scale
= (double)LogicalToCairoYRel(h
) / (double) LogicalToCairoXRel(w
);
1302 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1304 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, LogicalToCairoXRel(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1307 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1309 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1311 SetBrush( m_brush
);
1312 gs_cairo
->cairo_fill( m_cairo
);
1314 gs_cairo
->cairo_restore( m_cairo
);
1316 CalcBoundingBox( x
, y
);
1317 CalcBoundingBox( x
+w
, y
+h
);
1320 void wxGtkPrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1322 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1326 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
) );
1327 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
) );
1328 gs_cairo
->cairo_stroke ( m_cairo
);
1330 CalcBoundingBox( x
, y
);
1333 void wxGtkPrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1335 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1342 for ( i
=0; i
<n
; i
++ )
1343 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1345 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToCairoX(points
[0].x
+xoffset
), LogicalToCairoY(points
[0].y
+yoffset
) );
1347 for (i
= 1; i
< n
; i
++)
1348 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToCairoX(points
[i
].x
+xoffset
), LogicalToCairoY(points
[i
].y
+yoffset
) );
1350 gs_cairo
->cairo_stroke ( m_cairo
);
1353 void wxGtkPrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1357 gs_cairo
->cairo_save(m_cairo
);
1358 if (fillStyle
== wxWINDING_RULE
)
1359 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1361 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1363 int x
= points
[0].x
+ xoffset
;
1364 int y
= points
[0].y
+ yoffset
;
1365 gs_cairo
->cairo_new_path(m_cairo
);
1366 gs_cairo
->cairo_move_to( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
) );
1368 for (i
= 1; i
< n
; i
++)
1370 int x
= points
[i
].x
+ xoffset
;
1371 int y
= points
[i
].y
+ yoffset
;
1372 gs_cairo
->cairo_line_to( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
) );
1374 gs_cairo
->cairo_close_path(m_cairo
);
1376 SetBrush( m_brush
);
1377 gs_cairo
->cairo_fill_preserve( m_cairo
);
1380 gs_cairo
->cairo_stroke( m_cairo
);
1382 CalcBoundingBox( x
, y
);
1384 gs_cairo
->cairo_restore(m_cairo
);
1387 void wxGtkPrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1389 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1392 void wxGtkPrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1394 gs_cairo
->cairo_rectangle ( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
), LogicalToCairoXRel(width
), LogicalToCairoYRel(height
));
1396 SetBrush( m_brush
);
1397 gs_cairo
->cairo_fill_preserve( m_cairo
);
1400 gs_cairo
->cairo_stroke( m_cairo
);
1402 CalcBoundingBox( x
, y
);
1403 CalcBoundingBox( x
+ width
, y
+ height
);
1406 void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1408 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1410 wxCoord dd
= 2 * (wxCoord
) radius
;
1411 if (dd
> width
) dd
= width
;
1412 if (dd
> height
) dd
= height
;
1415 wxCoord rad
= (wxCoord
) radius
;
1417 gs_cairo
->cairo_new_path(m_cairo
);
1418 gs_cairo
->cairo_move_to(m_cairo
,LogicalToCairoX(x
+ rad
),LogicalToCairoY(y
));
1419 gs_cairo
->cairo_curve_to(m_cairo
,
1420 LogicalToCairoX(x
+ rad
),LogicalToCairoY(y
),
1421 LogicalToCairoX(x
),LogicalToCairoY(y
),
1422 LogicalToCairoX(x
),LogicalToCairoY(y
+ rad
));
1423 gs_cairo
->cairo_line_to(m_cairo
,LogicalToCairoX(x
),LogicalToCairoY(y
+ height
- rad
));
1424 gs_cairo
->cairo_curve_to(m_cairo
,
1425 LogicalToCairoX(x
),LogicalToCairoY(y
+ height
- rad
),
1426 LogicalToCairoX(x
),LogicalToCairoY(y
+ height
),
1427 LogicalToCairoX(x
+ rad
),LogicalToCairoY(y
+ height
));
1428 gs_cairo
->cairo_line_to(m_cairo
,LogicalToCairoX(x
+ width
- rad
),LogicalToCairoY(y
+ height
));
1429 gs_cairo
->cairo_curve_to(m_cairo
,
1430 LogicalToCairoX(x
+ width
- rad
),LogicalToCairoY(y
+ height
),
1431 LogicalToCairoX(x
+ width
),LogicalToCairoY(y
+ height
),
1432 LogicalToCairoX(x
+ width
),LogicalToCairoY(y
+ height
- rad
));
1433 gs_cairo
->cairo_line_to(m_cairo
,LogicalToCairoX(x
+ width
),LogicalToCairoY(y
+ rad
));
1434 gs_cairo
->cairo_curve_to(m_cairo
,
1435 LogicalToCairoX(x
+ width
),LogicalToCairoY(y
+ rad
),
1436 LogicalToCairoX(x
+ width
),LogicalToCairoY(y
),
1437 LogicalToCairoX(x
+ width
- rad
),LogicalToCairoY(y
));
1438 gs_cairo
->cairo_line_to(m_cairo
,LogicalToCairoX(x
+ rad
),LogicalToCairoY(y
));
1439 gs_cairo
->cairo_close_path(m_cairo
);
1442 gs_cairo
->cairo_fill_preserve(m_cairo
);
1445 gs_cairo
->cairo_stroke(m_cairo
);
1447 CalcBoundingBox(x
,y
);
1448 CalcBoundingBox(x
+width
,y
+height
);
1451 void wxGtkPrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1453 gs_cairo
->cairo_save (m_cairo
);
1455 gs_cairo
->cairo_translate (m_cairo
, LogicalToCairoX((wxCoord
) (x
+ width
/ 2.)), LogicalToCairoY((wxCoord
) (y
+ height
/ 2.)));
1456 gs_cairo
->cairo_scale(m_cairo
, 1, (double)LogicalToCairoYRel(height
)/(double)LogicalToCairoXRel(width
));
1457 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, LogicalToCairoXRel(width
/2), 0, 2 * M_PI
);
1459 SetBrush( m_brush
);
1460 gs_cairo
->cairo_fill_preserve( m_cairo
);
1463 gs_cairo
->cairo_stroke( m_cairo
);
1465 CalcBoundingBox( x
, y
);
1466 CalcBoundingBox( x
+ width
, y
+ height
);
1468 gs_cairo
->cairo_restore (m_cairo
);
1472 void wxGtkPrintDC::DoDrawSpline(wxList
*points
)
1476 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1479 wxList::compatibility_iterator node
= points
->GetFirst();
1480 p
= (wxPoint
*)node
->GetData();
1484 node
= node
->GetNext();
1485 p
= (wxPoint
*)node
->GetData();
1489 (double)(x1
+ c
) / 2;
1491 (double)(y1
+ d
) / 2;
1493 gs_cairo
->cairo_new_path( m_cairo
);
1494 gs_cairo
->cairo_move_to( m_cairo
, LogicalToCairoX((wxCoord
)x1
), LogicalToCairoY((wxCoord
)y1
) );
1495 gs_cairo
->cairo_line_to( m_cairo
, LogicalToCairoX((wxCoord
)x3
), LogicalToCairoY((wxCoord
)y3
) );
1497 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1498 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1500 node
= node
->GetNext();
1503 q
= (wxPoint
*)node
->GetData();
1511 x3
= (double)(x2
+ c
) / 2;
1512 y3
= (double)(y2
+ d
) / 2;
1514 gs_cairo
->cairo_curve_to(m_cairo
,
1515 LogicalToCairoX((wxCoord
)x1
), LogicalToCairoY((wxCoord
)y1
),
1516 LogicalToCairoX((wxCoord
)x2
), LogicalToCairoY((wxCoord
)y2
),
1517 LogicalToCairoX((wxCoord
)x3
), LogicalToCairoY((wxCoord
)y3
) );
1519 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1520 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1522 node
= node
->GetNext();
1525 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToCairoX((wxCoord
)c
), LogicalToCairoY((wxCoord
)d
) );
1527 gs_cairo
->cairo_stroke( m_cairo
);
1529 #endif // wxUSE_SPLINES
1531 bool wxGtkPrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1532 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1533 wxCoord xsrcMask
, wxCoord ysrcMask
)
1535 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1537 // Blit into a bitmap.
1538 wxBitmap
bitmap( width
, height
);
1540 memDC
.SelectObject(bitmap
);
1541 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1542 memDC
.SelectObject(wxNullBitmap
);
1544 // Draw bitmap. scaling and positioning is done there.
1545 DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1550 void wxGtkPrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1552 DoDrawBitmap( icon
, x
, y
, true );
1555 void wxGtkPrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1557 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1559 cairo_surface_t
* surface
;
1560 x
= wxCoord(LogicalToCairoX(x
));
1561 y
= wxCoord(LogicalToCairoY(y
));
1562 int bw
= bitmap
.GetWidth();
1563 int bh
= bitmap
.GetHeight();
1564 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1565 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1566 wxUint32
* data
= (wxUint32
*)buffer
;
1568 wxMask
*mask
= NULL
;
1569 if (useMask
) mask
= bmpSource
.GetMask();
1571 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1572 // then we'll use a different format and iterator than if it doesn't.
1573 if (bmpSource
.HasAlpha() || mask
)
1575 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1576 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1577 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1578 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1580 wxAlphaPixelData::Iterator
p(pixData
);
1582 for (y
=0; y
<bh
; y
++)
1584 wxAlphaPixelData::Iterator rowStart
= p
;
1585 for (x
=0; x
<bw
; x
++)
1587 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1588 // with alpha in the upper 8 bits, then red, then green, then
1589 // blue. The 32-bit quantities are stored native-endian.
1590 // Pre-multiplied alpha is used.
1591 unsigned char alpha
= p
.Alpha();
1595 *data
= ( alpha
/255 << 24
1596 | (p
.Red() * alpha
/255) << 16
1597 | (p
.Green() * alpha
/255) << 8
1598 | (p
.Blue() * alpha
/255) );
1603 p
.OffsetY(pixData
, 1);
1608 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1609 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1610 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1611 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1613 wxNativePixelData::Iterator
p(pixData
);
1615 for (y
=0; y
<bh
; y
++)
1617 wxNativePixelData::Iterator rowStart
= p
;
1618 for (x
=0; x
<bw
; x
++)
1620 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1621 // the upper 8 bits unused. Red, Green, and Blue are stored in
1622 // the remaining 24 bits in that order. The 32-bit quantities
1623 // are stored native-endian.
1624 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1629 p
.OffsetY(pixData
, 1);
1634 gs_cairo
->cairo_save(m_cairo
);
1635 // In case we're scaling the image by using a width and height different
1636 // than the bitmap's size create a pattern transformation on the surface and
1637 // draw the transformed pattern.
1638 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface(surface
);
1640 // Prepare to draw the image.
1641 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1642 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1643 // Use the original size here since the context is scaled already.
1644 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1645 // Fill the rectangle using the pattern.
1646 gs_cairo
->cairo_fill(m_cairo
);
1649 gs_cairo
->cairo_pattern_destroy(pattern
);
1650 gs_cairo
->cairo_surface_destroy(surface
);
1653 CalcBoundingBox(0,0);
1654 CalcBoundingBox(bw
,bh
);
1656 gs_cairo
->cairo_restore(m_cairo
);
1659 // wxGtkPrintDC has a constant resolution of 72dpi. If we want an higher resolution for printing
1660 // an image, the scaling has to be done by cairo.
1661 void wxGtkPrintDC::DoDrawScaledBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, bool useMask
, int quality
)
1663 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1665 cairo_surface_t
* surface
;
1666 int bw
= bitmap
.GetWidth();
1667 int bh
= bitmap
.GetHeight();
1668 x
= wxCoord(LogicalToCairoX(x
));
1669 y
= wxCoord(LogicalToCairoY(y
));
1670 w
= wxCoord(LogicalToCairoXRel(w
));
1671 h
= wxCoord(LogicalToCairoYRel(h
));
1672 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1673 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1674 wxUint32
* data
= (wxUint32
*)buffer
;
1676 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1677 // then we'll use a different format and iterator than if it doesn't.
1678 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1680 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1681 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1682 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1683 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1685 wxAlphaPixelData::Iterator
p(pixData
);
1687 for (y
=0; y
<bh
; y
++)
1689 wxAlphaPixelData::Iterator rowStart
= p
;
1690 for (x
=0; x
<bw
; x
++)
1692 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1693 // with alpha in the upper 8 bits, then red, then green, then
1694 // blue. The 32-bit quantities are stored native-endian.
1695 // Pre-multiplied alpha is used.
1696 unsigned char alpha
= p
.Alpha();
1700 *data
= ( alpha
<< 24
1701 | (p
.Red() * alpha
/255) << 16
1702 | (p
.Green() * alpha
/255) << 8
1703 | (p
.Blue() * alpha
/255) );
1708 p
.OffsetY(pixData
, 1);
1713 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1714 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1715 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1716 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1718 wxNativePixelData::Iterator
p(pixData
);
1720 for (y
=0; y
<bh
; y
++)
1722 wxNativePixelData::Iterator rowStart
= p
;
1723 for (x
=0; x
<bw
; x
++)
1725 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1726 // the upper 8 bits unused. Red, Green, and Blue are stored in
1727 // the remaining 24 bits in that order. The 32-bit quantities
1728 // are stored native-endian.
1729 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1734 p
.OffsetY(pixData
, 1);
1739 gs_cairo
->cairo_save(m_cairo
);
1741 // Prepare to draw the image.
1742 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1744 // In case we're scaling the image by using a width and height different
1745 // than the bitmap's size create a pattern transformation on the surface and
1746 // draw the transformed pattern.
1747 cairo_filter_t filter
;
1748 if (quality
== wxIMAGE_QUALITY_HIGH
) filter
= CAIRO_FILTER_BILINEAR
;
1749 else filter
= CAIRO_FILTER_GOOD
;
1750 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface(surface
);
1751 gs_cairo
->cairo_pattern_set_filter(pattern
,filter
);
1752 wxDouble scaleX
= (wxDouble
) w
/ (wxDouble
) bw
;
1753 wxDouble scaleY
= (wxDouble
) h
/ (wxDouble
) bh
;
1754 gs_cairo
->cairo_scale(m_cairo
, scaleX
, scaleY
);
1756 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1757 // Use the original size here since the context is scaled already.
1758 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1759 // Fill the rectangle using the pattern.
1760 gs_cairo
->cairo_fill(m_cairo
);
1763 gs_cairo
->cairo_pattern_destroy(pattern
);
1764 gs_cairo
->cairo_surface_destroy(surface
);
1767 CalcBoundingBox(0,0);
1768 CalcBoundingBox(bw
,bh
);
1770 gs_cairo
->cairo_restore(m_cairo
);
1773 void wxGtkPrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1775 DoDrawRotatedText( text
, x
, y
, 0.0 );
1778 void wxGtkPrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord xC
, wxCoord yC
, double angle
)
1780 double x
= LogicalToCairoX(xC
);
1781 double y
= LogicalToCairoY(yC
);
1785 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1787 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1788 #if wxUSE_UNICODE_UTF8
1789 const char *data
= text
.utf8_str();
1791 const wxCharBuffer data
= text
.utf8_str();
1794 size_t datalen
= strlen(data
);
1795 pango_layout_set_text( m_layout
, data
, datalen
);
1799 PangoAttrList
*attrs
= pango_attr_list_new();
1800 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1802 a
->end_index
= datalen
;
1803 pango_attr_list_insert(attrs
, a
);
1804 pango_layout_set_attributes(m_layout
, attrs
);
1805 pango_attr_list_unref(attrs
);
1808 if (m_textForegroundColour
.Ok())
1810 unsigned char red
= m_textForegroundColour
.Red();
1811 unsigned char blue
= m_textForegroundColour
.Blue();
1812 unsigned char green
= m_textForegroundColour
.Green();
1813 unsigned char alpha
= m_textForegroundColour
.Alpha();
1815 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1817 double redPS
= (double)(red
) / 255.0;
1818 double bluePS
= (double)(blue
) / 255.0;
1819 double greenPS
= (double)(green
) / 255.0;
1820 double alphaPS
= (double)(alpha
) / 255.0;
1822 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1825 m_currentBlue
= blue
;
1826 m_currentGreen
= green
;
1827 m_currentAlpha
= alpha
;
1833 if (fabs(m_scaleY
- 1.0) > 0.00001)
1835 // If there is a user or actually any scale applied to the device context, scale the font.
1837 // Scale font description.
1838 gint oldSize
= pango_font_description_get_size( m_fontdesc
); // cairo units
1839 double size
= oldSize
;
1840 size
= size
* m_scaleY
;
1841 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // still in cairo units, no scaling required
1843 // Actually apply scaled font.
1844 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1846 pango_layout_get_pixel_size( m_layout
, &w
, &h
); // cairo units
1847 w
= wxCoord(LogicalToCairoXRel(MapFromCairo(w
))); // convert from cairo to device units and back again
1848 h
= wxCoord(LogicalToCairoYRel(MapFromCairo(h
)));
1850 if ( m_backgroundMode
== wxSOLID
)
1852 unsigned char red
= m_textBackgroundColour
.Red();
1853 unsigned char blue
= m_textBackgroundColour
.Blue();
1854 unsigned char green
= m_textBackgroundColour
.Green();
1855 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1857 double redPS
= (double)(red
) / 255.0;
1858 double bluePS
= (double)(blue
) / 255.0;
1859 double greenPS
= (double)(green
) / 255.0;
1860 double alphaPS
= (double)(alpha
) / 255.0;
1862 gs_cairo
->cairo_save(m_cairo
);
1863 gs_cairo
->cairo_translate(m_cairo
, x
, y
); // have already been converted to cairo units before
1864 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1865 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1866 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // have been converted back and forth
1867 gs_cairo
->cairo_fill(m_cairo
);
1868 gs_cairo
->cairo_restore(m_cairo
);
1872 gs_cairo
->cairo_move_to (m_cairo
, x
, y
);
1873 if (fabs(angle
) > 0.00001)
1875 gs_cairo
->cairo_save( m_cairo
);
1876 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1877 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1878 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1879 gs_cairo
->cairo_restore( m_cairo
);
1883 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1884 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1887 // Reset unscaled size.
1888 pango_font_description_set_size( m_fontdesc
, oldSize
);
1890 // Actually apply unscaled font.
1891 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1895 pango_layout_get_pixel_size( m_layout
, &w
, &h
); // cairo units
1897 if ( m_backgroundMode
== wxSOLID
)
1899 unsigned char red
= m_textBackgroundColour
.Red();
1900 unsigned char blue
= m_textBackgroundColour
.Blue();
1901 unsigned char green
= m_textBackgroundColour
.Green();
1902 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1904 double redPS
= (double)(red
) / 255.0;
1905 double bluePS
= (double)(blue
) / 255.0;
1906 double greenPS
= (double)(green
) / 255.0;
1907 double alphaPS
= (double)(alpha
) / 255.0;
1909 gs_cairo
->cairo_save(m_cairo
);
1910 gs_cairo
->cairo_translate(m_cairo
, x
, y
); // have already been converted to cairo units before
1911 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1912 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1913 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1914 gs_cairo
->cairo_fill(m_cairo
);
1915 gs_cairo
->cairo_restore(m_cairo
);
1919 gs_cairo
->cairo_move_to (m_cairo
, x
, y
); // have already been converted to cairo units before
1920 if (fabs(angle
) > 0.00001)
1922 gs_cairo
->cairo_save( m_cairo
);
1923 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1924 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1925 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1926 gs_cairo
->cairo_restore( m_cairo
);
1930 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1931 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1937 // Undo underline attributes setting
1938 pango_layout_set_attributes(m_layout
, NULL
);
1940 // Back to device units:
1941 CalcBoundingBox (MapFromCairo(x
),MapFromCairo(y
));
1942 CalcBoundingBox (MapFromCairo(x
+ w
),MapFromCairo(y
+ h
));
1945 void wxGtkPrintDC::Clear()
1947 // Clear does nothing for printing, but keep the code
1950 gs_cairo->cairo_save(m_cairo);
1951 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1952 SetBrush(m_backgroundBrush);
1953 gs_cairo->cairo_paint(m_cairo);
1954 gs_cairo->cairo_restore(m_cairo);
1958 void wxGtkPrintDC::SetFont( const wxFont
& font
)
1965 pango_font_description_free( m_fontdesc
);
1967 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1969 // Scale font description from device units to pango units
1970 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1971 double size
= MapToCairo(oldSize
); // scale to cairo units
1972 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1974 // Actually apply scaled font.
1975 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1979 void wxGtkPrintDC::SetPen( const wxPen
& pen
)
1981 if (!pen
.Ok()) return;
1985 double width
= (double) m_pen
.GetWidth();
1986 if (width
== 0) width
= 0.1;
1988 gs_cairo
->cairo_set_line_width( m_cairo
, LogicalToCairoXRel( (wxCoord
)((1000.0 * (double)width
) / 1000.0)) );
1989 static const double dotted
[] = {2.0, 5.0};
1990 static const double short_dashed
[] = {4.0, 4.0};
1991 static const double long_dashed
[] = {4.0, 8.0};
1992 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1994 switch (m_pen
.GetStyle())
1996 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 1, 0 ); break;
1997 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 1, 0 ); break;
1998 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 1, 0 ); break;
1999 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 3, 0 ); break;
2003 int num
= m_pen
.GetDashes (&wx_dashes
) - 1;
2004 gdouble
*g_dashes
= g_new( gdouble
, num
);
2006 for (i
= 0; i
< num
; ++i
)
2007 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
2008 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
2014 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
2017 switch (m_pen
.GetCap())
2019 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
2020 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
2022 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
2025 switch (m_pen
.GetJoin())
2027 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
2028 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
2030 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
2033 unsigned char red
= m_pen
.GetColour().Red();
2034 unsigned char blue
= m_pen
.GetColour().Blue();
2035 unsigned char green
= m_pen
.GetColour().Green();
2036 unsigned char alpha
= m_pen
.GetColour().Alpha();
2038 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2040 double redPS
= (double)(red
) / 255.0;
2041 double bluePS
= (double)(blue
) / 255.0;
2042 double greenPS
= (double)(green
) / 255.0;
2043 double alphaPS
= (double)(alpha
) / 255.0;
2045 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2048 m_currentBlue
= blue
;
2049 m_currentGreen
= green
;
2050 m_currentAlpha
= alpha
;
2054 void wxGtkPrintDC::SetBrush( const wxBrush
& brush
)
2056 if (!brush
.Ok()) return;
2061 unsigned char red
= m_brush
.GetColour().Red();
2062 unsigned char blue
= m_brush
.GetColour().Blue();
2063 unsigned char green
= m_brush
.GetColour().Green();
2064 unsigned char alpha
= m_brush
.GetColour().Alpha();
2066 double redPS
= (double)(red
) / 255.0;
2067 double bluePS
= (double)(blue
) / 255.0;
2068 double greenPS
= (double)(green
) / 255.0;
2069 double alphaPS
= (double)(alpha
) / 255.0;
2071 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2073 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2076 m_currentBlue
= blue
;
2077 m_currentGreen
= green
;
2078 m_currentAlpha
= alpha
;
2081 if (m_brush
.IsHatch())
2084 cairo_surface_t
*surface
;
2085 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2086 cr
= gs_cairo
->cairo_create(surface
);
2087 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2088 gs_cairo
->cairo_set_line_width(cr
, 1);
2089 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2091 switch (m_brush
.GetStyle())
2094 gs_cairo
->cairo_move_to(cr
, 5, 0);
2095 gs_cairo
->cairo_line_to(cr
, 5, 10);
2096 gs_cairo
->cairo_move_to(cr
, 0, 5);
2097 gs_cairo
->cairo_line_to(cr
, 10, 5);
2099 case wxBDIAGONAL_HATCH
:
2100 gs_cairo
->cairo_move_to(cr
, 0, 10);
2101 gs_cairo
->cairo_line_to(cr
, 10, 0);
2103 case wxFDIAGONAL_HATCH
:
2104 gs_cairo
->cairo_move_to(cr
, 0, 0);
2105 gs_cairo
->cairo_line_to(cr
, 10, 10);
2107 case wxCROSSDIAG_HATCH
:
2108 gs_cairo
->cairo_move_to(cr
, 0, 0);
2109 gs_cairo
->cairo_line_to(cr
, 10, 10);
2110 gs_cairo
->cairo_move_to(cr
, 10, 0);
2111 gs_cairo
->cairo_line_to(cr
, 0, 10);
2113 case wxHORIZONTAL_HATCH
:
2114 gs_cairo
->cairo_move_to(cr
, 0, 5);
2115 gs_cairo
->cairo_line_to(cr
, 10, 5);
2117 case wxVERTICAL_HATCH
:
2118 gs_cairo
->cairo_move_to(cr
, 5, 0);
2119 gs_cairo
->cairo_line_to(cr
, 5, 10);
2122 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2125 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2126 gs_cairo
->cairo_stroke (cr
);
2128 gs_cairo
->cairo_destroy(cr
);
2129 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2130 gs_cairo
->cairo_surface_destroy(surface
);
2131 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2132 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2133 gs_cairo
->cairo_pattern_destroy(pattern
);
2137 void wxGtkPrintDC::SetLogicalFunction( int function
)
2139 if (function
== wxCLEAR
)
2140 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2141 else if (function
== wxOR
)
2142 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2143 else if (function
== wxNO_OP
)
2144 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2145 else if (function
== wxAND
)
2146 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2147 else if (function
== wxSET
)
2148 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2149 else if (function
== wxXOR
)
2150 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2151 else // wxCOPY or anything else.
2152 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2155 void wxGtkPrintDC::SetBackground( const wxBrush
& brush
)
2157 m_backgroundBrush
= brush
;
2158 gs_cairo
->cairo_save(m_cairo
);
2159 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2161 SetBrush(m_backgroundBrush
);
2162 gs_cairo
->cairo_paint(m_cairo
);
2163 gs_cairo
->cairo_restore(m_cairo
);
2166 void wxGtkPrintDC::SetBackgroundMode(int mode
)
2168 if (mode
== wxSOLID
) m_backgroundMode
= wxSOLID
;
2169 else m_backgroundMode
= wxTRANSPARENT
;
2172 void wxGtkPrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2174 gs_cairo
->cairo_rectangle ( m_cairo
, LogicalToCairoX(x
), LogicalToCairoY(y
), LogicalToCairoXRel(width
), LogicalToCairoYRel(height
));
2175 gs_cairo
->cairo_clip(m_cairo
);
2178 void wxGtkPrintDC::DestroyClippingRegion()
2180 gs_cairo
->cairo_reset_clip(m_cairo
);
2183 bool wxGtkPrintDC::StartDoc(const wxString
& message
)
2188 void wxGtkPrintDC::EndDoc()
2193 void wxGtkPrintDC::StartPage()
2198 void wxGtkPrintDC::EndPage()
2203 wxCoord
wxGtkPrintDC::GetCharHeight() const
2205 pango_layout_set_text( m_layout
, "H", 1 );
2208 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2210 return CairoToLogicalYRel(h
);
2213 wxCoord
wxGtkPrintDC::GetCharWidth() const
2215 pango_layout_set_text( m_layout
, "H", 1 );
2218 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2220 return CairoToLogicalXRel(w
);
2223 void wxGtkPrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2225 wxCoord
*externalLeading
,
2226 const wxFont
*theFont
) const
2234 if ( externalLeading
)
2235 *externalLeading
= 0;
2242 // Set layout's text
2243 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
2244 #if wxUSE_UNICODE_UTF8
2245 const char *dataUTF8
= string
.utf8_str();
2247 const wxCharBuffer dataUTF8
= string
.utf8_str();
2250 PangoFontDescription
*desc
= m_fontdesc
;
2251 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2253 gint oldSize
= pango_font_description_get_size( desc
);
2254 double size
= oldSize
;
2255 size
= size
* m_scaleY
;
2256 pango_font_description_set_size( desc
, (gint
)size
);
2258 // apply scaled font
2259 pango_layout_set_font_description( m_layout
, desc
);
2261 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2264 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2267 *width
= MapFromCairo((double)w
/ (double)m_scaleX
);
2269 *height
= MapFromCairo((double)h
/ (double)m_scaleY
);
2272 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2273 int baseline
= pango_layout_iter_get_baseline(iter
);
2274 pango_layout_iter_free(iter
);
2275 *descent
= MapFromCairo((double) h
- (double) PANGO_PIXELS(baseline
));
2278 // Reset unscaled size.
2279 pango_font_description_set_size( desc
, oldSize
);
2281 // Reset unscaled font.
2282 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2285 void wxGtkPrintDC::DoGetSize(int* width
, int* height
) const
2288 *width
= (int) ((double)gtk_print_context_get_width( m_gpc
) * (double)ms_resolution
/72.0 + 0.5) ;
2290 *height
= (int) ((double)gtk_print_context_get_height( m_gpc
) * (double)ms_resolution
/72.0 + 0.5);
2293 void wxGtkPrintDC::DoGetSizeMM(int *width
, int *height
) const
2295 // This function takes margins into consideration.
2296 gdouble w
= gtk_page_setup_get_page_width( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2297 gdouble h
= gtk_page_setup_get_page_height( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2300 *width
= (int) (w
+ 0.5);
2302 *height
= (int) (h
+ 0.5);
2305 wxSize
wxGtkPrintDC::GetPPI() const
2307 return wxSize((int) ms_resolution
,(int) ms_resolution
);
2310 void wxGtkPrintDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
2312 wxDC::SetLogicalOrigin( x
, y
);
2315 void wxGtkPrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2317 wxDC::SetDeviceOrigin( x
, y
);
2320 void wxGtkPrintDC::SetPrintData(const wxPrintData
& data
)
2324 if (m_printData
.GetOrientation() == wxPORTRAIT
)
2325 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
2327 GetSize( &m_deviceOffsetY
, &m_deviceOffsetX
);
2330 void wxGtkPrintDC::SetResolution(int ppi
)
2332 // We can't change ppi of the GtkPrintContext.
2333 ms_resolution
= ppi
;
2336 int wxGtkPrintDC::GetResolution()
2338 return ms_resolution
;
2341 // ----------------------------------------------------------------------------
2343 // ----------------------------------------------------------------------------
2345 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2347 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2348 wxPrintout
* WXUNUSED(printoutForPrinting
))
2353 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2354 wxPrintout
*printoutForPrinting
,
2355 wxPrintDialogData
*data
)
2356 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2358 Init(printout
, printoutForPrinting
);
2361 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2362 wxPrintout
*printoutForPrinting
,
2364 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2366 Init(printout
, printoutForPrinting
);
2369 wxGtkPrintPreview::~wxGtkPrintPreview()
2373 bool wxGtkPrintPreview::Print(bool interactive
)
2375 if (!m_printPrintout
)
2378 wxPrinter
printer(& m_printDialogData
);
2379 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2382 void wxGtkPrintPreview::DetermineScaling()
2384 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2386 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2388 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2392 wxSize ScreenPixels
= wxGetDisplaySize();
2393 wxSize ScreenMM
= wxGetDisplaySizeMM();
2395 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2396 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2397 m_previewPrintout
->SetPPIPrinter(wxGtkPrintDC::GetResolution(), wxGtkPrintDC::GetResolution());
2398 // Get width and height in points (1/72th of an inch)
2399 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2401 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGtkPrintDC::GetResolution() / 72.0);
2402 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGtkPrintDC::GetResolution() / 72.0);
2403 wxSize
sizeTenthsMM(paper
->GetSize());
2404 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2406 // If in landscape mode, we need to swap the width and height.
2407 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2409 m_pageWidth
= sizeDevUnits
.y
;
2410 m_pageHeight
= sizeDevUnits
.x
;
2411 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2415 m_pageWidth
= sizeDevUnits
.x
;
2416 m_pageHeight
= sizeDevUnits
.y
;
2417 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2419 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2420 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2422 // At 100%, the page should look about page-size on the screen.
2423 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGtkPrintDC::GetResolution();
2424 m_previewScaleY
= m_previewScaleX
;