print screens example handler (Rev 1.1.1)

Alex Rice alrice at ARCplanning.com
Tue Mar 4 10:19:01 EST 2003


On Monday, March 3, 2003, at 10:30  PM, Chipp Walters wrote:

> Alex,
>
> That's great! Perhaps you can jot down some notes on a website. Or, if 
> you
> like, you can email your notes to this list and I'll copy them and 
> post them
> on my RunRev site -- perhaps Ken will do the same.
>
> Looking forward to hearing more;-)

OK... here's my shpeel.

I found that simply doing "print this stack" in Revolution would print 
stuff, but usually not what one wants to see. In my app the user fills 
in answers on a bunch of screens, and on the last screen there is a 
Print Screens button. So I'm printing the screens current stack.

My requirements were- it should look nice, images and button icons 
should render properly, the print job should use printer fonts 
(formatForPrinting that is). The print job should respect user's 
selection for paper size, orientation and scaling.

I found that these requirements cannot be achieved by actually printing 
the on-screen stack the user is looking at. There are several reasons 
for this:

1- the formatForPrinting property only takes effect after re-opening 
the stack.
2- "lock screen" causes some printing artifacts with icons.
3- Without "lock screen", the stack will be flashing from card to card, 
opening/closing and generally confusing the user.

So, just bite the bullet and create a new stack for doing the print 
screens from. Like everything else in transcript, it's less code than 
you would think. Here is the handler I am using at this point:

--
-- nicePrintScreens handler
--
-- prints selected cards from a stack
-- works with graphics and button icons
-- uses printer fonts if available
-- scales to user's zoom and orientation selections
-- appears to work nicely on WinXP, 2000 and Mac OS X.
-- todo: error handling on stack save/open commands
--
on nicePrintScreens
   set the cursor to watch
   --
   -- create a new stack for performing print screens layout
   --
   lock messages
   new invisible stack "PrintScreens"
   -- don't keep stack in memory after we are done with it
   set the destroyStack of stack "PrintScreens" to true
   -- don't use printer fonts- yet.
   set the formatForPrinting of stack "PrintScreens" to false
   -- dont bother buffering since we are not actually displaying this 
stack on screen
   set the alwaysBuffer of stack "PrintScreens" to false
   -- make it our size
   set the width of stack "PrintScreens" to the width of this stack
   set the height of stack "PrintScreens" to the height of this stack
   -- copy selected cards
   repeat with tCardNumber = 1 to the number of cards in this stack
     -- here you could test the card to see if it's supposed to be 
printed
     put "true" into tActive
     if tActive then
       copy card tCardNumber of this stack to stack "PrintScreens"
     end if
   end repeat
   -- get rid of the first card in the stack
   -- it is blank and was put there when the stack was created.
   delete card 1 of stack "PrintScreens"
   -- yes, use printer fonts
   set the formatForPrinting of stack "PrintScreens" to true
   -- save out to file
   save stack "PrintScreens" as "printScreens.rev"
   close stack "printScreens.rev"
   -- re-open it to get the printer fonts to take effect
   go stack "printScreens.rev"
   --
   -- perform the print job
   --
   -- standard print dialog on Windows, page setup dialog on OS X.
   answer printer
   if the result = "Cancel" then
     beep
     exit nicePrintScreens
   end if
   -- the user's response for zoom and orientation is set into
   -- the printPaperSize
   put item 1 of the printPaperSize into tImgWidth
   put item 2 of the printPaperSize into tImgHeight
   put item 1 of the printMargins into tLeftMargin
   put item 3 of the printMargins into tRightMargin
   -- determine the scaling to fit the long sides
   -- of the print image and the card
   -- this was coded for a stack of 760x540 and it assumes that
   -- the stack is wider than it is tall.
   put the width of this stack into tMyWidth
   -- subtract the margins off the printable width
   put tImgWidth - tLeftMargin - tRightMargin into tImgWidth
   -- scale, if necessary
   -- note, this is scaling from Revolutions point of view.
   -- the user's zoom setting has already been translated into 
printPaperSize
   if tMyWidth > tImgWidth then
     put tImgWidth / tMyWidth into tScale
     set the printScale to tScale
   end if
   -- nice borders
   set the printCardBorders to true
   -- show the macos print dialog, if necessary
   if the platform  = "MacOS" then
     open printing with dialog
     if the result = "Cancel" then
       beep
       exit nicePrintScreens
     end if
   else
     open printing
   end if
   print stack "PrintScreens"
   close printing
   close stack "PrintScreens"
end nicePrintScreens



Alex Rice, Software Developer
Architectural Research Consultants, Inc.
alrice at ARCplanning.com
alrice at swcp.com






More information about the use-livecode mailing list