X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f415cab9ef1433413a1a68a982ee9b17c5a8deda..cfcc02a8a4f019e3846b73660209080602e44967:/samples/printing/printing.cpp?ds=sidebyside diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index bfe2f16192..0b4c31accc 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -40,6 +40,10 @@ #include "wx/generic/prntdlgg.h" #endif +#if wxUSE_GRAPHICS_CONTEXT +#include "wx/graphics.h" +#endif + #ifdef __WXMAC__ #include "wx/mac/printdlg.h" #endif @@ -50,12 +54,6 @@ #include "mondrian.xpm" #endif -#if wxUSE_LIBGNOMEPRINT -#include "wx/html/forcelnk.h" -FORCE_LINK(gnome_print) -#endif - - // Declare a frame MyFrame *frame = (MyFrame *) NULL; // int orientation = wxPORTRAIT; @@ -77,14 +75,17 @@ bool WritePageHeader(wxPrintout *printout, wxDC *dc, const wxChar *text, float m bool MyApp::OnInit(void) { + if ( !wxApp::OnInit() ) + return false; + wxInitAllImageHandlers(); m_testFont.Create(10, wxSWISS, wxNORMAL, wxNORMAL); g_printData = new wxPrintData; - // Set an initial paper size + // You could set an initial paper size here // g_printData->SetPaperId(wxPAPER_LETTER); // for Americans - g_printData->SetPaperId(wxPAPER_A4); // for everyone else +// g_printData->SetPaperId(wxPAPER_A4); // for everyone else g_pageSetupData = new wxPageSetupDialogData; // copy over initial paper size from print record @@ -334,13 +335,14 @@ void MyFrame::Draw(wxDC& dc) // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); - dc.Clear(); + // dc.Clear(); dc.SetFont(wxGetApp().m_testFont); - dc.SetBackgroundMode(wxTRANSPARENT); + // dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); + dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); @@ -350,7 +352,7 @@ void MyFrame::Draw(wxDC& dc) dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); - + dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK,0,wxDOT_DASH) ); @@ -360,7 +362,7 @@ void MyFrame::Draw(wxDC& dc) dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE - char *test = "Hebrew שלום -- Japanese (日本語)"; + const char *test = "Hebrew שלום -- Japanese (日本語)"; wxString tmp = wxConvUTF8.cMB2WC( test ); dc.DrawText( tmp, 10, 200 ); #endif @@ -408,6 +410,38 @@ void MyFrame::Draw(wxDC& dc) if (m_bitmap.Ok()) dc.DrawBitmap( m_bitmap, 10, 10 ); + +#if wxUSE_GRAPHICS_CONTEXT + wxGraphicsContext *gc = NULL; + + wxPrinterDC *printer_dc = wxDynamicCast( &dc, wxPrinterDC ); + if (printer_dc) + gc = wxGraphicsContext::Create( *printer_dc ); + + wxWindowDC *window_dc = wxDynamicCast( &dc, wxWindowDC ); + if (window_dc) + gc = wxGraphicsContext::Create( *window_dc ); + + if (gc) + { + // make a path that contains a circle and some lines, centered at 100,100 + gc->SetPen( *wxRED_PEN ); + gc->SetFont( wxGetApp().m_testFont, *wxGREEN ); + wxGraphicsPath path = gc->CreatePath(); + path.AddCircle( 50.0, 50.0, 50.0 ); + path.MoveToPoint(0.0, 50.0); + path.AddLineToPoint(100.0, 50.0); + path.MoveToPoint(50.0, 0.0); + path.AddLineToPoint(50.0, 100.0 ); + path.CloseSubpath(); + path.AddRectangle(25.0, 25.0, 50.0, 50.0); + + gc->StrokePath(path); + + delete gc; + } +#endif + } void MyFrame::OnSize(wxSizeEvent& event ) @@ -606,7 +640,7 @@ void MyPrintout::DrawPageTwo() { // GetTextExtent demo: wxString words[7] = {_T("This "), _T("is "), _T("GetTextExtent "), _T("testing "), _T("string. "), _T("Enjoy "), _T("it!")}; - long w, h; + wxCoord w, h; long x = 200, y= 250; wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL); @@ -678,7 +712,7 @@ dc->SetFont(headerFont); float topMarginLogical = (float)(mmToLogical*topMargin); float rightMarginLogical = (float)(mmToLogical*(pageWidthMM - rightMargin)); - long xExtent, yExtent; + wxCoord xExtent, yExtent; dc->GetTextExtent(text, &xExtent, &yExtent); float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0)); dc->DrawText(text, (long)xPos, (long)topMarginLogical);