Discrepancies in HTML and CSS rendering

SimplyHTML tries to implement HTML and CSS usage as close to the specified standard as possible. Still there are discrepancies for rendering of the resulting documents when viewed in different environments.

This chapter lists known discrepancies, why they seem to occur and how SimplyHTML tries to compensate the effects, if possible. Any additional hints and ideas to the author are appreciated.

Results have been tested in the following environments so far:

- Netscape 6.2.1 (SuSE Linux 8.0)
- Opera 6.0 B 1 (SuSE Linux 8.0)
- Internet Explorer 5.5 (Windows Me)
- Java J2SE 1.4 (SuSE Linux 8.0, Windows Me, Windows NT 3.51)

Following is a list of known discrepancies.

Font names

Fonts are locally bound to the machine SimplyHTML is running on. When formatting text to display font ' Palatino' for instance it is not possible to predict if respective document will display similarly in any given environment. To make it easier to exchange similar font settings over different system environments, some standardized font names can be used. Common font names for that purpose are

- Sans-Serif
- Serif
- Monospace

Unfortunately, the Java language has the name SansSerif for the font that most other applications know as Sans-Serif. As well Java uses name Monospaced, while other applications partly use Monospace.

Solution

This effect is fixed by mapping between the possible values mentioned above with class AttributeMapper. Class AttributeMapper is used in class SHTMLWriter to map from Java to HTML and in class SHTMLDocument.SHTMLReader.SHTMLCharacterAction to map from HTML to Java.

In the default style sheet of SimplyHTML this is solved by having several font family names with the one relevant for Java as the first, e.g. p { font-family:SansSerif, Sans-Serif; }. For some reason, however, this does not work with Java on Linux, i.e. having more than one font family name in the style sheet causes Java to not recognize the font style name at all under Linux.

Font sizes

Due to a bug in the javax.swing package, font sizes are rendered approximately 1.3 times smaller in JEditorPane than in any browser (bug id 4765271, see https://developer.java.sun.com/developer/bugParade/bugs/4765271.html).

Solution

SimplyHTML compensates this bug by providing customized views in class SHTMLEditorKit.SHTMLFactory. The views adjust font sizes before they are rendered so inside SimplyHTML fonts are displayed similar to as they are displayed in web browsers.

Unfortunately this does not fix the bug for cases where HTML is being displayed through Java APIs such as JavaHelp. So a bug fix from Sun to become available soon would still be highly welcome.

Table cell borders

Up to J2SE 1.4 cell borders are not rendered individually and there is no way to have different colors for borders of different sides of a cell. Either a border is drawn around all sides of a table cell or no border is drawn. There is no way for example to draw a vertical border between two cells only while the other sides of these cells have no borders.

Solution

SimplyHTML uses customized views to establish individual border rendering for table cells. Unfortunately this does not apply for cases where HTML is being displayed through Java APIs such as JavaHelp. A fix from Sun to become available soon would still be highly welcome.

Table cell margins

The CSS specification describes CSS attribute margin and its variations margin-top, margin-bottom, etc. as a way to set the distance between two block elements such as two paragraphs to each other but also for elements such as a table cell. However, a setting of margin-left:2pt for an arbitrary table cell is not being rendered up to now in any of the tested browsers.

Instead, only HTML attribute cellspacing is rendered so far, which is applicable only in the table tag (i.e. affecting all cells of respective table). Therefore specification and rendering of distances between individual table cells or for individual sides of a table cell is done correctly in SimplyHTML but it will not be shown in a web browser as it is shown in SimplyHTML.

Because SimplyHTML is built around formatting through CSS attributes, the cellspacing attribute can not be set for a given table in SimplyHTML. Attribute cellspacing is rendered in SimplyHTML, when contained in an existing HTML file.

Solution

There is no solution for this effect up to now.