Postscript Driver
Topics
:Overview
Constants
Postscript Fonts
PostScript Paper Sizes
Functions
PostScript is a device-independent programming language for describing the appearance of text and graphics on a printed page. PostScript is an interpreted language, which means that when a printer or other interpreter looks at the file it executes the instructions one by one. There is no compilation step.
A PostScript file is an ordinary ASCII file. The first line of every PostScript file begins with %! usually followed by the version identifier: PS-Adobe 2.0. Comments begin with a percent sign % and end with a new line character.
The PostScript interpreter manages a dictionary stack, an operand stack, an execution stack, and a graphics state stack. Each stack is processed last-in-first-out (LIFO). Most PostScript operators use the operand stack-for example; the statement for adding two numbers is as follows:
2 3 add
This statement "pushes" a 2 and then a 3 onto the stack, and then the add operator "pops" both numbers off and then pushes the result (5) back onto the stack. PostScript uses postfix notation, where the operands (2 and 3) precede the operators (add).
The unit of measurement in PostScript is referred to as a point. There are 72 points per inch by default. Thus, a letter-size sheet of paper measures 612 by 792 points, with the origin (0,0) in the lower left corner of the page. PostScript operators allow you to manipulate the coordinate system using operators such as translate, scale, rotate, and so on.
The current point is the reference point used by many PostScript commands, including the commands for placing text on the page. Once set, the current point remains fixed in position on the paper until moved again. The default coordinate system originates (zero-zero point) at the lower left corner of the page. The X-axis increases towards the right and the Y-axis increase towards the top of the page. The initial zero-zero point is always the physical corner of the paper, even if the printer can't print all the way to the edge of the page. By default, distances are specified in PostScript points (1/72 of an inch.) This is true only if the default coordinate system is used. The location of the origin, the units for measurements, and even the direction of the axis may be changed by the programmer.
// Setup postscript defaults const int DEFAULT_TAB_SIZE = 8; // Default tab size const double DEFAULT_POINT_SIZE = 10; // Default point size (10 pitch) const double DEFAULT_OFFSET = 0.0; // Default inches to indent each line const double DEFAULT_LR_MARGIN = 1.0; // Default left and right margin offset const double DEFAULT_TB_MARGIN = 1.0; // Default top and bottom margin offset const double PRINTABLE_OFFSET_Y = 25; // Printable area offset const double PRINTABLE_OFFSET_X = 25; // Printable area offset const double HEADER_OFFSET = 1.0; // Offset for header and trailer text const int THICK_LINE_WIDTH = 2; // Line width for header lines const int LINE_WIDTH = 1; // Line width for separator lines // Setup postscript constants const char SEP_CHAR = '\001'; // Column separator character const int MAXPAGES = 10000; // Maximum number of pages per job const int PS_EOF = 0x04; // PostScript end of file mark const int MAX_LINES = 160; // Maximum lines per page for documents const int PIXELS_PER_INCH = 72; // PostScript points per inch // Max lines for a unix man page produced by nroff // nroff is used to format man pages under most variants of UNIX const int UNIX_MAN_PAGE_LINES = 66; // Setup input/output buffer sizes for postscript documents const int MAX_LINE = 256; // No PostScript line can exceed 256 characters const int BUFIN = 1024; // Maximum length of an input line const int BUFOUT = (BUFIN * 5);
Most PostScript products include software to support 13 standard fonts based on the Courier, Times, Helvetica, and Symbol families. The following enumeration, defined in the PostScriptDrv class, is used to select a specific font:
enum PSFonts { COURIER, COURIER_BOLD, COURIER_OBLIQUE, COURIER_BOLD_OBLIQUE, TIMES, TIMES_BOLD, TIMES_ITALIC, TIMES_BOLD_ITALIC, HELV, HELV_BOLD, HELV_OBLIQUE, HELV_BOLD_OBLIQUE, SYMBOL };
The following enumeration, defined in the PostScriptDrv class, is used to select a specific paper size:
enum PSPaperSizes { // Non-metric Traditional Paper Sizes used in Canada and the // United States. Sheet sizes accommodate 1/8" (3 mm) head, // foot, and fore edge trim margins (width precedes height.) // Decimal inches multiplied by 25.4 to convert to approximate mm. // N.B. fractional mm measures must be rounded to the nearest // whole number. LETTER_SIZE, // 8.5 x 11 inches LEGAL_SIZE, // 8.5 x 14 inches TABLOID_SIZE, // 11 x 17 inches // ISO/DIN and JIS Standard Paper Sizes Trim sizes in mm. // Width precedes height. Sheet sizes accommodate 3mm head, // foot, and fore edge trim margins. To convert to approximate // decimal inches, divide measures by 25.4. A3_SIZE, // 297mm x 420mm (11.70" X 16.55") A4_SIZE // 210mm x 297mm (8.27" X 11.70") };
The PostScriptDrv class is used to create postscript documents. This version prints postscript documents to a file or the console. The default coordinate system is used for all PostScript operations and all distances are calculated in increments of 1/72 of an inch.
PostScriptDrv::PostScriptDrv()
PostScriptDrv::~PostScriptDrv()
PostScriptDrv::ChangeFont()
PostScriptDrv::CharWidth()
PostScriptDrv::CharsPerInch()
PostScriptDrv::Columns()
PostScriptDrv::ConvertTextFile()
PostScriptDrv::Copies()
PostScriptDrv::DocumentSetup()
PostScriptDrv::DrawHeaderLine()
PostScriptDrv::EndPage()
PostScriptDrv::Epilogue()
PostScriptDrv::FontSize()
PostScriptDrv::GetMode()
PostScriptDrv::HeaderFont()
PostScriptDrv::HeaderFontSize()
PostScriptDrv::LandScapeMode()
PostScriptDrv::LinesPerPage()
PostScriptDrv::MediaSetup()
PostScriptDrv::MoveTo()
PostScriptDrv::NCopies()
PostScriptDrv::NoMargins()
PostScriptDrv::PageHeight()
PostScriptDrv::PageWidth()
PostScriptDrv::PortraitMode()
PostScriptDrv::PrintLine()
PostScriptDrv::ProcessText()
PostScriptDrv::Prologue()
PostScriptDrv::SetDateString()
PostScriptDrv::SetDocumentName()
PostScriptDrv::SetFont()
PostScriptDrv::SetHeaderFont()
PostScriptDrv::SetPaperSize()
PostScriptDrv::SetTabStop()
PostScriptDrv::StartPage()
PostScriptDrv::StartX()
PostScriptDrv::StartY()
PostScriptDrv::StringLen()
PostScriptDrv::TabStop()
PostScriptDrv::TextFont()
PostScriptDrv::UseHeader()
PostScriptDrv::UseLRMargin()
PostScriptDrv::UseTBMargin()
PostScriptDrv::UsingHeader()
PostScriptDrv::UsingLRMargin()
PostScriptDrv::UsingTBMargin()
PostScriptDrv::drawLine()
PostScriptDrv::drawThickLine()
GetSystemTime()
PostScriptDrv::PostScriptDrv()
- Default class constructor responsible for setting the default page description values and default fonts.PostScriptDrv::PostScriptDrv(const PostScriptDrv &ob)
- Class copy constructor used to copy construct a PostScriptDrv object.PostScriptDrv &PostScriptDrv::operator=(const PostScriptDrv &ob)
- Overloaded assignment operator used to assign the specified object to the object that invoked the call.PostScriptDrv::~PostScriptDrv()
- Class destructor that does nothing.void PostScriptDrv::ChangeFont(ostream &stream, PSFonts font, double size)
- Public member function used to change the current font. PSFonts is an enumeration defined in the PostScriptDrv class used to select a font family.double PostScriptDrv::CharWidth()
- Public member function that returns the character width of the selected font. The character width of a Courier font is calculated by multiplying .6 by the selected font size. All the other PostScript fonts have a variable character width.double PostScriptDrv::CharsPerInch()
- Public member function that returns the characters per inch based on the selected font size. The number of characters per inch is calculated by dividing the pixels per inch by the character width of the selected font. - Public member function that returns the current number of columns, based on the selected font, paper size, margins, and orientation.int PostScriptDrv::ConvertTextFile(ifstream &infile, ostream &stream,int wrap = 0, int cut = 1)
- Public member function used to convert the specified ASCII document to a PostScript document. If wrap is true the line will wrap around the page if the number of columns are exceeded. If cut is true the line will be truncated to match the maximum number of columns set for this document. Returns true if successful.void PostScriptDrv::Copies(int num)
- Public member function used to set the number of copies that will be printed.void PostScriptDrv::DocumentSetup(double LR_margin = 0, double TB_margin = 0, int man = 0)
- Public member function used to calculate the "x" and "y" positions, lines per page and columns for landscape and portrait modes. The left/right and top/bottom margin offsets will not be used if left/right or top/bottom margins are not enabled. If "man" is true the line per page will be set to max lines per page for UNIX man pages produced by "nroff." Nroff is used to format man pages under most variants of UNIX.void PostScriptDrv::DrawHeaderLine()
- Public member function used to enable lines that will be printed below the page header and above the page number.void PostScriptDrv::EndPage(ostream &stream)
- Public member function used to write the end of page sequence to the specified stream when the end of a page is reached.void PostScriptDrv::Epilogue(ostream &stream, int page_count)
- Public member function used to write the PostScript epilogue to the specified stream when the end of document is reached.double PostScriptDrv::FontSize()
- Public member function that returns the current font size. - Public member function that returns true if using landscape mode.char *PostScriptDrv::HeaderFont()
- Public member function that returns the name of selected header font.double PostScriptDrv::HeaderFontSize()
- Public member function that returns the current size of the header font.void PostScriptDrv::LandScapeMode()
- Public member function used to enable landscape mode.int PostScriptDrv::LinesPerPage()
- Public member function that returns the current lines per page, based on the selected font, paper size, margins, and orientation. - Public member function used to set the physical sources and physical destinations for the media source and destination to be used by the printer. These settings are device dependent. The duplex option enables duplex printing if a duplex device is attached to the printer. Each pair of consecutive pages will be printed on opposite sides of a single sheet of paper. The manual feed option will feed the paper from the manual feed position. The tray options are used to select a specific paper tray to print from. The tray number indicates the actual paper tray. The correspondence between tray numbers and the actual positions is specific to each printer. Example: The HP LaserJet 5Si/5Si MX printer uses the following numbers to represent the actual paper trays: 0 = Tray 2, 1 = Tray 3, 2 = Envelope Feeder, 3 = Tray 1, 4 = Tray 4void PostScriptDrv::MoveTo(ostream &stream, int x, int y)
- Public member function used to move to the specified "x" and "y" positions. - Public member function that returns the current number of copies to be printed.void PostScriptDrv::NoMargins()
- Public member function used to disable left/right and top/bottom margins.int PostScriptDrv::PageHeight()
- Public member function that returns the current page height in PostScript points, based on the selected paper size.int PostScriptDrv::PageWidth()
- Public member function that returns the current page width in PostScript points, based on the selected paper size.void PostScriptDrv::PortraitMode()
- Public member function used to enable portrait mode.int PostScriptDrv::PrintLine(char *in, ostream &stream)
- Public member function used to print a line of text to the selected stream.int PostScriptDrv::PrintLine(char *s, unsigned max_len, ofstream &stream)
- Public member function used to print a line of text, up to the specified length, to the specified stream.int PostScriptDrv::ProcessText(char *in, ostream &stream, int cut = 1, int filter = 0)
- Public member function used to process a line of text before printing it. If cut is true the line will be truncated to match the maximum number of columns for this line. If filter is true each line will be filtered for escape sequences and non-printable characters before the line is truncated. Returns true if successful.void PostScriptDrv::Prologue(ostream &stream, char *pn = 0, char *hn = 0,char *cd = 0, char *un = 0)
-Public member function used to print the PostScript prologue to the specified stream. This indicates the start of the document. Arguments are: "pn" - Program Name, "hn" - Hostname, "cd" - Creation Date, "un" - Username. The arguments will be added to the prologue only if specified.void PostScriptDrv::SetDateString(char *s)
- Public member function used to add a date to this document. The date string will be printed on each page if the use of page headers is enabled.void PostScriptDrv::SetDateString(const char *s)
- Public member function used to add a date to this document. The date string will be printed on each page if the use of page headers is enabled.void PostScriptDrv::SetDocumentName(char *s)
- Public member function used to add a date to this document. The date string will be printed on each page if the use of page headers is enabled.void PostScriptDrv::SetDocumentName(const char *s)
- Public member function used to name this document. The document name will be printed on each page if the use of page headers is enabled.void PostScriptDrv::SetFont(PSFonts font, double size)
- Public member function used to set the document font. PSFonts is an enumeration defined in the PostScriptDrv class used to select a font family.void PostScriptDrv::SetHeaderFont(PSFonts font, double size)
- - Public member function used to set the header font. PSFonts is an enumeration defined in the PostScriptDrv class used to select a font family.void PostScriptDrv::SetPaperSize(PSPaperSizes size)
- Public member function used to set the paper size for this document. PSPaperSizes is an enumeration defined in the PostScriptDrv class used to set the paper size.void PostScriptDrv::SetTabStop(int num)
- Public member function used to set the tab size.void PostScriptDrv::StartPage(int n, ostream &stream)
- Public member function used to write the start of page sequence to the specified stream each time a new page is started. - Public member function that returns the starting "x" position for each page. - Public member function that returns the starting "y" position for each page.int PostScriptDrv::StringLen(char *s, int charWidth)
- Public member function used to convert a string's length to PostScript points.int PostScriptDrv::StringLen(const char *s, int charWidth)
- Public member function used to convert a string's length to PostScript points. - Public member function that returns the current tab setting.char *PostScriptDrv::TextFont()
- Public member function that returns the name of the selected font family.void PostScriptDrv::UseHeader()
- Public member function used to enable a header and page number to be printed on each page.void PostScriptDrv::UseLRMargin()
- Public member function used to enable left and right margins.void PostScriptDrv::UseTBMargin()
- Public member function used to enable top and bottom margins.int PostScriptDrv::UsingHeader()
- Public member function that returns true if headers and page numbers are enabled.int PostScriptDrv::UsingLRMargin()
- Public member function that returns true if left and right margins are enabled.int PostScriptDrv::UsingTBMargin()
- Public member function that returns true if top and bottom margins are enabled.void PostScriptDrv::drawLine(ostream &stream, int points, int xpos, int ypos)
- Public member function used to draw a line to the specified stream starting at the specified "x" and "y" positions. The number of PostScript points determines the length of the line.void PostScriptDrv::drawThickLine(ostream &stream, int points, int xpos, int ypos)
Public member function used to draw a thick line to the specified stream starting at the specified "x" and "y" positions. The number of PostScript points determines the length of the line.void GetSystemTime(char *s, int full_month_name = 1)
- Standalone function used to create a custom time string for PostScript page headers. If the "full_month_name" variable is false an abbreviated month name will be used instead of a full name, which is selected by default.
End Of Document |