revPrintText Answers
Rob Cozens
rcozens at pon.net
Thu May 30 13:29:01 EDT 2002
Hi All,
Here's my solution:
on printTable
theTable,theHeader,theFontSize,theLineLength,extraMargin,addedSpaceWidth,addedSpaceLocations
if theLineLength < 1 then put offset(return,theTable)-1 into theLineLength
if extraMargin is empty then put 36 into extraMargin else add 36 to
extraMargin
set cursor to watch
push card
lock screen
lock messages
go to card 1 of stack "Serendipity Library.rev"
if addedSpaceWidth is not empty then put justifyString("
",addedSpaceWidth) into theSpacer
put empty into newTable
repeat for each line tableLine in theTable
put char 1 to theLineLength of tableLine into tableLine
if addedSpaceWidth > 0 then
repeat with x = the number of lines of addedSpaceLocations down to 1
put theSpacer after char (line x of addedSpaceLocations) of tableLine
end repeat
end if
put tableLine&return after newTable
end repeat
put newTable into field "Text Formatter"
set the textFont of char 1 to -1 of field "Text Formatter" to "Courier New"
set the textSize of char 1 to -1 of field "Text Formatter" to theFontSize
put theHeader into field "Header Formatter"
set the textFont of char 1 to -1 of field "Header Formatter" to "Courier New"
set the textSize of char 1 to -1 of field "Header Formatter" to theFontSize
set the textStyle of char 1 to -1 of field "Header Formatter" to bold
put "<%pagenumber%>" into field "Footer Formatter"
set the textFont of char 1 to -1 of field "Footer Formatter" to "Courier New"
set the textSize of char 1 to -1 of field "Footer Formatter" to theFontSize
put the short date into field "Date Formatter"
set the textFont of char 1 to -1 of field "Date Formatter" to "Courier New"
set the textSize of char 1 to -1 of field "Date Formatter" to theFontSize
set the printMargins to extraMargin,108,extraMargin,36
revShowPrintDialog true,true
revPrintText (the htmlText of field "Text Formatter"),(the htmlText
of field "Date Formatter")&tab&(the htmlText of field "Header
Formatter"),tab&(the htmlText of field "Footer Formatter")
put empty into field "Text Formatter"
put empty into field "Header Formatter"
put empty into field "Footer Formatter"
put empty into field "Date Formatter"
pop card
unlock messages
unlock screen
set cursor to hand
end printTable
The resulting output meets my needs; so that's how it will appear
when my library is released. Maybe someday in my old age I'll
rewrite it to calculate the proper printMargins instead of forcing
the user to pass it.
Notes:
* I'm dealing with the "early cutoff" of lines at the bottom of the
page by setting a bigger top printMargin so the text is centered. I
hope someday revPrintText will do a better job of setting the bottom
of the text close to the top of the footer
* Since all lines of a table are the same length and the tables are
printed in a monoproportional font, I can center the table by
adjusting the left printMargin (and the right printMargin as well to
keep header & page #s centered).
* I tried putting the date in the same field with the header; but
that did not produce the correct output when the header had multiple
lines.
* At least 30% of this handler could be eliminated if I could find a
way to set the font & size Transcript uses when printing plain text.
I tried changing the stack's default text; but the revPrintText
output didn't change.
* If revPrintField allowed one to specify a header & footer al la
revPrintText, that would be a much easier way to go.
Special thanks to Jan Decroos for private suggestions & examples.
--
Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.com/who.htm
"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."
from "The Triple Foole" by John Donne (1572-1631)
More information about the use-livecode
mailing list