Added support for DrawEllipse and pen styles to
GNOME printing. Added test. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ece835440d
commit
cac7ac30cb
@ -36,7 +36,7 @@
|
||||
#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
|
||||
@ -71,6 +71,8 @@ bool WritePageHeader(wxPrintout *printout, wxDC *dc, wxChar *text, float mmToLog
|
||||
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
wxInitAllImageHandlers();
|
||||
|
||||
m_testFont.Create(10, wxSWISS, wxNORMAL, wxNORMAL);
|
||||
|
||||
g_printData = new wxPrintData;
|
||||
@ -108,6 +110,9 @@ bool MyApp::OnInit(void)
|
||||
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"));
|
||||
|
||||
@ -159,6 +164,8 @@ EVT_MENU(WXPRINT_PRINT_PS, MyFrame::OnPrintPS)
|
||||
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
|
||||
@ -166,6 +173,16 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, cons
|
||||
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))
|
||||
@ -212,7 +229,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
(*g_pageSetupData) = * g_printData;
|
||||
(*g_pageSetupData) = *g_printData;
|
||||
|
||||
wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
|
||||
pageSetupDialog.ShowModal();
|
||||
@ -261,6 +278,18 @@ void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event))
|
||||
_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);
|
||||
@ -269,23 +298,34 @@ void MyFrame::Draw(wxDC& dc)
|
||||
|
||||
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);
|
||||
@ -293,6 +333,9 @@ void MyFrame::Draw(wxDC& dc)
|
||||
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 )
|
||||
|
@ -33,9 +33,13 @@ class MyFrame: public wxFrame
|
||||
{
|
||||
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);
|
||||
@ -89,3 +93,5 @@ class MyPrintout: public wxPrintout
|
||||
|
||||
#define WXPRINT_ABOUT 109
|
||||
|
||||
#define WXPRINT_ANGLEUP 110
|
||||
#define WXPRINT_ANGLEDOWN 111
|
||||
|
@ -386,7 +386,7 @@ int wxGnomePageSetupDialog::ShowModal()
|
||||
|
||||
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,
|
||||
@ -637,10 +637,10 @@ void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
|
||||
|
||||
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 );
|
||||
}
|
||||
@ -663,6 +663,22 @@ void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y)
|
||||
|
||||
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)
|
||||
@ -714,6 +730,57 @@ void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width,
|
||||
|
||||
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)
|
||||
@ -946,6 +1013,24 @@ void wxGnomePrintDC::SetPen( const wxPen& pen )
|
||||
|
||||
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();
|
||||
@ -1028,6 +1113,7 @@ bool wxGnomePrintDC::StartDoc(const wxString& message)
|
||||
|
||||
void wxGnomePrintDC::EndDoc()
|
||||
{
|
||||
gnome_print_end_doc( m_gpc );
|
||||
}
|
||||
|
||||
void wxGnomePrintDC::StartPage()
|
||||
|
@ -386,7 +386,7 @@ int wxGnomePageSetupDialog::ShowModal()
|
||||
|
||||
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,
|
||||
@ -637,10 +637,10 @@ void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
|
||||
|
||||
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 );
|
||||
}
|
||||
@ -663,6 +663,22 @@ void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y)
|
||||
|
||||
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)
|
||||
@ -714,6 +730,57 @@ void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width,
|
||||
|
||||
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)
|
||||
@ -946,6 +1013,24 @@ void wxGnomePrintDC::SetPen( const wxPen& pen )
|
||||
|
||||
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();
|
||||
@ -1028,6 +1113,7 @@ bool wxGnomePrintDC::StartDoc(const wxString& message)
|
||||
|
||||
void wxGnomePrintDC::EndDoc()
|
||||
{
|
||||
gnome_print_end_doc( m_gpc );
|
||||
}
|
||||
|
||||
void wxGnomePrintDC::StartPage()
|
||||
|
Loading…
Reference in New Issue
Block a user