JDK-4285636 : HTML: Font size indices are miscalculated - off by 1 (vs. browsers)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.7,1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 1999-10-28
  • Updated: 2000-03-22
  • Resolved: 2000-03-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Description

Name: krT82822			Date: 10/27/99


The StyleSheet methods getIndexOfSize() and getPointSize() return the wrong results. Actually, font sizes are not officially part of HTML 3.2 but Swing supports them as do the browsers.
Unfortunately, the Swing implementation does not match the browsers, it produces indices that are off by one.
The browsers recognize 1-7 where as Swing recognizes 0-6. So in JTextPane everything is pushed up a size and there is no difference in appearance between a font with size=6 and one with size=7. As I said, this is not consistent with the browsers.

The following HTML page illustrates the difference. Display it in Netscape or IE and then in JTextPane:

<html><body>
<p>
<font size=0>zero</font><font size=1>one</font>
<font size=6>six</font><font size=7>seven</font>
</p>
</body></html>

There are two possible easy ways to fix this. In the class CSS make the following changes:

//Add a dummy entry at index 0, making sizeMap.length == 8
static int sizeMap[] = { 8, 10, 12, 14, 18, 24, 36 };

static int getIndexOfSize(float pt) {
  for (int i = 0; i < sizeMap.length; i ++ ) //change 0 to 1 here
    if (pt <= sizeMap[i])
      return i;
  return sizeMap.length - 1;
}

float getPointSize(int index) {
  if (index < 0)       //Change 0 to 1 here
    return sizeMap[0]; //Change 0 to 1 here
  else if (index > sizeMap.length - 1)
    return sizeMap[sizeMap.length - 1];
  else
    return sizeMap[index];
}

The other way is to leave the sizeMap array alone and make these changes:

static int getIndexOfSize(float pt) {
  for (int i = 0; i < sizeMap.length; i ++ )
    if (pt <= sizeMap[i])
       return i;             //Change i to i+1 here
  return sizeMap.length - 1; //Remove the "-1" here
}

float getPointSize(int index) {
  if (index < 0)   //Change 0 to 1 here
    return sizeMap[0];
  else if (index > sizeMap.length - 1) //Remove the "-1" here
    return sizeMap[sizeMap.length - 1];
  else
    return sizeMap[index];  //Change index to index-1 here
}

Of course, all this is totally untested!

This problem all causes relative sizes to be off by one. The browsers recognize -2 through +4 but Swing uses -3 through +3!

msexter
(Review ID: 96935) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION font tag now supports 1-7 to correctly match browsers. scott.violet@eng 2000-03-20
20-03-2000