Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Text control not wide enough in italic font
Text control not wide enough in italic font [message #1856400] Thu, 08 December 2022 13:38 Go to next message
Julien Guigné is currently offline Julien GuignéFriend
Messages: 9
Registered: April 2022
Junior Member
Hi,

we are facing a little issue when label text font is set to italic.
The div element wrapping the text node, inside the label's node, has got a calculated width for normal font.
But it doesn't change when text is set to italic, and the end is a bit truncated, which is imperfect :

index.php/fa/42762/0/

index.php/fa/42763/0/

Setting a mutation observer https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver on client label's node might be a solution, in order to update div's width according to real text width (https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript)

Thank you for your help.

Regards.

[Updated on: Thu, 08 December 2022 13:40]

Report message to a moderator

Re: Text control not wide enough in italic font [message #1856817 is a reply to message #1856400] Wed, 04 January 2023 09:03 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,

I'm now aware of any problems related to font styles. RAP framework has a mechanism called "text-size-determination", which renders every string with the corresponding font on the client in a div element and measure the actual string dimensions in the browser. As all the layout is done on the server, any attempt to adjust only client will fail. In order to help additional information will be needed as how did you set the font? Is it a web font and system one? Any small snippet to demonstrate the issue will be welcome.

Best regards,
Ivan
Re: Text control not wide enough in italic font [message #1857331 is a reply to message #1856817] Tue, 31 January 2023 11:38 Go to previous messageGo to next message
Julien Guigné is currently offline Julien GuignéFriend
Messages: 9
Registered: April 2022
Junior Member
If it can help.
Fonts are initialized in a singleton class :

public final class UIUtil
{

private Font fontNormal, fontBold, fontBoldAndItalic, fontItalic;
private Hashtable<String, Font> fontMap = new Hashtable<String, Font>();

private static UIUtil _instance;
    private UIUtil()
    {
    }

    public static UIUtil getInstance()
    {
    	synchronized(UIUtil.class)
    	{
	    	if (_instance == null)
	    	{
	    		_instance = new UIUtil();
	    		_instance.init();
	    	}
	    }
    	if (_instance.fontNormal == null)
    	{
    		_instance.init();	
    	}
    	return _instance;
    }

private void init()
	{
    	if (Display.getCurrent() == null)
    		return;

    	Font systemFont = Display.getCurrent().getSystemFont();
        fontNormal = systemFont;
        FontData[] fd = systemFont.getFontData();
        FontData fdBold = new FontData(fd[0].getName(), fd[0].getHeight(), SWT.BOLD);
        fontBold = UIUtil.getFont(fdBold);
        FontData fdBoldAndItalic = new FontData(fd[0].getName(), fd[0].getHeight(), SWT.BOLD | SWT.ITALIC);
        fontBoldAndItalic = UIUtil.getFont(fdBoldAndItalic);
        FontData fdItalic = new FontData(fd[0].getName(), fd[0].getHeight(), SWT.ITALIC);
        fontItalic = UIUtil.getFont(fdItalic);
	}

public static Font getFont(final FontData fd)
    {
        return getFont(fd, true);
    }

/*
     * Mandatory: called in UI thread
     */
    public static Font getFont(final FontData fontData, final boolean useCache)
    {
        if (fontData == null)
            return null;
        FontData fd = cloneFontData(fontData);
        Font font = null;
        String sFont = getFontString(fd);
        if (useCache)
            font = UIUtil.getFontFromMap(sFont);
        if (font != null && !font.isDisposed())
            return font;
        else
            font = new Font(Display.getCurrent(), fd);
        if (useCache)
        	getInstance().fontMap.put(sFont, font);
        return font;
    }

public static FontData cloneFontData(final FontData fontData)
    {
    	String name = fontData.getName();
    	int height = fontData.getHeight();
    	int style = fontData.getStyle();
    	return new FontData(name, height, style);
    }

 private static String getFontString(FontData fd)
    {
        String sFont = fd.getName() + " " + fd.getHeight() + " " + fd.getStyle();
        return sFont;
    }

private static Font getFontFromMap(final String sFont)
    {
        return getInstance().fontMap.get(sFont);
    }


// Methods called to set a font to a widget (for example a Label)
public static void setFontToItalic(final Label item)
    {
        if (item == null || item.isDisposed())
            return;
        setFont(item, getInstance().fontItalic);
    }
public static void setFont(final Label item, final Font font)
    {
        if (item == null || item.isDisposed() || font == null || font.isDisposed())
            return;
        item.setFont(font);
    }
}
Re: Text control not wide enough in italic font [message #1857469 is a reply to message #1857331] Thu, 09 February 2023 08:12 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,

did you trigger the layout after the font is changed on the widget? If not, the behavior is understandable. On the old layout (widget bounds) you set a new font which leads to text cut-off.

Best regards,
Ivan
Previous Topic:selection in multiline Text widget
Next Topic:current git fails to build with assertionin testWaitOnBackgroundThread
Goto Forum:
  


Current Time: Mon Jun 17 06:30:40 GMT 2024

Powered by FUDForum. Page generated in 0.02843 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top