Thursday, July 31, 2008

Creating multi font string in Xmotif.

In Xmotif the strings created are compound string i.e. they themselves carry some more information such as font, font size with the text. So to create the multifont string what you have to do is actually concatenate strings of different fonts to form a single multi font string.

In this exapmle we will create a string as shown.

At Larsen & Toubro Infotech Limited we strive to achieve.

XmString s1,s2,s3,text,tmp;

String string1 = “At ",

string2 = "Larsen & Toubro Infotech Limited ",

string3 = "we strive to achieve";

//Create compound strings with different fonts.

s1 = XmStringCreate(string1,"NORMALFONT");

s2 = XmStringCreate(string2,"BOLDFONT");

s3 = XmStringCreate(string3,"NORMALFONT");

//Now concatenate the strings to form a single string.

tmp = XmStringConcat(s1,s2);

text= XmStringConcat(tmp,s3);

Now the multi font compound string “text” is created which can be used for a label.

XtVaSetValues(label,XmNlabelString,text,NULL) ;

For this you have to mention the font list to be used. You can use the “fontlist” property of the widget in which this multifont list is to be displayed, or you can mention it in the .Xdefaults file. I’ll suggest to use the .Xdefaults file for this purpopse as the fonts then can be changed without recompilation of the program.

Just add this to your .Xdefaults file.

Nameof the application*fontList: -*-courier-bold-r-*--12-*=BOLDFONT,\


No comments:


My Blog List