// 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;
wxCoord xx = XLOG2DEV(points[0].x + xoffset);
wxCoord yy = YLOG2DEV(points[0].y + yoffset);
+ wxCoord xx0 = xx;
+ wxCoord yy0 = yy;
+
fprintf( m_pstream, "%d %d moveto\n", xx, yy );
CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
}
- fprintf( m_pstream, "fill\n" );
+ fprintf( m_pstream, "%d %d lineto\n", xx0, yy0 );
+ fprintf( m_pstream, "stroke\n" );
}
}
"%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 );
"%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 );
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());
"[%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 );
fprintf( m_pstream, buffer );
fprintf( m_pstream, " findfont\n" );
- fprintf( m_pstream, "%f scalefont setfont\n", YLOG2DEVREL(m_font.GetPointSize() * 1000) / 1000.0F);
+ 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 )
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
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;
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;
{
wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
+ wxCoord text_w, text_h, text_descent;
+
+ GetTextExtent(text, &text_w, &text_h, &text_descent);
+
SetFont( m_font );
if (m_textForegroundColour.Ok())
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;
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 */
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);
+
+ /* 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);
+ for (i = 0; i < len; i++)
+ {
+ int c = (unsigned char) textbuf[i];
+ if (c == ')' || c == '(' || c == '\\')
+ {
+ /* Cope with special characters */
+ fprintf( m_pstream, "\\" );
+ tmpbuf[0] = (char) c;
+ fprintf( m_pstream, tmpbuf );
+ }
+ else if ( c >= 128 )
+ {
+ /* Cope with character codes > 127 */
+ fprintf(m_pstream, "\\%o", c);
+ }
+ else
+ {
+ tmpbuf[0] = (char) c;
+ fprintf( m_pstream, tmpbuf );
+ }
+ }
+
+ 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)
{
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
// 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));
}
if (!m_pstream)
{
- wxMessageBox( _("Cannot open file for PostScript printing!"), _("Error"), wxOK );
+ wxLogError( _("Cannot open file for PostScript printing!"));
m_ok = FALSE;
return FALSE;
}
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();
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();
// 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 );
}
wxCoord wxPostScriptDC::GetCharHeight() const
{
if (m_font.Ok())
- return m_font.GetPointSize();
+ return m_font.GetPointSize();
else
return 12;
}
{
if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "CourBoO";
else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "CourBo";
- else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "Cour0";
+ else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "CourO";
else name = "Cour";
}
break;
{
if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "HelvBoO";
else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "HelvBo";
- else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "Helv0";
+ else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "HelvO";
else name = "Helv";
}
break;
wxString afmName = wxEmptyString;
if (!m_printData.GetFontMetricPath().IsEmpty())
{
- afmName = m_printData.GetFontMetricPath().fn_str();
+ afmName = m_printData.GetFontMetricPath();
}
/* 2. open and process the file
/* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
- afmName << name << ".afm";
- FILE *afmFile = fopen(afmName,"r");
+ afmName << name << wxT(".afm");
+ 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 << wxT(".afm");
+ afmFile = wxFopen(afmName,wxT("r"));
}
#ifdef __UNIX__
{
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
+ << wxT("afm") << wxFILE_SEP_PATH
+ << name << wxT(".afm");
+ afmFile = wxFopen(afmName,wxT("r"));
}
#endif
#endif
-
+
if (afmFile==NULL)
{
wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName.c_str() );
while(fgets(line,sizeof(line),afmFile)!=NULL)
{
/* A.) check for descender definition */
- if (wxStrncmp(line,"Descender",9)==0)
+ if (strncmp(line,"Descender",9)==0)
{
if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) ||
- (wxStrcmp(descString,"Descender")!=0))
+ (strcmp(descString,"Descender")!=0))
{
wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName.c_str(),line );
}
}
/* JC 1.) check for UnderlinePosition */
- else if(wxStrncmp(line,"UnderlinePosition",17)==0)
+ else if(strncmp(line,"UnderlinePosition",17)==0)
{
if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) ||
- (wxStrcmp(upString,"UnderlinePosition")!=0))
+ (strcmp(upString,"UnderlinePosition")!=0))
{
wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName.c_str(), line );
}
}
/* JC 2.) check for UnderlineThickness */
- else if(wxStrncmp(line,"UnderlineThickness",18)==0)
+ else if(strncmp(line,"UnderlineThickness",18)==0)
{
if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) ||
- (wxStrcmp(utString,"UnderlineThickness")!=0))
+ (strcmp(utString,"UnderlineThickness")!=0))
{
wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName.c_str(), line );
}
}
/* JC 3.) check for EncodingScheme */
- else if(wxStrncmp(line,"EncodingScheme",14)==0)
+ else if(strncmp(line,"EncodingScheme",14)==0)
{
if ((sscanf(line,"%s%s",utString,encString)!=2) ||
- (wxStrcmp(utString,"EncodingScheme")!=0))
+ (strcmp(utString,"EncodingScheme")!=0))
{
wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName.c_str(), line );
}
- else if (wxStrncmp(encString, "AdobeStandardEncoding", 21))
+ else if (strncmp(encString, "AdobeStandardEncoding", 21))
{
wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
afmName.c_str(),line, encString);
}
}
/* B.) check for char-width */
- else if(wxStrncmp(line,"C ",2)==0)
+ else if(strncmp(line,"C ",2)==0)
{
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.c_str(),line);
}
- if(wxStrcmp(cString,"C")!=0 || wxStrcmp(semiString,";")!=0 || wxStrcmp(WXString,"WX")!=0)
+ 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.c_str(),line);
}
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! */
}
/* 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 )
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
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());