The commands can be broken into the following categories. Note that all of these commands are preceded by XPrint (except for Printer$, PrinterCount, XPrint, and XPrint$).
|
Attach, Close |
|
Printer$, PrinterCount, XPrint$ |
|
Cancel, FormFeed |
|
Client, Collate, ColorMode, Copies, DC, Duplex, Lines, Margin, Mix, Orientation, Paper, Papers, PPI, Quality, Size, Tray, Trays |
|
Collate, ColorMode, Copies, Duplex, Mix, Orientation, Paper, Quality, Tray |
|
Chr Size, Color, Text Size GET Pixel, GET Pos, GET Scale |
|
Font, Scale, Scale Pixels, Style, Width SET Font, SET Pixel, SET Pos, |
|
Arc, Box, Ellipse, Line Pie, Polygon, Polyline, XPrint |
| Copy, ImageList, Render, Stretch |
Printing Text
In general, printing under PowerBASIC requires three steps.
XPrint Attach Default 'uses default printer XPrint Attach Choose 'open printer select dialog XPrint Attach PrinterName$ 'explicitly select a printer
XPrint "hello" 'print text and move print position to next line XPrint "hello"; 'print text and do not move print position
XPrint Attach Default 'use the default printer XPrint "hello" 'print one line of text XPrint "goodbye" 'print a second line of text XPrint Close 'send content to printer
In PowerBASIC, when the printer is detached, all buffer content is sent to the printer
Fonts
The font and font properties used for printing may be controlled by
an application. In general, the Font New command is used to create
one or more fonts. Each is given a handle. Then, the Set Font
statement can be used to select from any of the available handles.
Font New - create a font XPrint Set Font - select a font XPrint Text Size - get height/width of text string XPrint Chr Size - get height/width of a single character
Font New is used to define a font and its properties. It also gives the font a handle.
XPrint Set Font can select any font created by Font New. The selected font will be used
XPrint Text Size and XPrint Chr Size return string and character size (height/width) information for the selected font.
Printer Job Control
To print on a new page, use the XPrint FormFeed statement.
To cancel print statement not yet released to the printer, use the XPrint Cancel statement. Content released to the printer cannot be stopped by PowerBASIC.
XPrint FormFeed 'printing starts at 0,0 on new page Xprint Cancel 'cancel all buffered printing statements
Printing Graphics (Drawing Primitives)
PowerBASIC provides tools to create graphics. Both
drawing primitives and bitmap images may be sent to the
selected printer.
There are seven primitives - arc, box, ellipse, line, pie, polygon, and polyline. Setting of individual pixels is also supported.
The primitives can be roughly categorized by the way in which they use page coordinates for defining where a drawing takes place.
Examples of all the drawing functions are included in the reference table at the bottom of this page.
XPrint Set POS 'sets POS for the next operation XPrint Get POS 'get POS information XPrint 'write text at POS XPrint Line 'draw line from POS to x,y XPrint Set Pixel 'set color of pixel at POS
XPrint ARC XPrint Ellipse XPrint Pie XPrint Box
XPRINT Polygon XPRINT Polyline
Graphics Properties
When drawing the primitives discussed in the previous section
there are several properties which can be set to adjust how
the drawing looks.
XPRINT SCALE - define custom coordinate system XPRINT GET SCALE - get scale settings XPRINT SCALE PIXELS - Reset coordinate system to default XPRINT STYLE - Set line style XPRINT WIDTH - Set line width
XPrint Scale allows defining the upper/left and lower/right coordinates of the printable area of the selected printer.
XPrint Scale Pixel resets the coordinate system to pixels, returning from the custom coordinates set by XPrint Scale.
XPrint Style selects from 0-solid, 1-dash, 2-dot, 3-dashdot and 4-dashdotdot for drawing lines and borders of primitives.
XPrint Width set the line width in pixels (regardless of XPrint Scale settings). Default is 1 pixel. If set greater than 1, style 0-solid is always used.
Examples of all the drawing functions are included in the reference table at the bottom of this page.
Pixels, Pixels, Pixels
In addition to drawing primitives, PowerBASIC can work at
the pixel level - setting the pixel color at a specific location.
XPrint Color - sets default fg/bg colors XPrint Set Pixel - set pixel color at x,y XPrint Get Pixel - get pixel color at x,y XPrint Set POS
XPrint Color can set the foreground color, which XPrint Set Pixel uses as a default color.
XPrint Set Color sets the color at x,y. Uses default foreground color if a color is not explicitly specified. If a STEP option is invoke, the x,y dimension are relative to POS.
XPrint Get Pixel support depends on the printer driver's ability to provide the information. If not supported, -1 is returned.
XPrint Set POS changes the default position, which XPrint Set Color uses if invoked with the STEP option.
Printing Images
PowerBASIC supports several methods of printing images onto
a page, a shown in the next listing.
XPrint Copy - send bitmap to printer (all or partial) XPrint ImageList - print image from ImageList (all) XPrint Stretch - copy/resize bitmap (all or partial, with resize) XPrint Render - print image (all, with resize)
With Copy, ImageList and Stretch, a preloaded image from a control, window, bitmap structure or imagelist structure is used. Using preloaded images significantly speeds up image display operations, especially animated displays.
With Render, an image from a resource file or disk file is used.
Two of the functions, Stretch and Render can resize the image.
Two of the functions, Copy and Stretch, can be used to print only a portion of the original image.
The Printer
In addition to selecting a printer when using the XPrint command, there
are three other statements useful in managing the selection of a printer
for attachment.
Printer$ - get printer names, one at a time PrinterCount - get quantity of installed printers XPrint$ - get name of attached printer
Printercount tells how many printers are available. Printer$ takes a number from 1 to PrinterCount and returns the name of the printer. XPrint$ returns the name of the currently attached printer.
Also, PowerBASIC also enables a programmer to get or set various properties (over 18) of the attached printer. The specific functions were listed in the table at the top of the page. Examples of each are provided in the reference table at the bottom of this page.
Printing Commands - One Line Descriptions
All of these commands apply to attached host printers.
The use of line printer commands is discouraged and the
commands are not shown here.
Line Printers
PowerBASIC also supports line printers, where printing content is sent
directly to a port, rather than through a Windows device driver. See the
PowerBASIC Help file for more information on the LPRINT family of functions
which provides this capability. Using printers which connect through
Windows printer drivers is recommended for the greater capabilities
they offer. The line printer family of commands (LPRINT) are not
covered in this tutorial.
Function Reference
Here's a quick reference of the available array functions, in alphabetical
order.
name$ = XPrinter$ NAME, n% name$ = XPrinter$ PORT, n%
Takes a number from 1 to PrinterCount and returns the name or port of the printer.
n% = PrinterCount
XPrint "hello" ' text sent to printer ' doesn't print until XPrint Close is used
XPrint ARC (x1,y1)-(x2,y2), angBegin, angEnd, rgbColor!
XPrint Attach Default 'uses default printer XPrint Attach Choose 'open printer select dialog XPrint Attach PrinterName$ 'explicitly select a printer
All 3 options allow naming of print job. Just add ", jobname$" to the end of the statements.
XPrint Box (x1,y1)-(x2,y2), corner&, rgbColor&, fColor&, style&
XPrint CancelCancels print statements not yet released to the printer. Content released to the printer cannot be stopped by PowerBASIC.
XPrint Chr Size TO width!, height!
XPrint CLOSE 'detach currently selected printer 'send print buffer to printer
If not used, print content may be lost.
XPrint Color fgcolor&, bgcolor& 'rgb values, bgcolor optional
Use -1 for default color or -2 for background color.
XPrint Copy hBMP, id&, style& 'full at 0,0 XPrint Copy hBMP, id& TO (x,y), style& 'full at x,y XPrint Copy hBMP, id&, (a,b)-(c,d) TO (x,y), style& 'partial hBMP is handle of control, window, or bitmap id& is control identifier assigned CONTROL ADD GRAPHIC id& is 0 for window or bitmap image source Style& Options: %mix_NotMergeSrc - inverse of the MergeSrc color. %mix_NotCopySrc - inverse of the pen color. %mix_MaskSrcNot - colors common to source and inverse-pixel %mix_XorSrc - colors in the source and pixel, but not in both %mix_MaskSrc - colors common to both the source and the pixel. %mix_MergeNotSrc - combination of source and inverse-pixel colors %mix_CopySrc - source color (default) %mix_MergeSrc - combination of source and pixel colors
XPrint Ellipse (x1,y1)-(x2,y2), rgbColor&, fColor&, style& style& options: 0 - solid 1 - horizontal lines 2 - vertical lines 3 - upward diagonal lines 4 - downward diagonal lines 5 - crossed lines 6 - diagonal crossed lines
XPrint FormFeed ' starts new page
XPrint Get Client TO iWidth, iHeight
XPrint Get Collage TO status& ' 0 is false, -1 is true
XPrint Get ColorMode TO mode& ' 1-monochrome 2-color
XPrint Get copies TO count& ' # copies to print
XPrint Get DC TO hDC 'hDC is handle to page devices context
XPrint Get Duplex TO status& ' 0 if duplex unsupported Status Options: n/a 0 duplex printing not supported %DMDUP_SIMPLEX 1 single sided printing %DMDUP_VERTICAL 2 page flipped on vertical edge %DMDUP_HORIZONTAL 3 page flipped on horizontal edge
XPrint Get Lines TO count& 'max can print on one page
Count& differs depending on font size.
XPrint Get Margin TO left!, top!, rite!, bottom! 'margin sizes
XPrint Get Mix TO mode& 'mode& is how to mix color with 'color already at drawing location Mode& Options %mix_Blackness - always 0 (black). %mix_NotMergeSrc - inverse of the MergeSrc color. %mix_MaskNotSrc - colors common to pixel and source-inverse %mix_NotCopySrc - inverse of the pen color. %mix_MaskSrcNot - colors common to source and inverse-pixel %mix_Not - inverse of the pixel color. %mix_XorSrc - colors in the source and pixel, but not in both %mix_NotMaskSrc - inverse of the MaskSrc color. %mix_MaskSrc - colors common to both the source and the pixel. %mix_NotXorSrc - inverse of the XorSrc color. %mix_Nop - unchanged. %mix_MergeNotSrc - combination of source and inverse-pixel colors %mix_CopySrc - source color (default) %mix_MergeSrcNot - combination of source and pixel-inverse colors %mix_MergeSrc - combination of source and pixel colors %mix_Whiteness - always 1 (white).
XPrint Get Orientation = status& ' 1-portrait, 2-landscape
Zero is printer does not support paper orientation.
XPrint Get Paper TO type& '0 if paper styles unsupported Common Paper Types: %DMPAPER_LETTER = 1 Letter 8.5 x 11 inches %DMPAPER_LEGAL = 5 Legal 8.5 x 14 inches %DMPAPER_11X17 = 17 11x17 11 x 17 inches %DMPAPER_A3 = 8 A3 297 x 420 mm %DMPAPER_A4 = 9 A4 210 x 297 mm %DMPAPER_A5 = 11 A5 148 x 210 mm %DMPAPER_B4 = 12 B4 250 x 354 mm %DMPAPER_B5 = 13 B5 182 x 257 mm %DMPAPER_ENV_9 = 19 9 Envlp 3.875 x 8.875 inches %DMPAPER_ENV_10 = 20 10 Envlp 4.125 x 9.5 inches
XPrint Get Papers TO result$ 'CSV list of all available types
Use parsecount$ and parse$() functions to extract specific information from the result string.
XPrint Get Pixel (x,y) TO rgbColor&
If printer does not support the features, -1 is returned.
XPrint Get POS TO x,y 'current values of POS
XPrint Get PPI TO x,y 'always in pixels per inch
XPrint Get Quality TO result& ' 0-not supported, 1-draft, ' 2-low 3-medium 4-high
XPrint Get Scale TO x1,y1,x2,y2
XPrint get Size TO width, height 'full size
XPrint Get Tray TO tray& 'active paper tray Common Paper Tray Values %DMBIN_UPPER = 1 %DMBIN_LOWER = 2 %DMBIN_MIDDLE = 3 %DMBIN_MANUAL = 4 %DMBIN_ENVELOPE = 5 %DMBIN_ENVMANUAL = 6 %DMBIN_AUTO = 7
XPrint Get Trays TO trays& 'CSV string of supported trays
Use parsecount$ and parse$() functions to extract specific information from the result string.
XPrint ImageList (x,y), hList, index&, overlay&, style& hlist - handle to imagelist structure index& - index of image within imagelist overlay& - overlay image style& %ILD_NORMAL - use bgcolor of imagelist %ILD_TRANSPARENT - transparently if there is a mask %ILD_MASK - draw the mask %ILD_BLEND25 - blend 25% with system hilite color %ILD_BLEND50 - blend 50% with system hilite color
XPrint Line (x1,y1)- (x2,y2), rgbColor& XPrint Line STEP (x1,y1)- STEP (x2,y2), rgbColor&
Line drawn up to, but no including, the second point. (x1,y1) are optional - POS will be used. STEP indicates coordinates are relative to POS. rgbColor& is optional, default if foreground color.
XPrint Pie (x1,y1)-(x2,y2), ang1, ang2, lcolor&, fcolor&, fstyle& ang1 - starting angle (radians) ang2 - ending angle (radians) lcolor& - line color fcolor& - fill color fsyle& - fill style
XPrint Polygon points, rgbColor&, fillColor&, style&, fillmode& Fill Styles: 0 - solid 1 - horizontal lines 2 - vertical lines 3 - upward diagonal lines 4 - downward diagnonal lines 5 - crossed lines 6 - diagonal crossed lines Scalar UDT approach: TYPE PolyPoints 'scalar count as long x1 as single y1 as single x2 as single y2 as single x3 as single y3 as single END TYPE Array UDT approach: TYPE PolyPoint 'array x as single y as single END TYPE TYPE PolyArray count as long xy(1 TO 3) as PolyPoint END TYPE
Minimum of 2 vertices, maximum of 1024.
XPrint Polyline points, rgbColor&
For points, use same UDTs options as in XPrint Polygon.
XPrint Render bmpFile$, (x1,y1)-(x2-y2)
bmpFile$ is resource name or file name. Image can be stretched or shrunk. Entire image is used.
XPrint Scale (x1,y1)-(x2,y2) 'defines full page coordinates
XPrint Scale Pixels 'resets coordinates to pixels
XPrint Set Collate status& %DMCOLLATE_FALSE 0 %DMCOLLATE_TRUE 1
Causes error if printer does not support collating.
XPrint Set ColorMode status$ %DMCOLOR_MONOCHROME 1 %DMCOLOR_COLOR 2
XPrint Set Copies count& 'number of copies default=1
Error generated if count is greater than printer supports
XPrint Set Duplex status$ %DMDUP_SIMPLEX 1 single sided printing %DMDUP_VERTICAL 2 page flipped on vertical edge %DMDUP_HORIZONTAL 3 page flipped on horizontal edge
Error generated if printer does not support duplex printing.
XPrint Set Font hFont& 'use font handle from Font New
XPrint Set Mix mode& Mode& Options %mix_Blackness - always 0 (black). %mix_NotMergeSrc - inverse of the MergeSrc color. %mix_MaskNotSrc - colors common to pixel and source-inverse %mix_NotCopySrc - inverse of the pen color. %mix_MaskSrcNot - colors common to source and inverse-pixel %mix_Not - inverse of the pixel color. %mix_XorSrc - colors in the source and pixel, but not in both %mix_NotMaskSrc - inverse of the MaskSrc color. %mix_MaskSrc - colors common to both the source and the pixel. %mix_NotXorSrc - inverse of the XorSrc color. %mix_Nop - unchanged. %mix_MergeNotSrc - combination of source and inverse-pixel colors %mix_CopySrc - source color (default) %mix_MergeSrcNot - combination of source and pixel-inverse colors %mix_MergeSrc - combination of source and pixel colors %mix_Whiteness - always 1 (white).
XPrint Set Orientation status& '1-portrait, 2-landscape
XPrint Set Paper papertype& Common Paper Types: %DMPAPER_LETTER = 1 Letter 8.5 x 11 inches %DMPAPER_LEGAL = 5 Legal 8.5 x 14 inches %DMPAPER_11X17 = 17 11x17 11 x 17 inches %DMPAPER_A3 = 8 A3 297 x 420 mm %DMPAPER_A4 = 9 A4 210 x 297 mm %DMPAPER_A5 = 11 A5 148 x 210 mm %DMPAPER_B4 = 12 B4 250 x 354 mm %DMPAPER_B5 = 13 B5 182 x 257 mm %DMPAPER_ENV_9 = 19 9 Envlp 3.875 x 8.875 inches %DMPAPER_ENV_10 = 20 10 Envlp 4.125 x 9.5 inches
XPrint Pixel STEp (x,y), rgbColor& 'set pixel color at x,y XPrint Set Pixel STEP (x,y), rgbColor&
XPrint Color can set the foreground color, which XPrint Set Pixel uses as a default color.
With STEP, x,y is incremental from POS.
XPrint Set POS (x,y) 'POS is now at x,y XPrint Set POS STEP (x,y) 'POS is now at x,y from prior POS
XPrint Set Quality status& ' 0-not supported, 1-draft, ' 2-low 3-medium 4-high
XPrint Set Tray nTray% Common Paper Tray Values %DMBIN_UPPER = 1 %DMBIN_LOWER = 2 %DMBIN_MIDDLE = 3 %DMBIN_MANUAL = 4 %DMBIN_ENVELOPE = 5 %DMBIN_ENVMANUAL = 6 %DMBIN_AUTO = 7
XPrint Stretch hBMP, id%, (x1,y1)-(x2,y2) TO _ (x3,y3)-(x4-y4), mix, mode Mix Modes: %mix_NotMergeSrc - inverse of the MergeSrc color. %mix_NotCopySrc - inverse of the pen color. %mix_MaskSrcNot - colors common to source and inverse-pixel %mix_XorSrc - colors in the source and pixel, but not in both %mix_MaskSrc - colors common to both the source and the pixel. %mix_MergeNotSrc - combination of source and inverse-pixel colors %mix_CopySrc - source color (default) %mix_MergeSrc - combination of source and pixel colors Stretch Mode Options: %BLACKONWHITE - default. best for monochrome bitmaps (some color) - boolean OR of eliminated and existing pixels - preserves black pixels at expense of white pixels %WHITEONBLACK - boolean OR of eliminated and existing pixels - preserves white pixels at expense of black pixels %COLORONCOLOR - deletes eliminated lines of pixels %HALFTONE - highest quality for color bitmaps - pixel block average color kept ~ the same
Copy all or a portion of an image. Use handle of control, window, or bitmap structure.
XPrint STYLE style& ' 0-solid, 1-dash, 2-dot, 3-dashdot
XPrint TEXT SIZE text$ TO width!, height!
XPrint WIDTH n& ' drawing width of lines
devicename$ = XPrint$ ' returns name of attached printer
If you have any suggestions or corrections, please let me know.