|
Re: Text control not wide enough in italic font [message #1856817 is a reply to message #1856400] |
Wed, 04 January 2023 09:03   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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);
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.02859 seconds