Unit LinePrnt

****************************************************************************** TLinePrinter Version 1.0 8/8/96 - Bill Menees Copyright (c) 1996 This is a non-visual VCL component that encapsulates the Printer object. Notes: 1. Almost every property is measured in MeasureUnits (inches or millimeters). TabSize is the only exception; it is measured in spaces. 2. If you have no default printer, you will get warnings at design time. You may still be able to work with it, but I haven't really tested it. I've tried to make sure things are handled gracefully at run time if you have no printers installed, but I intentionally warn you at design time if you try to modify any properties that directly modify the underlying TPrinter object (e.g. Font, Orientation, Title). TPrinter depends on there being at least one printer. 3. If you try to set the margins too small, they get set to the corres- ponding gutter size. If you try to set the margins too large, they get set to the physical page size (height or width) minus the corres- ponding gutter size. Originally, I was going to raise a TLinePrinter exception, but that proved bad because exceptions could be fired while the component was being loaded (before you could trap them in code). To get around this, I had to just quietly set them to appropriate values. 4. If you increase the page size and set the margins then decrease the page size, the margins may be out of bounds. This is the reason for the Refresh method, it makes sure they are within bounds. Thus, you should ALWAYS call the TLinePrinter.Refresh method after you display a printer setup dialog, change any printer characteristics through API calls, etc. ******************************************************************************** 10/2/96 - Modifications suggested by: Göran Pettersson E-Mail: g.pettersson@udt.se A. Added new property 'MeasureUnit', for selection between Inches and Millimeters. B. Added english and metric constants for default AvailablePageHeight, AvailablePageWidth, PhysicalPageHeight, PhysicalPageWidth, GutterLeft, and GutterTop. ******************************************************************************** 10/31/96 - Modifications I decided to make: 1. PrintableWidth and PrintableHeight properties were added. They give the printable area bounded by the margins. 2. The former PageHeight and PageWidth properties were renamed to AvailablePageHeight and AvailablePageWidth. 3. There is now a public Canvas property! So if you need to do a little drawing of your own, you can. 4. OnNewPage used to fire before the new page was created. This wasn't very useful. Now OnNewPage fires after the new page is created. 5. HeaderFormat and FooterFormat are now used to format the Header and Footer instead of TableFormat. 6. The LinesAsTable property has been removed. Now PrintLines takes this as a parameter. This makes more sense. (LinesAsTable was only needed as a property in an early alpha version of TLinePrinter where the Lines were printed automatically in BeginDoc.) 7. There is now a PrevLine function so you can print multiple times on the same line if you need to. It returns a Boolean value to indicate its success. It only fails at the top of a page. *******************************************************************************) { $LONGSTRINGS ON

Classes

TLinePrinter -
TPrntProgDlg -

Functions

ExpandTabsAsSpaces - If there is nowhere to break, just return the whole line.
ParseFormatToken - Currently, this routine is terribly inefficient since Pos always starts back at the beginning of the string.
Register -
ReplaceSubString - =============================================================================} { Non-methods that may prove useful elsewhere.
StripBackToWhiteSpace -
TokenizeString - Width

Types

TLineSpacing
TMeasurement
TMeasureUnit
TPageBorders
TPageBorderStyle
TPixels

Constants

DateField
DefaultAvailablePageHeightIn
DefaultAvailablePageHeightMm
DefaultAvailablePageWidthIn
DefaultAvailablePageWidthMm
DefaultBorderWidth
DefaultDPI
DefaultGutterLeftIn
DefaultGutterLeftMm
DefaultGutterTopIn
DefaultGutterTopMm
DefaultPhysicalPageHeightIn
DefaultPhysicalPageHeightMm
DefaultPhysicalPageWidthIn
DefaultPhysicalPageWidthMm
LineField
LinePrinterWhiteSpaceChars
PageField
TimeField
TitleField
TokenSeparator

Variables


Functions


function ExpandTabsAsSpaces(const S: String; const TabSize: Integer): String;

If there is nowhere to break, just return the whole line.

procedure ParseFormatToken(var CurToken: String; var CurAlignment: TAlignment; var CurWidth: TMeasurement; const DefaultColWidth: TMeasurement);

Currently, this routine is terribly inefficient since Pos always starts back at the beginning of the string. Eventually, I hope to replace this with a Knuth-Morris-Pratt based search and replace that starts at a specified location. This works for now though for what I need.} {First, make sure old isn't contained in new. This gets around the infinite loop situation. If old is in new, we just return S unmodified.

procedure Register;


function ReplaceSubString(OldSubStr, NewSubStr, S: String): String;

=============================================================================} { Non-methods that may prove useful elsewhere. } {=============================================================================

function StripBackToWhiteSpace(const S: String): String;


procedure TokenizeString(const S: String; Tokens: TStringList);

Width

Types


TLineSpacing = (lsHalfSpace, lsSingleSpace, lsSingleAndAHalf, lsDoubleSpace);

TMeasurement = Single
These are declared so you can tell at a glance what a property or function's return value is used for.
TMeasureUnit = (muInches, muMillimeters);
Public declarations
TPageBorders = set of TPageBorderStyle

TPageBorderStyle = (pbTop, pbBottom, pbLeft, pbRight);

TPixels = Cardinal

Constants

DateField = '{$DATE}'

DefaultAvailablePageHeightIn = 10.5

DefaultAvailablePageHeightMm = 284.0

DefaultAvailablePageWidthIn = 8.0

DefaultAvailablePageWidthMm = 198.0

DefaultBorderWidth = 2

DefaultDPI = 300

In Pixels

DefaultGutterLeftIn = 0.25

DefaultGutterLeftMm = 6.0

DefaultGutterTopIn = 0.25

DefaultGutterTopMm = 6.0

DefaultPhysicalPageHeightIn = 11.0

In Inches

DefaultPhysicalPageHeightMm = 297.0

In Millimeters

DefaultPhysicalPageWidthIn = 8.5

DefaultPhysicalPageWidthMm = 210.0

LineField = '{$LINE}'

These are expanded only in Headers, Footers, and Tables.

LinePrinterWhiteSpaceChars = [#0..#32]

PageField = '{$PAGE}'

TimeField = '{$TIME}'

TitleField = '{$TITLE}'

TokenSeparator = '|'


Variables