Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 93447 - GC does not calculate extents properly for italicized text
Summary: GC does not calculate extents properly for italicized text
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 140919 159594 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-02 15:48 EDT by Pratik Shah CLA
Modified: 2020-04-27 12:55 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pratik Shah CLA 2005-05-02 15:48:53 EDT
Snippet showing the problem (in 3.1M6):

Display d = new Display();
Shell shell = new Shell(d, SWT.SHELL_TRIM);
final String s = "All";
Canvas canvas = new Canvas(shell, SWT.NONE);
FontData fd = canvas.getFont().getFontData()[0];
fd.setStyle(SWT.ITALIC);
Font font = new Font(d, fd);
canvas.setFont(font);
canvas.addPaintListener(new PaintListener() {
	public void paintControl(PaintEvent e) {
		e.gc.drawString(s, 0, 0);
	}
});
GC gc = new GC(shell);
gc.setFont(font);
Point p = gc.stringExtent(s);
canvas.setBounds(0, 0, p.x, p.y);
gc.dispose();
shell.pack();
shell.open();
while (!shell.isDisposed())
    while (!d.readAndDispatch())
        d.sleep();


Using textExtents() creates the same problem.  If you change the font to be 
bold instead of italicized, everything works fine.
Comment 1 Florian Priester CLA 2006-02-05 20:40:03 EST
What seems to happen here is that the GC uses the total advance width
of the string when measuring its extent, ignoring any overhang caused
by an italic font style. While this may be undesired in some cases,
it is probably the intended API behaviour. The same thing occurs when
using the TextLayout class. I think the solution would be to provide
additional methods that would return the entire visual bounding box of
the string. Not sure how difficult implementing such a feature would be,
though.

See also attachment 22859 [details] and the related bug 99298.
Comment 2 Steve Northover CLA 2006-05-10 10:32:56 EDT
*** Bug 140919 has been marked as a duplicate of this bug. ***
Comment 3 Grant Gayed CLA 2006-10-06 12:21:04 EDT
*** Bug 159594 has been marked as a duplicate of this bug. ***
Comment 4 Marc H. Marc H. CLA 2012-12-18 02:08:10 EST
Same problem with SWT 4.2.0 on Gtk.

It happens with Labels too (I'm not sure of both problems are somehow related though). Setting a minimal width is a possible workaround... But we cannot do this for every piece of italic text we want to display.
Comment 5 Eclipse Genie CLA 2020-04-27 12:55:22 EDT
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.