Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 319504

Summary: gc.drawText() does not show strikeout or underline text (win)
Product: [Eclipse Project] Platform Reporter: Lan Phan <quoclan>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test_project_swt3.6 none

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.