]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/gtk/gnome/gprint.cpp | |
3 | // Author: Robert Roebling | |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: Robert Roebling | |
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 | #include "wx/gtk/gnome/gprint.h" | |
19 | ||
20 | #if wxUSE_LIBGNOMEPRINT | |
21 | ||
22 | #include "wx/math.h" | |
23 | #include "wx/fontutil.h" | |
24 | #include "wx/gtk/private.h" | |
25 | #include "wx/module.h" | |
26 | #include "wx/dynlib.h" | |
27 | #include "wx/dcmemory.h" | |
28 | #include "wx/log.h" | |
29 | #include "wx/icon.h" | |
30 | ||
31 | #include <libgnomeprint/gnome-print.h> | |
32 | #include <libgnomeprint/gnome-print-pango.h> | |
33 | #include <libgnomeprint/gnome-print-config.h> | |
34 | #include <libgnomeprintui/gnome-print-dialog.h> | |
35 | #include <libgnomeprintui/gnome-print-job-preview.h> | |
36 | #include <libgnomeprintui/gnome-print-paper-selector.h> | |
37 | ||
38 | static const double RAD2DEG = 180.0 / M_PI; | |
39 | ||
40 | #include "wx/html/forcelnk.h" | |
41 | FORCE_LINK_ME(gnome_print) | |
42 | ||
43 | //---------------------------------------------------------------------------- | |
44 | // wxGnomePrintLibrary | |
45 | //---------------------------------------------------------------------------- | |
46 | ||
47 | #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \ | |
48 | typedef rettype (* name ## Type) args ; \ | |
49 | name ## Type pfn_ ## name; \ | |
50 | rettype name args \ | |
51 | { if (m_ok) return pfn_ ## name shortargs ; return defret; } | |
52 | ||
53 | #define wxDL_METHOD_LOAD( lib, name, success ) \ | |
54 | pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \ | |
55 | if (!success) return; | |
56 | ||
57 | class wxGnomePrintLibrary | |
58 | { | |
59 | public: | |
60 | wxGnomePrintLibrary(); | |
61 | ~wxGnomePrintLibrary(); | |
62 | ||
63 | bool IsOk(); | |
64 | void InitializeMethods(); | |
65 | ||
66 | private: | |
67 | bool m_ok; | |
68 | wxDynamicLibrary *m_gnome_print_lib; | |
69 | wxDynamicLibrary *m_gnome_printui_lib; | |
70 | ||
71 | public: | |
72 | wxDL_METHOD_DEFINE( gint, gnome_print_newpath, | |
73 | (GnomePrintContext *pc), (pc), 0 ) | |
74 | wxDL_METHOD_DEFINE( gint, gnome_print_moveto, | |
75 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
76 | wxDL_METHOD_DEFINE( gint, gnome_print_lineto, | |
77 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
78 | wxDL_METHOD_DEFINE( gint, gnome_print_arcto, | |
79 | (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 ) | |
80 | wxDL_METHOD_DEFINE( gint, gnome_print_curveto, | |
81 | (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 ) | |
82 | wxDL_METHOD_DEFINE( gint, gnome_print_closepath, | |
83 | (GnomePrintContext *pc), (pc), 0 ) | |
84 | wxDL_METHOD_DEFINE( gint, gnome_print_stroke, | |
85 | (GnomePrintContext *pc), (pc), 0 ) | |
86 | wxDL_METHOD_DEFINE( gint, gnome_print_fill, | |
87 | (GnomePrintContext *pc), (pc), 0 ) | |
88 | wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor, | |
89 | (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 ) | |
90 | wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth, | |
91 | (GnomePrintContext *pc, gdouble width), (pc, width), 0 ) | |
92 | wxDL_METHOD_DEFINE( gint, gnome_print_setdash, | |
93 | (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 ) | |
94 | ||
95 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage, | |
96 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
97 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage, | |
98 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
99 | ||
100 | wxDL_METHOD_DEFINE( gint, gnome_print_concat, | |
101 | (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 ) | |
102 | wxDL_METHOD_DEFINE( gint, gnome_print_scale, | |
103 | (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 ) | |
104 | wxDL_METHOD_DEFINE( gint, gnome_print_rotate, | |
105 | (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 ) | |
106 | wxDL_METHOD_DEFINE( gint, gnome_print_translate, | |
107 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
108 | ||
109 | wxDL_METHOD_DEFINE( gint, gnome_print_gsave, | |
110 | (GnomePrintContext *pc), (pc), 0 ) | |
111 | wxDL_METHOD_DEFINE( gint, gnome_print_grestore, | |
112 | (GnomePrintContext *pc), (pc), 0 ) | |
113 | ||
114 | wxDL_METHOD_DEFINE( gint, gnome_print_beginpage, | |
115 | (GnomePrintContext *pc, const guchar* name), (pc, name), 0 ) | |
116 | wxDL_METHOD_DEFINE( gint, gnome_print_showpage, | |
117 | (GnomePrintContext *pc), (pc), 0 ) | |
118 | wxDL_METHOD_DEFINE( gint, gnome_print_end_doc, | |
119 | (GnomePrintContext *pc), (pc), 0 ) | |
120 | ||
121 | wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout, | |
122 | (GnomePrintContext *gpc), (gpc), NULL ) | |
123 | wxDL_METHOD_DEFINE( void, gnome_print_pango_layout, | |
124 | (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout), /**/ ) | |
125 | ||
126 | wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new, | |
127 | (GnomePrintConfig *config), (config), NULL ) | |
128 | wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context, | |
129 | (GnomePrintJob *job), (job), NULL ) | |
130 | wxDL_METHOD_DEFINE( gint, gnome_print_job_close, | |
131 | (GnomePrintJob *job), (job), 0 ) | |
132 | wxDL_METHOD_DEFINE( gint, gnome_print_job_print, | |
133 | (GnomePrintJob *job), (job), 0 ) | |
134 | wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size, | |
135 | (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 ) | |
136 | ||
137 | wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation, | |
138 | (const guchar *abbreviation), (abbreviation), NULL ) | |
139 | wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance, | |
140 | (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false ) | |
141 | ||
142 | wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default, | |
143 | (void), (), NULL ) | |
144 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set, | |
145 | (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false ) | |
146 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length, | |
147 | (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false ) | |
148 | ||
149 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new, | |
150 | (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL ) | |
151 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page, | |
152 | (GnomePrintDialog *gpd, gint flags, gint start, gint end, | |
153 | const guchar *currentlabel, const guchar *rangelabel), | |
154 | (gpd, flags, start, end, currentlabel, rangelabel), /**/ ) | |
155 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies, | |
156 | (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate), /**/ ) | |
157 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies, | |
158 | (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate), /**/ ) | |
159 | wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range, | |
160 | (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE ) | |
161 | wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page, | |
162 | (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 ) | |
163 | ||
164 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags, | |
165 | (GnomePrintConfig *config, gint flags), (config, flags), NULL ) | |
166 | ||
167 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new, | |
168 | (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL ) | |
169 | }; | |
170 | ||
171 | wxGnomePrintLibrary::wxGnomePrintLibrary() | |
172 | { | |
173 | m_gnome_print_lib = NULL; | |
174 | m_gnome_printui_lib = NULL; | |
175 | ||
176 | wxLogNull log; | |
177 | ||
178 | m_gnome_print_lib = new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") ); | |
179 | m_ok = m_gnome_print_lib->IsLoaded(); | |
180 | if (!m_ok) return; | |
181 | ||
182 | m_gnome_printui_lib = new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") ); | |
183 | m_ok = m_gnome_printui_lib->IsLoaded(); | |
184 | if (!m_ok) return; | |
185 | ||
186 | InitializeMethods(); | |
187 | } | |
188 | ||
189 | wxGnomePrintLibrary::~wxGnomePrintLibrary() | |
190 | { | |
191 | if (m_gnome_print_lib) | |
192 | delete m_gnome_print_lib; | |
193 | if (m_gnome_printui_lib) | |
194 | delete m_gnome_printui_lib; | |
195 | } | |
196 | ||
197 | bool wxGnomePrintLibrary::IsOk() | |
198 | { | |
199 | return m_ok; | |
200 | } | |
201 | ||
202 | void wxGnomePrintLibrary::InitializeMethods() | |
203 | { | |
204 | m_ok = false; | |
205 | bool success; | |
206 | ||
207 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_newpath, success ) | |
208 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_moveto, success ) | |
209 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_lineto, success ) | |
210 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_curveto, success ) | |
211 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_arcto, success ) | |
212 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_closepath, success ) | |
213 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_stroke, success ) | |
214 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_fill, success ) | |
215 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setrgbcolor, success ) | |
216 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setlinewidth, success ) | |
217 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setdash, success ) | |
218 | ||
219 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbimage, success ) | |
220 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbaimage, success ) | |
221 | ||
222 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_concat, success ) | |
223 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_scale, success ) | |
224 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rotate, success ) | |
225 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_translate, success ) | |
226 | ||
227 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_gsave, success ) | |
228 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_grestore, success ) | |
229 | ||
230 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_beginpage, success ) | |
231 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_showpage, success ) | |
232 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_end_doc, success ) | |
233 | ||
234 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_create_layout, success ) | |
235 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_layout, success ) | |
236 | ||
237 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_new, success ) | |
238 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_context, success ) | |
239 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_close, success ) | |
240 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_print, success ) | |
241 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_page_size, success ) | |
242 | ||
243 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_unit_get_by_abbreviation, success ) | |
244 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_convert_distance, success ) | |
245 | ||
246 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_default, success ) | |
247 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_set, success ) | |
248 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_get_length, success ) | |
249 | ||
250 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_new, success ) | |
251 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_construct_range_page, success ) | |
252 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_copies, success ) | |
253 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_set_copies, success ) | |
254 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range, success ) | |
255 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range_page, success ) | |
256 | ||
257 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_paper_selector_new_with_flags, success ) | |
258 | ||
259 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_job_preview_new, success ) | |
260 | ||
261 | m_ok = true; | |
262 | } | |
263 | ||
264 | static wxGnomePrintLibrary* gs_lgp = NULL; | |
265 | ||
266 | //---------------------------------------------------------------------------- | |
267 | // wxGnomePrintNativeData | |
268 | //---------------------------------------------------------------------------- | |
269 | ||
270 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
271 | ||
272 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
273 | { | |
274 | m_config = gs_lgp->gnome_print_config_default(); | |
275 | m_job = gs_lgp->gnome_print_job_new( m_config ); | |
276 | } | |
277 | ||
278 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
279 | { | |
280 | g_object_unref (G_OBJECT (m_config)); | |
281 | } | |
282 | ||
283 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
284 | { | |
285 | // TODO | |
286 | return true; | |
287 | } | |
288 | ||
289 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
290 | { | |
291 | // TODO | |
292 | return true; | |
293 | } | |
294 | ||
295 | //---------------------------------------------------------------------------- | |
296 | // wxGnomePrintFactory | |
297 | //---------------------------------------------------------------------------- | |
298 | ||
299 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
300 | { | |
301 | return new wxGnomePrinter( data ); | |
302 | } | |
303 | ||
304 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
305 | wxPrintout *printout, | |
306 | wxPrintDialogData *data ) | |
307 | { | |
308 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
309 | } | |
310 | ||
311 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
312 | wxPrintout *printout, | |
313 | wxPrintData *data ) | |
314 | { | |
315 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
316 | } | |
317 | ||
318 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
319 | wxPrintDialogData *data ) | |
320 | { | |
321 | return new wxGnomePrintDialog( parent, data ); | |
322 | } | |
323 | ||
324 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
325 | wxPrintData *data ) | |
326 | { | |
327 | return new wxGnomePrintDialog( parent, data ); | |
328 | } | |
329 | ||
330 | wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent, | |
331 | wxPageSetupDialogData * data ) | |
332 | { | |
333 | // The native page setup dialog is broken. It | |
334 | // miscalculates newly entered values for the | |
335 | // margins if you have not chose "points" but | |
336 | // e.g. centimerters. | |
337 | // This has been fixed in GNOME CVS (maybe | |
338 | // fixed in libgnomeprintui 2.8.1) | |
339 | ||
340 | return new wxGnomePageSetupDialog( parent, data ); | |
341 | } | |
342 | ||
343 | bool wxGnomePrintFactory::HasPrintSetupDialog() | |
344 | { | |
345 | return false; | |
346 | } | |
347 | ||
348 | wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
349 | { | |
350 | return NULL; | |
351 | } | |
352 | ||
353 | bool wxGnomePrintFactory::HasOwnPrintToFile() | |
354 | { | |
355 | return true; | |
356 | } | |
357 | ||
358 | bool wxGnomePrintFactory::HasPrinterLine() | |
359 | { | |
360 | return true; | |
361 | } | |
362 | ||
363 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
364 | { | |
365 | // redundant now | |
366 | return wxEmptyString; | |
367 | } | |
368 | ||
369 | bool wxGnomePrintFactory::HasStatusLine() | |
370 | { | |
371 | // redundant now | |
372 | return true; | |
373 | } | |
374 | ||
375 | wxString wxGnomePrintFactory::CreateStatusLine() | |
376 | { | |
377 | // redundant now | |
378 | return wxEmptyString; | |
379 | } | |
380 | ||
381 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
382 | { | |
383 | return new wxGnomePrintNativeData; | |
384 | } | |
385 | ||
386 | //---------------------------------------------------------------------------- | |
387 | // wxGnomePrintSetupDialog | |
388 | //---------------------------------------------------------------------------- | |
389 | ||
390 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) | |
391 | ||
392 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
393 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
394 | wxPoint(0, 0), wxSize(600, 600), | |
395 | wxDEFAULT_DIALOG_STYLE | | |
396 | wxTAB_TRAVERSAL) | |
397 | { | |
398 | if (data) | |
399 | m_printDialogData = *data; | |
400 | ||
401 | Init(); | |
402 | } | |
403 | ||
404 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) | |
405 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
406 | wxPoint(0, 0), wxSize(600, 600), | |
407 | wxDEFAULT_DIALOG_STYLE | | |
408 | wxTAB_TRAVERSAL) | |
409 | { | |
410 | if (data) | |
411 | m_printDialogData = *data; | |
412 | ||
413 | Init(); | |
414 | } | |
415 | ||
416 | void wxGnomePrintDialog::Init() | |
417 | { | |
418 | wxPrintData data = m_printDialogData.GetPrintData(); | |
419 | ||
420 | wxGnomePrintNativeData *native = | |
421 | (wxGnomePrintNativeData*) data.GetNativeData(); | |
422 | ||
423 | m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(), | |
424 | (guchar*)"Print", | |
425 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); | |
426 | ||
427 | int flag = 0; | |
428 | if (m_printDialogData.GetEnableSelection()) | |
429 | flag |= GNOME_PRINT_RANGE_SELECTION; | |
430 | if (m_printDialogData.GetEnablePageNumbers()) | |
431 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; | |
432 | ||
433 | gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, | |
434 | flag, | |
435 | m_printDialogData.GetMinPage(), | |
436 | m_printDialogData.GetMaxPage(), | |
437 | NULL, | |
438 | NULL ); | |
439 | } | |
440 | ||
441 | wxGnomePrintDialog::~wxGnomePrintDialog() | |
442 | { | |
443 | m_widget = NULL; | |
444 | } | |
445 | ||
446 | int wxGnomePrintDialog::ShowModal() | |
447 | { | |
448 | // Transfer data from m_printDalogData to dialog here | |
449 | ||
450 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
451 | ||
452 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
453 | { | |
454 | gtk_widget_destroy(m_widget); | |
455 | m_widget = NULL; | |
456 | ||
457 | return wxID_CANCEL; | |
458 | } | |
459 | ||
460 | gint copies = 1; | |
461 | gboolean collate = false; | |
462 | gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); | |
463 | m_printDialogData.SetNoCopies( copies ); | |
464 | m_printDialogData.SetCollate( collate ); | |
465 | ||
466 | switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) | |
467 | { | |
468 | case GNOME_PRINT_RANGE_SELECTION: | |
469 | m_printDialogData.SetSelection( true ); | |
470 | break; | |
471 | case GNOME_PRINT_RANGE_ALL: | |
472 | m_printDialogData.SetAllPages( true ); | |
473 | m_printDialogData.SetFromPage( 0 ); | |
474 | m_printDialogData.SetToPage( 9999 ); | |
475 | break; | |
476 | case GNOME_PRINT_RANGE_RANGE: | |
477 | default: | |
478 | gint start,end; | |
479 | gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); | |
480 | m_printDialogData.SetFromPage( start ); | |
481 | m_printDialogData.SetToPage( end ); | |
482 | break; | |
483 | } | |
484 | ||
485 | gtk_widget_destroy(m_widget); | |
486 | m_widget = NULL; | |
487 | ||
488 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) | |
489 | return wxID_PREVIEW; | |
490 | ||
491 | return wxID_OK; | |
492 | } | |
493 | ||
494 | wxDC *wxGnomePrintDialog::GetPrintDC() | |
495 | { | |
496 | // Later | |
497 | return NULL; | |
498 | } | |
499 | ||
500 | bool wxGnomePrintDialog::Validate() | |
501 | { | |
502 | return true; | |
503 | } | |
504 | ||
505 | bool wxGnomePrintDialog::TransferDataToWindow() | |
506 | { | |
507 | return true; | |
508 | } | |
509 | ||
510 | bool wxGnomePrintDialog::TransferDataFromWindow() | |
511 | { | |
512 | return true; | |
513 | } | |
514 | ||
515 | //---------------------------------------------------------------------------- | |
516 | // wxGnomePageSetupDialog | |
517 | //---------------------------------------------------------------------------- | |
518 | ||
519 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
520 | ||
521 | wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent, | |
522 | wxPageSetupDialogData* data ) | |
523 | { | |
524 | if (data) | |
525 | m_pageDialogData = *data; | |
526 | ||
527 | wxGnomePrintNativeData *native = | |
528 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
529 | ||
530 | // This is required as the page setup dialog | |
531 | // calculates wrong values otherwise. | |
532 | gs_lgp->gnome_print_config_set( native->GetPrintConfig(), | |
533 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, | |
534 | (const guchar*) "Pts" ); | |
535 | ||
536 | m_widget = gtk_dialog_new(); | |
537 | ||
538 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); | |
539 | ||
540 | GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), | |
541 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); | |
542 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
543 | gtk_widget_show (main); | |
544 | ||
545 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); | |
546 | ||
547 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); | |
548 | ||
549 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), | |
550 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
551 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
552 | NULL); | |
553 | ||
554 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
555 | GTK_RESPONSE_OK); | |
556 | } | |
557 | ||
558 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
559 | { | |
560 | } | |
561 | ||
562 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
563 | { | |
564 | return m_pageDialogData; | |
565 | } | |
566 | ||
567 | int wxGnomePageSetupDialog::ShowModal() | |
568 | { | |
569 | wxGnomePrintNativeData *native = | |
570 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
571 | GnomePrintConfig *config = native->GetPrintConfig(); | |
572 | ||
573 | // Transfer data from m_pageDialogData to native dialog | |
574 | ||
575 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
576 | ||
577 | if (ret == GTK_RESPONSE_OK) | |
578 | { | |
579 | // Transfer data back to m_pageDialogData | |
580 | ||
581 | // I don't know how querying the last parameter works | |
582 | // I cannot test it as the dialog is currently broken | |
583 | // anyways (it only works for points). | |
584 | double ml,mr,mt,mb,pw,ph; | |
585 | gs_lgp->gnome_print_config_get_length (config, | |
586 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); | |
587 | gs_lgp->gnome_print_config_get_length (config, | |
588 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); | |
589 | gs_lgp->gnome_print_config_get_length (config, | |
590 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); | |
591 | gs_lgp->gnome_print_config_get_length (config, | |
592 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); | |
593 | gs_lgp->gnome_print_config_get_length (config, | |
594 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); | |
595 | gs_lgp->gnome_print_config_get_length (config, | |
596 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); | |
597 | ||
598 | // This probably assumes that the user entered the | |
599 | // values in Pts. Since that is the only the dialog | |
600 | // works right now, we need to fix this later. | |
601 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
602 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
603 | gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
604 | gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
605 | gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
606 | gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
607 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
608 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
609 | ||
610 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
611 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); | |
612 | ||
613 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); | |
614 | ||
615 | #if 0 | |
616 | wxPrintf( wxT("paper %d %d, top margin %d\n"), | |
617 | m_pageDialogData.GetPaperSize().x, | |
618 | m_pageDialogData.GetPaperSize().y, | |
619 | m_pageDialogData.GetMarginTopLeft().x ); | |
620 | #endif | |
621 | ||
622 | ret = wxID_OK; | |
623 | } | |
624 | else | |
625 | { | |
626 | ret = wxID_CANCEL; | |
627 | } | |
628 | ||
629 | gtk_widget_destroy( m_widget ); | |
630 | m_widget = NULL; | |
631 | ||
632 | return ret; | |
633 | } | |
634 | ||
635 | bool wxGnomePageSetupDialog::Validate() | |
636 | { | |
637 | return true; | |
638 | } | |
639 | ||
640 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
641 | { | |
642 | return true; | |
643 | } | |
644 | ||
645 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
646 | { | |
647 | return true; | |
648 | } | |
649 | ||
650 | //---------------------------------------------------------------------------- | |
651 | // wxGnomePrinter | |
652 | //---------------------------------------------------------------------------- | |
653 | ||
654 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
655 | ||
656 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
657 | wxPrinterBase( data ) | |
658 | { | |
659 | m_gpc = NULL; | |
660 | m_native_preview = false; | |
661 | } | |
662 | ||
663 | wxGnomePrinter::~wxGnomePrinter() | |
664 | { | |
665 | } | |
666 | ||
667 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
668 | { | |
669 | if (!printout) | |
670 | { | |
671 | sm_lastError = wxPRINTER_ERROR; | |
672 | return false; | |
673 | } | |
674 | ||
675 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
676 | wxGnomePrintNativeData *native = | |
677 | (wxGnomePrintNativeData*) printdata.GetNativeData(); | |
678 | ||
679 | GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() ); | |
680 | m_gpc = gs_lgp->gnome_print_job_get_context (job); | |
681 | ||
682 | // The GnomePrintJob is temporarily stored in the | |
683 | // native print data as the native print dialog | |
684 | // needs to access it. | |
685 | native->SetPrintJob( job ); | |
686 | ||
687 | ||
688 | printout->SetIsPreview(false); | |
689 | ||
690 | if (m_printDialogData.GetMinPage() < 1) | |
691 | m_printDialogData.SetMinPage(1); | |
692 | if (m_printDialogData.GetMaxPage() < 1) | |
693 | m_printDialogData.SetMaxPage(9999); | |
694 | ||
695 | wxDC *dc; | |
696 | if (prompt) | |
697 | dc = PrintDialog( parent ); | |
698 | else | |
699 | dc = new wxGnomePrintDC( this ); | |
700 | ||
701 | if (m_native_preview) | |
702 | printout->SetIsPreview(true); | |
703 | ||
704 | if (!dc) | |
705 | { | |
706 | gs_lgp->gnome_print_job_close( job ); | |
707 | g_object_unref (G_OBJECT (job)); | |
708 | sm_lastError = wxPRINTER_ERROR; | |
709 | return false; | |
710 | } | |
711 | ||
712 | wxSize ScreenPixels = wxGetDisplaySize(); | |
713 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
714 | ||
715 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
716 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
717 | printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(), | |
718 | wxGnomePrintDC::GetResolution() ); | |
719 | ||
720 | printout->SetDC(dc); | |
721 | ||
722 | int w, h; | |
723 | dc->GetSize(&w, &h); | |
724 | printout->SetPageSizePixels((int)w, (int)h); | |
725 | dc->GetSizeMM(&w, &h); | |
726 | printout->SetPageSizeMM((int)w, (int)h); | |
727 | ||
728 | printout->OnPreparePrinting(); | |
729 | ||
730 | // Get some parameters from the printout, if defined | |
731 | int fromPage, toPage; | |
732 | int minPage, maxPage; | |
733 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
734 | ||
735 | if (maxPage == 0) | |
736 | { | |
737 | gs_lgp->gnome_print_job_close( job ); | |
738 | g_object_unref (G_OBJECT (job)); | |
739 | sm_lastError = wxPRINTER_ERROR; | |
740 | return false; | |
741 | } | |
742 | ||
743 | printout->OnBeginPrinting(); | |
744 | ||
745 | int minPageNum = minPage, maxPageNum = maxPage; | |
746 | ||
747 | if ( !m_printDialogData.GetAllPages() ) | |
748 | { | |
749 | minPageNum = m_printDialogData.GetFromPage(); | |
750 | maxPageNum = m_printDialogData.GetToPage(); | |
751 | } | |
752 | ||
753 | ||
754 | int copyCount; | |
755 | for ( copyCount = 1; | |
756 | copyCount <= m_printDialogData.GetNoCopies(); | |
757 | copyCount++ ) | |
758 | { | |
759 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
760 | { | |
761 | wxLogError(_("Could not start printing.")); | |
762 | sm_lastError = wxPRINTER_ERROR; | |
763 | break; | |
764 | } | |
765 | ||
766 | int pn; | |
767 | for ( pn = minPageNum; | |
768 | pn <= maxPageNum && printout->HasPage(pn); | |
769 | pn++ ) | |
770 | { | |
771 | dc->StartPage(); | |
772 | printout->OnPrintPage(pn); | |
773 | dc->EndPage(); | |
774 | } | |
775 | ||
776 | printout->OnEndDocument(); | |
777 | printout->OnEndPrinting(); | |
778 | } | |
779 | ||
780 | gs_lgp->gnome_print_job_close( job ); | |
781 | if (m_native_preview) | |
782 | { | |
783 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); | |
784 | GtkWidget *preview = gs_lgp->gnome_print_job_preview_new | |
785 | ( | |
786 | job, | |
787 | (const guchar *)title.data() | |
788 | ); | |
789 | gtk_widget_show(preview); | |
790 | } | |
791 | else | |
792 | { | |
793 | gs_lgp->gnome_print_job_print( job ); | |
794 | } | |
795 | ||
796 | g_object_unref (G_OBJECT (job)); | |
797 | delete dc; | |
798 | ||
799 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
800 | } | |
801 | ||
802 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
803 | { | |
804 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); | |
805 | int ret = dialog.ShowModal(); | |
806 | if (ret == wxID_CANCEL) | |
807 | { | |
808 | sm_lastError = wxPRINTER_CANCELLED; | |
809 | return NULL; | |
810 | } | |
811 | ||
812 | m_native_preview = ret == wxID_PREVIEW; | |
813 | ||
814 | m_printDialogData = dialog.GetPrintDialogData(); | |
815 | return new wxGnomePrintDC( this ); | |
816 | } | |
817 | ||
818 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
819 | { | |
820 | return false; | |
821 | } | |
822 | ||
823 | //----------------------------------------------------------------------------- | |
824 | // wxGnomePrintDC | |
825 | //----------------------------------------------------------------------------- | |
826 | ||
827 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDC) | |
828 | ||
829 | wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) | |
830 | { | |
831 | m_printer = printer; | |
832 | ||
833 | m_gpc = printer->GetPrintContext(); | |
834 | ||
835 | m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc ); | |
836 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
837 | ||
838 | m_currentRed = 0; | |
839 | m_currentBlue = 0; | |
840 | m_currentGreen = 0; | |
841 | ||
842 | m_signX = 1; // default x-axis left to right | |
843 | m_signY = -1; // default y-axis bottom up -> top down | |
844 | } | |
845 | ||
846 | wxGnomePrintDC::~wxGnomePrintDC() | |
847 | { | |
848 | } | |
849 | ||
850 | bool wxGnomePrintDC::Ok() const | |
851 | { | |
852 | return true; | |
853 | } | |
854 | ||
855 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
856 | { | |
857 | return false; | |
858 | } | |
859 | ||
860 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
861 | { | |
862 | return false; | |
863 | } | |
864 | ||
865 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
866 | { | |
867 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
868 | ||
869 | SetPen( m_pen ); | |
870 | ||
871 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); | |
872 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
873 | gs_lgp->gnome_print_stroke ( m_gpc); | |
874 | ||
875 | CalcBoundingBox( x1, y1 ); | |
876 | CalcBoundingBox( x2, y2 ); | |
877 | } | |
878 | ||
879 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
880 | { | |
881 | } | |
882 | ||
883 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
884 | { | |
885 | double dx = x1 - xc; | |
886 | double dy = y1 - yc; | |
887 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
888 | double alpha1, alpha2; | |
889 | if (x1 == x2 && y1 == y2) | |
890 | { | |
891 | alpha1 = 0.0; | |
892 | alpha2 = 360.0; | |
893 | } | |
894 | else | |
895 | if (radius == 0.0) | |
896 | { | |
897 | alpha1 = alpha2 = 0.0; | |
898 | } | |
899 | else | |
900 | { | |
901 | alpha1 = (x1 - xc == 0) ? | |
902 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
903 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
904 | alpha2 = (x2 - xc == 0) ? | |
905 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
906 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
907 | ||
908 | while (alpha1 <= 0) alpha1 += 360; | |
909 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
910 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
911 | while (alpha2 > 360) alpha2 -= 360; | |
912 | } | |
913 | ||
914 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
915 | { | |
916 | SetBrush( m_brush ); | |
917 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
918 | gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
919 | ||
920 | gs_lgp->gnome_print_fill( m_gpc ); | |
921 | } | |
922 | ||
923 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
924 | { | |
925 | SetPen (m_pen); | |
926 | gs_lgp->gnome_print_newpath( m_gpc ); | |
927 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
928 | gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
929 | gs_lgp->gnome_print_closepath( m_gpc ); | |
930 | ||
931 | gs_lgp->gnome_print_stroke( m_gpc ); | |
932 | } | |
933 | ||
934 | CalcBoundingBox (x1, y1); | |
935 | CalcBoundingBox (x2, y2); | |
936 | CalcBoundingBox (xc, yc); | |
937 | } | |
938 | ||
939 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
940 | { | |
941 | x += w/2; | |
942 | y += h/2; | |
943 | ||
944 | int xx = XLOG2DEV(x); | |
945 | int yy = YLOG2DEV(y); | |
946 | ||
947 | gs_lgp->gnome_print_gsave( m_gpc ); | |
948 | ||
949 | gs_lgp->gnome_print_translate( m_gpc, xx, yy ); | |
950 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); | |
951 | gs_lgp->gnome_print_scale( m_gpc, 1.0, scale ); | |
952 | ||
953 | xx = 0; | |
954 | yy = 0; | |
955 | ||
956 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
957 | { | |
958 | SetBrush( m_brush ); | |
959 | ||
960 | gs_lgp->gnome_print_moveto ( m_gpc, xx, yy ); | |
961 | gs_lgp->gnome_print_arcto( m_gpc, xx, yy, | |
962 | XLOG2DEVREL(w)/2, sa, ea, 0 ); | |
963 | gs_lgp->gnome_print_moveto ( m_gpc, xx, yy ); | |
964 | ||
965 | gs_lgp->gnome_print_fill( m_gpc ); | |
966 | } | |
967 | ||
968 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
969 | { | |
970 | SetPen (m_pen); | |
971 | ||
972 | gs_lgp->gnome_print_arcto( m_gpc, xx, yy, | |
973 | XLOG2DEVREL(w)/2, sa, ea, 0 ); | |
974 | ||
975 | gs_lgp->gnome_print_stroke( m_gpc ); | |
976 | } | |
977 | ||
978 | gs_lgp->gnome_print_grestore( m_gpc ); | |
979 | ||
980 | CalcBoundingBox( x, y ); | |
981 | CalcBoundingBox( x+w, y+h ); | |
982 | } | |
983 | ||
984 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
985 | { | |
986 | } | |
987 | ||
988 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
989 | { | |
990 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
991 | ||
992 | if (n <= 0) return; | |
993 | ||
994 | SetPen (m_pen); | |
995 | ||
996 | int i; | |
997 | for ( i =0; i<n ; i++ ) | |
998 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); | |
999 | ||
1000 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); | |
1001 | ||
1002 | for (i = 1; i < n; i++) | |
1003 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); | |
1004 | ||
1005 | gs_lgp->gnome_print_stroke ( m_gpc); | |
1006 | } | |
1007 | ||
1008 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1009 | { | |
1010 | if (n==0) return; | |
1011 | ||
1012 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1013 | { | |
1014 | SetBrush( m_brush ); | |
1015 | ||
1016 | int x = points[0].x + xoffset; | |
1017 | int y = points[0].y + yoffset; | |
1018 | CalcBoundingBox( x, y ); | |
1019 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1020 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1021 | int i; | |
1022 | for (i = 1; i < n; i++) | |
1023 | { | |
1024 | int x = points[i].x + xoffset; | |
1025 | int y = points[i].y + yoffset; | |
1026 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1027 | CalcBoundingBox( x, y ); | |
1028 | } | |
1029 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1030 | gs_lgp->gnome_print_fill( m_gpc ); | |
1031 | } | |
1032 | ||
1033 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1034 | { | |
1035 | SetPen (m_pen); | |
1036 | ||
1037 | int x = points[0].x + xoffset; | |
1038 | int y = points[0].y + yoffset; | |
1039 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1040 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1041 | int i; | |
1042 | for (i = 1; i < n; i++) | |
1043 | { | |
1044 | int x = points[i].x + xoffset; | |
1045 | int y = points[i].y + yoffset; | |
1046 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1047 | CalcBoundingBox( x, y ); | |
1048 | } | |
1049 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1050 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1055 | { | |
1056 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); | |
1057 | } | |
1058 | ||
1059 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1060 | { | |
1061 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1062 | { | |
1063 | SetBrush( m_brush ); | |
1064 | ||
1065 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1066 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1067 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1068 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1069 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1070 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1071 | gs_lgp->gnome_print_fill( m_gpc ); | |
1072 | ||
1073 | CalcBoundingBox( x, y ); | |
1074 | CalcBoundingBox( x + width, y + height ); | |
1075 | } | |
1076 | ||
1077 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1078 | { | |
1079 | SetPen (m_pen); | |
1080 | ||
1081 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1082 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1083 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1084 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1085 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1086 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1087 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1088 | ||
1089 | CalcBoundingBox( x, y ); | |
1090 | CalcBoundingBox( x + width, y + height ); | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
1095 | { | |
1096 | wxCoord rad = (wxCoord) radius; | |
1097 | ||
1098 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1099 | { | |
1100 | SetBrush(m_brush); | |
1101 | gs_lgp->gnome_print_newpath(m_gpc); | |
1102 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1103 | gs_lgp->gnome_print_curveto(m_gpc, | |
1104 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
1105 | XLOG2DEV(x),YLOG2DEV(y), | |
1106 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
1107 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
1108 | gs_lgp->gnome_print_curveto(m_gpc, | |
1109 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
1110 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1111 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
1112 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
1113 | gs_lgp->gnome_print_curveto(m_gpc, | |
1114 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
1115 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1116 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
1117 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
1118 | gs_lgp->gnome_print_curveto(m_gpc, | |
1119 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
1120 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1121 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
1122 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1123 | gs_lgp->gnome_print_closepath(m_gpc); | |
1124 | gs_lgp->gnome_print_fill(m_gpc); | |
1125 | ||
1126 | CalcBoundingBox(x,y); | |
1127 | CalcBoundingBox(x+width,y+height); | |
1128 | } | |
1129 | ||
1130 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1131 | { | |
1132 | SetPen(m_pen); | |
1133 | gs_lgp->gnome_print_newpath(m_gpc); | |
1134 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1135 | gs_lgp->gnome_print_curveto(m_gpc, | |
1136 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
1137 | XLOG2DEV(x),YLOG2DEV(y), | |
1138 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
1139 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
1140 | gs_lgp->gnome_print_curveto(m_gpc, | |
1141 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
1142 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1143 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
1144 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
1145 | gs_lgp->gnome_print_curveto(m_gpc, | |
1146 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
1147 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1148 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
1149 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
1150 | gs_lgp->gnome_print_curveto(m_gpc, | |
1151 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
1152 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1153 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
1154 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1155 | gs_lgp->gnome_print_closepath(m_gpc); | |
1156 | gs_lgp->gnome_print_stroke(m_gpc); | |
1157 | ||
1158 | CalcBoundingBox(x,y); | |
1159 | CalcBoundingBox(x+width,y+height); | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, | |
1164 | wxCoord width, wxCoord height) | |
1165 | { | |
1166 | double r = 4 * (sqrt (2) - 1) / 3; | |
1167 | double halfW = 0.5 * width, | |
1168 | halfH = 0.5 * height, | |
1169 | halfWR = r * halfW, | |
1170 | halfHR = r * halfH; | |
1171 | wxCoord halfWI = (wxCoord) halfW, | |
1172 | halfHI = (wxCoord) halfH; | |
1173 | ||
1174 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1175 | ||
1176 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ | |
1177 | gs_lgp->gnome_print_moveto( m_gpc, | |
1178 | XLOG2DEV(x + width), | |
1179 | YLOG2DEV(y + halfHI) ); | |
1180 | gs_lgp->gnome_print_curveto( m_gpc, | |
1181 | XLOG2DEV(x + width), | |
1182 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1183 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), | |
1184 | YLOG2DEV(y + height), | |
1185 | XLOG2DEV(x + halfWI), | |
1186 | YLOG2DEV(y + height) ); | |
1187 | gs_lgp->gnome_print_curveto( m_gpc, | |
1188 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), | |
1189 | YLOG2DEV(y + height), | |
1190 | XLOG2DEV(x), | |
1191 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1192 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
1193 | gs_lgp->gnome_print_curveto( m_gpc, | |
1194 | XLOG2DEV(x), | |
1195 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1196 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1197 | YLOG2DEV(y), | |
1198 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
1199 | gs_lgp->gnome_print_curveto( m_gpc, | |
1200 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), | |
1201 | YLOG2DEV(y), | |
1202 | XLOG2DEV(x + width), | |
1203 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1204 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
1205 | ||
1206 | gs_lgp->gnome_print_closepath(m_gpc); | |
1207 | } | |
1208 | ||
1209 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1210 | { | |
1211 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1212 | { | |
1213 | SetBrush( m_brush ); | |
1214 | makeEllipticalPath( x, y, width, height ); | |
1215 | gs_lgp->gnome_print_fill( m_gpc ); | |
1216 | CalcBoundingBox( x, y ); | |
1217 | CalcBoundingBox( x + width, y + height ); | |
1218 | } | |
1219 | ||
1220 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1221 | { | |
1222 | SetPen (m_pen); | |
1223 | makeEllipticalPath( x, y, width, height ); | |
1224 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1225 | CalcBoundingBox( x, y ); | |
1226 | CalcBoundingBox( x + width, y + height ); | |
1227 | } | |
1228 | } | |
1229 | ||
1230 | #if wxUSE_SPLINES | |
1231 | void wxGnomePrintDC::DoDrawSpline(wxList *points) | |
1232 | { | |
1233 | SetPen (m_pen); | |
1234 | ||
1235 | double c, d, x1, y1, x2, y2, x3, y3; | |
1236 | wxPoint *p, *q; | |
1237 | ||
1238 | wxList::compatibility_iterator node = points->GetFirst(); | |
1239 | p = (wxPoint *)node->GetData(); | |
1240 | x1 = p->x; | |
1241 | y1 = p->y; | |
1242 | ||
1243 | node = node->GetNext(); | |
1244 | p = (wxPoint *)node->GetData(); | |
1245 | c = p->x; | |
1246 | d = p->y; | |
1247 | x3 = | |
1248 | (double)(x1 + c) / 2; | |
1249 | y3 = | |
1250 | (double)(y1 + d) / 2; | |
1251 | ||
1252 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1253 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1254 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1255 | ||
1256 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1257 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1258 | ||
1259 | node = node->GetNext(); | |
1260 | while (node) | |
1261 | { | |
1262 | q = (wxPoint *)node->GetData(); | |
1263 | ||
1264 | x1 = x3; | |
1265 | y1 = y3; | |
1266 | x2 = c; | |
1267 | y2 = d; | |
1268 | c = q->x; | |
1269 | d = q->y; | |
1270 | x3 = (double)(x2 + c) / 2; | |
1271 | y3 = (double)(y2 + d) / 2; | |
1272 | ||
1273 | gs_lgp->gnome_print_curveto(m_gpc, | |
1274 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), | |
1275 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1276 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1277 | ||
1278 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1279 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1280 | ||
1281 | node = node->GetNext(); | |
1282 | } | |
1283 | ||
1284 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); | |
1285 | ||
1286 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1287 | } | |
1288 | #endif // wxUSE_SPLINES | |
1289 | ||
1290 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1291 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
1292 | wxCoord xsrcMask, wxCoord ysrcMask) | |
1293 | { | |
1294 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); | |
1295 | ||
1296 | // blit into a bitmap | |
1297 | wxBitmap bitmap( width, height ); | |
1298 | wxMemoryDC memDC; | |
1299 | memDC.SelectObject(bitmap); | |
1300 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1301 | memDC.SelectObject(wxNullBitmap); | |
1302 | ||
1303 | // draw bitmap. scaling and positioning is done there | |
1304 | DrawBitmap( bitmap, xdest, ydest ); | |
1305 | ||
1306 | return true; | |
1307 | } | |
1308 | ||
1309 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1310 | { | |
1311 | DoDrawBitmap( icon, x, y, true ); | |
1312 | } | |
1313 | ||
1314 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
1315 | { | |
1316 | if (!bitmap.Ok()) return; | |
1317 | ||
1318 | if (bitmap.HasPixbuf()) | |
1319 | { | |
1320 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
1321 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); | |
1322 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1323 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1324 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1325 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1326 | ||
1327 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1328 | double matrix[6]; | |
1329 | matrix[0] = XLOG2DEVREL(width); | |
1330 | matrix[1] = 0; | |
1331 | matrix[2] = 0; | |
1332 | matrix[3] = YLOG2DEVREL(height); | |
1333 | matrix[4] = XLOG2DEV(x); | |
1334 | matrix[5] = YLOG2DEV(y+height); | |
1335 | gs_lgp->gnome_print_concat( m_gpc, matrix ); | |
1336 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
1337 | if (has_alpha) | |
1338 | gs_lgp->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1339 | else | |
1340 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1341 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1342 | } | |
1343 | else | |
1344 | { | |
1345 | wxImage image = bitmap.ConvertToImage(); | |
1346 | ||
1347 | if (!image.Ok()) return; | |
1348 | ||
1349 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1350 | double matrix[6]; | |
1351 | matrix[0] = XLOG2DEVREL(image.GetWidth()); | |
1352 | matrix[1] = 0; | |
1353 | matrix[2] = 0; | |
1354 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1355 | matrix[4] = XLOG2DEV(x); | |
1356 | matrix[5] = YLOG2DEV(y+image.GetHeight()); | |
1357 | gs_lgp->gnome_print_concat( m_gpc, matrix ); | |
1358 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
1359 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1360 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1361 | } | |
1362 | } | |
1363 | ||
1364 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
1365 | { | |
1366 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1367 | } | |
1368 | ||
1369 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
1370 | { | |
1371 | x = XLOG2DEV(x); | |
1372 | y = YLOG2DEV(y); | |
1373 | ||
1374 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); | |
1375 | ||
1376 | #if wxUSE_UNICODE | |
1377 | const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); | |
1378 | #else | |
1379 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); | |
1380 | if ( !wdata ) | |
1381 | return; | |
1382 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1383 | #endif | |
1384 | ||
1385 | size_t datalen = strlen((const char*)data); | |
1386 | pango_layout_set_text( m_layout, (const char*) data, datalen); | |
1387 | ||
1388 | if (underlined) | |
1389 | { | |
1390 | PangoAttrList *attrs = pango_attr_list_new(); | |
1391 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1392 | a->start_index = 0; | |
1393 | a->end_index = datalen; | |
1394 | pango_attr_list_insert(attrs, a); | |
1395 | pango_layout_set_attributes(m_layout, attrs); | |
1396 | pango_attr_list_unref(attrs); | |
1397 | } | |
1398 | ||
1399 | if (m_textForegroundColour.Ok()) | |
1400 | { | |
1401 | unsigned char red = m_textForegroundColour.Red(); | |
1402 | unsigned char blue = m_textForegroundColour.Blue(); | |
1403 | unsigned char green = m_textForegroundColour.Green(); | |
1404 | ||
1405 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1406 | { | |
1407 | double redPS = (double)(red) / 255.0; | |
1408 | double bluePS = (double)(blue) / 255.0; | |
1409 | double greenPS = (double)(green) / 255.0; | |
1410 | ||
1411 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1412 | ||
1413 | m_currentRed = red; | |
1414 | m_currentBlue = blue; | |
1415 | m_currentGreen = green; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | int w,h; | |
1420 | ||
1421 | if (fabs(m_scaleY - 1.0) > 0.00001) | |
1422 | { | |
1423 | // If there is a user or actually any scale applied to | |
1424 | // the device context, scale the font. | |
1425 | ||
1426 | // scale font description | |
1427 | gint oldSize = pango_font_description_get_size( m_fontdesc ); | |
1428 | double size = oldSize; | |
1429 | size = size * m_scaleY; | |
1430 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
1431 | ||
1432 | // actually apply scaled font | |
1433 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1434 | ||
1435 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1436 | #if 0 | |
1437 | if ( m_backgroundMode == wxSOLID ) | |
1438 | { | |
1439 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1440 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
1441 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1442 | } | |
1443 | #endif | |
1444 | // Draw layout. | |
1445 | gs_lgp->gnome_print_moveto (m_gpc, x, y); | |
1446 | if (fabs(angle) > 0.00001) | |
1447 | { | |
1448 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1449 | gs_lgp->gnome_print_rotate( m_gpc, angle ); | |
1450 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1451 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1452 | } | |
1453 | else | |
1454 | { | |
1455 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1456 | } | |
1457 | ||
1458 | // reset unscaled size | |
1459 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
1460 | ||
1461 | // actually apply unscaled font | |
1462 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1463 | } | |
1464 | else | |
1465 | { | |
1466 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1467 | #if 0 | |
1468 | if ( m_backgroundMode == wxSOLID ) | |
1469 | { | |
1470 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1471 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
1472 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1473 | } | |
1474 | #endif | |
1475 | // Draw layout. | |
1476 | gs_lgp->gnome_print_moveto (m_gpc, x, y); | |
1477 | if (fabs(angle) > 0.00001) | |
1478 | { | |
1479 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1480 | gs_lgp->gnome_print_rotate( m_gpc, angle ); | |
1481 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1482 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1483 | } | |
1484 | else | |
1485 | { | |
1486 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | if (underlined) | |
1491 | { | |
1492 | // undo underline attributes setting: | |
1493 | pango_layout_set_attributes(m_layout, NULL); | |
1494 | } | |
1495 | ||
1496 | CalcBoundingBox (x + w, y + h); | |
1497 | } | |
1498 | ||
1499 | void wxGnomePrintDC::Clear() | |
1500 | { | |
1501 | } | |
1502 | ||
1503 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
1504 | { | |
1505 | m_font = font; | |
1506 | ||
1507 | if (m_font.Ok()) | |
1508 | { | |
1509 | if (m_fontdesc) | |
1510 | pango_font_description_free( m_fontdesc ); | |
1511 | ||
1512 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
1513 | ||
1514 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1515 | } | |
1516 | } | |
1517 | ||
1518 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
1519 | { | |
1520 | if (!pen.Ok()) return; | |
1521 | ||
1522 | m_pen = pen; | |
1523 | ||
1524 | gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f ); | |
1525 | ||
1526 | static const double dotted[] = {2.0, 5.0}; | |
1527 | static const double short_dashed[] = {4.0, 4.0}; | |
1528 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1529 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1530 | ||
1531 | switch (m_pen.GetStyle()) | |
1532 | { | |
1533 | case wxDOT: gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; | |
1534 | case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1535 | case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1536 | case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
1537 | case wxUSER_DASH: | |
1538 | { | |
1539 | // It may be noted that libgnomeprint between at least | |
1540 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1541 | // and then leak the memory since it doesn't set the | |
1542 | // internal flag "privatedash" to 0. | |
1543 | wxDash *wx_dashes; | |
1544 | int num = m_pen.GetDashes (&wx_dashes); | |
1545 | gdouble *g_dashes = g_new( gdouble, num ); | |
1546 | int i; | |
1547 | for (i = 0; i < num; ++i) | |
1548 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
1549 | gs_lgp -> gnome_print_setdash( m_gpc, num, g_dashes, 0); | |
1550 | g_free( g_dashes ); | |
1551 | } | |
1552 | break; | |
1553 | case wxSOLID: | |
1554 | case wxTRANSPARENT: | |
1555 | default: gs_lgp->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; | |
1556 | } | |
1557 | ||
1558 | ||
1559 | unsigned char red = m_pen.GetColour().Red(); | |
1560 | unsigned char blue = m_pen.GetColour().Blue(); | |
1561 | unsigned char green = m_pen.GetColour().Green(); | |
1562 | ||
1563 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1564 | { | |
1565 | double redPS = (double)(red) / 255.0; | |
1566 | double bluePS = (double)(blue) / 255.0; | |
1567 | double greenPS = (double)(green) / 255.0; | |
1568 | ||
1569 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1570 | ||
1571 | m_currentRed = red; | |
1572 | m_currentBlue = blue; | |
1573 | m_currentGreen = green; | |
1574 | } | |
1575 | } | |
1576 | ||
1577 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
1578 | { | |
1579 | if (!brush.Ok()) return; | |
1580 | ||
1581 | m_brush = brush; | |
1582 | ||
1583 | // Brush colour | |
1584 | unsigned char red = m_brush.GetColour().Red(); | |
1585 | unsigned char blue = m_brush.GetColour().Blue(); | |
1586 | unsigned char green = m_brush.GetColour().Green(); | |
1587 | ||
1588 | if (!m_colour) | |
1589 | { | |
1590 | // Anything not white is black | |
1591 | if (! (red == (unsigned char) 255 && | |
1592 | blue == (unsigned char) 255 && | |
1593 | green == (unsigned char) 255) ) | |
1594 | { | |
1595 | red = (unsigned char) 0; | |
1596 | green = (unsigned char) 0; | |
1597 | blue = (unsigned char) 0; | |
1598 | } | |
1599 | // setgray here ? | |
1600 | } | |
1601 | ||
1602 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1603 | { | |
1604 | double redPS = (double)(red) / 255.0; | |
1605 | double bluePS = (double)(blue) / 255.0; | |
1606 | double greenPS = (double)(green) / 255.0; | |
1607 | ||
1608 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1609 | ||
1610 | m_currentRed = red; | |
1611 | m_currentBlue = blue; | |
1612 | m_currentGreen = green; | |
1613 | } | |
1614 | } | |
1615 | ||
1616 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
1617 | { | |
1618 | } | |
1619 | ||
1620 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
1621 | { | |
1622 | } | |
1623 | ||
1624 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1625 | { | |
1626 | } | |
1627 | ||
1628 | void wxGnomePrintDC::DestroyClippingRegion() | |
1629 | { | |
1630 | } | |
1631 | ||
1632 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
1633 | { | |
1634 | SetDeviceOrigin( 0,0 ); | |
1635 | ||
1636 | return true; | |
1637 | } | |
1638 | ||
1639 | void wxGnomePrintDC::EndDoc() | |
1640 | { | |
1641 | gs_lgp->gnome_print_end_doc( m_gpc ); | |
1642 | } | |
1643 | ||
1644 | void wxGnomePrintDC::StartPage() | |
1645 | { | |
1646 | gs_lgp->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); | |
1647 | } | |
1648 | ||
1649 | void wxGnomePrintDC::EndPage() | |
1650 | { | |
1651 | gs_lgp->gnome_print_showpage( m_gpc ); | |
1652 | } | |
1653 | ||
1654 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
1655 | { | |
1656 | pango_layout_set_text( m_layout, "H", 1 ); | |
1657 | ||
1658 | int w,h; | |
1659 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1660 | ||
1661 | return h; | |
1662 | } | |
1663 | ||
1664 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
1665 | { | |
1666 | pango_layout_set_text( m_layout, "H", 1 ); | |
1667 | ||
1668 | int w,h; | |
1669 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1670 | ||
1671 | return w; | |
1672 | } | |
1673 | ||
1674 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, | |
1675 | wxCoord *descent, | |
1676 | wxCoord *externalLeading, | |
1677 | wxFont *theFont ) const | |
1678 | { | |
1679 | if ( width ) | |
1680 | *width = 0; | |
1681 | if ( height ) | |
1682 | *height = 0; | |
1683 | if ( descent ) | |
1684 | *descent = 0; | |
1685 | if ( externalLeading ) | |
1686 | *externalLeading = 0; | |
1687 | ||
1688 | if (string.empty()) | |
1689 | { | |
1690 | return; | |
1691 | } | |
1692 | ||
1693 | // Set new font description | |
1694 | if (theFont) | |
1695 | pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); | |
1696 | ||
1697 | // Set layout's text | |
1698 | #if wxUSE_UNICODE | |
1699 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); | |
1700 | const char *dataUTF8 = (const char *)data; | |
1701 | #else | |
1702 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
1703 | if ( !wdata ) | |
1704 | { | |
1705 | if (width) (*width) = 0; | |
1706 | if (height) (*height) = 0; | |
1707 | return; | |
1708 | } | |
1709 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1710 | const char *dataUTF8 = (const char *)data; | |
1711 | #endif | |
1712 | ||
1713 | if ( !dataUTF8 ) | |
1714 | { | |
1715 | // hardly ideal, but what else can we do if conversion failed? | |
1716 | return; | |
1717 | } | |
1718 | ||
1719 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
1720 | ||
1721 | int w,h; | |
1722 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1723 | ||
1724 | if (width) | |
1725 | *width = (wxCoord)(w / m_scaleX); | |
1726 | if (height) | |
1727 | *height = (wxCoord)(h / m_scaleY); | |
1728 | if (descent) | |
1729 | { | |
1730 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1731 | int baseline = pango_layout_iter_get_baseline(iter); | |
1732 | pango_layout_iter_free(iter); | |
1733 | *descent = h - PANGO_PIXELS(baseline); | |
1734 | } | |
1735 | ||
1736 | // Reset old font description | |
1737 | if (theFont) | |
1738 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1739 | } | |
1740 | ||
1741 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
1742 | { | |
1743 | wxGnomePrintNativeData *native = | |
1744 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1745 | ||
1746 | // Query page size. This seems to omit the margins | |
1747 | // right now, although it shouldn't | |
1748 | double pw,ph; | |
1749 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1750 | ||
1751 | if (width) | |
1752 | *width = (int) (pw + 0.5); | |
1753 | if (height) | |
1754 | *height = (int) (ph + 0.5); | |
1755 | } | |
1756 | ||
1757 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
1758 | { | |
1759 | wxGnomePrintNativeData *native = | |
1760 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1761 | ||
1762 | // This code assumes values in Pts. | |
1763 | ||
1764 | double pw,ph; | |
1765 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1766 | ||
1767 | // Convert to mm. | |
1768 | ||
1769 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
1770 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1771 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1772 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
1773 | ||
1774 | if (width) | |
1775 | *width = (int) (pw + 0.5); | |
1776 | if (height) | |
1777 | *height = (int) (ph + 0.5); | |
1778 | } | |
1779 | ||
1780 | wxSize wxGnomePrintDC::GetPPI() const | |
1781 | { | |
1782 | return wxSize(72,72); | |
1783 | } | |
1784 | ||
1785 | void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1786 | { | |
1787 | m_signX = (xLeftRight ? 1 : -1); | |
1788 | m_signY = (yBottomUp ? 1 : -1); | |
1789 | ||
1790 | ComputeScaleAndOrigin(); | |
1791 | } | |
1792 | ||
1793 | void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1794 | { | |
1795 | int h = 0; | |
1796 | int w = 0; | |
1797 | GetSize( &w, &h ); | |
1798 | ||
1799 | wxDC::SetDeviceOrigin( x, h-y ); | |
1800 | } | |
1801 | ||
1802 | void wxGnomePrintDC::SetResolution(int ppi) | |
1803 | { | |
1804 | } | |
1805 | ||
1806 | int wxGnomePrintDC::GetResolution() | |
1807 | { | |
1808 | return 72; | |
1809 | } | |
1810 | ||
1811 | ||
1812 | class wxGnomePrintModule: public wxModule | |
1813 | { | |
1814 | public: | |
1815 | wxGnomePrintModule() {} | |
1816 | bool OnInit(); | |
1817 | void OnExit(); | |
1818 | ||
1819 | private: | |
1820 | DECLARE_DYNAMIC_CLASS(wxGnomePrintModule) | |
1821 | }; | |
1822 | ||
1823 | bool wxGnomePrintModule::OnInit() | |
1824 | { | |
1825 | gs_lgp = new wxGnomePrintLibrary; | |
1826 | if (gs_lgp->IsOk()) | |
1827 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); | |
1828 | return true; | |
1829 | } | |
1830 | ||
1831 | void wxGnomePrintModule::OnExit() | |
1832 | { | |
1833 | delete gs_lgp; | |
1834 | } | |
1835 | ||
1836 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) | |
1837 | ||
1838 | #endif | |
1839 | // wxUSE_LIBGNOMEPRINT |