Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 58569 - Regression: StyledText does not wrap correctly
Summary: Regression: StyledText does not wrap correctly
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-14 17:52 EDT by Florian Priester CLA
Modified: 2005-03-11 10:36 EST (History)
1 user (show)

See Also:


Attachments
Incorrect wrapping (screenshot) (6.13 KB, image/png)
2004-04-14 17:54 EDT, Florian Priester CLA
no flags Details
Another screenshot (10.61 KB, image/png)
2004-04-15 12:07 EDT, Florian Priester CLA
no flags Details
Examples of incorrect wrapping without any accents (screenshot) (10.68 KB, image/png)
2004-04-18 19:24 EDT, Florian Priester CLA
no flags Details
Disappearing caret (3.78 KB, image/png)
2004-06-03 12:14 EDT, Florian Priester CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Priester CLA 2004-04-14 17:52:32 EDT
In the example below, the contents of a StyledText control with SWT.WRAP
style are not wrapped correctly.

The visible problems are (resize shell as needed to reproduce):
- Glyphs disappearing partially or fully behind the right border
- Words being broken apart at non-7-bit letters
- Lines starting with a space

In 3.0M7 and earlier versions, the behaviour was as expected.
In 3.0M8 and later, it's broken.

I did not find any other bug addressing this.
Bug 49567 does not look like the same issue to me.

---

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class StyledTextWrapTest {
  public static void main(String[] args) {
    Display display = new Display();
    
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    
    Font font = new Font(display, "Tahoma", 14, SWT.NORMAL);
    
    StyledText text = new StyledText(shell, SWT.MULTI | SWT.WRAP);
    text.setFont(font);
    text.setText("This is an exãmple têxt. It shoüld wráp corrèctlý.");
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    
    shell.setSize(200, 300);
    shell.open();
    
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    
    font.dispose();
    
    display.dispose();
  }
}
Comment 1 Florian Priester CLA 2004-04-14 17:54:13 EDT
Created attachment 9506 [details]
Incorrect wrapping (screenshot)
Comment 2 Grant Gayed CLA 2004-04-15 10:17:04 EDT
Moving to FH.  Note that running with the latest swt on win2000 I can only make 
the lines-starting-with-space problem happen when resizing the shell, I don't 
see the other two listed problems.
Comment 3 Felipe Heidrich CLA 2004-04-15 11:14:57 EDT
We changed StyledText to use platform support to wrap lines (Uniscribe). For 
some reason uniscribe mark letters with accent (ã,ê,ü, etc) as soft breaks 
causing lines to wrap at these letters. I can see the same problem happening 
with Notepad.

I believe the accents are causing all this trouble, I will check how we can 
avoid it.
Comment 4 Florian Priester CLA 2004-04-15 12:07:29 EDT
Created attachment 9539 [details]
Another screenshot

Please also note that even if the string does not contain any accents,
it can still happen that both punctuation characters and the caret are
clipped at the right edge of the StyledText bounds (see attachment).

BTW, my copy of Notepad does not seem to have any problem with this.
Comment 5 Felipe Heidrich CLA 2004-04-15 13:52:14 EDT
This I can fix more easily (problem shown the second screenshot).
The problem with the accents is going te be hard cause the OS returns bogus 
informatation.
Comment 6 Florian Priester CLA 2004-04-18 19:24:09 EDT
Created attachment 9625 [details]
Examples of incorrect wrapping without any accents (screenshot)
Comment 7 Felipe Heidrich CLA 2004-04-19 13:49:05 EDT
Fixed > 20040419 in HEAD.
I've fixed all the problems you mentioned except the case:
"Iterator and Observer are behavio(u)ral patterns."
I think it is okay to break line at symbol "(" or ")", (I tested with other 
editor).

Please, verify this fix using this week integration build (it will be build 
tomorrow) and reopen this problem reported if necessary.
Comment 8 Florian Priester CLA 2004-04-20 19:40:39 EDT
I have just tried I20040420.
It works better now but there are still a few problems.

- The width of the caret does not seem to be taken into account when
  wrapping lines. If the caret is positioned at the end of a line and
  there is just enough room for the text on that line but not for the caret,
  the caret will be clipped. The word at the end of the line should be
  moved to the next line instead (this worked right in 3.0M7).

- The new algorithm still causes too many incorrect line breaks to occur.
  For example, there should be no line breaks in the following places:
  (| indicates wrong point to break a line)
  
  This is a sentence|.
  I've downloaded this from eclipse|.|org.
  I repeat|: this will not work.
  "|Don't break apart quotes and the text enclosed by them|"
  (|Don't break apart brackets and the text enclosed by them|)
  Only 60|% of the work has been completed.
  
  These are just a few cases that I've tested, there are probably more,
  I cannot give you a complete list, sorry.

  I can confirm that all of the above examples are handled correctly
  in the previous version of StyledText (3.0M7), SWT's native Text control,
  Notepad, Wordpad and OpenOffice.

  The old algorithm previously used by StyledText seemed to work right
  most of the time, at least for natural text written in Western languages,
  so my suggestion would be to use that as a reference.
Comment 9 Felipe Heidrich CLA 2004-04-22 16:35:42 EDT
I've fixed (>20040422 in HEAD) all the cases:
  This is a sentence|.
  I've downloaded this from eclipse|.|org.
  I repeat|: this will not work.
  "|Don't break apart quotes and the text enclosed by them|"
  (|Don't break apart brackets and the text enclosed by them|)
  Only 60|% of the work has been completed.

I still have to fix caret positioning before closing this pr.
Comment 10 Florian Priester CLA 2004-06-03 12:14:18 EDT
Created attachment 11545 [details]
Disappearing caret

Screenshot illustrating the case left to be fixed
Comment 11 Florian Priester CLA 2005-03-11 10:36:07 EST
I'm closing this report since the original text-wrapping issues
have all been fixed. For the remaining problem (the caret being clipped),
a separate and more detailed report has been opened (bug 87774).