Simplify drawing spline in wxPostScriptDC
We can produce simpler and more readable PostScript code by doing the calculations of Bézier curve parameters in the code instead of delegating this task to the PostScript processor.
This commit is contained in:
@@ -102,23 +102,6 @@ static const char *wxPostScriptHeaderEllipticArc=
|
|||||||
" { fill }{ stroke } ifelse\n" // -> fill or stroke
|
" { fill }{ stroke } ifelse\n" // -> fill or stroke
|
||||||
"} def\n";
|
"} def\n";
|
||||||
|
|
||||||
static const char *wxPostScriptHeaderSpline = "\
|
|
||||||
/DrawSplineSection {\n\
|
|
||||||
/y3 exch def\n\
|
|
||||||
/x3 exch def\n\
|
|
||||||
/y2 exch def\n\
|
|
||||||
/x2 exch def\n\
|
|
||||||
/y1 exch def\n\
|
|
||||||
/x1 exch def\n\
|
|
||||||
/xa x1 x2 x1 sub 0.666667 mul add def\n\
|
|
||||||
/ya y1 y2 y1 sub 0.666667 mul add def\n\
|
|
||||||
/xb x3 x2 x3 sub 0.666667 mul add def\n\
|
|
||||||
/yb y3 y2 y3 sub 0.666667 mul add def\n\
|
|
||||||
x1 y1 lineto\n\
|
|
||||||
xa ya xb yb x3 y3 curveto\n\
|
|
||||||
} def\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
static const char *wxPostScriptHeaderColourImage = "\
|
static const char *wxPostScriptHeaderColourImage = "\
|
||||||
% define 'colorimage' if it isn't defined\n\
|
% define 'colorimage' if it isn't defined\n\
|
||||||
% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
|
% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
|
||||||
@@ -1468,8 +1451,6 @@ void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points )
|
|||||||
|
|
||||||
SetPen( m_pen );
|
SetPen( m_pen );
|
||||||
|
|
||||||
// a and b are not used
|
|
||||||
//double a, b;
|
|
||||||
double c, d, x1, y1, x3, y3;
|
double c, d, x1, y1, x3, y3;
|
||||||
wxPoint *p, *q;
|
wxPoint *p, *q;
|
||||||
|
|
||||||
@@ -1482,16 +1463,8 @@ void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points )
|
|||||||
p = node->GetData();
|
p = node->GetData();
|
||||||
c = p->x;
|
c = p->x;
|
||||||
d = p->y;
|
d = p->y;
|
||||||
x3 =
|
x3 = (double)(x1 + c) / 2;
|
||||||
#if 0
|
y3 = (double)(y1 + d) / 2;
|
||||||
a =
|
|
||||||
#endif
|
|
||||||
(double)(x1 + c) / 2;
|
|
||||||
y3 =
|
|
||||||
#if 0
|
|
||||||
b =
|
|
||||||
#endif
|
|
||||||
(double)(y1 + d) / 2;
|
|
||||||
|
|
||||||
wxString buffer;
|
wxString buffer;
|
||||||
buffer.Printf( "newpath\n"
|
buffer.Printf( "newpath\n"
|
||||||
@@ -1520,10 +1493,16 @@ void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points )
|
|||||||
x3 = (double)(x2 + c) / 2;
|
x3 = (double)(x2 + c) / 2;
|
||||||
y3 = (double)(y2 + d) / 2;
|
y3 = (double)(y2 + d) / 2;
|
||||||
|
|
||||||
buffer.Printf( "%f %f %f %f %f %f DrawSplineSection\n",
|
// Calculate using degree elevation to a cubic bezier
|
||||||
XLOG2DEV(wxRound(x1)), YLOG2DEV(wxRound(y1)),
|
wxDouble c1x = (x1 + 2 * x2) / 3.0;
|
||||||
XLOG2DEV(wxRound(x2)), YLOG2DEV(wxRound(y2)),
|
wxDouble c1y = (y1 + 2 * y2) / 3.0;
|
||||||
XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3)) );
|
wxDouble c2x = (2 * x2 + x3) / 3.0;
|
||||||
|
wxDouble c2y = (2 * y2 + y3) / 3.0;
|
||||||
|
|
||||||
|
buffer.Printf("%f %f %f %f %f %f curveto\n",
|
||||||
|
XLOG2DEV(wxRound(c1x)), YLOG2DEV(wxRound(c1y)),
|
||||||
|
XLOG2DEV(wxRound(c2x)), YLOG2DEV(wxRound(c2y)),
|
||||||
|
XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3)));
|
||||||
buffer.Replace( ",", "." );
|
buffer.Replace( ",", "." );
|
||||||
PsPrint( buffer );
|
PsPrint( buffer );
|
||||||
|
|
||||||
@@ -1718,8 +1697,6 @@ bool wxPostScriptDCImpl::StartDoc( const wxString& WXUNUSED(message) )
|
|||||||
PsPrint( wxPostScriptHeaderColourImage );
|
PsPrint( wxPostScriptHeaderColourImage );
|
||||||
PsPrint( wxPostScriptHeaderReencodeISO1 );
|
PsPrint( wxPostScriptHeaderReencodeISO1 );
|
||||||
PsPrint( wxPostScriptHeaderReencodeISO2 );
|
PsPrint( wxPostScriptHeaderReencodeISO2 );
|
||||||
if (wxPostScriptHeaderSpline)
|
|
||||||
PsPrint( wxPostScriptHeaderSpline );
|
|
||||||
PsPrint( wxPostScriptHeaderStrSplit );
|
PsPrint( wxPostScriptHeaderStrSplit );
|
||||||
PsPrint( "%%EndProlog\n" );
|
PsPrint( "%%EndProlog\n" );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user