I fixed the PlainView and FieldView to not include the trailing \n
character in string width calculations and drawString. We did skip the
newline in some places and in other places didn't, this patch makes the
code consitently skip the newline.

2006-03-27  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/FieldView.java
        (getPreferredSpan): Don't include trailing newline in
        calculations.
        * javax/swing/text/PlainView.java
        (drawLine): Don't include trailing newline.
        (determineMaxLineLength): Don't include trailing newline.
        (getLineBuffer): Made method final.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.39
diff -u -1 -0 -r1.39 PlainView.java
--- javax/swing/text/PlainView.java	17 Mar 2006 15:29:33 -0000	1.39
+++ javax/swing/text/PlainView.java	27 Mar 2006 13:09:40 -0000
@@ -157,21 +157,21 @@
    * @param g the graphics to use for drawing the text
    * @param x the X coordinate of the baseline
    * @param y the Y coordinate of the baseline
    */
   protected void drawLine(int lineIndex, Graphics g, int x, int y)
   {
     try
       {
         Element line = getElement().getElement(lineIndex);
         int startOffset = line.getStartOffset();
-        int endOffset = line.getEndOffset();
+        int endOffset = line.getEndOffset() - 1;
         
         if (selectionStart <= startOffset)
           // Selection starts before the line ...
           if (selectionEnd <= startOffset)
             {
               // end ends before the line: Draw completely unselected text.
               drawUnselectedText(g, x, y, startOffset, endOffset);
             }
           else if (selectionEnd <= endOffset)
             {
@@ -318,21 +318,21 @@
       return maxLineLength;
     
     // otherwise we have to go through all the lines and find it
     Element el = getElement();
     Segment seg = getLineBuffer();
     float span = 0;
     for (int i = 0; i < el.getElementCount(); i++)
       {
         Element child = el.getElement(i);
         int start = child.getStartOffset();
-        int end = child.getEndOffset();
+        int end = child.getEndOffset() - 1;
         try
           {
             el.getDocument().getText(start, end - start, seg);
           }
         catch (BadLocationException ex)
           {
             AssertionError ae = new AssertionError("Unexpected bad location");
 	    ae.initCause(ex);
 	    throw ae;
           }
@@ -511,21 +511,21 @@
     // are longer than the previous longest line        
     Segment seg = getLineBuffer();
     float longestNewLength = 0;
     Element longestNewLine = null;    
 
     // Loop through the added lines to check their length
     for (int i = 0; i < newElements.length; i++)
       {
         Element child = newElements[i];
         int start = child.getStartOffset();
-        int end = child.getEndOffset();
+        int end = child.getEndOffset() - 1;
         try
           {
             el.getDocument().getText(start, end - start, seg);
           }
         catch (BadLocationException ex)
           {
             AssertionError ae = new AssertionError("Unexpected bad location");
 	    ae.initCause(ex);
 	    throw ae;
           }
@@ -630,18 +630,18 @@
       }    
   }
 
   /**
    * Provides a [EMAIL PROTECTED] Segment} object, that can be used to fetch text from
    * the document.
    *
    * @returna [EMAIL PROTECTED] Segment} object, that can be used to fetch text from
    *          the document
    */
-  protected Segment getLineBuffer()
+  protected final Segment getLineBuffer()
   {
     if (lineBuffer == null)
       lineBuffer = new Segment();
     return lineBuffer;
   }
 }
 
Index: javax/swing/text/FieldView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/FieldView.java,v
retrieving revision 1.11
diff -u -1 -0 -r1.11 FieldView.java
--- javax/swing/text/FieldView.java	17 Mar 2006 17:50:53 -0000	1.11
+++ javax/swing/text/FieldView.java	27 Mar 2006 13:09:40 -0000
@@ -119,21 +119,21 @@
 
     if (axis == Y_AXIS)
       return super.getPreferredSpan(axis);
 
     String text;
     Element elem = getElement();
 
     try
       {
         text = elem.getDocument().getText(elem.getStartOffset(),
-                                          elem.getEndOffset());
+                                          elem.getEndOffset() - 1);
       }
     catch (BadLocationException e)
       {
 	// Should never happen
 	AssertionError ae = new AssertionError();
 	ae.initCause(e);
 	throw ae;
       }
 
     return fm.stringWidth(text);

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to