Skip to content

[Mac] Buttons with font sizes larger than 23pt are not correctly rendered #3085

@xpomul

Description

@xpomul

Describe the bug
When setting the font to 24pt or more for a Button in SWT on MacOS with Cocoa, the button does not grow in height together with the font. This results in the upper part of the button label to be clipped.

To Reproduce

package net.winklerweb.test;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class FontScalingTest {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Button Test");
        shell.setLayout(new GridLayout(2, false));

        FontData defaultFontData = display.getSystemFont().getFontData()[0];
        
        new Label(shell, SWT.NONE).setText("Font Size:");
        
        Combo fontSizeCombo = new Combo(shell, SWT.READ_ONLY);
        fontSizeCombo.setItems("8", "10", "12", "14", "16", "18", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "36", "48", "72", "96");
        fontSizeCombo.select(4);
        fontSizeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                
        Button button = new Button(shell, SWT.PUSH);
        button.setText("Button");
        button.setLayoutData(GridDataFactory.swtDefaults().grab(false, false).span(1, 1).create());
                
        updateButtonFont(button, defaultFontData, 16);
        
        fontSizeCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter( e-> {
            int size = Integer.parseInt(fontSizeCombo.getText());
            updateButtonFont(button, defaultFontData, size);
            shell.layout(true);
        }));
        
        shell.setSize(500, 200);
        shell.open();
        
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        
        display.dispose();
    }
    
    private static void updateButtonFont(Button button, FontData baseFontData, int size) {
        Font oldFont = button.getFont();
        Font newFont = new Font(button.getDisplay(), baseFontData.getName(), size, baseFontData.getStyle());
        button.setFont(newFont);
        button.requestLayout();
        if (oldFont != null && !oldFont.isDisposed()) {
            oldFont.dispose();
        }
    }
}

Expected behavior
When selecting a font size of 24, 30, 36, ..., the button should grow vertically and show the complete text.

Screenshots

Image Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    arm64 / Apple M1

  2. JRE/JDK version
    JRE 25

Version since
more or less forever

Workaround (or) Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions