=Another Look at Hard Copy Printing= //[[user: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. [[toc]] ---- ==LPRINT Limitations== LPRINT is for wimps. It’s old fashioned and included for backwards compatibility. It isn't how printing should be accomplished in a GUI environment.//[[user:RodBird]][[toc]]// Now don’t misunderstand, LPRINTThis article is useful and combined with DUMP it lets you mimic old style teletype printing inabout filling the mainwin environment, but it has limitations. You can’t mix text and graphics, you can only LPRINT one font style and colour. It is great for program listing, printing lineprinted page, either by line program input and outputscaling up low resolution graphics or perhaps combining TABscaling down high resolution graphics. We will use a graphicbox control and fixed width fonts for structured, printed tables.the graphics command: However, for anything really fancy, you need to use a graphics control, either a graphics window or a graphicbox.#win.graphicbox "print size" ==A Better Way== So, leave behind the teletype. In so doing you need to imagine another canvas. Right now you probably imagine the screen, or the graphics control you see on that screen, as a canvas. When you think about printing, youYou will have a second canvas available, it isbetter understanding of the printed paper. Both of these canvases exist side by side“size” argument after reading this and each has their own resolution.you will be amazed at what Liberty BASIC can achieve. By that I mean the graphics control will have a===The screen pixel width and the printer will have a printed pixel width. A screen might have anything between 800 to 1920 pixels width wise, a printer may have 1984 printed pixels.view=== ==Scale== AlwaysOn screen the displayed imagegraphicbox control is scaled toour view of the printed image.drawing. I have used a small graphicbox, you can 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 printing graphics far larger than can be viewed, even full screen. What scale?Now, looking through the graphicbox imagine you see a drawing canvas and behind that a printing canvas. Each has their own 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. So how do we control this scaling? Since the printed resolution is not tied to the screen resolution we can choose. #win.graphicbox "print"===The drawing canvas=== Liberty BASIC 4.04 allowsThe drawing canvas that sits behind the programmer to specify how the current screen graphics willgraphicbox can be scaledas large as you want. We do not need to the printed page. The choices are • none • VGA • SVGA • XGA • Custom Pixel Width (expressed as a number) We can print raw pixels simply by issuing a print command with nodefine its 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 wideit will in effect filladopt the widthsize of the printed page, pixel perfect. ==Changing the Resolution== We can print scaled pixels by specifying a size. What Liberty BASIC will dodrawing. Its resolution 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.in screen pixels. [[code format="lb"]] #win.graphicbox "print 900" [[code]]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. ==Draw===The printing canvas=== The printing canvas is defined by your paper size and Print morethe 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 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 of the size, placement and resolution of the printed output! ===Size=== Liberty BASIC 4.04 allows the programmer to specify the size in a number of ways, the choices are • none - size will adopt your current screen 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 • 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 can see== will use less. [[toc]] 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 #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 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.[quit] close #1 end 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.==<span style="font-family: Times New Roman;"> </span>== ==<span style="color: black; line-height: normal; margin: 0cm 0cm 0pt;"> </span>== ==<span style="font-family: Times New Roman;"> </span>==