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