Printing and previewing
Scott Morrow
scott at elementarysoftware.com
Sat Mar 3 16:58:28 EST 2007
Graham,
I tackled this task a while back. Here is an outline of my
approach:
First, I use a separate "printing stack" for laying out the text,
adding page numbers, headers etc. I took the block of text I wanted
to print (unknown size) and broke it up into page size chunks,
placing text into a field on the "printing stack" and creating a new
card in the "printing stack" for each new page-sized chunk of text
until all the original text had been placed into the "printing
stack". Techniques for doing this have been discussed on this list
more than once. (I've included a script scrap below which was
developed from advice offered here.)
Once you have a mechanism for knowing where the page breaks occur,
this same routine can be used for putting text into a series of
fields inside a scrolling "preview" group that the user can examine.
I still use the "printing stack" with format for printing to
determine each page break and then copy the text off of each card and
place it into a normally formatted (and visible to the user) stack,
each card of the "printing stack" going into a separate "page-o-text"
field. I put a field that displays the page number in between each
"page-o-text" field. If this is all in a scrolling group then the
user can scroll through and see the number of pages and exactly where
each page break will occur.
HTH
-Scott Morrow
Elementary Software
(Now with 20% less chalk dust !)
web http://elementarysoftware.com/
email scott at elementarysoftware.com
---------------- script scrap for breaking a text block into page
sized chunks --------------------
-- assumes a stack "PrintComments" with a field "bigComment" (sized
appropriately)
-- assumes a source field "bigComment" of a source stack
<lPrintJobStackName> ... so that the htmlText can be used
-- watch for line wraps --
-- copy the styled text off the report field into the field of a
specially formatted substack, "PrintComments"
set the htmlText of fld "bigComment" of cd 1 to tMySourceText --
the htmlText of fld "bigComment" of cd pThisStudent of stack
lPrintJobStackName
-- the text needs to be broken into page size chunks
put 1 into tCardCounter
put the number of chars of fld "bigComment" of cd tCardCounter
into tNumOfChars
put the formattedHeight of char 1 to tNumOfChars of fld
"bigComment" of cd tCardCounter into tCharHeight
put (the height of fld "bigComment" of cd tCardCounter) into
tFieldHeight
REPEAT until tFieldHeight >= tCharHeight
put the number of chars of fld "bigComment" of cd tCardCounter
of stack "PrintComments" into tNumOfChars
put the formattedHeight of char 1 to tNumOfChars of fld
"bigComment" of cd tCardCounter of stack "PrintComments" into
tCharHeight
-- remove extra characters and put the remaining into a new
field on a new card
REPEAT with c = 1 to tNumOfChars
IF the formattedHeight of char 1 to c of fld "bigComment" of
cd tCardCounter of stack "PrintComments" >= tFieldHeight - 24 THEN
-- 24 is wiggle room
put the htmlText of char c to -1 of fld "bigComment" of cd
tCardCounter of stack "PrintComments" into tHtmlText
delete char c to -1 of fld "bigComment" of cd tCardCounter
of stack "PrintComments"
clone cd tCardCounter of stack "PrintComments"
put tCardCounter + 1 into tCardCounter
set the htmlText of fld "bigComment" of cd tCardCounter of
stack "PrintComments" to tHtmlText -- put the text that didn't fit,
into the new field
put "page" && tCardCounter into fld "footer" of cd
tCardCounter of stack "PrintComments" -- update the page number
exit REPEAT
END IF
END REPEAT -- remove extra characters and put the remaining into
a new field
END REPEAT -- text in the last field fits
set the formatForPrinting of stack "PrintComments" to true
close stack "PrintComments"
set the loc of stack "PrintComments" to -9999,-9999
set the vis of stack "PrintComments" to false
go cd 1 of stack "PrintComments"
print stack "PrintComments"
-- delete any extra cards in the "PrintComments" stack
-- and generally clean up
put the num of cds of stack "PrintComments" into tCardsToDelete
REPEAT with x = tCardsToDelete down to 2
delete cd x of stack "PrintComments"
END REPEAT
-----------------------------------------------------------------
On Mar 3, 2007, at 2:33 AM, Graham Samuel wrote:
> Folks, I'm faced with the problem of providing a printing routine
> to print one or more pages of text (the number of pages is not
> known in advance) on a PC, and also being able to offer an on-
> screen preview facility. Logically, I want the user to press a
> 'Print' button and get a printout, or a 'Preview' button and get a
> preview of the page(s) **exactly as they will appear on the
> physical printout**; this second mode would also allow the user to
> go on to print. I might relax on the "exactly" if I could ensure
> that the same amount of text appeared both on the preview and the
> printout, and the line breaks came in the same places: but it's
> second best really if the type doesn't look the same in both cases.
>
> With the aid of Dan Shafer's e-book on Printing in Revolution
> (thanks, Dan), I think I understand the issue revolving around the
> formatForPrinting property, in that I have to set up my printing
> stack with this property set to true and somehow create the fields
> with the text in - one card per page - without editing them (this
> seems something of a contradiction, but I'm experimenting...):
> however it appears to me that if I show these cards as previews, I
> will get an anomalous result, because the fonts the Rev system uses
> will not be ones intended for screen display, and therefore (we are
> warned) will look 'wrong'. If I do use the ones intended for screen
> display, I run into the danger that they won't look like the
> printout, and might even end up with different numbers of lines per
> page.
>
> Would anyone who has already tackled this be prepared to share
> their approach?
>
> TIA
>
> Graham
>
> PS It's a helluva lot easier on a Mac, where Preview is built in to
> the OS and fonts are WYSIWYG anyway. But my customers have PCs.
>
>
>
> ----------------------------------------
> Graham Samuel / The Living Fossil Co. / UK and France
More information about the use-livecode
mailing list