JDK-4207472 : Space added after named anchors
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: cinnabar,cinnabar_13,1.1
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,linux_suse_slec,solaris_2.6
  • CPU: x86,sparc
  • Submitted: 1999-01-31
  • Updated: 2005-06-22
  • Resolved: 2005-04-13
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 JDK 6
5.0u4Fixed 6 b32Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
- Named anchors cause a space to be added at the beginning of
  the text object that follows them.  
  
  This one has a workaround.  Simply add a <p> tag
  directly after the anchor.  For example:
  
  <a name="13507"></a><p>
  
  it doesn't add any space, but cleans up from the anchor tag.

==========================

The suggested fix does not work. Also it not only adds a space, it also adds a newline so the spacing of lines is incorrect as well. See 6219503.
###@###.### 2005-1-24 11:57:45 GMT

Comments
WORK AROUND There is a simple workaround for this bug. It is to have html comment inside anchor tag: --- 12<a name="123"><!-- --></a>34 --- This is rendered without any spaces If this workaround is acceptable I wold like to lower priority for this bug. ###@###.### 2005-03-18 01:05:34 GMT No, it isn't acceptable. We convert our docs programatically from Docbook to HTML using XSL stylesheets and we can not add the comments through this process. ###@###.### 2005-03-18 12:50:44 GMT ================ If you have control over XSLT then it could be changed to generate html comments ###@###.### 2005-03-18 12:58:53 GMT We don't unfortunately. We are using the docbook-xsl-stylesheets package from docbook.org. ###@###.### 2005-03-18 13:11:11 GMT
18-03-2005

EVALUATION The text package does not allow empty Elements, that is, Elements with a start == end offset. Therefore, the html package forces all character attributes (such as A) to have at least one character. A possible work around would be to have special Elements that aren't visible for cases like this. scott.violet@eng 1999-09-16 One thing we should support is views being invisible. View has the isVisible property, but unfortunately we don't really honor it during layout or character navigation. This particular bug could be fixed by making a LabelView that isn't visible, but the cusor navigation would have to be slightly changed to accomodate it. Additionaly when a View isn't visible we currently override the sizing methods to return 0. This doesn't seem quite right. If a view isn't visible, it shouldn't be layed out, painted, or participate in any other typical View methods. ###@###.### 2001-11-29 Name: slR10134 Date: 08/27/2002 (###@###.###) The idea of suggested fix is to return 0 in method getPreferredSpan if empty anchor was encountered. ====================================================================== This is needed for the Cinnabar release of JDS on Linux. According to current scheduling (changed recently) the last non-stopper build of Cinnabar is approx 4-5 weeks from now. Raising the priority. This needs to stay P2 or higher to appear on the Cinnabar P-Team bug list (please do not downgrade). What is the way to get this into a 1.5 Java rpm that is delivered into Cinnabar? ###@###.### 2005-1-25 11:12:41 GMT ============= Currently we use ' ' to have some content in <a></a> (we can not handle empty tags) ' ' has non zerro widht and becuase of it we have this bug. We can use '\n' instead. It makes tag non empty and after the fix for 4623342 (InlineView causes extra spacing around images in JTable) it has zerro width ###@###.### 2005-03-18 16:49:06 GMT ============= <sqe> RISK: NORMAL Verify this fix using the following regression test: test/javax/swing/text/html/HTMLDocument/4207472/bug4207472.java The change affects html rendering of pages which have empty anchor tags (that is <a></a>) Before we were using ' ' to have some content inside them now we use '\n'. Some of the things that are worth checking are: rendering pages with anchors navigating pages with anchors This change is in cross-platform code, so testing it on any single platform should be sufficient. </sqe> ###@###.### 2005-03-18 23:01:41 GMT There was a bug 4855860 [JTextPane returns too large preferredSize in some specific cases] affecting this bug too. ###@###.### 2005-05-11 17:09:56 GMT
18-03-2005

SUGGESTED FIX Name: slR10134 Date: 08/27/2002 ------- HTMLDocument.java ------- *** /tmp/sccs.wZaqpX ^T���� ������ 26 19:35:03 2002 --- HTMLDocument.java ^T���� ������ 26 19:25:22 2002 *************** *** 2716,2722 **** --- 2716,2729 ---- class AnchorAction extends CharacterAction { + private boolean isNamedAnchor; + public void start(HTML.Tag t, MutableAttributeSet attr) { + if (attr.getAttribute(HTML.Attribute.NAME) != null) { + isNamedAnchor = true; + } else { + isNamedAnchor = false; + } // set flag to catch empty anchors emptyAnchor = true; super.start(t, attr); *************** *** 2724,2729 **** --- 2731,2739 ---- public void end(HTML.Tag t) { if (emptyAnchor) { + if (isNamedAnchor) { + charAttr.addAttribute(hasEmptyAnchor, hasEmptyAnchor); + } // if the anchor was empty it was probably a // named anchor point and we don't want to throw // it away. *************** *** 3447,3452 **** --- 3457,3463 ---- boolean inTitle = false; boolean lastWasNewline = true; boolean emptyAnchor; + private String hasEmptyAnchor = "emptyAnchor"; /** True if (!emptyDocument && insertTag == null), this is used so * much it is cached. */ boolean midInsert; ------- InlineView.java ------- *** /tmp/sccs.DOa4oX ^T���� ������ 26 19:34:33 2002 --- InlineView.java ^T���� ������ 26 19:29:17 2002 *************** *** 29,38 **** --- 29,48 ---- */ public InlineView(Element elem) { super(elem); + if (elem.getAttributes().copyAttributes().getAttribute(hasEmptyAnchor) != null) { + forcedWidth = 0; + } StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); } + public float getPreferredSpan(int axis) { + if (forcedWidth != -1 && axis == View.X_AXIS) { + return 0; + } + return super.getPreferredSpan(axis); + } + /** * Gives notification from the document that attributes were changed * in a location that this view is responsible for. *************** *** 184,188 **** --- 194,200 ---- private boolean nowrap; private AttributeSet attr; + private String hasEmptyAnchor = "emptyAnchor"; + private int forcedWidth = -1; } ======================================================================
25-09-2004