Technical article 100780

How do I use fontset to display multibyte characters?

OpenServer 5.0.0

Written · Last revised

Problem

I want to use fontsets to display multibyte characters in Motif Widgets.

Solution

The attached example program creates a Labelwidget, a Textwidget
and a Pushbutton in a Bulletinboard Widget.  A Shift-JIS encoded
string called KANJI is to be displayed in all those widgets.
Compile this example with:
$  cc -b elf -o main main.c -lXm -lXt -lX11 -lsocket
and start it with:
$ LANG=ja_JP.SJIS ./main -xrm "*fontList : \
-jis-fixed-medium-r-normal--16-110-100-100-c-160-jisx0208.1983-0\;\
-sony-fixed-medium-r-normal--16-120-100-100-c-80-jisx0201.1976-0\;\
-adobe-helvetica-bold-o-normal--17-120-100-100-p-92-iso8859-1\:"
Note: This command line specifies a "fontList" which consists of
one fontset.  It is only for demonstration purposes that this
resource is loaded from the command line.
------------------------ Example program starts here ---------------------------
#include        <Xm/Xm.h>
#include        <Xm/Text.h>
#include        <Xm/Label.h>
#include        <Xm/BulletinB.h>
#include        <Xm/PushB.h>
#define MotifString( A ) ( XmStringLtoRCreate( (A), XmSTRING_DEFAULT_CHARSET ) )
/* Shift-JIS encoded -  see page 73 of "Japanese Information Processing/Ken Lunde" */
#define KANJI "\202\251\202\310\212\277\216\232\nThis string means kana [and] kanji"
main(argc, argv)
int     argc;
char    *argv[];
{
        XtAppContext    app_con;
        Widget          top,text, label, bulletin, button;
        XFontSet        fontset;
XtSetLanguageProc(NULL,NULL,NULL);

top=XtVaAppInitialize( &app_con, "Text", NULL, 0, &argc, argv, NULL, NULL );

bulletin=XtVaCreateManagedWidget("bulletin", xmBulletinBoardWidgetClass,
                                top,
                                XmNwidth, 500,
                                XmNheight, 400,
                                NULL);
label=XtVaCreateManagedWidget("label", xmLabelWidgetClass,
                                bulletin,
                                XmNx, 0,
                                XmNy, 0,
                                XmNlabelString, MotifString(KANJI),
                                NULL);
text=XtVaCreateManagedWidget("text", xmTextWidgetClass,
                                bulletin,
                                XmNx, 0,
                                XmNy, 100,
                                XmNvalue, KANJI,
                                XmNrows, 5,
                                XmNwordWrap, True,
                                XmNeditMode, XmMULTI_LINE_EDIT,
                                NULL);
button=XtVaCreateManagedWidget("button", xmPushButtonWidgetClass,
                                bulletin,
                                XmNx, 0,
                                XmNy, 250,
                                XmNlabelString, MotifString(KANJI),
                                NULL);
        XtRealizeWidget(top);
        XtAppMainLoop(app_con);
}
------------------------ Example program ends here ---------------------------

See also

XmFontList(Xm); Ken Lunde's Japanese Information Processing, O'Reilly & Associates Inc.

From the Xinuos technical article database, record 100780. Reproduced with permission. The original is at www.sco.com/ta/100780, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.