[futurebasic] Re: Printing HTML Files

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

From: "David A. Bailey" <dabs@...>
Date: Tue, 7 Dec 2004 11:30:23 -0800 (PST)
I have created this local function to print html files and it does so
fairly well.  The problem comes in a program that once you have printed
and then returned to the program and then built a new window to display an
html object the first call to  FN HRISHREVENT(event)  crashes the program.
This call is supposed to be in your event loop to hande html features and
cannot be avoided.  No problem with this call prior to printing only
after.

Here is the print routine.  You need to pass a file name and the reference
number for a folder in which it resides for it to function.  Any help with
where I might be doing something wrong would be appreciated.


LOCAL mode
dim err,n,tvert,PageHt,freMem&
dim @mp,mp2    as point
DIM renderrect as rect
dim spec       as fsspec
dim @Port      as ^CGrafPort
DIM @gPort     as ^CGrafPort
dim rgn        as rgnHandle
dim @HrRef     as HRReference
'~'2
LOCAL FN PrintHtml(FileName$,helpVRef)
'~'2
'A lot more error testing can be done but adding simple beeps shows no
problems with the toolbox calls

getport(gPort)'get the port data
err = fn FBmakefsspec(helpVRef,0,FileName$,spec)'make a file spec for the
file in the folder passed in helpVRef
renderRect;8 = [PRHANDLE] + _prInfo + _rPage'calculate the rendering
rectangle of the current page setup
InsetRect(renderRect,3,3)'inset the area 3 pixels for more margin
PageHt = renderRect.bottom'calculate the page height
tvert = 0'grenderRect.bottom'this is where the bottom starts for the first
page

err = fn HRNewReference(@HRref,_kHRRendererHTML32Type,gPort)'create a new
HR reference
err = fn HRForceQuickdraw(HRref,_true)'force quick draw drawing for this
port due to some printers
err = fn HRSetdrawborder(HRref,_false)'turn off drawing borders
err = FN HRSetScrollbarState(HRref,1,1)'we dont want scroll bars
err = FN HRSetRenderingRect(HRref,renderRect)'set the html render
rectangle to this size
err = fn HRGoToFile(HRref,#spec,_false,_false)'go to the file but no
history and no forced refresh
err = FN HRGetRenderedImageSize(HRref,mp)'now calculate the MAXIMUM
verticle size needed to render this file
mp2.h% = 0'mp2 is a point tracking the bottom left corner of the rendering

while tvert <= mp.v%'as long as the total verticle is less than the total
needed
Route _toPrinter'tell the system to route to the printer
getport(Port)'determine the printer port
'n needs to be refined to determine offset of last line
if tvert = 0 then n = 0 else n = 30'if this is the first page no scroll is
needed
mp2.v% = tvert - n'otherwise calculate the total verticle scroll
err = FN HRScrollToLocation (HRref,mp2)'set the scroll bar to the bottom
of the previous page minus the offset

rgn = fn NewRgn'create a new empty region
long if( rgn )
RectRgn(rgn,renderRect)'create a region from the rendering rectangle
err = fn HRDrawInPort(HRref,rgn,Port)'draw the reference using the region
and printer port
DisposeRgn(rgn)'dispose of the region
end if

tvert = tvert + PageHt'add a page height to the total verticle
long if tvert >= mp.v%'did we get the last page??
err = fn HRDeactivate(HRref)'deactivate global ref
err = fn HRDisposeReference(HRref)'dispose of global ref
END if
clear lprint'clear the lprint for this page
wend

route _toscreen'route back to screen
close lprint'immediately close the printing

err  = fn HRDeactivate(HRref)'deactivate global ref
err  = fn HRDisposeReference(HRref)'dispose of global ref
END FN


Thanks
David