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