HTML Rendering
Volume Number: 16
Issue Number: 8
Column Tag: Programming
HTML Rendering with FutureBASIC^3
By Chris Stasny
How to write a simple HTML Browser with
FutureBASIC^3
East Meets South
We had been dealing with our Japanese distributors for about six years when their
head honcho asked for a face-to-face. It's true that Thelma and I enjoy a life of bliss in
our double wide, but I wasn't sure how these foreigners would take to a genuine
Mississippi abode. They would have to circumnavigate several junk cars to reach the
front door. They would have to sleep with ol' Blue and a half dozen of his flea-bitten
companions who hold the existing claim to our guest bed. After a brief emailed
discussion of accommodations, we decided to meet in a neutral country: California.
There was a second introduction stacked in the Tarot cards, but this one was binary. I
was prodded into action when I discovered that the in-box had been overrun with
requests for some method of displaying HTML code. And both of those emails were
strongly worded! It was time for... Drum roll... Use deep voice... "FutureBASIC meets
the HTML Renderer.
The first step was to locate documentation of the new manager. Apple's only
documentation seems to be a terse little reference called HTML_RenderingLib.pdf. A
quick search of the hard drive turned up another necessary component. It is an
extension called HTMLRenderingLib, which seems to work well in both Systems 8.x
and 9. It took me more than an hour to locate the carbon library on a monthly SDK CD
that contained information on the constants and toolboxes. Another few minutes were
required for converting the code from C to FB^3. These converted toolbox calls are now
placed in a file named Tlbx HTML Rendering.Incl and can be found at stazsoftware.com,
on the Release 3 CD, or with electronic versions of this publication. The routines are
accessed by your program with the following line of code:
INCLUDE "Tlbx HTML Rendering.Incl
When Cultures Collide
The whole thing about meeting those foreigners had me on pins and needles. My first
faux pas came when they introduced themselves and handed me business cards. They do
this by holding the card in both hands and bowing slightly when it is presented. I could
tell right off that this was a big deal and I was anxious not to appear uncouth. (These
guys were really couth.) I hastily extracted a card from my wallet and smoothed it out
against my jeans. (This had the added benefit of wiping away some dirt and a few
non-descript chicken parts that had adhered to the card.) I scratched out Bubba's
Seafood and Shoe Repair, then carefully printed my name. I bowed and presented it to
that foreign guy. Please note here that things did not work out exactly as I had
envisioned. I am loath to admit it, but I believe that a recently consumed six pack of
Bud may have been responsible for my falling against him and knocking down the
entire Japanese contingent like a row of carefully placed dominoes.
The thought of working with the new HTML Rendering library had me on edge too. I
soon discovered that a few simple toolbox calls would do the work for me. To simplify
this example program, I decided to use the FutureBASIC II runtime (one of the many
runtimes available under the Command menu). This allowed me to prune window,
menu, and event handling so that the example could concentrate on the concepts of
HTML rendering. The entire code set (sans remarks and white space) is just over 100
lines. It was written to work with almost any preference setting, but you will need to
uncheck Toolboxes require "CALL" in the preferences window and make sure that you
compile in PPC. (This particular set of routines does not include 68K inline code.) The
program operates from a single window and contains a small set of globals.
BEGIN GLOBALS
DIM AS LONG gHRref // heavily used HR reference
DIM AS LONG @gPort& // "@" means don't use register
DIM gResizeFlag // bool: window will be resized
DIM gQuit // flag says it's time
to terminate
END GLOBALS
Program brevity may be contributed to the fact that we use only one window. Its
pointer is held in gPort&. For non-FBers: You don't have to type class variables in
FutureBASIC, though you can if you desire. There is no necessity for setting separate
variables for a grafport and a window pointer, as they are (in System 9 and earlier)
the same address. Another obvious difference from other languages is that a local
function does not have to return a result. Even if it does return something, the caller
does not have to accept the result. This makes for a bulletproof environment.
Almost every operation involving the HTML rendering library requires an HTML