/* * main.c * */ int main (int argc, char *argv[]) { int nFonts; char **szaFontNames; int i; /* --- Initialize GTK. Needed for the GDK_DISPLAY call --- */ gtk_init (&argc, &argv); /* --- Get the font names --- */ szaFontNames = XListFonts (GDK_DISPLAY (), "*", MAX_FONTS, &nFonts); /* --- Check number retrieved --- */ if (nFonts == MAX_FONTS) { /* --- They got a lot of fonts on their system. --- */ printf ("Many fonts on your system. Not displaying all."); } /* --- Display all the fonts --- */ for (i = 0; i < nFonts; i++) { /* --- Get the name --- */ printf ("%s\n", szaFontNames[i]); } XFreeFontNames (szaFontNames); return (0); }
int drawText(Display *d, int screen, Window *w, GC *gc, const char *str) { XFontStruct *font; XColor textColor; char **list; int textWidth, textHeight, textX, textY, returnNo; list = XListFonts(d, "-*-*-bold-r-normal--*-*-100-100-c-*-*", 200, &returnNo); if (returnNo) { srand(time(NULL)); static int fontIndex = rand() % returnNo; font = XLoadQueryFont(d, *(list + fontIndex)); XFreeFontNames(list); } if (!font) return -1; XParseColor(d, DefaultColormap(d, screen), text, &textColor); XAllocColor(d, DefaultColormap(d, screen), &textColor); XSetForeground(d, *gc, textColor.pixel); XSetBackground(d, *gc, WhitePixel(d, screen)); XSetFont(d, *gc, font->fid); textWidth = XTextWidth(font, str, strlen(str)); textHeight = font->ascent + font->descent; textX = (windowWidth - textWidth) / 2; textY = ((windowHeight - rectHeight) / 2 - textHeight) / 2 + textHeight / 2; XDrawImageString(d, *w, *gc, textX, textY, str, strlen(str)); return 0; }
static void okAction(Widget widget, xfselControlBlkType *ctrlBlk, XmPushButtonCallbackStruct *call_data) { char *fontPattern; char **fontName; int i; fontPattern = XmTextGetString(ctrlBlk->fontNameField); fontName = XListFonts(XtDisplay(ctrlBlk->form), fontPattern, 1, &i); XtFree(fontPattern); if (i != 1) { DialogF (DF_ERR, ctrlBlk->okButton, 1, "Font Specification", "Invalid Font Specification", "OK"); XFreeFontNames(fontName); } else { XtFree(ctrlBlk->fontName); ctrlBlk->fontName = XtMalloc(strlen(fontName[0]) + 1); strcpy(ctrlBlk->fontName, fontName[0]); XtFree(ctrlBlk->sel1); XtFree(ctrlBlk->sel2); XtFree(ctrlBlk->sel3); XFreeFontNames(fontName); XFreeFontNames(ctrlBlk->fontData); ctrlBlk->exitFlag = TRUE; } }
static void startupFont(xfselControlBlkType *ctrlBlk, const char *font) { int i; char **fontName; char part[TEMP_BUF_SIZE]; XmString str; fontName = XListFonts(XtDisplay(ctrlBlk->form), font, 1, &i); if (i == 0) { /* invalid font passed in at startup */ XFreeFontNames(fontName); return; } ctrlBlk->fontName = XtMalloc(strlen(fontName[0]) + 1); strcpy(ctrlBlk->fontName, fontName[0]); getFontPart(fontName[0], part); XFreeFontNames(fontName); str = XmStringCreate(part, XmSTRING_DEFAULT_CHARSET); XmListSetBottomItem(ctrlBlk->fontList, str); XmListSelectItem(ctrlBlk->fontList, str, TRUE); XmListSelectItem(ctrlBlk->fontList, str, TRUE); XmStringFree(str); dispSample(ctrlBlk); XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName); }
static void Realize(Widget aw, XtValueMask * value_mask, XSetWindowAttributes * attributes) { XltFontChooserWidget fc = (XltFontChooserWidget) aw; char *f = XtMalloc(256), **list; int i, j, nfonts; #define superclass (&xmMessageBoxClassRec) (*superclass->core_class.realize) (aw, value_mask, attributes); #undef superclass if (! FC_ShowDemo(fc)) return; /* Show the right font initially */ f[0] = '\0'; for (j=0; j<14; j++) { strcat(f, "-"); strcat(f, FC_Setting(fc)[j]); } if (FC_FontName(fc)) XtFree(FC_FontName(fc)); FC_FontName(fc) = f; /* How many fonts ? */ list = XListFonts(XtDisplay(fc), f, 4096, &nfonts); for (i=0; i<nfonts; i++) EnableMenu(aw, list[i]); XFreeFontNames(list); if (FC_DemoWidget(fc)) { XmFontList fl; XmFontListEntry fle; XFontSet fs; char m1[2][80], **missing = (char **)&m1[0][0]; char m2[80], *def = &m2[0]; int nmissing = 0; fs = XCreateFontSet(XtDisplay(fc), f, &missing, &nmissing, &def); if (fs != NULL) { fle = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONTSET, (XtPointer)fs); fl = XmFontListAppendEntry(NULL, fle); XtVaSetValues(FC_DemoWidget(fc), XmNfontList, fl, NULL); XmFontListEntryFree(&fle); XmFontListFree(fl); #if 0 /* Freeing the font set produces nice little core dumps */ XFreeFontSet(XtDisplay(fc), fs); /* FIX ME leak ?? */ #endif } } ShowCount(aw, nfonts); }
uint Fl_Font_::cache_xlist() { fl_open_display(); if(xlist_) return xlist_n_; xlist_ = XListFonts(fl_display, name_, 255, &xlist_n_); return xlist_n_; }
/* Find an X font with a given name, encoding, and size. */ static char * find_x_font(gx_device_X *xdev, char x11template[256], x11fontmap *fmp, const char *encoding_name, x11fontlist *fls, int xheight, bool *scalable_font) { int i; char *x11fontname = 0; int len1 = strlen(fmp->x11_name) + 1; if (fls->count == -1) { sprintf(x11template, "%s-*-*-*-*-*-*-%s", fmp->x11_name, encoding_name); fls->names = XListFonts(xdev->dpy, x11template, 32, &fls->count); } *scalable_font = false; for (i = 0; i < fls->count; i++) { const char *szp = fls->names[i] + len1; int size = 0; while (*szp >= '0' && *szp <= '9') size = size * 10 + *szp++ - '0'; if (size == 0) { *scalable_font = true; continue; } if (size == xheight) return fls->names[i]; } if (*scalable_font && xdev->useScalableFonts) { sprintf(x11template, "%s-%d-0-0-0-*-0-%s", fmp->x11_name, xheight, encoding_name); x11fontname = x11template; } return x11fontname; }
static PyObject * tkwin_ListFonts(TkWinObject *self, PyObject *args) { char *pattern; char **fontnames; int count; PyObject *list; if (!PyArg_ParseTuple(args, "s", &pattern)) return NULL; fontnames = XListFonts(Tk_Display(self->tkwin), pattern, 10000, &count); if (fontnames == NULL) count = 0; list = PyList_New(count); if (list != NULL) { int i; for (i = 0; i < count; i++) { PyObject *item = PyString_FromString(fontnames[i]); if (item == NULL) { Py_DECREF(list); list = NULL; break; } PyList_SetItem(list, i, item); } } if (fontnames != NULL) XFreeFontNames(fontnames); return list; }
void MCOldFontnode::buildtable() { if (table != NULL || MCnoui) return; int nnames; char **allnames = XListFonts(MCdpy, "-*-iso8859-1", MAXUINT2, &nnames); int i; for (i = 0 ; i < nnames ; i++) { char *sptr = allnames[i]; sptr++; if (MCU_strtok(sptr, "-") == NULL) continue; if ((sptr = MCU_strtok(NULL, "-")) == NULL) continue; MCOldFonttablenode *fnptr = findtablenode(sptr); if (fnptr == NULL) { fnptr = new MCOldFonttablenode; fnptr->name = strclone(sptr); fnptr->next = table; table = fnptr; } fnptr->addfont(); } XFreeFontNames(allnames); }
static void motFontDlgInitFamilyList(Ihandle* ih) { int i, j = 1, count = 0; char prev[1024]="", family[1024]; Ihandle* list1 = IupGetDialogChild(ih, "LIST1"); /* this will reduce the initial number */ char**font_list_str = XListFonts(iupmot_display, "-*-*-medium-r-*-*-0-0-*-*-*-*-*-*", 32767, &count); char*backup_list[32767]; if (!font_list_str) return; memcpy(backup_list, font_list_str, count*sizeof(char*)); qsort(font_list_str, count, sizeof(char*), motFontDlgCompareStr); for (i=0; i<count; i++) { motFontGetFamily(font_list_str[i], family); if (!iupStrEqual(family, prev)) /* avoid duplicates */ { IupStoreAttributeId(list1, "", j, family); strcpy(prev, family); j++; } } IupSetAttributeId(list1, "", j, NULL); memcpy(font_list_str, backup_list, count*sizeof(char*)); XFreeFontNames(font_list_str); }
Bool XftCoreAddFonts (XftFontSet *set, Display *dpy, Bool ignore_scalable) { char **xlfds; int num; int i; XftPattern *font; Bool ret; xlfds = XListFonts (dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", 10000, &num); if (!xlfds) return False; ret = True; for (i = 0; ret && i < num; i++) { font = XftXlfdParse (xlfds[i], ignore_scalable, True); if (font) { if (!XftFontSetAdd (set, font)) { XftPatternDestroy (font); ret = False; } } } XFreeFontNames (xlfds); return ret; }
// Returns true if the font exists, false otherwise static bool fontExists(const QString &fontName) { int count; char **fontNames = XListFonts(QX11Info::display(), (char*)fontName.toLatin1().constData(), 32768, &count); if (fontNames) XFreeFontNames(fontNames); return count != 0; }
// Returns TRUE if the font exists, FALSE otherwise static bool fontExists( const QString &fontName ) { int count; char **fontNames = XListFonts( QPaintDevice::x11AppDisplay(), (char*)fontName.latin1(), 32768, &count ); if ( fontNames ) XFreeFontNames( fontNames ); return count != 0; }
/*ARGSUSED*/ static void ok_callback(Widget w, SharedFontSelData *data, XmPushButtonCallbackStruct *call_data) { char *pattern; char **name; int i; pattern = XmTextGetString(data->name); name = XListFonts(XtDisplay(data->dialog), pattern, 1, &i); XtFree(pattern); if (i != 1) { do_dialog(VIM_ERROR, (char_u *)_("Error"), (char_u *)_("Invalid font specification"), (char_u *)_("&Dismiss"), 1, NULL); XFreeFontNames(name); } else { if (data->font_name) XtFree(data->font_name); data->font_name = XtNewString(name[0]); if (data->sel[ENCODING]) { XtFree(data->sel[ENCODING]); data->sel[ENCODING] = NULL; } if (data->sel[NAME]) { XtFree(data->sel[NAME]); data->sel[NAME] = NULL; } if (data->sel[STYLE]) { XtFree(data->sel[STYLE]); data->sel[STYLE] = NULL; } if (data->sel[SIZE]) { XtFree(data->sel[SIZE]); data->sel[SIZE] = NULL; } XFreeFontNames(name); data->num = 0; XFreeFontNames(data->names); data->names = NULL; data->exit = True; } }
static void ListFontNames(Display* dpy) { char **cp, **cp0; int i, count; cp = cp0 = XListFonts (dpy, "*", 256, &count); printf("%d fonts found\n", count); for(i = 0; i < count; i ++, cp++) printf("%s\n", *cp); if(count) XFreeFontNames(cp0); }
/* Removes wildcards from an XLFD. Returns \a xlfd with all wildcards removed if a match for \a xlfd is found, otherwise it returns \a xlfd. */ static QByteArray qt_fixXLFD(const QByteArray &xlfd) { QByteArray ret = xlfd; int count = 0; char **fontNames = XListFonts(QX11Info::display(), xlfd, 32768, &count); if (count > 0) ret = fontNames[0]; XFreeFontNames(fontNames); return ret ; }
/* Removes wildcards from an XLFD. Returns \a xlfd with all wildcards removed if a match for \a xlfd is found, otherwise it returns \a xlfd. */ static QCString qt_fixXLFD( const QCString &xlfd ) { QCString ret = xlfd; int count = 0; char **fontNames = XListFonts( QPaintDevice::x11AppDisplay(), xlfd, 32768, &count ); if ( count > 0 ) ret = fontNames[0]; XFreeFontNames( fontNames ); return ret ; }
static void get_list(char *pattern) { int available = nnames+1, i; char **fonts; XFontStruct *info; /* Get list of fonts matching pattern */ for (;;) { if (open_instead_of_list) { info = XLoadQueryFont (dpy, pattern); if (info) { fonts = &pattern; available = 1; XUnloadFont (dpy, info->fid); } else { fonts = NULL; } break; } if (long_list == L_MEDIUM) fonts = XListFontsWithInfo(dpy, pattern, nnames, &available, &info); else fonts = XListFonts(dpy, pattern, nnames, &available); if (fonts == NULL || available < nnames) break; if (long_list == L_MEDIUM) XFreeFontInfo(fonts, info, available); else XFreeFontNames(fonts); nnames = available * 2; } if (fonts == NULL) { fprintf(stderr, "%s: pattern \"%s\" unmatched\n", program_name, pattern); return; } font_list = (FontList *)Realloc((char *)font_list, (font_cnt + available) * sizeof(FontList)); for (i=0; i<available; i++) { font_list[font_cnt].name = fonts[i]; if (long_list == L_MEDIUM) font_list[font_cnt].info = info + i; else font_list[font_cnt].info = NULL; font_cnt++; } }
void KFontChooser::getFontList( QStrList &list, const char *pattern ) { int num; char **xFonts = XListFonts( qt_xdisplay(), pattern, 2000, &num ); for ( int i = 0; i < num; i++ ) { addFont( list, xFonts[i] ); } XFreeFontNames( xFonts ); }
int drawFont(int count, char *msg) { int x1; int y1; int i; int index; #ifdef CHANGE_FONT_SIZE int w; int h; int actual_count; char **font_list; #endif if (count <= 0) { return 0; // nothing to do } srandom(time(NULL)); XClearArea(g_disp, g_win, 0, 0, g_winWidth, g_winHeight, 0); #ifdef CHANGE_FONT_SIZE font_list = XListFonts(g_disp, "−*−courier−*−*−*−*−0−0−*−*−*−0−*−*", 2000, &actual_count); if (!font_list) { printf("actual_count=%d\n", actual_count); for (i = 0; i < actual_count; i++) { printf("%s\n", font_list[i]); } XFreeFontNames(font_list); } else { printf("XListFonts() reted NULL\n"); } #endif srandom(time(NULL)); for (i = 0, index = 0; i < count; i++) { x1 = random() % g_winWidth; y1 = random() % g_winHeight; XSetForeground(g_disp, g_gc, g_colors[index++].pixel); if (index == MAX_COLORS) { index = 0; } XDrawString(g_disp, g_win, g_gc, x1, y1, msg, strlen(msg)); XFlush(g_disp); usleep(g_delay_dur); } return 0; // nothing to do }
JFont::operator int() { if (hnd) return hnd; JFont *dest = (JFont*)JUNIX::JObjectCache[*this]; if (!dest) { char buf[256]; int count; char **fnames; static char* sweight[] = { "medium", "bold"}; static char* sstyle[] = { "r", "i"}; JString *fname = (JString*)JFontTable[name.toUpperCase()]; if (!fname) fname = &name; sprintf(buf, "*-%s-%s-%s-normal--0-0-0-0-*-iso8859-1", (char*)*fname, sweight[style & 1], sstyle[(style & 2)>>1]); if (!(fnames = XListFonts(JUNIX::theDisplay, buf, 16, &count))) { sprintf(buf, "*-%s-%s-%s-normal--0-0-*-iso8859-1", (char*)*fname, sweight[style & 1], sstyle[(style & 2)>>1]); if (!(fnames = XListFonts(JUNIX::theDisplay, buf, 16, &count))) { sprintf(buf, "*-%s-%s-normal--0-0-*-iso8859-1", sweight[style & 1], sstyle[(style & 2)>>1]); if (!(fnames = XListFonts(JUNIX::theDisplay, buf, 16, &count))) return null; }
static Lisp_Object __gtk_list_fonts_internal (const char *pattern) { char **names; int count = 0; Lisp_Object result = Qnil; names = XListFonts (GDK_DISPLAY (), pattern, MAX_FONT_COUNT, &count); while (count--) result = Fcons (build_ext_string (names [count], Qbinary), result); if (names) XFreeFontNames (names); return result; }
static int valid_font_name_p (Display *dpy, char *name) { /* Maybe this should be implemented by callign XLoadFont and trapping the error. That would be a lot of work, and wasteful as hell, but might be more correct. */ int nnames = 0; char **names = 0; if (! name) return 0; names = XListFonts (dpy, name, 1, &nnames); if (names) XFreeFontNames (names); return (nnames != 0); }
DviFontSizeList * InstallFontSizes (DviWidget dw, const char *x_name, Boolean *scalablep) { char fontNameString[2048]; char **fonts; int i, count; int size; DviFontSizeList *sizes, *new_size; XFontName fontName; unsigned int fontNameAttributes; *scalablep = FALSE; if (!XParseFontName ((XFontNameString)x_name, &fontName, &fontNameAttributes)) return 0; fontNameAttributes &= ~(FontNamePixelSize|FontNamePointSize |FontNameAverageWidth); fontNameAttributes |= FontNameResolutionX; fontNameAttributes |= FontNameResolutionY; fontName.ResolutionX = dw->dvi.display_resolution; fontName.ResolutionY = dw->dvi.display_resolution; XFormatFontName (&fontName, fontNameAttributes, fontNameString); fonts = XListFonts (XtDisplay (dw), fontNameString, 10000000, &count); sizes = 0; for (i = 0; i < count; i++) { size = ConvertFontNameToSize (fonts[i]); if (size == 0) { DisposeFontSizes (dw, sizes); sizes = 0; *scalablep = TRUE; break; } if (size != -1) { new_size = (DviFontSizeList *) XtMalloc (sizeof *new_size); new_size->next = sizes; new_size->size = size; new_size->x_name = savestr (fonts[i]); new_size->doesnt_exist = 0; new_size->font = 0; sizes = new_size; } } XFreeFontNames (fonts); return sizes; }
XFontStruct * find_best_font( Display *dpy, char **name) { char **list; int cnt; XFontStruct *s; list = XListFonts(dpy, *name, 1, &cnt); if (cnt && list) { free(*name); *name = strdup(list[0]); s = XLoadQueryFont(dpy, *name); XFreeFontNames(list); return s; } return NULL; }
void JXFontManager::GetXFontNames ( const JRegex& regex, JPtrArray<JString>* fontNames, JSortXFontNamesFn compare ) const { fontNames->CleanOut(); fontNames->SetCompareFunction( compare != NULL ? compare : JCompareStringsCaseInsensitive); fontNames->SetSortOrder(JOrderedSetT::kSortAscending); #ifdef _J_USE_XFT #else int nameCount; char** nameList = XListFonts(*itsDisplay, "*", INT_MAX, &nameCount); if (nameList == NULL) { return; } for (int i=0; i<nameCount; i++) { if (regex.Match(nameList[i]) && strcmp(nameList[i], "nil") != 0) { JString name = nameList[i]; JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { JString* n = new JString(name); assert( n != NULL ); fontNames->InsertAtIndex(index, n); } } } XFreeFontNames(nameList); #endif }
static XFontStruct *GetFont(FILE *err, Display *disp, char *name) { static const char *fontnames[] = { "sansb12", "8x13bold", "8x13", "9x15", "6x13", "fixed" }; #define MAXNAMES (sizeof(fontnames)/sizeof(fontnames[0])) int i; XFontStruct *font; int count; char **fontlist; gmx_bool bFont = FALSE; if (name) { bFont = (gmx_bool) ((font = XLQF(err, disp, name)) != NULL); } else { font = NULL; } for (i = 0; (!bFont && (i < MAXNAMES)); i++) { bFont = (gmx_bool) ((font = XLQF(err, disp, fontnames[i])) != NULL); } if (!bFont) { fontlist = XListFonts(disp, "?", 1, &count); if (count != 0) { bFont = (gmx_bool) ((font = XLQF(err, disp, fontlist[0])) != NULL); } } if (!bFont) { fprintf (err, "Cannot load any suitable font\n"); } return font; }
/* find a font spec that matches font spec FONT and also matches (the registry of) CHARSET. */ static Lisp_Object gtk_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset) { char **names; int count = 0; Lisp_Object result = Qnil; const char *patternext; int i; TO_EXTERNAL_FORMAT (LISP_STRING, font, C_STRING_ALLOCA, patternext, Qbinary); names = XListFonts (GDK_DISPLAY (), patternext, MAX_FONT_COUNT, &count); /* ### This code seems awfully bogus -- mrb */ for (i = 0; i < count; i ++) { const Bufbyte *intname; Bytecount intlen; TO_INTERNAL_FORMAT (C_STRING, names[i], ALLOCA, (intname, intlen), Qctext); if (gtk_font_spec_matches_charset (XDEVICE (device), charset, intname, Qnil, 0, -1)) { result = make_string ((char *) intname, intlen); break; } } if (names) XFreeFontNames (names); /* Check for a short font name. */ if (NILP (result) && gtk_font_spec_matches_charset (XDEVICE (device), charset, 0, font, 0, -1)) return font; return result; }
static void motFontDlgInitSizeList(Ihandle* ih, const char* fontface, int size) { int i, j = 1, selected=-1, count = 0, sz, prev_sz = -1; char pattern[1024]; Ihandle* list3 = IupGetDialogChild(ih, "LIST3"); int size_list[32767]; char**font_list_str; sprintf(pattern,"-*-%s-medium-r-*-*-*-*-*-*-*-*-*-*", fontface); font_list_str = XListFonts(iupmot_display, pattern, 32767, &count); if (!font_list_str) return; for (i=0; i<count; i++) size_list[i] = motGetFontSize(font_list_str[i]); qsort(size_list, count, sizeof(int), motFontDlgCompareSize); for (i=0; i<count; i++) { sz = size_list[i]; if (sz && sz != prev_sz) /* avoid duplicates, and zero */ { if (sz == size) selected = j; IupSetfAttributeId(list3, "", j, "%d", sz); prev_sz = sz; j++; } } IupSetAttributeId(list3, "", j, NULL); if (selected != -1) { IupSetfAttribute(list3, "VALUE", "%d", selected); IupSetfAttribute(list3, "TOPITEM", "%d", selected); } XFreeFontNames(font_list_str); }
Lisp_Object __get_gtk_font_truename (GdkFont *gdk_font, int expandp) { Display *dpy = GDK_FONT_XDISPLAY (gdk_font); GSList *names = ((GdkFontPrivate *) gdk_font)->names; Lisp_Object font_name = Qnil; while (names) { if (names->data) { if (valid_font_name_p (dpy, names->data)) { if (!expandp) { /* They want the wildcarded version */ font_name = build_string (names->data); } else { /* Need to expand out */ int nnames = 0; char **x_font_names = 0; x_font_names = XListFonts (dpy, names->data, 1, &nnames); if (x_font_names) { font_name = build_string (x_font_names[0]); XFreeFontNames (x_font_names); } } break; } } names = names->next; } return (font_name); }