eclipse / gef-classic

Eclipse GEF(tm) Classic code
Eclipse Public License 2.0
22 stars 48 forks source link

[Mac] TextFlow control height not calculated correctly if text contains an emoji character #414

Open Phillipus opened 3 months ago

Phillipus commented 3 months ago

This comes from one our users - https://github.com/archimatetool/archi/issues/1041

This is Mac only, it's OK on Windows.

If a Draw2d TextFlow control contains an emoji and a non-system font is used the overall text is clipped:

clipped

It should look like this:

correct

Here's a snippet to reproduce:

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.ParagraphTextLayout;
import org.eclipse.draw2d.text.TextFlow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MacEmojiTextHeight {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setSize(300, 200);

        // Create a container with root figure
        FigureCanvas fc = new FigureCanvas(shell);
        Figure rootFigure = new Figure();
        rootFigure.setOpaque(true);
        rootFigure.setBackgroundColor(new Color(255, 255, 255));
        fc.getLightweightSystem().getRootFigure().add(rootFigure);

        // XY Layout
        rootFigure.setLayoutManager(new XYLayout());

        // Setting a non-system font is important here. The system font renders correctly.
        Font font = new Font(display, new FontData("Arial", 14, SWT.NORMAL));
        rootFigure.setFont(font);

        // Create a TextFlow control with FlowPage
        FlowPage page = new FlowPage();
        TextFlow textFlow = new TextFlow();
        textFlow.setLayoutManager(new ParagraphTextLayout(textFlow, ParagraphTextLayout.WORD_WRAP_SOFT));
        page.add(textFlow);
        rootFigure.add(page, new Rectangle(10, 10, 200, 100));

        // Display text with an emoji
        String emoji = Character.toString(0x1F600); // Smiley face emoji
        textFlow.setText("Hello World " + emoji);

        shell.open();

        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}
github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 90 days with no activity.