#include "wx/metafile.h"
#include "wx/print.h"
#include "wx/printdlg.h"
-
+#include "wx/image.h"
#include "wx/accel.h"
#if wxTEST_POSTSCRIPT_IN_MSW
bool MyApp::OnInit(void)
{
+ wxInitAllImageHandlers();
+
m_testFont.Create(10, wxSWISS, wxNORMAL, wxNORMAL);
g_printData = new wxPrintData;
file_menu->Append(WXPRINT_PAGE_SETUP_PS, _T("Page Setup PostScript..."), _T("Page setup (PostScript)"));
file_menu->Append(WXPRINT_PREVIEW_PS, _T("Print Preview PostScript"), _T("Preview (PostScript)"));
#endif
+ file_menu->AppendSeparator();
+ file_menu->Append(WXPRINT_ANGLEUP, _T("Angle up\tAlt-U"), _T("Raise rotated text angle"));
+ file_menu->Append(WXPRINT_ANGLEDOWN, _T("Angle down\tAlt-D"), _T("Lower rotated text angle"));
file_menu->AppendSeparator();
file_menu->Append(WXPRINT_QUIT, _T("E&xit"), _T("Exit program"));
EVT_MENU(WXPRINT_PREVIEW_PS, MyFrame::OnPrintPreviewPS)
EVT_MENU(WXPRINT_PAGE_SETUP_PS, MyFrame::OnPageSetupPS)
#endif
+EVT_MENU(WXPRINT_ANGLEUP, MyFrame::OnAngleUp)
+EVT_MENU(WXPRINT_ANGLEDOWN, MyFrame::OnAngleDown)
END_EVENT_TABLE()
// Define my frame constructor
wxFrame(frame, wxID_ANY, title, pos, size)
{
canvas = NULL;
+ m_angle = 30;
+#if 0
+ wxImage image( wxT("test.jpg") );
+ image.SetAlpha();
+ int i,j;
+ for (i = 0; i < image.GetWidth(); i++)
+ for (j = 0; j < image.GetHeight(); j++)
+ image.SetAlpha( i, j, 50 );
+ m_bitmap = image;
+#endif
}
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
{
- (*g_pageSetupData) = * g_printData;
+ (*g_pageSetupData) = *g_printData;
wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
pageSetupDialog.ShowModal();
_T("About wxWidgets printing demo"), wxOK|wxCENTRE);
}
+void MyFrame::OnAngleUp(wxCommandEvent& event)
+{
+ m_angle += 5;
+ canvas->Refresh();
+}
+
+void MyFrame::OnAngleDown(wxCommandEvent& event)
+{
+ m_angle -= 5;
+ canvas->Refresh();
+}
+
void MyFrame::Draw(wxDC& dc)
{
dc.SetBackground(*wxWHITE_BRUSH);
dc.SetBackgroundMode(wxTRANSPARENT);
- dc.SetBrush(* wxCYAN_BRUSH);
- dc.SetPen(* wxRED_PEN);
+ dc.SetBrush(*wxCYAN_BRUSH);
+ dc.SetPen(*wxRED_PEN);
dc.DrawRectangle(0, 30, 200, 100);
dc.DrawText( wxT("Rectangle 200 by 100"), 40, 40);
+ dc.SetPen( wxPen(*wxBLACK,0,wxDOT_DASH) );
dc.DrawEllipse(50, 140, 100, 50);
+ dc.SetPen(*wxRED_PEN);
dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180);
-
+
#if wxUSE_UNICODE
char *test = "Hebrew שלום -- Japanese (日本語)";
wxString tmp = wxConvUTF8.cMB2WC( test );
dc.DrawText( tmp, 10, 200 );
#endif
+ wxString str;
+ int i = 0;
+ str.Printf( wxT("---- Text at angle %d ----"), i );
+ dc.DrawRotatedText( str, 100, 300, i );
+
+ i = m_angle;
+ str.Printf( wxT("---- Text at angle %d ----"), i );
+ dc.DrawRotatedText( str, 100, 300, i );
+
dc.SetPen(* wxBLACK_PEN);
dc.DrawLine(0, 0, 200, 200);
dc.DrawLine(200, 0, 0, 200);
wxIcon my_icon = wxICON(mondrian) ;
dc.DrawIcon( my_icon, 100, 100);
+
+ if (m_bitmap.Ok())
+ dc.DrawBitmap( m_bitmap, 10, 10 );
}
void MyFrame::OnSize(wxSizeEvent& event )
{
public:
MyCanvas *canvas;
+ wxBitmap m_bitmap;
+ int m_angle;
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
void Draw(wxDC& dc);
+ void OnAngleUp(wxCommandEvent& event);
+ void OnAngleDown(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
void OnPrint(wxCommandEvent& event);
#define WXPRINT_ABOUT 109
+#define WXPRINT_ANGLEUP 110
+#define WXPRINT_ANGLEDOWN 111
m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );
-#if 1
+#if 0
wxPrintf( wxT("paper %d %d, top margin %d\n"),
m_pageDialogData.GetPaperSize().x,
m_pageDialogData.GetPaperSize().y,
SetPen( m_pen );
- gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
- gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
- gnome_print_stroke ( m_gpc);
-
+ gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
+ gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
+ gnome_print_stroke ( m_gpc);
+
CalcBoundingBox( x1, y1 );
CalcBoundingBox( x2, y2 );
}
void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
+ if (m_pen.GetStyle() == wxTRANSPARENT) return;
+
+ if (n <= 0) return;
+
+ SetPen (m_pen);
+
+ int i;
+ for ( i =0; i<n ; i++ )
+ CalcBoundingBox( XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset));
+
+ gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
+
+ for (i = 1; i < n; i++)
+ gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
+
+ gnome_print_stroke ( m_gpc);
}
void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
+ if (m_brush.GetStyle () != wxTRANSPARENT)
+ {
+ SetBrush( m_brush );
+
+ gnome_print_newpath( m_gpc );
+ gnome_print_moveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ // start with top half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
+ // lower half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x+width), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ gnome_print_closepath( m_gpc );
+ gnome_print_fill( m_gpc );
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+ }
+
+ if (m_pen.GetStyle () != wxTRANSPARENT)
+ {
+ SetPen (m_pen);
+
+ gnome_print_newpath( m_gpc );
+ gnome_print_moveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ // start with top half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
+ // lower half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x+width), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ gnome_print_closepath( m_gpc );
+ gnome_print_stroke( m_gpc );
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+ }
}
void wxGnomePrintDC::DoDrawSpline(wxList *points)
gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f );
+
+ static const double dotted[] = {2.0, 5.0};
+ static const double short_dashed[] = {4.0, 4.0};
+ static const double wxCoord_dashed[] = {4.0, 8.0};
+ static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
+
+ switch (m_pen.GetStyle())
+ {
+ case wxDOT: gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
+ case wxSHORT_DASH: gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
+ case wxLONG_DASH: gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
+ case wxDOT_DASH: gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break;
+ case wxSOLID:
+ case wxTRANSPARENT:
+ default: gnome_print_setdash( m_gpc, 0, NULL, 0 ); break;
+ }
+
+
unsigned char red = m_pen.GetColour().Red();
unsigned char blue = m_pen.GetColour().Blue();
unsigned char green = m_pen.GetColour().Green();
void wxGnomePrintDC::EndDoc()
{
+ gnome_print_end_doc( m_gpc );
}
void wxGnomePrintDC::StartPage()
m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );
-#if 1
+#if 0
wxPrintf( wxT("paper %d %d, top margin %d\n"),
m_pageDialogData.GetPaperSize().x,
m_pageDialogData.GetPaperSize().y,
SetPen( m_pen );
- gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
- gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
- gnome_print_stroke ( m_gpc);
-
+ gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
+ gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
+ gnome_print_stroke ( m_gpc);
+
CalcBoundingBox( x1, y1 );
CalcBoundingBox( x2, y2 );
}
void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
+ if (m_pen.GetStyle() == wxTRANSPARENT) return;
+
+ if (n <= 0) return;
+
+ SetPen (m_pen);
+
+ int i;
+ for ( i =0; i<n ; i++ )
+ CalcBoundingBox( XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset));
+
+ gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
+
+ for (i = 1; i < n; i++)
+ gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
+
+ gnome_print_stroke ( m_gpc);
}
void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
+ if (m_brush.GetStyle () != wxTRANSPARENT)
+ {
+ SetBrush( m_brush );
+
+ gnome_print_newpath( m_gpc );
+ gnome_print_moveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ // start with top half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
+ // lower half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x+width), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ gnome_print_closepath( m_gpc );
+ gnome_print_fill( m_gpc );
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+ }
+
+ if (m_pen.GetStyle () != wxTRANSPARENT)
+ {
+ SetPen (m_pen);
+
+ gnome_print_newpath( m_gpc );
+ gnome_print_moveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ // start with top half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y),
+ XLOG2DEV(x+width), YLOG2DEV(y+height/2) );
+ // lower half
+ gnome_print_curveto( m_gpc,
+ XLOG2DEV(x+width), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height),
+ XLOG2DEV(x), YLOG2DEV(y+height/2) );
+
+ gnome_print_closepath( m_gpc );
+ gnome_print_stroke( m_gpc );
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+ }
}
void wxGnomePrintDC::DoDrawSpline(wxList *points)
gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f );
+
+ static const double dotted[] = {2.0, 5.0};
+ static const double short_dashed[] = {4.0, 4.0};
+ static const double wxCoord_dashed[] = {4.0, 8.0};
+ static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
+
+ switch (m_pen.GetStyle())
+ {
+ case wxDOT: gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
+ case wxSHORT_DASH: gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
+ case wxLONG_DASH: gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
+ case wxDOT_DASH: gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break;
+ case wxSOLID:
+ case wxTRANSPARENT:
+ default: gnome_print_setdash( m_gpc, 0, NULL, 0 ); break;
+ }
+
+
unsigned char red = m_pen.GetColour().Red();
unsigned char blue = m_pen.GetColour().Blue();
unsigned char green = m_pen.GetColour().Green();
void wxGnomePrintDC::EndDoc()
{
+ gnome_print_end_doc( m_gpc );
}
void wxGnomePrintDC::StartPage()