Skip to content

[Windows] Text is not displayed if the font has Underline or Strikeout and GC.setAdvanced(true) #3091

@Phillipus

Description

@Phillipus

Windows 11
Java 21
Latest SWT from I-builds

This is moved from eclipse-gef/gef-classic#1023

If a Font is used to draw text in a GC that has either Underline or Strikeout the text is not rendered if GC.setAdvanced(true)

The Underline or Strikeout for a Font can be set using a FontDialog:

Image

Run the Snippet:

import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class FontTest {
    
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setSize(200, 150);
        
        // Rather than open a FontDialog we'll create the Font from an equivalent FontData string which has underline set
        String fontString = "1|Arial|10.125|0|WINDOWS|1|-27|0|0|0|400|0|1|0|0|3|2|1|34|Arial";
        FontData fd = new FontData(fontString);
        Font font = new Font(display, fd);

        shell.addPaintListener(e -> {
            GC gc = e.gc;
            gc.setFont(font);

            gc.drawText("Hello World", 10, 10);
            
            gc.setAdvanced(true); // Comment this out to render text
            gc.drawText("Hello World", 10, 50);
        });

        shell.open();
        
        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}

It should look like this:

Image

But looks like this:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsHappens on Windows OS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions