- return NULL;
-}
-#endif // HAVE_STRCASESTR
-
-
-static const char *getFontElement(const char *pattern, char *buf,
- int bufsiz, ...) {
- const char *p, *v;
- char *p2;
- va_list va;
-
- va_start(va, bufsiz);
- buf[bufsiz-1] = 0;
- buf[bufsiz-2] = '*';
- while((v = va_arg(va, char *)) != NULL) {
- p = strcasestr(pattern, v);
- if (p) {
- strncpy(buf, p+1, bufsiz-2);
- p2 = strchr(buf, '-');
- if (p2) *p2=0;
- va_end(va);
- return p;
- }
- }
- va_end(va);
- strncpy(buf, "*", bufsiz);
- return NULL;
-}
-
-
-static const char *getFontSize(const char *pattern, int *size) {
- const char *p;
- const char *p2=NULL;
- int n=0;
-
- for (p=pattern; 1; p++) {
- if (! *p) {
- if (p2!=NULL && n>1 && n<72) {
- *size = n; return p2+1;
- } else {
- *size = 16; return NULL;
- }
- } else if (*p=='-') {
- if (n>1 && n<72 && p2!=NULL) {
- *size = n;
- return p2+1;
- }
- p2=p; n=0;
- } else if (*p>='0' && *p<='9' && p2!=NULL) {
- n *= 10;
- n += *p-'0';
- } else {
- p2=NULL; n=0;
- }
- }
-}
-
-
-XFontSet BScreen::createFontSet(const string &fontname) {
- XFontSet fs;
- char **missing, *def = "-";
- int nmissing, pixel_size = 0, buf_size = 0;
- char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
-
- fs = XCreateFontSet(blackbox->getXDisplay(),
- fontname.c_str(), &missing, &nmissing, &def);
- if (fs && (! nmissing))
- return fs;
-
- const char *nfontname = fontname.c_str();
-#ifdef HAVE_SETLOCALE
- if (! fs) {
- if (nmissing) XFreeStringList(missing);
-
- setlocale(LC_CTYPE, "C");
- fs = XCreateFontSet(blackbox->getXDisplay(), fontname.c_str(),
- &missing, &nmissing, &def);
- setlocale(LC_CTYPE, "");
- }
-#endif // HAVE_SETLOCALE
-
- if (fs) {
- XFontStruct **fontstructs;
- char **fontnames;
- XFontsOfFontSet(fs, &fontstructs, &fontnames);
- nfontname = fontnames[0];
- }
-
- getFontElement(nfontname, weight, FONT_ELEMENT_SIZE,
- "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
- getFontElement(nfontname, slant, FONT_ELEMENT_SIZE,
- "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
- getFontSize(nfontname, &pixel_size);
-
- if (! strcmp(weight, "*"))
- strncpy(weight, "medium", FONT_ELEMENT_SIZE);
- if (! strcmp(slant, "*"))
- strncpy(slant, "r", FONT_ELEMENT_SIZE);
- if (pixel_size < 3)
- pixel_size = 3;
- else if (pixel_size > 97)
- pixel_size = 97;
-
- buf_size = strlen(nfontname) + (FONT_ELEMENT_SIZE * 2) + 64;
- char *pattern2 = new char[buf_size];
- sprintf(pattern2,
- "%s,"
- "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
- "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
- nfontname, weight, slant, pixel_size, pixel_size);
- nfontname = pattern2;
-
- if (nmissing)
- XFreeStringList(missing);
- if (fs)
- XFreeFontSet(blackbox->getXDisplay(), fs);
-
- fs = XCreateFontSet(blackbox->getXDisplay(), nfontname, &missing,
- &nmissing, &def);