[REBOL] Printing Dialect
From: AJMartin:orcon at: 2-Oct-2003 22:55
Here's the start of my C# code for printing a report (Scribe).
/*
Name: Scribe
Title: "Scribe"
File: %Scribe.cs
Purpose: "A C# printing interface for Rebol."
Author: "Andrew Martin"
Date: 2/October/2003
Version: 0.2.1
*/
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
public class Scribe : Object {
private static void pd_PrintPage (object sender, PrintPageEventArgs e) {
Graphics g = e.Graphics;
String sMessage = Environment.UserName;
Font fMessage = new Font ("Arial", 24, GraphicsUnit.Point);
g.DrawString (sMessage, fMessage, Brushes.Black, 100, 100);
Font fHeader = new Font ("Arial", 12, GraphicsUnit.Point);
Brush bHeader = Brushes.Black;
Pen pHeader = new Pen (Color.Black, 1);
Rectangle rHeader = new Rectangle (0, 200, 120, 50);
g.DrawString ("Subject & Teacher", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Attendance (14)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Equipment (7)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Work (10)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Social (10)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Academic (9)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
rHeader.X += rHeader.Width;
g.DrawString ("Total (50)", fHeader, bHeader, rHeader);
g.DrawRectangle (pHeader, rHeader);
}
public static void Main (string[] args) {
PrintDocument pd = new PrintDocument ();
pd.PrintPage += new PrintPageEventHandler (pd_PrintPage);
PrintPreviewDialog ppd = new PrintPreviewDialog ();
ppd.Document = pd;
ppd.Icon = new Icon ("Scribe.ico");
ppd.ShowDialog ();
}
}
/*
End.
*/
And the lines needed to compile Scribe and run it:
csc /target:winexe /out:Scribe.exe /reference:System.dll
/reference:System.Windows.Forms.dll /reference:System.Drawing.dll
/win32icon:Scribe.ico Scribe.cs
Scribe
(Note that I've got an icon file which is linked in the above line. One can
substitute any convenient Window .ico file for this file.)
I'd like to factor out the C# parts and write a simplistic or simple Page
Description Dialect (or Language), so that I have Rebol generate most of the
report while Scribe handles the printing part.
I've thought of writing the dialect in C# then compiling and executing that
in Scribe, but that leads to problems with security and being harder to
understand for people not used to C#. I've also thought of using PostScript
and PDF, but they seem more complex to me. I've also thought of using a
special Rebol dialect something like this:
PrintPreview
[
Paper A4
Top Left %"Colenso Logo.png"
Top Center
"COLENSO HIGH SCHOOL"
"2003 - Year 10 Diploma Results"
"Term 2"
Left
Divider
"Mr & Mrs Family"
"123 Example Street"
"Nelson Park"
"NAPIER"
Space
"Name: Pupil Family" Right "Form Class: 10XY"
Center
Divider
| "Subject & Teacher" | "Attendance (14)" | "Equipment (7)" | "Work (10)" |
Social (10)
| "Academic (9)" | "Total (50)" |
Divider
| "10 Textiles" | 12.5 | 6 | 10 | 10 | 9 | 47.5 |
| "Mrs X Bafabt" | 12.5 | 7 | 5 | 10 | 6 | 40.5 |
Divider
]
For the above, I plan to use Rebol's 'compose function to insert each
pupil's reported data and feed the entire result to scribe. But I think I've
lost my way (HTML tables seems a better idea for describing a table).
Is there an approach that you can see that I've failed to see? Perhaps you
can think of a better and easier to understand printing dialect? One
important point is that I'd like to see exact placement on the page (like
the C# code shows), along with a few shortcuts (like the Rebol dialect
does).
Andrew J Martin
Grail Jedi
ICQ: 26227169
http://www.rebol.it/Valley/
http://valley.orcon.net.nz/
http://Valley.150m.com/