]>
Commit | Line | Data |
---|---|---|
ff910433 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f85b45fb RR |
2 | // Name: gprint.cpp |
3 | // Author: Robert Roebling | |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
6 | // Copyright: Robert Roebling | |
7 | // Licence: wxWindows Licence | |
ff910433 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
58c30cd8 RR |
10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
11 | #pragma implementation "gprint.h" | |
ff910433 RR |
12 | #endif |
13 | ||
14 | // For compilers that support precompilation, includes "wx/wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
7c72311f RR |
21 | #include "wx/gtk/gnome/gprint.h" |
22 | ||
23 | #if wxUSE_LIBGNOMEPRINT | |
24 | ||
ff910433 RR |
25 | #include "wx/fontutil.h" |
26 | #include "wx/printdlg.h" | |
27 | #include "wx/gtk/private.h" | |
28 | ||
29 | #include <libgnomeprint/gnome-print.h> | |
30 | #include <libgnomeprint/gnome-print-pango.h> | |
31 | #include <libgnomeprintui/gnome-print-dialog.h> | |
32 | ||
33 | //---------------------------------------------------------------------------- | |
34 | // wxGnomePrintNativeData | |
35 | //---------------------------------------------------------------------------- | |
36 | ||
37 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
38 | ||
39 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
40 | { | |
41 | m_config = gnome_print_config_default(); | |
42 | m_job = gnome_print_job_new( m_config ); | |
43 | } | |
44 | ||
45 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
46 | { | |
47 | g_object_unref (G_OBJECT (m_config)); | |
48 | g_object_unref (G_OBJECT (m_job)); | |
49 | } | |
50 | ||
51 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
52 | { | |
53 | // TODO | |
54 | return true; | |
55 | } | |
56 | ||
57 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
58 | { | |
59 | // TODO | |
60 | return true; | |
61 | } | |
62 | ||
63 | //---------------------------------------------------------------------------- | |
64 | // wxGnomePrintFactory | |
65 | //---------------------------------------------------------------------------- | |
66 | ||
67 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
68 | { | |
69 | return new wxGnomePrinter( data ); | |
70 | } | |
71 | ||
72 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
73 | wxPrintout *printout, | |
74 | wxPrintDialogData *data ) | |
75 | { | |
76 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
77 | } | |
78 | ||
79 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
80 | wxPrintout *printout, | |
81 | wxPrintData *data ) | |
82 | { | |
83 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
84 | } | |
85 | ||
86 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
87 | wxPrintDialogData *data ) | |
88 | { | |
89 | return new wxGenericPrintDialog( parent, data ); | |
90 | } | |
91 | ||
92 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
93 | wxPrintData *data ) | |
94 | { | |
95 | return new wxGenericPrintDialog( parent, data ); | |
96 | } | |
97 | ||
98 | bool wxGnomePrintFactory::HasPrintSetupDialog() | |
99 | { | |
100 | return true; | |
101 | } | |
102 | ||
103 | wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
104 | { | |
105 | return new wxGnomePrintSetupDialog( parent, data ); | |
106 | } | |
107 | ||
108 | bool wxGnomePrintFactory::HasOwnPrintToFile() | |
109 | { | |
110 | return true; | |
111 | } | |
112 | ||
113 | bool wxGnomePrintFactory::HasPrinterLine() | |
114 | { | |
115 | return true; | |
116 | } | |
117 | ||
118 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
119 | { | |
120 | // We should query "gnome_config_default" here | |
121 | return _("GNOME print"); | |
122 | } | |
123 | ||
124 | bool wxGnomePrintFactory::HasStatusLine() | |
125 | { | |
126 | return true; | |
127 | } | |
128 | ||
129 | wxString wxGnomePrintFactory::CreateStatusLine() | |
130 | { | |
131 | // We should query "gnome_config_default" here | |
132 | return _("Ready"); | |
133 | } | |
134 | ||
135 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
136 | { | |
137 | return new wxGnomePrintNativeData; | |
138 | } | |
139 | ||
140 | //---------------------------------------------------------------------------- | |
141 | // wxGnomePrintSetupDialog | |
142 | //---------------------------------------------------------------------------- | |
143 | ||
144 | IMPLEMENT_CLASS(wxGnomePrintSetupDialog, wxDialog) | |
145 | ||
146 | wxGnomePrintSetupDialog::wxGnomePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
147 | { | |
148 | wxGnomePrintNativeData *native = | |
149 | (wxGnomePrintNativeData*) data->GetNativeData(); | |
150 | ||
151 | m_widget = gnome_print_dialog_new (native->GetPrintJob(), (guchar*)"Print setup", 0); | |
152 | } | |
153 | ||
154 | wxGnomePrintSetupDialog::~wxGnomePrintSetupDialog() | |
155 | { | |
156 | m_widget = NULL; | |
157 | } | |
158 | ||
159 | int wxGnomePrintSetupDialog::ShowModal() | |
160 | { | |
161 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
162 | gtk_widget_destroy(m_widget); | |
163 | m_widget = NULL; | |
164 | ||
165 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
166 | return wxID_CANCEL; | |
167 | ||
168 | return wxID_OK; | |
169 | } | |
170 | ||
171 | bool wxGnomePrintSetupDialog::Validate() | |
172 | { | |
173 | return true; | |
174 | } | |
175 | ||
176 | bool wxGnomePrintSetupDialog::TransferDataToWindow() | |
177 | { | |
178 | return true; | |
179 | } | |
180 | ||
181 | bool wxGnomePrintSetupDialog::TransferDataFromWindow() | |
182 | { | |
183 | return true; | |
184 | } | |
185 | ||
186 | ||
187 | //---------------------------------------------------------------------------- | |
188 | // wxGnomePrinter | |
189 | //---------------------------------------------------------------------------- | |
190 | ||
191 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
192 | ||
193 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
194 | wxPrinterBase( data ) | |
195 | { | |
196 | m_gpc = NULL; | |
197 | } | |
198 | ||
199 | wxGnomePrinter::~wxGnomePrinter() | |
200 | { | |
201 | } | |
202 | ||
203 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
204 | { | |
205 | if (!printout) | |
206 | { | |
207 | sm_lastError = wxPRINTER_ERROR; | |
208 | return false; | |
209 | } | |
210 | ||
211 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
212 | wxGnomePrintNativeData *data = | |
213 | (wxGnomePrintNativeData*) printdata.GetNativeData(); | |
214 | ||
981a6af1 RR |
215 | // The GnomePrintJob is temporarily stored in the |
216 | // native print data as the native print setup dialog | |
217 | // needs to access it. | |
ff910433 RR |
218 | GnomePrintJob *job = data->GetPrintJob(); |
219 | m_gpc = gnome_print_job_get_context (job); | |
981a6af1 RR |
220 | |
221 | printout->SetIsPreview(false); | |
222 | ||
223 | if (m_printDialogData.GetMinPage() < 1) | |
224 | m_printDialogData.SetMinPage(1); | |
225 | if (m_printDialogData.GetMaxPage() < 1) | |
226 | m_printDialogData.SetMaxPage(9999); | |
ff910433 RR |
227 | |
228 | wxDC *dc; | |
ff910433 RR |
229 | if (prompt) |
230 | dc = PrintDialog( parent ); | |
231 | else | |
232 | dc = new wxGnomePrintDC( this ); | |
233 | ||
234 | if (!dc) | |
235 | { | |
236 | gnome_print_job_close( job ); | |
981a6af1 | 237 | sm_lastError = wxPRINTER_ERROR; |
ff910433 RR |
238 | return false; |
239 | } | |
240 | ||
981a6af1 RR |
241 | wxSize ScreenPixels = wxGetDisplaySize(); |
242 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
243 | ||
244 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
245 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
246 | printout->SetPPIPrinter( wxPostScriptDC::GetResolution(), | |
247 | wxPostScriptDC::GetResolution() ); | |
248 | ||
ff910433 RR |
249 | printout->SetDC(dc); |
250 | ||
981a6af1 RR |
251 | int w, h; |
252 | dc->GetSize(&w, &h); | |
253 | printout->SetPageSizePixels((int)w, (int)h); | |
254 | dc->GetSizeMM(&w, &h); | |
255 | printout->SetPageSizeMM((int)w, (int)h); | |
256 | ||
ff910433 RR |
257 | printout->OnPreparePrinting(); |
258 | printout->OnBeginPrinting(); | |
259 | ||
260 | if (!printout->OnBeginDocument(0, 0)) | |
261 | { | |
262 | sm_lastError = wxPRINTER_ERROR; | |
263 | } | |
264 | else | |
265 | { | |
266 | int pn; | |
267 | for (pn = 1; pn <= 2; pn++) | |
268 | { | |
269 | dc->StartPage(); | |
270 | printout->OnPrintPage(pn); | |
271 | dc->EndPage(); | |
272 | } | |
273 | ||
274 | printout->OnEndDocument(); | |
275 | printout->OnEndPrinting(); | |
276 | } | |
277 | ||
278 | gnome_print_job_close( job ); | |
279 | gnome_print_job_print( job ); | |
280 | ||
281 | delete dc; | |
282 | ||
283 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
284 | } | |
285 | ||
286 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
287 | { | |
288 | wxPrintDialog dialog( parent, &m_printDialogData ); | |
289 | if (dialog.ShowModal() == wxID_CANCEL) | |
290 | { | |
291 | sm_lastError = wxPRINTER_ERROR; | |
292 | return NULL; | |
293 | } | |
294 | ||
295 | return new wxGnomePrintDC( this ); | |
296 | } | |
297 | ||
298 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
299 | { | |
58c30cd8 | 300 | return false; |
ff910433 RR |
301 | } |
302 | ||
303 | //----------------------------------------------------------------------------- | |
304 | // wxGnomePrintDC | |
305 | //----------------------------------------------------------------------------- | |
306 | ||
307 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDCBase) | |
308 | ||
309 | wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) | |
310 | { | |
311 | m_printer = printer; | |
312 | ||
313 | m_gpc = printer->GetPrintContext(); | |
314 | ||
315 | m_layout = gnome_print_pango_create_layout( m_gpc ); | |
316 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
317 | ||
318 | m_currentRed = 0; | |
319 | m_currentBlue = 0; | |
320 | m_currentGreen = 0; | |
321 | ||
322 | m_signX = 1; // default x-axis left to right | |
323 | m_signY = -1; // default y-axis bottom up -> top down | |
324 | } | |
325 | ||
326 | wxGnomePrintDC::~wxGnomePrintDC() | |
327 | { | |
328 | } | |
329 | ||
330 | bool wxGnomePrintDC::Ok() const | |
331 | { | |
332 | return true; | |
333 | } | |
334 | ||
335 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
336 | { | |
337 | return false; | |
338 | } | |
339 | ||
340 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
341 | { | |
342 | return false; | |
343 | } | |
344 | ||
345 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
346 | { | |
347 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
348 | ||
349 | SetPen( m_pen ); | |
350 | ||
351 | gnome_print_moveto ( m_gpc, XDEV2LOG(x1), YDEV2LOG(y1) ); | |
352 | gnome_print_lineto ( m_gpc, XDEV2LOG(x2), YDEV2LOG(y2) ); | |
353 | gnome_print_stroke ( m_gpc); | |
354 | ||
355 | CalcBoundingBox( x1, y1 ); | |
356 | CalcBoundingBox( x2, y2 ); | |
357 | } | |
358 | ||
359 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
360 | { | |
361 | } | |
362 | ||
363 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
364 | { | |
365 | } | |
366 | ||
367 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
368 | { | |
369 | } | |
370 | ||
371 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
372 | { | |
373 | } | |
374 | ||
375 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
376 | { | |
377 | } | |
378 | ||
379 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
380 | { | |
381 | } | |
382 | ||
383 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
384 | { | |
385 | } | |
386 | ||
387 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
388 | { | |
389 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
390 | { | |
391 | SetBrush( m_brush ); | |
392 | ||
393 | gnome_print_newpath( m_gpc ); | |
394 | gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
395 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
396 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
397 | gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
398 | gnome_print_closepath( m_gpc ); | |
399 | gnome_print_fill( m_gpc ); | |
400 | ||
401 | CalcBoundingBox( x, y ); | |
402 | CalcBoundingBox( x + width, y + height ); | |
403 | } | |
404 | ||
405 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
406 | { | |
407 | SetPen (m_pen); | |
408 | ||
409 | gnome_print_newpath( m_gpc ); | |
410 | gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
411 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
412 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
413 | gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
414 | gnome_print_closepath( m_gpc ); | |
415 | gnome_print_stroke( m_gpc ); | |
416 | ||
417 | CalcBoundingBox( x, y ); | |
418 | CalcBoundingBox( x + width, y + height ); | |
419 | } | |
420 | } | |
421 | ||
422 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
423 | { | |
424 | } | |
425 | ||
426 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
427 | { | |
428 | } | |
429 | ||
430 | void wxGnomePrintDC::DoDrawSpline(wxList *points) | |
431 | { | |
432 | } | |
433 | ||
434 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
435 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
436 | wxCoord xsrcMask, wxCoord ysrcMask) | |
437 | { | |
438 | return false; | |
439 | } | |
440 | ||
441 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
442 | { | |
443 | } | |
444 | ||
445 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
446 | { | |
447 | } | |
448 | ||
449 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
450 | { | |
451 | if (m_textForegroundColour.Ok()) | |
452 | { | |
453 | unsigned char red = m_textForegroundColour.Red(); | |
454 | unsigned char blue = m_textForegroundColour.Blue(); | |
455 | unsigned char green = m_textForegroundColour.Green(); | |
456 | ||
457 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
458 | { | |
459 | double redPS = (double)(red) / 255.0; | |
460 | double bluePS = (double)(blue) / 255.0; | |
461 | double greenPS = (double)(green) / 255.0; | |
462 | ||
463 | gnome_print_setrgbcolor( m_gpc, redPS, bluePS, greenPS ); | |
464 | ||
465 | m_currentRed = red; | |
466 | m_currentBlue = blue; | |
467 | m_currentGreen = green; | |
468 | } | |
469 | } | |
470 | ||
471 | x = XLOG2DEV(x); | |
472 | y = YLOG2DEV(y); | |
473 | ||
ff910433 RR |
474 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
475 | ||
476 | #if wxUSE_UNICODE | |
477 | const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); | |
478 | #else | |
479 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); | |
480 | if ( !wdata ) | |
481 | return; | |
482 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
483 | #endif | |
484 | ||
485 | size_t datalen = strlen((const char*)data); | |
486 | pango_layout_set_text( m_layout, (const char*) data, datalen); | |
487 | ||
488 | if (underlined) | |
489 | { | |
490 | PangoAttrList *attrs = pango_attr_list_new(); | |
491 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
492 | a->start_index = 0; | |
493 | a->end_index = datalen; | |
494 | pango_attr_list_insert(attrs, a); | |
495 | pango_layout_set_attributes(m_layout, attrs); | |
496 | pango_attr_list_unref(attrs); | |
497 | } | |
498 | ||
499 | gnome_print_moveto (m_gpc, x, y); | |
500 | gnome_print_pango_layout( m_gpc, m_layout ); | |
501 | ||
502 | if (underlined) | |
503 | { | |
504 | // undo underline attributes setting: | |
505 | pango_layout_set_attributes(m_layout, NULL); | |
506 | } | |
507 | ||
508 | // CalcBoundingBox (x + width, y + height); | |
509 | CalcBoundingBox (x, y); | |
510 | } | |
511 | ||
512 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
513 | { | |
514 | } | |
515 | ||
516 | void wxGnomePrintDC::Clear() | |
517 | { | |
518 | } | |
519 | ||
520 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
521 | { | |
522 | m_font = font; | |
523 | ||
524 | if (m_font.Ok()) | |
525 | { | |
526 | if (m_fontdesc) | |
527 | pango_font_description_free( m_fontdesc ); | |
528 | ||
529 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
530 | ||
531 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
532 | } | |
533 | } | |
534 | ||
535 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
536 | { | |
537 | if (!pen.Ok()) return; | |
538 | ||
539 | int oldStyle = m_pen.GetStyle(); | |
540 | ||
541 | m_pen = pen; | |
542 | ||
543 | gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f ); | |
544 | ||
545 | unsigned char red = m_pen.GetColour().Red(); | |
546 | unsigned char blue = m_pen.GetColour().Blue(); | |
547 | unsigned char green = m_pen.GetColour().Green(); | |
548 | ||
549 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
550 | { | |
551 | double redPS = (double)(red) / 255.0; | |
552 | double bluePS = (double)(blue) / 255.0; | |
553 | double greenPS = (double)(green) / 255.0; | |
554 | ||
555 | gnome_print_setrgbcolor( m_gpc, redPS, bluePS, greenPS ); | |
556 | ||
557 | m_currentRed = red; | |
558 | m_currentBlue = blue; | |
559 | m_currentGreen = green; | |
560 | } | |
561 | } | |
562 | ||
563 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
564 | { | |
565 | } | |
566 | ||
567 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
568 | { | |
569 | } | |
570 | ||
571 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
572 | { | |
573 | } | |
574 | ||
575 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
576 | { | |
577 | } | |
578 | ||
579 | void wxGnomePrintDC::DestroyClippingRegion() | |
580 | { | |
581 | } | |
582 | ||
583 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
584 | { | |
585 | SetDeviceOrigin( 0,0 ); | |
586 | ||
587 | return true; | |
588 | } | |
589 | ||
590 | void wxGnomePrintDC::EndDoc() | |
591 | { | |
592 | } | |
593 | ||
594 | void wxGnomePrintDC::StartPage() | |
595 | { | |
596 | gnome_print_beginpage( m_gpc, (const guchar*) "1" ); | |
597 | } | |
598 | ||
599 | void wxGnomePrintDC::EndPage() | |
600 | { | |
601 | gnome_print_showpage( m_gpc ); | |
602 | } | |
603 | ||
604 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
605 | { | |
606 | return 0; | |
607 | } | |
608 | ||
609 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
610 | { | |
611 | return 0; | |
612 | } | |
613 | ||
981a6af1 | 614 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
615 | wxCoord *descent, |
616 | wxCoord *externalLeading, | |
617 | wxFont *theFont ) const | |
618 | { | |
981a6af1 RR |
619 | if ( width ) |
620 | *width = 0; | |
621 | if ( height ) | |
622 | *height = 0; | |
623 | if ( descent ) | |
624 | *descent = 0; | |
625 | if ( externalLeading ) | |
626 | *externalLeading = 0; | |
627 | ||
628 | if (string.IsEmpty()) | |
629 | { | |
630 | return; | |
631 | } | |
632 | ||
633 | // Set new font description | |
634 | if (theFont) | |
635 | pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); | |
636 | ||
637 | // Set layout's text | |
638 | #if wxUSE_UNICODE | |
639 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); | |
640 | const char *dataUTF8 = (const char *)data; | |
641 | #else | |
642 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
643 | if ( !wdata ) | |
644 | { | |
645 | if (width) (*width) = 0; | |
646 | if (height) (*height) = 0; | |
647 | return; | |
648 | } | |
649 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
650 | const char *dataUTF8 = (const char *)data; | |
651 | #endif | |
652 | ||
653 | if ( !dataUTF8 ) | |
654 | { | |
655 | // hardly ideal, but what else can we do if conversion failed? | |
656 | return; | |
657 | } | |
658 | ||
659 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
660 | ||
661 | int w,h; | |
662 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
663 | ||
664 | if (width) | |
665 | *width = (wxCoord) w; | |
666 | if (height) | |
667 | *height = (wxCoord) h; | |
668 | if (descent) | |
669 | { | |
670 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
671 | int baseline = pango_layout_iter_get_baseline(iter); | |
672 | pango_layout_iter_free(iter); | |
673 | *descent = h - PANGO_PIXELS(baseline); | |
674 | } | |
675 | ||
676 | // Reset old font description | |
677 | if (theFont) | |
678 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ff910433 RR |
679 | } |
680 | ||
681 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
682 | { | |
683 | // No idea if that is efficient | |
684 | GnomePrintConfig *config = gnome_print_config_default(); | |
685 | ||
686 | double w,h; | |
687 | bool result = gnome_print_config_get_page_size( config, &w, &h ); | |
688 | ||
689 | if (!result) | |
690 | { | |
691 | // Standard PS resolution DIN A4 size. | |
692 | w = 595.0; | |
693 | h = 842.0; | |
694 | } | |
695 | ||
696 | if (width) | |
697 | *width = (int) w; | |
698 | if (height) | |
699 | *height = (int) h; | |
ff910433 RR |
700 | } |
701 | ||
702 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
703 | { | |
704 | double w,h; | |
705 | ||
706 | /// Later, for now DIN A4 | |
707 | w = 210.0; | |
708 | h = 297.0; | |
709 | ||
710 | if (width) | |
711 | *width = (int) w; | |
712 | if (height) | |
713 | *height = (int) h; | |
714 | } | |
715 | ||
716 | wxSize wxGnomePrintDC::GetPPI() const | |
717 | { | |
718 | return wxSize(72,72); | |
719 | } | |
720 | ||
721 | void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
722 | { | |
723 | m_signX = (xLeftRight ? 1 : -1); | |
724 | m_signY = (yBottomUp ? 1 : -1); | |
725 | ||
726 | ComputeScaleAndOrigin(); | |
727 | } | |
728 | ||
729 | void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
730 | { | |
731 | int h = 0; | |
732 | int w = 0; | |
733 | GetSize( &w, &h ); | |
734 | ||
735 | wxDC::SetDeviceOrigin( x, h-y ); | |
736 | } | |
737 | ||
738 | void wxGnomePrintDC::SetResolution(int ppi) | |
739 | { | |
740 | } | |
741 | ||
742 | int wxGnomePrintDC::GetResolution() | |
743 | { | |
744 | return 72; | |
745 | } | |
7c72311f | 746 | |
58c30cd8 RR |
747 | |
748 | class wxGnomePrintModule: public wxModule | |
749 | { | |
750 | public: | |
751 | wxGnomePrintModule() {} | |
752 | bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); return true; } | |
753 | void OnExit() { } | |
754 | ||
755 | private: | |
756 | DECLARE_DYNAMIC_CLASS(wxGnomePrintModule) | |
757 | }; | |
758 | ||
759 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) | |
760 | ||
7c72311f RR |
761 | #endif |
762 | // wxUSE_LIBGNOMEPRINT |