]>
Commit | Line | Data |
---|---|---|
fa034c45 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/gtk/print.cpp | |
3 | // Author: Anthony Bretaudeau | |
4 | // Purpose: GTK printing support | |
5 | // Created: 2007-08-25 | |
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 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #if wxUSE_GTKPRINT | |
19 | ||
20 | #include "wx/gtk/print.h" | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/log.h" | |
24 | #include "wx/dcmemory.h" | |
380740af | 25 | #include "wx/dcprint.h" |
fa034c45 RR |
26 | #include "wx/icon.h" |
27 | #include "wx/math.h" | |
28 | #include "wx/image.h" | |
29 | #include "wx/module.h" | |
a7060b8c | 30 | #include "wx/crt.h" |
fa034c45 RR |
31 | #endif |
32 | ||
33 | #include "wx/fontutil.h" | |
34 | #include "wx/gtk/private.h" | |
35 | #include "wx/dynlib.h" | |
36 | #include "wx/paper.h" | |
fa034c45 RR |
37 | |
38 | #include <gtk/gtk.h> | |
fa034c45 | 39 | |
2b44ffc0 RR |
40 | #if wxUSE_GRAPHICS_CONTEXT |
41 | #include "wx/graphics.h" | |
42 | #endif | |
43 | ||
fa034c45 RR |
44 | #include "wx/link.h" |
45 | wxFORCE_LINK_THIS_MODULE(gtk_print) | |
46 | ||
47 | #if wxUSE_LIBGNOMEPRINT | |
48 | #include "wx/gtk/gnome/gprint.h" | |
49 | #endif | |
50 | ||
51 | // Usefull to convert angles from/to Rad to/from Deg. | |
52 | static const double RAD2DEG = 180.0 / M_PI; | |
53 | static const double DEG2RAD = M_PI / 180.0; | |
54 | ||
55 | //---------------------------------------------------------------------------- | |
56 | // wxGtkPrintModule | |
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 | //---------------------------------------------------------------------------- | |
61 | ||
62 | class wxGtkPrintModule: public wxModule | |
63 | { | |
64 | public: | |
a7060b8c | 65 | wxGtkPrintModule() |
fa034c45 RR |
66 | { |
67 | #if wxUSE_LIBGNOMEPRINT | |
68 | // This module must be initialized AFTER gnomeprint's one | |
69 | AddDependency(CLASSINFO(wxGnomePrintModule)); | |
70 | #endif | |
71 | } | |
72 | bool OnInit(); | |
f7b8e3d6 | 73 | void OnExit() {} |
fa034c45 RR |
74 | |
75 | private: | |
76 | DECLARE_DYNAMIC_CLASS(wxGtkPrintModule) | |
77 | }; | |
78 | ||
79 | bool wxGtkPrintModule::OnInit() | |
80 | { | |
f7b8e3d6 | 81 | if (gtk_check_version(2,10,0) == NULL) |
fa034c45 | 82 | wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory ); |
fa034c45 RR |
83 | return true; |
84 | } | |
85 | ||
fa034c45 RR |
86 | IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule, wxModule) |
87 | ||
fa034c45 RR |
88 | //---------------------------------------------------------------------------- |
89 | // wxGtkPrintFactory | |
90 | //---------------------------------------------------------------------------- | |
91 | ||
92 | wxPrinterBase* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
93 | { | |
94 | return new wxGtkPrinter( data ); | |
95 | } | |
96 | ||
97 | wxPrintPreviewBase *wxGtkPrintFactory::CreatePrintPreview( wxPrintout *preview, | |
98 | wxPrintout *printout, | |
99 | wxPrintDialogData *data ) | |
100 | { | |
101 | return new wxGtkPrintPreview( preview, printout, data ); | |
102 | } | |
103 | ||
104 | wxPrintPreviewBase *wxGtkPrintFactory::CreatePrintPreview( wxPrintout *preview, | |
105 | wxPrintout *printout, | |
106 | wxPrintData *data ) | |
107 | { | |
108 | return new wxGtkPrintPreview( preview, printout, data ); | |
109 | } | |
110 | ||
111 | wxPrintDialogBase *wxGtkPrintFactory::CreatePrintDialog( wxWindow *parent, | |
112 | wxPrintDialogData *data ) | |
113 | { | |
114 | return new wxGtkPrintDialog( parent, data ); | |
115 | } | |
116 | ||
117 | wxPrintDialogBase *wxGtkPrintFactory::CreatePrintDialog( wxWindow *parent, | |
118 | wxPrintData *data ) | |
119 | { | |
120 | return new wxGtkPrintDialog( parent, data ); | |
121 | } | |
122 | ||
123 | wxPageSetupDialogBase *wxGtkPrintFactory::CreatePageSetupDialog( wxWindow *parent, | |
124 | wxPageSetupDialogData * data ) | |
125 | { | |
126 | return new wxGtkPageSetupDialog( parent, data ); | |
127 | } | |
128 | ||
129 | bool wxGtkPrintFactory::HasPrintSetupDialog() | |
130 | { | |
131 | return false; | |
132 | } | |
133 | ||
e0d1fd7f VZ |
134 | wxDialog * |
135 | wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent), | |
136 | wxPrintData * WXUNUSED(data)) | |
fa034c45 RR |
137 | { |
138 | return NULL; | |
139 | } | |
140 | ||
888dde65 | 141 | wxDCImpl* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) |
4f37154e | 142 | { |
888dde65 | 143 | return new wxGtkPrinterDCImpl( owner, data ); |
4f37154e RR |
144 | } |
145 | ||
fa034c45 RR |
146 | bool wxGtkPrintFactory::HasOwnPrintToFile() |
147 | { | |
148 | return true; | |
149 | } | |
150 | ||
151 | bool wxGtkPrintFactory::HasPrinterLine() | |
152 | { | |
153 | return true; | |
154 | } | |
155 | ||
156 | wxString wxGtkPrintFactory::CreatePrinterLine() | |
157 | { | |
158 | // redundant now | |
159 | return wxEmptyString; | |
160 | } | |
161 | ||
162 | bool wxGtkPrintFactory::HasStatusLine() | |
163 | { | |
164 | // redundant now | |
165 | return true; | |
166 | } | |
167 | ||
168 | wxString wxGtkPrintFactory::CreateStatusLine() | |
169 | { | |
170 | // redundant now | |
171 | return wxEmptyString; | |
172 | } | |
173 | ||
174 | wxPrintNativeDataBase *wxGtkPrintFactory::CreatePrintNativeData() | |
175 | { | |
176 | return new wxGtkPrintNativeData; | |
177 | } | |
178 | ||
179 | //---------------------------------------------------------------------------- | |
180 | // Callback functions for Gtk Printings. | |
181 | //---------------------------------------------------------------------------- | |
182 | ||
e0d1fd7f | 183 | // We use it to pass useful objects to GTK printing callback functions. |
a7060b8c | 184 | struct wxPrinterToGtkData |
fa034c45 RR |
185 | { |
186 | wxGtkPrinter * printer; | |
187 | wxPrintout * printout; | |
a7060b8c | 188 | }; |
fa034c45 RR |
189 | |
190 | extern "C" | |
191 | { | |
192 | static void gtk_begin_print_callback (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) | |
193 | { | |
194 | wxPrinterToGtkData *data = (wxPrinterToGtkData *) user_data; | |
195 | ||
196 | data->printer->BeginPrint(data->printout, operation, context); | |
197 | } | |
198 | ||
199 | static void gtk_draw_page_print_callback (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) | |
200 | { | |
201 | wxPrinterToGtkData *data = (wxPrinterToGtkData *) user_data; | |
202 | ||
203 | data->printer->DrawPage(data->printout, operation, context, page_nr); | |
204 | } | |
205 | ||
e0d1fd7f VZ |
206 | static void gtk_end_print_callback(GtkPrintOperation * WXUNUSED(operation), |
207 | GtkPrintContext * WXUNUSED(context), | |
208 | gpointer user_data) | |
fa034c45 RR |
209 | { |
210 | wxPrintout *printout = (wxPrintout *) user_data; | |
211 | ||
212 | printout->OnEndPrinting(); | |
213 | } | |
214 | ||
e0d1fd7f VZ |
215 | static gboolean |
216 | gtk_preview_print_callback(GtkPrintOperation * WXUNUSED(operation), | |
217 | GtkPrintOperationPreview * WXUNUSED(preview), | |
218 | GtkPrintContext *context, | |
219 | GtkWindow *parent, | |
220 | gpointer user_data) | |
fa034c45 RR |
221 | { |
222 | wxPrintout *printout = (wxPrintout *) user_data; | |
223 | ||
224 | printout->SetIsPreview(true); | |
225 | ||
e0d1fd7f VZ |
226 | /* We create a Cairo context with 72dpi resolution. This resolution is |
227 | * only used for positioning. */ | |
fa034c45 RR |
228 | cairo_t *cairo = gdk_cairo_create(GTK_WIDGET(parent)->window); |
229 | gtk_print_context_set_cairo_context(context, cairo, 72, 72); | |
230 | ||
231 | return false; | |
232 | } | |
233 | } | |
234 | ||
235 | //---------------------------------------------------------------------------- | |
236 | // wxGtkPrintNativeData | |
237 | //---------------------------------------------------------------------------- | |
238 | ||
239 | IMPLEMENT_CLASS(wxGtkPrintNativeData, wxPrintNativeDataBase) | |
240 | ||
241 | wxGtkPrintNativeData::wxGtkPrintNativeData() | |
242 | { | |
243 | m_config = gtk_print_settings_new(); | |
244 | } | |
245 | ||
246 | wxGtkPrintNativeData::~wxGtkPrintNativeData() | |
247 | { | |
248 | g_object_unref (m_config); | |
249 | } | |
250 | ||
251 | // Convert datas stored in m_config to a wxPrintData. | |
252 | // Called by wxPrintData::ConvertFromNative(). | |
253 | bool wxGtkPrintNativeData::TransferTo( wxPrintData &data ) | |
254 | { | |
255 | if(!m_config) | |
256 | return false; | |
257 | ||
23abaeae VZ |
258 | int resolution = gtk_print_settings_get_resolution(m_config); |
259 | if ( resolution > 0 ) | |
260 | { | |
261 | // if resolution is explicitly set, use it | |
262 | data.SetQuality(resolution); | |
263 | } | |
264 | else // use more vague "quality" | |
265 | { | |
266 | GtkPrintQuality quality = gtk_print_settings_get_quality(m_config); | |
267 | if (quality == GTK_PRINT_QUALITY_HIGH) | |
268 | data.SetQuality(wxPRINT_QUALITY_HIGH); | |
269 | else if (quality == GTK_PRINT_QUALITY_LOW) | |
270 | data.SetQuality(wxPRINT_QUALITY_LOW); | |
271 | else if (quality == GTK_PRINT_QUALITY_DRAFT) | |
272 | data.SetQuality(wxPRINT_QUALITY_DRAFT); | |
273 | else | |
274 | data.SetQuality(wxPRINT_QUALITY_MEDIUM); | |
275 | } | |
fa034c45 RR |
276 | |
277 | data.SetNoCopies(gtk_print_settings_get_n_copies(m_config)); | |
278 | ||
279 | data.SetColour(gtk_print_settings_get_use_color(m_config)); | |
280 | ||
281 | switch (gtk_print_settings_get_duplex(m_config)) | |
282 | { | |
283 | case GTK_PRINT_DUPLEX_SIMPLEX: data.SetDuplex (wxDUPLEX_SIMPLEX); | |
284 | break; | |
285 | ||
286 | case GTK_PRINT_DUPLEX_HORIZONTAL: data.SetDuplex (wxDUPLEX_HORIZONTAL); | |
287 | break; | |
288 | ||
289 | default: | |
290 | case GTK_PRINT_DUPLEX_VERTICAL: data.SetDuplex (wxDUPLEX_VERTICAL); | |
291 | break; | |
292 | } | |
293 | ||
294 | GtkPageOrientation orientation = gtk_print_settings_get_orientation (m_config); | |
295 | if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT) | |
296 | { | |
297 | data.SetOrientation(wxPORTRAIT); | |
298 | data.SetOrientationReversed(false); | |
299 | } | |
300 | else if (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) | |
301 | { | |
302 | data.SetOrientation(wxLANDSCAPE); | |
303 | data.SetOrientationReversed(false); | |
304 | } | |
305 | else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT) | |
306 | { | |
307 | data.SetOrientation(wxPORTRAIT); | |
308 | data.SetOrientationReversed(true); | |
309 | } | |
310 | else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) | |
311 | { | |
312 | data.SetOrientation(wxLANDSCAPE); | |
313 | data.SetOrientationReversed(true); | |
314 | } | |
315 | ||
316 | data.SetCollate(gtk_print_settings_get_collate (m_config)); | |
317 | ||
318 | // Paper formats : these are the most common paper formats. | |
319 | GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (m_config); | |
320 | if (!paper_size) | |
321 | data.SetPaperId(wxPAPER_NONE); | |
322 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A3))) | |
323 | data.SetPaperId(wxPAPER_A3); | |
324 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A4))) | |
325 | data.SetPaperId(wxPAPER_A4); | |
326 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A5))) | |
327 | data.SetPaperId(wxPAPER_A5); | |
328 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_B5))) | |
329 | data.SetPaperId(wxPAPER_B5); | |
330 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_LETTER))) | |
331 | data.SetPaperId(wxPAPER_LETTER); | |
332 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL))) | |
333 | data.SetPaperId(wxPAPER_LEGAL); | |
334 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE))) | |
335 | data.SetPaperId(wxPAPER_EXECUTIVE); | |
336 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na_number-10"))) | |
337 | data.SetPaperId(wxPAPER_ENV_10); | |
338 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c5"))) | |
339 | data.SetPaperId(wxPAPER_ENV_C5); | |
340 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c6"))) | |
341 | data.SetPaperId(wxPAPER_ENV_C6); | |
342 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"jis-b5"))) | |
343 | data.SetPaperId(wxPAPER_B5_TRANSVERSE); | |
344 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b5"))) | |
345 | data.SetPaperId(wxPAPER_ENV_B5); | |
346 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na_monarch"))) | |
347 | data.SetPaperId(wxPAPER_ENV_MONARCH); | |
348 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-c"))) | |
349 | data.SetPaperId( wxPAPER_CSHEET); | |
350 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-d"))) | |
351 | data.SetPaperId( wxPAPER_DSHEET); | |
352 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-e"))) | |
353 | data.SetPaperId( wxPAPER_ESHEET); | |
354 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"letter"))) | |
355 | data.SetPaperId( wxPAPER_LETTERSMALL); | |
356 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-b"))) | |
357 | data.SetPaperId( wxPAPER_TABLOID); | |
358 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"ledger"))) | |
359 | data.SetPaperId( wxPAPER_LEDGER); | |
360 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"statement"))) | |
361 | data.SetPaperId( wxPAPER_STATEMENT); | |
362 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( GTK_PAPER_NAME_A4 ))) | |
363 | data.SetPaperId( wxPAPER_A4SMALL); | |
364 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b4"))) | |
365 | data.SetPaperId( wxPAPER_B4); | |
366 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"folio"))) | |
367 | data.SetPaperId( wxPAPER_FOLIO); | |
368 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"quarto"))) | |
369 | data.SetPaperId( wxPAPER_QUARTO); | |
370 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"10x14"))) | |
371 | data.SetPaperId( wxPAPER_10X14); | |
372 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"ledger"))) | |
373 | data.SetPaperId( wxPAPER_11X17); | |
374 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"letter"))) | |
375 | data.SetPaperId( wxPAPER_NOTE); | |
376 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na-number-9-envelope"))) | |
377 | data.SetPaperId( wxPAPER_ENV_9); | |
378 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-11"))) | |
379 | data.SetPaperId( wxPAPER_ENV_11); | |
380 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-12"))) | |
381 | data.SetPaperId( wxPAPER_ENV_12); | |
382 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-14"))) | |
383 | data.SetPaperId( wxPAPER_ENV_14); | |
384 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-designated"))) | |
385 | data.SetPaperId( wxPAPER_ENV_DL); | |
386 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c3"))) | |
387 | data.SetPaperId( wxPAPER_ENV_C3); | |
388 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c4"))) | |
389 | data.SetPaperId( wxPAPER_ENV_C4); | |
390 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"c6/c5"))) | |
391 | data.SetPaperId( wxPAPER_ENV_C65); | |
392 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b4"))) | |
393 | data.SetPaperId( wxPAPER_ENV_B4); | |
394 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b6"))) | |
395 | data.SetPaperId( wxPAPER_ENV_B6); | |
396 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"Italian"))) | |
397 | data.SetPaperId( wxPAPER_ENV_ITALY); | |
398 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"personal"))) | |
399 | data.SetPaperId( wxPAPER_ENV_PERSONAL); | |
400 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"fanfold-us"))) | |
401 | data.SetPaperId( wxPAPER_FANFOLD_US); | |
402 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"fanfold-European"))) | |
403 | data.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN); | |
404 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"foolscap"))) | |
405 | data.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN); | |
406 | else | |
407 | data.SetPaperId(wxPAPER_NONE); | |
408 | return true; | |
409 | } | |
410 | ||
411 | // Put datas given by the wxPrintData into m_config. | |
412 | // Called by wxPrintData::ConvertToNative(). | |
413 | bool wxGtkPrintNativeData::TransferFrom( const wxPrintData &data ) | |
414 | { | |
415 | if(!m_config) | |
416 | return false; | |
417 | ||
418 | wxPrintQuality quality = data.GetQuality(); | |
419 | if (quality == wxPRINT_QUALITY_HIGH) | |
420 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_HIGH); | |
421 | else if (quality == wxPRINT_QUALITY_MEDIUM) | |
422 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_NORMAL); | |
423 | else if (quality == wxPRINT_QUALITY_LOW) | |
424 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_LOW); | |
425 | else if (quality == wxPRINT_QUALITY_DRAFT) | |
426 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_DRAFT); | |
427 | else if (quality > 1) | |
428 | gtk_print_settings_set_resolution (m_config, quality); | |
429 | else | |
430 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_NORMAL); | |
431 | ||
432 | gtk_print_settings_set_n_copies(m_config, data.GetNoCopies()); | |
433 | ||
434 | gtk_print_settings_set_use_color(m_config, data.GetColour()); | |
435 | ||
436 | switch (data.GetDuplex()) | |
437 | { | |
438 | case wxDUPLEX_SIMPLEX: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_SIMPLEX); | |
439 | break; | |
440 | ||
441 | case wxDUPLEX_HORIZONTAL: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_HORIZONTAL); | |
442 | break; | |
443 | ||
444 | default: | |
445 | case wxDUPLEX_VERTICAL: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_VERTICAL); | |
446 | break; | |
447 | } | |
448 | ||
449 | if (!data.IsOrientationReversed()) | |
450 | { | |
451 | if (data.GetOrientation() == wxLANDSCAPE) | |
452 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_LANDSCAPE); | |
453 | else | |
454 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_PORTRAIT); | |
455 | } | |
456 | else { | |
457 | if (data.GetOrientation() == wxLANDSCAPE) | |
458 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE); | |
459 | else | |
460 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT); | |
461 | } | |
462 | ||
463 | gtk_print_settings_set_collate (m_config, data.GetCollate()); | |
464 | ||
465 | // Paper formats: these are the most common paper formats. | |
466 | switch (data.GetPaperId()) | |
467 | { | |
468 | case wxPAPER_A3: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A3)); | |
469 | break; | |
470 | case wxPAPER_A4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A4)); | |
471 | break; | |
472 | case wxPAPER_A5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A5)); | |
473 | break; | |
474 | case wxPAPER_B5_TRANSVERSE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "jis-b5")); | |
475 | break; | |
476 | case wxPAPER_B5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_B5)); | |
477 | break; | |
478 | case wxPAPER_LETTER: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_LETTER)); | |
479 | break; | |
480 | case wxPAPER_LEGAL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL)); | |
481 | break; | |
482 | case wxPAPER_EXECUTIVE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE)); | |
483 | break; | |
484 | case wxPAPER_ENV_10: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na_number-10")); | |
485 | break; | |
486 | case wxPAPER_ENV_C5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c5")); | |
487 | break; | |
488 | case wxPAPER_ENV_C6: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c6")); | |
489 | break; | |
490 | case wxPAPER_ENV_B5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c5b5")); | |
491 | break; | |
492 | case wxPAPER_ENV_MONARCH: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na_monarch")); | |
493 | break; | |
494 | case wxPAPER_CSHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-c")); | |
495 | break; | |
496 | case wxPAPER_DSHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-d")); | |
497 | break; | |
498 | case wxPAPER_ESHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-e")); | |
499 | break; | |
500 | case wxPAPER_LETTERSMALL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "letter")); | |
501 | break; | |
502 | case wxPAPER_TABLOID: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-b")); | |
503 | break; | |
504 | case wxPAPER_LEDGER: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "ledger")); | |
505 | break; | |
506 | case wxPAPER_STATEMENT: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "statement")); | |
507 | break; | |
508 | case wxPAPER_A4SMALL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A4)); | |
509 | break; | |
510 | case wxPAPER_B4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b4")); | |
511 | break; | |
512 | case wxPAPER_FOLIO: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "folio")); | |
513 | break; | |
514 | case wxPAPER_QUARTO: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "quarto")); | |
515 | break; | |
516 | case wxPAPER_10X14: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "10x14")); | |
517 | break; | |
518 | case wxPAPER_11X17: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "ledger")); | |
519 | break; | |
520 | case wxPAPER_NOTE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "letter")); | |
521 | break; | |
522 | case wxPAPER_ENV_9: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na-number-9-envelope")); | |
523 | break; | |
524 | case wxPAPER_ENV_11: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-11")); | |
525 | break; | |
526 | case wxPAPER_ENV_12: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-12")); | |
527 | break; | |
528 | case wxPAPER_ENV_14: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-14")); | |
529 | break; | |
530 | case wxPAPER_ENV_DL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-designated")); | |
531 | break; | |
532 | case wxPAPER_ENV_C3: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c3")); | |
533 | break; | |
534 | case wxPAPER_ENV_C4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c4")); | |
535 | break; | |
536 | case wxPAPER_ENV_C65: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "c6/c5")); | |
537 | break; | |
538 | case wxPAPER_ENV_B4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b4")); | |
539 | break; | |
540 | case wxPAPER_ENV_B6: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b6")); | |
541 | break; | |
542 | case wxPAPER_ENV_ITALY: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "Italian")); | |
543 | break; | |
544 | case wxPAPER_ENV_PERSONAL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "personal")); | |
545 | break; | |
546 | case wxPAPER_FANFOLD_US: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "fanfold-us")); | |
547 | break; | |
548 | case wxPAPER_FANFOLD_STD_GERMAN: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "fanfold-European")); | |
549 | break; | |
550 | case wxPAPER_FANFOLD_LGL_GERMAN: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "foolscap")); | |
551 | break; | |
552 | case wxPAPER_NONE: | |
553 | default: break; | |
554 | } | |
555 | ||
556 | return true; | |
557 | } | |
558 | ||
559 | void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings * config ) | |
560 | { | |
561 | if (config) | |
562 | m_config = gtk_print_settings_copy(config); | |
563 | } | |
564 | ||
565 | // Extract page setup from settings. | |
566 | GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* settings) | |
567 | { | |
568 | GtkPageSetup* page_setup = gtk_page_setup_new(); | |
a7060b8c | 569 | gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings)); |
fa034c45 | 570 | |
a7060b8c PC |
571 | GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings); |
572 | if (paper_size != NULL) | |
573 | gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size); | |
fa034c45 RR |
574 | |
575 | return page_setup; | |
576 | } | |
577 | ||
578 | // Insert page setup into a given GtkPrintSettings. | |
579 | void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup) | |
580 | { | |
581 | gtk_print_settings_set_orientation ( settings, gtk_page_setup_get_orientation (page_setup)); | |
a7060b8c | 582 | gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup)); |
fa034c45 RR |
583 | } |
584 | ||
585 | //---------------------------------------------------------------------------- | |
586 | // wxGtkPrintDialog | |
587 | //---------------------------------------------------------------------------- | |
588 | ||
589 | IMPLEMENT_CLASS(wxGtkPrintDialog, wxPrintDialogBase) | |
590 | ||
591 | wxGtkPrintDialog::wxGtkPrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
592 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
593 | wxPoint(0, 0), wxSize(600, 600), | |
594 | wxDEFAULT_DIALOG_STYLE | | |
595 | wxTAB_TRAVERSAL) | |
596 | { | |
597 | if (data) | |
598 | m_printDialogData = *data; | |
599 | ||
600 | m_parent = parent; | |
601 | SetShowDialog(true); | |
602 | } | |
603 | ||
604 | wxGtkPrintDialog::wxGtkPrintDialog( wxWindow *parent, wxPrintData *data ) | |
605 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
606 | wxPoint(0, 0), wxSize(600, 600), | |
607 | wxDEFAULT_DIALOG_STYLE | | |
608 | wxTAB_TRAVERSAL) | |
609 | { | |
610 | if (data) | |
611 | m_printDialogData = *data; | |
612 | ||
613 | m_parent = parent; | |
614 | SetShowDialog(true); | |
615 | } | |
616 | ||
617 | ||
618 | wxGtkPrintDialog::~wxGtkPrintDialog() | |
619 | { | |
620 | } | |
621 | ||
622 | // This is called even if we actually don't want the dialog to appear. | |
623 | int wxGtkPrintDialog::ShowModal() | |
624 | { | |
625 | GtkPrintOperationResult response; | |
626 | ||
627 | // We need to restore the settings given in the constructor. | |
628 | wxPrintData data = m_printDialogData.GetPrintData(); | |
629 | wxGtkPrintNativeData *native = | |
630 | (wxGtkPrintNativeData*) data.GetNativeData(); | |
631 | data.ConvertToNative(); | |
632 | ||
633 | GtkPrintSettings * settings = native->GetPrintConfig(); | |
634 | ||
635 | // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData. | |
636 | int fromPage = m_printDialogData.GetFromPage(); | |
637 | int toPage = m_printDialogData.GetToPage(); | |
638 | if (m_printDialogData.GetSelection()) | |
639 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_CURRENT); | |
640 | else if (m_printDialogData.GetAllPages()) | |
641 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_ALL); | |
642 | else { | |
643 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_RANGES); | |
644 | GtkPageRange *range; | |
645 | range = g_new (GtkPageRange, 1); | |
646 | range[0].start = fromPage-1; | |
647 | range[0].end = (toPage >= fromPage) ? toPage-1 : fromPage-1; | |
648 | gtk_print_settings_set_page_ranges (settings, range, 1); | |
649 | } | |
650 | ||
651 | // If the settings are OK, we restore it. | |
652 | if (settings != NULL) | |
653 | gtk_print_operation_set_print_settings (native->GetPrintJob(), settings); | |
a7060b8c | 654 | gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings)); |
fa034c45 RR |
655 | |
656 | // Show the dialog if needed. | |
657 | GError* gError = NULL; | |
658 | if (GetShowDialog()) | |
659 | response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError); | |
660 | else | |
90254df8 | 661 | response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError); |
fa034c45 RR |
662 | |
663 | // Does everything went well? | |
664 | if (response == GTK_PRINT_OPERATION_RESULT_CANCEL) | |
665 | { | |
666 | return wxID_CANCEL; | |
667 | } | |
668 | else if (response == GTK_PRINT_OPERATION_RESULT_ERROR) | |
669 | { | |
670 | g_error_free (gError); | |
671 | wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError->message)); | |
672 | return wxID_NO; // We use wxID_NO because there is no wxID_ERROR available | |
673 | } | |
674 | ||
675 | // Now get the settings and save it. | |
676 | GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings (native->GetPrintJob()); | |
677 | native->SetPrintConfig(newSettings); | |
678 | data.ConvertFromNative(); | |
679 | ||
680 | // Same problem as a few lines before. | |
681 | switch (gtk_print_settings_get_print_pages(newSettings)) | |
682 | { | |
683 | case GTK_PRINT_PAGES_CURRENT: | |
684 | m_printDialogData.SetSelection( true ); | |
685 | break; | |
fa034c45 | 686 | case GTK_PRINT_PAGES_RANGES: |
da249bc3 | 687 | {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others. |
fa034c45 RR |
688 | // For example, the user enters "1-3;5-7" in the dialog: pages 1-3 and 5-7 will be correctly printed when the user |
689 | // will hit "OK" button. However we can only save 1-3 in the print data. | |
690 | gint num_ranges = 0; | |
691 | GtkPageRange* range; | |
692 | range = gtk_print_settings_get_page_ranges (newSettings, &num_ranges); | |
da249bc3 RR |
693 | if (num_ranges >= 1) |
694 | { | |
a7060b8c PC |
695 | m_printDialogData.SetFromPage( range[0].start ); |
696 | m_printDialogData.SetToPage( range[0].end ); | |
da249bc3 RR |
697 | } |
698 | else { | |
699 | m_printDialogData.SetAllPages( true ); | |
700 | m_printDialogData.SetFromPage( 0 ); | |
701 | m_printDialogData.SetToPage( 9999 ); | |
702 | } | |
703 | break;} | |
704 | case GTK_PRINT_PAGES_ALL: | |
705 | default: | |
706 | m_printDialogData.SetAllPages( true ); | |
707 | m_printDialogData.SetFromPage( 0 ); | |
708 | m_printDialogData.SetToPage( 9999 ); | |
fa034c45 RR |
709 | break; |
710 | } | |
711 | ||
712 | return wxID_OK; | |
713 | } | |
714 | ||
715 | //---------------------------------------------------------------------------- | |
716 | // wxGtkPageSetupDialog | |
717 | //---------------------------------------------------------------------------- | |
718 | ||
719 | IMPLEMENT_CLASS(wxGtkPageSetupDialog, wxPageSetupDialogBase) | |
720 | ||
721 | wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow *parent, | |
722 | wxPageSetupDialogData* data ) | |
723 | { | |
724 | if (data) | |
725 | m_pageDialogData = *data; | |
726 | ||
727 | m_parent = parent; | |
728 | } | |
729 | ||
730 | wxGtkPageSetupDialog::~wxGtkPageSetupDialog() | |
731 | { | |
732 | } | |
733 | ||
734 | int wxGtkPageSetupDialog::ShowModal() | |
735 | { | |
736 | // Get the config. | |
737 | m_pageDialogData.GetPrintData().ConvertToNative(); | |
738 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
739 | GtkPrintSettings* nativeData = native->GetPrintConfig(); | |
740 | ||
741 | // We only need the pagesetup data which are part of the settings. | |
742 | GtkPageSetup* oldPageSetup = native->GetPageSetupFromSettings(nativeData); | |
743 | ||
744 | // If the user used a custom paper format the last time he printed, we have to restore it too. | |
745 | if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE) | |
746 | { | |
747 | wxSize customPaperSize = m_pageDialogData.GetPaperSize(); | |
748 | if (customPaperSize.GetWidth() > 0 && customPaperSize.GetHeight() > 0) | |
749 | { | |
750 | wxString title = _("Custom size"); | |
751 | GtkPaperSize* customSize = gtk_paper_size_new_custom ("custom", title.mb_str(), (gdouble) customPaperSize.GetWidth(), (gdouble) customPaperSize.GetHeight(), GTK_UNIT_MM); | |
752 | gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup, customSize); | |
753 | g_object_unref(customSize); | |
754 | } | |
755 | } | |
756 | ||
757 | // Now show the dialog. | |
758 | GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent->m_widget), | |
759 | oldPageSetup, | |
760 | nativeData); | |
761 | ||
762 | int ret; | |
763 | if (newPageSetup != oldPageSetup) | |
764 | { | |
765 | native->SetPageSetupToSettings(nativeData, newPageSetup); | |
766 | m_pageDialogData.GetPrintData().ConvertFromNative(); | |
767 | ||
768 | // Store custom paper format if any. | |
769 | if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE) | |
770 | { | |
771 | gdouble ml,mr,mt,mb,pw,ph; | |
772 | ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM); | |
773 | mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM); | |
774 | mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM); | |
775 | mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM); | |
776 | ||
777 | pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM); | |
778 | ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM); | |
779 | ||
780 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
781 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); | |
782 | ||
783 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); | |
784 | } | |
785 | ||
786 | ret = wxID_OK; | |
787 | } | |
788 | else | |
789 | { | |
790 | ret = wxID_CANCEL; | |
791 | } | |
792 | ||
793 | return ret; | |
794 | } | |
795 | ||
796 | //---------------------------------------------------------------------------- | |
797 | // wxGtkPrinter | |
798 | //---------------------------------------------------------------------------- | |
799 | ||
800 | IMPLEMENT_CLASS(wxGtkPrinter, wxPrinterBase) | |
801 | ||
802 | wxGtkPrinter::wxGtkPrinter( wxPrintDialogData *data ) : | |
803 | wxPrinterBase( data ) | |
804 | { | |
805 | m_gpc = NULL; | |
806 | ||
807 | if (data) | |
808 | m_printDialogData = *data; | |
809 | } | |
810 | ||
811 | wxGtkPrinter::~wxGtkPrinter() | |
812 | { | |
813 | } | |
814 | ||
815 | bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
816 | { | |
817 | if (!printout) | |
818 | { | |
819 | sm_lastError = wxPRINTER_ERROR; | |
820 | return false; | |
821 | } | |
822 | ||
823 | // Let's correct the PageInfo just in case the app gives wrong values. | |
824 | int fromPage, toPage; | |
825 | int minPage, maxPage; | |
826 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
827 | m_printDialogData.SetAllPages(true); | |
828 | ||
829 | if (minPage < 1) minPage = 1; | |
830 | if (maxPage < 1) maxPage = 9999; | |
831 | if (maxPage < minPage) maxPage = minPage; | |
832 | ||
833 | m_printDialogData.SetMinPage(minPage); | |
834 | m_printDialogData.SetMaxPage(maxPage); | |
835 | if (fromPage != 0) | |
836 | { | |
837 | if (fromPage < minPage) fromPage = minPage; | |
838 | else if (fromPage > maxPage) fromPage = maxPage; | |
839 | m_printDialogData.SetFromPage(fromPage); | |
840 | } | |
841 | if (toPage != 0) | |
842 | { | |
843 | m_printDialogData.SetToPage(toPage); | |
844 | if (toPage > maxPage) toPage = maxPage; | |
845 | else if (toPage < minPage) toPage = minPage; | |
846 | } | |
847 | ||
848 | if (((minPage != fromPage) && fromPage != 0) || ((maxPage != toPage) && toPage != 0)) m_printDialogData.SetAllPages(false); | |
849 | ||
850 | ||
851 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
852 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData(); | |
853 | ||
854 | GtkPrintOperation *printOp = gtk_print_operation_new (); | |
855 | ||
856 | native->SetPrintJob( printOp ); | |
857 | ||
858 | printout->SetIsPreview(false); | |
859 | ||
860 | wxPrinterToGtkData dataToSend; | |
861 | dataToSend.printer = this; | |
862 | dataToSend.printout = printout; | |
863 | ||
90254df8 | 864 | // These Gtk signals are caught here. |
fa034c45 RR |
865 | g_signal_connect (printOp, "begin-print", G_CALLBACK (gtk_begin_print_callback), &dataToSend); |
866 | g_signal_connect (printOp, "draw-page", G_CALLBACK (gtk_draw_page_print_callback), &dataToSend); | |
867 | g_signal_connect (printOp, "end-print", G_CALLBACK (gtk_end_print_callback), printout); | |
868 | g_signal_connect (printOp, "preview", G_CALLBACK (gtk_preview_print_callback), printout); | |
869 | ||
90254df8 RR |
870 | // This is used to setup the DC and |
871 | // show the dialog if desired | |
872 | wxGtkPrintDialog dialog( parent, &m_printDialogData ); | |
873 | dialog.SetPrintDC(m_dc); | |
874 | dialog.SetShowDialog(prompt); | |
fa034c45 | 875 | |
90254df8 RR |
876 | // doesn't necessarily show |
877 | int ret = dialog.ShowModal(); | |
878 | if (ret == wxID_CANCEL) | |
879 | { | |
880 | sm_lastError = wxPRINTER_CANCELLED; | |
881 | } | |
882 | if (ret == wxID_NO) | |
883 | { | |
884 | sm_lastError = wxPRINTER_ERROR; | |
885 | wxFAIL_MSG(_("The print dialog returned an error.")); | |
886 | } | |
fa034c45 RR |
887 | |
888 | g_object_unref (printOp); | |
889 | ||
890 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
891 | } | |
892 | ||
893 | void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context) | |
894 | { | |
895 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
896 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData(); | |
897 | ||
23abaeae VZ |
898 | // We need to update printdata with the new data from the dialog and we |
899 | // have to do this here because this method needs this new data and we | |
900 | // cannot update it earlier | |
901 | native->SetPrintConfig(gtk_print_operation_get_print_settings(operation)); | |
902 | printdata.ConvertFromNative(); | |
903 | ||
fa034c45 RR |
904 | SetPrintContext(context); |
905 | native->SetPrintContext( context ); | |
906 | ||
4f37154e | 907 | wxPrinterDC *printDC = new wxPrinterDC( printdata ); |
a9312950 | 908 | m_dc = printDC; |
fa034c45 RR |
909 | |
910 | if (!m_dc->IsOk()) | |
911 | { | |
912 | if (sm_lastError != wxPRINTER_CANCELLED) | |
913 | { | |
914 | sm_lastError = wxPRINTER_ERROR; | |
c8ddadff | 915 | wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used.")); |
fa034c45 RR |
916 | } |
917 | return; | |
918 | } | |
fa034c45 | 919 | |
40fcf546 | 920 | printout->SetPPIScreen(wxGetDisplayPPI()); |
a9312950 RR |
921 | printout->SetPPIPrinter( printDC->GetResolution(), |
922 | printDC->GetResolution() ); | |
fa034c45 RR |
923 | |
924 | printout->SetDC(m_dc); | |
925 | ||
926 | int w, h; | |
927 | m_dc->GetSize(&w, &h); | |
928 | printout->SetPageSizePixels((int)w, (int)h); | |
929 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); | |
930 | int mw, mh; | |
931 | m_dc->GetSizeMM(&mw, &mh); | |
932 | printout->SetPageSizeMM((int)mw, (int)mh); | |
933 | printout->OnPreparePrinting(); | |
934 | ||
935 | // Get some parameters from the printout, if defined. | |
936 | int fromPage, toPage; | |
937 | int minPage, maxPage; | |
938 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
939 | ||
940 | if (maxPage == 0) | |
941 | { | |
942 | sm_lastError = wxPRINTER_ERROR; | |
943 | wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage.")); | |
944 | return; | |
945 | } | |
946 | ||
947 | printout->OnBeginPrinting(); | |
948 | ||
949 | int numPages = 0; | |
950 | ||
951 | // If we're not previewing we need to calculate the number of pages to print. | |
952 | // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may | |
953 | // have defined in the dialog. So the number of pages is the maximum available. | |
954 | if (!printout->IsPreview()) | |
955 | { | |
956 | GtkPrintSettings * settings = gtk_print_operation_get_print_settings (operation); | |
957 | switch (gtk_print_settings_get_print_pages(settings)) | |
958 | { | |
959 | case GTK_PRINT_PAGES_CURRENT: | |
960 | numPages = 1; | |
961 | break; | |
962 | case GTK_PRINT_PAGES_RANGES: | |
963 | {gint num_ranges = 0; | |
964 | GtkPageRange* range; | |
965 | int i; | |
966 | range = gtk_print_settings_get_page_ranges (settings, &num_ranges); | |
967 | for (i=0; i<num_ranges; i++) | |
968 | { | |
969 | if (range[i].end < range[i].start) range[i].end = range[i].start; | |
970 | if (range[i].start < minPage-1) range[i].start = minPage-1; | |
971 | if (range[i].end > maxPage-1) range[i].end = maxPage-1; | |
972 | if (range[i].start > maxPage-1) range[i].start = maxPage-1; | |
973 | numPages += range[i].end - range[i].start + 1; | |
974 | } | |
975 | gtk_print_settings_set_page_ranges (settings, range, 1); | |
976 | break;} | |
977 | case GTK_PRINT_PAGES_ALL: | |
978 | default: | |
979 | numPages = maxPage - minPage + 1; | |
980 | break; | |
981 | } | |
982 | } | |
983 | else numPages = maxPage - minPage + 1; | |
984 | ||
985 | gtk_print_operation_set_n_pages(operation, numPages); | |
986 | } | |
987 | ||
e0d1fd7f VZ |
988 | void wxGtkPrinter::DrawPage(wxPrintout *printout, |
989 | GtkPrintOperation *operation, | |
990 | GtkPrintContext * WXUNUSED(context), | |
991 | int page_nr) | |
fa034c45 RR |
992 | { |
993 | int fromPage, toPage, minPage, maxPage, startPage, endPage; | |
994 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
995 | ||
996 | int numPageToDraw = page_nr + minPage; | |
997 | if (numPageToDraw < minPage) numPageToDraw = minPage; | |
998 | if (numPageToDraw > maxPage) numPageToDraw = maxPage; | |
999 | ||
1000 | GtkPrintSettings * settings = gtk_print_operation_get_print_settings (operation); | |
1001 | switch (gtk_print_settings_get_print_pages(settings)) | |
1002 | { | |
1003 | case GTK_PRINT_PAGES_CURRENT: | |
1004 | g_object_get_property((GObject*) operation, (const gchar *) "current-page", (GValue*) &startPage); | |
1005 | g_object_get_property((GObject*) operation, (const gchar *) "current-page", (GValue*) &endPage); | |
1006 | break; | |
1007 | case GTK_PRINT_PAGES_RANGES: | |
1008 | {gint num_ranges = 0; | |
1009 | GtkPageRange* range; | |
1010 | range = gtk_print_settings_get_page_ranges (settings, &num_ranges); | |
1011 | // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint. | |
da249bc3 RR |
1012 | if (num_ranges >= 1) |
1013 | { | |
a7060b8c PC |
1014 | startPage = range[0].start + 1; |
1015 | endPage = range[0].end + 1; | |
da249bc3 RR |
1016 | } |
1017 | else { | |
1018 | startPage = minPage; | |
1019 | endPage = maxPage; | |
1020 | } | |
fa034c45 RR |
1021 | break;} |
1022 | case GTK_PRINT_PAGES_ALL: | |
1023 | default: | |
1024 | startPage = minPage; | |
1025 | endPage = maxPage; | |
1026 | break; | |
1027 | } | |
1028 | ||
1029 | if(numPageToDraw == startPage) | |
1030 | { | |
1031 | if (!printout->OnBeginDocument(startPage, endPage)) | |
1032 | { | |
1033 | wxLogError(_("Could not start printing.")); | |
1034 | sm_lastError = wxPRINTER_ERROR; | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | // The app can render the page numPageToDraw. | |
1039 | if (printout->HasPage(numPageToDraw)) | |
1040 | { | |
1041 | m_dc->StartPage(); | |
1042 | printout->OnPrintPage(numPageToDraw); | |
1043 | m_dc->EndPage(); | |
1044 | } | |
1045 | ||
1046 | ||
1047 | if(numPageToDraw == endPage) | |
1048 | { | |
1049 | printout->OnEndDocument(); | |
1050 | } | |
1051 | } | |
1052 | ||
1053 | wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent ) | |
1054 | { | |
1055 | wxGtkPrintDialog dialog( parent, &m_printDialogData ); | |
fa034c45 RR |
1056 | |
1057 | dialog.SetPrintDC(m_dc); | |
90254df8 | 1058 | dialog.SetShowDialog(true); |
fa034c45 | 1059 | |
90254df8 | 1060 | int ret = dialog.ShowModal(); |
fa034c45 RR |
1061 | |
1062 | if (ret == wxID_CANCEL) | |
1063 | { | |
1064 | sm_lastError = wxPRINTER_CANCELLED; | |
1065 | return NULL; | |
1066 | } | |
1067 | if (ret == wxID_NO) | |
1068 | { | |
1069 | sm_lastError = wxPRINTER_ERROR; | |
1070 | wxFAIL_MSG(_("The print dialog returned an error.")); | |
1071 | return NULL; | |
1072 | } | |
1073 | ||
1074 | m_printDialogData = dialog.GetPrintDialogData(); | |
6d52ca53 | 1075 | |
4f37154e | 1076 | return new wxPrinterDC( m_printDialogData.GetPrintData() ); |
fa034c45 RR |
1077 | } |
1078 | ||
e0d1fd7f | 1079 | bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) ) |
fa034c45 RR |
1080 | { |
1081 | // Obsolete, for backward compatibility. | |
1082 | return false; | |
1083 | } | |
1084 | ||
1085 | //----------------------------------------------------------------------------- | |
c8ddadff | 1086 | // wxGtkPrinterDC |
fa034c45 RR |
1087 | //----------------------------------------------------------------------------- |
1088 | ||
eaeb9985 RR |
1089 | #define wxCAIRO_SCALE 1 |
1090 | ||
1091 | #if wxCAIRO_SCALE | |
1092 | ||
1093 | #define XLOG2DEV(x) LogicalToDeviceX(x) | |
1094 | #define XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
1095 | #define YLOG2DEV(x) LogicalToDeviceY(x) | |
1096 | #define YLOG2DEVREL(x) LogicalToDeviceYRel(x) | |
1097 | ||
1098 | #else | |
1099 | ||
a9312950 RR |
1100 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS) |
1101 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS) | |
1102 | #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS) | |
1103 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS) | |
fa034c45 | 1104 | |
eaeb9985 | 1105 | #endif |
fa034c45 | 1106 | |
888dde65 | 1107 | IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl) |
4f37154e | 1108 | |
115be92b VZ |
1109 | wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data) |
1110 | : wxDCImpl( owner ) | |
fa034c45 RR |
1111 | { |
1112 | m_printData = data; | |
1113 | ||
1114 | wxGtkPrintNativeData *native = | |
1115 | (wxGtkPrintNativeData*) m_printData.GetNativeData(); | |
1116 | ||
1117 | m_gpc = native->GetPrintContext(); | |
1118 | ||
90254df8 | 1119 | // Match print quality to resolution (high = 1200dpi) |
a9312950 | 1120 | m_resolution = m_printData.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc ); |
a7060b8c | 1121 | if (m_resolution < 0) |
a9312950 RR |
1122 | m_resolution = (1 << (m_resolution+4)) *150; |
1123 | ||
fa034c45 RR |
1124 | m_context = gtk_print_context_create_pango_context( m_gpc ); |
1125 | m_layout = gtk_print_context_create_pango_layout ( m_gpc ); | |
1126 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
1127 | ||
1128 | m_cairo = gtk_print_context_get_cairo_context ( m_gpc ); | |
1129 | ||
eaeb9985 RR |
1130 | #if wxCAIRO_SCALE |
1131 | m_PS2DEV = 1.0; | |
1132 | m_DEV2PS = 1.0; | |
6d52ca53 | 1133 | |
f7b8e3d6 | 1134 | cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution ); |
eaeb9985 RR |
1135 | #else |
1136 | m_PS2DEV = (double)m_resolution / 72.0; | |
1137 | m_DEV2PS = 72.0 / (double)m_resolution; | |
1138 | #endif | |
1139 | ||
fa034c45 RR |
1140 | m_currentRed = 0; |
1141 | m_currentBlue = 0; | |
1142 | m_currentGreen = 0; | |
1143 | ||
90254df8 | 1144 | m_signX = 1; // default x-axis left to right. |
fa034c45 | 1145 | m_signY = 1; // default y-axis bottom up -> top down. |
da249bc3 | 1146 | |
e0d1fd7f | 1147 | // By default the origin of the Cairo context is in the upper left |
90254df8 RR |
1148 | // corner of the printable area. We need to translate it so that it |
1149 | // is in the upper left corner of the paper (without margins) | |
da249bc3 RR |
1150 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
1151 | gdouble ml, mt; | |
1152 | ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS); | |
1153 | mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); | |
f7b8e3d6 | 1154 | cairo_translate(m_cairo, -ml, -mt); |
fa034c45 RR |
1155 | } |
1156 | ||
888dde65 | 1157 | wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl() |
fa034c45 RR |
1158 | { |
1159 | g_object_unref(m_context); | |
1160 | g_object_unref(m_layout); | |
1161 | } | |
1162 | ||
888dde65 | 1163 | bool wxGtkPrinterDCImpl::IsOk() const |
fa034c45 | 1164 | { |
e0d1fd7f | 1165 | return m_gpc != NULL; |
fa034c45 RR |
1166 | } |
1167 | ||
0b822969 | 1168 | void* wxGtkPrinterDCImpl::GetCairoContext() const |
2b44ffc0 | 1169 | { |
f7b8e3d6 | 1170 | return (void*) cairo_reference( m_cairo ); |
2b44ffc0 | 1171 | } |
2b44ffc0 | 1172 | |
888dde65 | 1173 | bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), |
e0d1fd7f VZ |
1174 | wxCoord WXUNUSED(y1), |
1175 | const wxColour& WXUNUSED(col), | |
89efaf2b | 1176 | wxFloodFillStyle WXUNUSED(style)) |
fa034c45 | 1177 | { |
e0d1fd7f VZ |
1178 | // We can't access the given coord as a Cairo context is scalable, ie a |
1179 | // coord doesn't mean anything in this context. | |
fa034c45 RR |
1180 | wxFAIL_MSG(_("not implemented")); |
1181 | return false; | |
1182 | } | |
1183 | ||
888dde65 | 1184 | void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter) |
fa034c45 RR |
1185 | { |
1186 | wxCoord xC = circleCenter.x; | |
1187 | wxCoord yC = circleCenter.y; | |
1188 | wxCoord xR = rect.x; | |
1189 | wxCoord yR = rect.y; | |
1190 | wxCoord w = rect.width; | |
1191 | wxCoord h = rect.height; | |
1192 | ||
d31d30d7 VZ |
1193 | const double r2 = (w/2)*(w/2)+(h/2)*(h/2); |
1194 | double radius = sqrt(r2); | |
fa034c45 RR |
1195 | |
1196 | unsigned char redI = initialColour.Red(); | |
1197 | unsigned char blueI = initialColour.Blue(); | |
1198 | unsigned char greenI = initialColour.Green(); | |
1199 | unsigned char alphaI = initialColour.Alpha(); | |
1200 | unsigned char redD = destColour.Red(); | |
1201 | unsigned char blueD = destColour.Blue(); | |
1202 | unsigned char greenD = destColour.Green(); | |
1203 | unsigned char alphaD = destColour.Alpha(); | |
1204 | ||
1205 | double redIPS = (double)(redI) / 255.0; | |
1206 | double blueIPS = (double)(blueI) / 255.0; | |
1207 | double greenIPS = (double)(greenI) / 255.0; | |
1208 | double alphaIPS = (double)(alphaI) / 255.0; | |
1209 | double redDPS = (double)(redD) / 255.0; | |
1210 | double blueDPS = (double)(blueD) / 255.0; | |
1211 | double greenDPS = (double)(greenD) / 255.0; | |
1212 | double alphaDPS = (double)(alphaD) / 255.0; | |
1213 | ||
1214 | // Create a pattern with the gradient. | |
1215 | cairo_pattern_t* gradient; | |
f7b8e3d6 VS |
1216 | gradient = cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), radius * m_DEV2PS ); |
1217 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS); | |
1218 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS); | |
fa034c45 RR |
1219 | |
1220 | // Fill the rectangle with this pattern. | |
f7b8e3d6 VS |
1221 | cairo_set_source(m_cairo, gradient); |
1222 | cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) ); | |
1223 | cairo_fill(m_cairo); | |
fa034c45 | 1224 | |
f7b8e3d6 | 1225 | cairo_pattern_destroy(gradient); |
fa034c45 RR |
1226 | |
1227 | CalcBoundingBox(xR, yR); | |
1228 | CalcBoundingBox(xR+w, yR+h); | |
1229 | } | |
1230 | ||
888dde65 | 1231 | void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection) |
fa034c45 RR |
1232 | { |
1233 | wxCoord x = rect.x; | |
1234 | wxCoord y = rect.y; | |
1235 | wxCoord w = rect.width; | |
1236 | wxCoord h = rect.height; | |
1237 | ||
1238 | unsigned char redI = initialColour.Red(); | |
1239 | unsigned char blueI = initialColour.Blue(); | |
1240 | unsigned char greenI = initialColour.Green(); | |
1241 | unsigned char alphaI = initialColour.Alpha(); | |
1242 | unsigned char redD = destColour.Red(); | |
1243 | unsigned char blueD = destColour.Blue(); | |
1244 | unsigned char greenD = destColour.Green(); | |
1245 | unsigned char alphaD = destColour.Alpha(); | |
1246 | ||
1247 | double redIPS = (double)(redI) / 255.0; | |
1248 | double blueIPS = (double)(blueI) / 255.0; | |
1249 | double greenIPS = (double)(greenI) / 255.0; | |
1250 | double alphaIPS = (double)(alphaI) / 255.0; | |
1251 | double redDPS = (double)(redD) / 255.0; | |
1252 | double blueDPS = (double)(blueD) / 255.0; | |
1253 | double greenDPS = (double)(greenD) / 255.0; | |
1254 | double alphaDPS = (double)(alphaD) / 255.0; | |
1255 | ||
1256 | // Create a pattern with the gradient. | |
1257 | cairo_pattern_t* gradient; | |
f7b8e3d6 | 1258 | gradient = cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y)); |
fa034c45 RR |
1259 | |
1260 | if (nDirection == wxWEST) | |
1261 | { | |
f7b8e3d6 VS |
1262 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redDPS, greenDPS, blueDPS, alphaDPS); |
1263 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redIPS, greenIPS, blueIPS, alphaIPS); | |
fa034c45 RR |
1264 | } |
1265 | else { | |
f7b8e3d6 VS |
1266 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS); |
1267 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS); | |
fa034c45 RR |
1268 | } |
1269 | ||
1270 | // Fill the rectangle with this pattern. | |
f7b8e3d6 VS |
1271 | cairo_set_source(m_cairo, gradient); |
1272 | cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) ); | |
1273 | cairo_fill(m_cairo); | |
fa034c45 | 1274 | |
f7b8e3d6 | 1275 | cairo_pattern_destroy(gradient); |
fa034c45 RR |
1276 | |
1277 | CalcBoundingBox(x, y); | |
1278 | CalcBoundingBox(x+w, y+h); | |
1279 | } | |
1280 | ||
888dde65 | 1281 | bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1), |
e0d1fd7f VZ |
1282 | wxCoord WXUNUSED(y1), |
1283 | wxColour * WXUNUSED(col)) const | |
fa034c45 | 1284 | { |
fa034c45 RR |
1285 | wxFAIL_MSG(_("not implemented")); |
1286 | return false; | |
1287 | } | |
1288 | ||
888dde65 | 1289 | void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
fa034c45 | 1290 | { |
04ee05f9 | 1291 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
fa034c45 RR |
1292 | |
1293 | SetPen( m_pen ); | |
f7b8e3d6 VS |
1294 | cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) ); |
1295 | cairo_line_to ( m_cairo, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
1296 | cairo_stroke ( m_cairo ); | |
fa034c45 RR |
1297 | |
1298 | CalcBoundingBox( x1, y1 ); | |
1299 | CalcBoundingBox( x2, y2 ); | |
1300 | } | |
1301 | ||
888dde65 | 1302 | void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y) |
fa034c45 | 1303 | { |
a9312950 RR |
1304 | int w, h; |
1305 | DoGetSize(&w, &h); | |
fa034c45 RR |
1306 | |
1307 | SetPen(m_pen); | |
1308 | ||
f7b8e3d6 VS |
1309 | cairo_move_to (m_cairo, XLOG2DEV(x), 0); |
1310 | cairo_line_to (m_cairo, XLOG2DEV(x), YLOG2DEVREL(h)); | |
1311 | cairo_move_to (m_cairo, 0, YLOG2DEV(y)); | |
1312 | cairo_line_to (m_cairo, XLOG2DEVREL(w), YLOG2DEV(y)); | |
fa034c45 | 1313 | |
f7b8e3d6 | 1314 | cairo_stroke (m_cairo); |
fa034c45 | 1315 | CalcBoundingBox( 0, 0 ); |
a9312950 | 1316 | CalcBoundingBox( w, h ); |
fa034c45 RR |
1317 | } |
1318 | ||
888dde65 | 1319 | void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) |
fa034c45 RR |
1320 | { |
1321 | double dx = x1 - xc; | |
1322 | double dy = y1 - yc; | |
1323 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
1324 | ||
1325 | double alpha1, alpha2; | |
1326 | if (x1 == x2 && y1 == y2) | |
1327 | { | |
1328 | alpha1 = 0.0; | |
1329 | alpha2 = 360.0; | |
1330 | } | |
1331 | else | |
1332 | if (radius == 0.0) | |
1333 | { | |
1334 | alpha1 = alpha2 = 0.0; | |
1335 | } | |
1336 | else | |
1337 | { | |
1338 | alpha1 = (x1 - xc == 0) ? | |
1339 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
1340 | atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
1341 | alpha2 = (x2 - xc == 0) ? | |
1342 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
1343 | atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
1344 | ||
1345 | while (alpha1 <= 0) alpha1 += 360; | |
1346 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between. | |
1347 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree. | |
1348 | while (alpha2 > 360) alpha2 -= 360; | |
1349 | } | |
1350 | ||
1351 | alpha1 *= DEG2RAD; | |
1352 | alpha2 *= DEG2RAD; | |
1353 | ||
f7b8e3d6 | 1354 | cairo_new_path(m_cairo); |
da249bc3 | 1355 | |
f7b8e3d6 VS |
1356 | cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2); |
1357 | cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc)); | |
1358 | cairo_close_path (m_cairo); | |
fa034c45 RR |
1359 | |
1360 | SetBrush( m_brush ); | |
f7b8e3d6 | 1361 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1362 | |
1363 | SetPen (m_pen); | |
f7b8e3d6 | 1364 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1365 | |
1366 | CalcBoundingBox (x1, y1); | |
1367 | CalcBoundingBox (xc, yc); | |
1368 | CalcBoundingBox (x2, y2); | |
1369 | } | |
1370 | ||
888dde65 | 1371 | void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) |
fa034c45 | 1372 | { |
f7b8e3d6 | 1373 | cairo_save( m_cairo ); |
fa034c45 | 1374 | |
f7b8e3d6 | 1375 | cairo_new_path(m_cairo); |
da249bc3 | 1376 | |
f7b8e3d6 | 1377 | cairo_translate( m_cairo, XLOG2DEV((wxCoord) (x + w / 2.)), XLOG2DEV((wxCoord) (y + h / 2.)) ); |
a9312950 | 1378 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); |
f7b8e3d6 | 1379 | cairo_scale( m_cairo, 1.0, scale ); |
fa034c45 | 1380 | |
f7b8e3d6 | 1381 | cairo_arc_negative ( m_cairo, 0, 0, XLOG2DEVREL(w/2), -sa*DEG2RAD, -ea*DEG2RAD); |
fa034c45 RR |
1382 | |
1383 | SetPen (m_pen); | |
f7b8e3d6 | 1384 | cairo_stroke_preserve( m_cairo ); |
fa034c45 | 1385 | |
f7b8e3d6 | 1386 | cairo_line_to(m_cairo, 0,0); |
fa034c45 RR |
1387 | |
1388 | SetBrush( m_brush ); | |
f7b8e3d6 | 1389 | cairo_fill( m_cairo ); |
fa034c45 | 1390 | |
f7b8e3d6 | 1391 | cairo_restore( m_cairo ); |
fa034c45 RR |
1392 | |
1393 | CalcBoundingBox( x, y); | |
1394 | CalcBoundingBox( x+w, y+h ); | |
1395 | } | |
1396 | ||
888dde65 | 1397 | void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y) |
fa034c45 | 1398 | { |
04ee05f9 | 1399 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
fa034c45 RR |
1400 | |
1401 | SetPen( m_pen ); | |
1402 | ||
f7b8e3d6 VS |
1403 | cairo_move_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); |
1404 | cairo_line_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); | |
1405 | cairo_stroke ( m_cairo ); | |
fa034c45 RR |
1406 | |
1407 | CalcBoundingBox( x, y ); | |
1408 | } | |
1409 | ||
888dde65 | 1410 | void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
fa034c45 | 1411 | { |
04ee05f9 | 1412 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
fa034c45 RR |
1413 | |
1414 | if (n <= 0) return; | |
1415 | ||
1416 | SetPen (m_pen); | |
1417 | ||
1418 | int i; | |
1419 | for ( i =0; i<n ; i++ ) | |
1420 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); | |
1421 | ||
f7b8e3d6 | 1422 | cairo_move_to ( m_cairo, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
fa034c45 RR |
1423 | |
1424 | for (i = 1; i < n; i++) | |
f7b8e3d6 | 1425 | cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
fa034c45 | 1426 | |
f7b8e3d6 | 1427 | cairo_stroke ( m_cairo); |
fa034c45 RR |
1428 | } |
1429 | ||
03647350 VZ |
1430 | void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], |
1431 | wxCoord xoffset, wxCoord yoffset, | |
89efaf2b | 1432 | wxPolygonFillMode fillStyle) |
fa034c45 RR |
1433 | { |
1434 | if (n==0) return; | |
1435 | ||
f7b8e3d6 | 1436 | cairo_save(m_cairo); |
fa034c45 | 1437 | if (fillStyle == wxWINDING_RULE) |
f7b8e3d6 | 1438 | cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_WINDING); |
fa034c45 | 1439 | else |
f7b8e3d6 | 1440 | cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_EVEN_ODD); |
fa034c45 RR |
1441 | |
1442 | int x = points[0].x + xoffset; | |
1443 | int y = points[0].y + yoffset; | |
f7b8e3d6 VS |
1444 | cairo_new_path(m_cairo); |
1445 | cairo_move_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); | |
fa034c45 RR |
1446 | int i; |
1447 | for (i = 1; i < n; i++) | |
1448 | { | |
1449 | int x = points[i].x + xoffset; | |
1450 | int y = points[i].y + yoffset; | |
f7b8e3d6 | 1451 | cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); |
fa034c45 | 1452 | } |
f7b8e3d6 | 1453 | cairo_close_path(m_cairo); |
fa034c45 RR |
1454 | |
1455 | SetBrush( m_brush ); | |
f7b8e3d6 | 1456 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1457 | |
1458 | SetPen (m_pen); | |
f7b8e3d6 | 1459 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1460 | |
1461 | CalcBoundingBox( x, y ); | |
1462 | ||
f7b8e3d6 | 1463 | cairo_restore(m_cairo); |
fa034c45 RR |
1464 | } |
1465 | ||
89efaf2b | 1466 | void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
03647350 | 1467 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 1468 | wxPolygonFillMode fillStyle) |
fa034c45 | 1469 | { |
888dde65 | 1470 | wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
fa034c45 RR |
1471 | } |
1472 | ||
888dde65 | 1473 | void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 1474 | { |
728ddc45 RR |
1475 | width--; |
1476 | height--; | |
1477 | ||
f7b8e3d6 VS |
1478 | cairo_new_path(m_cairo); |
1479 | cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); | |
fa034c45 RR |
1480 | |
1481 | SetBrush( m_brush ); | |
f7b8e3d6 | 1482 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1483 | |
1484 | SetPen (m_pen); | |
f7b8e3d6 | 1485 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1486 | |
1487 | CalcBoundingBox( x, y ); | |
1488 | CalcBoundingBox( x + width, y + height ); | |
1489 | } | |
1490 | ||
888dde65 | 1491 | void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
fa034c45 | 1492 | { |
728ddc45 RR |
1493 | width--; |
1494 | height--; | |
1495 | ||
fa034c45 RR |
1496 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); |
1497 | ||
1498 | wxCoord dd = 2 * (wxCoord) radius; | |
1499 | if (dd > width) dd = width; | |
1500 | if (dd > height) dd = height; | |
1501 | radius = dd / 2; | |
1502 | ||
1503 | wxCoord rad = (wxCoord) radius; | |
1504 | ||
f7b8e3d6 VS |
1505 | cairo_new_path(m_cairo); |
1506 | cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1507 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1508 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1509 | XLOG2DEV(x),YLOG2DEV(y), | |
1510 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
f7b8e3d6 VS |
1511 | cairo_line_to(m_cairo,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1512 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1513 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1514 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1515 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
f7b8e3d6 VS |
1516 | cairo_line_to(m_cairo,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1517 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1518 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1519 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1520 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
f7b8e3d6 VS |
1521 | cairo_line_to(m_cairo,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1522 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1523 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1524 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1525 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
f7b8e3d6 VS |
1526 | cairo_line_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1527 | cairo_close_path(m_cairo); | |
fa034c45 RR |
1528 | |
1529 | SetBrush(m_brush); | |
f7b8e3d6 | 1530 | cairo_fill_preserve(m_cairo); |
fa034c45 RR |
1531 | |
1532 | SetPen(m_pen); | |
f7b8e3d6 | 1533 | cairo_stroke(m_cairo); |
fa034c45 RR |
1534 | |
1535 | CalcBoundingBox(x,y); | |
1536 | CalcBoundingBox(x+width,y+height); | |
1537 | } | |
1538 | ||
888dde65 | 1539 | void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 1540 | { |
728ddc45 RR |
1541 | width--; |
1542 | height--; | |
1543 | ||
f7b8e3d6 | 1544 | cairo_save (m_cairo); |
fa034c45 | 1545 | |
f7b8e3d6 | 1546 | cairo_new_path(m_cairo); |
da249bc3 | 1547 | |
f7b8e3d6 VS |
1548 | cairo_translate (m_cairo, XLOG2DEV((wxCoord) (x + width / 2.)), YLOG2DEV((wxCoord) (y + height / 2.))); |
1549 | cairo_scale(m_cairo, 1, (double)YLOG2DEVREL(height)/(double)XLOG2DEVREL(width)); | |
1550 | cairo_arc ( m_cairo, 0, 0, XLOG2DEVREL(width/2), 0, 2 * M_PI); | |
fa034c45 RR |
1551 | |
1552 | SetBrush( m_brush ); | |
f7b8e3d6 | 1553 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1554 | |
1555 | SetPen (m_pen); | |
f7b8e3d6 | 1556 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1557 | |
1558 | CalcBoundingBox( x, y ); | |
1559 | CalcBoundingBox( x + width, y + height ); | |
1560 | ||
f7b8e3d6 | 1561 | cairo_restore (m_cairo); |
fa034c45 RR |
1562 | } |
1563 | ||
1564 | #if wxUSE_SPLINES | |
888dde65 | 1565 | void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points) |
fa034c45 RR |
1566 | { |
1567 | SetPen (m_pen); | |
1568 | ||
1569 | double c, d, x1, y1, x2, y2, x3, y3; | |
1570 | wxPoint *p, *q; | |
1571 | ||
b0d7707b RR |
1572 | wxPointList::compatibility_iterator node = points->GetFirst(); |
1573 | p = node->GetData(); | |
fa034c45 RR |
1574 | x1 = p->x; |
1575 | y1 = p->y; | |
1576 | ||
1577 | node = node->GetNext(); | |
b0d7707b | 1578 | p = node->GetData(); |
fa034c45 RR |
1579 | c = p->x; |
1580 | d = p->y; | |
1581 | x3 = | |
1582 | (double)(x1 + c) / 2; | |
1583 | y3 = | |
1584 | (double)(y1 + d) / 2; | |
1585 | ||
f7b8e3d6 VS |
1586 | cairo_new_path( m_cairo ); |
1587 | cairo_move_to( m_cairo, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1588 | cairo_line_to( m_cairo, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
fa034c45 RR |
1589 | |
1590 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1591 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1592 | ||
1593 | node = node->GetNext(); | |
1594 | while (node) | |
1595 | { | |
b0d7707b | 1596 | q = node->GetData(); |
fa034c45 RR |
1597 | |
1598 | x1 = x3; | |
1599 | y1 = y3; | |
1600 | x2 = c; | |
1601 | y2 = d; | |
1602 | c = q->x; | |
1603 | d = q->y; | |
1604 | x3 = (double)(x2 + c) / 2; | |
1605 | y3 = (double)(y2 + d) / 2; | |
1606 | ||
f7b8e3d6 | 1607 | cairo_curve_to(m_cairo, |
5cdcb787 RR |
1608 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
1609 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1610 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
fa034c45 RR |
1611 | |
1612 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1613 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1614 | ||
1615 | node = node->GetNext(); | |
1616 | } | |
1617 | ||
f7b8e3d6 | 1618 | cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
fa034c45 | 1619 | |
f7b8e3d6 | 1620 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1621 | } |
1622 | #endif // wxUSE_SPLINES | |
1623 | ||
888dde65 | 1624 | bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, |
e0d1fd7f VZ |
1625 | wxCoord width, wxCoord height, |
1626 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
89efaf2b | 1627 | wxRasterOperationMode rop, bool useMask, |
e0d1fd7f VZ |
1628 | wxCoord WXUNUSED_UNLESS_DEBUG(xsrcMask), |
1629 | wxCoord WXUNUSED_UNLESS_DEBUG(ysrcMask)) | |
fa034c45 | 1630 | { |
e0d1fd7f VZ |
1631 | wxASSERT_MSG( xsrcMask == wxDefaultCoord && ysrcMask == wxDefaultCoord, |
1632 | wxT("mask coordinates are not supported") ); | |
1633 | ||
fa034c45 RR |
1634 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1635 | ||
1636 | // Blit into a bitmap. | |
1637 | wxBitmap bitmap( width, height ); | |
1638 | wxMemoryDC memDC; | |
1639 | memDC.SelectObject(bitmap); | |
1640 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); | |
1641 | memDC.SelectObject(wxNullBitmap); | |
1642 | ||
1643 | // Draw bitmap. scaling and positioning is done there. | |
4f37154e | 1644 | GetOwner()->DrawBitmap( bitmap, xdest, ydest, useMask ); |
fa034c45 RR |
1645 | |
1646 | return true; | |
1647 | } | |
1648 | ||
888dde65 | 1649 | void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) |
fa034c45 RR |
1650 | { |
1651 | DoDrawBitmap( icon, x, y, true ); | |
1652 | } | |
1653 | ||
888dde65 | 1654 | void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) |
fa034c45 | 1655 | { |
888dde65 | 1656 | wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap")); |
fa034c45 | 1657 | |
5cdcb787 RR |
1658 | x = wxCoord(XLOG2DEV(x)); |
1659 | y = wxCoord(YLOG2DEV(y)); | |
fa034c45 RR |
1660 | int bw = bitmap.GetWidth(); |
1661 | int bh = bitmap.GetHeight(); | |
1662 | wxBitmap bmpSource = bitmap; // we need a non-const instance. | |
fb14d960 PC |
1663 | if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask()) |
1664 | bmpSource.SetMask(NULL); | |
fa034c45 | 1665 | |
f7b8e3d6 | 1666 | cairo_save(m_cairo); |
fa034c45 RR |
1667 | |
1668 | // Prepare to draw the image. | |
f7b8e3d6 | 1669 | cairo_translate(m_cairo, x, y); |
4d1d071d RR |
1670 | |
1671 | // Scale the image | |
5cdcb787 RR |
1672 | wxDouble scaleX = (wxDouble) XLOG2DEVREL(bw) / (wxDouble) bw; |
1673 | wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh; | |
f7b8e3d6 | 1674 | cairo_scale(m_cairo, scaleX, scaleY); |
4d1d071d | 1675 | |
fb14d960 PC |
1676 | gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0); |
1677 | cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST); | |
fa034c45 | 1678 | // Use the original size here since the context is scaled already. |
f7b8e3d6 | 1679 | cairo_rectangle(m_cairo, 0, 0, bw, bh); |
fa034c45 | 1680 | // Fill the rectangle using the pattern. |
f7b8e3d6 | 1681 | cairo_fill(m_cairo); |
fa034c45 | 1682 | |
fa034c45 RR |
1683 | CalcBoundingBox(0,0); |
1684 | CalcBoundingBox(bw,bh); | |
1685 | ||
f7b8e3d6 | 1686 | cairo_restore(m_cairo); |
fa034c45 RR |
1687 | } |
1688 | ||
888dde65 | 1689 | void wxGtkPrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) |
fa034c45 RR |
1690 | { |
1691 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1692 | } | |
1693 | ||
888dde65 | 1694 | void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
fa034c45 | 1695 | { |
a9312950 RR |
1696 | double xx = XLOG2DEV(x); |
1697 | double yy = YLOG2DEV(y); | |
fa034c45 RR |
1698 | |
1699 | angle = -angle; | |
1700 | ||
1701 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); | |
1702 | ||
197380a0 | 1703 | const wxScopedCharBuffer data = text.utf8_str(); |
fa034c45 RR |
1704 | |
1705 | size_t datalen = strlen(data); | |
1706 | pango_layout_set_text( m_layout, data, datalen); | |
1707 | ||
1708 | if (underlined) | |
1709 | { | |
1710 | PangoAttrList *attrs = pango_attr_list_new(); | |
1711 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1712 | a->start_index = 0; | |
1713 | a->end_index = datalen; | |
1714 | pango_attr_list_insert(attrs, a); | |
1715 | pango_layout_set_attributes(m_layout, attrs); | |
1716 | pango_attr_list_unref(attrs); | |
1717 | } | |
1718 | ||
1719 | if (m_textForegroundColour.Ok()) | |
1720 | { | |
1721 | unsigned char red = m_textForegroundColour.Red(); | |
1722 | unsigned char blue = m_textForegroundColour.Blue(); | |
1723 | unsigned char green = m_textForegroundColour.Green(); | |
1724 | unsigned char alpha = m_textForegroundColour.Alpha(); | |
1725 | ||
1726 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1727 | { | |
1728 | double redPS = (double)(red) / 255.0; | |
1729 | double bluePS = (double)(blue) / 255.0; | |
1730 | double greenPS = (double)(green) / 255.0; | |
1731 | double alphaPS = (double)(alpha) / 255.0; | |
1732 | ||
f7b8e3d6 | 1733 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1734 | |
1735 | m_currentRed = red; | |
1736 | m_currentBlue = blue; | |
1737 | m_currentGreen = green; | |
1738 | m_currentAlpha = alpha; | |
1739 | } | |
1740 | } | |
1741 | ||
a9312950 | 1742 | // Draw layout. |
f7b8e3d6 | 1743 | cairo_move_to (m_cairo, xx, yy); |
a7060b8c | 1744 | |
f7b8e3d6 | 1745 | cairo_save( m_cairo ); |
a7060b8c | 1746 | |
a9312950 | 1747 | if (fabs(angle) > 0.00001) |
f7b8e3d6 | 1748 | cairo_rotate( m_cairo, angle*DEG2RAD ); |
a7060b8c | 1749 | |
12ca5586 VS |
1750 | cairo_scale(m_cairo, m_scaleX, m_scaleY); |
1751 | ||
1752 | int w,h; | |
1753 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1754 | ||
1755 | if ( m_backgroundMode == wxBRUSHSTYLE_SOLID ) | |
1756 | { | |
1757 | unsigned char red = m_textBackgroundColour.Red(); | |
1758 | unsigned char blue = m_textBackgroundColour.Blue(); | |
1759 | unsigned char green = m_textBackgroundColour.Green(); | |
1760 | unsigned char alpha = m_textBackgroundColour.Alpha(); | |
1761 | ||
1762 | double redPS = (double)(red) / 255.0; | |
1763 | double bluePS = (double)(blue) / 255.0; | |
1764 | double greenPS = (double)(green) / 255.0; | |
1765 | double alphaPS = (double)(alpha) / 255.0; | |
1766 | ||
1767 | cairo_save(m_cairo); | |
1768 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); | |
1769 | cairo_rectangle(m_cairo, 0, 0, w, h); // still in cairo units | |
1770 | cairo_fill(m_cairo); | |
1771 | cairo_restore(m_cairo); | |
1772 | } | |
1773 | ||
f7b8e3d6 VS |
1774 | pango_cairo_update_layout (m_cairo, m_layout); |
1775 | pango_cairo_show_layout (m_cairo, m_layout); | |
a7060b8c | 1776 | |
f7b8e3d6 | 1777 | cairo_restore( m_cairo ); |
fa034c45 RR |
1778 | |
1779 | if (underlined) | |
1780 | { | |
1781 | // Undo underline attributes setting | |
1782 | pango_layout_set_attributes(m_layout, NULL); | |
1783 | } | |
a7060b8c | 1784 | |
1d9fe50d | 1785 | // Back to device units: |
a9312950 RR |
1786 | CalcBoundingBox (x, y); |
1787 | CalcBoundingBox (x + w, y + h); | |
fa034c45 RR |
1788 | } |
1789 | ||
888dde65 | 1790 | void wxGtkPrinterDCImpl::Clear() |
fa034c45 | 1791 | { |
0187f0bc | 1792 | // Clear does nothing for printing, but keep the code |
6d52ca53 | 1793 | // for later reuse |
0187f0bc | 1794 | /* |
f7b8e3d6 VS |
1795 | cairo_save(m_cairo); |
1796 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE); | |
fa034c45 | 1797 | SetBrush(m_backgroundBrush); |
f7b8e3d6 VS |
1798 | cairo_paint(m_cairo); |
1799 | cairo_restore(m_cairo); | |
0187f0bc | 1800 | */ |
fa034c45 RR |
1801 | } |
1802 | ||
888dde65 | 1803 | void wxGtkPrinterDCImpl::SetFont( const wxFont& font ) |
fa034c45 RR |
1804 | { |
1805 | m_font = font; | |
1806 | ||
1807 | if (m_font.Ok()) | |
1808 | { | |
1809 | if (m_fontdesc) | |
1810 | pango_font_description_free( m_fontdesc ); | |
1811 | ||
3e7ea45c | 1812 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
1d9fe50d | 1813 | |
12ca5586 VS |
1814 | float size = pango_font_description_get_size( m_fontdesc ); |
1815 | size = size * GetFontPointSizeAdjustment(72.0); | |
1816 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
1817 | ||
fa034c45 RR |
1818 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1819 | } | |
1820 | } | |
1821 | ||
888dde65 | 1822 | void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) |
fa034c45 RR |
1823 | { |
1824 | if (!pen.Ok()) return; | |
1825 | ||
1826 | m_pen = pen; | |
1827 | ||
b29b9485 | 1828 | double width; |
6d52ca53 | 1829 | |
b29b9485 RR |
1830 | if (m_pen.GetWidth() <= 0) |
1831 | width = 0.1; | |
1832 | else | |
1833 | width = (double) m_pen.GetWidth(); | |
fa034c45 | 1834 | |
f7b8e3d6 | 1835 | cairo_set_line_width( m_cairo, width * m_DEV2PS * m_scaleX ); |
fa034c45 RR |
1836 | static const double dotted[] = {2.0, 5.0}; |
1837 | static const double short_dashed[] = {4.0, 4.0}; | |
1838 | static const double long_dashed[] = {4.0, 8.0}; | |
1839 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1840 | ||
1841 | switch (m_pen.GetStyle()) | |
1842 | { | |
f7b8e3d6 VS |
1843 | case wxPENSTYLE_DOT: cairo_set_dash( m_cairo, dotted, 2, 0 ); break; |
1844 | case wxPENSTYLE_SHORT_DASH: cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break; | |
1845 | case wxPENSTYLE_LONG_DASH: cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break; | |
1846 | case wxPENSTYLE_DOT_DASH: cairo_set_dash( m_cairo, dotted_dashed, 4, 0 ); break; | |
04ee05f9 | 1847 | case wxPENSTYLE_USER_DASH: |
fa034c45 RR |
1848 | { |
1849 | wxDash *wx_dashes; | |
da249bc3 | 1850 | int num = m_pen.GetDashes (&wx_dashes); |
fa034c45 RR |
1851 | gdouble *g_dashes = g_new( gdouble, num ); |
1852 | int i; | |
1853 | for (i = 0; i < num; ++i) | |
1854 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
f7b8e3d6 | 1855 | cairo_set_dash( m_cairo, g_dashes, num, 0); |
fa034c45 RR |
1856 | g_free( g_dashes ); |
1857 | } | |
1858 | break; | |
04ee05f9 PC |
1859 | case wxPENSTYLE_SOLID: |
1860 | case wxPENSTYLE_TRANSPARENT: | |
f7b8e3d6 | 1861 | default: cairo_set_dash( m_cairo, NULL, 0, 0 ); break; |
fa034c45 RR |
1862 | } |
1863 | ||
1864 | switch (m_pen.GetCap()) | |
1865 | { | |
f7b8e3d6 VS |
1866 | case wxCAP_PROJECTING: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_SQUARE); break; |
1867 | case wxCAP_BUTT: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_BUTT); break; | |
fa034c45 | 1868 | case wxCAP_ROUND: |
f7b8e3d6 | 1869 | default: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_ROUND); break; |
fa034c45 RR |
1870 | } |
1871 | ||
1872 | switch (m_pen.GetJoin()) | |
1873 | { | |
f7b8e3d6 VS |
1874 | case wxJOIN_BEVEL: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_BEVEL); break; |
1875 | case wxJOIN_MITER: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_MITER); break; | |
fa034c45 | 1876 | case wxJOIN_ROUND: |
f7b8e3d6 | 1877 | default: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_ROUND); break; |
fa034c45 RR |
1878 | } |
1879 | ||
1880 | unsigned char red = m_pen.GetColour().Red(); | |
1881 | unsigned char blue = m_pen.GetColour().Blue(); | |
1882 | unsigned char green = m_pen.GetColour().Green(); | |
1883 | unsigned char alpha = m_pen.GetColour().Alpha(); | |
1884 | ||
1885 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1886 | { | |
1887 | double redPS = (double)(red) / 255.0; | |
1888 | double bluePS = (double)(blue) / 255.0; | |
1889 | double greenPS = (double)(green) / 255.0; | |
1890 | double alphaPS = (double)(alpha) / 255.0; | |
1891 | ||
f7b8e3d6 | 1892 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1893 | |
1894 | m_currentRed = red; | |
1895 | m_currentBlue = blue; | |
1896 | m_currentGreen = green; | |
1897 | m_currentAlpha = alpha; | |
1898 | } | |
1899 | } | |
1900 | ||
888dde65 | 1901 | void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush ) |
fa034c45 RR |
1902 | { |
1903 | if (!brush.Ok()) return; | |
1904 | ||
1905 | m_brush = brush; | |
1906 | ||
04ee05f9 | 1907 | if (m_brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT) |
a9312950 | 1908 | { |
f7b8e3d6 | 1909 | cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 ); |
a9312950 RR |
1910 | m_currentRed = 0; |
1911 | m_currentBlue = 0; | |
1912 | m_currentGreen = 0; | |
1913 | m_currentAlpha = 0; | |
1914 | return; | |
1915 | } | |
1916 | ||
fa034c45 RR |
1917 | // Brush colour. |
1918 | unsigned char red = m_brush.GetColour().Red(); | |
1919 | unsigned char blue = m_brush.GetColour().Blue(); | |
1920 | unsigned char green = m_brush.GetColour().Green(); | |
1921 | unsigned char alpha = m_brush.GetColour().Alpha(); | |
1922 | ||
1923 | double redPS = (double)(red) / 255.0; | |
1924 | double bluePS = (double)(blue) / 255.0; | |
1925 | double greenPS = (double)(green) / 255.0; | |
1926 | double alphaPS = (double)(alpha) / 255.0; | |
1927 | ||
1928 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1929 | { | |
f7b8e3d6 | 1930 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1931 | |
1932 | m_currentRed = red; | |
1933 | m_currentBlue = blue; | |
1934 | m_currentGreen = green; | |
1935 | m_currentAlpha = alpha; | |
1936 | } | |
1937 | ||
1938 | if (m_brush.IsHatch()) | |
1939 | { | |
1940 | cairo_t * cr; | |
1941 | cairo_surface_t *surface; | |
f7b8e3d6 VS |
1942 | surface = cairo_surface_create_similar(cairo_get_target(m_cairo),CAIRO_CONTENT_COLOR_ALPHA,10,10); |
1943 | cr = cairo_create(surface); | |
1944 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); | |
1945 | cairo_set_line_width(cr, 1); | |
1946 | cairo_set_line_join(cr,CAIRO_LINE_JOIN_MITER); | |
fa034c45 RR |
1947 | |
1948 | switch (m_brush.GetStyle()) | |
1949 | { | |
04ee05f9 | 1950 | case wxBRUSHSTYLE_CROSS_HATCH: |
f7b8e3d6 VS |
1951 | cairo_move_to(cr, 5, 0); |
1952 | cairo_line_to(cr, 5, 10); | |
1953 | cairo_move_to(cr, 0, 5); | |
1954 | cairo_line_to(cr, 10, 5); | |
fa034c45 | 1955 | break; |
04ee05f9 | 1956 | case wxBRUSHSTYLE_BDIAGONAL_HATCH: |
f7b8e3d6 VS |
1957 | cairo_move_to(cr, 0, 10); |
1958 | cairo_line_to(cr, 10, 0); | |
fa034c45 | 1959 | break; |
04ee05f9 | 1960 | case wxBRUSHSTYLE_FDIAGONAL_HATCH: |
f7b8e3d6 VS |
1961 | cairo_move_to(cr, 0, 0); |
1962 | cairo_line_to(cr, 10, 10); | |
fa034c45 | 1963 | break; |
04ee05f9 | 1964 | case wxBRUSHSTYLE_CROSSDIAG_HATCH: |
f7b8e3d6 VS |
1965 | cairo_move_to(cr, 0, 0); |
1966 | cairo_line_to(cr, 10, 10); | |
1967 | cairo_move_to(cr, 10, 0); | |
1968 | cairo_line_to(cr, 0, 10); | |
fa034c45 | 1969 | break; |
04ee05f9 | 1970 | case wxBRUSHSTYLE_HORIZONTAL_HATCH: |
f7b8e3d6 VS |
1971 | cairo_move_to(cr, 0, 5); |
1972 | cairo_line_to(cr, 10, 5); | |
fa034c45 | 1973 | break; |
04ee05f9 | 1974 | case wxBRUSHSTYLE_VERTICAL_HATCH: |
f7b8e3d6 VS |
1975 | cairo_move_to(cr, 5, 0); |
1976 | cairo_line_to(cr, 5, 10); | |
fa034c45 RR |
1977 | break; |
1978 | default: | |
1979 | wxFAIL_MSG(_("Couldn't get hatch style from wxBrush.")); | |
1980 | } | |
1981 | ||
f7b8e3d6 VS |
1982 | cairo_set_source_rgba(cr, redPS, greenPS, bluePS, alphaPS); |
1983 | cairo_stroke (cr); | |
fa034c45 | 1984 | |
f7b8e3d6 VS |
1985 | cairo_destroy(cr); |
1986 | cairo_pattern_t * pattern = cairo_pattern_create_for_surface (surface); | |
1987 | cairo_surface_destroy(surface); | |
1988 | cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); | |
1989 | cairo_set_source(m_cairo, pattern); | |
1990 | cairo_pattern_destroy(pattern); | |
fa034c45 RR |
1991 | } |
1992 | } | |
1993 | ||
89efaf2b | 1994 | void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function ) |
fa034c45 RR |
1995 | { |
1996 | if (function == wxCLEAR) | |
f7b8e3d6 | 1997 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR); |
fa034c45 | 1998 | else if (function == wxOR) |
f7b8e3d6 | 1999 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_OUT); |
fa034c45 | 2000 | else if (function == wxNO_OP) |
f7b8e3d6 | 2001 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST); |
fa034c45 | 2002 | else if (function == wxAND) |
f7b8e3d6 | 2003 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_ADD); |
fa034c45 | 2004 | else if (function == wxSET) |
f7b8e3d6 | 2005 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SATURATE); |
fa034c45 | 2006 | else if (function == wxXOR) |
f7b8e3d6 | 2007 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_XOR); |
fa034c45 | 2008 | else // wxCOPY or anything else. |
f7b8e3d6 | 2009 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE); |
fa034c45 RR |
2010 | } |
2011 | ||
888dde65 | 2012 | void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush ) |
fa034c45 RR |
2013 | { |
2014 | m_backgroundBrush = brush; | |
f7b8e3d6 VS |
2015 | cairo_save(m_cairo); |
2016 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST_OVER); | |
fa034c45 RR |
2017 | |
2018 | SetBrush(m_backgroundBrush); | |
f7b8e3d6 VS |
2019 | cairo_paint(m_cairo); |
2020 | cairo_restore(m_cairo); | |
fa034c45 RR |
2021 | } |
2022 | ||
888dde65 | 2023 | void wxGtkPrinterDCImpl::SetBackgroundMode(int mode) |
fa034c45 | 2024 | { |
04ee05f9 PC |
2025 | if (mode == wxBRUSHSTYLE_SOLID) |
2026 | m_backgroundMode = wxBRUSHSTYLE_SOLID; | |
e0d1fd7f | 2027 | else |
04ee05f9 | 2028 | m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT; |
fa034c45 RR |
2029 | } |
2030 | ||
888dde65 | 2031 | void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 2032 | { |
f7b8e3d6 VS |
2033 | cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); |
2034 | cairo_clip(m_cairo); | |
fa034c45 RR |
2035 | } |
2036 | ||
888dde65 | 2037 | void wxGtkPrinterDCImpl::DestroyClippingRegion() |
fa034c45 | 2038 | { |
f7b8e3d6 | 2039 | cairo_reset_clip(m_cairo); |
fa034c45 RR |
2040 | } |
2041 | ||
888dde65 | 2042 | bool wxGtkPrinterDCImpl::StartDoc(const wxString& WXUNUSED(message)) |
fa034c45 RR |
2043 | { |
2044 | return true; | |
2045 | } | |
2046 | ||
888dde65 | 2047 | void wxGtkPrinterDCImpl::EndDoc() |
fa034c45 RR |
2048 | { |
2049 | return; | |
2050 | } | |
2051 | ||
888dde65 | 2052 | void wxGtkPrinterDCImpl::StartPage() |
fa034c45 RR |
2053 | { |
2054 | return; | |
2055 | } | |
2056 | ||
888dde65 | 2057 | void wxGtkPrinterDCImpl::EndPage() |
fa034c45 RR |
2058 | { |
2059 | return; | |
2060 | } | |
2061 | ||
888dde65 | 2062 | wxCoord wxGtkPrinterDCImpl::GetCharHeight() const |
fa034c45 RR |
2063 | { |
2064 | pango_layout_set_text( m_layout, "H", 1 ); | |
2065 | ||
2066 | int w,h; | |
2067 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
2068 | ||
a9312950 | 2069 | return wxRound( h * m_PS2DEV ); |
fa034c45 RR |
2070 | } |
2071 | ||
888dde65 | 2072 | wxCoord wxGtkPrinterDCImpl::GetCharWidth() const |
fa034c45 RR |
2073 | { |
2074 | pango_layout_set_text( m_layout, "H", 1 ); | |
2075 | ||
2076 | int w,h; | |
2077 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
2078 | ||
a9312950 | 2079 | return wxRound( w * m_PS2DEV ); |
fa034c45 RR |
2080 | } |
2081 | ||
888dde65 | 2082 | void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
fa034c45 RR |
2083 | wxCoord *descent, |
2084 | wxCoord *externalLeading, | |
2085 | const wxFont *theFont ) const | |
2086 | { | |
2087 | if ( width ) | |
2088 | *width = 0; | |
2089 | if ( height ) | |
2090 | *height = 0; | |
2091 | if ( descent ) | |
2092 | *descent = 0; | |
2093 | if ( externalLeading ) | |
2094 | *externalLeading = 0; | |
2095 | ||
2096 | if (string.empty()) | |
2097 | { | |
2098 | return; | |
2099 | } | |
2100 | ||
12ca5586 VS |
2101 | cairo_save( m_cairo ); |
2102 | cairo_scale(m_cairo, m_scaleX, m_scaleY); | |
2103 | ||
fa034c45 | 2104 | // Set layout's text |
197380a0 | 2105 | const wxScopedCharBuffer dataUTF8 = string.utf8_str(); |
fa034c45 | 2106 | |
8cf694d4 | 2107 | gint oldSize=0; |
12ca5586 VS |
2108 | if ( theFont ) |
2109 | { | |
2110 | // scale the font and apply it | |
2111 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; | |
2112 | float size = pango_font_description_get_size(desc); | |
2113 | size = size * GetFontPointSizeAdjustment(72.0); | |
2114 | pango_font_description_set_size(desc, (gint)size); | |
fa034c45 | 2115 | |
12ca5586 VS |
2116 | pango_layout_set_font_description(m_layout, desc); |
2117 | } | |
fa034c45 RR |
2118 | |
2119 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
2120 | ||
12ca5586 VS |
2121 | int h; |
2122 | pango_layout_get_pixel_size( m_layout, width, &h ); | |
2123 | if ( height ) | |
2124 | *height = h; | |
a7060b8c | 2125 | |
fa034c45 RR |
2126 | if (descent) |
2127 | { | |
2128 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
2129 | int baseline = pango_layout_iter_get_baseline(iter); | |
2130 | pango_layout_iter_free(iter); | |
12ca5586 | 2131 | *descent = h - PANGO_PIXELS(baseline); |
fa034c45 RR |
2132 | } |
2133 | ||
12ca5586 VS |
2134 | if ( theFont ) |
2135 | { | |
2136 | // restore font and reset font's size back | |
2137 | pango_layout_set_font_description(m_layout, m_fontdesc); | |
fa034c45 | 2138 | |
12ca5586 VS |
2139 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; |
2140 | pango_font_description_set_size(desc, oldSize); | |
2141 | } | |
2142 | ||
2143 | cairo_restore( m_cairo ); | |
fa034c45 RR |
2144 | } |
2145 | ||
888dde65 | 2146 | void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const |
fa034c45 | 2147 | { |
a9312950 RR |
2148 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
2149 | ||
fa034c45 | 2150 | if (width) |
eaeb9985 | 2151 | *width = wxRound( (double)gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 ); |
fa034c45 | 2152 | if (height) |
eaeb9985 | 2153 | *height = wxRound( (double)gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 ); |
fa034c45 RR |
2154 | } |
2155 | ||
888dde65 | 2156 | void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const |
fa034c45 | 2157 | { |
a9312950 | 2158 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
fa034c45 RR |
2159 | |
2160 | if (width) | |
a9312950 | 2161 | *width = wxRound( gtk_page_setup_get_paper_width( setup, GTK_UNIT_MM ) ); |
fa034c45 | 2162 | if (height) |
a9312950 | 2163 | *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_MM ) ); |
fa034c45 RR |
2164 | } |
2165 | ||
888dde65 | 2166 | wxSize wxGtkPrinterDCImpl::GetPPI() const |
fa034c45 | 2167 | { |
a9312950 | 2168 | return wxSize( (int)m_resolution, (int)m_resolution ); |
fa034c45 RR |
2169 | } |
2170 | ||
888dde65 | 2171 | void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data) |
fa034c45 RR |
2172 | { |
2173 | m_printData = data; | |
fa034c45 RR |
2174 | } |
2175 | ||
4f37154e RR |
2176 | // overriden for wxPrinterDC Impl |
2177 | ||
6d52ca53 | 2178 | wxRect wxGtkPrinterDCImpl::GetPaperRect() const |
fa034c45 | 2179 | { |
4f37154e RR |
2180 | // Does GtkPrint support printer margins? |
2181 | int w = 0; | |
2182 | int h = 0; | |
2183 | DoGetSize( &w, &h ); | |
2184 | return wxRect( 0,0,w,h ); | |
fa034c45 RR |
2185 | } |
2186 | ||
6d52ca53 | 2187 | int wxGtkPrinterDCImpl::GetResolution() const |
fa034c45 | 2188 | { |
a9312950 | 2189 | return m_resolution; |
fa034c45 RR |
2190 | } |
2191 | ||
2192 | // ---------------------------------------------------------------------------- | |
2193 | // Print preview | |
2194 | // ---------------------------------------------------------------------------- | |
2195 | ||
2196 | IMPLEMENT_CLASS(wxGtkPrintPreview, wxPrintPreviewBase) | |
2197 | ||
2198 | void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
115be92b VZ |
2199 | wxPrintout * WXUNUSED(printoutForPrinting), |
2200 | wxPrintData *data) | |
fa034c45 | 2201 | { |
115be92b VZ |
2202 | // convert wxPrintQuality to resolution (input pointer can be NULL) |
2203 | wxPrintQuality quality = data ? data->GetQuality() : wxPRINT_QUALITY_MEDIUM; | |
2204 | switch ( quality ) | |
2205 | { | |
2206 | case wxPRINT_QUALITY_HIGH: | |
2207 | m_resolution = 1200; | |
2208 | break; | |
2209 | ||
115be92b VZ |
2210 | case wxPRINT_QUALITY_LOW: |
2211 | m_resolution = 300; | |
2212 | break; | |
2213 | ||
2214 | case wxPRINT_QUALITY_DRAFT: | |
2215 | m_resolution = 150; | |
2216 | break; | |
1f2a1c3c VZ |
2217 | |
2218 | default: | |
2219 | if ( quality > 0 ) | |
2220 | { | |
2221 | // positive values directly indicate print resolution | |
2222 | m_resolution = quality; | |
2223 | break; | |
2224 | } | |
2225 | ||
2226 | wxFAIL_MSG( "unknown print quality" ); | |
2227 | // fall through | |
2228 | ||
2229 | case wxPRINT_QUALITY_MEDIUM: | |
2230 | m_resolution = 600; | |
2231 | break; | |
2232 | ||
115be92b | 2233 | } |
1f2a1c3c VZ |
2234 | |
2235 | DetermineScaling(); | |
fa034c45 RR |
2236 | } |
2237 | ||
2238 | wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout, | |
115be92b VZ |
2239 | wxPrintout *printoutForPrinting, |
2240 | wxPrintDialogData *data) | |
2241 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
fa034c45 | 2242 | { |
115be92b | 2243 | Init(printout, printoutForPrinting, data ? &data->GetPrintData() : NULL); |
fa034c45 RR |
2244 | } |
2245 | ||
2246 | wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout, | |
115be92b VZ |
2247 | wxPrintout *printoutForPrinting, |
2248 | wxPrintData *data) | |
2249 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
fa034c45 | 2250 | { |
115be92b | 2251 | Init(printout, printoutForPrinting, data); |
fa034c45 RR |
2252 | } |
2253 | ||
2254 | wxGtkPrintPreview::~wxGtkPrintPreview() | |
2255 | { | |
2256 | } | |
2257 | ||
2258 | bool wxGtkPrintPreview::Print(bool interactive) | |
2259 | { | |
2260 | if (!m_printPrintout) | |
2261 | return false; | |
2262 | ||
2263 | wxPrinter printer(& m_printDialogData); | |
2264 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
2265 | } | |
2266 | ||
2267 | void wxGtkPrintPreview::DetermineScaling() | |
2268 | { | |
2269 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
2270 | ||
2271 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
2272 | if (!paper) | |
2273 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
2274 | ||
2275 | if (paper) | |
2276 | { | |
40fcf546 | 2277 | m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); |
115be92b | 2278 | m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution ); |
a7060b8c | 2279 | |
fa034c45 RR |
2280 | // Get width and height in points (1/72th of an inch) |
2281 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
115be92b VZ |
2282 | sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0); |
2283 | sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0); | |
6d52ca53 | 2284 | |
fa034c45 RR |
2285 | wxSize sizeTenthsMM(paper->GetSize()); |
2286 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2287 | ||
2288 | // If in landscape mode, we need to swap the width and height. | |
2289 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2290 | { | |
2291 | m_pageWidth = sizeDevUnits.y; | |
2292 | m_pageHeight = sizeDevUnits.x; | |
2293 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
2294 | } | |
2295 | else | |
2296 | { | |
2297 | m_pageWidth = sizeDevUnits.x; | |
2298 | m_pageHeight = sizeDevUnits.y; | |
2299 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
2300 | } | |
2301 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
2302 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
2303 | ||
2304 | // At 100%, the page should look about page-size on the screen. | |
115be92b | 2305 | m_previewScaleX = 0.8 * 72.0 / (double)m_resolution; |
fa034c45 RR |
2306 | m_previewScaleY = m_previewScaleX; |
2307 | } | |
2308 | } | |
2309 | ||
2310 | #endif | |
2311 | // wxUSE_GTKPRINT |