LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2005, 08:23 AM   #1
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Rep: Reputation: 0
About:XtSetArg--->XmNfontList. HELP!!!


In my programming,I write below:

n=0;

XtSetArg(args[n],XmNwidth,250);n++;
XtSetArg(args[n],XmNheight,150);n++;
XtSetArg(args[n],XmNfontList,"-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1");n++;

mybutton=XmCreatePushButton(parent_f,"parent_f",args,n);


when I compile my programming,there is an error,below:
X Error of failed request: BadFont (invalid Font parameter)
Major opcode of failed request: 55 (X_CreateGC)
Resource id in failed request: 0x1200017
Serial number of failed request: 153
Current serial number in output stream: 160

Help!!!!
i know there is an error in :XtSetArg(args[n],XmNfontList,"-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1").
How do I correct it?
Help !!!!!!!
thanks.

gaoeh
 
Old 11-03-2005, 09:58 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Suggestion -

Did you do an "xlsfonts|grep 'adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1' to verify that you actually have that font on your system?
 
Old 11-04-2005, 09:19 AM   #3
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Yes!
I do the "xlsfonts|grep 'adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1' ,the font is exist.

how can I do whit it?
 
Old 11-04-2005, 09:40 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
OK, then it sounds like the problem is that you're giving it a "font", but you're telling Xt to expect a "font list".

Please try this:
Code:
#include <X11/Intrinsic.h>
        #include <Xm/Xm.h>
        #include <Xm/Label.h>


        main(int argc, char *argv[])
        {
          Widget toplevel, msg;
          Arg al[10];
          int ac;

          toplevel=XtInitialize(argv[0],"",NULL,0,&argc,argv);

          ac=0;
          XtSetArg(al[ac],XmNlabelString,
                XmStringCreate("hello",XmSTRING_DEFAULT_CHARSET)); ac++;
          msg=XtCreateManagedWidget("msg",xmLabelWidgetClass,toplevel,al,ac);

          /* declare variables and hook in a different font. */
          {
            XFontStruct *font=NULL;
            XmFontList fontlist=NULL;
            char *namestring=NULL;

            namestring="*6x10*";
            font=XLoadQueryFont(XtDisplay(msg),namestring);
            fontlist=XmFontListCreate(font,XmSTRING_DEFAULT_CHARSET);
            ac=0;
            XtSetArg(al[ac],XmNfontList,fontlist); ac++;
            XtSetValues(msg,al,ac);
          }

          XtRealizeWidget(toplevel);
          XtMainLoop();
        }
Cheers .. PSM
 
Old 11-04-2005, 12:27 PM   #5
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
OK!paulsm4,thanks!
now the master question is resolved.but there is still a question.My programming is below:
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>

void main();
void activateCB();
XmString btn_text;

void main(argc,argv)
unsigned int argc;
unsigned **argv;
{
Widget toplevel;
Widget mybutton;
XtAppContext app_context;
Arg args[10];
int n;

toplevel=XtAppInitialize(&app_context,"XMdemos",NULL,0,&argc,argv,NULL,NULL,0);
btn_text=XmStringCreateLtoR("中国北京",XmSTRING_DEFAULT_CHARSET); /*中国北京 is a Chinese string.*/

n=0;
XtSetArg(args[n],XmNlabelString,btn_text);n++;
mybutton=XtCreateManagedWidget("button",xmPushButtonWidgetClass,toplevel,args,n);
XtAddCallback(mybutton,XmNactivateCallback,activateCB,NULL);

XFontStruct *font=NULL;
XmFontList fontlist=NULL;
char *namestring=NULL;
namestring="-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1"; /* this is a Chinese font */
font=XLoadQueryFont(XtDisplay(mybutton),namestring);
fontlist=XmFontListCreate(font,XmSTRING_DEFAULT_CHARSET);

n=0;
XtSetArg(args[n],XmNfontList,fontlist);n++;
XtSetArg(args[n],XmNwidth,250);n++;
XtSetArg(args[n],XmNheight,150);n++;
XtSetValues(mybutton,args,n);

XtRealizeWidget(toplevel);
XtAppMainLoop(app_context);
}

void activateCB(w,client_data,call_data)
Widget w;
caddr_t client_data;
caddr_t call_data;
{
printf("PushButton selected!\n");
}



When i run my programming,what the "mybutton"display is not "中国北京".
How can I do whit it? thanks!!!!!
I come from China.
Can you tell me another Chinese_font's name?
 
Old 11-04-2005, 12:41 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Maybe use XmStringCreateLocalized() as :
Code:
/*中国北京 is a Chinese string.*/
btn_text = XmStringCreateLocalized("中国北京", XmFONTLIST_DEFAULT_TAG);
 
Old 11-04-2005, 09:55 PM   #7
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
I do as you said.
"btn_text=XmStringCreateLtoR("中国北京",XmSTRING_DEFAULT_CHARSET);" is be changed as "btn_text = XmStringCreateLocalized("中国北京", XmFONTLIST_DEFAULT_TAG);"

