Another Look at Hard Copy Printing

- RodBird RodBird This is very much work in progress, I will update the text over the next month or so. You may discern that Liberty has a lot more printing prowess than perhaps we realise. I hope to tease that out.

This article is about filling the printed page, either by scaling up low resolution graphics or scaling down high resolution graphics. We will use a graphicbox control and the graphics command:

#win.graphicbox "print size"

You will have a better understanding of the “size” argument after reading this and you will be amazed at what Liberty BASIC can achieve.

The screen view


On screen the graphicbox control is our view of the drawing. I have used a small graphicbox, you can see LPRINT Limitations LPRINT is for wimps. It’s old fashioned and included for backwards compatibility. It isn't how printing should set the size to whatever suits your application, with or without scrollbars. The reason I have chosen a small graphicbox is that we will be accomplished in a GUI environment. Now don’t misunderstand, LPRINT is useful and combined with DUMP it lets you mimic old style teletype printing in the mainwin environment, but it has limitations. You can’t mix text and graphics, you printing graphics far larger than can only LPRINT one font style and colour. It is great for program listing, printing line by line program input and output or perhaps combining TAB and fixed width fonts for structured, printed tables. However, for anything really fancy, you need to use a graphics control, either a graphics window or a graphicbox. A Better Way So, leave behind the teletype. In so doing you need to be viewed, even full screen.

Now, looking through the graphicbox imagine another canvas. Right now you probably imagine the screen, or the graphics control you see on a drawing canvas and behind that screen, as a a printing canvas. When you think about printing, you have a second canvas available, it is the printed paper. Both of these canvases exist side by side and each Each has their own resolution. By size and resolution and both are bigger than the graphicbox. You will draw in one resolution and print in another, “size” will handle the transformation.

The drawing canvas


The drawing canvas that sits behind the graphicbox can be as large as you want. We do not need to define its size it will adopt the size of the drawing. Its resolution is in screen pixels.

Drawing commands will color visible pixels within the graphicbox, outside of those limits drawing is not visible but nevertheless Liberty draws and stores the graphics on the drawing canvas. You may scroll them into view if you switch on graphicbox scrollbars. You may also print the unseen graphics.

The printing canvas


The printing canvas is defined by your paper size and the printing resolution, in Dots Per Inch (DPI), of your printer. We cannot equate pixels with dots easily, the printer will use many dots to create the image of a single pixel, how many, is actually defined by the “size” parameter. The numbers below are based on experimentation.

My typical printer, using A4 paper and printing at 600 DPI is proven to have the capability of printing c5000 pixels across the printed page and c7000 pixels down the printed page in portrait mode. It is capable of higher resolution, especially if I mean the graphics set it to print at 1200 DPI.

Fortunately we don’t need to know the exact limits because the “size” parameter handles the transformation. For example printing 5000 pixels across the page produces a legible “Hello” 1mm wide that requires a magnifying glass to read. 7000 pixels produces a “Hello” that requires a microscope.

Scaling


The drawn pixel is being printed to the paper using a variable number of dots to represent the single pixel image.

Taking the imaginary printing canvas we define how many pixels will be printed width wise by setting the “size” parameter. That sets the number of dots that are applied to each printed pixel. Let’s assume the printer is capable of printing c5000 dots across an A4 page.

If we set “size” to 640 then 8 dots are used per pixel and a 640 pixel drawing will fill the page.
If we set “size” to 1024 then 5 dots are used per pixel and a 1024 pixel drawing will fill the page.
If we set “size” to 5000 then 1 dot is used per pixel and a 5000 pixel drawing will fill the page.

If the drawn image is smaller than “size” it will fill part of the printed page, if it is larger than “size” it will exceed the printed page. So with one simple “size” parameter we are in complete control will have a screen pixel width and the printer will have a of the size, placement and resolution of the printed pixel width. A screen might have anything between 800 to 1920 pixels width wise, a printer may have 1984 printed pixels. Scale Always the displayed image is scaled to the printed image. What scale? So how do we control this scaling? Since the printed resolution is not tied to the screen resolution we can choose. #win.graphicbox "print" output!

Size


Liberty BASIC 4.04 allows the programmer to specify how the the size in a number of ways, the choices are
• none - size will adopt your current screen graphics will be scaled to the printed page. The choices are • none width value in pixels
• VGA - size will be set to 640
• SVGA - size will be set to 800
• XGA - size will be set to 1024
Custom Pixel Width (expressed n - size will be set to n

Code sample


This simple example takes your printer up to a pretty high resolution. It should print pixel perfect graphics on an A4 sheet using a size of 4960. You will be able to beat this but there must be few applications that will need such high resolution printing. Typically you will use less.

ImageWidth = 4958
ImageHeight = 7015
midW=int(ImageWidth/2)
midH=int(ImageHeight/2)
nomainwin
WindowWidth = 400
WindowHeight = 400
UpperLeftX = (DisplayWidth-WindowWidth)/2
UpperLeftY = (DisplayHeight-WindowHeight)/2
graphicbox #1.g, 50,50,300,300
open "Graphics Printing" for window_nf as a number) We can print raw pixels simply by issuing a print command with no size specification. This allows the highest resolution of the printer to be shown. If we draw a few pixels we print a few (tiny) pixels. If we draw many pixels we see more, drawing 1984 pixels wide will in effect fill the width of the printed page, pixel perfect. Changing the Resolution #1
print #1, "trapclose [quit]"
print #1.g, "down ; place 0 0; color black ; box ";ImageWidth;" ";ImageHeight
print #1.g, "place ";midW;" ";midH
print #1.g, "circle ";midW
print #1.g, "place ";midW;" ";midH
print #1.g, "circle ";midH
print #1.g, "place ";midW;" ";midH
print #1.g, "\Hello"
print #1.g, "flush"
print #1.g, "print 4960"
wait

[quit]
close #1
end

We can print scaled pixels by specifying a size. What Liberty BASIC will do is take the width of the printed page (1984 pixels) and spread the specified display pixel SIZE across printed page. • VGA 640 • SVGA 800 • XGA 1024 Alternatively you can specify the number of pixels that will fill the printed page width by specifying a pixel size. #win.graphicbox "print 900" Draw and Print more than you can see

A graphicbox or graphic window control is actually a viewport on a large canvas. You may draw widely on that canvas and see only a portion of it in the graphics control. You may scroll that view. From a printing perspective the whole of the canvas is in view. Even from a tiny 400x300 graphics viewport you may draw and print full width graphics that fill the printed page.