dcpsg.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 2,062 行 · 第 1/5 页
CPP
2,062 行
PsPrint( ") show\n" );
if (m_font.GetUnderlined())
{
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
char buffer[100];
sprintf( buffer,
"gsave\n"
"%d %d moveto\n"
"%f setlinewidth\n"
"%d %d lineto\n"
"stroke\n"
"grestore\n",
LogicalToDeviceX(x), LogicalToDeviceY(uy),
m_underlineThickness,
LogicalToDeviceX(x + text_w), LogicalToDeviceY(uy) );
for (i = 0; i < 100; i++)
if (buffer[i] == ',') buffer[i] = '.';
PsPrint( buffer );
}
CalcBoundingBox( x, y );
CalcBoundingBox( x + size * text.Length() * 2/3 , y );
}
void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
{
if (angle == 0.0)
{
DoDrawText(text, x, y);
return;
}
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
SetFont( m_font );
if (m_textForegroundColour.Ok())
{
unsigned char red = m_textForegroundColour.Red();
unsigned char blue = m_textForegroundColour.Blue();
unsigned char green = m_textForegroundColour.Green();
if (!m_colour)
{
// Anything not white is black
if (! (red == (unsigned char) 255 &&
blue == (unsigned char) 255 &&
green == (unsigned char) 255))
{
red = (unsigned char) 0;
green = (unsigned char) 0;
blue = (unsigned char) 0;
}
}
// maybe setgray here ?
if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
{
double redPS = (double)(red) / 255.0;
double bluePS = (double)(blue) / 255.0;
double greenPS = (double)(green) / 255.0;
char buffer[100];
sprintf( buffer,
"%.8f %.8f %.8f setrgbcolor\n",
redPS, greenPS, bluePS );
for (int i = 0; i < 100; i++)
if (buffer[i] == ',') buffer[i] = '.';
PsPrint( buffer );
m_currentRed = red;
m_currentBlue = blue;
m_currentGreen = green;
}
}
int size = m_font.GetPointSize();
PsPrintf( wxT("%d %d moveto\n"),
LogicalToDeviceX(x), LogicalToDeviceY(y));
char buffer[100];
sprintf(buffer, "%.8f rotate\n", angle);
size_t i;
for (i = 0; i < 100; i++)
{
if (buffer[i] == ',') buffer[i] = '.';
}
PsPrint( buffer);
PsPrint( "(" );
const wxWX2MBbuf textbuf = text.mb_str();
size_t len = strlen(textbuf);
for (i = 0; i < len; i++)
{
int c = (unsigned char) textbuf[i];
if (c == ')' || c == '(' || c == '\\')
{
/* Cope with special characters */
PsPrint( "\\" );
PsPrint(c);
}
else if ( c >= 128 )
{
/* Cope with character codes > 127 */
PsPrintf( wxT("\\%o"), c);
}
else
{
PsPrint(c);
}
}
PsPrint( ") show\n" );
sprintf( buffer, "%.8f rotate\n", -angle );
for (i = 0; i < 100; i++)
{
if (buffer[i] == ',') buffer[i] = '.';
}
PsPrint( buffer );
if (m_font.GetUnderlined())
{
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
wxCoord w, h;
char buffer[100];
GetTextExtent(text, &w, &h);
sprintf( buffer,
"gsave\n"
"%d %d moveto\n"
"%f setlinewidth\n"
"%d %d lineto\n"
"stroke\n"
"grestore\n",
LogicalToDeviceX(x), LogicalToDeviceY(uy),
m_underlineThickness,
LogicalToDeviceX(x + w), LogicalToDeviceY(uy) );
for (i = 0; i < 100; i++)
{
if (buffer[i] == ',') buffer[i] = '.';
}
PsPrint( buffer );
}
CalcBoundingBox( x, y );
CalcBoundingBox( x + size * text.Length() * 2/3 , y );
}
void wxPostScriptDC::SetBackground (const wxBrush& brush)
{
m_backgroundBrush = brush;
}
void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function))
{
wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
}
#if wxUSE_SPLINES
void wxPostScriptDC::DoDrawSpline( wxList *points )
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
SetPen( m_pen );
// a and b are not used
//double a, b;
double c, d, x1, y1, x2, y2, x3, y3;
wxPoint *p, *q;
wxList::compatibility_iterator node = points->GetFirst();
p = (wxPoint *)node->GetData();
x1 = p->x;
y1 = p->y;
node = node->GetNext();
p = (wxPoint *)node->GetData();
c = p->x;
d = p->y;
x3 =
#if 0
a =
#endif
(double)(x1 + c) / 2;
y3 =
#if 0
b =
#endif
(double)(y1 + d) / 2;
PsPrintf( wxT("newpath\n")
wxT("%d %d moveto\n")
wxT("%d %d lineto\n"),
LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
node = node->GetNext();
while (node)
{
q = (wxPoint *)node->GetData();
x1 = x3;
y1 = y3;
x2 = c;
y2 = d;
c = q->x;
d = q->y;
x3 = (double)(x2 + c) / 2;
y3 = (double)(y2 + d) / 2;
PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
LogicalToDeviceX((wxCoord)x2), LogicalToDeviceY((wxCoord)y2),
LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
node = node->GetNext();
}
/*
At this point, (x2,y2) and (c,d) are the position of the
next-to-last and last point respectively, in the point list
*/
PsPrintf( wxT("%d %d lineto\n")
wxT("stroke\n"),
LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) );
}
#endif // wxUSE_SPLINES
wxCoord wxPostScriptDC::GetCharWidth() const
{
// Chris Breeze: reasonable approximation using wxMODERN/Courier
return (wxCoord) (GetCharHeight() * 72.0 / 120.0);
}
void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
m_signX = (xLeftRight ? 1 : -1);
m_signY = (yBottomUp ? 1 : -1);
ComputeScaleAndOrigin();
}
void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y )
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
int h = 0;
int w = 0;
GetSize( &w, &h );
wxDC::SetDeviceOrigin( x, h-y );
}
void wxPostScriptDC::DoGetSize(int* width, int* height) const
{
wxPaperSize id = m_printData.GetPaperId();
wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
int w = 595;
int h = 842;
if (paper)
{
w = paper->GetSizeDeviceUnits().x;
h = paper->GetSizeDeviceUnits().y;
}
if (m_printData.GetOrientation() == wxLANDSCAPE)
{
int tmp = w;
w = h;
h = tmp;
}
if (width) *width = (int)(w * ms_PSScaleFactor);
if (height) *height = (int)(h * ms_PSScaleFactor);
}
void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const
{
wxPaperSize id = m_printData.GetPaperId();
wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
int w = 210;
int h = 297;
if (paper)
{
w = paper->GetWidth() / 10;
h = paper->GetHeight() / 10;
}
if (m_printData.GetOrientation() == wxLANDSCAPE)
{
int tmp = w;
w = h;
h = tmp;
}
if (width) *width = w;
if (height) *height = h;
}
// Resolution in pixels per logical inch
wxSize wxPostScriptDC::GetPPI(void) const
{
return wxSize((int)(72 * ms_PSScaleFactor),
(int)(72 * ms_PSScaleFactor));
}
bool wxPostScriptDC::StartDoc( const wxString& message )
{
wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
{
if (m_printData.GetFilename() == wxEmptyString)
{
wxString filename = wxGetTempFileName( wxT("ps") );
m_printData.SetFilename(filename);
}
m_pstream = wxFopen( m_printData.GetFilename(), wxT("w+") );
if (!m_pstream)
{
wxLogError( _("Cannot open file for PostScript printing!"));
m_ok = false;
return false;
}
}
m_ok = true;
m_title = message;
PsPrint( "%!PS-Adobe-2.0\n" );
PsPrintf( wxT("%%%%Title: %s\n"), m_title.c_str() );
PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
if (m_printData.GetOrientation() == wxLANDSCAPE)
PsPrint( "%%Orientation: Landscape\n" );
else
PsPrint( "%%Orientation: Portrait\n" );
// PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
const wxChar *paper;
switch (m_printData.GetPaperId())
{
case wxPAPER_LETTER: paper = wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
case wxPAPER_LEGAL: paper = wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
case wxPAPER_A4: paper = wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
case wxPAPER_TABLOID: paper = wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
case wxPAPER_LEDGER: paper = wxT("Ledger"); break; // Ledger, 17 by 11 inches
case wxPAPER_STATEMENT: paper = wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
case wxPAPER_EXECUTIVE: paper = wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
case wxPAPER_A3: paper = wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
case wxPAPER_A5: paper = wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
case wxPAPER_B4: paper = wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
case wxPAPER_B5: paper = wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
case wxPAPER_FOLIO: paper = wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
case wxPAPER_QUARTO: paper = wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
case wxPAPER_10X14: paper = wxT("10x14"); break; // 10-by-14-inch sheet
default: paper = wxT("A4");
}
PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper );
PsPrint( "%%EndComments\n\n" );
PsPrint( "%%BeginProlog\n" );
PsPrint( wxPostScriptHeaderConicTo );
PsPrint( wxPostScriptHeaderEllipse );
PsPrint( wxPostScriptHeaderEllipticArc );
PsPrint( wxPostScriptHeaderColourImage );
PsPrint( wxPostScriptHeaderReencodeISO1 );
PsPrint( wxPostScriptHeaderReencodeISO2 );
if (wxPostScriptHeaderSpline)
PsPrint( wxPostScriptHeaderSpline );
PsPrint( "%%EndProlog\n" );
SetBrush( *wxBLACK_BRUSH );
SetPen( *wxBLACK_PEN );
SetBackground( *wxWHITE_BRUSH );
SetTextForeground( *wxBLACK );
// set origin according to paper size
SetDeviceOrigin( 0,0 );
wxPageNumber = 1;
m_pageNumber = 1;
return true;
}
void wxPostScriptDC::EndDoc ()
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?