Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » ITableFontProvider and System fonts
ITableFontProvider and System fonts [message #324060] Thu, 17 January 2008 04:04 Go to next message
Eclipse UserFriend
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 #324066 is a reply to message #324060] Thu, 17 January 2008 05:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Maybe it's returning a list with the font data for all the different
font sizes for that font name and maybe the biggest one is first.
Maybe you should create a FontDescriptor and then call setHeight on it
to match the height of the font that the table control would be using by
default.


C. BOUDJENNAH wrote:
> 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 #324071 is a reply to message #324060] Thu, 17 January 2008 05:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

Anyway, even with a too big font, Cyrillic characters are not well displayed...
So, maybe my problem is not here...The best thing for my app would be to be able to use the default font with Cyrillic characters when I want to...
Does anywone know how I can do that???
Thx!
Re: ITableFontProvider and System fonts [message #324072 is a reply to message #324071] Thu, 17 January 2008 05:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Are you sure you've installed the language packs on your OS to display
these national characters... It seems to me I couldn't display Hebrew
characters until I updated the OS to support them. I don't remember how
I did that. It's been a while. Are other parts of the OS able to
display the characters you want? I.e., if you use it for a file name
does it display correctly?


C. BOUDJENNAH wrote:
> Anyway, even with a too big font, Cyrillic characters are not well displayed...
> So, maybe my problem is not here...The best thing for my app would be to be able to use the default font with Cyrillic characters when I want to...
> Does anywone know how I can do that???
> Thx!
>
Re: ITableFontProvider and System fonts [message #324076 is a reply to message #324072] Thu, 17 January 2008 05:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

I looked at the languages options in Windows and the services are installed for French (I'm French, so, so far it's normal!), English and Russian...So I guess it should be OK on my OS side...
Re: ITableFontProvider and System fonts [message #324081 is a reply to message #324066] Thu, 17 January 2008 09:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

I tried moving the order of the FontData's in the FontData's tables and I have the same problem.
So I tried using a FontDescriptor and setting the height of each FontData at one third of its previous height and the problem is that the width is not changed and cannot be changed. So I have flattened characters!!!
And about the Windows setting, I can switch to Cyrillic when I write here: &#1081;&#1094;&#1082;&#1077;&#1085;& #1075;&#1096;&#1097;&#1079;&#1092;&#1099 ;&#1074;&#1072;&#1087;&#1088;&#1086;& ;#1083;&#1076;&#1078;&#1103;&#1095;&#108 9;&#1084;&#1080;&#1090;
So I guess my OS is OK with the character sets...
I really don't know how I can do that.
Basically, I have a Table Viewer, I have a label provider, which also implements ITableFontProvider and I just would like to be able to display Cyrillic characters in my table when some informations have to be displayed in Cyrillic...
Re: ITableFontProvider and System fonts [message #324083 is a reply to message #324081] Thu, 17 January 2008 09:05 Go to previous messageGo to next message
Eclipse UserFriend
Could try to create SWT-Only Snippet and post it to the swt-newsgroup.

I don't think this is a JFace-Problem.

Tom

C. BOUDJENNAH schrieb:
> I tried moving the order of the FontData's in the FontData's tables and I have the same problem.
> So I tried using a FontDescriptor and setting the height of each FontData at one third of its previous height and the problem is that the width is not changed and cannot be changed. So I have flattened characters!!!
> And about the Windows setting, I can switch to Cyrillic when I write here: &#1081;&#1094;&#1082;&#1077;&#1085;& #1075;&#1096;&#1097;&#1079;&#1092;&#1099 ;&#1074;&#1072;&#1087;&#1088;&#1086;& ;#1083;&#1076;&#1078;&#1103;&#1095;&#108 9;&#1084;&#1080;&#1090;
> So I guess my OS is OK with the character sets...
> I really don't know how I can do that.
> Basically, I have a Table Viewer, I have a label provider, which also implements ITableFontProvider and I just would like to be able to display Cyrillic characters in my table when some informations have to be displayed in Cyrillic...


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: ITableFontProvider and System fonts [message #324102 is a reply to message #324081] Thu, 17 January 2008 11:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

For information, instead of real cyrillic characters, my table displays characters like this:
ÇÎÍÀ 1 - ÂÅÐÕÍÅÅ ÏÅÐÅÊÐÛÒÈÅ 2 ÝÒÀÆÀ
Re: ITableFontProvider and System fonts [message #324108 is a reply to message #324066] Thu, 17 January 2008 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

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 #324110 is a reply to message #324108] Thu, 17 January 2008 11:43 Go to previous messageGo to next message
Eclipse UserFriend
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...


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: ITableFontProvider and System fonts [message #324112 is a reply to message #324110] Thu, 17 January 2008 11:45 Go to previous messageGo to next message
Eclipse UserFriend
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...
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: ITableFontProvider and System fonts [message #324124 is a reply to message #324112] Thu, 17 January 2008 12:22 Go to previous messageGo to next message
Eclipse UserFriend
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 #324175 is a reply to message #324124] Fri, 18 January 2008 08:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

I succeeded in displaying Cyrillic characters doing this:
when I know that a String must be displayed with Cyrillic characters, I tell the JRE that this String has been written with cyrillic characters at first.
I do that in my label provider with that kind of method:
<code>
public static String getCyrillicString(String str) {
String cStr = str;
byte[] strData = str.getBytes();
try {
cStr = new String(strData, "Cp1251");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cStr;
}
</code>
and I return the returned String in the getColumnText() of my LabelProvider.
"Cp1251" is the Windows Cyrillic encoding style (the application I work on is only designed for Windows). I got it on this page:
http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc. html
Re: ITableFontProvider and System fonts [message #324176 is a reply to message #324175] Fri, 18 January 2008 08:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This seems to me to be further indication that the string you started
with was not properly decoded to actually contain Cyrillic characters.
Likely you read the bytes in using the wrong encoding and ended up with
the wrong characters. So your str.getBytes() will re encode the string
as bytes using the default encoding of the JRE which is likely to be
some ISO Latin type of thing (i.e., you probably get the bytes you read
incorrectly originally) and then you re decode those bytes using the
proper decoding this type. This seems like a complete hack. I think
you'd be better to go back and figure out where the original string came
from and figure why it wasn't read in and decoded with the proper
encoding in the first place...


C. BOUDJENNAH wrote:
> I succeeded in displaying Cyrillic characters doing this:
> when I know that a String must be displayed with Cyrillic characters, I tell the JRE that this String has been written with cyrillic characters at first.
> I do that in my label provider with that kind of method:
> <code>
> public static String getCyrillicString(String str) {
> String cStr = str;
> byte[] strData = str.getBytes();
> try {
> cStr = new String(strData, "Cp1251");
> } catch (UnsupportedEncodingException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return cStr;
> }
> </code>
> and I return the returned String in the getColumnText() of my LabelProvider.
> "Cp1251" is the Windows Cyrillic encoding style (the application I work on is only designed for Windows). I got it on this page:
> http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc. html
>
Re: ITableFontProvider and System fonts [message #324178 is a reply to message #324176] Fri, 18 January 2008 09:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

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?
Re: ITableFontProvider and System fonts [message #324179 is a reply to message #324060] Fri, 18 January 2008 10:08 Go to previous messageGo to next message
Eclipse UserFriend
Sorry to hijack your thread somewhat, but can you post a small example or link showing how plumbed in an ITableFontProvider to a TableViewer please? I wanted to use that and a ITableColorProvider.

Thanks in advance
Re: ITableFontProvider and System fonts [message #324181 is a reply to message #324179] Fri, 18 January 2008 10:23 Go to previous messageGo to next message
Eclipse UserFriend
Toby Weston schrieb:
> Sorry to hijack your thread somewhat, but can you post a small example or link showing how plumbed in an ITableFontProvider to a TableViewer please? I wanted to use that and a ITableColorProvider.
>
> Thanks in advance

http://wiki.eclipse.org/JFaceSnippets

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: ITableFontProvider and System fonts [message #324183 is a reply to message #324179] Fri, 18 January 2008 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

When I tested that, I just implemented ITableFontProvider in my ITableLabelProvider. Then I had to implement the getFont() method.
But I disabled it because I found a way to do what I want without using this...
But, as I think about it, the fact that it works is kind of weird because I never say to my viewer : "This is your font provider"...
But I don't remember having done something else...
Re: ITableFontProvider and System fonts [message #324193 is a reply to message #324178] Fri, 18 January 2008 13:32 Go to previous messageGo to next message
Eclipse UserFriend
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.&nbsp; I think they are being loaded
incorrectly or stored incorrectly.&nbsp; 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.&nbsp; 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.&nbsp; 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>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Performs escape encoding on the given string so that it
can be represented using 1-byte characters.</small><br>
<small>&nbsp;&nbsp; * Any characters higher than 0xFF are replaced with an
escape of the form \\uXXXX, where XXXX is the</small><br>
<small>&nbsp;&nbsp; * four-digit hex representation of the Unicode code point.</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static String unicodeEscapeEncode(String unicode)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; StringBuilder result = new StringBuilder(unicode.length());</small><br>
<small>&nbsp;&nbsp;&nbsp; for (int i = 0, size = unicode.length(); i &lt; size; ++i)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char character = unicode.charAt(i);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (character &gt; '\u00ff')</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; result.append("\\u");</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; String hex = Integer.toString(character, 16);</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for (int j = hex.length(); j &lt; 4; ++j)</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; result.append("0");</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; result.append(hex);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; result.append(character);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; return result.toString();</small><br>
<small>&nbsp; }</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--
Re: ITableFontProvider and System fonts [message #324265 is a reply to message #324181] Mon, 21 January 2008 14:58 Go to previous messageGo to next message
Eclipse UserFriend
&gt; Toby Weston schrieb:
&gt; > Sorry to hijack your thread somewhat, but can you
&gt; post a small example or link showing how plumbed in
&gt; an ITableFontProvider to a TableViewer please? I
&gt; wanted to use that and a ITableColorProvider.
&gt; >
&gt; > Thanks in advance
&gt;
&gt; http://wiki.eclipse.org/JFaceSnippets
&gt;
&gt; Tom
&gt;

Sorry Tom, probably missing the obvious but I can't see the ITAbleFontProvider example...
Re: ITableFontProvider and System fonts [message #324266 is a reply to message #324265] Mon, 21 January 2008 15:00 Go to previous messageGo to next message
Eclipse UserFriend
&gt;
&gt; Sorry Tom, probably missing the obvious but I can't
&gt; see the ITAbleFontProvider example...

a ha! I *am* missing the obvious! This seems to be the one...

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java ?view=markup

Thanks
Re: ITableFontProvider and System fonts [message #324269 is a reply to message #324266] Mon, 21 January 2008 15:52 Go to previous messageGo to next message
Eclipse UserFriend
Jup. But if your are on 3.3 I'd suggest using ColumnLabelProvider.

http://wiki.eclipse.org/JFaceSnippets#Snippet024TableViewerE xploreNewAPI

I need to advertise my work ;-)

Tom

Toby Weston schrieb:
> &gt;
> &gt; Sorry Tom, probably missing the obvious but I can't
> &gt; see the ITAbleFontProvider example...
>
> a ha! I *am* missing the obvious! This seems to be the one...
>
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java ?view=markup
>
> Thanks


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: ITableFontProvider and System fonts [message #324285 is a reply to message #324269] Tue, 22 January 2008 04:19 Go to previous message
Eclipse UserFriend
&gt;
&gt; I need to advertise my work ;-)
&gt;
&gt; Tom
&gt;

Thanks Tom, that's awesome. SWT and JFace so rock, I love 'em! :)
Previous Topic:running an external process
Next Topic:Custom Cell Editors in TableViewer
Goto Forum:
  


Current Time: Sat Jul 12 15:40:14 EDT 2025

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

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

Back to the top