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