[futurebasic] Re: [FB] OS X printing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2002 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sun, 22 Dec 2002 22:04:30 +1300
On Sunday, December 22, 2002, at 12:55  AM, Douglas Stemen wrote:

> RP,
>
> Several months ago you gave me the code listed below to change the 
> page print orientation within the program.
>
> It works great except that when use prHndl&=PRHANDLE and then 
> pagewidth=prHndl&..prInfo.rpage.right% to get the width of the page 
> for printing (after setting the page orientation).
>
> The PRHANDLE function does not not return the page width and height 
> that corresponds with the orientation I set. Of course, PRHANDLE does 
> return the correct page width if DEF PAGE is used.
>
> Do you know how I can get PRHANDLE to read the correct page dimensions 
> that are set with  FN PMSetOrientation ?

The demo below, tested in OS X 10.2.2, seems to do what you want.

'---------------
'~'A
'                           CPU : Carbon
'~'B
_kPMPortrait  = 1
_kPMLandscape = 2
toolbox fn PMSetOrientation( PMPageFormat pageFormat, ¬
                 UInt16 orientation, Boolean lock ) = OSStatus


local fn GetAdjustedPageRect( r as ^Rect )
'~'1
dim as PMRect    pmPageRect
dim as OSStatus  err
dim as Boolean @ result
// force update of current orientation, scale, etc
err = fn PMSessionValidatePageFormat( gFBPrintSession, ¬
           gFBPageFormat, result )
// get the PMRect
err = fn PMGetAdjustedPageRect( gFBPageFormat, pmPageRect )
// convert PMRect to Rect
r.left   = pmPageRect.left
r.top    = pmPageRect.top
r.right  = pmPageRect.right
r.bottom = pmPageRect.bottom
end fn



dim as Rect      r
dim as Handle    myPRHandle
dim as OSStatus  err

myPRHandle = prHandle
print "Default page rect"
print myPRHandle..prInfo.rPage.left%  myPRHandle..prInfo.rPage.top%;
print myPRHandle..prInfo.rPage.right% myPRHandle..prInfo.rPage.bottom%

// set landscape orientation
err   = fn PMSetOrientation( gFBPageFormat, _kPMLandscape, _false )
if err then stop "PMSetOrientation error " + str$( err )
fn GetAdjustedPageRect( r )
// fix the PRHandle to contain the new adjusted page rect
BlockMove @r, @gFBPRHandle&..prInfo.rPage`, sizeof( Rect )


print "After setting landscape orientation"
print myPRHandle..prInfo.rPage.left%  myPRHandle..prInfo.rPage.top%;
print myPRHandle..prInfo.rPage.right% myPRHandle..prInfo.rPage.bottom%

do
HandleEvents
until 0
'---------------

Robert P.