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