Table Rendering Algorithm

Does anybody have or know where to find a table rendering algorithm. I need to implement a simple <table>,<tr> and <td> system to render a HTML like table on a fixed font printer.
LVL 27
BigRatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
in what language?
0
BigRatAuthor Commented:
It can be in any language you like, Eddie. In fact I will rewrite it into RatScript.

I have simply the elements TR and TD, the TABLE element just starts it off. The contents of TD is fixed font, so the width=length of the text, height = constant. But I allow a column span on TD, so I now need another algorithm to render the table.
0
Eddie ShipmanAll-around developerCommented:
I'm really not sure what you're after here. Are you taking a data table
and iterating the records to create an HTML table to print on a fixed font
printer?

What options do you want as far as styles is concerned? do you want to control
the width of the columns, colspan, etc?

This is a pretty broad question that can lead to loads of ineffective code.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

BigRatAuthor Commented:
I have explained a bit about what I'm doing in the HTML barcode question, to which you have recently contributed.

I started off with something like :-

<table>
<tr><td>Order Number:</td><td>$mbest_nr$</td></tr>
<tr><td>Order Type:</td><td>$type$</td></tr>
<tr><td>Description:</td><td><format type="short" format="6"/></td></tr>
</table>

(The contents are irrelevant, they get fetched out of databases etc...)

This produced a table with a fixed number of columns and I was able to write an algorithm to format it onto a printer, or into a fixed font document. The HTML version is just a simple translation.

Next if I have a table like :-

<table>
<tr><td>PartNr</td><td>Description</td><td>Qty</td></tr>

I fill out the relevant rows, BUT I'd like to add a row like :-

    <tr><td cols="3">--> order 3 months outstanding!!!</td></tr>

The question now arises, how do you implement column spanning?

I thought, since most browsers have to implement this sort of complexity, somenbody might know of a link or a document which broaches the subject and can give me a start without having to re-invent the wheel.
0
Eddie ShipmanAll-around developerCommented:
<tr><td colspan="3">--> order 3 months outstanding!!!</td></tr>

is how to do the column spanning.
0
BigRatAuthor Commented:
It is irrelevant whether one writes cols="3" or colspan="3", the point is in :-

<tr><td>some text</td><td colspan="2">some other text</td></tr>
<tr><td colspan="2">some more text</td><td>even more text</td></tr>

The table has three columns. What are the widths of columns 1,2,3 given the withds of the cells above? And please generalize the algorithm for an arbitary number of rows and columns.
0
Eddie ShipmanAll-around developerCommented:
In row 1, the colwidths are 33% and 67%
and
In row 2 the colwidths are 67% and 33%
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BigRatAuthor Commented:
Of course, one works out a percentage of the whole!

1. Determine the width of each row, by adding the width of each "td".
2. Determine the max-width (or allow to be set somewhere)
3. Determine the rows "cell" count (cell = <td colspan=1>)
4. Each cell has a width of max-width/count
5. Each td has a width of colspan*cell-width
6. Fit the text in the td accoding to it's width and properties.

I'll implement that and get back in a couple of hours!
0
Eddie ShipmanAll-around developerCommented:
It is no different that dynamically resizing columns on a TStringGrid
and I know you've done that before... ;-)
0
BigRatAuthor Commented:
I have implemented it with border selection as well. I can't think why I did not see the solution before?! Thanks for the pointer!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.