X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aece0491ee47ba60c8bf7ed8f8482e39d1c5cc59..738f9e5a12b8bb3936cc10347be98390602d3660:/src/generic/dcpsg.cpp?ds=sidebyside diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 8fb105fc8f..3f039b97ac 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -362,18 +362,18 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) wxChar userId[256]; wxGetUserId (userId, sizeof (userId) / sizeof (char)); wxChar tmp[256]; - wxStrcpy (tmp, _T("/tmp/preview_")); + wxStrcpy (tmp, wxT("/tmp/preview_")); wxStrcat (tmp, userId); m_printData.SetFilename(tmp); #endif wxChar tmp2[256]; wxStrcpy(tmp2, m_printData.GetFilename()); - wxStrcat (tmp2, _T(".ps")); + wxStrcat (tmp2, wxT(".ps")); m_printData.SetFilename(tmp2); } - else if ((m_printData.GetFilename() == _T("")) && (m_printData.GetPrintMode() == wxPRINT_MODE_FILE)) + else if ((m_printData.GetFilename() == wxT("")) && (m_printData.GetPrintMode() == wxPRINT_MODE_FILE)) { - wxString file = wxSaveFileSelector (_("PostScript"), _T("ps")); + wxString file = wxSaveFileSelector (_("PostScript"), wxT("ps")); if ( file.IsEmpty() ) { m_ok = FALSE; @@ -389,7 +389,7 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) void wxPostScriptDC::SetClippingRegion (long x, long y, long w, long h) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_clipping) return; @@ -411,12 +411,12 @@ void wxPostScriptDC::SetClippingRegion (long x, long y, long w, long h) void wxPostScriptDC::SetClippingRegion( const wxRegion &WXUNUSED(region) ) { - wxFAIL_MSG( _T("wxPostScriptDC::SetClippingRegion not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::SetClippingRegion not implemented.") ); } void wxPostScriptDC::DestroyClippingRegion() { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); wxDC::DestroyClippingRegion(); @@ -429,28 +429,28 @@ void wxPostScriptDC::DestroyClippingRegion() void wxPostScriptDC::Clear() { - wxFAIL_MSG( _T("wxPostScriptDC::Clear not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") ); } void wxPostScriptDC::DoFloodFill (long WXUNUSED(x), long WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) { - wxFAIL_MSG( _T("wxPostScriptDC::FloodFill not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") ); } bool wxPostScriptDC::DoGetPixel (long WXUNUSED(x), long WXUNUSED(y), wxColour * WXUNUSED(col)) const { - wxFAIL_MSG( _T("wxPostScriptDC::GetPixel not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") ); return FALSE; } void wxPostScriptDC::DoCrossHair (long WXUNUSED(x), long WXUNUSED(y)) { - wxFAIL_MSG( _T("wxPostScriptDC::CrossHair not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") ); } void wxPostScriptDC::DoDrawLine (long x1, long y1, long x2, long y2) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -472,7 +472,7 @@ void wxPostScriptDC::DoDrawLine (long x1, long y1, long x2, long y2) void wxPostScriptDC::DoDrawArc (long x1, long y1, long x2, long y2, long xc, long yc) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); long dx = x1 - xc; long dy = y1 - yc; @@ -539,7 +539,7 @@ void wxPostScriptDC::DoDrawArc (long x1, long y1, long x2, long y2, long xc, lon void wxPostScriptDC::DoDrawEllipticArc(long x,long y,long w,long h,double sa,double ea) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360; if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360; @@ -581,7 +581,7 @@ void wxPostScriptDC::DoDrawEllipticArc(long x,long y,long w,long h,double sa,dou void wxPostScriptDC::DoDrawPoint (long x, long y) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -600,7 +600,7 @@ void wxPostScriptDC::DoDrawPoint (long x, long y) void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle)) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (n <= 0) return; @@ -659,7 +659,7 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], long xoffset, long void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], long xoffset, long yoffset) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -690,7 +690,7 @@ void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], long xoffset, long yo void wxPostScriptDC::DoDrawRectangle (long x, long y, long width, long height) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_brush.GetStyle () != wxTRANSPARENT) { @@ -737,7 +737,7 @@ void wxPostScriptDC::DoDrawRectangle (long x, long y, long width, long height) void wxPostScriptDC::DoDrawRoundedRectangle (long x, long y, long width, long height, double radius) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (radius < 0.0) { @@ -816,7 +816,7 @@ void wxPostScriptDC::DoDrawRoundedRectangle (long x, long y, long width, long he void wxPostScriptDC::DoDrawEllipse (long x, long y, long width, long height) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_brush.GetStyle () != wxTRANSPARENT) { @@ -867,7 +867,7 @@ static void LocalDecToHex( int dec, char *buf ) void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, long x, long y, bool WXUNUSED(useMask) ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (!bitmap.Ok()) return; @@ -921,7 +921,7 @@ void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, long x, long y, bool void wxPostScriptDC::SetFont( const wxFont& font ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (!font.Ok()) return; @@ -1016,7 +1016,7 @@ void wxPostScriptDC::SetFont( const wxFont& font ) void wxPostScriptDC::SetPen( const wxPen& pen ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (!pen.Ok()) return; @@ -1101,7 +1101,7 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) void wxPostScriptDC::SetBrush( const wxBrush& brush ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (!brush.Ok()) return; @@ -1144,7 +1144,7 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) void wxPostScriptDC::DoDrawText( const wxString& text, long x, long y ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); SetFont( m_font ); @@ -1251,12 +1251,12 @@ void wxPostScriptDC::SetBackground (const wxBrush& brush) void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function)) { - wxFAIL_MSG( _T("wxPostScriptDC::SetLogicalFunction not implemented.") ); + wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") ); } void wxPostScriptDC::DoDrawSpline( wxList *points ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); SetPen( m_pen ); @@ -1328,7 +1328,7 @@ long wxPostScriptDC::GetCharWidth() const void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? 1 : -1); @@ -1341,7 +1341,7 @@ void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) void wxPostScriptDC::SetDeviceOrigin( long x, long y ) { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); int h = 0; int w = 0; @@ -1358,16 +1358,23 @@ void wxPostScriptDC::DoGetSize(int* width, int* height) const if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); + int w = 595; + int h = 842; if (paper) { - if (width) *width = paper->GetSizeDeviceUnits().x; - if (height) *height = paper->GetSizeDeviceUnits().y; + w = paper->GetSizeDeviceUnits().x; + h = paper->GetSizeDeviceUnits().y; } - else + + if (m_printData.GetOrientation() == wxLANDSCAPE) { - if (width) *width = 595; - if (height) *height = 842; + int tmp = w; + w = h; + h = tmp; } + + if (width) *width = w; + if (height) *height = h; } void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const @@ -1378,16 +1385,23 @@ void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); + int w = 210; + int h = 297; if (paper) { - if (width) *width = paper->GetWidth() / 10; - if (height) *height = paper->GetHeight() / 10; + w = paper->GetWidth() / 10; + h = paper->GetHeight() / 10; } - else + + if (m_printData.GetOrientation() == wxLANDSCAPE) { - if (width) *width = 210; - if (height) *height = 297; + int tmp = w; + w = h; + h = tmp; } + + if (width) *width = w; + if (height) *height = h; } // Resolution in pixels per logical inch @@ -1399,7 +1413,7 @@ wxSize wxPostScriptDC::GetPPI(void) const bool wxPostScriptDC::StartDoc( const wxString& message ) { - wxCHECK_MSG( m_ok, FALSE, _T("invalid postscript dc") ); + wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") ); if (m_printData.GetFilename() == "") { @@ -1444,7 +1458,7 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) void wxPostScriptDC::EndDoc () { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); if (m_clipping) { @@ -1461,21 +1475,21 @@ void wxPostScriptDC::EndDoc () fprintf( m_pstream, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings fprintf( m_pstream, "%%%%Title: %s\n", (const char *)m_title.mb_str() ); - fprintf( m_pstream, "%%%%Creator: %s\n", (const char*)wxConvLibc.cWX2MB(wxTheApp->argv[0]) ); + fprintf( m_pstream, "%%%%Creator: %s\n", (const char*)wxConvCurrent->cWX2MB(wxTheApp->argv[0]) ); fprintf( m_pstream, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() ); wxChar userID[256]; if ( wxGetEmailAddress(userID, sizeof(userID)) ) { - fprintf( m_pstream, "%%%%For: %s ", MBSTRINGCAST wxConvCurrent->cWX2MB(userID) ); + fprintf( m_pstream, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) ); wxChar userName[245]; if (wxGetUserName(userName, sizeof(userName))) - fprintf( m_pstream, " (%s)", MBSTRINGCAST wxConvCurrent->cWX2MB(userName) ); + fprintf( m_pstream, " (%s)", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userName) ); fprintf( m_pstream, "\n" ); } else if ( wxGetUserName(userID, sizeof(userID)) ) { - fprintf( m_pstream, "%%%%For: %s\n", MBSTRINGCAST wxConvCurrent->cWX2MB(userID) );; + fprintf( m_pstream, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) );; } // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe @@ -1594,10 +1608,11 @@ void wxPostScriptDC::EndDoc () void wxPostScriptDC::StartPage() { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); fprintf( m_pstream, "%%%%Page: %d\n", wxPageNumber++ ); + // What is this one supposed to do? RR. // *m_pstream << "matrix currentmatrix\n"; // Added by Chris Breeze @@ -1606,11 +1621,6 @@ void wxPostScriptDC::StartPage() // transformation and so we need to reset the origin // (and rotate the page for landscape printing) -/* - m_scaleFactor = 1.0; - m_logicalOriginX = 0; - m_logicalOriginY = 0; -*/ // Output scaling long translate_x, translate_y; double scale_x, scale_y; @@ -1623,21 +1633,22 @@ void wxPostScriptDC::StartPage() if (m_printData.GetOrientation() == wxLANDSCAPE) { -// translate_y -= m_maxY; -// fprintf( m_pstream, "90 rotate\n" ); - - printf( "Hi.\n" ); + int h; + GetSize( (int*) NULL, &h ); + translate_y -= h; + fprintf( m_pstream, "90 rotate\n" ); - fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" ); + // I copied this one from a PostScript tutorial, but to no avail. RR. +// fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" ); } -// fprintf( m_pstream, "%.8f %.8f scale\n", scale_x, scale_y ); -// fprintf( m_pstream, "%ld %ld translate\n", translate_x, translate_y ); + fprintf( m_pstream, "%.8f %.8f scale\n", scale_x, scale_y ); + fprintf( m_pstream, "%ld %ld translate\n", translate_x, translate_y ); } void wxPostScriptDC::EndPage () { - wxCHECK_RET( m_ok && m_pstream, _T("invalid postscript dc") ); + wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); fprintf( m_pstream, "showpage\n" ); } @@ -1648,9 +1659,9 @@ bool wxPostScriptDC::DoBlit( long xdest, long ydest, long xsrc, long ysrc, int rop, bool WXUNUSED(useMask) ) { - wxCHECK_MSG( m_ok && m_pstream, FALSE, _T("invalid postscript dc") ); + wxCHECK_MSG( m_ok && m_pstream, FALSE, wxT("invalid postscript dc") ); - wxCHECK_MSG( source, FALSE, _T("invalid source dc") ); + wxCHECK_MSG( source, FALSE, wxT("invalid source dc") ); /* blit into a bitmap */ wxBitmap bitmap( (int)fwidth, (int)fheight ); @@ -1680,13 +1691,13 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, if (!fontToUse) fontToUse = (wxFont*) &m_font; - wxCHECK_RET( fontToUse, _T("GetTextExtent: no font defined") ); - wxCHECK_RET( x, _T("GetTextExtent: x == NULL") ); - wxCHECK_RET( y, _T("GetTextExtent: y == NULL") ); + wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") ); + wxCHECK_RET( x, wxT("GetTextExtent: x == NULL") ); + wxCHECK_RET( y, wxT("GetTextExtent: y == NULL") ); const wxWX2MBbuf strbuf = string.mb_str(); -#if !USE_AFM_FOR_POSTSCRIPT +#if !wxUSE_AFM_FOR_POSTSCRIPT /* Provide a VERY rough estimate (avoid using it). * Produces accurate results for mono-spaced font * such as Courier (aka wxMODERN) */ @@ -1747,6 +1758,9 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, static int lastWeight= INT_MIN; static int lastDescender = INT_MIN; static int lastWidths[256]; /* widths of the characters */ + + double UnderlinePosition = 0.0; + double UnderlineThickness = 0.0; /* get actual parameters */ const int Family = fontToUse->GetFamily(); @@ -1780,7 +1794,7 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "TimesBoO"; else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "TimesBo"; else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "TimesO"; - else if name = "TimesRo"; /* no typo */ + else name = "TimesRo"; } break; default: @@ -1799,7 +1813,7 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, if (!m_printData.GetFontMetricPath().IsEmpty()) { - strcpy( afmName, m_printData.GetFontMetricPath().fn_str() ) + strcpy( afmName, m_printData.GetFontMetricPath().fn_str() ); } /* 2. open and process the file @@ -1823,21 +1837,21 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, FILE *afmFile = fopen(afmName,"r"); #ifdef __UNIX__ - if (afmFile==NULL) - { - strcpy( afmName, "/usr/local/share/wx/gs_afm/" ); - strcat(afmName,name); - strcat(afmName,".afm"); - FILE *afmFile = fopen(afmName,"r"); - } - - if (afmFile==NULL) - { - strcpy( afmName, "/usr/share/wx/gs_afm/" ); - strcat(afmName,name); - strcat(afmName,".afm"); - FILE *afmFile = fopen(afmName,"r"); - } + if (afmFile==NULL) + { + strcpy( afmName, "/usr/local/share/wx/afm/" ); + strcat(afmName,name); + strcat(afmName,".afm"); + afmFile = fopen(afmName,"r"); + } + + if (afmFile==NULL) + { + strcpy( afmName, "/usr/share/wx/afm/" ); + strcat(afmName,name); + strcat(afmName,".afm"); + afmFile = fopen(afmName,"r"); + } #endif if (afmFile==NULL) @@ -1940,14 +1954,20 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, } /* JC: calculate UnderlineThickness/UnderlinePosition */ - m_underlinePosition = m_underlinePosition * fontToUse->GetPointSize() / 1000.0f; - m_underlineThickness = m_underlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor; + { + // VS: dirty, but is there any better solution? + double *pt; + pt = (double*) &m_underlinePosition; + *pt = UnderlinePosition * fontToUse->GetPointSize() / 1000.0f; + pt = (double*) &m_underlineThickness; + *pt = UnderlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor; + } /* 3. now the font metrics are read in, calc size this / is done by adding the widths of the characters in the / string. they are given in 1/1000 of the size! */ - long widthSum=0; + double widthSum=0; long height=Size; /* by default */ unsigned char *p; for(p=(unsigned char *)strbuf; *p; p++) @@ -1955,22 +1975,22 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, if(lastWidths[*p]== INT_MIN) { wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p,*p); - widthSum += (long)(lastWidths[' ']/1000.0F * Size); /* assume space */ + widthSum += /*(long)*/(lastWidths[' ']/1000.0F * Size); /* assume space */ } else { - widthSum += (long)((lastWidths[*p]/1000.0F)*Size); + widthSum += /*(long)*/((lastWidths[*p]/1000.0F)*Size); } } /* add descender to height (it is usually a negative value) */ - if (lastDescender!=INT_MIN) + if (lastDescender != INT_MIN) { height += (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ } /* return size values */ - *x = widthSum; + *x = (long)widthSum; *y = height; /* return other parameters */