1. Printing in Windows

To all,

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

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

TIA

Jonas

new topic     » topic index » view message » categorize

2. Re: Printing in Windows

Hi Jonas,
when printing in Windows you have to do all the positioning yourself.

To ensure that words begin on a new line, you must always measure the size
of the text you intend to fit on the line and if it doesn't fit, reduce it
by one word and try again until it does fit.
Then you can "print" the line. You must give X and Y positions before each
print instruction to make sure you are positioned correctly.

You can think of printing in windows as having a page and placing characters
anywhere on any "pixel" address, and when the page is complete, issuing an
"end-page" command. Then you can start the next page.

Its very messy and prone to easy mistakes, particularly when using multiple
fonts etc...

This is all theory, 'cos I haven't tried with Win32lib yet, just VB and C.

------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

----- Original Message -----
From: "Jonas Temple" <jktemple at yhti.net>
To: "EUforum" <EUforum at topica.com>
Sent: Wednesday, March 14, 2001 12:58 AM
Subject: Printing in Windows


>
>
> To all,
>
> I wondered if anyone has tried-and-true routines to print text in
> Windows using the Win32Lib routines for printing?  I am looking
> specifically for:
>
> - Ways to handle word wrapping
> - How to detect when data should flow onto a new page (my program could
> print multiple pages)
>
> TIA
>
> Jonas
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Printing in Windows

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 message » categorize

4. Re: Printing in Windows

On 13 Mar 2001, at 7:19, Derek Parnell wrote:

> 
> 
> Hi Jonas,
> when printing in Windows you have to do all the positioning yourself.
> 
> To ensure that words begin on a new line, you must always measure the size
> of the text you intend to fit on the line and if it doesn't fit, reduce it
> by one word and try again until it does fit.
> Then you can "print" the line. You must give X and Y positions before each
> print instruction to make sure you are positioned correctly.
> 
> You can think of printing in windows as having a page and placing characters
> anywhere on any "pixel" address, and when the page is complete, issuing an
> "end-page" command. Then you can start the next page.
> 
> Its very messy and prone to easy mistakes, particularly when using multiple
> fonts etc...
> 
> This is all theory, 'cos I haven't tried with Win32lib yet, just VB and C.

I did just that on the C64 around 1990. I also changed fonts (adding a pixel
here or
there) to some words, to make the page do both left- and right-aligning. It's
do-able,
but on the C64 it could take an hour or more to do 15 pages.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Printing in Windows

On Tue, 13 Mar 2001 07:19:40 -0800, Derek Parnell wrote:

> To ensure that words begin on a new line, you must always measure the size
> of the text you intend to fit on the line and if it doesn't fit, reduce it
> by one word and try again until it does fit.
> Then you can "print" the line. You must give X and Y positions before each
> print instruction to make sure you are positioned correctly.

As I've mentioned on many occasions, the DrawText() function would do
most of this automatically, for both fixed and var fonts... sigh.
A complete page or paragraph in one shot.


-- Arachne V1.66, NON-COMMERCIAL copy, http://arachne.cz/

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu