X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce7f10f2a6adf516152286a2e78cca93b9ad87ce..b6c8bd695963b52cec60cf2247bf4b1651d889d8:/src/generic/dcpsg.cpp diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 825e079caa..963735393b 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -233,6 +233,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; @@ -650,7 +664,8 @@ void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wx CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset); } - fprintf( m_pstream, "fill\n" ); + fprintf( m_pstream, "closepath\n" ); + fprintf( m_pstream, "stroke\n" ); } } @@ -824,7 +839,7 @@ void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord "%d %d %d %d 0 360 ellipse\n" "fill\n", XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2), - XLOG2DEV(width / 2), YLOG2DEVREL(height / 2) ); + XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) ); CalcBoundingBox( x - width, y - height ); CalcBoundingBox( x + width, y + height ); @@ -839,7 +854,7 @@ void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord "%d %d %d %d 0 360 ellipse\n" "stroke\n", XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2), - XLOG2DEV(width / 2), YLOG2DEVREL(height / 2) ); + XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) ); CalcBoundingBox( x - width, y - height ); CalcBoundingBox( x + width, y + height ); @@ -872,13 +887,12 @@ void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, if (!image.Ok()) return; + wxCoord w = image.GetWidth(); + wxCoord h = image.GetHeight(); + wxCoord ww = XLOG2DEVREL(image.GetWidth()); wxCoord hh = YLOG2DEVREL(image.GetHeight()); - image = image.Scale( ww, hh ); - - if (!image.Ok()) return; - wxCoord xx = XLOG2DEV(x); wxCoord yy = YLOG2DEV(y + bitmap.GetHeight()); @@ -895,11 +909,12 @@ void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, "[%d 0 0 %d 0 %d]\n" "{currentfile pix readhexstring pop}\n" "false 3 colorimage\n", - ww, ww, xx, yy, ww, hh, ww, hh, ww, -hh, hh ); + w, w, xx, yy, ww, hh, w, h, w, -h, h ); - for (int j = 0; j < hh; j++) + + for (int j = 0; j < h; j++) { - for (int i = 0; i < ww; i++) + for (int i = 0; i < w; i++) { char buffer[5]; LocalDecToHex( image.GetRed(i,j), buffer ); @@ -924,91 +939,90 @@ void wxPostScriptDC::SetFont( const wxFont& font ) m_font = font; - const char *name; - const char *style = ""; int Style = m_font.GetStyle(); int Weight = m_font.GetWeight(); + const char *name; switch (m_font.GetFamily()) { case wxTELETYPE: case wxMODERN: - name = "/Courier"; - break; - case wxSWISS: - name = "/Helvetica"; + { + if (Style == wxITALIC) + { + if (Weight == wxBOLD) + name = "/Courier-BoldOblique"; + else + name = "/Courier-Oblique"; + } + else + { + if (Weight == wxBOLD) + name = "/Courier-Bold"; + else + name = "/Courier"; + } break; + } case wxROMAN: -// name = "/Times-Roman"; - name = "/Times"; // Altered by EDZ + { + if (Style == wxITALIC) + { + if (Weight == wxBOLD) + name = "/Times-BoldItalic"; + else + name = "/Times-Italic"; + } + else + { + if (Weight == wxBOLD) + name = "/Times-Bold"; + else + name = "/Times-Roman"; + } break; + } case wxSCRIPT: - name = "/Zapf-Chancery-MediumItalic"; + { + name = "/ZapfChancery-MediumItalic"; Style = wxNORMAL; Weight = wxNORMAL; break; + } + case wxSWISS: default: - case wxDEFAULT: // Sans Serif Font - name = "/LucidaSans"; - } - - if (Style == wxNORMAL && (Weight == wxNORMAL || Weight == wxLIGHT)) - { - if (m_font.GetFamily () == wxROMAN) - style = "-Roman"; - else - style = ""; - } - else if (Style == wxNORMAL && Weight == wxBOLD) - { - style = "-Bold"; - } - else if (Style == wxITALIC && (Weight == wxNORMAL || Weight == wxLIGHT)) - { - if (m_font.GetFamily () == wxROMAN) - style = "-Italic"; - else - style = "-Oblique"; - } - else if (Style == wxITALIC && Weight == wxBOLD) - { - if (m_font.GetFamily () == wxROMAN) - style = "-BoldItalic"; - else - style = "-BoldOblique"; - } - else if (Style == wxSLANT && (Weight == wxNORMAL || Weight == wxLIGHT)) - { - if (m_font.GetFamily () == wxROMAN) - style = "-Italic"; - else - style = "-Oblique"; - } - else if (Style == wxSLANT && Weight == wxBOLD) - { - if (m_font.GetFamily () == wxROMAN) - style = "-BoldItalic"; - else - style = "-BoldOblique"; - } - else - { - style = ""; + { + if (Style == wxITALIC) + { + if (Weight == wxBOLD) + name = "/Helvetica-BoldOblique"; + else + name = "/Helvetica-Oblique"; + } + else + { + if (Weight == wxBOLD) + name = "/Helvetica-Bold"; + else + name = "/Helvetica"; + } + break; + } } - char buffer[100]; - strcpy( buffer, name ); - strcat( buffer, style ); - - fprintf( m_pstream, buffer ); + fprintf( m_pstream, name ); fprintf( m_pstream, " reencodeISO def\n" ); - fprintf( m_pstream, buffer ); + fprintf( m_pstream, name ); fprintf( m_pstream, " findfont\n" ); - fprintf( m_pstream, "%f scalefont setfont\n", YLOG2DEVREL(m_font.GetPointSize() * 1000) / 1000.0F); + char buffer[100]; + sprintf( buffer, "%f scalefont setfont\n", YLOG2DEVREL(m_font.GetPointSize() * 1000) / 1000.0F); // this is a hack - we must scale font size (in pts) according to m_scaleY but // YLOG2DEVREL works with wxCoord type (int or longint). Se we first convert font size - // to 1/1000th of pt and then back. + // to 1/1000th of pt and then back. + for (int i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf( m_pstream, buffer ); } void wxPostScriptDC::SetPen( const wxPen& pen ) @@ -1021,11 +1035,18 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) m_pen = pen; - #ifdef __WXMSW__ - fprintf( m_pstream, "%d setlinewidth\n", XLOG2DEVREL(m_pen.GetWidth()) ); - #else - fprintf( m_pstream, "%d setlinewidth\n", XLOG2DEVREL(m_pen.GetWidth()) ); - #endif + { + char buffer[100]; + #ifdef __WXMSW__ + sprintf( buffer, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen.GetWidth()) / 1000.0f ); + #else + sprintf( buffer, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen.GetWidth()) / 1000.0f ); + #endif + for (int i = 0; i < 100; i++) + if (buffer[i] == ',') buffer[i] = '.'; + fprintf( m_pstream, buffer ); + } + /* Line style - WRONG: 2nd arg is OFFSET @@ -1086,9 +1107,13 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; - fprintf( m_pstream, + 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; @@ -1129,9 +1154,13 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; - fprintf( m_pstream, + 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; @@ -1143,7 +1172,13 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); - SetFont( m_font ); + wxCoord text_w, text_h, text_descent; + + GetTextExtent(text, &text_w, &text_h, &text_descent); + + // VZ: this seems to be unnecessary, so taking it out for now, if it + // doesn't create any problems, remove this comment entirely + //SetFont( m_font ); if (m_textForegroundColour.Ok()) { @@ -1171,9 +1206,13 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; - fprintf( m_pstream, - "%.8f %.8f %.8f setrgbcolor\n", - redPS, greenPS, bluePS ); + 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; @@ -1183,13 +1222,12 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) int size = m_font.GetPointSize(); - wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline +// wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline +// commented by V. Slavik and replaced by accurate version +// - note that there is still rounding error in text_descent! + wxCoord by = y + size - text_descent; // baseline fprintf( m_pstream, "%d %d moveto\n", XLOG2DEV(x), YLOG2DEV(by) ); - /* I don't know how to write char to a stream, so I use a mini string */ - char tmpbuf[2]; - tmpbuf[1] = 0; - fprintf( m_pstream, "(" ); const wxWX2MBbuf textbuf = text.mb_str(); int len = strlen(textbuf); @@ -1201,8 +1239,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { /* Cope with special characters */ fprintf( m_pstream, "\\" ); - tmpbuf[0] = (char) c; - fprintf( m_pstream, tmpbuf ); + fputc(c, m_pstream); } else if ( c >= 128 ) { @@ -1211,8 +1248,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) } else { - tmpbuf[0] = (char) c; - fprintf( m_pstream, tmpbuf ); + fputc(c, m_pstream); } } @@ -1221,25 +1257,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) ); + m_underlineThickness, + XLOG2DEV(x + text_w), YLOG2DEV(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", + XLOG2DEV((wxCoord)(x + size)), YLOG2DEV((wxCoord)by) ); + + char buffer[100]; + sprintf(buffer, "%.8f rotate\n", angle); + int 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(); + int 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", + XLOG2DEV(x), YLOG2DEV(uy), + m_underlineThickness, + XLOG2DEV(x + w), YLOG2DEV(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) { @@ -1370,8 +1530,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 @@ -1404,7 +1564,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)); } @@ -1422,7 +1583,7 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) if (!m_pstream) { - wxMessageBox( _("Cannot open file for PostScript printing!"), _("Error"), wxOK ); + wxLogError( _("Cannot open file for PostScript printing!")); m_ok = FALSE; return FALSE; } @@ -1494,8 +1655,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(); @@ -1507,10 +1668,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) XLOG2DEV(m_minX); + wxCoord minY = (wxCoord) YLOG2DEV(m_minY); + wxCoord maxX = (wxCoord) XLOG2DEV(m_maxX); + wxCoord maxY = (wxCoord) YLOG2DEV(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) @@ -1622,8 +1799,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(); @@ -1639,7 +1816,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 ); } @@ -1676,7 +1859,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; } @@ -1691,8 +1874,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(); @@ -1764,10 +1945,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) @@ -1783,36 +1964,44 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, 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 */ wxString afmName = wxEmptyString; if (!m_printData.GetFontMetricPath().IsEmpty()) { - afmName = m_printData.GetFontMetricPath().fn_str(); + afmName = m_printData.GetFontMetricPath(); } /* 2. open and process the file @@ -1831,31 +2020,36 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */ - afmName << name << ".afm"; - FILE *afmFile = fopen(afmName,"r"); + afmName << name; + FILE *afmFile = wxFopen(afmName,wxT("r")); + if (afmFile==NULL) { afmName = wxThePrintSetupData->GetAFMPath(); - afmName << wxFILE_SEP_PATH << name << ".afm"; - afmFile = fopen(afmName,"r"); + afmName << wxFILE_SEP_PATH << name; + afmFile = wxFopen(afmName,wxT("r")); } -#ifdef __UNIX__ - 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" */ { afmName = wxINSTALL_PREFIX; afmName << wxFILE_SEP_PATH - << "share" << wxFILE_SEP_PATH - << "wx" << wxFILE_SEP_PATH - << "afm" << wxFILE_SEP_PATH - << name << ".afm"; - afmFile = fopen(afmName,"r"); + << wxT("share") << wxFILE_SEP_PATH + << wxT("wx") << 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.c_str() ); @@ -1953,23 +2147,24 @@ 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 = YLOG2DEVREL((wxCoord)(UnderlinePosition * fontToUse->GetPointSize())) / 1000.0f; pt = (double*) &m_underlineThickness; - *pt = UnderlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor; + *pt = YLOG2DEVREL((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++) @@ -1977,19 +2172,25 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, if(lastWidths[*p]== INT_MIN) { wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p,*p); - widthSum += (lastWidths[' ']/1000.0F * Size); /* assume space */ + sum += lastWidths[' ']; /* assume space */ } else { - widthSum += ((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 ) @@ -2037,10 +2238,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 @@ -2327,7 +2526,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());