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