Re: Printing in Windows

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jonas Temple wrote:

> I wondered if anyone has tried-and-true routines
> to print text in Windows using the Win32Lib routines
> for printing?

The Generic demo has printing routines that you can use.

> - Ways to handle word wrapping

> - How to detect when data should flow onto a new
> page (my program could print multiple pages)

The Generic demo handles multiple pages. The main loop is in printDoc, which
prints a page until it's out of data:

    -- until end of document or error
    while length( doc ) != 0
    and   not printErr do
        -- send document to printer; returns unprinted amount
        doc = printPage( doc )
    end while

The routine printPage prints up to one page worth of data. It gets the
height of the font:

    -- get the attributes of font
    result = getFontSize( Printer )
    fontY = result[2]

and the prints until it runs out of room or data, whichever comes first:

    while True do
        -- out of text?
        if length( doc ) = 0 then
            exit
        end if

        -- out of space?
        if y + fontY > pageY then
            exit
        end if

        -- print on page
        setPenPosition( Printer, 0, y )
        wPuts( Printer, doc[1] )

        -- remove line from document
        doc = doc[2..length( doc )]

        -- move down a line
        y += fontY

    end while

Your code would be a bit more complicated, since it would need to measure
the length of the text as well. You can get the size of the page by calling:

    result = getCtlSize( Printer )
    pageX = result[1]
    pageY = result[2]

You can get the size of any chunk of text by calling:

    result = getTextExtent( Printer, <text> )

I hope this helps!

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu