Unicode support

I would like to port a Motif app that uses its own nonstandard character encodings to use Unicode now that there are fonts available that provide all the glyphs it needs. I am tantalisingly close to success in a test program - I can get a text widget to render all but 22 of the 132 glyphs I need using the GNU FreeFont TrueType fonts. However, the Motif text widget displays the offending 22 as outline rectangles even though they are definitely defined in the font. An example is the character with code 0x2a3e which won't display properly even the the character with code 0x2a04 will.

I am pretty sure that my test program is not at fault - if I put what is in its text widget into a file and look at it using the same font with other tools that understand UTF-8, the result looks fine. E.g. the screenshot at http://dl.dropbox.com/u/34693999/Screen%20shot%202011-08-15%20at%2017.24... shows the same UTF-8 charactera viewed with the FreeMono font using my test program and Apple's textedit I get similar results on Linux - my test program won't render the glyphs but Gnome Terminal will.

Any help very much appreciated.

Regards,

Rob.


dpeterc

dpeterc's picture

Hello Rob, My experience

Hello Rob,

My experience with OpenMotif's UTF-8 support would suggest that the font you wish to use does not contain the offending characters.
The fact that some other toolkit shows all the characters in that font is not conclusive, since most other toolkits handle missing characters in more graceful way, and use fallback font to display them.

The font situation on Linux is still so desperate that modern distributions like Ubuntu or OpenSUSE do not ship with a single font capable of showing Simplified Chinese and iso-8859-1..16, all within one font. And if Chinese is real hard, there is no real excuse for not having all iso-8859-1..16 within at least one utf8 font.

If you do not believe me that the font you try to use in Motif does not contain the missing characters, try drawing them directly with Xft library.
Here is a sample skeleton code:
#include
XftFont *fXFT;
XftDraw *xftd=NULL;
XGlyphInfo glyphinfo;
XftColor blackXFT;

fXFT = XftFontOpenName(display, screen, fontName);
xftd = XftDrawCreate(display, window, visual, cmap);
XftColorAllocName(xinfo.dpy, xinfo.visual, xinfo.cmap, "black", &blackXFT);

XftDrawStringUtf8(xftd, &blackXFT, fXFT, textX, textY, (XftChar8 *) labelStr, strlen(labelStr));
XftDrawDestroy(xftd);

If you need some other code snippets for UTF support on Motif, like font selection of available XFT fonts as drop down menu, let me know.
Here is the demo version of my software
http://www.arahne.si/download/software-demo/104.html
run ArahWeave, Files > Save setup, Appearance tab, and there you can choose the XFT font, size and style.
You need to restart program to try new font, but language change is immediate, without restart ... assuming font has all the characters :-(


RobArthan

RobArthan's picture

Many thanks and yes, I do

Many thanks and yes, I do believe you. I didn't try your sample code (what was that #include?), but I did have a look at the font with fontforge and it doesn't have the glyphs in question. I didn't appreciate that Apple's font rendering system and also GTK would both be so clever as to find a font that works. Is there no way to get Motif to handle missing glyphs nicely?

The situation with mathematical symbols seems to be every bit as bad as the situation you describe with Chinese.

Regards,

Rob.


dpeterc

dpeterc's picture

The include

The include was
include
(hash gets eaten by the forum cms)

I am pretty sure that Motif does not do glyph replacement automatically, and there is no way to force it (other than patching the code).
At present, it can only be done by opening the font with Xft library and checking for specific glyph in a font by XftFontCheckGlyph
http://linux.die.net/man/3/xft

Best regards,

Dušan


dpeterc

dpeterc's picture

one more trial of

one more trial of include
include X11/Xft/Xft.h


dpeterc

dpeterc's picture

I have followed my own

I have followed my own advice and have implemented glyph checking in font selection, so user can only select the font, which contains the glyphs needed for currently selected language. I have used
XftCharExists(display, fontXFT, unicodeGlyphIndex)
and this is how it looks in the interface
http://www.shrani.si/f/1u/BJ/3sJcKYav/fontselection.png