Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Phillipus opened this issue Apr 10, 2024 · 0 comments

Comments

@Phillipus
Copy link
Contributor

This comes from one our users - archimatetool/archi#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();
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant