Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319504 - gc.drawText() does not show strikeout or underline text (win)
Summary: gc.drawText() does not show strikeout or underline text (win)
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 02:36 EDT by Lan Phan CLA
Modified: 2010-07-13 00:26 EDT (History)
1 user (show)

See Also:


Attachments
Test_project_swt3.6 (4.37 KB, application/octet-stream)
2010-07-12 02:36 EDT, Lan Phan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lan Phan CLA 2010-07-12 02:36:14 EDT
Created attachment 173992 [details]
Test_project_swt3.6

Windows: I don't use StyledText to draw strikeout or underline text, but using LOGFONT in fontdata instead.

try {
				Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
				Object logFont = FontData.class.getField("data").get(fontdata); //$NON-NLS-1$
				if (logFont != null && logFontClass != null) {
					logFontClass.getField("lfStrikeOut").set(logFont, new Byte((byte)1)); //$NON-NLS-1$
				}
			} catch (Throwable ex) {
				System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + ex); //$NON-NLS-1$ //$NON-NLS-2$
			}

I remembered that my code runs well in swt 3.5, but after moving to swt 3.6, strikeout or underline text is disappeared. I found that strikeout or underline text only shows when advance mode is OFF.
Is it a bug? Or, you prevent using LOGFONT directly in swt 3.6?
I attached my test project for your reference.
Comment 1 Felipe Heidrich CLA 2010-07-12 09:03:54 EDT
You are using reflection to access internal data. This is not supported, I will have to close this bug as wont fix.

Why don't you use TextLayout to draw underlined/strikeout text ?
Comment 2 Lan Phan CLA 2010-07-12 11:34:45 EDT
I wanna keep all info in FontData, using gc.drawText() is enough to me.
If swt does not support it, why I can draw strikeout or underline text with that way? And, it works well in swt 3.5 too.
Please consider it again. Thanks.
Comment 3 Felipe Heidrich CLA 2010-07-12 14:27:16 EDT
(In reply to comment #2)
> I wanna keep all info in FontData, using gc.drawText() is enough to me.
> If swt does not support it, why I can draw strikeout or underline text with
> that way? 

You are using win32 internals directly, I can't  guarantee it will always work. 
In advance mode we use GdiFont instead of LOGFONT.
In windows 7 we plan on using Direct2D in the future (again, LOGFONT won't be used).
Even on GDI, setting lfStrikeOut only works when logical font supports it natively.

Why can you use TextLayout ?
gc.drawText() is not enough for you, it does not have underline that you need.
Comment 4 Lan Phan CLA 2010-07-13 00:26:53 EDT
Ok, I see, thanks for your explanation.