tags:

views:

105

answers:

2

I need to determine what font and size will be used for each HTML element. They may be set in various css, div, span, or on the element itself.

If I were to do this manually I would start by looking at the element and work backwards until I came to span, div, or css that had a font and/or size. That is the value I want. The browser can obviously do this because it displays the text using a font and size. I want to print a list with two columns, one with the text and the other with the font/size.

A: 

If you are looking for a non-programmatic way: I would suggest the firebug plugin for mozilla. Firebug will not only show you all attributes, but allow you to turn them on and off in the client.

Adam
Thank you, but I am looking for a programmatic way. Preferably Java, but I can be flexible. We are duplicating existing paper documents and the fonts have to match. I want to have a program that prints the above mentioned list so I can use it to compare without having to manually identify the HTML font being used.
Steven Schulman
A: 

You want to reproduce the functionality of parsing HTML into DOM objects, parsing CSS into rules over those objects, and applying those rules across the objects to end up with the associated computedStyle values? That sounds pretty much like a web browser to me.

You could try scripting Firefox or an IE WebBrowser control. There's also an open-source native Java browser/toolkit being developed, though I don't know how practical that is yet.

bobince