X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6eec2beef703b0be6d83e78e44f8b0a3a1999ac4..e81a301cbdc8729b0a71fa5dfd7124bf59368673:/src/generic/dcpsg.cpp diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index d1a44cfe67..3fe32bf0b2 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -10,8 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation -#pragma interface +#pragma implementation "dcpsg.h" #endif #include "wx/wxprec.h" @@ -21,8 +20,6 @@ #endif #ifndef WX_PRECOMP - #include "wx/setup.h" - #include "wx/defs.h" #endif // WX_PRECOMP #if wxUSE_PRINTING_ARCHITECTURE @@ -39,13 +36,14 @@ #include "wx/image.h" #include "wx/log.h" #include "wx/generic/dcpsg.h" -#include "wx/generic/prntdlgg.h" +#include "wx/printdlg.h" #include "wx/button.h" #include "wx/stattext.h" #include "wx/radiobox.h" #include "wx/textctrl.h" #include "wx/prntbase.h" #include "wx/paper.h" +#include "wx/filefn.h" #include @@ -232,6 +230,20 @@ static char wxPostScriptHeaderReencodeISO2[] = // wxPostScriptDC //------------------------------------------------------------------------------- +float wxPostScriptDC::ms_PSScaleFactor = 10.0; + +void wxPostScriptDC::SetResolution(int ppi) +{ + ms_PSScaleFactor = (float)ppi / 72.0; +} + +int wxPostScriptDC::GetResolution() +{ + return (int)(ms_PSScaleFactor * 72.0); +} + + + wxPostScriptDC::wxPostScriptDC () { m_pstream = (FILE*) NULL; @@ -252,7 +264,7 @@ wxPostScriptDC::wxPostScriptDC () // Compatibility only // HH: Doesn't seem to work for wxMSW... - #ifndef __WXMSW__ + #if !defined(__WXMSW__) m_printData = * wxThePrintSetupData; #endif } @@ -403,10 +415,10 @@ void wxPostScriptDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoo "%d %d lineto\n" "%d %d lineto\n" "closepath clip newpath\n", - XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x+w), YLOG2DEV(y), - XLOG2DEV(x+w), YLOG2DEV(y+h), - XLOG2DEV(x), YLOG2DEV(y+h) ); + LogicalToDeviceX(x), LogicalToDeviceY(y), + LogicalToDeviceX(x+w), LogicalToDeviceY(y), + LogicalToDeviceX(x+w), LogicalToDeviceY(y+h), + LogicalToDeviceX(x), LogicalToDeviceY(y+h) ); } @@ -428,9 +440,10 @@ void wxPostScriptDC::Clear() wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") ); } -void wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) +bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) { wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") ); + return FALSE; } bool wxPostScriptDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const @@ -457,8 +470,8 @@ void wxPostScriptDC::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) "%d %d moveto\n" "%d %d lineto\n" "stroke\n", - XLOG2DEV(x1), YLOG2DEV(y1), - XLOG2DEV(x2), YLOG2DEV (y2) ); + LogicalToDeviceX(x1), LogicalToDeviceY(y1), + LogicalToDeviceX(x2), LogicalToDeviceY (y2) ); CalcBoundingBox( x1, y1 ); CalcBoundingBox( x2, y2 ); @@ -508,8 +521,8 @@ void wxPostScriptDC::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, "%d %d lineto\n" "closepath\n" "fill\n", - XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL(radius), YLOG2DEVREL(radius), (wxCoord)alpha1, (wxCoord) alpha2, - XLOG2DEV(xc), YLOG2DEV(yc) ); + LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2, + LogicalToDeviceX(xc), LogicalToDeviceY(yc) ); CalcBoundingBox( xc-radius, yc-radius ); CalcBoundingBox( xc+radius, yc+radius ); @@ -525,8 +538,8 @@ void wxPostScriptDC::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, "%d %d lineto\n" "stroke\n" "fill\n", - XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL(radius), YLOG2DEVREL(radius), (wxCoord)alpha1, (wxCoord) alpha2, - XLOG2DEV(xc), YLOG2DEV(yc) ); + LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2, + LogicalToDeviceX(xc), LogicalToDeviceY(yc) ); CalcBoundingBox( xc-radius, yc-radius ); CalcBoundingBox( xc+radius, yc+radius ); @@ -555,7 +568,7 @@ void wxPostScriptDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,d fprintf( m_pstream, "newpath\n" "%d %d %d %d %d %d true ellipticarc\n", - XLOG2DEV(x+w/2), YLOG2DEV(y+h/2), XLOG2DEVREL(w/2), YLOG2DEVREL(h/2), (wxCoord)sa, (wxCoord)ea ); + LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2), LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2), (wxCoord)sa, (wxCoord)ea ); CalcBoundingBox( x ,y ); CalcBoundingBox( x+w, y+h ); @@ -568,7 +581,7 @@ void wxPostScriptDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,d fprintf(m_pstream, "newpath\n" "%d %d %d %d %d %d false ellipticarc\n", - XLOG2DEV(x+w/2), YLOG2DEV(y+h/2), XLOG2DEVREL(w/2), YLOG2DEVREL(h/2), (wxCoord)sa, (wxCoord)ea ); + LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2), LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2), (wxCoord)sa, (wxCoord)ea ); CalcBoundingBox( x ,y ); CalcBoundingBox( x+w, y+h ); @@ -588,8 +601,8 @@ void wxPostScriptDC::DoDrawPoint (wxCoord x, wxCoord y) "%d %d moveto\n" "%d %d lineto\n" "stroke\n", - XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x+1), YLOG2DEV(y) ); + LogicalToDeviceX(x), LogicalToDeviceY(y), + LogicalToDeviceX(x+1), LogicalToDeviceY(y) ); CalcBoundingBox( x, y ); } @@ -606,8 +619,8 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wx fprintf( m_pstream, "newpath\n" ); - wxCoord xx = XLOG2DEV(points[0].x + xoffset); - wxCoord yy = YLOG2DEV(points[0].y + yoffset); + wxCoord xx = LogicalToDeviceX(points[0].x + xoffset); + wxCoord yy = LogicalToDeviceY(points[0].y + yoffset); fprintf( m_pstream, "%d %d moveto\n", xx, yy ); @@ -615,8 +628,8 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wx for (int i = 1; i < n; i++) { - xx = XLOG2DEV(points[i].x + xoffset); - yy = YLOG2DEV(points[i].y + yoffset); + xx = LogicalToDeviceX(points[i].x + xoffset); + yy = LogicalToDeviceY(points[i].y + yoffset); fprintf( m_pstream, "%d %d lineto\n", xx, yy ); @@ -632,8 +645,8 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wx fprintf( m_pstream, "newpath\n" ); - wxCoord xx = XLOG2DEV(points[0].x + xoffset); - wxCoord yy = YLOG2DEV(points[0].y + yoffset); + wxCoord xx = LogicalToDeviceX(points[0].x + xoffset); + wxCoord yy = LogicalToDeviceY(points[0].y + yoffset); fprintf( m_pstream, "%d %d moveto\n", xx, yy ); @@ -641,15 +654,16 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wx for (int i = 1; i < n; i++) { - xx = XLOG2DEV(points[i].x + xoffset); - yy = YLOG2DEV(points[i].y + yoffset); + xx = LogicalToDeviceX(points[i].x + xoffset); + yy = LogicalToDeviceY(points[i].y + yoffset); fprintf( m_pstream, "%d %d lineto\n", xx, yy ); CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset); } - fprintf( m_pstream, "fill\n" ); + fprintf( m_pstream, "closepath\n" ); + fprintf( m_pstream, "stroke\n" ); } } @@ -666,19 +680,19 @@ void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCo int i; for ( i =0; i= 128 ) { @@ -1210,8 +1246,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) } else { - tmpbuf[0] = (char) c; - fprintf( m_pstream, tmpbuf ); + fputc(c, m_pstream); } } @@ -1220,25 +1255,149 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) if (m_font.GetUnderlined()) { wxCoord uy = (wxCoord)(y + size - m_underlinePosition); - wxCoord w, h; - GetTextExtent(text, &w, &h); + char buffer[100]; - fprintf( m_pstream, + sprintf( buffer, "gsave\n" "%d %d moveto\n" - "%d setlinewidth\n" + "%f setlinewidth\n" "%d %d lineto\n" "stroke\n" "grestore\n", - XLOG2DEV(x), YLOG2DEV(uy), - (wxCoord)m_underlineThickness, - XLOG2DEV(x + w), YLOG2DEV(uy) ); + LogicalToDeviceX(x), LogicalToDeviceY(uy), + m_underlineThickness, + LogicalToDeviceX(x + text_w), LogicalToDeviceY(uy) ); + for (i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf( m_pstream, 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 && m_pstream, 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] = '.'; + fprintf( m_pstream, buffer ); + + m_currentRed = red; + m_currentBlue = blue; + m_currentGreen = green; + } + } + + int size = m_font.GetPointSize(); + + long by = y + (long)floor( double(size) * 2.0 / 3.0 ); // approximate baseline + + // FIXME only correct for 90 degrees + fprintf(m_pstream, "%d %d moveto\n", + LogicalToDeviceX((wxCoord)(x + size)), LogicalToDeviceY((wxCoord)by) ); + + char buffer[100]; + sprintf(buffer, "%.8f rotate\n", angle); + size_t i; + for (i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf(m_pstream, buffer); + + fprintf( m_pstream, "(" ); + 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 */ + fprintf( m_pstream, "\\" ); + fputc(c, m_pstream); + } + else if ( c >= 128 ) + { + /* Cope with character codes > 127 */ + fprintf(m_pstream, "\\%o", c); + } + else + { + fputc(c, m_pstream); + } + } + + fprintf( m_pstream, ") show\n" ); + + sprintf( buffer, "%.8f rotate\n", -angle ); + for (i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf( m_pstream, 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] = '.'; + fprintf( m_pstream, buffer ); + } + + CalcBoundingBox( x, y ); + CalcBoundingBox( x + size * text.Length() * 2/3 , y ); +} void wxPostScriptDC::SetBackground (const wxBrush& brush) { @@ -1275,8 +1434,8 @@ void wxPostScriptDC::DoDrawSpline( wxList *points ) "newpath\n" "%d %d moveto\n" "%d %d lineto\n", - XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), - XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); + LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1), + LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) ); CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); @@ -1296,9 +1455,9 @@ void wxPostScriptDC::DoDrawSpline( wxList *points ) fprintf( m_pstream, "%d %d %d %d %d %d DrawSplineSection\n", - XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), - XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), - XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); + 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 ); @@ -1312,7 +1471,7 @@ void wxPostScriptDC::DoDrawSpline( wxList *points ) fprintf( m_pstream, "%d %d lineto\n" "stroke\n", - XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); + LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) ); } wxCoord wxPostScriptDC::GetCharWidth() const @@ -1369,8 +1528,8 @@ void wxPostScriptDC::DoGetSize(int* width, int* height) const h = tmp; } - if (width) *width = w; - if (height) *height = h; + if (width) *width = (int)(w * ms_PSScaleFactor); + if (height) *height = (int)(h * ms_PSScaleFactor); } void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const @@ -1403,7 +1562,8 @@ void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const // Resolution in pixels per logical inch wxSize wxPostScriptDC::GetPPI(void) const { - return wxSize(72, 72); + return wxSize((int)(72 * ms_PSScaleFactor), + (int)(72 * ms_PSScaleFactor)); } @@ -1417,11 +1577,11 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) m_printData.SetFilename(filename); } - m_pstream = fopen( m_printData.GetFilename().fn_str(), "w+" ); + m_pstream = wxFopen( m_printData.GetFilename().fn_str(), wxT("w+") ); if (!m_pstream) { - wxMessageBox( _("Cannot open file for PostScript printing!"), _("Error"), wxOK ); + wxLogError( _("Cannot open file for PostScript printing!")); m_ok = FALSE; return FALSE; } @@ -1493,8 +1653,8 @@ void wxPostScriptDC::EndDoc () wxCoord wx_printer_translate_x, wx_printer_translate_y; double wx_printer_scale_x, wx_printer_scale_y; - wx_printer_translate_x = m_printData.GetPrinterTranslateX(); - wx_printer_translate_y = m_printData.GetPrinterTranslateY(); + wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); + wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); wx_printer_scale_x = m_printData.GetPrinterScaleX(); wx_printer_scale_y = m_printData.GetPrinterScaleY(); @@ -1506,10 +1666,26 @@ void wxPostScriptDC::EndDoc () // Compute the bounding box. Note that it is in the default user // coordinate system, thus we have to convert the values. - wxCoord llx = (wxCoord) ((XLOG2DEV(m_minX)+wx_printer_translate_x)*wx_printer_scale_x); - wxCoord lly = (wxCoord) ((YLOG2DEV(m_minY)+wx_printer_translate_y)*wx_printer_scale_y); - wxCoord urx = (wxCoord) ((XLOG2DEV(m_maxX)+wx_printer_translate_x)*wx_printer_scale_x); - wxCoord ury = (wxCoord) ((YLOG2DEV(m_maxY)+wx_printer_translate_y)*wx_printer_scale_y); + wxCoord minX = (wxCoord) LogicalToDeviceX(m_minX); + wxCoord minY = (wxCoord) LogicalToDeviceY(m_minY); + wxCoord maxX = (wxCoord) LogicalToDeviceX(m_maxX); + wxCoord maxY = (wxCoord) LogicalToDeviceY(m_maxY); + + // LOG2DEV may have changed the minimum to maximum vice versa + if ( minX > maxX ) { wxCoord tmp = minX; minX = maxX; maxX = tmp; } + if ( minY > maxY ) { wxCoord tmp = minY; minY = maxY; maxY = tmp; } + + // account for used scaling (boundingbox is before scaling in ps-file) + double scale_x = m_printData.GetPrinterScaleX() / ms_PSScaleFactor; + double scale_y = m_printData.GetPrinterScaleY() / ms_PSScaleFactor; + + wxCoord llx, lly, urx, ury; + llx = (wxCoord) ((minX+wx_printer_translate_x)*scale_x); + lly = (wxCoord) ((minY+wx_printer_translate_y)*scale_y); + urx = (wxCoord) ((maxX+wx_printer_translate_x)*scale_x); + ury = (wxCoord) ((maxY+wx_printer_translate_y)*scale_y); + // (end of bounding box computation) + // If we're landscape, our sense of "x" and "y" is reversed. if (m_printData.GetOrientation() == wxLANDSCAPE) @@ -1621,8 +1797,8 @@ void wxPostScriptDC::StartPage() wxCoord translate_x, translate_y; double scale_x, scale_y; - translate_x = m_printData.GetPrinterTranslateX(); - translate_y = m_printData.GetPrinterTranslateY(); + translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); + translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); scale_x = m_printData.GetPrinterScaleX(); scale_y = m_printData.GetPrinterScaleY(); @@ -1638,7 +1814,13 @@ void wxPostScriptDC::StartPage() // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" ); } - fprintf( m_pstream, "%.8f %.8f scale\n", scale_x, scale_y ); + char buffer[100]; + sprintf( buffer, "%.8f %.8f scale\n", scale_x / ms_PSScaleFactor, + scale_y / ms_PSScaleFactor); + for (int i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf( m_pstream, buffer ); + fprintf( m_pstream, "%d %d translate\n", translate_x, translate_y ); } @@ -1653,7 +1835,7 @@ bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord fwidth, wxCoord fheight, wxDC *source, wxCoord xsrc, wxCoord ysrc, - int rop, bool WXUNUSED(useMask) ) + int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) ) { wxCHECK_MSG( m_ok && m_pstream, FALSE, wxT("invalid postscript dc") ); @@ -1675,7 +1857,7 @@ bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord wxPostScriptDC::GetCharHeight() const { if (m_font.Ok()) - return m_font.GetPointSize(); + return m_font.GetPointSize(); else return 12; } @@ -1690,8 +1872,6 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if (!fontToUse) fontToUse = (wxFont*) &m_font; 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(); @@ -1763,10 +1943,10 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, double UnderlineThickness = 0.0; /* get actual parameters */ - const int Family = fontToUse->GetFamily(); - const int Size = fontToUse->GetPointSize(); - const int Style = fontToUse->GetStyle(); - const int Weight = fontToUse->GetWeight(); + int Family = fontToUse->GetFamily(); + int Size = fontToUse->GetPointSize(); + int Style = fontToUse->GetStyle(); + int Weight = fontToUse->GetWeight(); /* if we have another font, read the font-metrics */ if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight) @@ -1777,43 +1957,49 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, lastStyle = Style; lastWeight = Weight; - char *name = (char*) NULL; + const char *name = NULL; switch (Family) { case wxMODERN: - { - if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "CourBoO"; - else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "CourBo"; - else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "Cour0"; - else name = "Cour"; - } + case wxTELETYPE: + { + if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "CourBoO.afm"; + else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "CourBo.afm"; + else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "CourO.afm"; + else name = "Cour.afm"; break; + } case wxROMAN: - { - if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "TimesBoO"; - else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "TimesBo"; - else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "TimesO"; - else name = "TimesRo"; - } + { + if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "TimesBoO.afm"; + else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "TimesBo.afm"; + else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "TimesO.afm"; + else name = "TimesRo.afm"; break; + } + case wxSCRIPT: + { + name = "Zapf.afm"; + Style = wxNORMAL; + Weight = wxNORMAL; + } + case wxSWISS: default: - { - if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "HelvBoO"; - else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "HelvBo"; - else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "Helv0"; - else name = "Helv"; - } + { + if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "HelvBoO.afm"; + else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "HelvBo.afm"; + else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "HelvO.afm"; + else name = "Helv.afm"; break; + } } /* get the directory of the AFM files */ - char afmName[256]; - afmName[0] = 0; - + wxString afmName = wxEmptyString; if (!m_printData.GetFontMetricPath().IsEmpty()) { - strcpy( afmName, m_printData.GetFontMetricPath().fn_str() ); + afmName = m_printData.GetFontMetricPath(); } /* 2. open and process the file @@ -1832,32 +2018,38 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */ - strcat(afmName,name); - strcat(afmName,".afm"); - FILE *afmFile = fopen(afmName,"r"); + afmName << name; + FILE *afmFile = wxFopen(afmName,wxT("r")); -#ifdef __UNIX__ if (afmFile==NULL) { - strcpy( afmName, "/usr/local/share/wx/afm/" ); - strcat(afmName,name); - strcat(afmName,".afm"); - afmFile = fopen(afmName,"r"); + afmName = wxThePrintSetupData->GetAFMPath(); + afmName << wxFILE_SEP_PATH << name; + afmFile = wxFopen(afmName,wxT("r")); } - if (afmFile==NULL) +#if defined(__UNIX__) && !defined(__VMS__) + if (afmFile==NULL) + /* please do NOT change the line above to "else if (afmFile==NULL)" - + - afmFile = fopen() may fail and in that case the next if branch + MUST be executed - and it would not if there was "else" */ { - strcpy( afmName, "/usr/share/wx/afm/" ); - strcat(afmName,name); - strcat(afmName,".afm"); - afmFile = fopen(afmName,"r"); + afmName = wxGetDataDir(); + afmName << wxFILE_SEP_PATH +#if defined(__LINUX__) || defined(__FREEBSD__) + << wxT("gs_afm") << wxFILE_SEP_PATH +#else + << wxT("afm") << wxFILE_SEP_PATH +#endif + << name; + afmFile = wxFopen(afmName,wxT("r")); } #endif if (afmFile==NULL) { - wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName ); - wxLogDebug( wxT(" using approximate values\n")); + wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName.c_str() ); + wxLogDebug( wxT(" using approximate values")); for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */ lastDescender = -150; /* dito. */ } @@ -1879,7 +2071,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) || (strcmp(descString,"Descender")!=0)) { - wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName,line ); + wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName.c_str(),line ); } } /* JC 1.) check for UnderlinePosition */ @@ -1888,7 +2080,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) || (strcmp(upString,"UnderlinePosition")!=0)) { - wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName, line ); + wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName.c_str(), line ); } } /* JC 2.) check for UnderlineThickness */ @@ -1897,7 +2089,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) || (strcmp(utString,"UnderlineThickness")!=0)) { - wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName, line ); + wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName.c_str(), line ); } } /* JC 3.) check for EncodingScheme */ @@ -1906,12 +2098,12 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if ((sscanf(line,"%s%s",utString,encString)!=2) || (strcmp(utString,"EncodingScheme")!=0)) { - wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName, line ); + wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName.c_str(), line ); } else if (strncmp(encString, "AdobeStandardEncoding", 21)) { - wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"), - afmName,line, encString); + wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"), + afmName.c_str(),line, encString); } } /* B.) check for char-width */ @@ -1919,11 +2111,11 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, { if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5) { - wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName,line); + wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName.c_str(),line); } if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0) { - wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName,line); + wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName.c_str(),line); } /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */ if (ascii>=0 && ascii<256) @@ -1933,7 +2125,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, else { /* MATTHEW: this happens a lot; don't print an error */ - /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */ + /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */ } } /* C.) ignore other entries. */ @@ -1951,43 +2143,50 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, lastWidths[220] = lastWidths['U']; // Ü lastWidths[252] = lastWidths['u']; // ü lastWidths[223] = lastWidths[251]; // ß - } - /* JC: calculate UnderlineThickness/UnderlinePosition */ - { + /* JC: calculate UnderlineThickness/UnderlinePosition */ + // VS: dirty, but is there any better solution? double *pt; pt = (double*) &m_underlinePosition; - *pt = UnderlinePosition * fontToUse->GetPointSize() / 1000.0f; + *pt = LogicalToDeviceYRel((wxCoord)(UnderlinePosition * fontToUse->GetPointSize())) / 1000.0f; pt = (double*) &m_underlineThickness; - *pt = UnderlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor; + *pt = LogicalToDeviceYRel((wxCoord)(UnderlineThickness * fontToUse->GetPointSize())) / 1000.0f; + } + /* 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! */ - double widthSum=0; + long sum=0; wxCoord height=Size; /* by default */ unsigned char *p; for(p=(unsigned char *)wxMBSTRINGCAST strbuf; *p; p++) { if(lastWidths[*p]== INT_MIN) { - wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p,*p); - widthSum += /*(wxCoord)*/(lastWidths[' ']/1000.0F * Size); /* assume space */ + wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p,*p); + sum += lastWidths[' ']; /* assume space */ } else { - widthSum += /*(wxCoord)*/((lastWidths[*p]/1000.0F)*Size); + sum += lastWidths[*p]; } } + double widthSum = sum; + widthSum *= Size; + widthSum /= 1000.0F; + /* add descender to height (it is usually a negative value) */ - if (lastDescender != INT_MIN) - { - height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ - } + //if (lastDescender != INT_MIN) + //{ + // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ + //} + // - commented by V. Slavik - height already contains descender in it + // (judging from few experiments) /* return size values */ if ( x ) @@ -2035,10 +2234,8 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, wxPrintSetupData *wxThePrintSetupData = (wxPrintSetupData *) NULL; -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject) -#endif // Redundant now I think #if 1 @@ -2325,7 +2522,8 @@ void wxPrintSetupData::operator=(const wxPrintData& data) SetPrinterCommand(data.GetPrinterCommand()); SetPrintPreviewCommand(data.GetPreviewCommand()); SetPrinterOptions(data.GetPrinterOptions()); - SetPrinterTranslation(data.GetPrinterTranslateX(), data.GetPrinterTranslateY()); + SetPrinterTranslation((wxCoord)data.GetPrinterTranslateX(), + (wxCoord)data.GetPrinterTranslateY()); SetPrinterScaling(data.GetPrinterScaleX(), data.GetPrinterScaleY()); SetPrinterOrientation(data.GetOrientation()); SetPrinterMode((int) data.GetPrintMode());