Community
Participate
Working Groups
Build Identifier: 20100218-1602 When a TextLayout needs to break a line in the middle of word, it may break one character ahead of the correct one causing it to overflow the width set using setWidth(..). getBounds() then returns that width, rather than the actual width of the overflowing layout. As far as I can tell, this happens when the correct break location is after a letter and before a non-letter. Reproducible: Always Steps to Reproduce: package swt; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.TextLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; public class TextLayoutBug { public static void main (String [] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.addListener(SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { GC gc = event.gc; gc.setBackground (new Color (display, 128, 128, 255)); gc.fillRectangle (shell.getClientArea()); TextLayout layout = new TextLayout(display); layout.setFont (new Font(display, "Arial", 10, SWT.NORMAL)); layout.setText("abcd&& abcde&& abcdef&&"); layout.setWidth(36); layout.setAlignment(SWT.CENTER); Rectangle layoutSize = layout.getBounds(); Rectangle rect = new Rectangle (20, 20, layoutSize.width, layoutSize.height); gc.setBackground (new Color (display, 255, 255, 0)); gc.fillRectangle(rect); layout.draw (gc, rect.x, rect.y); gc.drawText ("Reported layout bounds: " + layoutSize.width + " X " + layoutSize.height, rect.x, rect.y + rect.height + 5, true); } }); shell.pack(); shell.setSize(300, 150); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
Created attachment 174986 [details] snippet reproducing the bug
Created attachment 174987 [details] screenshot
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.