When I compile my programming,the result is below:
[cring@localhost cring]$ cc -o xmbutton xmbutton.c -L/usr/X11R6/lib -lXm -lXt -lX11
xmbutton.c: In function `main':
xmbutton.c:19: warning: passing arg 6 of `XtAppInitialize' from incompatible pointer type
xmbutton.c:20: too many arguments to function `XmStringCreateLocalized'
xmbutton.c:12: warning: return type of `main' is not `int'
[cring@localhost cring]$

when I "man XmStringCreateLocalized",I know XmStringCreateLocalized has only one parameter which is "char *name".

Your suggestion is helpful!thanks.
 
Old 11-05-2005, 04:14 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You right, my bad...
Code:
btn_text = XmStringCreateLocalized("中国北京");
and
Code:
btn_text = XmStringCreate("中国北京", XmFONTLIST_DEFAULT_TAG);
are equivalent

Also, try to change :
Code:
void main(argc,argv)
unsigned int argc;
unsigned **argv;
to :
Code:
void main(int argc, char * argv[])
 
Old 11-05-2005, 04:23 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Here is a version that compiles fine :
Code:
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>

void activateCB();
XmString btn_text;

int main(int argc, char * argv[]) {
	Widget toplevel;
	Widget mybutton;
	XtAppContext app_context;
	XFontStruct *font=NULL;
	XmFontList fontlist=NULL;
	char *namestring=NULL;
	
	Arg args[10];
	int n;

	toplevel=XtAppInitialize(&app_context,"XMdemos",NULL,0,&argc,argv,NULL,NULL,0);
	btn_text=XmStringCreateLocalized("中国北煩"); /*中国北煩 is a Chinese string.*/

	n=0;
	XtSetArg(args[n],XmNlabelString,btn_text);n++;
	mybutton=XtCreateManagedWidget("button",xmPushButtonWidgetClass,toplevel,args,n);
	XtAddCallback(mybutton,XmNactivateCallback,activateCB,NULL);

	namestring="-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1"; /* this is a Chinese font */
	font=XLoadQueryFont(XtDisplay(mybutton),namestring);
	fontlist=XmFontListCreate(font,XmSTRING_DEFAULT_CHARSET);

	n=0;
	XtSetArg(args[n],XmNfontList,fontlist);n++;
	XtSetArg(args[n],XmNwidth,250);n++;
	XtSetArg(args[n],XmNheight,150);n++;
	XtSetValues(mybutton,args,n);

	XtRealizeWidget(toplevel);
	XtAppMainLoop(app_context);
	return 0;
}

void activateCB(Widget w,
		caddr_t client_data, 
		caddr_t call_data) 
{
	printf("PushButton selected!\n");
}
cc -o xmbutton xmbutton.c -I/usr/X11R6/include -L/usr/X11R6/lib -lXm -lXt -lX11
 
Old 11-05-2005, 07:25 AM   #10
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
keefaz:I do as you said,and I also run the version that you compiles fine.but the result is no right,the character displayed on "mybutton" is"涓????含",this is not right.the character displayed on mybutton should be "中国北京".

Is there something wrong with my Linux system.My system is Red Hat Linux 9.0.
the font "-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1" is not on my RHL9.0 system,later I install it on my OS.The font-file I get is from Tru64 UNIX system.

Can you give me some advice? Thanks.
 
Old 11-05-2005, 07:36 AM   #11
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
The font_file of "-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1" is:adecw_screen_gb2312_16_18_75.pcf which I get from Tru64 Unix system.I install it on Red Hat Linux9.0.
When I run command below:
-----------------------
[cring@localhost cring]$ xlsfonts | grep screen
adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1
[cring@localhost cring]$
-----------------------
the font is indeed in my RHL9.0 system.

Help!thanks.
 
Old 11-05-2005, 07:38 AM   #12
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Did you set your locale, what does say :
Code:
echo $LANG
from a console prompt ?
 
Old 11-05-2005, 08:57 PM   #13
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
-------------------------
[cring@localhost cring]$ echo $LANG
zh_CN.GB18030
[cring@localhost cring]$
-------------------------

I guess the problem is as you said.
In my RHL9.0 system,the context of /etc/sysconfig/i18n is below:
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en:ja_JP.eucJP:ja_JP:ja"
SYSFONT="lat0-sun16"
SYSFONTACM="8859-15"

Is the problem in here?How can I add my fontname of ""-adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1" to my system LANG?

Thanks very much!!!
 
Old 11-06-2005, 12:15 AM   #14
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Setting the environment variable "$LANG" sets the "locale". The locale helps determine which character set will be used in your Xt/Motif application (it does sound like you're using Motif, aren't you?)

Here are a couple of links that might help:

http://www.cs.arizona.edu/computer.h...coseprg_9.html

http://docs.hp.com/en/B1171-90155/ch04s01.html

http://www.linuxforum.net/chinese/doc/i18n/DOCU_007.HTM
 
Old 11-06-2005, 03:30 AM   #15
gaoeh
LQ Newbie
 
Registered: Oct 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks a lot.I will try my best to understand what you said.
I believe I must be understand this about font problems.
I will see you give me the materials in above link.
Thanks a lot!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration