dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Postscript PostscriptG


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Postscript PostscriptGraphics.cs, 1.1, 1.2 PostscriptPrintSession.cs, 1.1, 1.2
Date: Sat, 19 Jul 2003 06:17:12 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Postscript
In directory subversions:/tmp/cvs-serv2799/System.Drawing.Postscript

Modified Files:
        PostscriptGraphics.cs PostscriptPrintSession.cs 
Log Message:


Put some basic infrastructure in place to output page headers
and footers to "output.ps".


Index: PostscriptGraphics.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Postscript/PostscriptGraphics.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** PostscriptGraphics.cs       18 Jul 2003 05:17:56 -0000      1.1
--- PostscriptGraphics.cs       19 Jul 2003 10:17:10 -0000      1.2
***************
*** 23,26 ****
--- 23,27 ----
  {
  
+ using System.IO;
  using System.Drawing;
  using System.Drawing.Text;
***************
*** 29,34 ****
  internal class PostscriptGraphics : ToolkitGraphicsBase
  {
        // Constructor.
!       public PostscriptGraphics(IToolkit toolkit) : base(toolkit) {}
  
        // Get or set the graphics object's properties.
--- 30,45 ----
  internal class PostscriptGraphics : ToolkitGraphicsBase
  {
+       // Internal state.
+       private TextWriter writer;
+       private PostscriptPrintSession session;
+ 
        // Constructor.
!       public PostscriptGraphics(IToolkit toolkit, TextWriter writer,
!                                                         
PostscriptPrintSession session)
!                       : base(toolkit)
!                       {
!                               this.writer = writer;
!                               this.session = session;
!                       }
  
        // Get or set the graphics object's properties.

Index: PostscriptPrintSession.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Postscript/PostscriptPrintSession.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** PostscriptPrintSession.cs   18 Jul 2003 05:17:56 -0000      1.1
--- PostscriptPrintSession.cs   19 Jul 2003 10:17:10 -0000      1.2
***************
*** 23,26 ****
--- 23,28 ----
  {
  
+ using System.IO;
+ using System.Text;
  using System.Drawing.Printing;
  
***************
*** 30,33 ****
--- 32,40 ----
        private String printerName;
        private PrintDocument document;
+       private TextWriter writer;
+       private Encoding encoding;
+       private IToolkit toolkit;
+       private bool onPage;
+       private int pageNum;
  
        // Constructor.
***************
*** 36,39 ****
--- 43,51 ----
                                this.printerName = printerName;
                                this.document = document;
+                               this.writer = null;
+                               this.encoding = Encoding.Default;
+                               this.toolkit = new PostscriptToolkit();
+                               this.onPage = false;
+                               this.pageNum = 1;
                        }
  
***************
*** 54,58 ****
        public void StartPrint(PrintEventArgs e)
                        {
!                               // TODO
                        }
  
--- 66,103 ----
        public void StartPrint(PrintEventArgs e)
                        {
!                               // TODO: other output types, especially 
pipe-to-lpr.
!                               writer = new StreamWriter("output.ps");
! 
!                               // Write the Postscript header to the stream.
!                               writer.WriteLine("%!PS-Adobe-3.0");
!                               // TODO: bounding box
!                               writer.WriteLine
!                                       ("%%Creator: Portable.NET 
System.Drawing.Postscript");
!                               writer.WriteLine("%%DocumentData: Clean8Bit");
!                               writer.WriteLine("%%DocumentPaperSizes: {0}",
!                                       
document.DefaultPageSettings.PaperSize.Kind.ToString());
!                               if(document.DefaultPageSettings.Landscape)
!                               {
!                                       writer.WriteLine("%%Orientation: 
Landscape");
!                               }
!                               else
!                               {
!                                       writer.WriteLine("%%Orientation: 
Portrait");
!                               }
!                               writer.WriteLine("%%Pages: (atend)");
!                               writer.WriteLine("%%PageOrder: Ascend");
!                               if(document.DocumentName != "document")
!                               {
!                                       writer.WriteLine("%%Title: {0}", 
document.DocumentName);
!                               }
!                               writer.WriteLine("%%EndComments");
! 
!                               // Write the prolog definitions.
!                               writer.WriteLine("%%BeginProlog");
!                               foreach(String line in prolog)
!                               {
!                                       writer.WriteLine(line);
!                               }
!                               writer.WriteLine("%%EndProlog");
                        }
  
***************
*** 60,64 ****
        public void EndPrint(PrintEventArgs e)
                        {
!                               // TODO
                        }
  
--- 105,119 ----
        public void EndPrint(PrintEventArgs e)
                        {
!                               // Finalize the last page.
!                               EndPage(null);
! 
!                               // Output the Postscript trailer.
!                               writer.WriteLine("%%Trailer");
!                               writer.WriteLine("%%Pages: {0}", pageNum - 1);
!                               writer.WriteLine("%%EOF");
! 
!                               // Close the output stream.
!                               writer.Close();
!                               writer = null;
                        }
  
***************
*** 66,71 ****
        public Graphics StartPage(PrintPageEventArgs e)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 121,147 ----
        public Graphics StartPage(PrintPageEventArgs e)
                        {
!                               // Make sure that the previous page was closed.
!                               EndPage(e);
! 
!                               // Output the page header information.
!                               writer.WriteLine("%%Page: {0} {0}", pageNum, 
pageNum);
!                               writer.WriteLine("%%BeginPageSetup");
! 
!                               // Save the current VM state, so that we can
!                               // discard temporary definitions at the end
!                               // of the page.
!                               writer.WriteLine("/pagelevel save def");
! 
!                               // TODO: apply a rotation for landscape mode.
! 
!                               // Mark the end of the page header information.
!                               writer.WriteLine("%%EndPageSetup");
! 
!                               // We are now on a page.
!                               onPage = true;
! 
!                               // Create a "Graphics" object for this page and 
return it.
!                               return ToolkitManager.CreateGraphics
!                                       (new PostscriptGraphics(toolkit, 
writer, this));
                        }
  
***************
*** 73,77 ****
        public void EndPage(PrintPageEventArgs e)
                        {
!                               // TODO
                        }
  
--- 149,166 ----
        public void EndPage(PrintPageEventArgs e)
                        {
!                               if(onPage)
!                               {
!                                       // Restore the VM state at the start of 
the page.
!                                       writer.WriteLine("pagelevel restore");
! 
!                                       // Show the page.
!                                       writer.WriteLine("showpage");
! 
!                                       // We are no longer processing a page.
!                                       onPage = false;
! 
!                                       // Increase the page count.
!                                       ++pageNum;
!                               }
                        }
  
***************
*** 97,100 ****
--- 186,252 ----
                                }
                        }
+ 
+       // Write a string value to the PostScript stream while escaping
+       // characters that may cause problems in the printer otherwise.
+       internal void Write(String str)
+                       {
+                               // See if we can short-cut the conversion 
process
+                               // for simple strings with no funky characters.
+                               int posn = 0;
+                               char ch;
+                               while(posn < str.Length)
+                               {
+                                       ch = str[posn];
+                                       if(ch < 0x20 || ch > 0x7E)
+                                       {
+                                               break;
+                                       }
+                                       else if(ch == '(' || ch == ')' || ch == 
'\\')
+                                       {
+                                               break;
+                                       }
+                                       ++posn;
+                               }
+                               if(posn >= str.Length)
+                               {
+                                       writer.Write('(');
+                                       writer.Write(str);
+                                       writer.Write(')');
+                                       writer.Write(' ');
+                                       return;
+                               }
+ 
+                               // Convert the string into the final encoding 
and write it.
+                               byte[] bytes = encoding.GetBytes(str);
+                               writer.Write('(');
+                               foreach(byte b in bytes)
+                               {
+                                       if(b < 0x20 || b > 0x7E)
+                                       {
+                                               writer.Write('\\');
+                                               writer.Write((char)('0' + ((b 
>> 6) & 0x03)));
+                                               writer.Write((char)('0' + ((b 
>> 3) & 0x07)));
+                                               writer.Write((char)('0' + (b & 
0x07)));
+                                       }
+                                       else if(b == ((int)'(') ||
+                                                       b == ((int)')') ||
+                                                       b == ((int)'\\'))
+                                       {
+                                               writer.Write('\\');
+                                               writer.Write((char)b);
+                                       }
+                                       else
+                                       {
+                                               writer.Write((char)b);
+                                       }
+                               }
+                               writer.Write(')');
+                               writer.Write(' ');
+                       }
+ 
+       // The PostScript prolog to add to every output stream.
+       private static readonly String[] prolog = {
+               // TODO
+       };
  
  }; // class PostscriptPrintSession





reply via email to

[Prev in Thread] Current Thread [Next in Thread]