From b64de91622281ec29d4e5990d09aa6ca6c41e0a0 Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Thu, 3 Aug 2000 21:43:30 +0000
Subject: [PATCH] fixed low resolution problem with wxPostScriptDC

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7926 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/postscpt.tex | 12 ++++++++++
 include/wx/generic/dcpsg.h |  6 +++++
 src/generic/dcpsg.cpp      | 46 +++++++++++++++++++++++++-------------
 src/generic/printps.cpp    | 10 +++++----
 4 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/docs/latex/wx/postscpt.tex b/docs/latex/wx/postscpt.tex
index 425d22d4e7..541f3158c0 100644
--- a/docs/latex/wx/postscpt.tex
+++ b/docs/latex/wx/postscpt.tex
@@ -36,4 +36,16 @@ This constructor and the global printer settings are now deprecated;
 use the wxPrintData constructor instead.
 
 
+\membersection{wxPostScriptDC::SetResolution}\label{wxpostscriptdcsetresolution}
 
+\func{static void}{SetResolution}{\param{int}{ ppi}}
+
+Set resolution (in pixels per inch) that will be used in PostScript
+output. Default is 720ppi.
+
+\membersection{wxPostScriptDC::GetResolution}\label{wxpostscriptdcgetresolution}
+
+\func{static int}{GetResolution}{\void}
+
+Return resolution used in PostScript output. See 
+\helpref{SetResolution}{wxpostscriptdcsetresolution}.
diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h
index 9ce1a6efe4..535e7ec729 100644
--- a/include/wx/generic/dcpsg.h
+++ b/include/wx/generic/dcpsg.h
@@ -129,6 +129,12 @@ public:
   void SetPrintData(const wxPrintData& data) { m_printData = data; }
 
   virtual int GetDepth() const { return 24; }
+  
+  static void SetResolution(int ppi);
+  static int GetResolution();
+  
+private:  
+  static float ms_PSScaleFactor;
 
 protected:
 
diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp
index 6b5c65a0e7..08d6fb0223 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;
@@ -872,13 +886,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 +908,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 );
@@ -1006,12 +1020,12 @@ void wxPostScriptDC::SetFont( const wxFont& font )
     fprintf( m_pstream, " findfont\n" );
 
     sprintf( buffer, "%f scalefont setfont\n", YLOG2DEVREL(m_font.GetPointSize() * 1000) / 1000.0F);
-    for (int i = 0; i < 100; i++)
-        if (buffer[i] == ',') buffer[i] = '.';
-    fprintf( m_pstream, buffer );
                 // 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.
+    for (int i = 0; i < 100; i++)
+        if (buffer[i] == ',') buffer[i] = '.';
+    fprintf( m_pstream, buffer );
 }
 
 void wxPostScriptDC::SetPen( const wxPen& pen )
@@ -1529,8 +1543,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
@@ -1563,7 +1577,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));
 }
 
 
@@ -1799,7 +1814,8 @@ void wxPostScriptDC::StartPage()
     }
 
     char buffer[100];
-    sprintf( buffer, "%.8f %.8f scale\n", scale_x, scale_y );
+    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 );
@@ -1840,7 +1856,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;
 }
diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp
index f819ed81ee..9a97d9cc6e 100644
--- a/src/generic/printps.cpp
+++ b/src/generic/printps.cpp
@@ -162,8 +162,8 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
     logPPIPrinterY = 100;
     */
 
-    logPPIPrinterX = 72;
-    logPPIPrinterY = 72;
+    logPPIPrinterX = wxPostScriptDC::GetResolution();
+    logPPIPrinterY = wxPostScriptDC::GetResolution();
 
     printout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
     printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
@@ -350,9 +350,11 @@ void wxPostScriptPrintPreview::DetermineScaling()
     {
         m_previewPrintout->SetPPIScreen(100, 100);
         //      m_previewPrintout->SetPPIPrinter(100, 100);
-        m_previewPrintout->SetPPIPrinter(72, 72);
+        m_previewPrintout->SetPPIPrinter(wxPostScriptDC::GetResolution(), wxPostScriptDC::GetResolution()); 
 
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
+        sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxPostScriptDC::GetResolution() / 72.0);
+        sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxPostScriptDC::GetResolution() / 72.0);
         wxSize sizeTenthsMM(paper->GetSize());
         wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
 
@@ -373,7 +375,7 @@ void wxPostScriptPrintPreview::DetermineScaling()
         }
 
         // At 100%, the page should look about page-size on the screen.
-        m_previewScale = (float)0.8;
+        m_previewScale = (float)0.8 * 72.0 / (float)wxPostScriptDC::GetResolution();
     }
 }
 
-- 
2.50.0

