Пример #1
0
int
main(int argc, char **argv)
{
#ifdef LESSTIF_VERSION
  Widget toplevel;
  XtAppContext app;
  XmFontList fontlist;
  XmString xmstr1 = XmStringCreate("Here is a ", "MY_FONT1");
  XmString xmstr2 = XmStringCreate("different font", "MY_FONT");
  char buf[] = { 0xdf, 0x80, 0x06, 0x00, 0x01, 0x00 };
  XmStringContext context;
  char *text;
  XmStringCharSet cs;
  XmStringDirection dir;
  Boolean sep;

  XmString xmstr = XmStringConcat(xmstr1, xmstr2);

  XtSetLanguageProc(NULL, NULL, NULL);

  toplevel = XtVaAppInitialize(&app, "Label", NULL, 0, &argc, argv, NULL, NULL);

  fontlist = XmFontListAppendEntry(NULL,
			   XmFontListEntryCreate("MY_FONT",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));

  fontlist = XmFontListAppendEntry(fontlist,
			   XmFontListEntryCreate("MY_FONT1",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1")));

  asn1_dump((unsigned char *)xmstr);

  printf("SINGLE SEGMENT\n");
  text = NULL;
  cs = "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1";
  _XmStringSingleSegment(xmstr, &text, &cs);
  printf("text: %s cs: %s\n", text ? text : "(empty)", cs ? cs : "(empty)");

  if (_XmStringIsXmString((XmString)buf))
	printf("IS STRING\n");
  else
	printf("ISN'T STRING\n");

  asn1_dump((unsigned char *)buf);

  XmStringInitContext(&context, xmstr);
  while (XmStringGetNextSegment(context, &text, &cs, &dir, &sep)) {
    printf("%s %s %d %d\n", text ? text : "(null)", cs ? cs : "(null)",
	   dir, sep);
  }
  XmStringFreeContext(context);

  printf("current charset: %s\n", _XmStringGetCurrentCharset());
#endif
  exit(0);
}
Пример #2
0
/*
 * fetch the first text 'segment' of the external TCS that matches the given
 * char set.
 */
Boolean 
XmStringGetLtoR(
  XmString string,
  XmStringTag tag,
  char **text )
{
  XmStringContext context;
  char * t;
  XmStringTag c, curtag = NULL; 
  XmStringDirection d;
  Boolean s, is_local = FALSE, done = FALSE, is_default = FALSE;
  
  _XmProcessLock();
  if (!string) {
	_XmProcessUnlock();
	return(FALSE);
  }
  if (!tag) {
	_XmProcessUnlock();
	return (FALSE);
  }
  
  if ((tag == XmFONTLIST_DEFAULT_TAG) || 
      (strcmp(tag, XmFONTLIST_DEFAULT_TAG) == 0))
    is_local = TRUE; 
  
  *text = NULL;				  /* pre-condition result */
  
  if (!is_local)
    {
      if ((strcmp(tag, XmSTRING_DEFAULT_CHARSET) == 0))
	{
	  curtag = _XmStringGetCurrentCharset();
	  is_default = TRUE;
	}
      else curtag = tag;
    }
  
  XmStringInitContext (&context, string);
  
  while ( ! done)
    {
      if (XmStringGetNextSegment (context, &t, &c, &d, &s))
	{
	  if (c && ((d == XmSTRING_DIRECTION_L_TO_R) ||
		    (d == XmSTRING_DIRECTION_UNSET)) &&
	      (((is_local || is_default) && 
		((c == XmFONTLIST_DEFAULT_TAG) || 
		 (strcmp(c, XmFONTLIST_DEFAULT_TAG) == 0) ||
		 (strcmp(c, _XmStringGetCurrentCharset()) == 0))) ||
	       (curtag && (strcmp (c, curtag) == 0))))
	    {
	      *text = t;		  /* OK, pass text to caller */
	      done = TRUE;
	    }
	  else
	    XtFree (t);			  /* not this text */
	  
	  if (c)
	    XtFree (c);			  /* always dump charset */
	}
      else
	done = TRUE;
    }
  
  XmStringFreeContext (context);
  _XmProcessUnlock();
  return (*text != NULL);
}