United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4285636 : HTML: Font size indices are miscalculated - off by 1 (vs. browsers)

Details
Type:
Bug
Submit Date:
1999-10-28
Status:
Resolved
Updated Date:
2000-03-22
Project Name:
JDK
Resolved Date:
2000-03-22
Component:
client-libs
OS:
generic,solaris_2.6
Sub-Component:
javax.swing
CPU:
generic,sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1.7,1.3.0
Fixed Versions:
1.4.0 (beta)

Related Reports
Duplicate:

Sub Tasks

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


                                     
2004-06-14
EVALUATION

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



Hardware and Software, Engineered to Work Together