ITableFontProvider and System fonts [message #324060] |
Thu, 17 January 2008 04:04  |
Eclipse User |
|
|
|
Originally posted by: automatic.javalobby.org
Hi, everybody!
I'm working on a RCP application which uses a TableViewer.
This TableViewer may have to display Cyrillic characters.
So I tried to implement ITableFontProvider in my LableProvider and to override the getFont() method to get some system font and use it in my table:
<code>
public Font getFont(Object element, int columnIndex) {
FontRegistry reg = JFaceResources.getFontRegistry();
Font returnedFont = reg.defaultFont();
FontData[] fdt = returnedFont.getDevice().getFontList(
"Arial Narrow", true);
if (!reg.getKeySet().contains("Arial Narrow")) {
reg.put("Arial Narrow", fdt2);
}
Font f = reg.get("Arial Narrow");
return f;
}
</code>
But the displayed font is really TOO BIG! I don't understand why but the table viewer seems to use the FontData with a size bigger than it should...
Does anyone ever had this kind of problem? Does anywone have an idea of what is going on?
Thanks in advance!
Chris
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: ITableFontProvider and System fonts [message #324124 is a reply to message #324112] |
Thu, 17 January 2008 12:22   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Tom,
Yes, and from the character he's showing, it almost looks more like he's
not doing proper unicode decoding. I wonder where he gets the
characters from? He could get odd results if he reads in unicode
without proper unicode decoding...
Tom Schindl wrote:
> One more thing, if the font-system doesn't find the requested font it
> returns one it thinks is closest to the one requested.
>
> Tom
>
> Tom Schindl schrieb:
>> Did you tried using this font in a Text-Widget? Does it work there?
>>
>> Tom
>>
>> C. BOUDJENNAH schrieb:
>>> About the size of the characters, using this:
>>> <code>
>>> FontDescriptor fdesc=FontDescriptor.createFrom("Arial Unicode
>>> MS",8,SWT.NORMAL);
>>> f = fdesc.createFont(f.getDevice());
>>> </code>
>>> and returning the font in the getFont() method allows you to get a
>>> font with the right size.
>>> But I still cannot display well the Cyrillic characters, though I'm
>>> sure that "Arial Unicode MS" can display those characters. In
>>> another application coded in VB by another team, they used this
>>> font, and changed the charset, to display cyrillic characters...
>>
>>
>
>
|
|
|
|
|
|
|
|
|
Re: ITableFontProvider and System fonts [message #324193 is a reply to message #324178] |
Fri, 18 January 2008 13:32   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
This is a multi-part message in MIME format.
--------------000407070701080705000307
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Definitely ask them to check. I think they are being loaded incorrectly
or stored incorrectly. For example, if the strings are coming from a
..properties file, that properties file *must *be encoded as "ISO-8859-1"
which means that special character *must *be escaped. Here's an EMF
utility that is used to save a generated .properties file to be sure it
can be properly saved using "ISO-8859-1" encoding. There are command
line utilities to do such things, i.e., to create a properly encoded
properties file given arbitrary textual input...
/**
* Performs escape encoding on the given string so that it can be
represented using 1-byte characters.
* Any characters higher than 0xFF are replaced with an escape of
the form \\uXXXX, where XXXX is the
* four-digit hex representation of the Unicode code point.
*/
public static String unicodeEscapeEncode(String unicode)
{
StringBuilder result = new StringBuilder(unicode.length());
for (int i = 0, size = unicode.length(); i < size; ++i)
{
char character = unicode.charAt(i);
if (character > '\u00ff')
{
result.append("\\u");
String hex = Integer.toString(character, 16);
for (int j = hex.length(); j < 4; ++j)
{
result.append("0");
}
result.append(hex);
}
else
{
result.append(character);
}
}
return result.toString();
}
C. BOUDJENNAH wrote:
> The String comes from a library developped by another team...So you think I should ask this team to check how they create those strings?
>
--------------000407070701080705000307
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Definitely ask them to check. I think they are being loaded
incorrectly or stored incorrectly. For example, if the strings are
coming from a .properties file, that properties file <b>must </b>be
encoded as "ISO-8859-1" which means that special character <b>must </b>be
escaped. Here's an EMF utility that is used to save a generated
..properties file to be sure it can be properly saved using "ISO-8859-1"
encoding. There are command line utilities to do such things, i.e., to
create a properly encoded properties file given arbitrary textual
input...<br>
<blockquote><small> /**</small><br>
<small> * Performs escape encoding on the given string so that it
can be represented using 1-byte characters.</small><br>
<small> * Any characters higher than 0xFF are replaced with an
escape of the form \\uXXXX, where XXXX is the</small><br>
<small> * four-digit hex representation of the Unicode code point.</small><br>
<small> */</small><br>
<small> public static String unicodeEscapeEncode(String unicode)</small><br>
<small> {</small><br>
<small> StringBuilder result = new StringBuilder(unicode.length());</small><br>
<small> for (int i = 0, size = unicode.length(); i < size; ++i)</small><br>
<small> {</small><br>
<small> char character = unicode.charAt(i);</small><br>
<small> if (character > '\u00ff')</small><br>
<small> {</small><br>
<small> result.append("\\u");</small><br>
<small> String hex = Integer.toString(character, 16);</small><br>
<small> for (int j = hex.length(); j < 4; ++j)</small><br>
<small> {</small><br>
<small> result.append("0");</small><br>
<small> }</small><br>
<small> result.append(hex);</small><br>
<small> }</small><br>
<small> else</small><br>
<small> {</small><br>
<small> result.append(character);</small><br>
<small> }</small><br>
<small> }</small><br>
<br>
<small> return result.toString();</small><br>
<small> }</small><br>
</blockquote>
<br>
<br>
C. BOUDJENNAH wrote:
<blockquote
cite="mid:7085457.28971200667926693.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">The String comes from a library developped by another team...So you think I should ask this team to check how they create those strings?
</pre>
</blockquote>
<br>
</body>
</html>
--------------000407070701080705000307--
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11713 seconds