1

I'm trying to display some Unicode (Cyrillic, actually) using XmLabel and a server-side XLFD font (-monotype-arial-medium-r-normal--*-90-*-*-p-*-iso10646-1). Whenever I use XmStringCreate() or XmStringCreateLtoR() as an XmString factory, the result meets my expectations.

When I try to use XmStringGenerate() factory, however, passing in either XmMULTIBYTE_TEXT for a multi-byte Unicode string, or XmWIDECHAR_TEXT for a wide string, garbage is rendered onto the screen, regardless of the font used (I tried both UTF-8 and single-byte Cyrillic server-side fonts).

The result can be seen below (the 1st 2 lines are ok, 2nd through 6th labels were created with XmStringGenerate() and are obviously not ok):

enter image description here

The complete code (requires Motif 2.1+ and a C99-compliant compiler) is here.

Can anyone suggest a working XmStringGenerate() example suitable for displaying Unicode characters (not just ISO-8859-1)?

Bass
  • 4,977
  • 2
  • 36
  • 82
  • 1
    The ida prigram from fbida https://www.kraxel.org/releases/fbida/ uses XmStringGenerate and it works with UTF-8 text on my system. I'm not well versed in Motif so I can't tell you what exactly is different between it and your code. – n. m. could be an AI Dec 19 '15 at 11:08
  • @n.m.: Taken a look at `ida` source code. Basically, what I've found so far is `XmCHARSET_TEXT` can be used to display a multi-bute string in a locale-independent way: `XmStringGenerate(mbs, "UTF-8", XmCHARSET_TEXT, NULL)`. `ida`, on the other hand, uses `XmStringGenerate(mbs, NULL, XmMULTIBYTE_TEXT, NULL)`, but this works for Unicode locales only (setting `LANG` to `C` breaks the program unless it overrides the locale via `setlocale()` when started). – Bass Dec 21 '15 at 12:09
  • 1
    Yes, multibyte text is only UTF-8 if your locale is UTF-8. You know there are other locales, some with their own multibyte encodings different from UTF-8. – n. m. could be an AI Dec 21 '15 at 12:20
  • @n.m.: Thanks for the answer. Yes I'm aware of other multibyte encodings. I'll put my question differently then. Is it possible to use `XmMULTIBYTE_TEXT` and/or `XmWIDECHAR_TEXT` in a locale-independent way? – Bass Dec 21 '15 at 12:49
  • 1
    I'm almost sure that no it isn't possible with multibyte text. In practice widechar text is almost always UCS-4, so it could work. – n. m. could be an AI Dec 21 '15 at 13:09

1 Answers1

1

XmMULTIBYTE_TEXT is locale-dependent, as n.m suggested, and, aside from CJK (i. e. for Roman and Slavic languages), can only be used in UTF-8 locales. Core X11 fonts can be specified as either fonts (XmFONT_IS_FONT):

-monotype-arial-medium-r-normal--*-90-*-*-p-*-iso10646-1

or font sets (XmFONT_IS_FONTSET):

-monotype-arial-medium-r-normal--*-90-*-*-p-*-*-*:

Speaking of XmWIDECHAR_TEXT mode, it seems impossible to specify a proper font with an explicit encoding, but setting a font set instead works perfectly for Motif 2.1 through 2.3.

Bass
  • 4,977
  • 2
  • 36
  • 82